|
Explore TEAMS!
|
Student /
AboutJoninfo below ->Hello, name is Jonathan Hohrath. I am a senior at chelmsford high this year. My favorite subjects are, as you might have guessed, math and science. Other than teams academy, classes that i am taking are Studio art 2, Writing for college, and AP Calculus. After school i run on the varsity crosscountry team. My favorite things to do when i get home is eating, playing video games, hanging out with my friends, and playing sports like soccer and frisbee. This summer i worked at kimballs farm in westford. I am looking foward to a great year here at Teams Academy?. s/n: jhoh10 Yay, another cross-country runner! - Chris M.
Lab 3: Line Following
CODE
// Jon Hohrath's Line Following Fiesta
// 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);
const uint16_t blktape = 600;
// This sets the number that the create will use to compare whether
// a spot is black tape or white board.
cr8_drive_direct(100,100);
// Starts the bot going forward at 100mm/s
while(1)
{
cr8_update(cr8);
// opens a loop that continually checks sensors
if (cr8->cliff_frontleft_range < blktape)
{
cr8_set_leds(off,off,255,255);
cr8_drive_direct(-100,110);
}
// if the front left cliff sensor sees black tape, then set power led to red, and rotate counterclockwise
else if (cr8->cliff_frontright_range < blktape)
{
cr8_set_leds(off,off,0,255);
cr8_drive_direct(110,-100);
}
// if the front right cliff sensor sees black tape, then set power led to green, and rotate clockwise.
else
{
cr8_drive_direct(100,100);
}
// continues going forward if neither sensor is activated
cr8_delay(20);
}
// goes back to the loop after 20 mileseconds.
// release the sensor data strucutre memory and exit the program
cr8_free(cr8);
return 0;
}
Write-Up
Jonathan Hohrath
Line Following Lab Results/Lessons Learned
Summary of Results
My task was to create a code that would enable the create to follow a black electrical tape line
that turned in several directions on a large poster board. I set up a code that would start the
create by moving forward. At any point during its course, if its two front cliff sensors read a
=
light value similar to the value black tape creates, then it will turn away from that sensor.
Also, to explain to me what was happening, I programmed the create to flash its power led either
red if the front left cliff sensor read black tape, or green if the front right cliff sensor read
black tape. The result was a code that allowed the robot to keep its front (between both cliff
sensors) on either side of the line. This code allowed the iRobot Create to successfully “follow
the line” through most of the line course, and allowed me to see what cliff sensors were going off
at different points in the course.
Since I am redoing this lab result, you required me to make an addition to my code. My
addition was already present, however, in the form of the led progress pointers. I can see what
sensors cliff sensors are tripping at what points in the course.
Lessons learned:
- Basic understanding of the thought processes of the command module
- Check what happens to robot, revising program, check what happens to robot, revising program can
really improve the reliability of your program
- Exposed to the fact that these robots are not perfect. Sensors on some of these robots can be
faulty, which is a good lesson to learn.
- Use of a flowchart to make writing a program easier
Course Problems:
My programmed ‘bot had problems at the 180 bend after the triple 90 degree turns. This problem
occurred due to physical restrictions of the create on the course we set up. The problem was that
the sensors were simply too far apart, so as the robot turned it cut off some of the course,
resulting in the robot careening off course. If I could “add” stuff to the create, I would add two
sensors that were only 1” apart, so I could following the line with hairpin accuracy. Overall, I
think this lab was a fun and enlightening experience.
Flow Chart
![]()
Lab 4: Wimp Mode
CODE
/* Add comment
Jonathan Hohrath
Red
Lab 4
12/6/07
Imitation Wimp Mode
*/
// Include the Command Module API
#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 safe(void);
// 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:
int16_t dis = 1000*cr8->dist_m + cr8->dist_mm;
int16_t ang = 360*cr8->revolutions + cr8->angle;
int i = 0;
// Initialize LOCAL Variables used in function main:
cr8->angle = 0;
cr8->dist_mm = 0; // if code resets, reset distance counters
cr8_update(cr8);
cr8_drive_direct(0,0);
cr8_set_leds(0,0,0,255); // a green led mimics wimp mode while letting me know wimp hasnt started yet
while (cr8->button_play == 0) // kicks out when play button is pressed
{
cr8_update(cr8);
}
while(safe())
{
cr8_set_leds(0,0,0,0);
dis = 1000*cr8->dist_m + cr8->dist_mm;
while((1000*cr8->dist_m + cr8->dist_mm) - dis == 0 && safe())
{
cr8_delay(20); // this checks every 20 secs for safety, as well as if the
cr8_update(cr8); //create has moved at all
}
dis = 1000*cr8->dist_m + cr8->dist_mm;
while ((1000*cr8->dist_m + cr8->dist_mm) - dis < 580 && safe())
{
cr8_drive_direct(250,250); // starts off driving forward, while checking bump sensors
cr8_update(cr8); // if distance traveled is over 58 mm,then then kick out of loop
if (cr8->bumper_left)
{
cr8_update(cr8);
ang = 360*cr8->revolutions + cr8->angle;
while(ang-(360*cr8->revolutions + cr8->angle) < 45 && safe())
{
cr8_drive_direct(250,-250); // responding to left bump sensor while moving by turning
cr8_update(cr8); // in the opposite direction of bump for 45 degrees
if (cr8->bumper_left) // responding to left bump sensor while turning
{
cr8_update(cr8);
ang = 360*cr8->revolutions + cr8->angle;
while(ang-(360*cr8->revolutions + cr8->angle) < 45 && safe())
{
cr8_drive_direct(250,-250);
cr8_update(cr8);
}
}
if (cr8->bumper_right) // responding to right bump sensor while turning
{
cr8_update(cr8);
ang = 360*cr8->revolutions + cr8->angle;
dis = 1000*cr8->dist_m + cr8->dist_mm;
while((360*cr8->revolutions + cr8->angle - ang < 45) && safe())
{
cr8_drive_direct(-250,250);
cr8_update(cr8);
}
}
}
dis = 1000*cr8->dist_m + cr8->dist_mm;
}
if (cr8->bumper_right) // responding to right bump sensor while moving by turning
{ // in the opposite direction of bump for 45 degrees
cr8_update(cr8);
ang = 360*cr8->revolutions + cr8->angle;
while((360*cr8->revolutions + cr8->angle) - ang < 45 && safe())
{
cr8_drive_direct(-250,250);
cr8_update(cr8);
if (cr8->bumper_left) // responding to left bump sensor while turning
{
cr8_update(cr8);
ang = 360*cr8->revolutions + cr8->angle;
while(ang-(360*cr8->revolutions + cr8->angle) < 45 && safe())
{
cr8_drive_direct(250,-250);
cr8_update(cr8);
}
}
if (cr8->bumper_right) // responding to right bump sensor while turning
{
cr8_update(cr8);
ang = 360*cr8->revolutions + cr8->angle;
while((360*cr8->revolutions + cr8->angle) - ang < 45 && safe())
{
cr8_drive_direct(-250,250);
cr8_update(cr8);
}
}
}
dis = 1000*cr8->dist_m + cr8->dist_mm; // reset distance so create doesnt go off into distance
}
}
cr8_drive_direct(0,0); // stops, delay is necessary because the robot needs to stop completely.
cr8_delay(200);
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:
*/
int safe(void) // this function is a check for safety
{
cr8_update(cr8);
if (cr8->cliff_frontright || cr8->cliff_right || cr8->cliff_frontleft || cr8->cliff_left || cr8->wheeldrop_left || cr8->wheeldrop_right || cr8->button_advance )
{
cr8_drive_direct(0,0);
cr8_beep_error();
cr8_set_leds(off,off,255,255);
return(0); // if sensors pressed, kicks out of above safe loops, stops moving, turn on red power led.
}
else
{
return(1);
}
}
// End of function xxxxx
Write-Up
Jonathan Hohrath
12-5-07
Wimp Mode Write-Up
I was very pleased with my results for the wimp mode lab. I created a code that allowed
the create to mimic the demo "wimp mode" to a certain degree. My code starts off like the wimp
mode, by flashing a green led and waiting for the play button to be pressed. Then, it and waits
for its distance traveled to be greater than 0.(by being pushed). Then, for 580 mm, it drives
foward, and while driving, it checks to see if bump sensors go off. If the left one goes off, then
it will rotate 45 degrees clockwise. If right is bumped, it will rotate 45 degrees in the other
direction. It does check bump sensors while rotating as well. After rotating unbumped for 45
degrees, it goes foward and checks bump sensors, and if the bump sensors trip, then it responds in
the manner above. If the create travels 580 mm unbumped, it will stop, and reset the code to the
, waiting for it to be pushed again. Throughout the entire code, it checks safety features (cliff
sensors, wheel drop sensors and buttons). If unsafe, it will beep error, stop moving, and flash a
red led. There are a few imperfections with my code. First, the safety response of my code isn't
as complex as the demo response. In the demo, if the create's cliff sensors trip, it moves
backwards, away from the cliff, and rotates, which is different than my stop moving and flash red.
Next, my robot has to rotate the entire 45 degrees before if responds to bump sensor triggers,
while in the wimp it responds almost instantaneously. Next, in the wimp mode, if you hold one
sensor continuously it will spin in the other direction continuously, however, in my code it jerks
every 45 degrees, much to my dismay. Finally, when the safety features trip in the demo mode, you
can reset it, while in my code you have to reset the robot after the safety checks trip. I
thought this lab was a great experience, overall, because i learned about the importance of loop
placing and i learned about the create's logic.
![]() |