Você está na página 1de 20

Ping)))Dar - a Radar Style Display :: Parallax Forums http://forums.parallax.com/forums/default.aspx?

f=6&m=129099

Forum Quick Jump


Parallax Forums > Public Forums > Stamps In Class > Ping)))Dar - a Radar Style Display
Stamps In Class

[ << Previous Thread | Next Thread >> ] | Show Newest Post First ]

Andy Lindsay (Parallax) Posted 6/5/2006 4:32 PM (GMT -7)


Forum Moderator

Ping)))Dar – A Radar Style Display (Updated!)


This activity features a program that displays what the Boe-Bot detects in the Debug Terminal as it
sweeps the Ping))) rangefinder back and forth. Figure 1 shows an example with a cup and box set in the
Boe-Bot's 180° field of detection along with their signatures displayed in the Debug Terminal.
Experimenting with this program will help you better understand what the Boe-Bot can and cannot
detect with the Ping))) Ultrasonic Rangefinder and Mounting Bracket, which is important for writing
programs that navigate with this object detection system.

Date Joined Jul 2004 View Video Introduction – Ping)))Dar


Total Posts : 1046

Figure 2 shows a Boe-Bot assembled with the Ping))) Ultrasonic Rangefinder and Mounting Bracket
kits. The mounting bracket kit makes it possible for the Boe-Bot to swivel the Ping))) rangefinder and
measure object distances across a 180° field in front of it.

Figure 1: Seeing what the Boe-Bot Detects with Ping)))Dar.bs2

Figure 2: Boe-Bot with Ping))) Ultrasonic Rangefinder and Mounting Bracket Kit

1 de 20 3/14/2009 12:12 PM
Ping)))Dar - a Radar Style Display :: Parallax Forums http://forums.parallax.com/forums/default.aspx?f=6&m=129099

Getting Started
This project contains advanced topics, not intended for Boe-Bot beginners. Before continuing, it is
highly recommended you complete the following tasks in order to gain a better understanding on how
this program operates:

√ Complete all activities in What’s a Microcontroller


√ Complete at minimum Chapters 1-4 in Robotics with the Boe-Bot
√ Complete at minimum Chapters 1-3 in Smart Sensors and Applications
√ Download the product documentation and assembly instructions for the PING)))
Bracket Kit

Parts Required
(1) Fully assembled and tested Boe-Bot® Robot
(1) Ping))) Ultrasonic Rangefinder
(1) Ping))) Mounting Bracket Kit

Polar to Cartesian Coordinate Conversion


Ping)))Dar.bs2 will scan a 180° field in front of the Boe-Bot by incrementally rotating the Ping)))
Mounting Bracket and then taking a distance measurement. It will do this rapidly enough that the
mounting bracket servo will appear to just be rotating from right to left and back again as it updates the
Debug Terminal display.

For each measurement in a given sweep, the information Ping)))Dar.bs2 will have to work with is a
distance measurement (d) and an angle measurement (θ) as shown in Figure 3. When coordinates are
given in terms of distance and angle, they are called polar coordinates. These coordinates are typically
expressed in parentheses like this: (d θ). When telling those coordinates to someone, you would
normally say, "d at an angle of theta." In order to display these measurements graphically in the Debug
Terminal, Ping)))Dar.bs2 will have to convert these polar coordinates to Cartesian (x, y) coordinates.
That way, the DEBUG CRSRXY, x, y, "*" command can be used to graphically display the measurement
by positioning the cursor and then placing an asterisk.

Figure 3: Object's Polar and Cartesian Coordinates

2 de 20 3/14/2009 12:12 PM
Ping)))Dar - a Radar Style Display :: Parallax Forums http://forums.parallax.com/forums/default.aspx?f=6&m=129099

Calculating the x and y axis components given polar coordinates is not difficult. The equations for x and
y are shown below. The x-axis component involves multiplying the distance by the cosine of the angle,
and the y component is the distance multiplied by the sine of the angle.

Since the BASIC Stamp is an integer math processor, the programming for making these conversions is a
little different from what you might expect with a PC programming language. Ping)))Dar.bs2's
Polar_To_Cartesian subroutine is explained in Advanced Topic − Inside the Polar_To_Cartesian
Subroutine.

Assembly and Electrical Connections


√ Follow the instructions in the Ping))) Mounting Bracket Documentation for making the
mechanical and electrical connections to the servo and Ping))) Ultrasonic rangefinder. When you
are done, the servo will be connected to the Board of Education's servo port 14, and the Ping)))
rangefinder will be connected to port 15.

Mounting Bracket Adjustments


Keep in mind that Ping)))Dar.bs2 will measure distances and angles. Recall from What's a
Microcontroller that a PULSOUT command's Duration argument sends a message to a standard servo
telling it what rotational position to hold. In other words, the PULSOUT command's Duration argument tells
the Ping))) mounting bracket's standard servo what angle to turn to. Ping)))Dar.bs2 will need to convert
the PULSOUT command's Duration argument to a binary radian measurement before the program can do
polar to Cartesian coordinate conversion. Since the object's position is dependent on good distance and
angle measurements, it will be important mechanically adjust and calibrate your Ping))) Mounting
Bracket system so that the program's PULSOUT commands can sweep it from 0° (to the right) to 180° (to
the left). The first adjustment step toward good Ping))) Mounting Bracket servo angular control is
making sure that the Ping))) rangefinder is mounted so that the servo points the Ping))) rangefinder
straight ahead when the servo receives 1.5 ms center pulses.

√ Run PingServoCenter.bs2.
√ Make sure the Board of Education's 3-position power switch is set to position-2.
√ Check to see whether the mounting bracket servo points the Ping))) rangefinder straight
ahead on the Boe-Bot.
√ If it does, then continue to the Software Calibration for 180° Sweep section. Otherwise,

3 de 20 3/14/2009 12:12 PM
Ping)))Dar - a Radar Style Display :: Parallax Forums http://forums.parallax.com/forums/default.aspx?f=6&m=129099

keep following the checklist instructions here.


