PDA

View Full Version : servo motor control



sudarshan
05-30-2010, 05:06 PM
hi
i want control two servo motors for my robots hand one servo for each hand?
and i have attached a plate in it so it carry some dishes like food and water
i want to lift the plate and lower the plate with the two servos
when it raises i want it to hold its position and move for some distance and stop and then lower the plate

the problem i am facing is
i can hold the plate in position but i can't make it to move at the same time
i am using atmega 32 and avr 40pin v2 board from robokits.co.in

please help me

pratheek
05-30-2010, 05:46 PM
i can hold the plate in position but i can't make it to move at the same time


In which direction(axis) do you want to move the hand?

avinash_g
05-30-2010, 05:51 PM
Explain your setup with diagrams.

vikas
05-30-2010, 06:56 PM
post pic / better explanation

sudarshan
05-30-2010, 08:18 PM
please refer the followng url
http://www.superrobot.co.cc/Home/robotics/mega_prime

currently no plate is attached to the robot.but you can see the hand of the robot at the end of the hand the plate will be attached
All the works properly the servo and the movement
the servos are controlled with delays .i want to hold the servos postion up and move to a person and lower the plate after sometime

allbits
05-30-2010, 11:33 PM
Is it that you need to know how to control a servo, or is it that you have a problem driving the servo??

Atleast can you specify which servo you are using??

avinash_g
05-31-2010, 09:37 AM
Look A servo needs 50 hertz signals OK.

The width of the pulse control the angle.

So set up AVR Micros TIMER1 for PWM MODE 14 (Fast PWM with Resolution Governed By ICR1 Register.

Set ICR1 = 1249 (this sets the PWM period = 20ms in 16MHz clock rate and PRESCALER=256)

Now you can generate variable duty cycle by writing to OCR1A and OCR1B registers.

OCR1A=78 will give 0 degree and for each increase in OCR1A will increment servo by 5.76 degrees.

Thats it!

sudarshan
05-31-2010, 09:57 AM
i am using it on portA of the atmega32 because robokits have give servo connetors only on portA will i get the timer output on portA
i am using standard dual ball bearing servo from robokits

avinash_g
05-31-2010, 10:08 AM
If you use the method I told above to KEEP the servo in a locked angle you don't need any CPU power. The TIMER will keep the servo locked!

The CPU is free to do other tasks.

But if you use software to lock servos then 100% of the CPU power goes to lock CPU (unless you use some complex programming).

Thats a foolish thing to do!

PORTA don't have PWM outputs.

:confused: Hey, I feel some kinda fool to help Robokits(Our Competitor!) Customer. :confused:

sudarshan
05-31-2010, 11:49 AM
:confused: Hey, I feel some kinda fool to help Robokits(Our Competitor!) Customer. :confused:

Hey for me only cost matters so i buy from then.if you think you can provide cheaper board ,servos,high torque motorsfor cheaper rates than robokits let me know i will you customer.

if you have any competition with robokits is yours not mine so if you feel i am "Robokits(Our Competitor!) Customer" then dont respond to my posts.....

avinash_g
05-31-2010, 12:48 PM
Heres the code to Control Servos From PWM from TIMER1 Module



#include <avr/io.h>
#include <util/delay.h>

void main()
{
TCCR1A|=(1<<COM1A1)|(1<<COM1B1)|(1<<WGM11);
TCCR1B|=(1<<WGM13)|(1<<WGM12)|(1<<CS11)|(1<<CS10);//PRESCALER=64 MODE 14(FAST PWM)

ICR1=4999; //fPWM=50Hz (Period = 20ms Standard).

DDRD|=(1<<PD4)|(1<<PD5); //PWM Pins as Out

OCR1A=374;
OCR1B=374; //Servos In Neutral Position (90 degree).

//Now you can set OCR1A and OCR1B inbetween 312 and 437 to get
//angles between 0 and 180 degrees

OCR1A=437; //Servo in 180 degree


}



Connect Servo Control Line to OC1A (PD5) PIN (PIN19)

Make sure AVR Fuse is
LOW=0xFF HIGH=C9

And The XTAL is 16MHz

By the way I am not helping you Individually.

I am posting it here so that other RI members and visitors may use it!

sudarshan
05-31-2010, 12:59 PM
thanks avinash_g for the code it was really helpfull
also publish article on you site

avinash_g
05-31-2010, 01:24 PM
Any one know the exact timing for Futaba S3003 ??? I mean the pulse width for 0 90 and 180 degrees ??? And the PWM Period.

In the above Code I have used standard value
Fpwm=50Hz
0 degree=1.25 ms 90 = 1.50ms and 180 = 1.75 ms

avinash_g
06-06-2010, 06:47 PM
See my servo in action

http://www.roboticsindia.com/media.php?do=details&mid=40

sudarshan
06-06-2010, 09:34 PM
hi
i modified my robot by changing the servo control with timer
my robot works fine .
i hope you would publish this article in you webpage to.

thank you,
Sudarshan
robot.superrobot.co.in

allbits
06-06-2010, 10:30 PM
Just to add on,,

IF you are just controlling a couple of servos, a couple of 555s are enough.
A micro is not necessary at all.

avinash_g
06-07-2010, 07:21 PM
i hope you would publish this article in you webpage to.

Hi Guys

I wrote the Servo Motor Control with ATmega32 Tutorial this weekend. Enjoy !
http://extremeelectronics.co.in/avr-tutorials/servo-motor-control-by-using-avr-atmega32-microcontroller/

Hope you find it useful. Don't Forget to leave your replies.