I'm trying to run 4 servo motors from my arduino and i wish them all to rotate clockwise 360 degrees, pause for a few seconds, and then rotate the same amount anti clockwise. I also wish two servos (servo01/02) to delay rotating for a few seconds after servo03/04 have started rotating so that they are slightly behind.
Any advice would be great thanks. I've posted my current script below.
Thanks.
#include <Servo.h>
Servo servo01; // create servo object to control a servo
Servo servo02; // a maximum of eight servo objects can be created
Servo servo03;
Servo servo04;
int pos = 0; // variable to store the servo position
void setup()
{
servo01.attach(3); // attaches the servo on pin 9 to the servo object
servo02.attach(6);
servo03.attach(9);
servo04.attach(11);
}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
servo03.write(pos); // tell servo to go to position in variable 'pos'
servo04.write(pos);
delay(50);
}
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
servo01.write(pos);
servo02.write(pos);
delay(1);
// waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
servo03.write(pos); // tell servo to go to position in variable 'pos'
servo04.write(pos);
delay(1); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
servo01.write(pos); // tell servo to go to position in variable 'pos'
servo02.write(pos);
delay(1);
}
I'm trying to run 4 servo motors from my arduino and i wish them all to rotate clockwise 360 degrees
Lets start with the basics. What kind of devices do you have? Post a link. Typically, a servo can not rotate 360 degrees. Most are limited to 180 degrees. If the servo has been modified for continuous rotation, then it is no longer a servo, in that it can not be commanded to go to a specific position and stay there.
So, it is important to know just what it is we are dealing with, before we can know how to deal with it.
I'd be very suspicious of anything that calls itself a "robot servo".
I think that what you've got there is an ex-servo.
As PaulS said, modded servos are no longer servos and cannot be commanded to a set position without the addition of external hardware like an encoder or a limit switch.
It isn't essential, but useful if comments agree with code:
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 1 degree
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 1 degree
Currently the two pairs of servos rotate at different times which is fine. However, if i set the rotation 'pos' to '180' it rotates fully about 8 times. If I change this number to 90 they rotate about 8 times, pause, and then rotate in the same direction 8 more times. It seems the input rotation angle of '180' doesn't correspond with half a full rotation.
mattmorris_1:
Currently the two pairs of servos rotate at different times which is fine. However, if i set the rotation 'pos' to '180' it rotates fully about 8 times. If I change this number to 90 they rotate about 8 times, pause, and then rotate in the same direction 8 more times. It seems the input rotation angle of '180' doesn't correspond with half a full rotation.
Have you read any of the posts above this?
If the servo has been modified for continuous rotation, then it is no longer a servo, in that it can not be commanded to go to a specific position and stay there.
I'd be very suspicious of anything that calls itself a "robot servo".
I think that what you've got there is an ex-servo.
As PaulS said, modded servos are no longer servos and cannot be commanded to a set position without the addition of external hardware like an encoder or a limit switch.
Do you understand this?
A typical RC servo has a range of motion of about 180 degrees or maybe a little less. It will move to a specified position and stay there.
RC servos that have been modified for continuous rotation can only be commanded to rotate forward, rotate backward and stop. They know nothing of their absolute position, and cannot be made to stop at a specific position without adding additional hardware like an encoder.
I have read all the above posts. I don't know whether it has been modified or not.
Even if I can't tell it to rotate to a certain angle, can I control how long it rotates for? I then wish it to pause for a few seconds and then rotate back the other way. Any idea how this can be done?