√ Make sure CenterPing.bs2 is running for the remaining checklist instructions in this section.
√ Start by removing the screw that connects the servo horn to the output shaft shown in
Figure 4 (a).
√ Pull upward on the Ping))) rangefinder. The horn, which is attached to the Ping)))
rangefinder with screws should slide up and off the servo's output shaft, also shown in Figure 4
(a).
√ Orient the Ping))) rangefinder so that it is pointing straight ahead as shown in Figure 4 (b).
√ Slide the servo horn back onto the output shaft.

Perfect alignment may not be possible, so choose the closest to straight ahead.
If the teeth on the output shaft do not line up with the servo horn when it is pointing exactly straight ahead, there will be two ways that the
servo horn lines up: with the Ping))) pointing slightly to the left, or slightly to the right. Choose position that is as closest to straight ahead. You
will then be able to fine tune straight-ahead by adjusting the screws that attach the servo to the Boe-Bot chassis.

√ Screw the screw back in that holds the servo horn to the Ping))) mounting bracket.

Figure 4: Mounting the Ping))) Rangefinder so that It Points Straight Ahead

√ To adjust for any slight error caused by the output shaft to servo horn gear teeth alignment,
start by loosening the screws that attach the servo to the Boe-Bot chassis.
√ Now, you will have some wiggle room to rotate the servo's housing slightly to make up for
any offset resulting from the alignment of the servo horn and output shaft's teeth.
√ Make sure to re-tighten all the screws when you are done.

Example Program – PingServoCenter.bs2

' Smart Sensors and Applications - PingServoCenter.bs2


' Send 1.5 ms "center" pulses to the servo the Ping))) rangefinder
is
' attached to.

4 de 20 3/14/2009 12:12 PM
Ping)))Dar - a Radar Style Display :: Parallax Forums http://forums.parallax.com/forums/default.aspx?f=6&m=129099

' {$STAMP BS2}


' {$PBASIC 2.5}

PingServo PIN 14 ' Servo directs Ping)))

Center CON 750 ' Center/0-degree pulse duration


BtwnPulses CON 20 ' ms between servo pulses

DO ' Main loop


PULSOUT PingServo, Center ' Center signal -> Ping))) servo
PAUSE BtwnPulses ' 20 ms delay between pulses
LOOP ' Repeat main loop

Software Calibration for 180° Sweep


The Boe-Bot needs to be able to point the Ping))) rangefinder from 0° (to the right) to 180° (to the left)
as shown in Figure 5. The Ping))) mounting bracket's servo should direct the ping to 0° when it receives
0.5 ms pulses and to 180° when it receives 2.5 ms pulses. Since the PULSOUT command times pulse
durations in terms of 2 μs units, the command PULSOUT 14, 250 will cause the servo to rotate the Ping)))
rangefinder to 0°, and PULSOUT 14, 1250 will direct it to 180°.

Figure 5: Angle and Ping))) Rangefinder Direction

The TestPingDirection.bs2 program declares LimitRight and LimitLeft as constants equal to 250 and
1250. The program also declares PingServo to be PIN 14 and Center to be 750. So the command
PULSOUT PingServo, LimitRight should direct the rangefinder 0° to the right, and PULSOUT
PingServo, LimitLeft direct the rangefinder 180°. Also, PULSOUT PingServo, Center should point the
rangefinder straight ahead.

If the LimitLeft and LimitRight constants do not make the servo point the Ping))) rangefinder to 0° and
180°, the program's CON directive values should be adjusted. For LimitRight, values smaller than 250
will cause the servo to rotate further in the clockwise direction (to the right) while values larger than 250
will cause it to rotate to a position closer to center. Likewise, values greater than 1250 will cause the
servo to rotate further in the counterclockwise direction (to the left) while values smaller that 1250 will
cause it to rotate to a position closer to center.

√ Run TestPingDirection.bs2 and make sure the servo points the Ping))) rangefinder to 0°,
then to 180°, then to 90° (straight ahead).
√ If the servo doesn't point to 0°, adjust the LimitRight constant accordingly. Values less
than 250 will result in more clockwise rotation and values greater than 250 will result in less
clockwise rotation.

5 de 20 3/14/2009 12:12 PM
Ping)))Dar - a Radar Style Display :: Parallax Forums http://forums.parallax.com/forums/default.aspx?f=6&m=129099

√ If the servo doesn't point to 180° to the left, adjust the LimitLeft constant accordingly.
Values greater than 1250 will result in more counterclockwise rotation, and values less than 1250
will result in less counterclockwise rotation.
√ Update these CON directives, and make notes of the values you used. These same CON
directives will have to be updated in this activity's Ping)))Dar.bs2 program and also in the next
activity's GotoClosestObject.bs2 program.

Example Program – TestPingDirection.bs2

' Smart Sensors and Applications - TestPingDirection.bs2


' Point the Ping))) 0-degrees (to the right), then 180-degrees (to
the right),
' then straight ahead.

' {$STAMP BS2}


' {$PBASIC 2.5}

PingServo PIN 14 ' Servo directs


Ping)))

LimitLeft CON 1250 ' Ping servo


90-degrees left
LimitRight CON 250 ' Ping servo
90-degrees right

Center CON 750 ' Center/0-degree


pulse duration
BtwnPulses CON 20 ' ms between servo
pulses
counter VAR Byte ' Loop index

DEBUG "Look to 0-degrees (right).", CR


FOR counter = 1 TO 100 ' 100 pulses 0-degrees
(right)
PULSOUT 14, LimitRight
PAUSE 20
NEXT

DEBUG "Look to 180-degrees (left).", CR


FOR counter = 1 TO 100 ' 100 pulses 180-degrees
(left)
PULSOUT 14, LimitLeft
PAUSE 20
NEXT

DEBUG "Look to 90-degrees (straight ahead).", CR


FOR counter = 1 TO 100 ' 100 pulses 90-degrees
(ahead)
PULSOUT 14, Center
PAUSE 20
NEXT

END

