Recent Changes - Search:

TEAMS Academy Wiki

THS

Explore TEAMS!
for visiting sophomores & juniors


Robotics


EnvBioTech

Bat Design

Assistive Tech

Students

Instructors

TEAMS Forum

TEAMS Calendar

TEAMS Web Site

Wiki Info

edit Robots.SideBar

HuntMurphyMainC

*/
// Include the Command Module API
#include "create.h"
#define safe ((!cr8->wheeldrop_right) || (!cr8->wheeldrop_left) || (!cr8->wheeldrop_caster) || (!cr8->cliff_left) || (!cr8 ->cliff_right) || (!cr8->cliff_frontleft) || (!cr8 ->cliff_frontright))
#define intime (cr8_stopwatch_time() < 3600)
// Pointer to the Sensor Data structure
cr8_t *cr8;
// Declare any new function prototypes here:

void findballs (void); // find balls

	void pickdrop (int color); // pick drop and make sure the correct color ball was found
        void checkcolor (int color); // pick drop and make sure the correct color ball was found
        void findlight (void); // find the net by finding the light 
	void rightbumper(void); // spin 90 degrees away from right bumper when right bumper is pressed  
	void leftbumper (void); // spin 90 degrees away from left bumper when left bumper is pressed
	void controlarm_up (void); // find balls 
        void reset_odometer(void); // reset odometer
	void spin (int l, int r); // Declare GLOBAL constants used in function main:
        void blink_display(int dvar1, int dvar2, int dvar3, int dvar4); // display important information 


// For example: int dashboard(int counter, char partnumber);
// Declare GLOBAL constants used in program:
const uint8_t red =255;

	const uint8_t green =0;


// Declare GLOBAL Variables used in program:
// Initialize GLOBAL Variables used in program:

		    uint16_t color1 = 0;
		uint16_t color2 = 0;
		uint8_t toggle = 0;
		uint8_t timer =0;
		uint16_t time =0;
		uint16_t lightmeter = 0; 
		uint16_t bluelow = 8;
		uint16_t bluehigh = 66;
                uint16_t yellowlow = 60;
		uint16_t yellowhigh = 110;
		uint8_t asrg;

// Declaraion for function "main"
int main(void) {
cr8_adc_enable(ADC_CENTER_1);

	cr8_adc_enable(ADC_CENTER_2);
	cr8_adc_enable(ADC_LEFT_1);
  // 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_stopwatch_start();
   while(intime)
	{
	 controlarm_up();
	 cr8_update(cr8);
	 cr8_set_leds(1,1,0,255);
	 if(cr8->button_play)
		{
		 cr8_set_leds(1,0,0,255);
		 while(intime)
			{
			 color1=bluelow;
			 color2=bluehigh;
			 cr8_update(cr8);
			 while((cr8->adc_left2 < color1) || (cr8->adc_left2 >color2))
			        {
			         cr8_update(cr8);
			         findballs();
			         pickdrop();
			         checkcolor(color1, color2);
			        }
			 findlight();
			 pickdrop();
			 cr8_update(cr8);
			}
		}
	 if(cr8 -> button_advance)
		{
		 cr8_set_leds(0,1,0,255);
		 while(intime)
			{
			 color1=yellowlow;
			 color2=yellowhigh;
			 cr8_update(cr8);
			 while((cr8->adc_left2 < color1) || (cr8->adc_left2 >color2))
			        {
			         cr8_update(cr8);
			         findballs();
			         pickdrop();
			         checkcolor(color1, color2);
			        }
			 findlight();
			 pickdrop();
			 cr8_update(cr8);
			}
		}
	 cr8_update(cr8);
	}
  cr8_free(cr8);
  return(0);

} // End of function main
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
\\ Functions that are used by two or more main functions

// while right bumper pressed turn CCW. Once the bumper is released the cr8 turns CCW.
void rightbumper(void)

	{
	 cr8_set_mc_led0(0);// turns off left cm led
	 cr8_set_mc_led1(1);// turns on right cm led
	 // turn CCW
	 while ((cr8 -> bumper_right) && (!cr8->bumper_left) && (safe) && (cr8_stopwatch_time() < time))
		{
		 blink_display(cr8 -> adc_center2, 0, cr8 -> angle, cr8_stopwatch_time());
		 cr8_drive_direct(-250,250);
		 cr8_update(cr8);
		}
	 reset_odometer();
	 // drive CCW a half turn 
	 while ((cr8 -> angle < 45) && (!cr8 -> bumper_right) && (!cr8 -> bumper_left) && (safe) && (cr8_stopwatch_time() < time))  
		{
		 blink_display(cr8 -> adc_center2, 0, cr8 -> angle, cr8_stopwatch_time());
		 cr8_drive_direct(-250,250);
		 cr8_update(cr8);
		}
	 cr8_update(cr8);
	 reset_odometer();
	 return;
	}



// While left bumper is pressed turn CW. Once released create turns CW.
void leftbumper(void)

	{
	 cr8_set_mc_led0(1); // turns on left cm led
	 cr8_set_mc_led1(0); // turns off right cm led
	 // turn CW
	 while ((cr8 -> bumper_left) && (!cr8->bumper_right) && (safe) && (cr8_stopwatch_time() < time))  
		{
		 blink_display(cr8 -> adc_center2, 0, cr8 -> angle, cr8_stopwatch_time());
		 cr8_drive_direct(250,-250);
		 cr8_update(cr8);
		}
	 reset_odometer();
 	 // turn create CW half turn
	 while ((cr8->angle>-45)&&(!cr8->bumper_right)&&(!cr8->bumper_left)&&(safe)&&(cr8_stopwatch_time()<time))                          
		{
		 blink_display(cr8 -> adc_center2, 0, cr8 -> angle, cr8_stopwatch_time());
		 cr8_drive_direct(250,-250);
		 cr8_update(cr8);
		}
	 cr8_update(cr8);
	 reset_odometer();
	 return;
	}


// display important information on the create.
void blink_display(int dvar1, int dvar2, int dvar3, int dvar4)

	{
	 if (cr8_stopwatch_time() >= time + 3)
		{
		 lcd_print_4vars(dvar1, dvar2, dvar3, dvar4, true, false);
		 time = cr8_stopwatch_time();
		 cr8_set_leds(0,togglegreen%2,0,255);
		 toggle++;
	     cr8_update(cr8);
		}
	 return; 
	}

// resets values of odometer. Sets time, toggle and angle to zero.
void reset_odometer (void)

	{
	 cr8_update(cr8);
	 time = 0;
	 toggle = 0;
	 cr8 -> angle = 0;
	 cr8_update(cr8);
	 return; 
	}

// lift the contraption up
void controlarm_up(void)

	{
	 cr8_cricket_servo_set(1, 0);
	 cr8_delay(1000);
	 cr8_cricket_servo_set(0, 120);
	 return;
	} 


_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
HuntMurphyFindballs // find any color ball on the field
HuntMurphyPickDrop // capture and move the ball to the right side of the create
HuntMurphyCheckColor// check to make sure that the correct color ball was captured
HuntMurphyFindlight// find the net by finding light

Edit - History - Print - Recent Changes - Search
Page last modified on January 22, 2009, at 08:25 AM