0

I used a servo as a grabber so I don't know the angle I need specifically.I need it to break the serve.write(angle) when the grabber holds something. I used a simple code

#include <Servo.h>
Servo myservo; 
void setup() {
  myservo.attach(9); 
}
void loop() {
  myservo.write(100);                  
  delay(500);
  myservo.write(50);                  
  delay(500);                           
}

when it holds anything it deos not return to the small angle until I remove the obstacle from its way.

1

You change the angle in small increments until the sensor triggers:

bool closing = false;
bool openeing = false;
int angle;

void loop(){

    //read touchSensor

    if(sensorHit){
        closing  = false;
    }
    if(closing){
        if(angle <= minAngle) closing = false;
        angle -= 1;
        myservo.write(angle);

    }

    if(opening){
        if(angle >= maxAngle) opening = false;
        angle += 1;
        myservo.write(angle);

    }

}

The to start moving the grasper you set opening or closing to true. You can also add some trigger logic in the places where they get set back to false for the next movement if applicable.

  • when I control it manually by joystick, if I hold press a little I can not reverse the angle. I don't use touchSensor. – Mostafa Rady Nov 12 '17 at 19:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.