Shop OBEX P1 Docs P2 Docs Learn Events
New robot — Parallax Forums

New robot

totcohandtotcohand Posts: 28
edited 2009-03-04 03:28 in Robotics
ok. Just got all the parts to make my new bot. I have a few ?'s about the program I am writing though.· First of all, I have a P/T turret that turns left and rigt when an object is detected in the front. I want it to store a time for each side to determine which side has a clear path. In my program I used Time1 and time2 but I am not sure if I have it written right.· Also when I run it, the bot does not move and it just runs the ping if I put my hand if front of it, it will go into the turret scan subroutine but nothing else. If you are wondering why my times are weird for the turret I am using a continuous rotation servo for the pan function.· Any suggestions will be greatly appreciated.

Thank You

'{$stamp BS2}
'{$Pbasic 2.5}
'Lynxmotion Bot
'Written by Jason Smith 25Feb09
'
'
'
Variables
Right·· PIN 14········································ 'Variable for right motor controller
Left··· PIN 15········································ 'Variable for left motor controller
Hturret PIN 01········································ 'Variable for Horizontle Turret movement
Vturret PIN 12········································ 'Variable for verticle turret movement
Ping··· PIN 00········································ 'Variable for Ping sensor
counter VAR Byte······································ 'Variable for counter
Time··· VAR Word······································ 'Variable for time
Time1·· VAR Byte······································ 'Variable for time1
Time2·· VAR Byte······································ 'Variable for time2
'
Initialize
PAUSE 5000············································ 'Wait 5 sec before starting
'
Main Program
Main:
GOSUB radar··········································· 'check distance
IF time > 1000 THEN GOSUB Forward····················· 'if distance is clear go Foward
IF time <= 1000 THEN GOSUB turret_scan················ 'if object is detected then scan for clear path
IF time1 > time2 THEN GOSUB turn_left················· 'if time1 is greater than time2 then turn left
IF time2 > time1 THEN GOSUB turn_right················ 'if time2 is greater than time1 then turn right
GOTO Main

'
Sub-Routines
Forward:
DO WHILE Time > 1000··································· 'keep moving until Ping senses something in the way
GOSUB radar············································ 'run radar subroutine
IF Time <= 1000 THEN GOTO Main························· 'keep checking distance while moving foward
PULSOUT right, 400
PULSOUT left, 800······································ 'Go forward
PAUSE 18
LOOP

Back_Up:
FOR counter = 1 TO 20
GOSUB radar
IF time > 700 THEN GOTO Main·························· 'return to main if time is right
PULSOUT right, 800
PULSOUT left, 500····································· 'Back up
PAUSE 18
NEXT
RETURN

Turn_Right:
FOR counter = 1 TO 130································· 'keep moving for 130 pulses
GOSUB radar
IF Time > 1000 THEN GOTO Main·························· 'keep checking distance while turning
PULSOUT right, 740
PULSOUT left, 800······································ 'Turn right
PAUSE 18
NEXT
RETURN

Turn_Left:
FOR counter = 1 TO 130································· 'keep moving for 130 pulses
GOSUB radar
IF Time > 1000 THEN GOTO Main·························· 'keep checking distance while turning
PULSOUT right, 800
PULSOUT left, 740······································ 'Turn left
PAUSE 18
NEXT
RETURN

Turret_Scan:
FOR counter = 1 TO 115
PULSOUT hturret, 800
NEXT
GOSUB time_1
PAUSE 1500
FOR counter = 1 TO 230
PULSOUT hturret, 450
NEXT
GOSUB time_2
PAUSE 1500
FOR counter = 1 TO 48
PULSOUT hturret, 825
NEXT

Radar:
PULSOUT ping, 5
PULSIN ping, 1, time
RETURN

Time_1:
PULSOUT ping, 5
PULSIN ping, 1, time1
RETURN

Time_2:
PULSOUT ping, 5
PULSIN ping, 1, time2
RETURN

Comments

  • totcohandtotcohand Posts: 28
    edited 2009-03-03 15:33
    Just wanted to add that I am using a sabertooth 2x5 controller from lynxmotion as I got it for free.
  • Jessica UelmenJessica Uelmen Posts: 490
    edited 2009-03-03 17:23
    Hi totcohand,

    It appears that in your Turret_Scan subroutine, you left out the RETURN command. This would be why it is stuck in this subroutine, as you are never telling the program to return to Main.

    Hope this helps!

    Jessica

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jessica Uelmen
    Education Department
    Parallax, Inc.

    Post Edited (Jessica Uelmen (Parallax)) : 3/3/2009 7:16:20 PM GMT
  • Guenther DaubachGuenther Daubach Posts: 1,321
    edited 2009-03-03 18:19
    Hi Jessica,

    actually, totcohand left out the RETURN, not the NEXT. So execution "falls through" to Radar: and only returns after falsely doing the ping stuff.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Greetings from Germany,

    G
  • Jessica UelmenJessica Uelmen Posts: 490
    edited 2009-03-03 18:35
    Thanks Guenther!

    That's what I meant to type - I was thinking RETURN and typed NEXT because it must have been the last thing I saw in the code.

    Jessica

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jessica Uelmen
    Education Department
    Parallax, Inc.
  • totcohandtotcohand Posts: 28
    edited 2009-03-04 03:28
    Thanks alot for the help! Ill give this a shot and see what else fails next. [noparse]:)[/noparse]
Sign In or Register to comment.