LEARN.PARALLAX.COM
Published on LEARN.PARALLAX.COM (https://learn.parallax.com)
Home > Remote Control Rock, Talk, and Roll ActivityBot

Remote Control Rock, Talk, and Roll ActivityBot

With its multi-core Propeller brains, this ActivityBot can play music or talk while driving, or change direction while talking, while at the same time decoding IR remote signals and monitoring for collisions with obstacle-detecting touch-whisker sensors.  No coding interrupts required!

But if you accidentally drive your robot into an object, be prepared for your ActivityBot to feel it!  If the whiskers detect contact, the ActivityBot will jump back and say “Ouch!” then sit still, quietly, until you are ready to drive it more carefully. This project is easy to customize with your own WAV files or with other types of sensors.  Or for more of a group challenge, build a walled maze and use it for a driving skill contest!

Requires parts not included in the base ActivityBot Robot kit. See parts list below for details. It is highly recommended that you complete all of the ActivityBot tutorials before trying this project.

 

Parts Required

  • (1) Built and tested ActivityBot robot (#36500)
  • (1) microSD card with FAT32 format (#32328)*
  • (1) Portable Mini Hamburger Speaker (#900-00018)
  • (1) ActivityBot Speaker Mount Kit (#725-32905)
  • (1) Universal IR Remote (#020-00001)
  • Optional (not provided) – microSD/USB card adapter

*Check your ActivityBot kit; a microSD card was included with some versions as a bonus and it is now sold as an optional accessory.

You will also be using these items that are included in the ActivityBot Kit:

  • (2) Whisker wires
  • (2) 3-pin headers
  • (2) 10 kΩ resistors (brown-black-orange)
  • (3) 220 Ω resistors (red-red-brown)
  • (1) IR reciever
  • (1) piezo speaker – optional but a good idea
  • (misc) jumper wires

Putting the Pieces Together

You will need to add the veho360 speaker and its mounting bracket, the whisker circuits, and one IR receiver circuit to your ActivityBot.  You will also need to configure your IR remote for Sony protocol.

First Things First

  • Charge your veho360 or Portable Mini Hamburger Speaker (if it is not charged yet) while you complete the rest of the building steps.  It comes with a USB charging cable. (Note: the speaker’s cable doesn’t work for programming the ActivityBot; for that you must use the cable that came with the robot kit).
  • Make sure you are using the latest SimpleIDE software, and the latest Learn Libraries and ActivityBot Libraries.
  • Make sure your robot has been calibrated recently. If it hasn’t, follow these directions to calibrate your ActivityBot.

Prepare the Gadgets

  • Make sure your IR remote has fresh batteries!
  • Configure your IR remote for Sony protocol (if it is not already configured) following its manufacturer instructions. (For the Brightstar brand remote available from Parallax, press and hold the Setup button until the light near it turns on. Then, press 6-0-5.)

]

  • Follow the directions in the ActivityBot Speaker Mount product guide to attach the bracket to the robot chassis, and mount the charged veho360 or Portable Mini Hamburger speaker. 

 

Build and Test the Sensor Circuits

You will need to build and test three sensor circuits on your ActivityBot breadboard: two for whiskers, and one for the Infrared Receiver.  When you are done, your board will look something like the one below.

  • Follow the directions on the Build the Whiskers page from the ActivityBot tutorial .  You can use the component placement shown in the photo below, or follow the wiring diagram in the Build the Whiskers page. Either is fine!
  • Test the whisker circuits to make sure they are working.
  • Build and test the IR Receiver circuit, following the Infrared Receiver and Remote tutorial.
  • Gently bend the IR receiver legs so the dome on the sensor is facing upwards. This will help it to receive IR signals from the remote, no matter which way it is traveling.
  • If you like, add a piezo speaker circuit to I/O pin 4. The application code will use it as a low-battery reset indicator at the start of the main routine.

Taking a Test Drive

Now it is time to put all the necessary files on the ActivityBot, and then take it for a drive!

  • Download the AB-IR-Remote-Wav.zip file (contains code, libraries and WAV files for this project)
  • Open the project AB-IR-Remote-Wav.side from the un-zipped project folder.
  • Connect the USB cable, and put the Activity Board power switch in position 1.

You will need to transfer the eleven WAV files from the project folder to the microSD card that comes with the ActivityBot kit. If you have a microSD/USB card adapter, you can use that to load the files onto the SD card directly from your computer before putting the card into the ActivityBoard.  If you don’t, just follow the directions below.

  • Insert the microSD card into the card slot on the Activity Board, if it is not already there.

  • In SimpleIDE, click the Program menu, then select File to SD Card.
  • Browse to the unzipped project folder, select one of the WAV files, and click Open.
  • Repeat until all eleven WAV files are on the microSD card.

Now, you are ready to run the program!

Note: If you are using the ActivityBot 360° Robot (#32600), change #include “abdrive.h” to #include “abdrive360.h” at the beginning of the program before uploading the code to your robot.

  • Click Load EEPROM & Run.
  • Set the power switch to 0. Disconnect the USB cable and put the robot on the floor.
  • Put the power switch in position 2.
  • Turn on the power-volume switch on the portable speaker.
  • Test drive it!

 

Driving Directions

The remote’s driving controls take a little bit of practice.  This is “set-and-forget” motion – you do not have to hold a button down to make the robot keep moving in that direction. Also, the motions are designed with ramping, so you can control speed as well as direction (with practice!).  Be ready to hold the Mute button down to make it stop!

Here are some driving tips:

  • A quick button tap makes the robot move slowly. Tap again or hold the button longer to make it go faster.  
  • Tap the Mute button to slow down a motion. Tap again to slow it further, or hold it down to stop. 
  • To drive around, press the Channel+ button, quickly tap Vol + or – and then tap Channel+ again immediately.  This lets you drive forward with slight course adjustments to the left or right.
  • Press Vol + or – to make the robot turn in place. Then, tap the Channel+ button a few times to make it drive in a widening circle. 
  • Try to keep the receiver in sight. If the robot is too far away, or behind an object, or if the speaker is blocking your view of the receiver, the robot might not respond to the remote.
  • The number buttons play the audio files. Buttons 1–9 play spoken words.  Button 0 plays music that will last for about 40 seconds unless you interrupt it with a different audio file.
  • Try driving the ActivityBot into an object, if you haven’t done so by accident already, to see what happens!

How Does it All Work Together?

Dig Inside the Code

The AB-IR-Remote-WAV application uses the simpletools and abdrive (or abdrive360) libraries, which may be familiar to you already. It also uses the wavplayer library to play the audio files, and sirc to decode the infrared signals received from the remote controller. 

Comments Count!

A detailed comment block (all the lines between /* and */) helps other people know what is needed to use the application code, and what to expect from it in action. 

/*
  AB-IR-Remote-Wav.c
  10/30/2013 version 0.5
  https://learn.parallax.com/activitybot

  ActivityBot plays WAV files on speaker from SD card
  Sensors: IR receiver on P10, touch whiskers on P7 & P8
  Control with Sony-compatible remote (Parallax #020-00001)
  (Brightstar: hold Setup until lit, then enter 605)
  Drive with 5 buttons: Channel+/-, Vol +/-, and mute
  Number keys select WAV files to play
  If whiskers are pressed, robot backs up & stops, plays WAV
*/

#include "simpletools.h"
#include "wavplayer.h"                  // Needs 0.9 or later              
#include "abdrive.h"                    // Needs 0.5.5 or later
#include "sirc.h"             

 

Setup Tasks Get the Hardware Ready

Inside the main routine, there are a few setup tasks.  First, a freqout call lets you know the program is starting, or re-starting if the batteries run low.  Next, drive_speed(0,0) starts the servo/encoder control core, but does not move the motors yet.  Then, a call to drive_setRampStep determines how quickly the robot will move into and out of maneuvers.

int main()                              // Main - execution begins!
{
  freqout(4, 2000, 2000);               // Start beep - low battery reset alarm
  drive_speed(0,0);                     // Start servos/encoders cog
  drive_setRampStep(10);                // Set ramping at 10 ticks/sec per 20 ms
  sirc_setTimeout(50);                  // Remote timeout = 50 ms

  int DO = 22, CLK = 23, DI = 24, CS = 25;  // Declare SD I/O pins
  sd_mount(DO, CLK, DI, CS);                // Mount SD card
  wav_volume(7);                            // Set vol here, 1 - 10 

 

Nested Control Loops

This program has a loop-within-a-loop structure. The outer loop is a simple while(1) that repeats forever.  The inner while loop is conditional, and only repeats if no whisker is pressed.  It translates to “add the input states of P7 and P8, and as long as the answer is equal to 2, repeat the loop.”  Recall that the whisker touch-sensors are “active-low” circuits that return a 1 if not pressed, and a 0 if pressed. So as long as both whisker circuits are reporting a 1, no object collision has been detected.

while(1)                               // Outer loop
  {
    while((input(7) + input(8)) == 2)    // Inner loop while whiskers not pressed
    {

 

Decoding the Remote

The inner loop’s first line is all that is needed to receive information from the IR Remote.  The sirc library’s sirc_button function decodes infrared patterns detected by the IR receiver, and returns the value corresponding to the remote control button.  That value is assigned to the button variable.  (If you want to use a different Propeller I/O pin with the IR receiver, change it here.)

      int button = sirc_button(10);      // check for remote key press

 

Select a Sound

A series of if(button ==… statements comes next, and the one matching the current value of the button variable gets executed.  For values 0-9, the audio file named in the wav_play function call is accessed from the microSD card and the Propeller chip generates the audio signals that are played on the veho360 speaker.  The wavplayer library launches other Propeller cores to handle those tasks, so the audio files keep playing while the core executing the main function keeps the inner and outer loops looping.  

      // Audio responses - if number key pressed, play named WAV file
      if(button == 1)wav_play("hello.wav");               
      if(button == 2)wav_play("follow.wav");   
      if(button == 3)wav_play("byebye.wav");                
      if(button == 4)wav_play("oops.wav");                
      if(button == 5)wav_play("thankyou.wav");                 
      if(button == 6)wav_play("dontknow.wav");                   
      if(button == 7)wav_play("yes.wav");               
      if(button == 8)wav_play("no.wav");                
      if(button == 9)wav_play("maybe.wav");
      if(button == 0)wav_play("electro.wav");       

 

Select a Motion

If the channel up/down, volume up/down, or mute button is pressed, the corresponding drive_rampStep function call sets the wheel speeds to make the robot move in the direction noted in the comment.  

Since these are calls to drive_rampStep and not to drive_speed, a quick tap on the button will set a slower motion, but holding the button down for a moment longer will set a faster motion. Likewise, a quick tap on the mute button will slow down a motion, but you must hold the button down to stop. 

The drive_rampStep function is part of the abdrive library, which uses a separate core to handle the servo motor and encoder control. So, the function call only needs to set the new direction, and the robot will continue on that course until a new IR button press sets a new direction.  And, the core executing the main function is free to continue with the inner and outer while loops.

      // Motion responses - if key pressed, set wheel speeds
      if(button == CH_UP)drive_rampStep(128, 128);   // Forward
      if(button == CH_DN)drive_rampStep(-128, -128); // Backward
      if(button == VOL_DN)drive_rampStep(-128, 128); // Left turn      
      if(button == VOL_UP)drive_rampStep(128, -128); // Right turn
      if(button == MUTE)drive_rampStep(0, 0);        // Stop

 

Dropping Out of the Inner Loop

Recall that the inner loop is conditional – it only repeats if neither one of the whisker touch-sensors is pressed.  But if a whisker IS pressed, the code execution drops out of the inner loop to the code below.  Here, drive_speed functions make the motors stop, back up quickly for 500 milliseconds, and stop again.  Then, a call to wav_play makes the ActivityBot say “Ouch!”.  The robot will not drive again until it receives another IR signal.

    // Sensor response - if a whisker is pressed
    drive_speed(0, 0);                  // Stop driving
    drive_speed(-100, -100);            // Back up 0.5 seconds
    pause(500);
    drive_speed(0, 0);                  // Stop driving
    wav_play("ouch.wav");               // Play named WAV file
    pause(1000);                        // Pause & return to outer loop
  }            
}

 

AB-IR-Remote-Wav Complete Code Listing

Here is the whole code listing at once:

/*
  AB-IR-Remote-Wav.c
  10/30/2013 version 0.5
  https://learn.parallax.com/activitybot

  ActivityBot plays WAV files on speaker from SD card
  Sensors: IR receiver on P10, touch whiskers on P7 & P8
  Control with Sony-compatible remote (Parallax #020-00001)
  (Brightstar: hold Setup until lit, then enter 605)
  Drive with 5 buttons: Channel+/-, Vol +/-, and mute
  Number keys select WAV files to play
  If whiskers are pressed, robot backs up & stops, plays WAV
*/

#include "simpletools.h"
#include "wavplayer.h"                  // Needs 0.9 or later              
#include "abdrive.h"                    // Needs 0.5.5 or later
#include "sirc.h"              


int main()                              // Main - execution begins!
{
  freqout(4, 2000, 2000);               // Start beep - low battery reset alarm
  drive_speed(0,0);                     // Start servos/encoders cog
  drive_setRampStep(10);                // Set ramping at 10 ticks/sec per 20 ms
  sirc_setTimeout(50);                  // Remote timeout = 50 ms

  int DO = 22, CLK = 23, DI = 24, CS = 25;  // Declare SD I/O pins
  sd_mount(DO, CLK, DI, CS);                // Mount SD card
  wav_volume(7);                            // Set vol here, 1 - 10  

  while(1)                               // Outer loop
  {
    while((input(7) + input(8)) == 2)    // Inner loop while whiskers not pressed
    {
      int button = sirc_button(10);      // check for remote key press
 
      // Audio responses - if number key pressed, play named WAV file
      if(button == 1)wav_play("hello.wav");               
      if(button == 2)wav_play("follow.wav");   
      if(button == 3)wav_play("byebye.wav");                
      if(button == 4)wav_play("oops.wav");                
      if(button == 5)wav_play("thankyou.wav");                 
      if(button == 6)wav_play("dontknow.wav");                   
      if(button == 7)wav_play("yes.wav");               
      if(button == 8)wav_play("no.wav");                
      if(button == 9)wav_play("maybe.wav");
      if(button == 0)wav_play("electro.wav");                  
 
      // Motion responses - if key pressed, set wheel speeds
      if(button == CH_UP)drive_rampStep(128, 128);   // Forward
      if(button == CH_DN)drive_rampStep(-128, -128); // Backward
      if(button == VOL_DN)drive_rampStep(-128, 128); // Left turn      
      if(button == VOL_UP)drive_rampStep(128, -128); // Right turn
      if(button == MUTE)drive_rampStep(0, 0);        // Stop
    }

    // Sensor response - if a whisker is pressed
    drive_speed(0, 0);                  // Stop driving
    drive_speed(-100, -100);            // Back up 0.5 seconds
    pause(500);
    drive_speed(0, 0);                  // Stop driving
    wav_play("ouch.wav");               // Play named WAV file
    pause(1000);                        // Pause & return to outer loop
  }            
}

Do More With This Project

 

Did You Know?

You can use your own WAV files for this project.  Give your ActivityBot a vocabulary all its own, add different music tracks, or even sound effects.  Our Sound Library features easy how-to’s for using the free Audacity software:

  • Sound Library

 

Try This – Driving Test!

Gather some friends, and see who is the best ActivityBot driver!

  • Increase the length of the last pause function call to 2500. 
  • Set up a maze of boxes with walls about 30 cm apart, with several turns of different angles. 
  • Use a stopwatch and take turns driving through the box maze to see who can drive through it fastest. But be careful – hitting a wall causes a 3-second penalty!

 

Try a Different Sensor

Remember this little piece of code, the inner while(… loop? ?

    while((input(7) + input(8)) == 2)    // Inner loop while whiskers not pressed

If you want to use a different sensor for object detection, this is the line to change.  For example, instead of whiskers, let’s say you have a PING))) Ultrasonic Distance Sensor connected to P8. Provided you add #include “ping.h” to the top of your code, just replace that line with the following:

   while(ping_cm(8) > 10)               // Inner loop while no object within 10 cm

This will keep the inner loop looping as long as the measured distance returned by the PING))) sensor is greater than 10 cm.

 

Teacher Tips

Here are some helpful hints for using this activity in a classroom:

  • Overhead fluorescent light fixtures can emit infrared light and interfere with IR signals.  It might be wise to have your students try the Your Turn section of the IR Receiver and Remote Tutorial and then scope out the classroom lighting for sources of infrared interference.
  • If several students are trying this project in the same room, be aware that every remote can control every robot.  Have students move to different corners of the room, or take turns. 
  • Or, take advantage of the single-controller, many-robot feature. It can be fun to have the robots line up or face each other in a square and have one remote controller make them speak and dance in unison!
  • If you have several robots in the same place, try modifying the program for each one separately to respond to only a few of the number buttons.  That way you can give each robot a smaller but unique set of audio responses from the same remote.

DISCUSSION FORUMS | PARALLAX INC. STORE

About | Terms of Use | Feedback: learn@parallax.com | Copyright©Parallax Inc. 2024


Source URL:https://learn.parallax.com/courses/remote-control-rock-talk-and-roll-activitybot/
Links