Go Down

Topic: Balancing robot for dummies (Read 146 times) previous topic - next topic

kas

#45
Oct 29, 2010, 02:23 pm Last Edit: Oct 29, 2010, 10:07 pm by kas Reason: 1
@beautifulsmall

Thanks for the information  :)
I will study the code and come back to you soon

Please post a link to the motors you are using and possibly a close up photo of your bot. Seems that this gearless setup should solve the backlash problem.

beautifulsmall

Kas, the motors are the dog's B'llks, and cost me ,about £60 uk,each, after tax, ect.ie, not a commertial product, plenty of bal rob videos are with cheap motors so ive ordered some 120rpm, 6v from china, photo shows a bit of back axel so im hoping i can attatch a mouse encoder, ball.
on Earwig are RE-max 29, neobium magnet, coreless. DC motors, non-cogging,
I will explain the construction because i once took one apart. re-assembly was not in a clean room.
A commutated DC motor has a rotating core surrounded by a set of magnets , the coreless design has a solid magnet bar in the centre and the wire winding is spun into a tube which surrounds the magnetic core. 7-11 poles are used but the winding pattern effectivley gives an analoge effect , BUT they will vibrate at 1Khz, and anything less, they are super twitchy!very low inertia.
Backlash, belt systems are good, belt tension matters, on earwig i have M3 HTD belts and 1:8 ratio, aluminium motor pulley, plastic wheel pulley. The motors are 20N side load max, the belts are 100N max, so I do run with a loose belt, and backlash.
Backlash compensation,  in wheel velocity calculation :

if velocity changes direction , velocity =0 for next two loops

because im rubbish at code, I set a loop to count time and let it loose every 4ms , before this the loop ran at its natural speed and despite having a dt in all the calculations, I needed to reset all the pid values constantly.
the velocity at direction change should be around zero or at least trying to get there so setting wheel velocity to zero cuts out the velocity jump as the motor changes direction and the belt tension changes from one side to the other. this does not affect encoder absolute position which must be read at static zero up.

blackfin , stereo vision,
Kas, its so hard to teach kids there 0xff times table :D ;D

kas

Quote
Reply #46 - Today at 02:51:56
beautifulsmall, on which side of the Atlantic ocean are you living ??
Should you live on the "wrong side"  ;), I hope you have another life for sleeping  :D  :D

Thanks for you coreless motor description, I was confusing "coreless" and "brushless" motors (the ones with separate ESC controllers)

Quote
ive ordered some 120rpm, 6v from china
Depending on wheels size and bot weight, you may find 120rpm a bit slow for proper operation

Planetary geared motor are supposed to have no mecanical backlash
Still trying to identify adequate units with attached encoders

Patrik

Finally after a lot of stupid questions I got the kalman filter to work. I need to tune the zero ACC_Z value some more and some other things but it works. The effect is quite amazing, see the video here and see for yourself. (Values in quids).

I was to say the least confused about the unit quids and the arrangement of the acc. and the gyro. But now I understands it and man it's smart to be able to us int values...


I will post some more information about the tests on my blog later this weekend...
The balancing robot for dummies guide
http://www.x-firm.com/?page_id=145

kas

Very clean signal   8-) 8-)
Also check signal quality when sensor is upside down
My sensor combo gives poor result when inversed and couldn't be positioned as per your photo

For ACC_Z, gravity correction = (0° value - 180° value)/2

Quids are nice for integer math
Those are basic 10 bits Quids (360° = 1204 Quids)
For better resolution, we may use Quids12 (360° = 4096 Quids)  ;)

kas

@patrick
If your are still looking for a 12V battery, look at this one
http://cgi.ebay.co.uk/ws/eBayISAPI.dll?ViewItem&item=150447448378
3800 mAh, 22 bucks shipped

Patrik

#51
Oct 30, 2010, 08:36 pm Last Edit: Oct 30, 2010, 09:33 pm by X-firm Reason: 1
@Kas

I have some small things I wanted to ask you that I don't really understand. I used the greyed sensor inputs like in the image below is that correct:


I changed the following in your code:
I recalculated the zero value for Acc_Z
440/3300*1024 = 136
Code: [Select]

void calibrateSensors() {    // Set zero sensor values
 long v7
 for(int n=0; n<5; n++) {
   v = 0;
   for(int i=0; i<50; i++)       v += readSensor(n);
   sensorZero[n] = v/50;
 }                                                          
 sensorZero[ACC_Z] -= 137;                        
}


I changed the gyro rate and also changed to my GYR_X instead of using GYR_Y. I also changed the sign off the return value;
Code: [Select]

int getGyroRate() {                                             // ARef=3.3V, Gyro sensitivity=2mV/(deg/sec)
 return int((sensorValue[GYR_X] * 0.88888888889)*-1);                 // in quid/sec:(1024/360)/1024 * 3.3/0.010)
}

int getAccAngle() {                      
 return (arctan2(-sensorValue[ACC_Z], -sensorValue[ACC_X]) + 256);    // in Quid: 1024/(2*PI))
}


What I don't really understand is why I didn't need to change the sign of the ACC_X value to get it like your values.

Why do you enter the values as negative in to the function arctan2 and why adding 256?
Quote

(arctan2(-sensorValue[ACC_Z], -sensorValue[ACC_X]) + 256)


I'm not that good at math so you have to excuse my sometimes stupid questions..

The balancing robot for dummies guide
http://www.x-firm.com/?page_id=145

Patrik

@kas
Thanks for the tips.

