Shop OBEX P1 Docs P2 Docs Learn Events
PSC help needed! — Parallax Forums

PSC help needed!

PitchingOnePitchingOne Posts: 24
edited 2006-05-02 00:45 in General Discussion
Hello everyone,
······ I am new to Parallax products. I am trying to operate three servos via the PSC useing the Javelin Stamp demo board. I got serial communication (green light flashes on the PSC) but the following does not work:

1- I can't get the PSC to tell me it's version number. The following code attempts to do that

public void getSvoCtrlResponse(){
··· buffer.clear();
··· uart.sendString("!SCVER?");····· //command servo to verify communication
··· uart.sendByte(0x0D);··········· //End Byte

····· uart.setDirection(1);····················· //read mode
········· for(int i =0;i <3;i++){
··········· buffer.append((char)uart.receiveByte());
········· }
······· System.out.println(buffer.toString());
···· uart.setDirection(0);· //write mode
}//end getVersion



2- after this verification, I attempt to check the servo's current position with the following code:
public void checkServoPos(int pscChannel){
··· uart.sendString("!SCRSP");········ //servo position command
··· uart.sendByte(pscChannel);····· //Channel of Servo
··· uart.sendByte(0x0D);··········· //End Byte
···· buffer.clear();
···· uart.setDirection(1);·························· //read mode
········· for(int i =0;i <3;i++){··················· //Three byte response expected for version command
········ buffer.append((char)uart.receiveByte());
········· }
······· System.out.println(buffer.toString());
··· uart.setDirection(0);·························· //write mode

}
3- then, I command the servos to move :
·· public void moveServo(int pscChannel, int ramp,int pulseWidth)
··· {
··· uart.sendString("!SC");········ //Servo Controller
··· uart.sendByte(pscChannel);····· //Channel of Servo
··· uart.sendByte(ramp);··········· //Ramp Rate
··· uart.sendByte(pulseWidth);····· //Pulse Width
··· uart.sendByte(pulseWidth>>>8);
··· uart.sendByte(0x0D);··········· //End Byte
··· }
·I have attached my whole code, in case you would like see it.

Your help will be truly appreciated. I am trying to finalize this code by this weekend.

Thanks

