Rover project need some help

I already made my order but thanks anyways. I’ll keep it in mind though for a later project.

Well, I’ve been working on perfecting my code but a problem has suddenly came up. After troubleshooting I found the problem was in the ping sensor. I stuck a sound command in the sensor not working properly part of the code.

toolong: ; if the program gets here the sensor is not functioning, or wired wrong serout s_out, i9600, "Timeout, sensor is not working", 13] sound p9,[3000\500] return

I immediatly feared that the several crashes my robot had(some of them fairly severe) had messed up the sensor. However, when I inspected the sensor I found the sticker on the middle circuit board was partially burnt up.(why I never noticed smoke I don’t know)I’ve never ran my ping for more than 5 minutes so I don’t know why this happened. So I’m guessing my sensor is dead now isn’t it?

Good bet. You might check what voltage you had it hooked up to before trying a replacement.

Alan KM6VV

I’ve been powering everything except for the motors with a regular 9 volt battery. Is this to much? Is there any way I can get it working again? I scraped off the burnt sticker and none of the plastic had actually melted or even deformed so there isn’t any visible damage that I can see.

Normally sensors and so forth are 5v, you don’t want to give them 9v. The BB2 has a 5v regulator on board. peripheral pins have a powered pin, and you can often select 5v (logic) or servo power (6+).

I doubt if you can do much with the sensor. Just check your voltage, and try the part again.

Alan KM6VV

You’re right, the jumper for the 5 volt regulator wasn’t in. :cry: :cry: :cry: I burned my baby’s eyes out oh well I’ll just have to buy new ones. :unamused: In the meantime I’ll just work with my IR sensors. Thanks for the help though I won’t make that mistake again. marks one more tally mark on board that says list of horrible robot building failures.

Sorry it took so long I’ve been a little busy.


Meet Pal (its the best name I could think of since it kind of makes me think of a dog) As soon as I get a new ping sensor I’m planning on using it instead of the ir sensors.
Here’s my code I’m currently using to operate it. (Take note that 6 months ago I didn’t know what computer code really was)

[code]wdist var word

LSpeed var word
RSpeed var word

minspeed con 2000
maxspeed con 1000

SC var bit
SR var bit
SL var bit

Turn var bit
Rand var long

getgoing var word

ir_right var word
ir_left var word

LSpeed = 1452
RSpeed = 1452

low p0
low p1

; Numbers lower than 1452 result in forward direction.
; Numbers higher than 1452 result in reverse direction.

sound 9, [100\880, 100\988, 100\1046, 100\1175]
enablehservo
rand = random 2
main

SC=0
SR=0
SL=0

gosub servo_scan

if(sc=1)and(sr=1)and(sl=1)then;all sensor positions covered
gosub back_and_turn
goto main

elseif(sc=0)and(sr=0)and(sl=0);all sensor positions are clear of obstacles
gosub stop_gawking
goto main

elseif(sc=1)and(sr=0)and(sl=0);something is directly in front of the robot
gosub back_and_turn
goto main

elseif(sc=1)and(SR=1)and(SL=0);something is covering the robots right side
for getgoing = 1 to 30
Lspeed =(Lspeed - 10)
Rspeed =(Rspeed + 10);left stationary turn
gosub dosomething
next
for getgoing = 1 to 30
Lspeed =(Lspeed + 10)
Rspeed =(Rspeed - 10);stop
gosub dosomething
next
goto main

elseif(sc=1)and(SR=0)and(SL=1);something is covering the robots left side
for getgoing = 1 to 30
Lspeed =(Lspeed + 10)
Rspeed =(Rspeed - 10);right stationary turn
gosub dosomething
next
for getgoing = 1 to 30
Lspeed =(Lspeed - 10)
Rspeed =(Rspeed + 10);stop
gosub dosomething
next
goto main

