Shop OBEX P1 Docs P2 Docs Learn Events
Ping))) problem, PLEASE HELP — Parallax Forums

Ping))) problem, PLEASE HELP

connorbossconnorboss Posts: 1
edited 2009-12-29 20:45 in Accessories
Hello all! I believe I am having a problem with my ping))) sensor. I am using it to make a balancing robot and it is having some problems which I am not sure if they are hardware or software related. The ping sensor seemed to work fine when I ran a test to find the optimum height for my balancing program. This test program is as follows...

distance VAR WORD
pingsensor PIN 15
DO
PULSOUT pingSensor, 4
PULSIN pingSensor, 1, distance


DEBUG DEC distance
DEBUG CR
PAUSE 20
LOOP

When I run this program the sensor returns good data that I was able to write my balancing program off of. However, when I load my balancing program onto the basic stamp, the ping sensor flashes erratically. I have it to the point now that the ping sensor seems fairly stable until it reaches my zero error. I have already tested for browning out and that is not the case. This is my balancing program...

rservo PIN 12
lservo PIN 13
ping PIN 15

distance VAR WORD
kp CON 20
perfect CON 300
error VAR WORD
drive VAR WORD
right VAR WORD
left VAR WORD

DO

PULSOUT ping, 5
PULSIN ping, 1, distance
error = perfect - distance
drive = error * kp
IF (drive > 100) THEN
drive = 100
ELSEIF (drive < -100) THEN
drive = -100
ENDIF
right = 750 - drive
left = 750 + drive
PULSOUT rservo, right
PULSOUT lservo, left

LOOP

It is really weird because when I take out the two pulsout commands for the servos the ping sensor stabilizes mostly. Like I said before the ping sensor and robot will run smoothly until it begins to reach zero error which is bad because the robot is balanced at zero error. I was wondering if anyone had had this happen to them and if anyone knew what it was or how to fix it? Thank you in advance for any help.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-12-28 21:35
    There are two problems with your program ...

    1) The PULSOUT statements will take some time to execute, anywhere from 1.3ms to 1.7ms each, an average of 3ms for both. That adds to the loop time.

    2) Assuming the PING))) takes about 3ms for the echo to return, the total loop time is about 6-8ms which is way too short for the servos. They need to have the control pulse occur about every 20ms. The easiest way to do this would be to add a "PAUSE 17" to the loop. The question is whether 50 times a second is fast enough for balancing. If you add more code to the loop, you can reduce the PAUSE time appropriately to keep the loop time near 20ms.
  • JohnBFJohnBF Posts: 107
    edited 2009-12-29 20:45
    I think my project shows that a 20ms cycle is fast enough to keep a robot balanced.

    http://forums.parallax.com/forums/default.aspx?f=21&m=162898

    I found it difficult to have the BS2 complete all the steps that quiclkly, although more efficient programming might have done the trick. In any case there was no difficulty once I move to the BS2SX, or in a later version using the Propeller.

    /John
Sign In or Register to comment.