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

MarkLab3Code

Back to Mark's Lab 3

/*
 * Line Follow as Written by Mark Troutt
 */

// Include the Command Module API
#include "create.h"

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

// Main function
int main(void)
{
  // Allocate memory for sensor data structure
  cr8 = cr8_alloc();

  // Initialize the Create and Command Module
  // Sync communications settings.
  cr8_init(cr8);

  // Start Robot Code Here
  //	      ||
  //	     \||/
  //          \/

  while(!trouble()){          //start loop
    cr8_update(cr8);   //update sensors
	cr8_delay(5);

	if(cr8->cliff_frontleft_range <= 800)  //check frontleft sensor for black
	{
	  cr8_drive_direct(0, 40);           //start turning to the left
	  cr8_set_mc_led0(0);                  //tell me with lights what's up
	  cr8_set_mc_led1(1);
	  cr8_delay(5);
	}
	else if(cr8->cliff_frontright_range <= 800)//check frontright sensor for black
	{
	  cr8_drive_direct(40, 0);           //start turning to the right
	  cr8_set_mc_led0(1);                  //tell me with lights what's up
	  cr8_set_mc_led1(0);
	  cr8_delay(5);
	}
	else
	{
	  cr8_drive_direct(100, 100);    //drive straight ahead
	  cr8_set_mc_led0(1);            //tell me what's up with lights
	  cr8_set_mc_led1(1);
	  cr8_delay(5);
	}
  }

  cr8_drive_direct(0, 0);            //Out of loop, stop moving


  // release the sensor data strucutre memory and exit the program
  cr8_free(cr8);
  return 0;
}


//Checks to see if the create should stop
int trouble(void)
{
  int ret = false; //initialize ret and default it to false
  if(cr8->bumper_right || cr8->bumper_left || cr8->cliff_left || cr8->cliff_right || cr8->cliff_frontleft || cr8->cliff_frontright)
  {
    ret = true;  //If in danger, set return to true
  }
  return ret;    //returns ret
}
Edit - History - Print - Recent Changes - Search
Page last modified on February 04, 2008, at 07:25 PM