- Go forward for 3 seconds
- Roam randomly
- Precision Steering
- Wide turn & Spin
- Turn signals
So far we have only completed the first two steps so our Robot can go forward and then stop after three seconds and then can also roam completely randomly.
For the code we have made three functions:
- Go forward
- Turn right
- Turn left
The go forward function:
//go forward function
int goForward(){
int counter = 0;
int counterFinal = 3000;
boolean breakFunction = false;
while(true){
if(counter<counterFinal){
left.write(180);
right.write(0);
}
if(counter>(counterFinal-1)){
left.write(90);
right.write(90);
break;
}
counter += 1;
delay(1);
}
}
The turn right function:
//turn right function
int turnRight(){
int counter = 0;
int counterFinal = 3000;
boolean breakFunction = false;
while(true){
if(counter<counterFinal){
left.write(180);
right.write(90);
}
if(counter>(counterFinal-1)){
left.write(90);
right.write(90);
break;
}
counter += 1;
delay(1);
}
}
The turn left function:
//turn left function
int turnLeft(){
int counter = 0;
int counterFinal = 3000;
boolean breakFunction = false;
while(true){
if(counter<counterFinal){
left.write(90);
right.write(0);
}
if(counter>(counterFinal-1)){
left.write(90);
right.write(90);
break;
}
counter += 1;
delay(1);
}
}
The main loop:
void loop(){
int randomNumber = random(3);
if(randomNumber == 0){
turnRight();
}
if(randomNumber == 1){
turnLeft();
}
if(randomNumber == 2){
goForward();
}
claw.write(0);
delay(1);
}
The main loop chooses one of three numbers: 0, 1, or 2. Depending on which number it picks the robot will do one of three things: turn right, turn left, or go forward. After completing the function it will repeat this endlessly and become a random roaming robot.
Pictures:
Pictures:
Making a robot like this one is a great way to put together all the things that we have learned in robotics and will help me in the future because it is good practice on how to put all these parts together to make something bigger.
No comments:
Post a Comment