2

My assignment is to design and implement software to cause your Shield-Bot to run continuously in a “figure 8” where the two loops are at least 1 foot in diameter.

I have put the following code together, which makes a figure 8 correctly the first time, but then after each rotation around it slowly loses form. I need each rotation the same way.

#include <Servo.h>

//declare servo motor variables
Servo leftServo;
Servo rightServo;

void loop() {
   //assign i/o pins to servo
  leftServo.attach(13);
  rightServo.attach(12);
  //Declare values for the first circle
  int leftFirtCirlceSpeed=1548;
  int rightFirstCircleSpeed=1300;

  //send pulse to each servo motor. Servo circles
  leftServo.writeMicroseconds(leftFirtCirlceSpeed);
  rightServo.writeMicroseconds(rightFirstCircleSpeed);
  delay(13000);

  //declare left/right servo int and assign these variables the pulse width so that the servo stops
  //int leftStop = 1500;
  //int rightStop = 1500;

  //send pulse to each servo motor. Servo stops
  //leftServo.writeMicroseconds(leftStop);
  //rightServo.writeMicroseconds(rightStop);
  //delay(100);

   //declare left/right servo int and assign these variables the pulse width so that the servo goes straight
  int leftStraight = 1700;
  int rightStraight = 1300;

  //send pulse to each servo motor. Servo goes straight
  leftServo.writeMicroseconds(leftStraight);
  rightServo.writeMicroseconds(rightStraight);
  delay(2000);

  //Declare values for the second circle
  int leftSecondCircleSpeed = 1700;
  int rightSecondCircleSpeed = 1458;

  //send pulse to each servo motor. Servo circles
  leftServo.writeMicroseconds(leftSecondCircleSpeed);
  rightServo.writeMicroseconds(rightSecondCircleSpeed);
  delay(9000);

  //leftServo.writeMicroseconds(leftStop);
  //rightServo.writeMicroseconds(rightStop);
  //delay(100);

  //send pulse to each servo motor. Servo goes straight
  leftServo.writeMicroseconds(leftStraight);
  rightServo.writeMicroseconds(rightStraight);
  delay(2000);
}
dda
  • 6,030
  • 2
  • 25
  • 34
familyGuy
  • 425
  • 2
  • 5
  • 22
  • Your best bet is to just trial and error it out. Too many things can go wrong with servos. – user2309843 Jun 13 '17 at 19:09
  • 1
    Yea, you are right! I thought there might be some magic number. let me give another try-Thanks! – familyGuy Jun 13 '17 at 19:13
  • 1
    @familyGuy *imho*, one should design some sort of **feedback-loop**, possibly involving sensors, otherwise any tiny error is going to be magnified through time due to accumulation. – Patrick Trentin Jun 14 '17 at 13:04

0 Answers0