elseif(SC=0)and(SR=0)and(Sl=1);something is barely in the robots left field of view
for getgoing = 1 to 26
Lspeed =(Lspeed + 10)
Rspeed =(Rspeed - 10);slight right turn
gosub dosomething
next
for getgoing = 1 to 26
Lspeed =(Lspeed - 10)
Rspeed =(Rspeed + 10);stop
gosub dosomething
next
goto main

elseif(SC=0)and(SR=1)and(SL=0);something is barely in the robots right field of view
for getgoing = 1 to 26
Lspeed =(Lspeed - 10)
Rspeed =(Rspeed + 10);slight left turn
gosub dosomething
next
for getgoing = 1 to 26
Lspeed =(Lspeed + 10)
Rspeed =(Rspeed - 10)
gosub dosomething
next
goto main

elseif(SC=0)and(SR=1)and(SL=1);this place is too narrow to pass through!
gosub back_and_turn
goto main
endif
;----------------------------------------------------------------------------------------------------------------------------------------------------------
sensor_check
ADIN P16, wdist
pause 20
sound p9,[50\wdist4]
return
;----------------------------------------------------------------------------------------------------------------------------------------------------------
dosomething
;servo pulses
pulsout 0,(LSpeed
2) ; Left Sabertooth channel.
pulsout 1,(RSpeed*2) ; Right Sabertooth channel.
pause 20
return
;----------------------------------------------------------------------------------------------------------------------------------------------------------
servo_scan

hservo[p2\7000\900];right servo position
hservowait[p2]
pause 15
gosub sensor_check
if(wdist>200)then
SR = 1
else
SR = 0
endif

hservo[p2-7000\900];left servo position
hservowait[p2]
pause 15
gosub sensor_check
if(wdist>200)then
SL = 1
else
SL = 0
endif

hservo[p2\0\900];middle servo position
hservowait[p2]
pause 15
gosub sensor_check
if(wdist>175)then
SC = 1
else
SC = 0
endif

return
;----------------------------------------------------------------------------------------------------------------------------------------------------------
stop_gawking

repeat
for getgoing = 1 to 24
Lspeed =(Lspeed - 10)
Rspeed =(Rspeed - 10)
gosub dosomething
next
for getgoing = 1 to 24
Lspeed =(Lspeed + 10)
Rspeed =(Rspeed + 10)
gosub dosomething
next
gosub sensor_check
if (wdist>175)then
return
endif

hservo[p2\8800\900]
hservowait[p2]
pause 15
gosub sensor_check
if (wdist>180)then
for getgoing = 1 to 24
Lspeed =(Lspeed - 10);left turn
Rspeed =(Rspeed + 10)
gosub dosomething
next
for getgoing = 1 to 24
Lspeed =(Lspeed + 10)
Rspeed =(Rspeed - 10)
gosub dosomething
next
else
endif

hservo[p2-8800\900]
hservowait[p2]
pause 15
gosub sensor_check
if (wdist>180)then
for getgoing = 1 to 24
Lspeed =(Lspeed + 10);right turn
Rspeed =(Rspeed - 10)
gosub dosomething
next
for getgoing = 1 to 24
Lspeed =(Lspeed - 10)
Rspeed =(Rspeed + 10)
gosub dosomething
next
gosub sensor_check
else
endif
hservo[p2\0\900]
hservowait[p2]
pause 15
gosub sensor_check
if (wdist<150)then
for getgoing = 1 to 20
Lspeed =(Lspeed - 10)
Rspeed =(Rspeed - 10)
gosub dosomething
next
for getgoing = 1 to 20
Lspeed =(Lspeed + 10)
Rspeed =(Rspeed + 10)
gosub dosomething
next
else
endif
until (wdist > 175)
return
;----------------------------------------------------------------------------------------------------------------------------------------------------------
back_and_turn
for getgoing = 1 to 17
Lspeed =(Lspeed + 10)
Rspeed =(Rspeed + 10);backwards
gosub dosomething
next
for getgoing = 1 to 17
Lspeed =(Lspeed - 10)
Rspeed =(Rspeed - 10);stop
gosub dosomething
next
rand = random rand ; feed in the old value
Turn = rand & 0x1 ; takes the low bit to be either 0 or 1
debug [dec turn, 13]
if (Turn = 0)then
sound 9,[250\250]
for getgoing = 1 to 26
Lspeed =(lspeed-10)
Rspeed =(Rspeed+10);turn left
gosub dosomething
next
for getgoing = 1 to 26
Lspeed =(Lspeed+10)
Rspeed =(Rspeed-10);stop
gosub dosomething
next
elseif (Turn = 1)
sound 9,[250\500]
for getgoing = 1 to 26
Lspeed =(Lspeed +10)
Rspeed =(Rspeed -10);turn right
gosub dosomething
next
for getgoing = 1 to 26
Lspeed =(Lspeed -10)
Rspeed =(Rspeed +10);stop
gosub dosomething
next
endif
return
;----------------------------------------------------------------------------------------------------------------------------------------------------------
;toolong: ; if the program gets here the sensor is not functioning, or wired wrong
;serout s_out, i9600, “Timeout, sensor is not working”, 13]
;sound p9,[5000\50]
goto main[/code]

