Help using Pololu infrared beacon

Hello everybody,

I am a new Rover user and I got a Lynxmotion A4WD1. I would like to design a tracking algorithm just like Mark (awesome tracking algorithm by the way !) but I don’t have a camera, I just got a Pololu infrared Beacon (one on the Robot and one on the Car to track) giving the orientation (North, North-East, East, South-East, South, South-West, West, North-West). I am using 2 US sensors to determine the distance of the Leader when it is facing the Robot.

So let’s say that I can determine the angle (more or less 25°) each 0.20 seconds, how can I adapt this algorithm to track my Leader ?

An other question: I have read the algorithm and I do not found the command to send the information to the motors. For my robot I have to use the command “PULSOUT”.

Thank you,

Guillaume

I split your thread from the x-rover thread. Mark is no longer on the forum.

Okay, thanks.

Hi

I have done some experimentation with a simple code and here is a video of the vehicle motion:

As we can see the dynamic response is not so fluid and I have a lot of problem to follow the leader “dynamically”. I am going to post my code, can you have a look and tell me if you have suggestions or ideas to make it better ?

My final goal it to achieve a leader tracking like the X-rover :
lynxmotion.net/viewtopic.php?f=9&t=5580

Guillaume

That’s pretty cool! 8)

Thanks robot dude, here is the code :

[code]’ ==============================================================================

’ File… navigation_beacon.bas
’ Purpose… Define a simple navigation based on IR beacon informations
’ Author… © 2010 Guillaume FRAPSAUCE – All Rights Reserved
’ E-mail… [email protected]
’ Started… 08/07/2010
’ Modified… 21/07/2010

’ ==============================================================================

’ ------------------------------------------------------------------------------
’ Program Description
’ ------------------------------------------------------------------------------

’ This is a simple program for the navigation of the robot based on the IR beacon
’ Direction informations and on the US sensors.

’ We get the direction information from the IR beacon to detect the leader and
’ Turn the robot toward this direction. Then we are going straight on toward the
’ Location of the leader until the US sensor indicates the leader’s proximity.

’ ------------------------------------------------------------------------------

’ Variables definition
West var Word ’ Beacon West output
South var Word ’ Beacon South output
East var Word ’ Beacon East output
North var Word ’ Beacon North output

dir_W var nib
dir_S var nib
dir_E var nib
dir_N var nib
i var byte ’ Incremental value

right var byte ’ Right US sensor value
left var byte ’ Left US sensor value

distanceL var byte ’ Distance from an obstacle to the left US sensor
distanceR var byte ’ Distance from an obstacle to the right US sensor

thresholdmin var byte ’ Distance min
thresholdmax var byte ’ Distance max

ltpwr var word ’ Left motors command
rtpwr var word ’ Right motors command
’ ltpwr < 2950 --> Backward
’ ltpwr = 2950 --> Stop
’ ltpwr > 2950 --> Forward

’ Variable definition

distanceL=0
distanceR=0

thresholdmin = 20 'cm
thresholdmax = 30 'cm

ltpwr=2950
rtpwr=2950

’ ------------------------------------------------------------------------------
’ Main Program Loop
’ ------------------------------------------------------------------------------

MAIN
ADIN P16, West
ADIN P17, South
ADIN P18, East
ADIN P19, North
’ serout s_out, i9600, “WEST :”,DEC West , " SOUTH :" , DEC South, " EAST :" , DEC EAST, " NORTH :" , DEC NORTH,13]

if West<500 Or South <500 or East <500 or North<500 then ; Detection of the Robot leader
gosub beacon
gosub ultrasonic
gosub calibration
gosub navigation
gosub motors
else
right=2950
left=2950
endif
gosub motors
goto main

’ ------------------------------------------------------------------------------
’ Beacon
’ ------------------------------------------------------------------------------
beacon

dir_W=0
dir_S=0
dir_E=0
dir_N=0
i=0

do ; Storage of the past 5 directions

if West < 200 then
	dir_W=dir_W+1
	i=i+1
endif

if South < 200 then
	dir_S=dir_S+1
	i=i+1
endif

if East < 200 then 
	dir_E=dir_E+1
	i=i+1
endif

if North < 200 then
	dir_N=dir_N+1
	i=i+1
endif

pause 40

while i <5

; We take the dominant direction as the Leader’s direction

if dir_W > dir_S & dir_W > dir_E & dir_W > dir_N then
	serout s_out, i9600, "WEST",13]
	dir_W=1
	dir_S=0
	dir_E=0
	dir_N=0

	
elseif dir_S > dir_W & dir_S > dir_E & dir_S > dir_N & dir_W > dir_E
serout s_out, i9600, "SOUTH-WEST",13]
	dir_W=0
	dir_S=0
	dir_E=1
	dir_N=0
	
elseif dir_S > dir_W & dir_S > dir_E & dir_S > dir_N & dir_W < dir_E
serout s_out, i9600, "SOUTH-EAST",13]
	dir_W=1
	dir_S=0
	dir_E=0
	dir_N=0
	
