Dear Friends,
im new to arduino community, i have quadruped compliant robot as my fyp with 2 degrees of freedom per leg. im having trouble programming my servo motors with arduino Atmega 2560. They have to move in opposite directions at same time. e.g. servo1 90-140 degrees and servo2 90-40 degrees. operating them at the same time is near to impossible for me. kindly assist in the matter. I shall be grateful.
operating them at the same time is near to impossible for me.
That suggests you've tried.
Maybe if we could see the code, we could help.
I deleted your duplicate of this question in another part of the forum.
Awol
This is the first time im posting a problem here, i thought my problem is primarily programming so i should post it there, anyway i just tried the simple sweep by writing both the servos in the same loop and they moved at the same time at same angles. i don't understand how to move them in opposite directions. i have been studying online from quite some time, there are things regarding threading and scheduling, i think scheduling is what is needed but it requires due board as it says for running two parallel loops, kindly help in the matter.
best regards
. i don't understand how to move them in opposite directions.
servo0.write(angle);
servo1.write(180 - angle);
Might be a start.
Servo myservo;
Servo myservo1; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup()
{
Serial.begin(9600);
myservo.attach(9);
myservo1.attach(10); // attaches the servo on pin 9 and 10 to the servo object.
}
void loop()
{
for(pos = 90; pos > 40; pos -=1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos);
myservo1.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 15ms for the servo to reach the position
}
for(pos = 40; pos<=90; pos+=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos);
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 15ms for the servo to reach the position
}
}
I have this code. now both servos will move from 90 to 40 and then back to 90 from 40.
i want one to move from 90 to 40 and other to move from 90 to 140 and back to 90 from 140.
how can this be implemented.
how can this be implemented
Didn't reply #3 give you a clue?
Yes, i understand. thanks a lot.
Can you give me another clue. i shall be grateful.
what if i want the second servo to do it's task earlier than the first servo. how can i implement that.
Best regards
what if i want the second servo to do it's task earlier than the first servo. how can i implement that.
Define what you mean by earlier. How much earlier? Is a week enough?
Paul
I have written this code and uploaded it
But what is required has been attached in the image, how can i achieve that. kindly help.
i have few days left for submission.
#include <Servo.h>
Servo myservo;
Servo myservo1;// create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(1);
myservo1.attach(5); // attaches the servo on pin 9 to the servo object
myservo.write(90);
myservo1.write(90);
}
void loop()
{
for(pos = 90; pos > 40; pos -= 1) // goes from 90 degrees to 40 degrees and the other from 140 to 90
{ // in steps of 1 degree
myservo.write(pos);
myservo1.write(180-pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 40; pos<=90; pos+=1) // goes from 40 to 90 and the other from 90 to 140 degrees
{
myservo.write(pos);
myservo.write(180-pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
} // tell servo to go to position in variable 'pos'
// waits 15ms for the servo to reach the position
}
The clue in reply #3 was just a clue - you need to adapt the arithmetic to suit your application.
I have attached all there is, i just can't figure it out. being new to this i managed to learn quite a bit in few days. i have to make it work by tomorrow. i shall be grateful if you can help me with it. the image says all. just one servo needs to make it back earlier.
i can get it straight.
i can't*
sorry.
what if i want the second servo to do it's task earlier than the first servo. how can i implement that.
If you want a part to move faster or to arrive earlier, then maybe use pos+=2 or pos+=3 for that component.
The for loop has been assigned to both the component doing this will give the increment to both the motors, if we look at the code and thus they will move again at the same speed. achieving movement at the same time.
