Ping and Servo control
Scott Portocarrero
Posts: 72
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
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
Post Edited (SRLM) : 8/14/2009 4:22:12 PM GMT