Testing Ping)))Dar
One of the most important things about Ping)))Dar.bs2 is that it will help give you a better idea of what
the Boe-Bot "sees" as it sweeps the Ping))) rangefinder from left to right. Make sure to test a variety of
objects at a variety of distances. Keep in mind also that the program is imposing a 100 cm distance limit
on measurements to make the display more convenient.

Before running the program, the LimitRight and LimitLeft CON directives should be updated so that the
servo that directs the Ping))) rangefinder to sweep from 0° to 180° using the values you determined with
TestPingDirection.bs2.

Ping)))Dar converts the PULSOUT command's Duration arguments into binary radian servo rotation angle

6 de 20 3/14/2009 12:12 PM
Ping)))Dar - a Radar Style Display :: Parallax Forums http://forums.parallax.com/forums/default.aspx?f=6&m=129099

measurements with the help of a constant and the ** operator. Let's assume that LimitRight is 250 and
LimitLeft is 1250. The main routine in Ping)))Dar.bs2 has code that sweeps the PULSOUT command's
Duration argument from 250 to 1250 in increments of 15. As shown in Figure 6, that's about 2.7° for
each increment of 15, which is pretty close to 2 brads (2.8125°).

Figure 6: Rotation Angle vs. PULSOUT Duration

Mapping the PULSOUT command's duration argument to the number of brads the servo has rotated
involves the ** operator. In the next example program, the command that does the job is angle =
pingDir - LimitRight ** PingDirToAngle. The pingDir variable is used in the command PULSOUT
PingServo, PingDir to point the Ping))) rangefinder to 0 brads (0°), then 2 brads, then 4 brads and so
on all the way to 128 brads (180°). As it does this, the pingDir variable starts at LimitRight (250), then
265, then 280, and so on up through LimitLeft (1250).

Since the expression angle = pingDir - LimitRight ** PingDirToAngle subtracts LimitRight from
pingDir before the ** operation, the value ** scales will range from 0 through 1000 instead of 250 to 1250. The
PingDirToAngle constant has to be the right number of 65535ths to scale this range of 0 to 1000 into 0 through 128
brads. This is another job for the ** scale constant equation introduced in Chapter 3, Activity #3 in Smart Sensors and
Applications

Here is an example of calculating PingDirToAngle constant when LimitRight is 250 and LimitLeft is
1250. Make sure to follow along because you will need to recalculate this constant based on the
LimitLeft and LimitRight constants you determined for your mounting bracket system with
TestPingDirection.bs2. The number of output scale elements is 0 through 128, which is 129 elements
since the range includes zero. Next, LimitLeft − LimitRight = 1250 − 250 = 1000. Again, we are
talking about a range that's inclusive of 0, so there are really 1001 elements in the input scale.

Substituting 129 and 1001 into the ** scale constant equation yields:

7 de 20 3/14/2009 12:12 PM
Ping)))Dar - a Radar Style Display :: Parallax Forums http://forums.parallax.com/forums/default.aspx?f=6&m=129099

Why is 1 subtracted from the denominator?


The */ operators and ** operator always round down to the next integer. Subtracting 1 from the
denominator, corrects these rounding errors and, on the average, makes value **
ScaleConstant sort the input scale elements to their most correct output scale elements. To
learn more about how this works, see Chapter 3, Activity #3 in Smart Sensors and Applications.

Example Program – Ping)))Dar.bs2


Some of the checklist instructions below involve updating CON directives that you determined with
TestPingDirection.bs2. While they are not necessarily crucial to this program, they will be crucial for
GotoClosestObject.bs2, the Boe-Bot Ping))) Mounting Bracket navigation program in the next activity.

√ Open Ping)))Dar.bs2 with your BASIC Stamp Editor.


√ Update the LimitRight and LimitLeft CON directives in the program to tune the 0° right and
180° left pulse widths.
√ If you changed either LimitLeft or LimitRight, calculate the value needed for the
PingDirToAngle CON directive with the PingDirToAngle equation just discussed. Make sure to
update this value in your program too.
√ Make notes of all these CON directives because you will need to substitute them into the next
activity's GotoClosestObject.bs2 example program.
√ Run the program and maximize your Debug Terminal so that it takes up the entire computer
screen.
√ Observe the Debug Terminal as you try placing a variety of objects at various distances
from the Boe-Bot at various locations in its 180° field of detection.
√ Make sure to try the suggestions in the section after the example program entitled Your
Turn - Understanding what the Boe-Bot Does and Does not S" ee". It brings to light some of this
setup's capabilities and drawbacks, and they turn out to be important for writing navigation
programs.
' -----[ Title
]--------------------------------------------------------------
' Smart Sensors and Applications - Ping)))Dar.bs2
' Display radar style object distance measurements in the Debug
Terminal.
' as the Boe-Bot sweeps the Ping))) Mounting Bracket servo from
right
' (0-degrees) to left (180-degrees).

' {$STAMP BS2} ' Target device =


BASIC Stamp 2
' {$PBASIC 2.5} ' Language =
PBASIC 2.5

' -----[ I/O Definitions


]----------------------------------------------------

PingServo PIN 14 ' Servo that directs


Ping)))
Ping PIN 15 ' Ping))) sensor
signal pin

8 de 20 3/14/2009 12:12 PM
Ping)))Dar - a Radar Style Display :: Parallax Forums http://forums.parallax.com/forums/default.aspx?f=6&m=129099

' -----[ Constants


]----------------------------------------------------------

LimitLeft CON 1250 ' Bracket 90-degrees


LimitLeft
LimitRight CON 250 ' Bracket 90-degrees
LimitRight
PingDirToAngle CON 8454 ' Servo pulse -> angle
with **

CmConstant CON 2260 ' Echo time -> cm with


**
SinCosTo256 CON 517 ' For */ -127..127 ->
-256..256
Increment CON 15 ' Servo PULSOUT
increment value
Negative CON 1 ' Negative sign
Positive CON 0 ' Positive sign

' -----[ Variables


]----------------------------------------------------------

pingDir VAR Word ' Pulse duration ->


