Skip to content
This repository has been archived by the owner on Jul 31, 2022. It is now read-only.

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Gron1275 authored Oct 28, 2018
1 parent 29b4869 commit 65f4889
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions Grenan/Roomba2 with working randomizer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#pragma config(Sensor, dgtl12, bowBump, sensorTouch)
#pragma config(Sensor, dgtl3, ledINIT, sensorLEDtoVCC)
#pragma config(Sensor, dgtl6, led2, sensorLEDtoVCC)
#pragma config(Sensor, dgtl9, led3, sensorLEDtoVCC)
#pragma config(Motor, port6, starboardFWD, tmotorServoContinuousRotation, openLoop)
#pragma config(Motor, port7, starboardBACK, tmotorServoContinuousRotation, openLoop)
#pragma config(Motor, port8, portFWD, tmotorServoContinuousRotation, openLoop)
#pragma config(Motor, port9, portBACK, tmotorServoContinuousRotation, openLoop)
/*
Project Title: Roomba
Team Members: Grennon, Kyle, Pat, Buddy
Date: 10/22/2018
Section: Block C
Task Description: Make a roomba that turns when it hits stuff
Pseudocode:
Make the robot move forward until bowBump is pressed
Then have the code move robot backwards and spin for an amt of time that is determined by a wait comand with a random Int inside of it
We might put it in a while loop this way it runs contunuiously
*/

void motorStop(){
stopMotor(portBACK);
stopMotor(starboardBACK);
stopMotor(starboardFWD);
stopMotor(portFWD);
}
void backOff(){
int left_or_right;
left_or_right = rand() % 2;
motorStop();
wait(0.5);
startMotor(portFWD, 43);
startMotor(portBACK, 43);
startMotor(starboardFWD, -42);
startMotor(starboardFWD, -42);
wait(1);
motorStop();
if(left_or_right == 0){
startMotor(portFWD, -43);
startMotor(portBACK, -43);
startMotor(starboardFWD, -42);
startMotor(starboardFWD, -42);
wait(2);
motorStop();

}
if(left_or_right == 1){
startMotor(portFWD, 43);
startMotor(portBACK, 43);
startMotor(starboardFWD, 42);
startMotor(starboardFWD, 42);
wait(2);
motorStop();
}

}

task main(){
wait(5);
while(1 == 1){
startMotor(portFWD, -43);
startMotor(portBACK, -43);
startMotor(starboardFWD, 42);
startMotor(starboardFWD, 42);

if(SensorValue[bowBump] == 1){
backOff();

}
}
}

0 comments on commit 65f4889

Please sign in to comment.