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

FrancisEggHuntMainC

/* Add comment

 	- francis ambe
	- red cohort
	- wall following
	- date
	- and overview here 
  • /

// Include the Command Module API

  1. include "create.h"
  2. define safe ((cr8->wheeldrop_left==0)&&(cr8->wheeldrop_right==0)&&(cr8->bumper_right==0)&&(cr8->bumper_left==0)&&(cr8->cliff_left==0)&&(cr8->cliff_right==0)&&(cr8->cliff_frontleft==0)&&(cr8->cliff_frontright==0))

// Pointer to the Sensor Data structure cr8_t *cr8; uint16_t time = 0; uint16_t last_val = 0; uint16_t dy_dx = 0; uint8_t stop = 1; // 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);
	cr8_adc_enable(ADC_CENTER_1); // distance sensor
    cr8_adc_enable(ADC_CENTER_2); // light sensor


  // Declare LOCAL constants used in function main:



  // Declare LOCAL Variables used in function main:

  // Initialize LOCAL Variables used in function main:


  /*

   write code for main here!

  */

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


	while((cr8_stopwatch_time()<=5200)&&(safe))
	{
		cr8_cricket_servo_set(0, 200);
	    cr8_update(cr8);
		while((cr8->button_play==0)&&(safe))
		{
			cr8_set_leds(0,0,0,0);
			cr8_delay(100);
			cr8_set_leds(1,0,0,0);
			cr8_update(cr8);

			if(cr8_stopwatch_time() >= (time+2))
			{
				lcd_print_4vars(cr8->adc_center1, cr8->adc_center2, ((cr8->angle)+((cr8->revolutions)*360)), 0, false, false); // display distance sensor
				cr8_update(cr8);
				time = cr8_stopwatch_time();
			}
		}

			while(cr8_stopwatch_time()<=65)
			{
				cr8_drive_direct(-200, -200);
			}

			cr8_update(cr8);
			cr8_cricket_servo_set(0, 200);	
			cr8->revolutions = 0;
			cr8->angle = 0;
			last_val = cr8->adc_center2;
			dy_dx = cr8->adc_center2 - last_val;

		while ((cr8_stopwatch_time() >65))
		{
			while((safe) &&	((cr8->adc_center2) <= 150 )&&((cr8->angle)+((cr8->revolutions)*360)) <= 360)
			{		
				cr8_beep_error();
				cr8_drive_direct(-100 , 100);
				if(cr8_stopwatch_time() >= (time+2))
				{
					lcd_print_4vars(cr8->adc_center1, cr8->adc_center2,((cr8->angle)+((cr8->revolutions)*360)) , 0, false, false);
					time = cr8_stopwatch_time();
				}
				cr8_delay(50);
				cr8_update(cr8); 	
			}

			while(((cr8->adc_center2) >= 150 )&&((cr8->adc_center2) <= 350 ))
			{
				cr8_drive_direct(-200 , -200);	
				cr8_update(cr8);
			}
				if(cr8->adc_center2 > 350)
				{				
					cr8_drive_direct(0,0);
					cr8_cricket_servo_set(0, 80);					
				}

		}	

		cr8->revolutions = 0;
		cr8->angle = 0;

		if(((cr8->adc_center1) <= 200)&&((cr8->angle)+((cr8->revolutions)*360)) <= 180)
		{
			cr8_drive_direct(-100 , 100);
		}

			while(!safe)
			{
				if(cr8_stopwatch_time() >= (time+2))
				{
					lcd_print_4vars(cr8->adc_center1, cr8->adc_center2, ((cr8->angle)+((cr8->revolutions)*360)), 0, false, false); 
					cr8_update(cr8);
					time = cr8_stopwatch_time();
				}
					cr8_drive_direct(0, 0);
					cr8_beep_error();
					cr8_set_leds(0, 0, 255, 255);
					cr8_delay(100);
					cr8_set_leds(0, 0, 255, 0);
					cr8_update(cr8);
			}
	}


 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 22, 2009, at 09:24 PM