/* - Dan Higgins
- Red cohort
- Wimp mode Lab 4
- December 15, 2007
- After being moved the robot will move forward for 600mm unless either bumper is pressed. If a bumper is hit the robot will make a 90 degree turn away from the bump and move 600 mm
// Include the Command Module API
- include "create.h"
// Pointer to the Sensor Data structure
cr8_t *cr8;
// Declare any new function prototypes here:
int rightbump(void);
int leftbump(void);
int reset(void);
// For example: int dashboard(int counter, char partnumber);
uint8_t safe(void)
{
cr8_update(cr8);
// Check for unsafe conditions:
// Wheel Drops
// Cliff Detection
if(cr8->wheeldrop_left || cr8->wheeldrop_right ||
cr8->wheeldrop_caster ||
cr8->cliff_right || cr8->cliff_left ||
cr8->cliff_frontright || cr8->cliff_frontleft)
{
cr8_drive_direct(0,0);
cr8_beep_error();
cr8_set_leds(off,off,255,255);
reset();
return 0;
}
else {
// No unsafe conditions found
return 1;
}
}
// Declare GLOBAL constants used in program:
// Declare GLOBAL Variables used in program:
// Initialize GLOBAL Variables used in program:
// Declaraion for function "main"
int main(void)
{
// Allocate memory for sensor data structure
cr8 = cr8_alloc();
/* Initialize the Create and Command Module
Sync communications settings. */
cr8_init(cr8);
// Declare LOCAL constants used in function main:
// For example: const int Pi100 = 314;
// Declare LOCAL Variables used in function main:
// For example: int i, j;
// Initialize LOCAL Variables used in function main:
// For example: i = 1;
/*
write code for main here!
*/
cr8_update(cr8);
cr8_delay(10);
reset();
while(safe())
{
while(1)
{
while(cr8->dist_mm == 0 && safe()) //while the odometer is equal to zero
{
cr8_set_leds(1,1,0,255);
cr8_cricket_display(cr8->dist_mm,true,false);
cr8_update(cr8);
cr8_delay(10);
}
while(cr8->dist_mm !=0 && safe()) //when the odometer is greater than zero
{
cr8_drive_direct(250,250);
cr8_cricket_display(cr8->dist_mm,true,false);
cr8_update(cr8);
cr8_delay(10);
if(cr8->bumper_right == true && safe()) //turn 90 degrees left and reset
{
rightbump();
reset();
}
else if(cr8->bumper_left == true && safe()) // turn 90 degrees right and reset
{
leftbump();
reset();
}
while(cr8->dist_mm >= 600 && safe())
{
cr8_drive_direct(0,0);
cr8_delay(25);
while(cr8->dist_mm > 0)
{
reset();
cr8_update(cr8);
cr8_cricket_display(cr8->dist_mm,true,false);
}
}
}\\
}
}
cr8_free(cr8);
return(0);
} // End of function main
//Defining Functuons
int rightbump(void)
{
while(cr8->bumper_right == true && safe())//when right bumper is pressed the robot will trun 90 degrees to the left and reset
{
cr8_drive_direct(-250,250);
cr8_cricket_display(cr8->angle,true,false);
cr8_update(cr8);
cr8_delay(10);
cr8_set_leds(0,1,0,0);
}
cr8->angle = 0;
while(cr8->angle < 90 && cr8->bumper_right == false && cr8->bumper_left == false)
{
cr8_drive_direct(-250,250);
cr8_cricket_display(cr8->angle,true,false);
cr8_update(cr8);
cr8_delay(10);
cr8_set_leds(0,1,0,0);
cr8->dist_mm = 0;\\
}
return(1);
}
int leftbump(void)
{
while(cr8->bumper_left == true && safe())//when left bumper is pressed the robot will trun 90 degrees to the right and reset
{
cr8_drive_direct(250,-250);
cr8_cricket_display(cr8->angle,true,false);
cr8_update(cr8);
cr8_delay(10);
cr8_set_leds(0,0,0,255);
}
cr8->angle = 359;
while(cr8->angle > 269 && cr8->bumper_right == false && cr8->bumper_left == false)
{
cr8_drive_direct(250,-250);
cr8_cricket_display(cr8->angle,false,false);
cr8_update(cr8);
cr8_delay(10);
cr8_set_leds(0,0,0,255);
cr8->dist_mm = 0;
}
return(1);
}
int reset(void)
{
cr8->angle = 0;
cr8->dist_mm = 0;
cr8_update(cr8);
cr8_delay(10);
return(1);
}