Postion control question


I am running SimpleFOC on the following setup

Ardunio Mega,
DRV8302 driver
1024 ppr encoder
Maxon 4 pole pair motor

Torque Control is Voltage
Motion Control is Angle

I have been trying to tune my setup for position / angle control but can’t seem to get over this behavior.

The blue = Target, Yellow = Angle, Green = Velocity, Red = Voltage.

As you can see the motor moves to 60% of the target very quickly then takes ages (approx 5 secs ) to move the rest.

I have tried increasing the P term in the angle loop but this just give big oscillations in a steady state.

What should I be adjusting?


I’m a newbie in this, but here are some hints from my short experience:

  • First you need to tune the velocity PID, because I think the angle control mode is based, underneath, on the velocity control mode. So set Motion Control to “Velocity” and look at the velocity curve when you suddenly change the velocity from 0 to X rad/sec. You need to achieve a velocity change that looks like the green curve here :

  • When the velocity PID is correctly tuned, you can get back to Angle Motion Control and tune the angle PID the same way. However, the angle PID is usually more simple, something like 20;0;0 (P only).

  • Would you please provide all your PID values? My guess is that you should increase “I” in the velocity PID.

  • Don’t be afraid if you don’t get very good result in Voltage mode. You need to start in Voltage mode in order to tune the Velocity PID then Angle PID in isolation. But then you’ll need to switch to Current modes to achieve better results (this will add more headache, though, cause this will add 1 or 2 more PIDs).


Thanks quentin,

like you, I am a newbie to FOC and brushless motors but have a little understanding of control theory.

I tune the motor first in Voltage and Velocity modes and got a good response to step changes. It it is a fairly high-power Maxon motor currently running with no load. P =1.8, I=0, D=0. When I first went to angle control I got terrible oscillations even with it holding zero position. I found detuning the P term on the velocity controller down to 0.5 helped.

The P term on the angle controller is currently set to 3 if I increase it the oscillations come back.

What looks strange is if you look at the response of the angle position (yellow) is very fast to respond but then slows causing a knee in the line.InkedAngle_Control_LI


You’ll have to tune your PID parameters. When setting up a motor with SimpleFOC, it is usually really helpful to start simple and get more complicated…

E.g. is your motor working as expected in open loop velocity mode?

Once that is working, add the sensor and start tuning your PID values for voltage mode. For a Maxon motor these could be quite different to the examples in the library.

Generally speaking, zero P, I & D, and increase P until you get as close to your target (velocity/position) as you can but without getting oscillations. Then increase I until you get a nice, quick response. D can usually be left on 0, sometimes it helps to set it to a very low value.

It is also conceivable that there is an electrical problem, for example the DRV8302’s OCP kicking in because the currents are getting too high. You could check this by monitoring the nOCTW pin. Or you could test your setup (with unloaded motor) with a lower voltage_limit so as to be sure the current stays in spec.

I assume the red line (voltage) is the output voltage as calculated by simplefoc?

1 Like

Thanks runger for your input (anybody else feel free to jump in)

Yes, I have gone through all the basic steps, test the motor, driver and encoder. The motor seems to be working fine in open loop control. Although I had to keep the voltage low to stop excessive heating (but I think that normally for a low resistance motor in open loop)

As I said before the response in velocity control seems very good. If I increase P to high I do get oscillations.

You might be right about the DRV8302’s OCP kicking in. I try some more experiments. Current monitoring is next on my list of thing to try.

Yes you are right the red line is Volt_Q from the monitor line