Servo Motor read position

Dear everyone,

I'm doing my final year project and was wondering whether you could help me out. I'm using a servo-electric gripper as shown below. My aim is to move the gripper manually by hand upwards and downwards and I want the distance between the 2 grippers recorded. Also, I want to set a maximum and minimum distance between the grippers so they won't hit each other. Do you have any idea on how to do that? I was thinking of using servo.read() but not sure how it's going to work.

thinking of using servo.read()

Servo.read() returns the value that was last sent to the servo with Servo.write(). It does not return where the servo is. There is no way to know the position of a standard hobby servo. You tell it where to go, give it enough time to get there and trust that it makes it. To know the position you will need to add a feedback mechanism, like a potentiometer or limit switches.

Thank you so much for replying so fast! So is there no way in knowing where the position of the grippers are? Could I assign a maximum and minimum value distance between the 2 grippers?

Here is a short sketch that allows you to enter an angle in the serial monitor and the servo will move to that angle. You can use it to find the min and max angles. Set the serial monitor baud rate to 9600 and no line endings (see attached image).

#include <Servo.h>

Servo servo;

const byte servoPin = 4;

void setup()
{
  Serial.begin(9600);
  servo.write(90);
  servo.attach(servoPin);

}

void loop()
{
  if (Serial.available())
  {
    int pos = Serial.parseInt();
   // prevent harm to servo from over extension
    if (pos > 180)
    {
      pos = 180;
    }
    if (pos < 0)
    {
      pos - 0;
    }
    servo.write(pos);
  }
}

serial mon.jpg

sgaabdu4:
Thank you so much for replying so fast! So is there no way in knowing where the position of the grippers are?

Do you mean that although you send a command such as myGripperServo.write(75); it is possible that it cannot go that far because of the thing that is being gripped?

If so, I think you will very quickly burn out the motors in your servos.

...R

Yes, don't try to mechnically force the position of hobby servos, they are not designed for it and will
cook themselves.

If you need position feedback, you need something capable of producing position feedback such
as an encoder.

They do make rc servos that have feedback.

1 Like

justone:
They do make rc servos that have feedback.

But that does not mean that they should be programmed to move farther than is possible.

...R

Robin2:
But that does not mean that they should be programmed to move farther than is possible.

...R

What does that have to do with my reply or the link I supplied?

Maybe you should also have added that they should not be powered by the Arduino.

Please advise. Just trying to help.

Robin2:
But that does not mean that they should be programmed to move farther than is possible.

Correct. But it does give you a way to tell if you have asked the servo to travel further than physically possible. That seems like a fairly useful ability to me.

Steve

For what? To prevent toasting the motor? Should each servo command be followed by a check whether the turn was successful, and if not, a counter turn would kick in to place the servo in a reachable position, where the motor is nottoasting itself?

Johan_Ha:
For what? To prevent toasting the motor? Should each servo command be followed by a check whether the turn was successful, and if not, a counter turn would kick in to place the servo in a reachable position, where the motor is nottoasting itself?

If the servo is closing a gripper on an item of unknown size that's an excellent idea. Well thought out.

Steve

justone:
What does that have to do with my reply or the link I supplied?

I was concerned that the OP might interpret your (very correct) reply to mean that he could command a servo to go to (say) 75° and then read the position as 68° because the object in his gripper would not allow the servo to move any further.

...R

Convert a standard hobby servo into one that gives position feedback:
http://forums.trossenrobotics.com/tutorials/how-to-diy-128/get-position-feedback-from-a-standard-hobby-servo-3279/

Thank you so much guys! Really appreciate all the help! I've found out the maximum and minimum position of the servo gripper and now I'm translating it to the actual robot arm gripper so the robot arm gripper will mimic the one from the Servo gripper.