Advice for dealing with non-linearity in balancing robot PID?

Hi all,

I am a mechanical/biomedical engineer, but have limited electronics/software experience. I am trying to learn, so I have built a two-wheeled balancing robot (similar to a segway). I’m getting moderately good results, but the bot is quite twitchy. Other bots I see online have very little steady-state movement, maybe rocking back and forth. But with mine, it will twitch a few times a second. Usually these are just little twitches, not enough to prevent balancing. Note that this isn’t oscillation – it seems to be random in nature.

I suspect that the twitching is coming from non-linearity in the system. Possibly, from the following:

  • A fairly large dead zone in the motors’ response to PWM input: when slowly increasing the PWM range from 0 to 100%, the wheels don’t turn at all until above 25%. Then the speed seems to max out with a PWM at about 50%. I measured this with a simple script to use the encoders to measure velocity over the range of PWM duty cycles. I am aware that this was measured under no-load conditions, and I’m sure that adding a load will prevent maxing out of the speed before 100% duty cycle, but it will not help the dead space.

  • Backlash in the gearboxes: fairly self-explanatory. These motors don’t seem to have too much backlash – less than other DC motors I have seen, but enough to cause issues near vertical setpoint. I think this is fairly minor though.

I am fairly sure that the problem isn’t PID tuning – if I adjust any of the parameters up or down, the system becomes unstable and performance is degraded. My system has very good disturbance rejection – you can bump it and jostle it quite a lot and it will still recover but then continue twitching.

Any ideas? I tried filtering the input (IMU readings) and output (drive signal), but the lag inherent to filtering makes the system less stable. I also thought about empirically finding a linearizing function, to predict an appropriate PWM setting for a desired motor power. Has anyone tried anything like this? Or overcome in any other way? For my IMU, is it worth it to replace the complementary filter with a Kalman filter? Will it make much of a difference?

Thanks in advance.

submitted by /u/ManBearHybrid
[link] [comments]