Shop OBEX P1 Docs P2 Docs Learn Events
can't get going with PBasic - need help! — Parallax Forums

can't get going with PBasic - need help!

rolivierrolivier Posts: 7
edited 2009-05-28 17:21 in Robotics
I built my first·robot arm·using a Parallax Servo Controller (PSC) to control 3 servos.· I used the CPSCI program to capture key sequences and it works great!·· Now I would like to write my own program using PBasic 2.5.·· I tried all of the snippets in the Parallax Servo Controller (#28023) - Rev B manual, but can't get any to work.· If I could just get the Position Command to work then I could probably·figure out·the rest.
Here is what I tried:
1. I used the Basic Stamp editor to create the source file and check syntax.
2. I tried running the program from the editor, but it gives me a stamp-not-found error, so...
3. I tried running it with hyperterminal.· Didn't work, so...
4. I copied the program using via DOS, e.g. "copy myfoo.bas COM3"
5. The program loaded into the PSC, but nothing happened.· The servo did not move.
6. I tried using different file extensions, e.g. .bas, .bsx, etc
7. I tried compiling to a .exe and .obj and executing/loading those, still no response from the servos.
7. I tried using different channels: the·three I use are 0, 1, and 2
8. I tried sending the other snippets, no luck.· If I put them all together in a program (I thought maybe the baud rate had to be set/reset first), I get a few odd shakes of the robot arm but that's it.
shakehead.gif

If PBasic works for you on PSC, please tell me how to get started.· I'm working in Windows XP.· Here is the snippet:

'{$PBASIC 2.5}

ch· VAR· Byte

pw· VAR· Word

ra·· VAR· Byte

Sdat· CON 15···· ' << it is 15 in the example, but I also tried 2, since the serial pin on the PSC chip is 2.

baud· CON· 396

······· ra = 7

······· ch = 11··· ' << i used 0 instead of 11, since this is the first channel i am using on the PSC.· Also tried 1 and 2

DO

······· pw = 1250

······· SEROUT Sdat, Baud+$8000, {"!SC", ch, ra, pw.LOWBYTE, pw.HIGHBYTE, CR}

······· PAUSE· 1000

······· pw = 250

······· SEROUT Sdat, Baud+$8000, {"!SC", ch, ra, pw.LOWBYTE, pw.HIGHBYTE, CR}

······· PAUSE· 1000

LOOP

Comments

  • KB3JJGKB3JJG Posts: 95
    edited 2009-05-28 00:19
    You are using { in your serout statements instead of [noparse][[/noparse], swap the { for [noparse][[/noparse] and you should be ok.
    ·
  • rolivierrolivier Posts: 7
    edited 2009-05-28 11:40
    thanks for responding. I tried it with square brackets instead of curly braces, still no go. I'll try a different approach.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-05-28 14:25
    The PSC is not programmable. It sounds like you are trying to use the Stamp Editor to program the PSC itself. To do what you want, you will need a separate Stamp and some kind of mounting board (like the Board of Education) for it that will provide a programming connector and voltage regulator.

    The PSC does have a microcontroller on it, but it's not user programmable. It receives serial commands from a PC or another microcontroller and produces servo control pulses as commanded.

    Post Edited (Mike Green) : 5/28/2009 2:31:24 PM GMT
  • rolivierrolivier Posts: 7
    edited 2009-05-28 14:39
    OK that makes sense, but the PSC is always connected to the laptop so the laptop should be able to send serial commands. I can live without the Stamp Editor and the BOE; I would rather keep this project as simple as possible. If I use the CPSCI program (open source from Parallax), the robot arm works just fine. I could probably continue to use it my robot arm this way but I was hoping to code something similar so I can understand it better. I have the CPSCI source code so my next step is to tear into it to try to figure it out.
    thanks for responding
    -=Rich
  • Mike GreenMike Green Posts: 23,101
    edited 2009-05-28 14:46
    Download the manual for the serial version of the PSC. It documents the command format. You could use any programming language to control the PSC that can open a serial port and send bytes out the port.
  • rolivierrolivier Posts: 7
    edited 2009-05-28 15:03
    That's what I'm trying to do. The example above (in my first post) is a snippet from the PSC serial manual where they show what it takes to make the PSC move a servo. I now understand that I can't just download the code as-is and have it move the servos. What I'm trying to figure out is how to programatically get it into a form that the PSC can digest.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-05-28 15:13
    The serial PSC manual describes each of the commands. These are the byte sequences that you have to send from the PC to the PSC to get the PSC to do its thing.

    In the case of the movement command you showed, you have to send the characters "!", "S", "C", then the channel number as a single byte value, then the ramp value as a single byte value, then the pulse width value as two byte values with the least significant byte first, then a carriage return character (value 13).

    The details of how to write this sort of thing depend on the programming language you plan to use.
  • rolivierrolivier Posts: 7
    edited 2009-05-28 15:25
    I understand now. Thanks for explaining it. You have a lot of patience!
  • SamMishalSamMishal Posts: 468
    edited 2009-05-28 16:52
    Rolivier,

    What you are trying to do is precisely what we did in the Robot Vision project shown in the following video
    ·http://www.youtube.com/watch?v=LwvspYFXJMM&feature=channel_page


    All the controls were performed with the programming language RobotBASIC· http://www.RobotBASIC.com.

    In the program you can find examples for how to control the Parallax Servo Controller using RobotBASIC
    which is what you are trying to do here is a link:
    ·http://www.robotbasic.org/resources/Humanoid+Vision.zip


    There was an article about all this in Servo
    ·http://www.servomagazine.com/media-files/971/A_Robotic_Puppet-SV200811.pdf

    If you want to see how to use RobotBASIC's serial IO see this document
    ·http://www.robotbasic.org/resources/RobotBASIC_To_BS2_Comms.pdf

    Also see this to see how to set the BS2 to do serial IO with RB
    ·http://www.robotbasic.org/resources/RobotBASIC_Serial_IO.pdf



    I hope that helps

    Regards

    Post Edited (SamMishal) : 5/28/2009 5:08:17 PM GMT
  • rolivierrolivier Posts: 7
    edited 2009-05-28 17:21
    Thanks for the pointers, I'll check them out!
    -=Rich
Sign In or Register to comment.