Using PING)), IR, Sound Impact and Whiskers on Boe-Bot


I am working on a project that is due in a couple of weeks. I have not been able to program my robot using any other sensors other than the PING)).
I am trying to make a robot that follows sound and color, spins when it is touched by whiskers and looks for where it goes as well as escape corners.

I have got it to function with PING)) by rotating when encountering obstacles. However, I tried programming whiskers in by using a while loop but, an error occurred. I have not attempted t program with Sound Impact and IR sensors.

Any advice? ASAP would help me.


  • 9 Comments sorted by Date Added Votes
  • Mike GreenMike Green Posts: 22,601
    edited October 2017 Vote Up1Vote Down
    It's always hard to advise anyone on errors without the actual code posted. Either include it as an attachment or cut and paste between [ code] and [ /code] brackets (without the extra space).

    First get different programs working ... one using PING))), one using IR, one using whiskers, one using sound impact. You may not be able to combine all of these and still get any kind of effective speed of reaction. PING))) takes a lot of time. IR is pretty fast. Whisker sensing is instantaneous. Sound impact timing depends on what you're doing with it. Think about (specifically) you want your robot to do with IR sensing or sound impact sensing. Try adding whisker sensing to a PING))) program first ... not using a while, but IF-THEN statements.
  • Thank you very much. I have attempted this but, my program is quite weird. I have tried adding Ping and Whiskers as you mentioned. I attached the code as follows. Green
  • Unfortunately you've run across a fundamental limitation of the Basic Stamps ... they can only do one thing at a time. When your program does a PAUSE or PULSIN or PULSOUT, it stops doing anything else for the specified time (or for PULSIN until the pulse finishes). Servos require control pulses about every 20ms. If they occur less often, the servo shuts down. Other statements also take time ... typically a couple of hundred microseconds. It doesn't take too many GOSUBs and RETURNs before they eat up a few milliseconds. There's a demo program called Roaming with PING that demonstrates how to combine the use of a PING servo with distance sensing using the PING plus movements based on what's sensed. If you calculate the execution time along each of the program's paths (through the program), you'll find that it's pretty close to the "magic" 20ms along several of the paths.

    Here's some useful information on Stamp Programming. Look particularly at the tables of statement execution time. Add comments to each statement with the execution time for the statement. Then you can trace through the program in your head and mark down the range of times for subroutines and major sections of your code.

    The best you may be able to do is to stop, scan the environment with the PING and note distance sensed straight ahead and a little to the right and to the left. Your program can decide which way to turn, do so, then move straight ahead while checking the whiskers. If one of the whiskers is on, have your robot back up, then start again with the PING sensing.

    Notice that only one of the following is done at a time: the wheels turn right or left, the wheels back up, the wheels go forward with whisker sensing, the PING moves, the PING senses.
  • Hello Mike Green,

    I was able to get my robot to function using the whiskers and ping at the same time. However, its movement is odd. It rotates in circles instead of moving forward and the pingservo does not work. I have attached the file of my program. Please review. Any feedback is highly appreciated.

    I do not know if this is a problem with hardware or simply a debugging issue with determining certain rotational values of each wheel for forward, backward and turning movements.
    Mike Green wrote: »
  • There are a lot of places where the 20ms maximum time between servo pulses is violated. For example,
    Turn_Right:                             ' Right Turn, About 45 Degrees
      FOR pulseCount = 0 TO 7               ' Number Of Pulses To Turn
        PULSOUT PingServo, 750              ' Ping Servo Forward Pulse Value
        PULSOUT LeftServo, 850              ' Left Servo Right Pulse Value
        PULSOUT RightServo, 850             ' Right Servo Right Pulse Value
        PAUSE 20                            ' Refresh Delay
    This uses 1.5ms + 1.7ms + 1.7ms + 20ms = 24.9ms between pulses. That's enough for the servos to turn off. Change this PAUSE to 15 to fix that. Do the same sort of thing for other loops. Similarly, you need to adjust for the PULSIN time when objects are far from the robot like this
    Ping_Around:                            ' Start 180 Degree Pan-Scan
      counter = 0                           ' Reset Passive Delay Counter
      oldDistance = 30                      ' Current Old Distance Values
      task = 0                            ' Current Task Priority
      FOR pulseCount = 0 TO 20              ' Number Of Pulses To Spin
        LOW Ping                            ' Force PING))) Line Low
        PULSOUT PingServo, 1085             ' Ping Servo 90 Left Pulse Value
        PULSOUT Ping, 5                     ' Activate PING)))
        PULSIN  Ping, 1, distance           ' Receive Distance Value
        PAUSE 20                            ' Refresh Delay
    Change the PAUSE to 20-((distance>>1) MAX 19). This shortens the PAUSE based on the time needed for the PULSIN (with a minimum PAUSE of 1ms). Change other loops similarly.

    I'm sure there's other stuff as well, but this is something that catches beginners.
  • I would even change these PING loops to move the servo then look for an obstacle like this
    LOW Ping                            ' Force PING))) Line Low
      FOR pulseCount = 0 TO 20              ' Number Of Pulses To Spin
        PULSOUT PingServo, 1085             ' Ping Servo 90 Left Pulse Value
        PAUSE 20                            ' Refresh Delay
      PULSOUT Ping, 5                     ' Activate PING)))
      PULSIN  Ping, 1, distance           ' Receive Distance Value
    There's no need to PING while the servo is moving
  • Thank you very much. I attempted to make the following changes. The movement is still abnormal, where it spins in circles repeatedly but, does not go forward. I thought it was a problem with the whiskers sensors so I added the GOSUB Forward_Pulse into those loops. But, that did not make a difference. I attached it here again. Could this be a result of not having the PING)) scan and then move forward? Green
  • Do you have a picture of your setup that may help if there is a wiring problem.
    Infernal Machine
  • Sorry for the delay ... It's a busy season and I'm really lost trying to understand what your program is doing. How about starting with Roaming With PING?

    I think you would want to scan with the PING and make a note in a variable of where the longest clear path is found, maybe straight ahead (1), a little to the left (2) a little to the right(3), or no path is seen within some distance (4). You'd then do something like your "taskN" where 1 = forward, 2 = turn left, move a little forward, then turn right, 3 = turn right, move a little forward, then turn left, 4 = back up. If a whisker is triggered in one of these tasks, the routine would GOTO some other routine that would look again at the whiskers, act appropriately (back up or back up and turn a little), then RETURN to start again with the PING scan.
Sign In or Register to comment.