Gyro Stabilize Motion Reaction Problem

Hello,
I am trying to design gimbal.
I have a good encoder and also good perforamnce IMU.

I can get directly AHRS data from my IMU with 100hz.

I use SimpleFOC library to drive my motors. Actually, velocity loop and position loop working normally in a good way. I have designed my own tuner. For example I can give the input with different frequencies and angles or velocity inputs. (for example, 5hz 0.1 rad/s or 10 hz 10 deg) etc.

Here some results. It’s the 5 degree input to position loop at 5 Hz. image-2024-10-10-03-55-12 hosted at ImgBB — ImgBB
Also, here the 0.4 deg/s speed input at 5Hz.
image-2024-10-10-03-57-59 hosted at ImgBB — ImgBB

I think position and speed loops somehow working good.

So, idea for the stabilization, I tried the 2 ways and I faced with similar result.

The first way I tried, once I got the error from AHRS(when I click a button, I got for example YAW angle as target and when I turn the system with my hands I got current YAW angle. Basically, error is target-curren YAW angle). Then I put this angle error to a PID and create a speed reference. Then I give this speed reference to the speed loop. It’s the first way I tried.

Second way, I used the error value as position input. I got the error value and added the current position of the motors(ie. encoder angle) and give that as position reference to position loop. So, position loop basically work like the PID controller I used in the first way.

For both, I faced the same issue. The system reactions are too low. I always got some error. To better understand the issue, I draw the error angles (target YAW and current yaw value). You can see the change of the error value below(blue line).

I used 20khz PWM frequency and my both motor.loopFOC and motor.move functions works 5khz.

I tried to tune PIDs, I tried so many things but never saw a smooth turn and very small error value. I don’t know why it happens. I use good quality IMU and encoder. Also, I think the position loop and velocity loop tuning somehow is good.

What’s your opinion? What should I do?
Thanks.

Your IMU is at 100hz, which means your reaction time is 10ms at best. Then your AHRS algorithm adds more delay. This sounds way too long, so I’d fix that first. 800 Hz sounds like an absolute minimum to me.
On top of that, you might want to improve the PID tuning of your motors to make them more responsive.

Are you printing something at regular intervals? That could slow your loop down and cause the periodic drops of the blue curve.

Hello, Thanks for the comment. Actually my IMU provide raw data much more than that but AHRS data is 100Hz. I will try to increase that. What do you think about my motor.loopFOC() and motor.move() functions? Both work 5KHz. Should I increase loopFOC and downsample to motor.move func?

5 kHz for motor.loopFOC() is fine, 5 kHz for motor.move() might be too fast (introducing noise). There’s a parameter in SimpleFOC called motion_downsample that you might want to use to slow down (decimate) your calls to motor.move(). My advice is to use tools such as “SimpleFOCStudio” or “SimpleFOC WebUI” to tune your PID parameters (including motion_downsample).

Another thinking that, I am not sure using position command is usefull or not. I tried both speed and position loop. For speed, I used my own PID and for position input, I used directly position loop. Which one would be better? I will try to tune PID more responsive but somehow it’s not too bad now right?

Both speed and position control should work equally well for a gimbal. My experience is that you usually end up using position control, as even though a gimbal’s primary goal is not to deal with absolute positioning, you usually need absolute positioning at some point.

Thank you. I will try this.

I increased my IMU to 1KHz and used custom fusion code. Now, gimbal reactions much better. I will try to increase the motor.loopFOC() to 10Khz and downsample the motor.move().

Also, I will try these tools to tune PID. If I can’t satisfy the performance, I consider to use different controllers like ADRC or Sliding mode.

Thanks for your help!