Whiskers

Status
Not open for further replies.

Cyborg

New Member
Hey can someone help here, I'm building a robot and I tried it with one whisker to see if it can go reverse if it bumped into something (leftwhisker), But my problem is that it has to stay for a while before it can go reverse in other words is that you have to hold the whisker for like 4 sec. for it to reverse. Can Anyone help me. I'm using picbasic pro demo with pic16F628 (4mhz Crystal). This is the code I used.


lefteye var portb.1 'left sensor
counter var word

sense: 'check for objects in front, right, left
if lefteye = 1 then forward
if lefteye = 0 then backward
goto sense
backward:

FOR counter = 1 TO 104 ' Backward
PULSOUT 0, 183
PULSOUT 2, 500
PAUSE 10
next
goto sense

Forward:

PULSOUT 0, 500
PULSOUT 2, 183
PAUSE 10
goto sense
end
 
Hi!

I don't know how basic works, so I'm not very sure about the commands you use, but could it be that the forward commands take a longer time to execute and that will make the whisker to be polled only at 4 seconds intervals?

BR
 
The problem is the Pause 10 in the forward routine. For example if the robot hits the wall right after the forward routine is called then it will wait for 10 seconds before it checks the whiskers. For stuff like this using PAUSE doesn't work well because while you execute the pause loop nothing else happens. To fix this you should use the timers manualy. Doing this lets you look at the timer value and is it isn't high enough you check the whisker right away and reverse is its hit. you loop around these two sub routines. Check your data sheet to learn how to directly access the timers.

Brent
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…