Society of Robots - Robot Forum
Software => Software => Topic started by: Hasan999 on December 19, 2009, 09:21:23 AM
-
Ok fine, I'm a beginner, but seriously, WTH ?... why is it not as simple as Servo(PORTA,1,90) <--where Servo at A1 turns 90 degrees.
I don't really know what is Duty cycle, PWM etc etc... [I bought Axon Microcontroller just because it said, "extensive source code and tutorials have been developed to make it easy enough for a beginner" - so I thought I would not need to understand the theories]
I know C programming, but this is getting too confusing just to program a servo to turn exactly 90 degrees everytime.
Can someone PLEASE show me a (working) sample program to rotate a Servo at A1, 90 degrees clockwise and then 90 degrees anti-clw with a delay of 1 second in between ?
Thanks a lot !!
-
Well, you will always need to understand the theory.
This should help you learn it fast:
http://www.societyofrobots.com/axon/axon_function_list.shtml#hardware_defines (http://www.societyofrobots.com/axon/axon_function_list.shtml#hardware_defines)
http://www.societyofrobots.com/axon/axon_function_list.shtml#servo_centering (http://www.societyofrobots.com/axon/axon_function_list.shtml#servo_centering)
http://www.societyofrobots.com/actuators_servos.shtml (http://www.societyofrobots.com/actuators_servos.shtml)
Every servo is different, so there is no universal command to make a servo go to an exact angle. You send a square wave, and the servo moves to a particular angle. You'll have to experiment to find with square wave pulse width gives the angle you want.
Here is some sample code close to what you want:
//PWM a pulse
for(uint16_t i=0;i<65500;i++)
{
servo(PORTH,2,900);
delay_ms(20);
}
//delay for 1s
delay_ms(1000);
//PWM another pulse
for(uint16_t i=0;i<65500;i++)
{
servo(PORTH,2,300);
delay_ms(20);
}
-
Thanks a lot Admin...
I still don't understand the theories lol ;D... but Thanks for the sample code...
I used "Trial and Error" method to:
Make Servo Center
Rotate Servo 90º Left
Servo Center
Rotate Servo 90º Right
Servo Center
(each with a delay of 1 second)
It is for HS-422 Servo (using Axon Microcontroller)
Here is the precise program [Pin E4]:
(I'm posting for OTHER lazy newbies like me, who just wants to get started without doing a PhD in Controlling Servos)
for (uint16_t i=0 ; i<15 ; i++)
{
servo(PORTE,4,700); //CENTER
delay_ms(20);
}
delay_ms(1000);
for (uint16_t i=0 ; i<15 ; i++)
{
servo(PORTE,4,285); //LEFT
delay_ms(20);
}
delay_ms(1000);
for (uint16_t i=0 ; i<15 ; i++)
{
servo(PORTE,4,700); //CENTER
delay_ms(20); }
}
delay_ms(1000);
for (uint16_t i=0 ; i<15 ; i++)
{
servo(PORTE,4,1115); //RIGHT
delay_ms(20);
}
delay_ms(1000);
for (uint16_t i=0 ; i<15 ; i++)
{
servo(PORTE,4,700); //CENTER
delay_ms(20);
}
//Note: Difference in DurationCycle for 90º is 415
//That means: left-center-right: 285-700-1115
//Could also be: left-center-right: 265-680-1095
Thanks Admin :)