|
Explore TEAMS!
|
Student /
EggHuntMain/* Add comment - Christropher Ghadban && Max Sacoccio - Red cohort - Practice C/C++ Program - December 9th, 2008 - OVERVIEW: 1. Choose a ball color with advance(yellow) and play(blue). 2. Lift the trap. 3. Use camera to find a ball. 4. Drive to and center trap above ball. 5. Drop trap. 6. Use camera to find the lights and drive to them. 7. Lift the trap and push the ball in the goal in a set programmed sequence. 8. Repeat until to f "our" balls have been scored. 9. Search for enemy balls and collect them.
// Include the Command Module API #include "create.h" #define safe ((!cr8->cliff_left) && (!cr8->cliff_frontleft) && (!cr8->cliff_frontright) && (!cr8->cliff_right) && (!cr8->wheeldrop_right) && (!cr8->wheeldrop_left) && (!cr8->wheeldrop_caster)) #define unsafe ((cr8->cliff_left) || (cr8->cliff_frontleft) || (cr8->cliff_frontright) || (cr8->cliff_right) || (cr8->wheeldrop_right) || (cr8->wheeldrop_left) || (cr8->wheeldrop_caster)) #define lightfound ((cr8->adc_right1 <= 250) || (cr8->adc_right2 <= 250)) //normal value for light sensor values. #define onefoot ((((cr8->dist_m * 1000) + (cr8->dist_mm)) >= 0) && (((cr8->dist_m * 1000) + (cr8->dist_mm)) <= 320)) #define close ((cr8->adc_right1 >= 300) || (cr8->adc_right2 >= 300)) // the robot is 30 or so cm away. // Pointer to the Sensor Data structure cr8_t *cr8; // Declare any new function prototypes here: // For example: int dashboard(int counter, char partnumber); void resetodo(void); void displayvalues(void); void lifttrap(void);// merely lifts the trap. void findball(void);// find ball includes centering on the ball. void droptrap(void);//just drops the trap. void findlights(void);//finds the lights and drives to them. void score/retreat(void);//as name suggests/backs up and gets ready to start again. // Declare GLOBAL constants used in program: // Declare GLOBAL Variables used in program: // Initialize GLOBAL Variables used in program: // Declaration 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:
const uint8_t red = 255;
const uint8_t bright = 255;
// Declare LOCAL Variables used in function main:
uint8_t toggle;
uint16_t time;
uint8_t x;
// Initialize LOCAL Variables used in function main:
toggle = 0;
time = cr8_stopwatch_time();
cr8_adc_enable(ADC_CENTER_1); // light sensor1
cr8_adc_enable(ADC_CENTER_2); // light sensor2
// main program...
//holds main loop together
while(!time > 900)
{
lcd_set_backlight(bright);
cr8_update(cr8);
displayvalues();
//play and advance buttons blink until one is pressed.
while((!cr8->button_play) && (!cr8->button_advance) && (safe) && (!time > 900))
{
cr8_set_leds((toggle%2), (toggle%2), off, bright);
toggle++;
cr8_update(cr8);
lcd_print_4vars((cr8->adc_right1),(cr8->adc_right2),(cr8_stopwatch_time()),0, true, false);
cr8_delay(2);
}
if(cr8->button_play)
{
x == 0;
for(x = x; x <= 3 ; x = x + 1) // increases speed of create to 200 mm/sec in about three seconds.
{
cr8_update(cr8);
lifttrap();// merely lifts the trap.
findball();// find ball includes centering on the ball.
droptrap();//just drops the trap.
findlights();//finds the lights and drives to them.
score/retreat();//as name suggests/backs up and gets ready to start again.
if((unsafe) || (time > 900)) // ensures necessary conditions are met while in for loop.
{
break; // if any conditions are met the for loop is broken.
}
}
}
if(cr8->button_advance)
{
x == 0;
for(x = x; x <= 3 ; x = x + 1) // increases speed of create to 200 mm/sec in about three seconds.
{
cr8_update(cr8);
lifttrap();// merely lifts the trap.
findball();// finds ball using camera, includes centering on the ball.
droptrap();//just drops the trap.
findlights();//finds the lights and drives to them.
score/retreat();//as name suggests/backs up and gets ready to start again.
if((unsafe) || (time > 900)) // ensures necessary conditions are met while in for loop.
{
break; // if any conditions are met the for loop is broken.
}
}
}
/* while((unsafe) && (!time > 900)) {
cr8_update(cr8);
cr8_drive_direct(0, 0);
displayvalues();
cr8_set_leds(off, off, red, off);
cr8_set_leds(off, off, red, bright);
cr8_delay(10);
resetodo();
}
} cr8_free(cr8); return(0); } // End of function main /* Declare other functions you create here... For example, to define function xxxxx of type integer (int) with two input parameters, sample_num and code...
void resetodo(void) { // Declare LOCAL constants used in function xxxxx:
// Declare LOCAL Variables used in function xxxxx:
// Initialize LOCAL Variables ised in function xxxxx:
// Write code for function XXXXX here:
cr8_update(cr8);
cr8->dist_mm = 0;
cr8->dist_m = 0;
cr8->angle = 0;
cr8->revolutions = 0;
cr8_update(cr8);
//Return int value for function xxxxx:
return;
} // End of function resetodo /*Declare other functions you create here... For example, to define function xxxxx of type integer (int) with two input parameters, sample_num and code...
void displayvalues(void) { // Declare LOCAL constants used in function main: // Declare LOCAL Variables used in function main: // Initialize LOCAL Variables used in function main: // Write code for function servo here: lcd_print_4vars((cr8->adc_right1),(cr8->adc_right2),(cr8_stopwatch_time()),0, true, false); //cr8_delay(2); //Return int value for function xxxxx: return; } // End of function displayvalues // Declare other functions you create here... void displayvalues(void); //with two input parameters, sample_num and code... void lifttrap(void) { // Declare LOCAL constants used in function main:
// Declare LOCAL Variables used in function main:
// Initialize LOCAL Variables used in function main:
cr8_adc_enable(ADC_CENTER_1); // light sensor1
// Write code for function lifttrap here:
cr8_cricket_servo_set(0,-50);
displayvalues();
//Return int value for function xxxxx:
return;
} // End of function lifttrap // Declare other functions you create here... void displayvalues(void); //with two input parameters, sample_num and code... void findball(void) { // Declare LOCAL constants used in function main: // Declare LOCAL Variables used in function main: uint16_t time; // Initialize LOCAL Variables used in function main: time = cr8_stopwatch_time(); // Write code for function findball here: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX //Return int value for function xxxxx:
return;
} // End of function findball // Declare other functions you create here... void displayvalues(void); //with two input parameters, sample_num and code... void droptrap(void) { // Declare LOCAL constants used in function main:
// Declare LOCAL Variables used in function main:
// Initialize LOCAL Variables used in function main:
cr8_adc_enable(ADC_CENTER_1); // light sensor1
// Write code for function droptrap here:
cr8_cricket_servo_set(0,0);
displayvalues();
//Return int value for function xxxxx:
return;
} // End of function droptrap // Declare other functions you create here... void displayvalues(void); //with two input parameters, sample_num and code... void findlights(void) { // Declare LOCAL constants used in function main: // Declare LOCAL Variables used in function main: uint16_t time; // Initialize LOCAL Variables used in function main: time = cr8_stopwatch_time(); // Write code for function findlights here: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX //Return int value for function xxxxx:
return;
} // End of function findlights // Declare other functions you create here... void resetodo(void); void displayvalues(void); //with two input parameters, sample_num and code... void score/retreat(void) { // Declare LOCAL constants used in function main:
// Declare LOCAL Variables used in function main:
// Initialize LOCAL Variables used in function main:
time = cr8_stopwatch_time();
cr8_adc_enable(ADC_CENTER_1); // light sensor1
cr8_adc_enable(ADC_CENTER_2); // light sensor2
// Write code for function score/retreat here:
//Return int value for function xxxxx:
return;
} // End of function score/retreat
|