我的任务是设计和实施软件,使您的 Shield-Bot 在“数字 8”中连续运行,其中两个回路的直径至少为 1 英尺。
我把下面的代码放在一起,第一次正确地制作了一个数字 8,但是在每次绕它旋转之后慢慢地失去形式。我需要以相同的方式进行每次旋转。
#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);
}