View Single Post
  #4   Spotlight this post!  
Unread 12-02-2008, 17:39
ay2b's Avatar
ay2b ay2b is offline
Registered User
AKA: Andy
FRC #2928
Team Role: Mentor
 
Join Date: Mar 2004
Rookie Year: 1994
Location: Seattle, WA
Posts: 211
ay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant future
Re: two drive styles

Preprocessor directives still require you to recompile the code for each robot. Here's what I've done in the past, and what I recommend doing, in order to control multiple robots with the same code:

First, make sure that your code is well isolated. Create a robot.c/robot.h file which defines all the robot functionality. It will have a functions like robot_drive_1(speed, turn), robot_set_arm_position(height), etc. This should be the ONLY place in all of the code which sets any PWM output values. (Even with only one robot, this will make adapting the code to changes in the design faster & easier.) Similarly, isolate all of your OI into one place. With one robot, I generally have a file, oi.h, where I will do things like: #define drive_x p1_x and #define drive_y p1_y, etc. With different OIs, you might want to handle that a little differently.

Second, make sure that your code can tell the difference between the two robots. The easiest way to do this is to make a jumper that shorts one of the digital inputs to ground. (i.e. connect the two outside pins, or the white and black wires from a pwm cable.) In robot.h you will have defined which pin this is (something like #define ROBOT1 rc_dig_in17).

Now you can do something in your code like this:
Code:
if (ROBOT1)
{
    robot_drive(oi_drive_left, oi_drive_right);
}
else
{
    robot_drive(oi_drive_speed+oi_drive_turn-127, oi_drive_speed-oi_drive_turn);
}
(Please note: the above is PSEUDO-CODE and may not actually compile, or work correctly if it does compile.)

Similarly, you could do this on the OI by wiring a jumper to close one of the unused pins (p4_sw_aux1 or similar) on a joystick input port. Look for this in the code to determine which OI you are using.

Personally, the height of doing this was in 2006, where we had four robots (two teams each with a competition robot and a practice robot based on the previous year's robot) and four OIs (two with steering wheels - each with their own bias, two with joysticks). I used two digital i/o pins on each robot and two joystick ports on each OI, and any OI could be used to drive any robot, all with the same code loaded onto each robot. For the record, I would not try to support so many different combinations again, but it can be done.
__________________

2011 - SD Quarterfinalists (980), LA Quarterfinalists (980)
2010 - LA (2404) Finalists (980), AZ Motorola Quality (980)
2009 - LA Semifinalists (980); Las Vegas Quarterfinalists (980); SD (2404); IRI #1 Seed, Finalist (980)
2008 - SD Quarterfinalists (980), LA Champions (980), LA Rookie Inspiration Award (2404); CalGames Finalists
2007 - So.Cal Finalists (980), SD Quarterfinalists (980); CalGames Finalists
2006 - So.Cal Regional Champion (4), Toronto Judge's Award Day 1 (4)
2005 - SVR Champions, Delphi "Driving Tomorrow's Technology" (980); AZ Xerox Creativity (980); So.Cal Finalists, RadioShack Innovation in Control (980); Championship Archimedes Division Semifinalists; IRI Finalists (980)
2004 - So.Cal Regional Champions, Leadership in Controls (980); AZ GM Industrial Design (980); Championship Galileo Division #2 Seed; IRI Champions
2003 - PNW Semi-finalists (488)
2002 - PNW Finalists (488)
2000 - X-bot / 488 - Mentor / Founder
1994 - Sunny Delight - Driver - champion