direction
time VAR Word ' Ping))) echo time
distance VAR Time ' Object distance
x VAR Word ' x Debug cursor
coordinate
y VAR Word ' y Debug cursor
coordinate
angle VAR Byte ' Angle from
LimitRight in brads
counter VAR angle ' Loop counter
sweepInc VAR Nib ' Sweep increment
sweepDir VAR Bit ' Increment/decrement
pingDir
xSign VAR Bit ' x variable sign
ySign VAR xSign ' Stores sign of y
variable
nsign VAR Bit ' Numerator sign
dsign VAR Bit ' Denominator sign

' -----[ Initialization


]-----------------------------------------------------

pingDir = LimitRight ' Start servo at


0-degrees

FOR counter = 1 TO 40 ' Initialize servo


position
PULSOUT PingServo, pingDir
PAUSE 20
NEXT

sweepInc = Increment ' Set the sweep


increment

' -----[ Main Routine


]-------------------------------------------------------

DO

IF pingDir <= LimitRight THEN ' Refresh display if


far right
DEBUG CLS, CRSRXY, 50, 25, "X"
ENDIF

9 de 20 3/14/2009 12:12 PM
Ping)))Dar - a Radar Style Display :: Parallax Forums http://forums.parallax.com/forums/default.aspx?f=6&m=129099

GOSUB Sweep_Increment ' Move servo by


sweepInc

' Calculate angle from far right in brads.


angle = pingDir - LimitRight ** PingDirToAngle

GOSUB Get_Ping_Cm ' Get cm measurement


distance = distance MAX 100 / 4 ' Scale for Debug
Terminal

GOSUB Polar_To_Cartesian ' distnace @ angle ->


(x, y)

x = x * 2 ' 2 spaces for


every 1 CR

DEBUG CRSRXY, 50 + x, 25 - y, "*" ' Display (x, y)


coordinate

LOOP

' -----[ Subroutine - Get_Ping_Cm


]-------------------------------------------

' Gets Ping))) rangefinder measurement and converts time to


centimeters.
' Distance may be declared as time to save variable space.

Get_Ping_Cm:

PULSOUT Ping, 5
PULSIN Ping, 1, time
distance = time ** CmConstant

RETURN

' -----[ Subroutine - Polar_To_Cartesian


]------------------------------------

' Calculates x and y (Cartesian coordinates) given distance and


angle
' (polar coordinates).

Polar_To_Cartesian:

' Calculate x coordinate.


x = COS angle ' Polar to Cartesian
xSign = x.BIT15 ' Store sign bit
x = ABS(x) */ SinCOsTo256 ' Polar to Cartesian
continued
x = distance */ x
IF xSign = negative THEN x = -x ' Correct sign with
sign bit

' Calculate y coordinate.


y = SIN angle ' Polar to Cartesian
ySign = y.BIT15 ' Store sign bit
y = ABS(y) */ SinCOsTo256 ' Polar to Cartesian
continued
y = distance */ y
IF ySign = negative THEN y = -y ' Correct sign with
sign bit

RETURN

10 de 20 3/14/2009 12:12 PM
Ping)))Dar - a Radar Style Display :: Parallax Forums http://forums.parallax.com/forums/default.aspx?f=6&m=129099

' -----[ Subroutine - Sweep_Increment


]---------------------------------------

' Increment/decrement the position of the servo that directs the


Ping)))
' rangefinder. When pingDir goes outside either LimitRight or
LimitLeft,
' the sweep direction toggles.

Sweep_Increment:

' Change sweepDir for adding/subtracting increment if at


rotation limit.
IF pingDir <= LimitRight THEN
sweepDir = Positive
ELSEIF pingDir >= LimitLeft THEN
sweepDir = Negative
ENDIF

' Add/subtract increment to/from pingDir.


IF sweepDir = negative THEN
pingDir = pingDir - sweepInc
ELSEIF sweepDir = Positive THEN
pingDir = pingDir + sweepInc
ENDIF

' Send positioning pulse to Ping))) Mounting Bracket servo.


PULSOUT PingServo, pingDir

RETURN

Your Turn - Understanding what the Boe-Bot does and does not "See"
To understand what your Boe-Bot does and does not "see" with the Ping))) rangefinder, a few
experiments are in order. Here are some questions that can be answered with Ping)))Dar.bs2 and various
objects placed in the Boe-Bot's field of detection.

√ If you place one object behind another object, can it see the object in back?
√ How far do you have to rotate a flat object before it is no longer visible to Ping)))?
√ Start with one or two cylindrical objects about 3 ft (91 cm) apart and 2 ft (61 cm) from the
front of the Boe-Bot.

For best results, use tall cylindrical objects, such as soda cans, water bottles, etc. Sheets of
paper can also be conveniently rolled into 8.5 inch (21.5 cm) tall by 2 to 3 inch (5 to 7.5 cm)
diameter cylinders with a couple pieces of tape.

√ As you move the objects closer to each other, how close can they be to each other before
they appear to be one object in the Debug Terminal?
√ If you keep the objects the same distance from each other but move them closer to the front
of the Boe-Bot, is the gap between them detected again at some point?
√ To what extent does setting the Increment constant is set to a smaller value help the
Boe-Bot detect the gap between objects?

How Ping)))Dar.bs2 Works


The initialization routine applies forty pulses to make sure the servo turns and starts 0° (far-right). In this
program, the FOR...NEXT loop is only used once. In GoToClosestObject.bs2 in the next activity, the loop
is used frequently to point the Ping))) rangefinder in various directions, so in that program, the loop is
placed in a subroutine called Point_At_PingDir. One other initialization detail is setting the
sweepInc variable equal to the Increment constant (15). This value is used by the Sweep_Increment

11 de 20 3/14/2009 12:12 PM
Ping)))Dar - a Radar Style Display :: Parallax Forums http://forums.parallax.com/forums/default.aspx?f=6&m=129099

subroutine to rotate the Ping))) Mounting Bracket servo slightly between each distance measurement.

pingDir = LimitRight ' Start servo at 0-degrees

FOR counter = 1 TO 40 ' Initialize servo position


PULSOUT PingServo, pingDir
PAUSE 20
NEXT

