Hello all,
I am currently on my project that utilises two servo based robotic arm(DC servo motors mg95).
The thing i want to attain is to control the servo arms by the principle of shadowing technique(possible synchro kind of approach where u move one arm and the other arm moves according to the position obtained by the arm).
clearly saying,
There is one arm(dummy), and another arm (actual arm).
So i set a posture on the dummy arm , the position is sent to the actual arm and is attains the position we set on the dummy arm.
In case if the second arm cannot attain the exact position, the position thus attained in the second arm is then transferred back to the dummy arm and the dummy corrects itself to the position attained by the actual arm, so as to maintain the same posture.
So I tried this using just two servos, and stuck on the way…
Here are my procedures followed and progress>
-
Understood that servo motor does not give position output initially(although it can give the value which is previously written, not the angle attained by the motor), so i have soldered a terminal out of the servos potentiometer wiper pin and took out to connect to arduinos analog pin.
-
so here is the code i used to try initially,
#include <Servo.h>//servo library
Servo myservo1; // create servo object to control a servo
Servo myservo2; // create servo object to control a servo
int potpin1 = A0; // analog pin used to connect the potentiometer of servo 1
int potpin2 = A1; // analog pin used to connect the potentiometer of servo 2
int val1; // variable to read the value from the analog pin
int val2;// variable to read the value from the analog pin
//int ang=0;//
void setup()
{
Serial.begin(9600);
myservo1.attach(9); // attaches the servo on pin 9 to the servo object
myservo2.attach(10);
}
void loop()
{
// myservo1.attach(9);
val1=analogRead(potpin1); //read the angle information of first servo
val1=constrain(val1,54,593); // since servo 0 degree gives analogvalue 54, i constrained it to the range 0=54,180=593
val1=map(val1,54,593, 0,180); //mapped the constrained values into degree form
myservo2.write(val1); //write the maped degree values to the second servo
delay(500); //wait till the servo attains the position
val2=analogRead(potpin2); //read the angle information of second servo
val2=constrain(val2,54,593);
val2=map(val2,54,593, 0,180);
myservo1.write(val2); //write the value to the first servo (incase if the second servo cannot attain the desired angle)
delay(500); // delay to wait for the servo reach the position
//myservo1.detach();
//Serial.print("Servo 1 angle info");
//Serial.print(ang);
//Serial.print("degrees");
//Serial.print("Potentiometer");
//Serial.println(val1);
//Serial.print("Servo 2 angle info");
//Serial.print(ang);
//Serial.print("degrees");
//Serial.print("Potentiometer");
//Serial.println(val2);
//delay(1000);
}
well the code gets compiled and uploaded successfully, and servos seems working fine, coz the angle is same on the both servos.
The problem i face here is i cannot set the angle on the first servo, by moving its knob, it seems pretty hard to move.
The thing which gives me a bit of happiness is that with power off condition i can move the servo knob , and as soon as the power is on , it maintains the exact position on both the servos.
Pls give your suggesstion to make my project work.