Comments and suggestions are very much encouraged. :slight_smile:

Well, looks like you’ve been busy indeed!

I’d say you have a success on your hands.

Next I suppose you’ll work on ranging on-the-fly?

Alan KM6VV

By

what exactly do you mean?

Rather then stopping to take a scan, you take data AS you’re moving.

Alan KM6VV

I would like to do that. I’m just not quite sure how yet. I’ve been pondering and thinking of ways to but I haven’t thought of anything so far.

One of the things I’ve really been focusing on though is an object finder program where when the rover stops to scan there is a panning servo with a small arm attached to it that scans as well but just closer in(so the robot doesn’t try pick up a wall of course). Then, if the results come back positive it would use some angle equations to reach to the needed distance.(this is the fuzzy part since at my age (see profile) I haven’t had a trigonomatry class in school yet. Finally, when grabbing the object the gripper has a pressure sensor mounted on it to (hopefully) take the object. Right now it’s still in the prototyping stage though and may not ever pan out to work.

This tutorial shows how to do what is being discussed. :wink:

lynxmotion.com/images/html/build135.htm

The 4wd1auto program demonstrates how to use sensors to do “avoidance”.

To find and drive to objects, you do something similar. Both tasks require you to take periodic scans. Do a little each time, and keep repeating until you get the full “picture”.

You drive towards the target, then stop at an appropriate range to enable you to use your gripper. a sensor specifically for the gripper could be useful.

Look into “behavior” programming. Search this forum for previous discussions. The 'bot shifts behaviors as it transverses between different surroundings. First it discovers an object, then moves towards it, then it is within range to grasp it. Then it grasps, next maybe picks it up, and then onto to delivering it somewhere.

Just think, you’ll be able to start your trig class knowing that there will be something useful in it for you!

Alan KM6VV

I’ll keep this stuff in mind but as I said the oject finder is still in its early stages and I don’t even have enough stuff right now to do it yet. In the meantime though I’ll work on “ranging on the fly”. I suddenly got an idea on how to use that tutorial for my current configuration(sensor on panning servo).

Ahhhhh, the bane of most teenagers learning math. They all say “there’s no real world application!”

Remember, Math is your friend! Very useful for the Science and Engineering fields!

Alan KM6VV

I can’t believe I didn’t think of this earlier. It does pretty well. It just needs some fine tuning. 8)

[code]wdist var word

LSpeed var word
RSpeed var word

minspeed con 2000
maxspeed con 1000

SC var bit
SR var bit
SL var bit

Turn var bit
Rand var long

getgoing var word

ir_right var word
ir_left var word

LSpeed = 1452
RSpeed = 1452

low p0
low p1

; Numbers lower than 1452 result in forward direction.
; Numbers higher than 1452 result in reverse direction.