sweepInc = Increment ' Set the sweep increment

The main routine's DO...LOOP refreshes the Debug Terminal display after each right-left sweep. As the
main routine's DO...LOOP repeats, the first thing the program does is clear the Debug Terminal and place
the "X" character at 50 spaces over and 25 carriage returns down. This "X" indicates the Boe-Bot's
position.

IF pingDir <= LimitRight THEN ' Refresh display if far right


DEBUG CLS, CRSRXY, 50, 25, "X"
ENDIF

Next, the program calls the Sweep_Increment subroutine, which adjusts the Ping))) Mounting Bracket's
servo slightly each time it gets called. Calling this subroutine repeatedly each time through the main
routine's DO...LOOP results in the back and forth sweeping motion. This subroutine uses the pingDir
variable to direct the servo.

GOSUB Sweep_Increment ' Move servo by sweepInc

The Sweep_Increment subroutine modified the value of pingDir, and then used it in a PULSOUT
command's Duration argument to point the Ping))) Mounting Bracket servo in a new direction. That
means we can use the value of pingDir to determine the angle to which the Ping))) rangefinder is
pointing in terms of binary radians.

Figure 7 shows a few examples of how the PULSOUT command's Duration argument relates to the Ping)))
Mounting Bracket servo's rotational position. For example, when pingDir is LimitRight, (250), the
angle is 0°, which is 0 binary radians (brads). When pingDir is 500, the angle is about 45°, or 32 brads.
Likewise, pingDir can be 750 or1000, and the respective servo angles will be 90° (64 brads) and 135°
(96 brads). By the time pingDir gets to LimitLeft (1250), the angle will be 180° = 128 brads.

Figure 7: PULSOUT Duration Argument vs. Rotation Angle

Here is the command that converts pingDir, which ranges from LimitRight to LimitLeft (250 to 1250)
to angle, which ranges from 0 to 128 brads. Note that this is the same kind of equation we used in
Chapter 3, Activity #3 and #4.

12 de 20 3/14/2009 12:12 PM
Ping)))Dar - a Radar Style Display :: Parallax Forums http://forums.parallax.com/forums/default.aspx?f=6&m=129099

' Calculate angle from far right in brads.


angle = pingDir - LimitRight ** PingDirToAngle

Without parentheses, PBASIC executes operators from left to right. So the command angle = pingDir
- LimitRight ** PingDirToAngle first subtracts LimitRight from pingDir. This resulting value, which
could be anywhere from 0 through 1000, has the ** PingDirToAngle operation performed on it. Since
PingDirToAgle is 8454 in the example program, it means a value from 0 through 1000 gets multiplied by
8454 / 65536. If pingDir stores 1000, the result is 128.9978, and the ** operator rounds it down to 128,
which is the correct number of brads assuming the servo is in fact pointing left (180° from far right).
Likewise, (750 - 250) × 8454 / 65536 results is 64.4989, which rounds down to 64 brads, which is 90°,
and the servo should be pointing straight ahead.

Next, the distance of the object at the angle the Ping))) Mounting Bracket servo is pointing to gets
measured and scaled to a centimeter measurement. This centimeter measurement is further scaled down
by 1/4 of its actual value to make it fit more conveniently in a Debug Terminal maximized in a typical
1024 by 768 pixel monitor.

GOSUB Get_Ping_Cm ' Get cm measurement


distance = distance MAX 100 / 4 ' Scale for Debug Terminal

Now, we know the object's distance and angle relative to the Ping))) rangefinder on the front of the
Boe-Bot. The problem is that these values are polar coordinates (distance angle), but the program needs
to express them in terms of Cartesian coordinates (x, y) for Debug Terminal display. The Cartesian
coordinates, are necessary for displaying the asterisks that denote the object's position in the Debug
Terminal with the DEBUG command's CRSRXY formatter. So, the program calls the Polar_To_Cartesian
subroutine. Given distance and angle, the subroutine calculates the corresponding x and y coordinates.

GOSUB Polar_To_Cartesian ' distance @ angle -> (x, y)

Before repeating the main routine's DO...LOOP, the last step is to plot an asterisk at the (x, y) coordinate.
x will be a value that ranges from about -50 to 50. So, the x-coordinate in DEBUG CRSRXY is 50 + x. The
y-coordinate will range from 0 to 25. However, CRSRXY will plot the value in terms of carriage returns
down from the top line of the Debug Terminal. What we really want is carriage returns upward from the
"X" that was plotted at 50 spaces over and 25 carriage returns down. That's why the CRSRXY formatter's
y-coordinate is 25 - y. As y gets larger, the asterisk is plotted closer to the X at (50, 25). As y gets
smaller, the asterisk is plotted closer to the top of the Debug Terminal.

' Display asterisk at x,y coordinate.


DEBUG CRSRXY, 50 + x, 25 - y, "*"

Advanced Topic − Inside the Polar_To_Cartesian Subroutine


Please see additional content posted below.

Post Edited By Moderator (Jessica Uelmen (Parallax)) : 3/13/2009 3:35:25 PM GMT

Image Attachment :
Image Attachment :
Image Attachment :
Image Attachment :

BoeBotSees.JPG 17KB
(image/pjpeg) FullyAssembled.JPG 31KB
This image has been viewed (image/pjpeg) PingMounted.JPG 40KB
201 time(s). This image has been viewed PolarToCartesian.JPG 13KB
(image/pjpeg)
200 time(s). (image/pjpeg)
This image has been viewed
This image has been viewed
201 time(s).
200 time(s).
Image Attachment :

Direction.JPG 48KB
(image/pjpeg)

13 de 20 3/14/2009 12:12 PM
Ping)))Dar - a Radar Style Display :: Parallax Forums http://forums.parallax.com/forums/default.aspx?f=6&m=129099

This image has been viewed


201 time(s).
RinksCustoms Posted 6/19/2006 12:49 PM (GMT -7)
Tickling critical mass... Back to Top
Friggin COOL!!! Interlinked with an infared detection system, and maybe a camera system (poke around the
propeller forums), this qould make for one heck of a robotic guidance system. Possibly better than the ones i see
in prototype on TV used to control real cars.