I had planed to by a lipo battery from Hobbyking but they are on 11,7V I think so this suited me just fine and free shipping also :)

Quote

@patrick
If your are still looking for a 12V battery, look at this one
http://cgi.ebay.co.uk/ws/eBayISAPI.dll?ViewItem&item=150447448378
3800 mAh, 22 bucks shipped
The balancing robot for dummies guide
http://www.x-firm.com/?page_id=145

kas

#53
Oct 31, 2010, 09:05 am Last Edit: Oct 31, 2010, 09:08 am by kas Reason: 1
Quote
I used the greyed sensor inputs like in the image below is that correct:
Nice drawing  ;), my setup is actually as per your drawing


Quote
I recalculated the zero value for Acc_Z
440/3300*1024 = 136
I looked at the MMA7341L Accelerometer datasheet:



Please keep in mind that quoted sensitivity (440 mV/g) is a typical value. Your specific sensor may be as low as 413, or as high as 466.
I suggest you calculate Acc_Z zero value using the experimental way as described above


Quote
What I don't really understand is why I didn't need to change the sign of the ACC_X  value to get it like your values.
Why do you enter the values as negative in to the function arctan2 and why adding 256?
Quote:

(arctan2(-sensorValue[ACC_Z], -sensorValue[ACC_X]) + 256)
Signs are related to axis orientation.
Just adjust the signs by experimenting and make sure you get data format as described in reply #7.
256 is an offset (90°) to get a 0 angle value when the bot is vertical

Patrik

@kas

Tanks for the replay of all my questions and I bought the battery you gave me a link to.

I will make some more experiments with the kalman filter and also add the other axis so I can see if the bot is tilting side wise as well.

Under the week I will start moving the motors and make some experiments with the encoders.

In the weekend I will start building the body to the robot...
The balancing robot for dummies guide
http://www.x-firm.com/?page_id=145

kas

you may experiment with the encoders, but I strongly advise not to implemente them in the bot yet.
You can balance pretty well w/o encoders
Encoders will reduce potential forward/backward drifting

Good luck  ;)

kas

#56
Oct 31, 2010, 07:20 pm Last Edit: Oct 31, 2010, 07:21 pm by kas Reason: 1
                          [size=14] ** Balancing robot for dummies **[/size]


 [size=14]Part five (final): DC motor control and V1 code[/size]

The updatePid function (see part 4) returns a -255 +255 range value for the motors commands
    0        stop (bot is vertical)
+255      fast forward
-255       fast backward

Motor controllers only understand 0 +255 range values
This is taken care of in the Drive_Motor code

Code: [Select]
int Drive_Motor(int torque)  {
 if (torque >= 0)  {                                        // drive motors forward
   digitalWrite(InA_R, LOW);                        
   digitalWrite(InB_R, HIGH);
   digitalWrite(InA_L, LOW);                    
   digitalWrite(InB_L, HIGH);
 }  else {                                                  // drive motors backward
   digitalWrite(InA_R, HIGH);                      
   digitalWrite(InB_R, LOW);
   digitalWrite(InA_L, HIGH);                      
   digitalWrite(InB_L, LOW);
   torque = abs(torque);
 }
 analogWrite(PWM_R,torque);
 analogWrite(PWM_L,torque * 0.9);                           // motors are not built equal...

Please refer to http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1282384853/0
for additional informations

The first part of this tutorial is now terminated (finally...  :-X :-X :-X)
I am impressed by the number of time this thread has been viewed, I hope the info was clear and detailed enough
If you started your own project or intend to do so in the near future, please jump in now and just leave a comment here


KasBot V1 complete code file:
** EDIT **  can't find the trick to upload a file   any hint ???

KasBot V1 is fully functional and should balance for ever
Just modify the code according to your own gyro sensitivity
Code: [Select]
int getGyroRate() {                                          // ARef=3.3V, Gyro sensitivity=2mV/(deg/sec)
 return int(sensorValue[GYR_Y] * 4.583333333);              // in quid/sec:(1024/360)/1024 * 3.3/0.002)  
}
My gyro (IDG300) is 2mV/deg/sec
For Accelerators, adjust gravity offset in calibrateSensors()
PID parameters should also be tuned according to your own bot geometry and weight

More to come:
V1.5 will bring "utilities" for live tuning without re uploading the code
V1.7 will replace Arduino 10 bit ADC with MPC3208 12 bit ADC (increased resolution)
V2.0 should combine encoders info in PID to suppress potential forward/backward drifting
V3.0 should bring RC remote control features (Xbee technology)
V4.0 will add IR Ping))) sensor for obstacle avoidance
V5.0 will add...    your own ideas  ;) ;)

Long (probably endless) roadmap  ::)

Ro-Bot-X

I have to say this is awesome! You managed to write it for dummies, I hope I'm dumb enough to get it, hehe. I have different acc and gyro sensors, old ones, I have to dig up some data sheets to find out the resolution for them. Other than that, I should be fine, except for motors speed, that is lower than 200 rpm. Oh well, I'll use them for now. I'll add some 10k pots to adjust the PID parameters. I'll report my progress probably next weekend, during the week I don't have much time. This weekend will be the chassis manufacturing out of some plywood. After I get to the final tweaks I'll cut a nicer one from acrylic. Wish me luck!

kas

Hi Ro-Bot-X
Thanks for the nice comments

Quote
...Wish me luck!
I do!!!   :) :) :)

hoyeungl

I need the infomation about the PID which you stated.

How come in your error terms is a speed, and the return part is a pwm duty ratio?

What is the K stands for? Gain? or others?
How can I calculate it?

Go Up