elseif dir_S > dir_W & dir_S > dir_E & dir_S > dir_N & dir_W = dir_E
serout s_out, i9600, "SOUTH",13]
	dir_W=0
	dir_S=1
	dir_E=0
	dir_N=0

elseif dir_E > dir_W  & dir_E > dir_S & dir_E > dir_N 
serout s_out, i9600, "EAST",13]
	dir_W=0
	dir_S=0
	dir_E=1
	dir_N=0

elseif dir_N > dir_W & dir_N > dir_S & dir_N > dir_E 
	serout s_out, i9600, "NORTH",13]
	dir_W=0
	dir_S=0
	dir_E=0
	dir_N=1    	

else
serout s_out, i9600, "PROBLEM",13]
return

endif

return

’ ------------------------------------------------------------------------------
’ Ultra Sonic Sensors
’ ------------------------------------------------------------------------------
ultrasonic

 ' Sensor RIGHT
high P15
input p12
SerIn P12, n9600, [WAIT("R"), dec right ]    'wait for "R" and get the data
Low P15 


' Sensor LEFT
high P15
input p13
SerIn P13, n9600, [WAIT("R"), dec left ]    'wait for "R" and get the data
Low P15 

return

’ ------------------------------------------------------------------------------
’ US sensor calibration
’ ------------------------------------------------------------------------------

calibration
;=====================================================================================
; RIGHT US sensor calibration

if right < 8 then
distanceR=15
endif

if right >= 8 and right < 9 then
distanceR=20
endif

if right >= 9 and right < 11 then
distanceR=25
endif

if right >= 11 and right < 12 then
distanceR=30
endif

if right >= 12 and right < 14 then
distanceR=35
endif

if right >= 14 and right < 17 then
distanceR=40
endif

if right >= 17 and right < 18 then
distanceR=45
endif

if right >= 18 and right < 20 then
distanceR=50
endif

if right >= 20 and right < 21 then
distanceR=55
endif

if right >=21  and right < 26 then
distanceR=60
endif

if right >= 26 and right < 29 then
distanceR=70
endif

if right >= 29 and right <33 then
distanceR=80
endif

if right >= 33 then
distanceR=100
endif

;=====================================================================================
; Left US sensor calibration

if left < 8 then
distanceL=15
endif

if left >= 8 and left < 9 then
distanceL=20
endif

if left >= 9 and left < 11 then
distanceL=25
endif

if left >= 11 and left < 12 then
distanceL=30
endif

if left >= 12 and left < 14 then
distanceR=35
endif

if left >= 14 and left < 17 then
distanceL=40
endif

if left >= 17 and left < 18 then
distanceL=45
endif

if left >= 18 and left < 20 then
distanceL=50
endif

if left >= 20 and left < 21 then
distanceL=55
endif

if left >=21  and left < 26 then
distanceL=60
endif

if left >= 26 and left < 29 then
distanceL=70
endif

if left >= 29 and left <33 then
distanceL=80
endif

if left >= 33 then
distanceL=100
endif

serout s_out,i9600,"RIGHT:   ", dec distanceR,"cm", "         LEFT:   ", dec distanceL,"cm", 13]	'Display the distance

return

’ ------------------------------------------------------------------------------
’ Navigation
’ ------------------------------------------------------------------------------
navigation

if dir_S=1 then
	ltpwr=2450
	rtpwr=3450
endif

if dir_W=1 then
	ltpwr=2450
	rtpwr=3450
endif

if dir_E=1 then
	ltpwr=3450
	rtpwr=2450
endif

if dir_N=1 then
	; Too close
	if distanceR < thresholdmin then
		rtpwr=2450
	endif

	if distanceL < thresholdmin then
		ltpwr=2450
	endif

	; Good interval
	if distanceR >= thresholdmin and distanceR <= thresholdmax then
		rtpwr=2950
	endif

	if distanceL >= thresholdmin and distanceL <= thresholdmax then
		ltpwr=2950
	endif


	; Too far
	if distanceR > thresholdmax then
		rtpwr=3450
	endif

	if distanceL > thresholdmax then
		ltpwr=3450
	endif
endif

return

’ ------------------------------------------------------------------------------
’ Motors
’ ------------------------------------------------------------------------------

motors
low p4
low p5

pulsout 5, ltpwr ; Left wheel
pulsout 4, rtpwr ; Right wheel
pause 10

return
[/code]

Looks like you are making progress!

Mark’s code inspired me to buy a camera, and get it on a Micromouse (well OK, MicroMoose). I wasn’t able to get a CMU Cam, eventually got a refund for the order I placed. I’ve now (one year later) got the BlackFin camera w/ WiFi link, probably a much better camera!

I’ve been able to drive my MicroMoose around with a PS2, but that’s about all. With a little luck, I’ll get some custom brackets made to mount the “Camera stack” on a tilt R/C servo this weekend. There’s also a front jaw to be mounted, and get the BBII and RoboClaw boards bolted down. rubber bands and document clips only go so far…

I’m no where near being able to control my 'bot with the camera system. But it should be a fun exercise! (More learning required).

