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.