Closed Tom0514 closed 8 months ago
It is generally possible to run a current loop on PWM (this is how FOC works in a nutshell), but it is generally timing critical and should be done in firmware. The actual equation that scales voltage to current in a motor should include the motor velocity and the winding resistance.
You are going to run into timing issues when doing it over the network, but you can maximize the feedback rate and hope for the best. As a first debugging step I'd recommend looking at logs and checking what your PWM commands look like. The red LED and sound probably indicate that your controller is unstable and oscillating.
Thank you for your reply!
The actual equation that scales voltage to current in a motor should include the motor velocity and the winding resistance.
The dynamic equation of the motor is: U=Ri+L*di/dt+Keθm_dot
. Can I directly convert the output of MPC
to a voltage value through this equation, and then scale it to the corresponding PWM
value. Of course, the inductance L
here is unknown, but I think the magnitude of the inductor voltage should be much smaller than the other two items. Is it possible to ignore the inductor voltage to achieve an approximate mapping from current to voltage?
You are going to run into timing issues when doing it over the network, but you can maximize the feedback rate and hope for the best.
Doesn't changing the feedback frequency affect the sampling time of MPC
? My sampling time is 0.01s
, so I set the feedback frequency to 100Hz
.
I thought about it, I can use its Integer multiple relationships to achieve the sampling time and feedback required by MPC
.
The red LED and sound probably indicate that your controller is unstable and oscillating.
In the early stage of MPC
, the output current signal has a large oscillation. I think this may be the reason. I will try to add constraints to the control input rate.
For the joint X5-9
, when setting the upper and lower bounds of the state variable and the control input of MPC
, the parameters I set are:
% The state variables correspond to motor position, motor speed, link position, and link speed
lbx = -1*[pi, 14/9.55, pi, 14/9.55];
ubx = +1*[pi, 14/9.55, pi, 14/9.55];
% control input: Motor winding current
lbu = -1.6;
ubu = +1.6;
The current is set according to the peak current in the parameter table (1.6A @ 36V
), the speed of the motor and link is obtained from the maximum speed (14 RPM
), and the constraints of the position of the motor and connecting rod are self-selected (+/- 4 rotations (8 x 360-degree total range)
). Is this reasonable? Thanks!
For the joint X5-9, when setting the upper and lower bounds of the state variable and the control input of MPC, the parameters I set are:
This can give +1/-1
commands under the direct PWM
strategy to observe the joint output, so as to obtain the relevant upper and lower limit values.
Hello, ennerf!
I have designed a PI
current controller with a feedback frequency of 1000Hz
, and when I am tracking a fixed value of 0.1A/0.2A, it is tracking ok. But today when I was trying to trace a sequence of control input signals from the MPC
solution, it had a problem.
Then when I try to track a higher fixed value of current under this PI
parameter again, the feedback results are almost the same, and there is no tendency to track the target at all.
Here is my feedback plot for tracking a fixed value of current using a PI
controller (P-0.2
, I-50
):
The control input signals of the MPC and the corresponding simulation results (state trajectory and reference trajectory) are as follows:
Track the control input signal under the PI
parameter:
Is this a problem with the PI
parameter? Why this happens, I have a hard time understanding. Here is my code.
Hope you take a look! Thank you so much!
Best regards, Xu.
I tried running your code, and I think you are running into at least two issues:
You may be commanding something that is physically impossible. On an unloaded X8-3 going full tilt I get a maximum motorCurrent of 0.15 amps. I'd recommend doing a sanity check where you command max pwm and check what the output is for your system.
You are not capping the i term, so the controller is running into integral windup and can't recover.
Thank you for your reply! I'm going to double-check the two points you raised. Thanks again!!!
You may be commanding something that is physically impossible. On an unloaded X8-3 going full tilt I get a maximum motorCurrent of 0.15 amps.
Sorry, the output of my actual MPC
is windingCurrent
, I looked at the uploaded code and wrote motorCurrent
. At that time, in order to verify whether it was a problem with tracking signals, I tested motorCurrent
, but I looked at the log files, and it seemed that the tracking could not be achieved.
I'll check the problem again, I'm really sorry.
Hello, ennerf !
I'm testing the
MPC
algorithm in a joint, and my control input signal is the motor winding current, i.e.windingCurrent
. When testing the joint, I scaled the value to the[-1,1]
interval and sent it to the motor with adirect PWM
strategy, but the actual effect was far from the simulation result.So, I want to track the current signal by cascading a bottom PID current controller. But when writing the current controller on the
direct PWM
strategy and applying it to the joint, the LED of the joint turns red and then makes a screeching sound. Is it possible to implement a current controller underdirect PWM
strategy? Thanks!Best regards, Xu.