Keyboard Controlled Boe-Bot Robot

edited 2014-12-09 - 18:52:21 in Learn with BlocklyProp
This example code makes it easy to control your Boe-Bot while it is connected to a PC via the Programming cable. After you run the code, use these keys to control the Boe-Bot:

8 = forward
2 = backward
4 = rotate left
6 = rotate right
5 = stay still

There's no need to hold the key down, just press/release it once (sometimes twice if the BASIC Stamp misses the first character because it's busy sending pulses to the servos).


' {$STAMP BS2} ' {$PBASIC 2.5} pulse VAR Word maneuver VAR Word FREQOUT 4, 2000, 3000 DEBUG "8 = forward", CR, "2 = backward", CR, "4 = rotate left", CR, "6 = rotate right", CR, "5 = stay still" DO SERIN 16, 84, 20, Timeout, [maneuver] Timeout: GOSUB Go LOOP Go: LOOKDOWN maneuver, ["5", "8", "2", "4", "6"], maneuver LOOKUP maneuver, [750, 850, 650, 650, 850], pulse PULSOUT 13, pulse LOOKUP maneuver, [750, 650, 850, 650, 850], pulse PULSOUT 12, pulse RETURN [/Code][Code]

' {$STAMP BS2}
' {$PBASIC 2.5}

pulse VAR Word
maneuver VAR Word

FREQOUT 4, 2000, 3000
DEBUG "8 = forward", CR,
"2 = backward", CR,
"4 = rotate left", CR,
"6 = rotate right", CR,
"5 = stay still"

DO
SERIN 16, 84, 20, Timeout, [maneuver]
Timeout:
GOSUB Go
LOOP


Go:

LOOKDOWN maneuver, ["5", "8", "2", "4", "6"], maneuver
LOOKUP maneuver, [750, 850, 650, 650, 850], pulse
PULSOUT 13, pulse
LOOKUP maneuver, [750, 650, 850, 650, 850], pulse
PULSOUT 12, pulse

RETURN

[/Code]

