Back up to Programming Main Site
FIRST Robotics Examples and Exercises
Week 1: Basics of the Default Code, Digital I/O, and Analog I/O
- Download, expand, and open the default code and workspace for the EduRC.
The default code for the EduRC is very similar (but not exactly the same as)
the full size robot default code.
- Download the default code from IFI: EduRC
Default Code
- Expand the ZIP file into a new folder. You will get a folder
named "EduCode"
- Open MPLab IDE, choose File, Open Workspace. Browse to the
EduCode folder you made and open the EduCode.mpw file.
- Open the user_routines.c file and examine the comments and code.
Read in conjunction with the Programming
Reference Guide
- Input and Output from the robot controller is done through global
variables provided in the default code. Your program for the robot reads
from and writes to these global variables to control the robot.
- Download the following code: EduCode-ioexample.zip
- Expand and open the project in MPLab, as with the default code.
- Compile the code and load it on the Robot Controller (RC) using IFI Loader
- Hook up the following to the RC:
- PWM 1: Motor
- Digital and Analog IO 1: Potentiometer
- Digital and Analog IO 6: Switch
- Digital and Analog IO 12: Photo Sensor
- Turn on the RC with a computer connected to the serial port and look at the output. See how the output changes as the switches and potentiometer are changed.
- Exercise 1: Modify the IO Example code to control the motor.
- When the switch is pressed, the motor should go on full speed forward.
- When the switch is released, it should stop.
- Exercise 2: Modify the IO Example code to control the motor based on the potentiometer input.
- The control should be linear.
- When the potentiometer is turned all the way down, the motor should be stopped.
- When the potentiometer is turned half way, the motor should go half-speed.
- When the potentiometer is fully turned on, the motor should go full speed.
- Exercise 3: Modify your solution to Exercise 2 to add a "brake".
- If the photoswitch is tripped, the motor should stop regardless of the potentiometer setting.
Week 2: Full Size Robot and Operator Interface
- The full size robot controller works very similar to the Edu (Mini)
robot controller!
- The biggest differences are the number of connections we can make to it (more pins to
connect sensors, switches, motors, etc)
and that we have a remote, radio connected, Operator Interface to work with.
- We controlled inputs and outputs on the robot controller by working with
global variables. Working with joysticks and other devices connected
to the operator interface is the same -- there are global variables for each
button, knob, or joystick axis on every joystick port. The program in the
robot controller can use the values of the global variables to tell if a
button is pressed, how far a joystick is moved, etc. Based on that, the
program can make decisions and change the outputs on the robot controller
(motors, lights, etc). The names of the variables can be found in the same
reference documents we used for the robot controller - the
RC
Reference Guide and the Programming
Reference Guide at IFI Robotics' web site.
- The team develops a "pin list" or "i/o map" with the electrical subteam
to establish what devices will plug into each specific port on the robot
controller and the Operator Interface. This is so that the whole team is on
the same page, and for safety reasons (imagine if an arm were plugged into
where the drive train was supposed to be!). Here is an example from our 2006
season:
- Exercise: Make the full size robot's drive train respond to
Joystick movements. The goal is to use joysticks on the operator
interface to control the drivetrain:
- Use two joysticks on the OI, one controlling the left drive train, one controlling the right
drive train.
- When a joystick is pushed up, the corresponding drive train (left or
right) should go forward. When pulled back, it should reverse.
- The speed of the movement should be proportional to the amount the
joystick is moved from its center position.
Hints to get started:
- There is different "default" code from IFI Robotics depending on which
year robot you are working with. Download the matching code below:
- 2005 Robot (Rhinobot) Default Code
- 2006 or 2007 Robot Default Code
Expand the ZIP file and open the workspace in MPLab.
- Make sure the code compiles properly before you start.
- Examine the default code -- you will see that the "Default_Routine()"
function where we said we normally would add our code already has some
functionality in it. You will want to remove or disable this (delete,
comment out, or simply rename the function and create your own
Default_Routine)
- Add your joystick-based drive control. You will need to know where your
joysticks are connected, and where the motors for the drive train are
connected.
- Work with one joystick and one drive train side at a time. Once one
works, the second one should be easy!
- Ask questions and work together!!
Back up to Programming Main Site