Shop OBEX P1 Docs P2 Docs Learn Events
Automous R/C Car — Parallax Forums

Automous R/C Car

Scott PortocarreroScott Portocarrero Posts: 72
edited 2009-07-14 04:21 in BASIC Stamp
Ok so here is the veeerrry beginning of my code. All I am trying to do here is steer the car out of the way of an object when the car gets close. I understand that the car doesn't move forward yet. My Issues:

1) The rawdata coming from the PING has a value of no more that 250 with a home made servo extension cable attached. When I plug the PING directly into the bread board it give me the correct readings up to 5000. The question is why would an extension cable give me such a variance?

2) I am very new to PBasic. Can somebody look over my code and tell me what I am doing wrong, maybe give me some pointers. All I want it to steer right when something is detected close to the left PING and to steer left when something is detected close to the right PING. To me this sounds very simple but it doesn't work.

Heeeeellllllllllppppp! freaked.gif

Post Edited (Scott Portocarrero) : 7/13/2009 4:39:46 AM GMT

Comments

  • Scott PortocarreroScott Portocarrero Posts: 72
    edited 2009-07-10 04:43
    Anyone confused.gif
  • dev/nulldev/null Posts: 381
    edited 2009-07-10 11:12
    Change this part of your code:

    IF rawdata1 < 200 AND rawdata2 < 200 THEN GOSUB Steer_Center
    IF rawdata1 > 200 AND rawdata2 > 200 THEN GOSUB Steer_Center
    IF rawdata1 > rawdata2 THEN GOSUB Steer_Left
    IF rawdata1 < rawdata2 THEN GOSUB Steer_Right
    IF rawdata1 = rawdata2 THEN GOSUB Steer_Center
    PAUSE 20
    
    GOTO Main
    
    



    About the PING sensor, do you have a Voltmeter? Then you can check the cable for resistance, maybe its broken. This shouldn't happen to a PING and if the cable is ok, the PING might be damaged.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't worry. Be happy
  • Scott PortocarreroScott Portocarrero Posts: 72
    edited 2009-07-12 05:41
    It didn't work. I think I need to get the values coming from the PING)) correct (in the 5000's) for this to work properly. What do you think?
  • dev/nulldev/null Posts: 381
    edited 2009-07-12 10:50
    Try this:

    IF rawdata1 > rawdata2 THEN 
       GOSUB Steer_Left
    ELSEIF  rawdata1 < rawdata2 THEN
       GOSUB Steer_Right
    ELSE
       GOSUB Steer_Center
    ENDIF
    
    PAUSE 20
    
    GOTO Main
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't worry. Be happy
  • dev/nulldev/null Posts: 381
    edited 2009-07-12 10:51
    You should add some slack to your measurements, so this will probably work better:
    This way, there is a slack of 50 before you start turning.

    IF rawdata1 > (rawdata2+50) THEN 
       GOSUB Steer_Left
    ELSEIF  rawdata1 < (rawdata2 + 50) THEN
       GOSUB Steer_Right
    ELSE
       GOSUB Steer_Center
    ENDIF
    
    PAUSE 20
    
    GOTO Main
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't worry. Be happy
  • SRLMSRLM Posts: 5,045
    edited 2009-07-13 04:14
    You'd probably get more responses if you attached the file with the correct extension.
  • Scott PortocarreroScott Portocarrero Posts: 72
    edited 2009-07-13 04:21
  • SRLMSRLM Posts: 5,045
    edited 2009-07-13 05:06
    Try making the raw data variables word sized. According to the documentation it can be up to 18 ms long. Also, you can make your steering routines much more efficient if you have just one routine that takes an argument of the direction. Something like this:

    IF want go left THEN dir = SERVO_LEFT
    ELSEIF want go straight THEN dir = SERVO_STRAIGHT
    ELSEIF want go right THEN dir = SERVO_RIGHT
    ELSE GOTO error

    GOSUB steer

    ...

    steer:

    ...
    PULSOUT servo_pin, dir
    ...
  • Scott PortocarreroScott Portocarrero Posts: 72
    edited 2009-07-13 22:43
    Excuse my ignorance but is "want go left" a variable like:

    want go left VAR BYTE
    want go right VAR BYTE
    want go straight VAR BYTE

    What is GOTO error?

    I feel like this is something very simple!
  • SRLMSRLM Posts: 5,045
    edited 2009-07-14 04:21
    Scott Portocarrero said...
    Excuse my ignorance but is "want go left" a variable like:

    It's my lazy pseudo code...

    "want go left" would be the condition that determines a left hand turn. From your code, you used the comparison "rawdata1 > rawdata2".

    I put the GOTO error in there as a catch all for debugging: if the robot shouldn't go left, right, or straight, what's else is there to do? You could determine that you have an error at that point.

    As a side note, you used "IF rawdata1 = rawdata2 THEN Steer_Center". This case will almost never be true since there are ~65,000 possible values for rawdata1 and ~65,000 values for rawdata2. The chances that they are equal are very small. Instead, what you might want to do is to use ranges. For example, if the right sensor distance is less than 12 cm and the left sensor is greater than 12 then turn left.

    edit: dev/null posted something similar, using the term slack.
Sign In or Register to comment.