Hi all,
I am currently working on a project in which I need to rotate a motor with a wheel attached to a desired position as fast as possible with little overshoot and/or oscillations. I am using the b-g431b-esc1 with a Cubemars GL30 290KV motor and an as5047p encoder in ABI mode. I have decided to start using PlatformIO for this project with Simplefoc version 2.3.1.
Initially, I used an Emax GB4114 42KV motor for some first tests. I wrote the code heavily based on the b-g431b-esc1 example code for position control (which btw has a mistake, as is says: motor.controller = MotionControlType::velocity
). After some tuning this worked fine using the standard cascaded position-velocity controllers.
However, after switching to the Cubemars GL30 290KV I wasn’t able to control the motor to a desired position without oscillations. I tried to first tune the velocity controller in velocity mode and increased motor.LPF_velocity.Tf
, but I wasn’t able to get rid of shaky behavior a low velocities. I checked the velocity signal when controlling in torque
mode (which I think is voltage control, as I haven’t enabled current sensing as far as I know?), which is very noisy at low velocities.
As a solution I decided to not use the standard cascaded position-velocity controllers, but put it in torque
mode and write my own direct position controller in the main loop:
void loop() {
// PID position loop
if ((millis() - t1) >= Dt) {
float angle = encoder.getAngle();
e = filter(target) - angle; // error
ei = ei + e*(Dt/1000); // integrated error
ed = (e - e_old)/(Dt/1000); // differentiated error
// control command
C = P*e + I*ei + D*ed;
// update values
e_old = e;
t1 = millis();
}
// iterative FOC function
motor.loopFOC();
// Motion control function
motor.move(C);
// communicate with the user
serialReceiveUserCommand();
}
For now the control loop only gets execute at every fixed Dt
(currently at 2 ms) to make differentiating and integrating easier. All in all it works quite well, but it could be optimized by letting it run as fast as it can and tuning can always be optimized of course. The step response looks like this now:
I am quite happy with the results, however it does raise a couple of questions:
- Why is the standard position controller in SimpleFOC a cascaded version?
- Why is the velocity signal of the as5047p encoder so noisy at low speeds?
- And why was the Emax GB4114 42KV position control seemingly not effected by it? Is it because of faster dynamics of a higher KV motor? I got the feeling it might be a similar issue as posted below for a higher KV motor also using b-g431b-esc1:
https://community.simplefoc.com/t/b-g431b-esc1-beginner-guide-i2c-guide/515/10?u=jornel
I am happy to hear your thoughts!
Kind regards,
Jornel