Date Joined Nov 2005


Total Posts : 403 Back to Top

George Sutton Posted 9/19/2006 9:37 AM (GMT -7)


Registered Member
Andy,

I am unable on multiple attenpts to download the attached file(s) in the ZIP attachment. Are the code and PDF
still available? Thanks.

Back to Top
Date Joined Jul 2004
Total Posts : 12

Andy Lindsay (Parallax) Posted 9/19/2006 6:40 PM (GMT -7)


Forum Moderator

Advanced Topic − Inside the Polar_To_Cartesian Subroutine


Given a distance at an angle (d θ), you can calculate the x and y coordinates (x, y) with the
help of a calculator and these two formulas:

Calculating x and y with the BASIC Stamp involves the SIN, COS, and */ operators.

√ Look up and review the */, SIN and COS operators in either the BASIC Stamp Manual
Date Joined Jul 2004 or the BASIC Stamp Editor's Help feature
Total Posts : 1046

Given an angle in brads, PBASIC's COS operator returns 127 to 0 to -127 to 0 as the brad angle
goes from 0 to 64 to 128 to 192. Calculating the cosine from 0° to 90° to 180° to 270° with a
calculator will yield results that range from 1 to 0 to -1 and back to 0 again. The SIN operator
behaves similarly, returning values that range from 0 to 127 to 0 to -127 as the angle in brads goes
from 0 to 64 to 128 to 192. Again, if you calculate the sine of angles from 0° to 90° to 180° to 270°
with a calculator, you will see that the actual sine values range from 0 to 1 to 0 to -1. The problem
here is that we want to multiply distance results for SIN and COS values that range from -1 to 1, not
-127 to 127.

One way around this is creative use of the */ operator. This operator multiples a value by a number
of 256ths. By using the */ operator twice, we can first scale a value in the range of -127 through
127 up to a range from -256 through 256. Then, we can use */ again to multiply that result by the
distance. The second time, the */ operator will be multiplying the distance variable by sine and
cosine values that are in terms of a number of 256ths. The result will be very close to what you
would get from a calculator, multiplying the distance sine and cosine value that range from -1
through 1.

14 de 20 3/14/2009 12:12 PM
Ping)))Dar - a Radar Style Display :: Parallax Forums http://forums.parallax.com/forums/default.aspx?f=6&m=129099

To scale a value that will fall in the range of -127 through 127 to its equivalent in the range from
Aristides Alvarez (Parallax) -256 to 256,
Posted we'll use
9/20/2006 the
7:28 scale-7)constant equation introduced in Chapter 3, Activity #5 in Smart
AM*/(GMT
Forum Moderator
Sensors and Applications.
George,

You should be able to download the zipped file from the link in the first post.

If just clicking on the link doesn't work, please try the following:
1- right click (contextual) on the link
2- select "Save Target as..."
3- In the "Save As" window specify where you want the file to be saved in your computer.
4- Once you have the file in your computer you can just UnZip it and see the content.
Since the input range is -127 through 127, that's 255 possible values. The output range is going to
Regards,
be -256 to 256, which is 513 possible values.
Post Edited By Moderator (Jessica Uelmen (Parallax)) : 3/13/2009 3:33:14 PM GMT
Date Joined Jul 2004
Total Posts : 315
Image Attachment : Image Attachment :
Image Attachment : Image Attachment :

(4)scaleconstant.JPG 7KB (5)outputinputscale.JPG


(2)outputinputscale.JPG (image/pjpeg)
To calculate a constant we'll call
7KB (image/pjpeg) SinCosTo256 , we'll substitute
This image has been viewed
4KB255 and 513 into the */(6)SinCosTo256.JPG
(image/pjpeg) scale(image/pjpeg) 6KB
constant equation:
This image has been viewed This image has been viewed
182 time(s). 178 time(s). This image has been viewed
197 time(s). 182 time(s).
Image Attachment :

(3)PingDirToAngle.JPG
12KB (image/pjpeg)
This image has been viewed
10 time(s).
Now that we know SinCosTo256 has to be 517, here is the routine for polar to Cartesian coordinate conversion.
Back to Top
Notice that the sign of both the cosine and sine calculations are stored in the xSign and ySign bits, and the rest of
the calculations are done with the absolute values of x and y. That's because /, */, //, and ** were designed to be
used with positive integers only. So, the absolute value of each measurement is taken first. Then the rest of the
operations are done on the positive integer values, and the sign of the x and y results are restored at the end by
johnsrobotics Posted 9/20/2006 1:07 PM (GMT -7)
Spining Roboticist IF...THEN statements.
I have an odd problem downloading anything from the parallax website in .zip format. I'm using winXP pro sp2.
' Calculate
The file always downloadsxwithcoordinate.
no extension, but if I add ".zip" to the end of the filename, windows automatically
recognizes
x it= asCOS
a .zip archive...maybe that would help?
angle ' Polar to Cartesian
xSign = x.BIT15 ' Store sign bit
x = ABS(x) */ SinCOsTo256 ' Polar to Cartesian continued
x = distance */ x
IF xSign = negative THEN x = -x ' Correct sign with sign bit

' Calculate y coordinate.


Date Joined Aug 2004 y = SIN angle ' Polar to Cartesian
Total Posts : 26
ySign = y.BIT15 ' Store sign bit
y = ABS(y) */ SinCOsTo256 Back to Top
' Polar to Cartesian continued
y = distance */ y
IF ySign = negative THEN y = -y ' Correct sign with sign bit

Kevin Wood Posted 9/20/2006 1:38 PM (GMT -7)


Registered Member
Andy,
Post Edited By Moderator (Jessica Uelmen (Parallax)) : 3/13/2009 3:31:41 PM GMT
Can you give a timeframe for the release of the text/course?
Date Joined Aug 2004
Total Posts : 768 Thanks.
Image Attachment : Image Attachment :
Image Attachment : Image Attachment :

sincos.JPG 2KB (1)scaleconstant.JPG


(image/pjpeg) 7KB (image/pjpeg)
DegreesVsPULSOUT.JPG
This image has been This image has been
16KB (image/pjpeg) PULSOUTDurationVsRotationAngle.JPG
viewed 200 time(s). viewed 10 time(s).
This image has been viewed 21KB (image/pjpeg)
196 time(s). This image has been viewed 199 time(s). Back to Top

Image Attachment :
angle.JPG 1KB (image/pjpeg)
Back to Top
George Sutton Posted 9/20/2006 1:42 PM (GMT -7)
Registered Member
Aristides and johnsrobotics,

Thanks for the ideas. I tried everything that you have recommended, to no avail. It shows a "valid" ZIP file, with
a 1.11MB file size. But when opened, it shows "0 files and 0 bytes". Latest version of WinZip, never had this
problem with all the thousands of zip downloads I have accessed. But thanks for the ideas. And Andy has
provided me with a solution. Thanks to Andy as well!

15 de 20 3/14/2009 12:12 PM
Ping)))Dar - a Radar Style Display :: Parallax Forums http://forums.parallax.com/forums/default.aspx?f=6&m=129099

