Robots

Reference Sheet

Reference Sheet.doc

List of programs to work on

Learning how to program your robot

1. Creating a new project and adding files to it

  • Create a new folder for your program
  • Create a new project file
  • Add your other files to it
  • Open main.c

2. Compile and Download a program

  • Tools -> Make Clean
  • Tools -> Make All
    • Finding errors in your program (Syntax errors)
  • Tools -> Program

3. Change/Troubleshoot your com port

Program 1 - Blinking Lights

1. Create a program where the lights blink on and off

  • Using cr8_set_leds( , , , );
  • Using cr8_delay( );
  • Creating a "while" loop that lasts forever

2. Now make them chase each other (play,advance, then power)
3. Now try speeding them up and slowing them down

  • Changing the time for a delay

4. Now try to change your program so that the lights blink until the play button has been pressed.

  • Creating a "while" loop that only lasts until the play button is pressed
  • Commands vs. sensor values
  • Using the cr8_update(cr8); statement
  • Conditional statements

Program 2 - Safe Robot

1. Start with your blinking light program, and make it so that when the play button is pressed, the robot starts driving straight ahead.

  • Using cr8_drive_direct( , );

2. Make the robot stop when it is picked up.
3. Make the robot stop if it is picked up or if it "sees" a cliff

  • Using more complex conditional statements
  • Using #define to simplfy your program
  • Using the ! command

4. Make the robot spin in place when the bumpers are pressed. (Left bumper turns left, right bumper turns right)

  • Using "if" statments

5. Make the robot drive backwards if both bumpers are pressed.

  • Making sure statements are exclusive.

Program 3 - Wall Following

  • Using cr8_drive( , );
  • Using a more complicated thought process to come up with a solution.

[[tab Robots Final Project]]
Robot Reference Sheet (Blue)

Final Project Guidelines

  • Your project is worth 300 Experimentation Points (Plus 100 Work Habits Points)
  • Your proposals are due on Monday (March 31st)
  • You will have one week to finish your program
  • Your grade will be based on the difficulty of the task you choose, and by how well you accomplish it
  • You should try to include something that is new for you. Consider
    • Using a distance sensor so that robot follows the wall without touching it.
    • Adding songs to some other program and making it function better.
    • Using a display to show variables or text

Using a display

  • If you are displaying text, use the command lcd_printf("With what you want displayed in quotes");
  • If you are displaying sensor values, the easiest things to use is lcd_print_4vars(cr8->button_play,cr8->button_advance,cr8->bumper_left,cr8->bumper_right,off,off);

You can put in any variables that you like (just make sure to include 4, and then send it two offs. The reference sheet tells you where each thing will be displayed on the screen.

  • IF YOU ARE DISPLAYING SENSOR VALUES, MAKE SURE YOUR COMMAND TO PRINT IS IN A LOOP WITH AN UPDATE OR YOUR SENSOR VALUES WILL NOT BE ACCURATE

Here is a simple piece of example code to try to get your display working.
while(true)
{
cr8_update(cr8);
lcd_print_4vars(cr8->button_play,cr8->button_advance,cr8->bumper_left,cr8->bumper_right,off,off);
cr8_delay(300);
}

Common Errors
If only part of your message is printed, you need to put in a delay. The text can only refresh the text so fast. so only part of your message will be displayed.

Servo Motors

Follow this link for info on servo motors.
Read all the way to end of the page, and then ask questions.

Adding Music

Max's Song Example(From TEAMS):
Feel free to cut & paste the code below into your program & modify the portions in [BLUE] …
To Define Your Song: Define your song notes and song number in section of main.c before your program…right after the cr8_init(cr8); command

cr8_byte_tx(CR8_OPCODE_SONG); // Don't change anything on this line
cr8_byte_tx(THE NUMBER OF YOUR SONG);
cr8_byte_tx( NUMBER OF NOTES IN YOUR SONG );
cr8_byte_tx( 72 ); note #1 from OI chart of notes
cr8_byte_tx( 8 ); //note length = 8/64th sec = 1/8 sec
cr8_byte_tx( 88 ); //note #2
cr8_byte_tx( 12 ); //note length
.
// .
// .
// etc.
To play your song, put these two lines of code in your program…
cr8_byte_tx(CR8_OPCODE_PLAY); // send opcode to play song (you could use 141 instead of "CR8_OPCODE_PLAY")
cr8_byte_tx( THE NUMBER OF YOUR SONG );

Create OI Chart of Notes

Adding External Sensors

Sensor Example Code
[A Powerpoint to help you get started]

Line following:

1. You need to connect a display to your robot and (using the code above) display the values of the cliff sensors. Make sure you use RANGE to get state, not strength. For example, use cr8->cliff_left_range instead of cr8_cliff_left.
2. Write down the values that your sensors have when they are over the yellow line. Write down the values the sensors have when they are over the table. Make sure you write down the values for each sensor. They will all be different.
3. Now figgure out the logic to make your robot follow the line. If the line starts out between the two front sensors, you know if that if either sensor "sees" the line, it needs to turn. Don't be afraid to make mistakes. This might involve a lot of trial and error.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License