«1

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-29 05:01
    This thread is being moved from the BASIC Stamp Forum to the Javelin Forum.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-04-29 05:46
  • bulkheadbulkhead Posts: 405
    edited 2006-04-29 05:51
    I use the PSC with the class provided by parallax (see the yahoo group, there should be a thread at the top of this forum). I'll attach the class too. You can probably check how it is done in the class, and that should be pretty close to what you want to do (if not, EXACTLY what you are trying to do). Make sure you have it wired correctly too, I have the 3 wire jumper hooked up to ground, the javelin's 5V regulated output, and my signal pin.

    One strange problem I could not over come was, I could not get my PSC to work unless I ran it off of a separate battery pack from my javelin. Now I just run 2 battery packs, 1 for each and it works. If you still can't get it to work, it might be worth your time to check if it works using separate power sources before trying other things.

    Put the file(s) in lib>stamp>peripheral>servo>psc (you need to create those folders if you dont already have them)

    One more thing, which you you will probably figure out-when the PSC starts up, the servos all go to center position and ramp towards their first initialized position. To prevent this, I power on my javelin first, then I turn on my PSC after a few seconds.
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-04-29 06:17
    I noticed you try to use 38k4 baud.
    Do not use 38k4 as the javelin may have
    trouble receiving at 38k4. Stick to 2400 baud.

    regards peter
  • PitchingOnePitchingOne Posts: 24
    edited 2006-04-29 14:12
    ThanK you very much for the prompt response.
    I went to the site you referred on yahoo groups but I get this message,
    "You are not a member of the group JavelinCode. "·
    I will now go to the lab and test the servos with your suggested comments. I will notify if it works or not.burger.gif
    Thanks


    ·
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-04-29 14:35
    You must join the JavelinCode group to download files.
    It is free.

    regards peter
  • PitchingOnePitchingOne Posts: 24
    edited 2006-04-29 16:54
    Ok... I tried psc_onepin_test.java and it failed. The terminal does not give me the right angle. it displays -2184-9 and it displays this to all (l c r m p) commands.

    I have one power supply for the Javelin and another one for the servos. One of my servos moves continuously (continous motor) as soon as the PSC is turned on...I am not quite sure why it does that, since I do not tell it to move. I think it is trying to go to center position, but it never stops itself.
    I disconnected this servo, and connected the other two servos to test them individually...but the code failed as well.

    I tried my own code leaving the 2400 baud and nothing works still. I don't know what to do next.
  • PitchingOnePitchingOne Posts: 24
    edited 2006-04-29 17:14
    To make it clearer, I am trying to control two continous motors and one standard motor. The continous motors rotate continously as soon as the PSC power switch is turned on. Why does not stop?
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-04-29 17:27
    The testprogram uses CPU.pin0 for the serial connection and requires
    one servo motor connected to channel 0 of the psc.
    Your program used CPU.pin4 for the Uart, you might want to change
    that in the psc_onepin_test.java program. Be sure to have only
    one motor connected to channel 0.

    regards peter

    Post Edited (Peter Verkaik) : 4/29/2006 5:30:15 PM GMT
  • PitchingOnePitchingOne Posts: 24
    edited 2006-04-29 18:04
    I am aware of that,I changed it because the PSC serial line is connected to pin 4 from the Javelin I/O header board. I changed it to pin0, just to see if this would miraculously do something, but it does not work.

    mad.gif
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-04-29 18:24
    Check out this thread, it is the thread Bulkhead started to get his psc running.
    http://forums.parallax.com/showthread.php?p=577032

    Bulkhead has it running with the psc class, so obviously there is something wrong
    with your hardware setup. Please provide all servo motor types and how you
    connect the motors, the psc,·the javelin and the power supplies.
    For a start, stick to 1 motor connected to channel 0.

    regards peter
  • PitchingOnePitchingOne Posts: 24
    edited 2006-04-29 20:53
    I have two Continuous servo motors and 1 standard servo motor.

    This is exactly how it is wired:
    The javelin powers the PSC (the cables were separated so that the white wire goes to pin0, red to vdd and black to vss )

    The servos have their own power supply(5V). so when the PSC's swith is on, the servo's turn on.

    One servo is connected to Channel 0 just so we can test one servo at a time.

    When I test the standard servo, it moves to it's home position as soon as I power the PSC, even if there is no program running in the Javelin. (I guess this is normal, but it still does not respond to what I command it to do)

    When I test the continous motors, they both rotate forever, as soon as the PSC swith is turned on...why don't they stop moving?

    I read the thread that bulkhead started, and followed what he said seemed to strangly work, but my servos still do not respond.

    Once again, thank for your help
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-04-29 21:06
    Add the following line to the start of main()
    System.out.println(myPsc.version());

    The current version of psc is v1.3 so myPsc.version() should return 0x3133
    (which is 12595 decimal)
    If you don't get that number then somehow the cummunication
    between javelin and psc board fails. If you do get that number
    you know there is communication.

    regards peter
  • PitchingOnePitchingOne Posts: 24
    edited 2006-04-29 21:15
    All right!! that works. I get 12596 on the Terminal.
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-04-29 21:42
    And what do you get for the c command?
    (enter c in the one line text window of the Javelin message window)
    It should display "Angle = 90.0"

    regards peter
  • PitchingOnePitchingOne Posts: 24
    edited 2006-04-29 21:50
    I get -2184.-9.
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-04-29 22:05
    Add the lines
    ······· int pos = myPsc.getPosition(0);
    ······· System.out.println(pos);
    to the end of·the while (true) loop
    (after·the line
    ······· System.out.println(angle%10);
    )
    The center position equals 750
    so it then should display 750

    regards peter
  • PitchingOnePitchingOne Posts: 24
    edited 2006-04-29 22:12
    I get -4606...Why am I getting these values?
  • PitchingOnePitchingOne Posts: 24
    edited 2006-04-29 22:23
    I get that value for all the commands that I send. So, do you have any idea why the continuous servos won't stop moving?
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-04-29 22:36
    The -4606 position value corresponds to the -21849 angle value
    (obviously, since the angle is calculated from the position)

    I would disconnect those continues servos and only connect
    the standard servo to channel 0.

    Then what do you get?

    regards peter
  • PitchingOnePitchingOne Posts: 24
    edited 2006-04-29 22:37
    That is what I get for the standard servo. [noparse]:([/noparse]
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-04-29 23:00
    You get -4606 which is -4606+65536 = 60930 or 0xEE02

    You should get 750 or 0x02EE

    It appears the lowbyte and highbyte of position are swapped.

    Add the following line after the line int pos =
    pos = (pos>>>8)|(pos<<8); //swap low and high byte of pos

    That should then display 750

    Then try the other commands as well.

    regards peter
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-04-29 23:11
    The psc manual states
    Syntax: “!SCRSP” x $0D
    Reply: x y z(where x is the channel number, and z:y is the value reported)
    The psc class complies to this definition.

    The basic stamp example in the manual says
    SEROUT Sdat, Baud+$8000, [noparse][[/noparse]"!SCRSP", ch, CR]
    SERIN Sdat, Baud, 1000, Init,[noparse][[/noparse]STR Buff\3]
    DEBUG "Servo ", DEC buff(0), " ", HEX2 buff(1), " :", HEX2 buff(2), CR

    which would indicate the position is y:z (and not z:y)


    Perhaps bulkhead can confirm which is the correct definition.

    regards peter
  • PitchingOnePitchingOne Posts: 24
    edited 2006-04-29 23:31
    Ok, the math is now correct, but my servos are still not working. The standard servo, jerks a little when the PSC switch is on and it does not respond to my commands. And as far as the other servos (Continuous servos) I tested them one at a time as well and they still move continously...what is going on? My head is spinning right now.
  • PitchingOnePitchingOne Posts: 24
    edited 2006-04-29 23:34
    Is it possible to speak to you over the phone?
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-04-30 00:01
    You cannot speak to me over the phone.
    The math appears to be correct, but the psc class worked for bulkhead.
    I posted a message in the basic forum regarding the byte order of
    the position value. The manual is in error, either with the definition or with
    the example. Hopefully I get an answer soon.

    As I don't have a psc board, someone with servo experience should post
    a reply, for I have no idea why your servo isn't moving. You haven't
    by mistake set the psc board to channel 16 have you? (check jumper)

    regards peter
  • PitchingOnePitchingOne Posts: 24
    edited 2006-04-30 00:05
    What jumper?
  • PitchingOnePitchingOne Posts: 24
    edited 2006-04-30 00:24
    Ok. something real strange just happened. I downloaded your test program again, to the javelin. Originally, the Terminal window would showed up displaying the version number and the angle position of the servo.

    Now, the terminal window does not show up! However, when I move the serial cable out of my javelin I/O header (I accidently did this) the terminal window showed up!!!! with diffent angle position for all the commands...I thought that was a great sign, but the servos won't respond. As far as the serial line is concerned, I am not sure why it all of a sudden responds that way.

    WOW, this is really blowing my mind... : (
  • bulkheadbulkhead Posts: 405
    edited 2006-04-30 00:35
    Ok, first check your wiring. The 3 wire jumper should be plugged into one of the 2 rows in the black enclosure above channel 15. The black wire should be on the outside, for the jumper and the servos.

    Did you make the changes to your program in the test program? That would explain why it is different. I am currently using the psc class, so that should be working, but I can't really say about that test program (although I recall it working).

    If your servos go to center position when you turn on your PSC, it means that it is running the "frames" stored in its own memory. These are the commands that you load onto it through USB or serial port directly. You need to have your javelin send the first data bytes to "initialize" the servo positions BEFORE you turn on your PSC, otherwise it will begin executing the frames that are stored in your PSC. I avoid this by turning on my javelin, and then waiting for the green light on the PSC to flash (indicating data transfer). At that point I turn on the PSC's switch.

    When you send a data byte or bytes to your PSC, you should see the PSC's green LED flash. If it is, then you know your javelin is sending the commands.

    If you can, try running your single servo off of 4 AA batteries. Servos may not function properly at low voltages, although I believe they are designed for 4.8V operation. This probably won't help much, but it's something to try. If you have a multimeter, check the voltage that the servo is getting when the PSC is switched on.

    Edit: one more thing I forgot to mention. I tried using the getPosition() method,but I get really large/small numbers and don't know how to convert them. I just keep track of position in my main class, and it works fine for my purposes.

    Post Edited (bulkhead) : 4/30/2006 12:39:11 AM GMT
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-04-30 01:46
    I mean the jumper in figure 5, page 7, of the psc manual.
    regards peter
Sign In or Register to comment.