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

HigginsLab4Code

/* Add comment

     - name
    - cohort
    - assignment
    - date
    - and overview here
  • /

// Include the Command Module API

  1. include "create.h"

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

// Declare any new function prototypes here: // For example: int dashboard(int counter, char partnumber); int reset(void); 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);
        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);
    cr8_adc_enable(ADC_CENTER_1); // distance sensor
    cr8_adc_enable(ADC_RIGHT_1); // distance sensor

  // Declare LOCAL constants used in function main:

      // For example:  const int Pi100 = 314; 

  // Declare LOCAL Variables used in function main:

    int mode = 0;           

  // Initialize LOCAL Variables used in function main:

    // For example:  i = 1;   

  /*

   write code for main here! 

  */
  cr8_update(cr8);
  cr8_delay(10);
  cr8_set_leds(1,0,0,0);                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  while(cr8->button_play == false)
  {
  cr8_update(cr8);
  cr8_delay(10);
  }   


  while(safe())
  {
    reset();

    if (cr8->button_advance)
    {
        mode = (mode + 1) % 2;

        while(cr8->button_advance == true)
        {
            cr8_set_leds(1,1,0,255);
            cr8_update(cr8);
            cr8_delay(10);

        } 
    }
    if (mode)
    {
        cr8_cricket_display(cr8->adc_center1,0,0);
        // left side
    }
    else {
        cr8_cricket_display(cr8->adc_right1,0,0);
        //right side
    }


    if(cr8->adc_center1 >= 250)
    {
        cr8_set_leds(0,0,0,255);
        cr8_drive_direct(50,150);
        cr8_update(cr8);
        cr8_delay(10);

    }
    else if(cr8->adc_center1 <= 100)   
    {
        cr8_set_leds(0,1,0,0);
        cr8_drive_direct(150,50);
        cr8_update(cr8);
        cr8_delay(10);

    }
    else
    {
        cr8_set_leds(1,0,0,0);
        cr8_drive_direct(150,150); 
        cr8_update(cr8);
        cr8_delay(15);
    }   


    while(cr8->adc_right1 >= 250 || cr8->bumper_left == true || cr8->bumper_right == true)
    {

        cr8_set_leds(1,1,0,0); 
        cr8_drive_direct(0,0);
        cr8_delay(500);
        cr8_drive_direct(-50,-50);
        cr8_delay(600);       
        cr8_update(cr8);
        cr8_delay(15);
        cr8_drive_direct(-50,50); 
        cr8_delay(1100);
        reset();
        cr8_update(cr8);
        cr8_delay(15);
    }

  }

  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

  • /

int reset(void) {

 cr8->angle = 0;
 cr8->dist_mm = 0;
 cr8_update(cr8);
 cr8_delay(10);
 return(1);

}

Edit - History - Print - Recent Changes - Search
Page last modified on January 29, 2008, at 06:00 PM