PDA

View Full Version : Ping sensor and Bot orientation to adversary



Migs
09-14-2007, 03:58 PM
Friends:

Lets say I have a Ping sensor on a servo on my SumoBot. It turns and detects the adversary. How do I tell my Bot to turn to the direction that Ping sensor is facing if it doesn't have an encoder? Is there some way to figure this out?
Think BS2 on BOE as my Bot brains.

Thanks amigos, and good to be here (this is my first post on TRF) -Migs

Matt
09-14-2007, 08:11 PM
Hey Migs,

I think that without encoders you would be left with a solution based upon timing. You can send out a signal to the motors for X seconds to turn the bot. You would have to do some experimenting and testing to find out that Y signal for X seconds turns the bot Z degrees. After you have that you could probably do some fairly accurate turning.

Migs
09-15-2007, 06:15 AM
Hi Matt:

I sent you an e-mail about JIS scredrivers yesterday, hope you got it. OK, on to sensors:

Since you bit my bait lets assume I have an encoder and determine the angle. The problem still remains of detecting the left and right edge of my adversary. Would you do this by making a narrow hood on the sensor? Do you or anyone you have heard of have a solution for when the Bot is in motion? This is one of the areas that interests me and I plan to dedicate some research in this area (If my humble tinkering can so be called).
Also, how do folks deal with the blind spot within the 4 inch range of IR sensors? Is there any near field sensor? Or is mounting them farther back on the Bot the only way? Perhaps you can point me to the best sensored Bot you have seen in your experience so I can ask these questions.

Thanks Matt!, and congratulations on prizing innovation in this field through Trossen.

Migs

Matt
09-16-2007, 11:14 PM
Hi Matt:

>>>I sent you an e-mail about JIS scredrivers yesterday, hope you got it. OK, on to sensors:

Haven't seen it here at home, I should have it at work when I get in tomorrow.

>>Since you bit my bait

Oh, no :rolleyes:

>>> lets assume I have an encoder and determine the angle. The problem still remains of detecting the left and right edge of my adversary. Would you do this by making a narrow hood on the sensor?

Hmmm, We haven't tried this before. I would be worried about bouncing signals, interference, etc. I'm not sure it would work, but you could experiment with it. Let us know if you do.

>>> Do you or anyone you have heard of have a solution for when the Bot is in motion? This is one of the areas that interests me and I plan to dedicate some research in this area (If my humble tinkering can so be called).

I'm afraid this is where you go over my head in terms of experience, I've never participated in battlebots myself or had to write complex motion tracking algorithms. In theory it can all be done I'm sure. What it boils down to is two things: resolution & reaction time. By resolution I mean, how accurate can you get with your available sensors, processors, & algorithms. If your sensors can only give you a fuzzy view of another bot zipping by and it's speed and direction it might be tough to attack accurately. The second hurdle is responding fast enough to attack. That is up to the accuracy of your encoders and motor response time.

I may be telling you stuff you already know... You should post a more full description of your bot so others can know what hardware you are working with and help out. Is this for a specific competition?

>>>Also, how do folks deal with the blind spot within the 4 inch range of IR sensors?

You hit this one on the head, you need to set the sensors back. That's what I've always done.

>>Thanks Matt!, and congratulations on prizing innovation in this field through Trossen.


Thank you :) My biggest reward from all this is getting to watch others innovate. I love seeing all the exciting projects people much smarter than me build!

Migs
09-19-2007, 07:17 AM
Thanks for your comments Matt! -Migs

Droid Works
11-12-2007, 01:44 PM
Here is a example of ping roaming code. Just adjust this code to move TO the obstacle instead of away.




' File...... Ping))).bs2
' Purpose... Roam And Scan Using PING)))
' {$STAMP BS2}
' {$PBASIC 2.5}


' -----[ I/O Definitions ]-------------------------------------------------
Piezo PIN 4 ' Piezo Speaker
RightServo PIN 12 ' Right Servo
LeftServo PIN 13 ' Left Servo
PingServo PIN 14 ' PING))) Servo
Ping PIN 15 ' PING))) Sensor


' -----[ Variables ]-------------------------------------------------------
irDetectLeft VAR Bit ' Variable For Left IR Input
irDetectRight VAR Bit ' Variable For Right IR Input
pulseCount VAR Byte ' Used For Measuring Turns
distance VAR Word ' Current Distance Of Object
oldDistance VAR Word ' Old Distance Value
counter VAR Word ' PING))) Cycle Counter
task VAR Nib ' Current Task


