Go Down

Topic: Turning a motor into a servo (Read 2 times) previous topic - next topic

Fons1302

Hi,

I described my problem on Pololu's forum (http://forum.pololu.com/viewtopic.php?f=15&t=3592) but a short summary:

I have 2 brushed DC motors, a dual motor driver (with PWM control), a arduino UNO and 4 linear continuous rotation pots. I thought of making my own servo's cause I wanted a 1-on-1 angular positioning control (for tele-operation). I mean that each motor has a pot on its axis and I control its position with another but identical pot. I thought it would have been easy and just write a simple code where the two pot readouts must reach the same value but the motors where loud and unprecise. Pololu told me to use a PID feedback code for a good result (it would offer me Jrk-like performance - http://www.pololu.com/catalog/product/1392). I know what it is briefly (saw it in class) but they told me the code would be complicated.

I looked around and found some stuff about PID but I can't find my way in it. Does anyone know a code that would give servo-like perfomance with the hardware I have?? It would be very nice and efficient cause I don't want two buy 2 Jrk's if I can get the same with my motor driver and Arduino.

Thanks a lot.

fliggygeek

I would expect that the noise you are experiencing is PWM hum, the only way to solve this is to make your PWM switch at much higher frequency which i i have NFI how to do on an Arduino. As far as the continuous pots, PID seems to be the way to go here, it will require some complex maths but it should work. A short intro here if u don't quite get it. Basically your motor driver would be told "move motor forward a bit" and would send PWM signal to motor to turn forwards. The controller then looks at the value that the pot changed and compares it to the change in PWM signal it sent. it does some maths here and thinks, if i want to turn it x amount, i change the PWM signal by x*4  (for example) and it does this constantly, adapting for changes in torque etc. this enables much higher amounts of accuracy. As to how to code this, it'd be fun, but quite challenging.
"Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent di

zoomkat

If you are on a beer budget, you may want to take a diffrent approach for your tele-operation (I assume a cam pan/tilt). You can make a cam pan/tilt platform using large standard hobby servos. If you can live with only +-45 deg. of movement (you might find or make one for a larger range), you can use an inexpensive servo tester like below to control each servo. Bottom are some more expensive cam mounts.

http://www.hobbycity.com/hobbycity/store/uh_viewItem.asp?idProduct=8296
http://www.hobbycity.com/hobbycity/store/uh_viewItem.asp?idProduct=14774



http://www.servocity.com/html/pan_tilt_roll___accessories.html
http://www.servocity.com/html/pt-2100_pan__tilt_system.html
Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

Fons1302

#3
Feb 13, 2011, 07:54 pm Last Edit: Feb 13, 2011, 08:00 pm by Fons1302 Reason: 1
@ fliggygeek,
I forgot about the switching frequency of the PWM signal. I have to look it up thanks. But I don't think it is the only reason for the bad servo attitude but I'll have to try it again with a higher frequency. I used the code you can see below and like you can see it is pretty simple. I use the difference of both pot positions for poistioning. The bigger the difference the higher speed I give the motor. But like you say, PID would be much better and it would be a challenge to write. Thanks for explaining the basics. I'll have to think about a clever feedback code. But aren't any standard PID algorithms in circulation?

@ zoomkat,
It is indeed a pan/tilt setup I would like to control with my head (with the help of a headset). Later on I would like to add the roll too but you got to start 'simple'. I don't know why I tried servo's first but I am not sure if servo's can make precise angle reproduction... it follows your pots' movement very well but can you make it move 59,5 degrees if your turn your pot 59,5 degrees?? Is it simpel to setup like the 'Knob' tutorial (http://arduino.cc/en/Tutorial/Knob)? I have to learn more about servo's I guess. I thought of using the hardware I have and it should work with the right software but I must check out the local RC stores for some quality/price ideas. I need more or less a 170° and a 120° movement. Those servo testers are simple useful things its seems. Those large pan/tilt setups use about the same motors that I have I think. Thanks for the links!

/*
 Motor Position Control
 Control a motor's position with two potentiometers.
 */
void setup()
{
 Serial.begin(9600);
 pinMode(8, OUTPUT);
 pinMode(9, OUTPUT);
 pinMode(10, OUTPUT);
}
void loop()
{
 int sensorposition = analogRead(0);
 int motorposition = analogRead(1);
 int difference = sensorposition - motorposition;
 Serial.println(difference, DEC);
 if (difference > 0)
 {
   digitalWrite(8, HIGH);
   digitalWrite(9, LOW);
   if (difference > 255)
   { analogWrite(10, 255); }
   else { analogWrite(10, difference); }
 }
 if (difference < 0)  
 {
   digitalWrite(8, LOW);
   digitalWrite(9, HIGH);
   if (abs(difference) < 255)
   { analogWrite(10, abs(difference)); }
   else { analogWrite(10, 255); }
 }
 if (difference == 0)  
 {
   digitalWrite(8, HIGH);
   digitalWrite(9, HIGH);
   analogWrite(10, 0);
 }
}

zoomkat

Quote
It is indeed a pan/tilt setup I would like to control with my head (with the help of a headset).


This is the part that you will probably find not workable for what you want to do unless you accept some limitations.
Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

Go Up