Hi, i need some help on my project. It is a 2 wheel self-balance robot. The robot can balance on its own now, however it tends to tilt to one side and then keep running in that direction . Somebody suggested that i should feed back the information from the wheel's encoders, but i don' know how to do it. Many thanks to someone that can give me some guide now !
It won't be necessary to use wheel encoders. The behaviour you describe can be sorted out by using a suitable control algorithm (which includes some control filtering and using suitable control parameters - usually 'PID' parameters) and by ensuring that sensors give relatively accurate and stable readings (so that the control algorithm and operate on these readings effectively).
Things to try are: log the sensor data while the motors are de-activated, and see if you get good (sensible) readings from accelerometers and gyroscopes when you change the angle of tilt of the robot.
If using serial communications.... set the baud rate to 115200 baud (and don't use anything slower).
Utilise a 'complementary filter' in the control software that operates on measured angles (from gyroscopes and accelerometers). And use relatively fast sample rates.
And, to treat motor backlash (if there is any), software can be used to apply some finite minimum voltage to the motors in attempts to reduce the 'deadzone' window.
Thanks, i'm using MPU6050 for both gyro and accelerometer; PID control; complementary filter (something like this: tilt_angle = 0.6gyro_angle + 0.4accel_angle). My sampling rate is about 0.1 second, is it too slow ?
Also, i noted that when i turn on the power of the microcontroller, then let it run for a bit while, then turn the motors on, then it runs pretty fine. But if i turn on the micro controller and the motors at the same time, then the tilt measurement will deviate alot ( i have logged the data, and found that it's the gyro measurement that deviates that makes the tilt measurement deviate). Is the because of the motors ?
You could just try:
tilt_angle = accel_angle;
And see how that goes for the moment. That's just to ignore the gyro measurements until the issue is sorted with the misbehaving gyro measurements.
The other thing that could help is to put a reasonably large capacitor on the supply rail of the MPU6050... just to make sure it gets a stable supply voltage.... eg. no spikes during powering up etc.
Also, try a sampling period of 1 millisecond, ie. 0.001 seconds. Just to try.
Southpark:
It won't be necessary to use wheel encoders.
Yes it will. They are the only sensor capable of detecting lateral drift accurately. (short of GPS)
The way things are done is that an outer control loop driven from the lateral position is used to
adjust the set-point of the inner balance loop.
MarkT:
Yes it will. They are the only sensor capable of detecting lateral drift accurately. (short of GPS)The way things are done is that an outer control loop driven from the lateral position is used to
adjust the set-point of the inner balance loop.
Yeah... if the robot just needs to stay put (and not lean) for 20 minutes or half an hour.... no wheel encoders are necessary. I'm just assuming the o.p. is having a significant lean issue with their bot even for really short durations of time.... like 5 seconds.