Controlling Servo motor with a position attained by another servo motor(mirror)

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>

  1. 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.

  2. 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.

The problem is that you and the servo are both trying to control the dummy arm. The servo is trying to hold position while you are trying to change position. One way to fix that is to add a button that tells the Arduino to 'detach' the dummy servo to allow manual control. When you are done positioning the dummy (and thus 'actual') arms you release the button causing the Arduino to re-attach the dummy servo and hold position. One problem with that is that the servo won't be able to provide you with force feedback when the actual arm hits an object. Maybe the servo should re-attach if the dummy servo gets too far ahead of the actual servo.

It is more common to use the terms 'master' and 'slave' rather than 'dummy' and 'actual'.

It is possible to break a powered servo by forcing the arm, and you certainly can’t read out the arm position.

Instead, for a position sensor, use a potentiometer in a voltage divider with an arm connected to the potentiometer shaft. You can read the shaft position with analogRead().

jremington:
Instead, for a position sensor, use a potentiometer in a voltage divider with an arm connected to the potentiometer shaft. You can read the shaft position with analogRead().

I believe the OP has modified his servo so the Arduino can read its internal potentiometer.

…R

Yes, I saw that the OP had modified the servo, but it is still powered. That will not work, because the pot is used (in many cases) to charge a capacitor for the feedback pulse timing.

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

@jremington

yeah you are right, and i got that when i executed it first>, but the thing i need is that i want to move the master(in my case dummy), and the slave(actual) should move according to it. the only way to move is that i found the voltage given to the motor inside the servo should be reduced, so that thte torque developed will be reduced which in further can make us to move the arm>>
Am i right???

@jremington
i tried detaching the servo in program while giving power to the servo, but still i cant change its orientation, coz the last sent value is stored in some kind internally and maintains its angle even i unplug the signal pin of the servo from the arduino.
may be its due the capcitor which u said>>
i wonder removing that capacitor would do the trick???

@jremington
so in case if i want to remove the capacitor , to stop maintaining the feedback pulse, which one should i remove?? here is the attached image of the circuit of servo

DSC_0034[1].jpg

I really don't think your idea will work. You can read out the pot of an unpowered servo, just remove all the other electronics.

How will you know that the slave can't reach the desired position?

no jremington, i think u didnot get my point, the posture of the master and slave arms should be maintained, and in addition the master arm should also accept the angular info given by the user, so in order to maintain the posture the master arm should also be equipped with servo right??

also i m thinking of keeping this part aside> and implementing the new idea of adding a button and a multiple turns pot, to give a angle manually to controll the master posture, which in changes the posture of the slave, and the program already given will maintain the postures ??

may be this will help???

I got your point, and don't see how you can make it work.

@OP
If I understand it well the arms are working but you cannot move the Master because it is too strong. What if you make the Master's servo weaker? Somethink like adding resistor between motor and power in Master's servo? I think it should be possible to make the servo weak enough you can move the Master easily but if noone touches it the Master will keep the Slave's position.

I think the system will need to be a great deal more sophisticated to achieve what you are describing.

I reckon the master unit needs some sort of force sensors that automatically depower its servos when you try to move the arm of the master. And I don't think hobby servos are the appropriate devices for that role - that is not what they are designed for.

Perhaps you could replace the electronics with a hobby servo to provide more functionality. An Arduino should be perfectly suitable for that job if it is equipped with a h-bridge to control the motor and suitable PID code to govern the positioning.

...R

You might consider a “haptic knob” which provides force feedback. Here is an overview. In your case the knob could be driven by a DC motor/encoder combination that would provide force feedback and position information independently.

However, you still have the problem that you don’t know what the slave servo is actually doing:

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

jremington:
I really don't think your idea will work. You can read out the pot of an unpowered servo, just remove all the other electronics.

There's no need to remove any electronics or unpower the servo. It just needs to be detached, ('servo.detach()'), to move the mechanism manually.
adafruit sell servos that have a wire added to the pot wiper. It appears to work well, and the voltage can be directly read with 'analogRead()' for recording or whatever.

adafruit:
It looks like a servo, it acts like a servo, but it's more than just a servo! We got a factory to custom-make these classic 'standard' sized hobby servos with a twist - the feedback (potentiometer wiper) line is brought out to a fourth white wire. You can read this wire with an analog input such as those on an Arduino, to get the servo's position. That information can be used in robotics to improve stability or even allow 'recording' of servo motion.

More info and a video here:- Analog Feedback Servo