Comments

  • bomberbomber Posts: 297
    edited 2011-09-18 - 07:59:05
    I was doing a similar type of remote control with the Propeller, ecept it uses the PropBOE, a C3 with the Xbee sip adapter you sent me, a SD card to store the turns in memory, and some whisker sensors for navigation. I can post the code if you want, although it will be built around the PropBOE.
    " 'I hate my code' is the developers version of 'Do I look fat in this dress?' " Quote by Kelly Sommers
  • edited 2011-09-19 - 07:59:34
    Sounds pretty cool. I would recommend holding that for now. The production PropBOEs will be somewhat different, and we'll have a different site for projects. When all that is in place, we'll prepare to be amazed.
  • rock2010rock2010 Posts: 1
    edited 2011-11-26 - 23:28:59
    Thank you Andy for the useful program. i have one question in mind, how can I add a third motor that controls lets say a gun and modify the code so we can control this third motor separately. I want to move the boe-bot with some commands and use other keys to move the gun attached to the third motor right and left.

    Thanks a lot.
  • edited 2011-11-28 - 09:47:26
    Finding a toy gun that's light enough for the Boe-Bot to carry without tipping foward might be a challenge. I suppose you could attach a counterweight to the back or mount it on top. Another thing to try would be the Ping))) Ultrasonic Sensor + Mounting Bracket. The "turret" servo is included.

    Product page:
    http://www.parallax.com/tabid/768/ProductID/563/Default.aspx
    Downloads & Resources
    http://www.parallax.com/tabid/176/ProductID/92/Default.aspx
    http://www.parallax.com/tabid/755/ProductID/248/Default.aspx

    The simplest way to add keyboard control of the turret servo would be to duplicate elements of the wheel control servo code for a third turret servo. For example, you could start by adding a couple of variables for turret character and turret pulse control. Something like this:

    turretChar VAR Byte
    turretPulse VAR Word

    Then, add a second SERIN command to get a second character for turret direction to the DO...LOOP:

    SERIN 16, 84, 20, TimeoutTurret, [turretChar]
    TimeoutTurret:

    Inside the Go subroutine, you'd probably want to add something like this (assuming turret servo is connected to P14):

    LOOKDOWN turretChar, ["4", "7", "8", "9", "6"], turretChar
    LOOKUP turretChar, [1100, 925, 750, 550, 350], turretPulse
    PULSOUT 14, turretPulse

    For more information on standard servo control, download "What's a Microcontroller? v3.0 (.pdf)" from the www.parallax.com/go/WAM resource page, and check out Chapter 4.

    For more information on Boe-Bot continuous rotation servo control, download "Robotics with the Boe-Bot Text v3.0 (.pdf)" from the www.parallax.com/go/Boe-Bot resource page and check Chapter 2, Activity #4, #6, and Chapter 4.
  • John KauffmanJohn Kauffman Posts: 649
    edited 2011-12-05 - 18:12:40
    The name of this thread gave me an idea. "Keyboard" around my house means piano.
    I'm wondering if a microphone on a PropBot could hear a note from the piano and react to the pitch. What a set of possibilities for integration of music and motion. I'll start digging through the Objects Exchange. Remember the video of the Hokey Pokey Toddler Dance Team from five years ago?
  • joecooldeejayjoecooldeejay Posts: 4
    edited 2012-02-05 - 06:36:41
    i have absolutely no idea how to code but i have the basic stamp 2 homework board. i want to use this program with like p0 and p1 to control hobby motors. could someone take the time to do it? i dont get all of that fancy new code stuff!!!!!:smile:
  • edited 2012-02-08 - 16:38:15
    You can run the code as-is if you instead connect the servos to P12 and P13. You'll still need to consult Robotics with the Boe-Bot for wiring examples. (Free pdf download from www.parallax.com/go/Boe-Bot.) The schematic and wiring diagram is in Robotics with the Boe-Bot Chapter 2, Activity #3. There are instructions for two different boards there; make sure to follow the instructions for the HomeWork Board. You'll also need to follow the instructions in chapter 1 for installing the software.

    If you'd like to be able to do more, I'd recommend going to www.parallax.com/go/WAM and downloading the What's a Microcontroller PDF. Each chapter has a few activities, and each activity takes about 15 minutes to work through. You can skip the 5th activity in chapters 2 and 3. By the time you are through with Chapter 4, you'll be able to do it on your own, and you'll know all about the "fancy new code stuff" and lots more.
  • joecooldeejayjoecooldeejay Posts: 4
    edited 2012-02-11 - 17:19:21
    it's so close, but im using rc car type motors, not servos. i can tell its close because i hear a buzzing noise that changes when i hit keys.
  • edited 2012-02-14 - 09:58:31
    Have you connected the I/O pins to the motor controller input where the hobby RF receiver output would normally go? If not, a detailed description of your setup would help.
  • joecooldeejayjoecooldeejay Posts: 4
    edited 2012-02-14 - 18:23:02
    Have you connected the I/O pins to the motor controller input where the hobby RF receiver output would normally go? If not, a detailed description of your setup would help.

    I'm sorry I'm being so confusing. I'm trying to use a snap rover base from elenco's snap circuits that has the regular small motors found in rc cars. I'm trying to control that from a laptop that is on board the snap rover. I am controlling it using logmein so it is as if I am sitting at the laptop controlling it. I hope this makes sense.
  • joecooldeejayjoecooldeejay Posts: 4
    edited 2012-02-14 - 18:25:51
    I'm sorry I'm being so confusing. I'm trying to use a snap rover base from elenco's snap circuits that has the regular small motors found in rc cars. I'm trying to control that from a laptop that is on board the snap rover. I am controlling it using logmein so it is as if I am sitting at the laptop controlling it. I hope this makes sense.

    I am connecting the basic stamp homework board to the motor inputs on the snap rover. This is the snap rover. http://www.amazon.com/Elenco-SCROV-10-Snap-Circuits-Rover/dp/B000GG7XXK. I'm just using the yellow base with the motors in it.
  • edited 2012-02-17 - 19:10:45
    Alright, I found a PDF manual for this rover at http://www.pololu.com/catalog/product/1675.

    It looks to me like you'll need to control the U8 motor control block with I/O pins and series resistors. I'd recommend this circuit:

    Homework.......Series................U8 Motor
    Board..............Resistor.............Control Block
    P15
    R=1k
    LF
    P14
    R=1k
    LB
    P13
    R=1k
    RF
    P12
    R=1k
    RB

    With that circuit, this code should work. You might need to reduce the series resistor values from R=1k to R=470, but try it with 1k first.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    pulse    VAR  Word
    maneuver VAR  Word
    
    FREQOUT 4, 2000, 3000
    DEBUG "8 = forward", CR,
          "2 = backward", CR,
          "4 = rotate left", CR,
          "6 = rotate right", CR,
          "5 = stay still"
    
    DO
      SERIN 16, 84, 20, Timeout, [maneuver]
      Timeout:
      LOOKDOWN maneuver, ["5", "8", "2", "4", "6"], maneuver
      ON maneuver GOSUB StayStill, Forward, Backward, Left, Right
    LOOP
    
    StayStill:
      INPUT 15
      INPUT 14
      INPUT 13
      INPUT 12
      RETURN
    
    Forward:
      HIGH 15
      INPUT 14
      HIGH 13
      INPUT 12
      RETURN
    
    Backward:
      INPUT 15
      HIGH 14
      INPUT 13
      HIGH 12
      RETURN
    
    Left:
      INPUT 15
      HIGH 14
      HIGH 13
      INPUT 12
      RETURN
    
    Right:
      HIGH 15
      INPUT 14
      INPUT 13
      HIGH 12
      RETURN
    
    
  • landonmay13landonmay13 Posts: 10
    edited 2014-12-07 - 13:51:05
    Does this work with the ActivityBot? If not, can you make one for it?
  • Duane DegnDuane Degn Posts: 10,002
    edited 2014-12-07 - 15:20:59
    Does this work with the ActivityBot? If not, can you make one for it?

    Is "this" in "Does this work" refer to the program in the top post? If so, then the exact program won't work with the ActivityBot but the AB can do this sort of stuff much easier than the BOE-Bot could. Do you want to control the AB by sending commands over the USB cable?
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2014-12-08 - 17:15:30
    The code here is for a BS2. Won't work with your ActivityBot.

    Check:

    http://learn.parallax.com/activitybot

    for the current ActivityBot-based projects. The projects are updated regularly, so check back often. Drop them a line if you see something for the BS2 BOE-Bot, and are interested in doing the same with the ActivityBot.
  • dsustkodsustko Posts: 2
    edited 2014-12-08 - 18:15:20
    Duane Degn wrote: »
    Is "this" in "Does this work" refer to the program in the top post? If so, then the exact program won't work with the ActivityBot but the AB can do this sort of stuff much easier than the BOE-Bot could. Do you want to control the AB by sending commands over the USB cable?

    Duane yes, can you help me understand how to control ActivityBot on macbook connected via USB?
  • edited 2014-12-09 - 11:02:27
    It turns out that getting it to behave like the published keyboard controlled Boe-Bot requires some tricks that haven't appeared in any of the learn.parallax.com guides yet. So, here is some code to get you started. 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.
    • 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.

    attachment.php?attachmentid=112208&d=1418151639

    The trick to this code is disconnecting the default serial terminal connection for print and scan calls and replacing it with one that runs in another cog. Why? Because the fdserial library has an rxTime function that only waits for a certain amount of time, so the code won't get stuck waiting for characters. Although not critical here, there are lots of cases where the ActivityBot will want to also scan for sensors.
    /*
      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
      }  
    }
    
    543 x 249 - 99K
  • Duane DegnDuane Degn Posts: 10,002
    edited 2014-12-09 - 11:43:40
    That looks great Andy!

    There are lots of applications which can benefit from monitoring the serial line without blocking the flow of the program.

    Thank you for the example.
  • dsustkodsustko Posts: 2
    edited 2014-12-09 - 18:52:21
    thank you so much Andy, this is exactly what i was looking for. Worked like charm! Now im experimenting with adding keyboard controlled audio and LED's. Next step is adding wireless control through xbee.
    Thank you again!
Sign In or Register to comment.