Keyboard Controlled ActivityBot

Here is an example of controlling the ActivityBot with the SimpleIDE Terminal and your computer keyboard.  You can just type like f, b, l, r, and s, to make the ActivityBot go forward, backward, left, right, and stop.  The speeds are currently really slow (+/-32), but you can increase those values once you're sure your ActivityBot won't try to drive off the table.


Test Keyboard Control

  • Click SimpleIDE's New Project button.
  • Copy code below and paste into SimpleIDE.
  • Click Run With Terminal.
  • Click the Echo On checkbox in the SimpleIDE terminal.
  • Click by the > prompt before you start typing characters like f b l r and s.
  Keyboard Controlled ActivityBot.c

#include "simpletools.h"                      // Library includes
#include "abdrive.h"

terminal *term;                               // For full duplex serial terminal
char c = 0;                                   // Stores character input

int main()                                    // Main function
  simpleterm_close();                         // Close default same-cog terminal
  term = fdserial_open(31, 30, 0, 115200);    // Set up other cog for terminal
  drive_speed(0, 0);                          // Start drive system at 0 speed

  // Display user instructions and prompt.  
  dprint(term, "Check Echo On in SimpleIDE Terminal\n\n");
  dprint(term, "f = Forward\nb = Backward\nl = Left\nr = Right\n\n>");

  while(1)                                    // Main loop
    c = fdserial_rxTime(term, 50);            // Get character from terminal
    if(c == 'f') drive_speed(32, 32);         // If 'f' then forward
    if(c == 'b') drive_speed(-32, -32);       // If 'b' then backward
    if(c == 'l') drive_speed(-32, 32);        // If 'l' then left
    if(c == 'r') drive_speed(32, -32);        // If 'r' then right
    if(c == 's') drive_speed(0, 0);           // If 's' then stop