Let's mix channels from an RC hobby controller to make a robot drive!
Previously on Adventures in Science, we saw how to read PWM signals from an RC hobby receiver and turn them into signals that could drive motors. While we could have done this with an off-the-shelf electronic speed control (ESC) unit, it's much more fun to do it manually in code!
This time, we look at reading two channels and mixing them together to create a robot platform that can drive back and forth as well as turn and spin. Using the same 6-channel aircraft controller from last time, we mix in channel one (left/right on the right stick) to allow for steering.
x is the left/right position on the stick and
y is the up/down position, here is the overly simple (yet effective) mixing scheme we use (in pseudocode):
left_motor_speed = x + y right_motor_speed = y - x
We then constrain the speeds to a value between -255 and 255 before sending it to our
drive() function, which we discussed on the last episode. The only downside is that attempting to drive back-left and back-right results in some behavior that's not quite intuitive. However, with a bit of practice, the difficulty can be easily overcome.
This type of control scheme, where one stick is moved forward/backward and left/right, is known as "Arcade Drive" when it comes to ground-based robots. The other type, which is only covered very briefly in the video, is "Tank Drive," where two sticks are configured to only move forward/backward. Driving forward consists of pushing both sticks forward, and turning requires the driver to move the sticks to different positions.
Arcade Drive is generally considered easier to learn, especially for beginners who have experience with video games, but it requires some code to implement. Tank Drive, on the other hand, requires more practice, but it is often favored in robot competitions (e.g. FIRST) thanks to the precision it affords drivers. It's also much easier to implement in code.
If you've competed in combat bots or ground-based robotic competitions like FIRST, what kind of control scheme do you prefer? Share in the comments!
Well since I'm an old fart, tank drive is what I used back when I did combat. Keep in mind that some of the more economical radios won't allow you to use tank drive. The left stick goes forward/backwards, but the right stick only goes left/right.