User Manual

* Your transmitter/receiver might treat channels 0 and 1 differently
* than the receiver this code was developed for. If your 3pi turns
* when you expect it to go straight or vice versa, you may need to flip
* a sign in the calculation below or swap the connections at the receiver.
*
*/
long m1 = (neutralPulseTime - (int)ch[0].pulse) +
((int)ch[1].pulse - neutralPulseTime);
long m2 = (neutralPulseTime - (int)ch[0].pulse) -
((int)ch[1].pulse - neutralPulseTime);
m1 = m1 * 255 / minPulseTime;
m2 = m2 * 255 / minPulseTime;
set_motors(m1, m2);
}
}
// This part of the code is never reached. A robot should
// never reach the end of its program, or unpredictable behavior
// will result as random code starts getting executed. If you
// really want to stop all actions at some point, set your motors
// to 0,0 and run the following command to loop forever:
//
// set_motors(0,0);
// while(1);
}
Please note that individual transmitter/receiver systems vary, so you might need to modify this code some before it
will work well with your particular system. If you run the program with the LCD connected, it will report back the
duration of the pulses it’s detecting on each channel in microseconds. You can then use the trim settings on your
transmitter to adjust the neutral points to 1.5 ms, or you can modify the neutral points in the code. You also might
want to characterize the ranges of the pulses and adjust the motor speed scaling so that the motors reach full speed
when the transmitter sticks are at their full extents. Lastly, you might need to change some of the signs in the
channel mixing formulas so that the robot responds intuitively (e.g. so that it turns left rather than right when you
move the stick left).
Sample Project: RC 3pi © 2001–2009 Pololu Corporation
4. Software Page 9 of 11