problem on programming basic stamp II

Interested in Robotics? Here's the place to be.
Post Reply
bobbob
Posts: 9
Joined: Sun Feb 23, 2003 1:01 am
Location: hk
Contact:

problem on programming basic stamp II

Post by bobbob »

now i want to program the stamp to do a task, firstly, i want it to do two action. the first one is test the IR , if there is output 0, then do go forward, the secord action is go right turn after the first action
my problem is the stamp only do the first action, and do nothing on the second one, then what should i do?
i am bob
hamsterears
Posts: 40
Joined: Sun Feb 16, 2003 1:01 am
Contact:

Re: problem on programming basic stamp II

Post by hamsterears »

Let me see if I understand what you're trying to do.<p>You want the robot to check for an IR source. If it doesn't detect one, it's supposed to move forward, then stop. Then it's supposed to turn 90 degrees.<p>And what it's doing is check for the IR source, move forward, and stop? It doesn't turn?<p>You're probably going to have to post the code. I can think of some things I'd try, but without the code I might be sending you on a wild goose chase.<p>Michael Fagan
bobbob
Posts: 9
Joined: Sun Feb 23, 2003 1:01 am
Location: hk
Contact:

Re: problem on programming basic stamp II

Post by bobbob »

if hand1_IR_det = 0 then right
if hand1_IR_det = 1 then left
pause 30
gosub forward
' --- navigation rountines
right:
for pulse_count = 1 to 75
pulsout 12, 1000
pulsout 13, 1000
pause 20
return
left:
for pulse_count= 1 to 75
pulsout 12, 500
pulsout 13, 500
pause 20
return
forward:
pulsout 12, 500
pulsout 13, 1000
pause 20<p>Here is the main code of the program, i find the stamp only know right turn or left turn, but do not go forward after the turning
thanks
i am bob
hlreed
Posts: 349
Joined: Wed Jan 09, 2002 1:01 am
Location: Richmond, TX
Contact:

Re: problem on programming basic stamp II

Post by hlreed »

bob,
In your code, right, left and forward are all the same code. That is why only one thing happens.
That is all I can tell you since I know nothing about your robot.
Harold L. Reed
Microbes got brains
chessman
Posts: 292
Joined: Tue Jan 14, 2003 1:01 am
Location: Issaquah, WA
Contact:

Re: problem on programming basic stamp II

Post by chessman »

right:
for pulse_count = 1 to 75
pulsout 12, 1000
pulsout 13, 1000
pause 20
return <p>Odd how this works....since there's no NEXT pulse_count statement...it should just pulsout on each pin and then nothing, so I'm suprised it does anything at all. It shouldn't...<p>On the forward section, you also forgot the FOR...NEXT statement<p>Also, your IF THEN statement should be changed.<p>Try:<p>IF hand1_IR_det = 0 THEN GOSUB right
ELSE
GOSUB left<p>Don't forget the RETURN statement at the end of Forward.<p>Also, it appears that you want this code to loop.<p>Try putting a label 'Main:' at the top of your main code. Then, after GOSUB Forward, try GOTO Main.<p>Of course, some of my code my be a little off so Harold please correct me if need be ;)
hlreed
Posts: 349
Joined: Wed Jan 09, 2002 1:01 am
Location: Richmond, TX
Contact:

Re: problem on programming basic stamp II

Post by hlreed »

I don't know the syntax of stamp basic. You are probably right. I did not see any returns either.
But the code is the same in each sub, so they should do the same thing.
Harold L. Reed
Microbes got brains
chessman
Posts: 292
Joined: Tue Jan 14, 2003 1:01 am
Location: Issaquah, WA
Contact:

Re: problem on programming basic stamp II

Post by chessman »

Right, the code is the same, but the lengths of the PULSOUT commands are different. From the code, I'm assuming the bot has two RC servos as the motors...but I'm not comprehending the way each of them have to move to give a certain direction of travel.
hlreed
Posts: 349
Joined: Wed Jan 09, 2002 1:01 am
Location: Richmond, TX
Contact:

