BEMF Motor Control

Even the most sophisticated servo-powered scoring devices are only effective when the robot can accurately manuever itself into scoring range. Though you can move your robot using fd()s and bk()s, to accurately travel at precise distances and speeds, its better to use something called closed loop motor control. Though that sounds big and fancy, the basic idea is simply that the CBC can control the motors more accurately with feedback, just like you can ride a bike easier with your eyes open. The CBC has the ability to get a form of feedback called Back-EMF directly from the motor's power cable, so every motor in your kit can be used (to varying degrees of success) with closed loop motor control. KIPR provides a small set of handy functions that make closed loop motor control with BEMF very easy to use, as we'll see in this article.

Speed control with mav

The simplest BEMF function is called mav. Here's a quick example to try out before we dive in to what it does:

  1. int main() {
  2. mav(0, 700); // begin moving motor 0 at 700 ticks per second
  3. mav(2, 700); // begin moving motor 2 at 700 ticks per second
  4.  
  5. sleep(5);
  6.  
  7. mav(0, -700); // change motor 0 to travel in reverse at 700 ticks per second
  8. // motor 2 is still moving at 700 ticks per second!
  9.  
  10. sleep(5);
  11.  
  12. off(0); // just like before, we shut our motors off with the off function
  13. off(2);
  14. }

Plug some motors on ports 0 and 2, and watch them spin. Didn't we learn this already? Well, sort of. You'll notice the wheels are spinning a bit slower than if you had done an fd(). Thats what the number 700 means. 1000 is roughly full speed, so 700 means 70%. So now your robot is moving a bit slower.

But why exactly is this useful? Well for starters, it is sometimes necessary for robots to move slowly. When you start using sensors on your bot, you'll find that sometimes going slower improves reaction times and enhances accuracy. But you'll mostly use this form of speed control to ensure that your robots go straight. By slightly adjusting the motor speeds, you can account for the slight differences in motor strength, robot construction, weight distribution, and other small factors that can lead to a robot that veers. Which ever direction your robot appears to drift to, simply reduce the opposite motor's speed by about 5-10 ticks at a time until the problem goes away. So for instance, if my robot veered left, I might say:

  1. int main() {
  2. mav(0, 900); // run the left wheel at normal speed
  3. mav(2, 890); // run the right wheel a tad bit slower
  4. }

Simple enough, right? But done correctly it can dramatically enhance your robots accuracy. Don't get too wrapped up in trying to get a perfectly straight robot however, because it often times isn't possible, and you'll just be wasting time that could be better spent trying to score points!

(Obviously this isn't finished yet but I'm taking a small break until the meeting, then resume working probably - Matt)