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.

asked Nov 12, 2017 at 15:42

1 Answer 1

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.

answered Nov 12, 2017 at 16:09
1
  • when I control it manually by joystick, if I hold press a little I can not reverse the angle. I don't use touchSensor. Commented Nov 12, 2017 at 19:11

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.