' -----[ Initialization ]--------------------------------------------------

FREQOUT Piezo, 100, 3800 ' Signal Program Start/Reset
FREQOUT 4, 200, 3000
FREQOUT 4, 100, 2600
FREQOUT 4, 170, 2400
FREQOUT 4, 140, 4200
FREQOUT 4, 30, 2000
FREQOUT 4, 200, 2500 + 500
FREQOUT 4, 100, 2500
FREQOUT 4, 80, 1300
FREQOUT 4, 200, 1200
FREQOUT 4, 150, 1000
FREQOUT 4, 35, 2000
FREQOUT 4, 140, 2800
FREQOUT 4, 10, 1000
FREQOUT 4, 100, 2500
FREQOUT 4, 50, 1500
FREQOUT 4, 100, 3800

' -----[ Program Code ]----------------------------------------------------

Main:
DO

FREQOUT 8, 1, 38500 ' Emit 38.5 kHz IR To Left
irDetectLeft = IN9 ' Store IR Detection Values

FREQOUT 2, 1, 38500 ' Emit 38.5 kHz IR To Right
irDetectRight = IN0 ' Store IR Detection Values

IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
GOSUB Blink
GOSUB Ping_Around ' Object Detected via IR Forward
ELSEIF (irDetectLeft = 0) THEN
GOSUB Blink_left
GOSUB Ping_Around ' Object Detected via IR Left
ELSEIF (irDetectRight = 0) THEN
GOSUB Blink_right
GOSUB Ping_Around ' Object Detected via IR Right
ENDIF

counter = counter + 1 ' Increment Passive Counter

IF counter > 10 THEN ' Wait For 10 Servo Pulses
GOSUB Ping_Out ' Activate PING)))
ENDIF

IF (distance > 30) THEN ' Is Object Farther Than 30 cm?
GOSUB Forward_Pulse ' If Yes Go Forward
ELSE
GOSUB Ping_Around ' Otherwise Scan For Clear Path
ENDIF

LOOP


' -----[ Subroutines ]-----------------------------------------------------

IF (IN0 = 0) OR (IN9 = 0) THEN
Blink_left:
FOR counter = 1 TO 2
HIGH 10
FREQOUT 4, 100, 2500
FREQOUT 4, 150, 1500
FREQOUT 4, 100, 3800
LOW 10
PAUSE 20
NEXT
ENDIF
RETURN

IF (IN0 = 0) OR (IN9 = 0) THEN
Blink_right:
FOR counter = 1 TO 2
HIGH 1
FREQOUT 4, 100, 3600
FREQOUT 4, 50, 3000
FREQOUT 4, 75, 2000
LOW 1
PAUSE 20
NEXT
ENDIF
RETURN



IF (IN0 = 0) OR (IN9 = 0) THEN
Blink:
FOR counter = 1 TO 2
HIGH 1
HIGH 10
FREQOUT 4, 150, 3500
FREQOUT 4, 50, 4000
FREQOUT 4, 25, 3000
LOW 1
LOW 10
PAUSE 20
NEXT
ENDIF
Forward_Pulse: ' Send A Single Forward Pulse
PULSOUT PingServo, 750 ' Ping Servo Forward Pulse Value
PULSOUT LeftServo, 850 ' Left Servo Forward Pulse Value
PULSOUT RightServo, 650 ' Right Servo Forward Pulse Value
PAUSE 20 ' Refresh Delay
RETURN

' ************************************************** ***********************

Turn_Left: ' Left Turn, About 45 Degrees
FOR pulseCount = 0 TO 12 ' Number Of Pulses To Turn
PULSOUT PingServo, 750 ' Ping Servo Forward Pulse Value
PULSOUT LeftServo, 650 ' Left Servo Left Pulse Value
PULSOUT RightServo, 650 ' Right Servo Left Pulse Value
PAUSE 20 ' Refresh Delay
NEXT
RETURN

' ************************************************** ***********************

Turn_Right: ' Right Turn, About 45 Degrees
FOR pulseCount = 0 TO 12 ' 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
NEXT
RETURN

' ************************************************** ***********************

Back_Up: ' Back Up
FOR pulseCount = 0 TO 40 ' Number Of Pulses To Backup
PULSOUT PingServo, 750 ' Ping Servo Forward Pulse Value
PULSOUT LeftServo, 650 ' Left Servo Backup Pulse Value
PULSOUT RightServo, 850 ' Right Servo Backup Pulse Value
PAUSE 20 ' Refresh Delay
NEXT
RETURN

Ping_Out: ' PING)))
counter = 0 ' Reset Passive Delay Counter
LOW Ping ' Force PING))) Line Low
PULSOUT Ping, 5 ' Activate PING))) Pulse
PULSIN Ping, 1, distance ' Receive Return Pulse
distance = distance ** 2257 ' Calculate Distance
RETURN

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
NEXT

distance = distance ** 2257 ' Calculate Distance In cm
IF distance > oldDistance THEN ' Is distance > Last Clear Path
oldDistance = distance ' Update oldDistance Value
task = 1
ENDIF

' ************************************************** ***********************


FOR pulseCount = 0 TO 20 ' Number Of Pulses To Spin
LOW Ping ' Force PING))) Line Low
PULSOUT PingServo, 850 ' Ping Servo 45 Left Pulse Value
PULSOUT Ping, 5 ' Activate PING)))
PULSIN Ping, 1, distance ' Receive Distance Value
PAUSE 20 ' Refresh Delay
NEXT

distance = distance ** 2257 ' Calculate Distance In cm
IF distance > oldDistance THEN ' Is distance > Last Clear Path
oldDistance = distance ' Update oldDistance Value
task = 2
ENDIF

' ************************************************** ***********************


FOR pulseCount = 0 TO 20 ' Number Of Pulses To Spin
LOW Ping ' Force PING))) Line Low
PULSOUT PingServo, 400 ' Ping Servo 45 Right Pulse Value
PULSOUT Ping, 5 ' Activate PING)))
PULSIN Ping, 1, distance ' Receive Distance Value
PAUSE 20 ' Refresh Delay
NEXT

distance = distance ** 2257 ' Calculate Distance In cm
IF distance > oldDistance THEN ' Is distance > Last Clear Path
oldDistance = distance ' Update oldDistance Value
task = 3
ENDIF

' ************************************************** ***********************


FOR pulseCount = 0 TO 20 ' Number Of Pulses To Spin
LOW Ping ' Force PING))) Line Low
PULSOUT PingServo, 225 ' Ping Servo 90 Right Pulse Value
PULSOUT Ping, 5 ' Activate PING)))
PULSIN Ping, 1, distance ' Receive Distance Value
PAUSE 20 ' Refresh Delay
NEXT

distance = distance ** 2257 ' Calculate Distance In cm
IF distance > oldDistance THEN ' Is distance > Last Clear Path
oldDistance = distance ' Update oldDistance Value
task = 4
ENDIF

ON task GOSUB Task0, Task1, Task2, Task3, Task4

distance = 50 ' Prevent Scan From Looping

RETURN

Task0: ' Forward Was Clearest Path
GOSUB Turn_Right ' This Could Mean Narrow Path
GOSUB Turn_Right ' So We'll Turn Around
GOSUB Turn_Right ' You Can Change The Behavior
GOSUB Turn_Right ' Of Any Of The Tasks
RETURN

Task1: ' 90 Degrees Left Was Clearest
GOSUB Turn_Left
GOSUB Turn_Left
RETURN

Task2: ' 45 Degrees Left Was Clearest
GOSUB Turn_Left
RETURN

Task3: ' 45 Degrees Right Was Clearest
GOSUB Turn_Right
RETURN

Task4: ' 90 Degrees Right Was Clearest
GOSUB Turn_Right
GOSUB Turn_Right
RETURN

Migs
11-13-2007, 09:30 AM
Thanks Droidworks! I'm going to tweak it tonight. I'm also going to set it up with four of those new IR sensors from HVW, except on my Johnny 5 ... If it works out nice I'll post pictures.

Thanks so much for taking the time to help!

Migs

lnxfergy
07-05-2008, 12:53 PM
Migs,

A few points you have to consider about sonar: 1) a Sonar sensor has a wide field of view. A sonar is probably only going to give you a 45 degree window that the opponent is in, not an exact location. A sharp IR ranger will give you a location with a much higher degree of accuracy. 2) Sonar is kinda slow. You have to wait at least 50ms for the sound waves to die off (even if you didn't hit something). This means you can only take 20 readings a second).

Another point, why bother with the servo. Just mount the sensor on the front of the bot, and pan the bot itself. When you detect the opponent you are already facing it, so charge forward! Further, with no servo, you don't have a limited range of motion, you can spin around way more than 180 degrees.

-Fergs