Re: problem on programming basic stamp II

Post by hlreed »

You are right. They looked the same to me.
You must have two motors to turn. Call them ML and MR. If the motors are on opposite sides, then
turn left = MR > ML, right = MR < ML and straight = MR = ML. The amount of turn depends on how far apart they are.
These are probably not servos, since servos take a position instead of a velocity.
We will get bobbob straight.
Harold L. Reed
Microbes got brains
chessman
Posts: 292
Joined: Tue Jan 14, 2003 1:01 am
Location: Issaquah, WA
Contact:

Re: problem on programming basic stamp II

Post by chessman »

I was implying modified servos for continuous rotation. And actually, after looking at my last post, of course they aren't modified servos! If they were, he would use the SERVO command.<p>The Pulsout is to generate the PWM, and he's using 75 cycles of that specified pulse width. Which confuses me as to how his motors are layed out when he has the pseudo-code:<p>Straight =
LM: 500
RM: 1000<p>They should be the same....unless there is one drive motor and one steering motor. Ah oh well, we'll figure it out soon enough.
josmith
Posts: 340
Joined: Tue Dec 04, 2001 1:01 am
Contact:

Re: problem on programming basic stamp II

Post by josmith »

You're trying out to many things at once. Try writing a program to try out each motion individually without including the ir input. Just forward pause stop etc. As someone else mentioned you have for with no next.
When you get to the IR part use the debug command to see what is going on.<p>[ March 14, 2003: Message edited by: josmith ]</p>
chessman
Posts: 292
Joined: Tue Jan 14, 2003 1:01 am
Location: Issaquah, WA
Contact:

Re: problem on programming basic stamp II

Post by chessman »

I wrote up some code for you real quick, try it out as your main code. The lengths of the PULSOUT commands might need to be changed to do want you want, but this infrastructure will work:<p>Main:<p>IF hand1_IR_det = 0 THEN Right
ELSE
GOSUB Left<p>Maina:<p>PAUSE 30
GOSUB Forward
PAUSE 100
GOTO Main<p>Right:<p>GOSUB RightSUB
GOTO Maina<p>Left:<p>pulse_count = 0
FOR pulse_count = 0 to 74
PULSOUT 12, 1000
PULSOUT 13, 1000
PAUSE 20
NEXT
return<p>RightSUB:<p>pulse_count = 0
FOR pulse_count = 0 to 74
PULSOUT 12, 500
PULSOUT 13, 500
PAUSE 20
NEXT
return<p>Forward:<p>pulse_count = 0
FOR pulse_count = 0 to 74
PULSOUT 12, 500
PULSOUT 13, 1000
PAUSE 20
NEXT
return
bobbob
Posts: 9
Joined: Sun Feb 23, 2003 1:01 am
Location: hk
Contact:

Re: problem on programming basic stamp II

Post by bobbob »

thanks, this time the stamp can work out the two action. but i have a problem, if i want the second action to be done just after the first one finish, that mean the stamp will consider go left or right , after finishing the turning, then it go forward, how can i do this,
if my program is design to add up a few actions together , one action is followed by the other, what is the most important thing needed to be considered ?
i am bob
bwts
Posts: 229
Joined: Tue Jun 11, 2002 1:01 am
Location: britain
Contact:

Re: problem on programming basic stamp II

Post by bwts »

The most important conderation is how to decide what action to do next.<p>Check sensors => make decision => act<p>Loop indefinately.<p>It is the decision making that makes your robot special!!<p>B)
"Nothing is true, all is permitted" - Hassan i Sabbah
bobbob
Posts: 9
Joined: Sun Feb 23, 2003 1:01 am
Location: hk
Contact:

Re: problem on programming basic stamp II

Post by bobbob »

thanks, i knew how to program it to do things step by step now. and i found my big problem in the beginning is that i always put the 'goto main' command and it made some loops that is not designed.<p>[ March 17, 2003: Message edited by: bobbob ]</p>
i am bob
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests