Recent Changes - Search:

TEAMS Academy Wiki

Explore TEAMS!
for visiting sophomores & juniors

Robotics

EnvBioTech

Bat Design

Assistive Tech


Students


Instructors

TEAMS Forum

TEAMS Calendar

TEAMS Web Site

Wiki Info

edit Student.SideBar

DaraEggHuntMainC

/* Add comment

 	- Dara
	- cohort
	- Egghunt
	- jan,10,09
	- decide if the ball capture or not and then if successfully capture bring it to the goal. 
  • /

// Include the Command Module API

  1. include "create.h"
  2. define safe (!cr8->cliff_frontleft && !cr8->cliff_frontright && !cr8->cliff_left && !cr8->cliff_right && !cr8->wheeldrop_left && !cr8->wheeldrop_right && !cr8->wheeldrop_caster)
  3. define unsafe (cr8->cliff_frontleft || cr8->cliff_frontright || cr8->cliff_left || cr8->cliff_right || cr8->wheeldrop_left || cr8->wheeldrop_right || cr8->wheeldrop_caster)

// Pointer to the Sensor Data structure cr8_t *cr8;

// Declare any new function prototypes here: // For example: int dashboard(int counter, char partnumber);

// 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!

  */
  int	time = 0;
	int stop = 3600;

	time = cr8_stopwatch_time();

	cr8_adc_enable(ADC_CENTER_1); // enable right light sensor
	cr8_adc_enable(ADC_CENTER_2); // enable left light sensor
	cr8_adc_enable(ADC_RIGHT_1);
	cr8_adc_enable(ADC_RIGHT_2);


	lcd_set_backlight(255);
	cr8_update(cr8); 
	cr8_stopwatch_start();

	while(cr8_stopwatch_time()<stop && (safe))
	{
		cr8_update(cr8);
		while((safe) && (cr8_stopwatch_time()<stop) && (cr8->adc_right1<305)) // wait for play button to be press 
		{

					cr8_set_leds(1,0,0,255);
					cr8_delay(15);
					cr8_set_leds(0,0,0,255);
					cr8_update(cr8);

					if((time+5 <=cr8_stopwatch_time()))// LCD display = distance and angle

										{
											cr8_update(cr8);
											lcd_print_4vars((cr8->adc_center2),(cr8->adc_center1),(cr8->adc_right1),(cr8->adc_right2),true,false);
											time = cr8_stopwatch_time();
										}  


			while(cr8->adc_right1>305 && (safe) && (!cr8->bumper_right || !cr8->bumper_left)&& (cr8_stopwatch_time()<stop))//keep spinnig until the robot found a light source

			{
				cr8_update(cr8);

				while(((cr8->adc_center1) < 400 || (cr8->adc_center2 ) < 400) &&  (safe))
				{
					cr8_drive_direct(200,-200);
					cr8_update(cr8); 
					if((time+5 <=cr8_stopwatch_time()))// LCD display = distance and angle

										{
											cr8_update(cr8);
											lcd_print_4vars((cr8->adc_center2),(cr8->adc_center1),(cr8->adc_right2),(cr8->adc_right1),true,false);
											time = cr8_stopwatch_time();
										} 

					 while(((cr8->adc_center1) > 350 || (cr8->adc_center2 ) > 350) &&  (safe))// LLS control right wheel, RLS control left wheel. the speed control by the light source(the greater senor value, the faster the speed)

					{
						cr8_set_leds(1,1,0,255);
						cr8_delay(15);
						cr8_drive_direct(-(cr8->adc_center1*4 - cr8->adc_center2),-(cr8->adc_center2*4 - cr8->adc_center1));// driving using the poportion control
						cr8_update(cr8); 

							if((time+5 <=cr8_stopwatch_time()))// LCD display 

										{
											cr8_update(cr8);
											lcd_print_4vars((cr8->adc_center2),(cr8->adc_center1),(cr8->adc_right2),(cr8->adc_right1),true,false);
											time = cr8_stopwatch_time();
										} 




							if(cr8->bumper_left && (safe) && (cr8_stopwatch_time()<stop)) // if left bumper hit back up to the right

								{	
									cr8_update(cr8);
									cr8->dist_mm = 0;
									cr8->dist_m = 0;
									cr8->angle=0;
									cr8_update(cr8);
										while(cr8->angle > -45 && (safe))
										{ 
											cr8_drive_direct(100,-100);
											cr8_update(cr8);

										if((time+5 <=cr8_stopwatch_time()))// LCD display = distance and angle

													{
														cr8_update(cr8);
														lcd_print_4vars((cr8->adc_center2),(cr8->adc_center1),(cr8->adc_right2),(cr8->adc_right1),true,false);
														time = cr8_stopwatch_time();
													}
								}					

										cr8_update(cr8);
								}

						if(cr8->bumper_right && (safe) && (cr8_stopwatch_time()<stop))// if right bumper hit back up to the left

						{	
						cr8_update(cr8);
						cr8->dist_mm = 0;
						cr8->dist_m = 0;
						cr8->angle=0;
						cr8_update(cr8);
							while(cr8->angle < 45 && (safe))
							{ 
								cr8_drive_direct(-100, 100);
								cr8_update(cr8);
								if((time+5 <=cr8_stopwatch_time()))// LCD display = distance and angle

										{
											cr8_update(cr8);
											lcd_print_4vars((cr8->adc_center2),(cr8->adc_center1),(cr8->adc_right2),(cr8->adc_right1),true,false);
											time = cr8_stopwatch_time();
										}  
                            }
					cr8_update(cr8);	
					}
				if(cr8->bumper_right && cr8->bumper_left && (safe) &&  (cr8_stopwatch_time()<stop))// if right bumper hit back up to the left
					{	
						cr8_update(cr8);
						cr8->dist_mm = 0;
						cr8->dist_m = 0;
						cr8->angle=0;
						cr8_update(cr8);
							while(cr8->angle < 180 && (safe))
							{ 
								cr8_drive_direct(-100, 100);
								cr8_update(cr8);

							if((time+5 <=cr8_stopwatch_time()))// LCD display = distance and angle

										{
											cr8_update(cr8);
											lcd_print_4vars((cr8->adc_center2),(cr8->adc_center1),(cr8->adc_right2),(cr8->adc_right1),true,false);
											time = cr8_stopwatch_time();
										} 
                                    }
					}	
					cr8_update(cr8);	

				while(((cr8->adc_center1) >= 500 || (cr8->adc_center2) >= 500) && (cr8->adc_right1 < 305) && (safe) && (cr8_stopwatch_time()<stop)) // when come to close to the light stop, and rotate to score the goal
					{

								cr8_update(cr8);
								cr8->dist_mm = 0;
								cr8->dist_m = 0;
								cr8->angle=0;
								cr8_update(cr8);
								while(((cr8->dist_m)*1000)+(cr8->dist_mm)<400)
								{
									cr8_drive_direct(200,200);
									cr8_update(cr8);

										while(((cr8->dist_m)*1000)+(cr8->dist_mm)>300)
											{
												cr8_drive_direct(0,0);
												cr8_update(cr8);

													if((time+5 <=cr8_stopwatch_time()))// LCD display = distance and angle

												{
												cr8_update(cr8);
												lcd_print_4vars((cr8->adc_center2),(cr8->adc_center1),(cr8->adc_right2),(cr8->adc_right1),true,false);
												time = cr8_stopwatch_time();
												} 
											}	
									if((time+5 <=cr8_stopwatch_time()))// LCD display = distance and angle

										{
											cr8_update(cr8);
											lcd_print_4vars((cr8->adc_center2),(cr8->adc_center1),(cr8->adc_right2),(cr8->adc_right1),true,false);
											time = cr8_stopwatch_time();
										} 
								}	



						cr8_update(cr8);


							cr8_cricket_servo_set(1, 250); 

							cr8_update(cr8);


						if((time+5 <=cr8_stopwatch_time()))// LCD display = distance and angle

										{
											cr8_update(cr8);
											lcd_print_4vars((cr8->adc_center2),(cr8->adc_center1),(((cr8->dist_m)*1000)+(cr8->dist_mm)),((cr8->angle)+((cr8->revolutions)*360)),true,false);
											time = cr8_stopwatch_time();
										}
						} 
                    }
				}
			}
		}	

}

  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...

int xxxxx(int sample_num, char code) {

	// 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:




  //Return int value for function xxxxx: 
  return(1);      You must always return a value to sending program
			--in this case a 1 to indicate fn done with no problems.

} // End of function xxxxx

  • /
Edit - History - Print - Recent Changes - Search
Page last modified on January 26, 2009, at 10:33 PM