sound 9, [100\880, 100\988, 100\1046, 100\1175]
enablehservo
rand = random 2
main
Lspeed = 1452
Rspeed = 1452
for getgoing = 1 to 10
Lspeed =(Lspeed-10)
Rspeed =(Rspeed-10)
gosub dosomething
next

gosub servo_scan
if(sc=1)and(sr=1)and(sl=1)then;all sensor positions covered
Lspeed = 1452
Rspeed = 1452
gosub dosomething
gosub back_and_turn
goto main

elseif(sc=0)and(sr=0)and(sl=0);all sensor positions are clear of obstacles
goto main

elseif(sc=1)and(sr=0)and(sl=0);something is directly in front of the robot
Lspeed = 1452
Rspeed = 1452
gosub dosomething
gosub back_and_turn
goto main

elseif(sc=1)and(SR=1)and(SL=0);something is covering the robots right side
Lspeed = 1452
Rspeed = 1452
gosub dosomething
for getgoing = 1 to 30
Lspeed =(Lspeed - 10)
Rspeed =(Rspeed + 10);left stationary turn
gosub dosomething
next
for getgoing = 1 to 30
Lspeed =(Lspeed + 10)
Rspeed =(Rspeed - 10);stop
gosub dosomething
next
goto main

elseif(sc=1)and(SR=0)and(SL=1);something is covering the robots left side
Lspeed = 1452
Rspeed = 1452
gosub dosomething
for getgoing = 1 to 30
Lspeed =(Lspeed + 10)
Rspeed =(Rspeed - 10);right stationary turn
gosub dosomething
next
for getgoing = 1 to 30
Lspeed =(Lspeed - 10)
Rspeed =(Rspeed + 10);stop
gosub dosomething
next
goto main

elseif(SC=0)and(SR=0)and(Sl=1);something is barely in the robots left field of view
Lspeed = 1452
Rspeed = 1452
gosub dosomething
for getgoing = 1 to 26
Lspeed =(Lspeed + 10)
Rspeed =(Rspeed - 10);slight right turn
gosub dosomething
next
for getgoing = 1 to 26
Lspeed =(Lspeed - 10)
Rspeed =(Rspeed + 10);stop
gosub dosomething
next
goto main

elseif(SC=0)and(SR=1)and(SL=0);something is barely in the robots right field of view
Lspeed = 1452
Rspeed = 1452
gosub dosomething
for getgoing = 1 to 26
Lspeed =(Lspeed - 10)
Rspeed =(Rspeed + 10);slight left turn
gosub dosomething
next
for getgoing = 1 to 26
Lspeed =(Lspeed + 10)
Rspeed =(Rspeed - 10)
gosub dosomething
next
goto main

elseif(SC=0)and(SR=1)and(SL=1);this place is too narrow to pass through!
gosub back_and_turn
goto main
endif
;----------------------------------------------------------------------------------------------------------------------------------------------------------
sensor_check
ADIN P16, wdist
pause 20
sound p9,[50\wdist4]
return
;----------------------------------------------------------------------------------------------------------------------------------------------------------
dosomething
;servo pulses
pulsout 0,(LSpeed
2) ; Left Sabertooth channel.
pulsout 1,(RSpeed*2) ; Right Sabertooth channel.
pause 20
return
;----------------------------------------------------------------------------------------------------------------------------------------------------------
servo_scan

hservo[p2\8000\900];right servo position
hservowait[p2]
pause 15
gosub sensor_check
if(wdist>190)then
SR = 1
else
SR = 0
endif

hservo[p2-8000\900];left servo position
hservowait[p2]
pause 15
gosub sensor_check
if(wdist>190)then
SL = 1
else
SL = 0
endif

hservo[p2\0\900];middle servo position
hservowait[p2]
pause 15
gosub sensor_check
if(wdist>175)then
SC = 1
else
SC = 0
endif