Looking forward to hearing about your experiences. And about the beacon. I’ve not heard of anyone using it on a 'bot.

Alan KM6VV

KM6VV That is true that to use a camera would be much better to detect and track a leader or a specific colour I was just scared about the data processing :blush:

Have you made some progress this week end about the camera system ?

I just have a question about my code, as you can see on the code of my previous post I use a lot of “If … Then … endif” for the US sensor calibration. Do you know if there is a way to write a table corresponding to this calibration and how can I get the correct data from this table, instead of using 10000 conditions if…then…endif

Guillaume

You might want to use the extended format of the if…then… elseif… format

if distanceR > thresholdmax then statements elseif distanceL > thresholdmax then other statements endif

But this is sort of a compromise. I like the C language case… switch, which directly addresses this problem.

There should be a “blob” function that returns the centroid of the color blob (tracked object) you wish to track. From there, you pan/tilt the camera to point to the blob. Then for course correction, you take the camera angle relative to the front of the 'bot, and use it as an error correction to the drive system. Tilt info can probably be used to give an angle by which you can judge distance to the target. The Blackfin camera also has an IR sensor mounted on it (optional), so that range data is also available. I’m looking forward to writing interpreted C code for the Blackfin to do my tracking. Then the Blackfin would send course/speed info to the RoboClaw motor controller.

For now, as I’ve mentioned, I’ve just got the Atom Pro on board taking instructions from the PS2. Camera is “along for the ride”.

I did get a bracket made to allow me to attach the jaw. no vertical motion yet, but I’m working on a worm screw drive to move it. Also made a plate to adapt the Blackfin camera to a multipurpose bracket to effect the tilt. I still need to make a cutout in the top plate of my 'bot to take an R/C servo for the rotate. A document clip holds the multi-purpose bracket for now! (Gives me tilt only).

I spend most of my time working out the mechanical details! And then machining custom brackets to accomplish what I want.

Alan KM6VV

Here is an other video of the robot. The following behaviour is much better when close to the leader. When far it tries to reach the leader from the beacon informations.

We can see a technical problem at the end of the video :blush:

Guillaume

Yes, following is better up close.

It would seem you have an angular error that increases with the range? Possibly a scaling issue?

One thing that would help your angular resolution is to “dither” the beacon modules. By this, I mean rotate them slightly (45 deg?) back and forth to split up the 90 degree angles of the sensors/emitters. Better yet, rotate and get the acquire/loose angles, then calculate the mean angle of the received beam. But of course, you’d have to have a means to rotate the beacons. This could be nothing more then a mini-R/C servo.

I do admire your progress!

Alan KM6VV

Thanks for your reply Alain.

The problem with the Polulu IR Beacon is that gives you the Direction of the other Beacon (N,E,S or W), and for each direction the pin is high (5v) or low (0v). When the other beacon is detected, ONLY one pin is high and the 3 other are low. So there is no possibility to calculate a mean to increase the precision, and as the pin is high or low there is no hopes to get the distance between the devices.

I though as well to rotate the beacon of 45° to determine the directions (NE,NW,SE and SW) that is a pain to code :unamused:
The problem is for example if the beacon is detected as North-East, we have no ideas about the range so we can not determine clearly the rate of turn of the robot. If the leader is NE and far, a low rate of turn will be enough but if the leader is NE and close a low rate of turn won’t be enough. If we decide to set a high rate of turn then we will be too reactive and we will have a problem of transition between NE and NW, going left and right involving an instability in the motion. Do you know what I mean ? Well this is a good challenge :smiley:

I was thinking to implement more IR sensors on the front of the robot to increase the detection of the angle. I would like to choose the kind of IR sensors outputting a signal proportional to the distance, the problem would be easier if we can get the distance !!

Well I think I am over with this project (this is a MSc project) and the only things I can do now is recommendations for next year students. Thanks for your comments.

Guillaume

Hi Guillaume,

Yes, it is not a trivial problem! I thought about it a while, and with multiple detectors, and needing to “sweep” them, it could be a read chore to work out the angles through which the beacon was detected.

Sharp GP2D12 or similar sensors will give you an analog range. SRF08 or similar ultrasonic sensors can as well. both have their complications! A mix of both would seem best.

Lasers and a camera is something I want to try. They probably have their own set of problems, but it will be fun to try!

Best of Luck,

Alan KM6VV

Hi, i use ir beacon to tracking people with arduino, do we use all same program in each piece of IR(receiver and sender) or every one of (receiver and sender ) must have special code independent of another and how we connect IR beacon with arduino ?

Can you provide a link as to which IR beacon you have?

I use a pair of this piece
pololu.com/product/702

RobotShop sells that pair here: robotshop.com/en/pololu-ir-b … -pair.html
If you want one to “chase” the other, then you would use different code. If you want them to find each other very fast, then you would use the same code.

Regarding connections, you will really need to read through the guide to understand how the units operate.

robotshop.com/media/files/pd … manual.pdf
Note that soldering is required as well. These would not be suggested for beginners.

yes i want from it find each other ,do you have exist code for that ?

Unfortunately not.