Shop OBEX P1 Docs P2 Docs Learn Events
Ping and Servo control — Parallax Forums

Ping and Servo control

Scott PortocarreroScott Portocarrero Posts: 72
edited 2009-08-15 04:27 in BASIC Stamp
All I am trying to do is take a reading from the ping, if the distance of the reading is less than 600 I want to go right. It kind of works but will start pulsing the servo to go right as long as the distance reading is less that 600. The servo doesn't go straight to right but pulses a couple of degrees at a time, never really makes it though. Can someone look over my code and make some suggestions??

Ok so here is a snippet of my code:

LeftPing PIN 2
CenterPing PIN 3
RightPing PIN 4

SteeringServo PIN 5
SpeedControl PIN 6

LeftRaw VAR Word
CenterRaw VAR Word
RightRaw VAR Word
PulseCount VAR Word

Min_D CON 600 ' ~14"
Max_D CON 5000 ' ~3'


main:

DO

IN2 = 0
PULSOUT LeftPing, 1 ' Activate sensor
PULSIN LeftPing, 1, LeftRaw ' Store Results
PAUSE 1000
DEBUG ? LeftRaw

LOOP


IF (LeftRaw < Min_D) THEN
GOSUB right




right:
FOR PulseCount = 1 TO 10
PULSOUT SteeringServo,650
PAUSE 20
NEXT
GOTO main

Comments

  • SRLMSRLM Posts: 5,045
    edited 2009-08-14 16:08
    Please post code (as an attachment) that compiles. The version you posted won't compile. Also, I suspect that you commented out everything that you thought was irelevant. Even if I were to uncomment the LOOP, that would just create an infinite loop of pinging. So, please re comment too.

    Post Edited (SRLM) : 8/14/2009 4:22:12 PM GMT
  • Scott PortocarreroScott Portocarrero Posts: 72
    edited 2009-08-15 03:10
    Sorry 'bout that here is the new file
  • SRLMSRLM Posts: 5,045
    edited 2009-08-15 04:27
    You need to either change line 57 to GOTO or change line 139 to RETURN. Also, you can get rid of line 39 (it slows things down considerably without reason).
Sign In or Register to comment.