Back to Top
Date Joined Jul 2004
Total Posts : 12

Aristides Alvarez (Parallax) Posted 9/20/2006 1:58 PM (GMT -7)


Forum Moderator
Hello Kevin,

Thanks for your interest. Andy is totally done with this book. Now it’s in the editorial pipeline. Since the release of
the Propeller™ microcontroller we’re been assigning higher priority to Propeller related books, as Propeller Manual
and Hydra manual.

Our editor is getting close to finishing a huge job right now and next in the list is Smart Sensors and Applications.
We are trying to finish this Stamps in Class book as soon as possible.

As soon as we have a firm deadline we’re going to announce it in this forum (meanwhile you can keep accessing
the pieces that form this book through forum posts as this one and the ones in this thread
http://forums.parallax.com/forums/default.aspx?f=6&m=98784).

Regards,
Date Joined Jul 2004
Total Posts : 315
Aristides Alvarez
Education and Technical Support Manager
Parallax, Inc.

Back to Top

bulkhead Posted 9/20/2006 7:27 PM (GMT -7)


Registered Member
This is intersting, I've tried this out and it didn't work. Based on my experimenting, a cup about 1.5feet in front of
the BOE would be detected in about 90 degrees of the sensor's 180 degree sweep. This is consistent with the
data given in the instruction manual which I believe says the width of the detection beam is from 20 to 40
Date Joined Sep 2005 degrees (40 degrees being closer objects).
Total Posts : 406
From the picture, this certainly looks to be the case (close range), so how does one get so many data points?
Even if it had a 20 angle beam, objects would "appear" much wider and the accuracy would be much less. That's
why the laser rangers with .3 degree or so detection beam cost over $1000. Can anyone explain this?

Back to Top

Andy Lindsay (Parallax) Posted 9/20/2006 8:55 PM (GMT -7)


Forum Moderator
bulkhead, regarding:

bulkhead said...
This is intersting, I've tried this out and it didn't work. Based on my experimenting, ...

Did you follow the instructions in the PDF and run the source code? If your picture matches mine, but the screen
capture is way different, post it and let's take a closer look. The center of the cup was about 1.5 ft at 135
degrees, and it was conical, 4.25 inches tall, with a 2.5 inch diameter base and a 3.5 inch diameter opening. The
center of the box was about 2.3 ft at 45 degrees, and the box was about 4 inches wide by 6 inches tall by 3
inches deep.

bulkhead said...
From the picture, this certainly looks to be the case (close range), so how does one get so many
data points?
Date Joined Jul 2004
Total Posts : 1046 The PDF and source code explain the details. You can download them by right clicking the Ping)))Dar.zip file at
the beginning of this thread and selecting Save target as... After downloading and unzipping the file, you will
have a PDF with instructions to follow and source code to modify per the PDF and then run and test.

Post Edited (Andy Lindsay (Parallax)) : 9/21/2006 4:21:59 AM GMT

16 de 20 3/14/2009 12:12 PM
Ping)))Dar - a Radar Style Display :: Parallax Forums http://forums.parallax.com/forums/default.aspx?f=6&m=129099

Back to Top

AIman Posted 1/9/2007 1:19 PM (GMT -7)


Registered Member
Andy,

What happens with radar style sonar if the robot is in a sort of enclosure like a closet? Can it detect whats
behind? I would imaging with a full rotation servo and extra wire it could work...

Date Joined Jun 2006


Total Posts : 411

Back to Top

Andy Lindsay (Parallax) Posted 1/9/2007 2:06 PM (GMT -7)


Forum Moderator
It's certainly doable, though extra hardware would be required. With a continuous rotation servo, some type of
feedback mechanism would probably be necessary to know which direction the Ping))) Ultrasonic Distance Sensor
is pointing. The first thing that comes to mind is an encoder.

A "quick and easy" approach would be to stack two standard servos on top of each other. The bottom servo has a
little over 180 degrees in rotation for +/- 90 degrees. The one on top has an additional 180-degrees for +/- 180
degrees. For example, to look behind you to 170 degrees to the left, turn the bottom servo 90 degrees to the left,
and the top servo 80 degrees to the left. For that matter, you could simply direct both of them to turn 85-degrees
left, and potentially save a variable.

Andy Lindsay
Education Department
Parallax, Inc.
Date Joined Jul 2004
Total Posts : 1046 Back to Top

computer guy Posted 6/10/2007 11:57 PM (GMT -7)


Registered Member
It would be cool to get a 3D version of this going on the propeller.
I am not volunteering by the way.

Check out my robot using the propeller robot.tmcp.com.au


If you offer cheap PCB fabrication, perl programming or any other helpful services please email me at.
anthonybmyatt@yahoo.com.au

Date Joined Jan 2007


Total Posts : 821 Back to Top

Bean (Hitt Consulting) Posted 6/11/2007 4:41 AM (GMT -7)

17 de 20 3/14/2009 12:12 PM
Ping)))Dar - a Radar Style Display :: Parallax Forums http://forums.parallax.com/forums/default.aspx?f=6&m=129099

