Shop OBEX P1 Docs P2 Docs Learn Events
PING)), LCD, and Servo Combination Problems — Parallax Forums

PING)), LCD, and Servo Combination Problems

Bill ChennaultBill Chennault Posts: 1,198
edited 2010-01-11 23:01 in General Discussion
All--

Environment: SX28 at 4MHz on a PDB with a USB SX-Key·and the 7.5v Parallax wall transformer.

PING)) works fine for me and is amazingly accurate.

My Parallax parallel 2x16 LCD works fine with the demo programs, including the modifications I make to them.

The servo is easy to use, although I probably do not understand it thoroughly.

I can make PING)) work with the LCD.

I can make PING)) work with the servo.

I CANNOT make PING)) work with the servo AND the LCD. When the servo works correctly, the LCD displays garbage (seen in the first·clip). When the LCD works correctly, the servo is highly stupid (seen in the second clip). By the way, you probably cannot read the LCD display in the second clip, but it is displaying·the correct PING)) distance.

My impression is that there are timing issues that prevent the LCD working with the servo code. I have attached the code plus two very short video clips of how it executes: Servo Working and LCD Working. The only difference between the two video clips is shutting down the IDE, turning off the PDB, and removing and replacing the USB connection.

Here is the meat of the code. (The entire code is attached.)

Start:
· PLP_A = %0000·····' pull-ups on unused pins
· PLP_B = %1111_1110
· PLP_C = %0000_0011
Lcd_Setup:
· DELAY_MS 500·····' let LCD self-init
· LCD_INIT· ·····' initialize (multi-line)
Main:
·· for idx = 0 to pulses
··· tmpB5 = idx/30
··· tmpB6 = __REMAINDER
··· if tmpB6 = 0 then····' Ping every 0, 30, 60, and 90 pulses
····· ' Ping . . .
····· distance = GET_DISTANCE
····· DELAY_MS 100
····· ' Send Distance to LCD . . .
····· LCD_CMD LcdCls
····· DELAY_MS 25····' for effect
····· LCD_STR "Distance: "
····· LCD_DEC distance, 5
····· DELAY_MS 25
··· endif
··· pulsout servo, 1000
··· DELAY_MS 20
· next
· for idx = 0 to pulses
··· tmpB5 = idx/30
··· tmpB6 = __REMAINDER
··· if tmpB6 = 0 then····' Ping every 0, 30, 60, and 90 pulses
····· ' Ping . . .
····· distance = GET_DISTANCE
····· DELAY_MS 100
····· ' Send Distance to LCD . . .
····· LCD_CMD LcdCls
····· DELAY_MS 25····' for effect
····· LCD_STR "Distance: "
····· LCD_DEC distance, 5
····· DELAY_MS 25
··· endif
··· pulsout servo, 500
··· DELAY_MS 20
· next
· GOTO Main


I sure would appreciate any comments you might have.

Thanks!

--Bill

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.

Comments

  • JonnyMacJonnyMac Posts: 9,211
    edited 2010-01-11 20:32
    One of the issues you may run into is the requirement for refreshing the servo when you need a long delay. I tend to define a variable for the servo's position and then create a shell for PAUSE like this:

    SUB SERVO_DELAY
      '{$IFUSED SERVO_DELAY}
      msDuration    VAR    __WPARAM12
    
      DO WHILE msDuration > 20
        PULSOUT Servo, pos
        MS_DELAY 19
        msDuration = msDuration - 20
      LOOP
      '{$ENDIF}
      ENDSUB
    



    So, instead of PAUSE 1000 you would use SERVO_DELAY 1000. Of course, pos needs to be set first.
  • Bill ChennaultBill Chennault Posts: 1,198
    edited 2010-01-11 22:28
    JonnyMac--

    Thanks for the hint! I will implement it tomorrow and see what happens.

    It must be possible to do this with an SX, because I HAVE the BS2 code that will do it on the BOE-Bot. It has become a learning issue with me, even though I will eventually just use three PING)) sensors on my machine.

    Thanks, again.

    --Bill

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You are what you write.
  • JonnyMacJonnyMac Posts: 9,211
    edited 2010-01-11 22:32
    You might want to "round robin" your Ping scans. Remember, the Ping can take up to 11ms to respond and you really need to be refreshing your servo every 20ms or so. Another, albeit trickier, approach is to us interrupt so that you can ensure the servo is updated ever 20ms no matter what else is happening.
  • Bill ChennaultBill Chennault Posts: 1,198
    edited 2010-01-11 23:01
    JonnyMac--

    Forgive me. I don't think I wrote clearly.

    What I will PROBABLY do is simply mount three PING)) sensors solidly to the front of the machine at angles to one another such that I can cover the forward, say, 90*, or so. I'll activate one on the side, read it, then the front one, read it, and then the one on the other side and read it. I may not sweep back the other direction. Instead I'm thinking I could just start over as outlined above.

    Another thing that seems neat to me is the idea of making each PING)) a smart sensor, somewhat along the lines I followed with the BS2p40 and the four OEM-BS2 Stamps that formed the brains of Ugly Buster and then RC Buster. I think a "fast" Stamp dedicated to each PING)) would do this nicely.

    However, the programming issue involving the servo and PING)) and the LCD (I don't really need the LCD, but I thought it would be neat to·look at while the robot pings around) intrigues me, especially since I don't seem to be able to do it! [noparse]:)[/noparse]

    So, I am going to follow your advice tomorrow, first!

    --Bill

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You are what you write.
Sign In or Register to comment.