return
;----------------------------------------------------------------------------------------------------------------------------------------------------------
back_and_turn
for getgoing = 1 to 17
Lspeed =(Lspeed + 10)
Rspeed =(Rspeed + 10);backwards
gosub dosomething
next
for getgoing = 1 to 17
Lspeed =(Lspeed - 10)
Rspeed =(Rspeed - 10);stop
gosub dosomething
next
rand = random rand ; feed in the old value
Turn = rand & 0x1 ; takes the low bit to be either 0 or 1
debug [dec turn, 13]
if (Turn = 0)then
sound 9,[250\250]
for getgoing = 1 to 26
Lspeed =(lspeed-10)
Rspeed =(Rspeed+10);turn left
gosub dosomething
next
for getgoing = 1 to 26
Lspeed =(Lspeed+10)
Rspeed =(Rspeed-10);stop
gosub dosomething
next
elseif (Turn = 1)
sound 9,[250\500]
for getgoing = 1 to 26
Lspeed =(Lspeed +10)
Rspeed =(Rspeed -10);turn right
gosub dosomething
next
for getgoing = 1 to 26
Lspeed =(Lspeed -10)
Rspeed =(Rspeed +10);stop
gosub dosomething
next
endif
return[/code]

Pretty good!

I see you’ve even got a random turn direction in there!

We’re always “fine tuning”, by the way.

Alan KM6VV

I added this snippet of code to the subroutine for backing up and turning making the random number generator secondary. It adds a little bit more “intelligence” to the robot’s behavior. It dawned on me that it looks kind of “stupid” when it went into a corner and the random number made it turn into the corner instead of turning out of it.

And, two questions:
The ir sensor is starting to annoy me since its output seems to sometimes vary. Is this pretty common for the GP2D12?
I’ve been really looking for some emergent behaviors. What exactly should I expect?

[code]hservo[p2\12000\900]
hservowait[p2]
pause 15
gosub sensor_check
look_right = wdist

hservo[p2-12000\900]
hservowait[p2]
pause 15
gosub sensor_check
look_left = wdist

if(look_right<look_left)then
for getgoing = 1 to 26
Lspeed =(Lspeed +10)
Rspeed =(Rspeed -10);turn right
gosub dosomething
next
for getgoing = 1 to 26
Lspeed =(Lspeed -10)
Rspeed =(Rspeed +10);stop
gosub dosomething
next
elseif(look_left<look_right)
for getgoing = 1 to 26
Lspeed =(lspeed-10)
Rspeed =(Rspeed+10);turn left
gosub dosomething
next
for getgoing = 1 to 26
Lspeed =(Lspeed+10)
Rspeed =(Rspeed-10);stop
gosub dosomething
next
else
random number generator
endif
[/code]

Major advancement!!!
Since my rover only scans three points it tends to happen to get stuck on stuff fairly often(like at the end of the video). After a lot of head scratching this code has solved that problem.

[code]left_servo_scan
servopos =-8000
repeat
hservo[p2\servopos\900]
hservowait[p2]
pause 15
gosub sensor_check
servopos =(servopos+1000)
until (wdist>240)or(servopos>=-1000)
if(wdist>240)then
sl = 1
else
sl = 0
endif
return

;--------------------------------------------------------------------------------------------------------------------
center_servo_scan
servopos =-1000
repeat
hservo[p2\servopos\900]
hservowait[p2]
pause 15
gosub sensor_check
servopos =(servopos+1000)
until (wdist>240)or(servopos>=1000)
if(wdist>240)then
sc = 1
else
sc = 0
endif
return
;--------------------------------------------------------------------------------------------------------------------
right_servo_scan
servopos =1000
repeat
hservo[p2\servopos\900]
hservowait[p2]
pause 15
gosub sensor_check
servopos =(servopos+1000)
until (wdist>240)or(servopos>=8000)
if(wdist>240)then
sr = 1
else
sr = 0
endif
return[/code]
It works pretty well. It just needs some fine tuning. :wink:

Video coming…sometime.