Forum Moderator
AIman said...
Andy,

What happens with radar style sonar if the robot is in a sort of enclosure like a closet? Can it
detect whats behind? I would imaging with a full rotation servo and extra wire it could work...

Andy,
Could you mount two pings back-to-back, and fire them independantly (so they don't confuse each other) ?

Bean.
Date Joined Jul 2004
Total Posts : 5401
“The United States is a nation of laws - poorly written and randomly enforced.” - Frank Zappa
-------------------------------
www.hittconsulting.com

Back to Top

Andy Lindsay (Parallax) Posted 6/11/2007 7:56 AM (GMT -7)


Forum Moderator
computer guy,

That should be interesting. Pan and tilt servos are easy enough. The interesting part will be coming up with an
algorithm that resolves successive measurements into a better representation of the object's shape.

Bean,

Either the Propeller or SX microcontrollers could deliver simultaneous pulses and track the echo times. The
question is, will one Ping))) sensor get confused by the echo from the other Ping))) sensor's echo if it gets there
first. I'm assuming it won't be a problem since the sound is coming from the opposite direction and getting
blocked by the PCB, but we won't know until somebody tests it.

Andy
Date Joined Jul 2004
P.S. Bean, I read your message again after clicking Submit and realized that I misunderstood the question (and
Total Posts : 1046
the point of the question). Yes, if one Ping))) sensor starts after the other has finished its measurement, the
robot will have 360 degree ultrasonic object detection with a BASIC Stamp 2 at the helm.

Andy Lindsay
Education Department
Parallax, Inc.

Post Edited (Andy Lindsay (Parallax)) : 6/11/2007 3:06:07 PM GMT

Back to Top

Jessica Uelmen (Parallax) Posted 3/6/2009 5:17 PM (GMT -7)


Forum Moderator
Hey guys!

We've updated the Ping)))Dar project to include a brief video introduction/demonstration for your viewing
pleasure. You can check it out on YouTube here.

Happy Developing!

Jessica

Jessica Uelmen
Education Department
Parallax, Inc.

Date Joined Oct 2008 Post Edited (Jessica Uelmen (Parallax)) : 3/11/2009 7:15:27 PM GMT
Total Posts : 44
Back to Top

Whit Posted 3/6/2009 6:48 PM (GMT -7)


Registered Member
Nice work Jessica!

Whit+

"We keep moving forward, opening new doors, and doing new things, because we're curious and curiosity keeps
leading us down new paths." - Walt Disney

18 de 20 3/14/2009 12:12 PM
Ping)))Dar - a Radar Style Display :: Parallax Forums http://forums.parallax.com/forums/default.aspx?f=6&m=129099

Back to Top
Date Joined Mar 2007
Total Posts : 857

Jessica Uelmen (Parallax) Posted 3/9/2009 11:50 AM (GMT -7)


Forum Moderator
Thanks, Whit! Always great to get feedback - and positive feedback is even better! :)

Glad you enjoyed it,

Jessica

Jessica Uelmen
Education Department
Parallax, Inc.

Back to Top
Date Joined Oct 2008
Total Posts : 44

nkBotMan Posted Yesterday 8:08 PM (GMT -7)


Registered Member
I was on youtube the other day and found some BOE Bots roaming, using the ping dar for object avoidance. I was
wondering if anyone would have some source code to point me in the right direction on how to go about doing
that.
Date Joined Mar 2009
Total Posts : 1 Thanks in advance,

Nick

Back to Top

Mike Green Posted Yesterday 9:01 PM (GMT -7)


Registered Member
Go to the Parallax webstore page for the PING))) sensor and you'll find links to Roaming with the PING))) sample
code

Date Joined Oct 2004


Total Posts : 10850

Back to Top

Bean (Hitt Consulting) Posted Today 4:51 AM (GMT -7)


Forum Moderator
Andy,
In the very first post you have images of several equations. In each of them the value 66536 is used. I beleive
these should be 65536.

Bean.

19 de 20 3/14/2009 12:12 PM
Ping)))Dar - a Radar Style Display :: Parallax Forums http://forums.parallax.com/forums/default.aspx?f=6&m=129099

-------------------------------
There is a fine line between arrogance and confidence. Make sure you don't cross it...

Date Joined Jul 2004


Total Posts : 5401

Back to Top

Whit Posted Today 7:02 AM (GMT -7)


Registered Member
Nice catch Bean.

It is listed as 65535ths in the text (following fig. 6), 66536 in the equations (also following fig. 6 and the
65535ths note) and then as 65536 further along in the text (following fig. 7).

Whit+

"We keep moving forward, opening new doors, and doing new things, because we're curious and curiosity keeps
leading us down new paths." - Walt Disney

Back to Top
Date Joined Mar 2007
Total Posts : 857

Jessica Uelmen (Parallax) Posted Today 8:43 AM (GMT -7)


Forum Moderator
Thanks guys! We've updated the post.

Jessuca

Jessica Uelmen
Education Department
Parallax, Inc.

Back to Top
Date Joined Oct 2008
Total Posts : 44

[ << Previous Thread | Next Thread >> ]

Forum Information
Currently it is Friday, March 13, 2009 1:07 PM (GMT -7)
There are a total of 327,999 posts in 49,000 threads.
In the last 3 days there were 94 new threads and 721 reply posts. View Active Threads
Who's Online
This forum has 15453 registered members. Please welcome our newest member, firdaus.
31 Guest(s), 18 Registered Member(s) are currently online. Details
jb1311, Bob H, nutson, Bill Drummond, CJMJ, modemman, Jay Kickliter, Carl Hayes, Phil Pilgrim (PhiPi), rjo_, Fred Hawkins, LEDboy, kwinn,
Mightor, Timmoore, SRLM, RobotWorkshop, Bill Chennault

Forum powered by dotNetBB v2.42EC SP2.02


dotNetBB © 2000-2009

Need Support? | Forum Help Manual

20 de 20 3/14/2009 12:12 PM

Você também pode gostar