Moving a servo between 2 points
i using adafruit motor shield control small robotics platform, code motors works code servo not stop moving after reaches end of cycle. more specifically, servo stays on, hums loudly because trying overdrive inner workings in either direction depending on way trying drive it.
i need 2 things happen, servo move way 0 , way 180. (standard servo, not continuous)
and
every time power on project servo feels need move position 0. can eliminated servo stays wherever last? if not not big deal previous problem.
press keyboard key 1 0 degrees on servo.
press keyboard key 2 180 degrees on servo.
i have tried changing degree numbers , didn't help, there line of code perhaps supposed added stop servo ?
thanks,
ec7
i need 2 things happen, servo move way 0 , way 180. (standard servo, not continuous)
and
every time power on project servo feels need move position 0. can eliminated servo stays wherever last? if not not big deal previous problem.
code: [select]
#include <afmotor.h> //add support motorshield motor library
#include <servo.h> //add support motorshield servo library
servo myservo; // create servo object control servo (pin10)
af_dcmotor motor1(1, motor12_64khz); // create motor #1, 64khz pwm - right track
af_dcmotor motor2(2, motor12_64khz); // create motor #2, 64khz pwm - left track
af_dcmotor motor3(3, motor12_1khz); // create motor #3, 1khz pwm - tilt camera mount
af_dcmotor motor4(4, motor12_1khz); // create motor #4, 1khz pwm - lights / buzzer (depending on polarity)
void setup() {
myservo.attach(10); // attaches servo1 on pin 10 servo object
serial.begin(9600); // setup serial library @ 9600 bps
}
void loop() {
// read io:
if (serial.available() > 0) {
int inbyte = serial.read();
int speed; // local variable
//motor 1 - low speed - left track
switch (inbyte) {
case 'q':
motor1.setspeed(175);
motor1.run(forward); // motor runs forward
break;
case 'w':
motor1.run(release); // motor stops
break;
case 'e':
motor1.setspeed(175);
motor1.run(backward); // motor runs backwards
break;
//motor 1 - high speed - left track
case 'q':
motor1.setspeed(225);
motor1.run(forward); // motor runs forward
break;
case 'w':
motor1.run(release); // motor stops
break;
case 'e':
motor1.setspeed(225);
motor1.run(backward); // motor runs backwards
break;
//motor 2 - low speed - right track
case 'a':
motor2.setspeed(175);
motor2.run(forward); // motor runs forward
break;
case 's':
motor2.run(release); // motor stops
break;
case 'd':
motor2.setspeed(175);
motor2.run(backward); // motor runs backwards
break;
//motor 2 - high speed - right track
case 'a':
motor2.setspeed(225);
motor2.run(forward); // motor runs forward
break;
case 's':
motor2.run(release); // motor stops
break;
case 'd':
motor2.setspeed(225);
motor2.run(backward); // motor runs backwards
break;
//motor 3 - custom speed - pt cam
case 'z':
motor3.setspeed(125);
motor3.run(forward); // motor runs forward
break;
case 'x':
motor3.run(release); // motor stops
break;
case 'c':
motor3.setspeed(125);
motor3.run(backward); // motor runs backwards
break;
//servo1 - open , close claws
case '1':
myservo.write(0); // closed
break;
case '2':
myservo.write(180); // open
break;
default:
// turn connections off:
(int thispin = 2; thispin < 7; thispin++) {
digitalwrite(thispin, low);
}
}
}
}
press keyboard key 1 0 degrees on servo.
press keyboard key 2 180 degrees on servo.
i have tried changing degree numbers , didn't help, there line of code perhaps supposed added stop servo ?
thanks,
ec7
quote
the servo move way 0 , way 180.
is servo capable of such movement? sounds hitting physical end stops.
Arduino Forum > Topics > Robotics (Moderator: fabioc84) > Moving a servo between 2 points
arduino
Comments
Post a Comment