Shop OBEX P1 Docs P2 Docs Learn Events
Serial PSC Commands - Page 2 — Parallax Forums

Serial PSC Commands

2»

Comments

  • WaldoDTDWaldoDTD Posts: 142
    edited 2005-12-09 17:35
    the issue is not recieving the commands, when it updates the servos instead of going to the desired position, it goes to the exact opposite position then when i put in the opposite position it goes to the correct position.
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-12-09 17:42
    You still need the line cmdlen=0 otherwise when receiving a new command, the

    parsing starts at the position in buf[noparse]/noparse where the previous command ended, while

    the new command starts at position 0 in buf[noparse]/noparse.

    Regards peter
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-12-09 17:54
    I deleted the post I just sent, so here it is again.

    Change the line

    · if (a == '\r')

    in main()

    into

    · if (a == 0)

    I noticed that CR (0x0D) is NOT placed in buf[noparse]/noparse, but is replaced by a binary 0.

    regards peter
    ·
  • WaldoDTDWaldoDTD Posts: 142
    edited 2005-12-11 20:54
    Is there a formula or equation to go from angle measure to servo position number for the PSC?? i know that 750 is the center position so... yeah -Signol01

    Post Edited (Signol) : 12/12/2005 3:33:17 AM GMT
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-12-12 11:15
    According to the manual

    http://www.parallax.com/dl/docs/prod/motors/ServoController.pdf

    servo position values 250 and 1250 correspond to 180 degrees rotation.

    Lets call those positions Pmin and Pmax

    then you can use

    P = (A/180)*(Pmax-Pmin) + Pmin· to calculate Position value for given Angle

    A = (P-Pmin)/(Pmax-Pmin)*180 to calculate Angle for given Position

    regards peter
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-12-12 14:03
    I have written a PSC class that allows PSC control using angles. The fact that

    different servos have different position ranges is hidden from the main application.

    Angle resolution is 0.1 degree but I must check the·formulaes used for overflow.

    The class goes into folder lib/stamp/peripheral/servo/psc

    regards peter
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-12-12 17:07
    I rewrote the angle/position methods to prevent overflow.

    I·make use of the method umulf() (multiply unsigned int with unsigned fraction)

    in class UnsignedIntMath.

    http://groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/math/

    regards peter



    Post Edited (Peter Verkaik) : 12/12/2005 6:19:23 PM GMT
  • WaldoDTDWaldoDTD Posts: 142
    edited 2005-12-13 00:42
    is this the correct way to use the psc class? I am confused and nothing is working
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-12-13 01:31
    Yes, but I think you need to set the positions or angles.
    Also, with 6 channels, your servos must be connected to channels 0 to 5.
    initChannel just fills some private arrays. No commands are sent to the psc.
    setAngle() and setPosition() move the servos. Below I have used the values
    you used in version IV of your program.

    ··· control.initChannel(0,250,1250,(short)52428);
    ··· control.initChannel(1,250,1250,(short)52428);
    ··· control.initChannel(2,250,1250,(short)52428);
    ··· control.initChannel(3,250,1250,(short)52428);
    ··· control.initChannel(4,250,1250,(short)52428);
    ··· control.initChannel(5,250,1250,(short)52428);
    ··· control.setPosition(0,0,1500); //move directly to home position
    ··· control.setPosition(1,0,2500);
    ··· control.setPosition(2,0,2500);
    ··· control.setPosition(3,0,1500);
    ··· control.setPosition(4,0,1500);
    ··· control.setPosition(5,0,1500);

    You use positions 1500 and 2500 which are outside the default values.
    To be able to work with angles you need to define the correct Pmin, Pmax and acf
    for each servo. If you work with positions only, you can even leave the
    control.initChannel() lines out. Also note that my class does not store 'home' values.

    Any of your update(int value) must be replaced by control.setPosition(channel,0,value)
    so one.update(510) is replaced by control.setPosition(0,0,510)

    I have done so in the attachement (using values from version IV).



    regards peter
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-12-13 01:41
    I like your idea of a home value.
    I could add a home parameter to initChannel,
    a positive value >= 0 would indicate an angle home parameter (default 900, center),
    a negative value would indicate a home position (default -750, center).
    I can then add a method home(int channel, int ramp) that moves a servo
    to its home position.
    How about that?

    regards peter
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-12-13 07:40
    I have added a home position parameter to initChannel(), and this method
    also moves the servo directly to this home position. setAngle() or setPosition() is not
    required for initializion anymore, saves code in main().

    http://groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/peripheral/servo/psc/

    regards peter
  • WaldoDTDWaldoDTD Posts: 142
    edited 2005-12-14 02:24
    Cool thanks! I have been working with IV actually and i was able to complete the project with that version. I am going to try and incorporate the psc class in V before i submit my work to the publisher.Thanks again!-Signol01
  • WaldoDTDWaldoDTD Posts: 142
    edited 2005-12-14 02:48
    ok, here is the new revision of version V.-Signol
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-12-14 03:41
    One thing, the home parameter in initChannel,

    if home < 0 then it indicates a home position (default -250 to -1250)
    if home >= 0 then home indicates a home angle (0-1800 representing 0.0-180.0 degrees)

    so you should say

    ··· for(int i=0; i<5; i++){
    ····· x = 750;
    ····· control.initChannel(i,250,1250,(short)52428,-x);
    ····· if ((i == 1) || (i == 2)){
    ······· x = 1250;
    ····· }
    ··· }

    Why are you not using the values 1500 and 2500 anymore?

    regards peter
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-12-14 03:45
    Actually, I think it should be

    ··· for(int i=0; i<5; i++){
    ····· x = 750;
    ····· if ((i == 1) || (i == 2)){
    ······· x = 1250;
    ····· }
    ····· control.initChannel(i,250,1250,(short)52428,-x);
    ··· }

    otherwise home is 750 for all servos.

    regards peter
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-12-14 03:54
    ··control.initChannel(0,250,1250,(short)52428,-750);
    ··control.initChannel(1,250,1250,(short)52428,-1250);
    ··control.initChannel(2,250,1250,(short)52428,-1250);
    ··control.initChannel(3,250,1250,(short)52428,-750);
    ··control.initChannel(4,250,1250,(short)52428,-750);
    ··control.initChannel(5,250,1250,(short)52428,-750);
    }

    and call initServos in main().
    This also allows you to reset your servos from anywhere else in your program.

    regards peter



    }
  • WaldoDTDWaldoDTD Posts: 142
    edited 2005-12-14 03:58
    Ok,
    This version is the tested code. The reason why I am not using 2500, 1400 anymore is because I was using the PSC program to get the positions when the number scale is 500 to 2500 2000 units versus the 1000 units on the serial commands. Also, I didn't realize that the home parameter was degrees until recently. Here is the working prototype of Mark V.-Signol01
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-12-14 04:05
    Looking at your commands,
    I noticed command 'k' sets servo 3 to position 1300.
    That is the only time that a position is outside the 250-1250 range,
    yet you didn't define Pmax for servo 3 to be 1300.
    Any reason why, or is this a typo?
    regards peter
    ·
  • WaldoDTDWaldoDTD Posts: 142
    edited 2005-12-14 04:13
    I think that you are looking at the wrong release, the new one is set to 650
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-12-14 04:25
    Our posts crossed.
    In your latest program the 1300 is replaced by 650.
    With all positions in range you can now use angles.

    I have done that in the attachement. If version V runs,

    so should version VI.

    regards peter
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-12-14 06:12
    Can you test something for me?

    Put the following

    ··········· int pos = control.getPosition(0);
    ··········· System.out.print("servo #0 position: ");
    ··········· System.out.println(pos);

    as the first statements inside block if (cmd) {}

    I like to know if the PSC reply works using a single I/O line.

    Please report if you get any reading in the IDE message window or

    if the javelin appears to be stopped.

    regards peter
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-12-14 22:34
    I have updated the psc class. initChannel() now also takes a ramp parameter
    that specifies how fast the servo must move to its home position.
    http://groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/peripheral/servo/psc/

    I noticed you try to move the servos to their home positions at rate 5.

    ··· for (int z=0; z<=5; z++){
    ····· control.setHome(z,5);
    ··· }//end for loop

    but initChannel() already moved the servos to their home position.
    With the new psc class you can specify the rate directly in initChannel.

    regards peter
  • WaldoDTDWaldoDTD Posts: 142
    edited 2005-12-17 14:01
    ok, I will try and test it next week, my project is up for review so i don't have access to the robot. Thanks for your help!-Signol
  • WaldoDTDWaldoDTD Posts: 142
    edited 2006-01-08 04:25
    Ok, I just remembered i need to test that thing for you, I will do so tommorrow (finals are coming up and a lot has been going on I got accepted into Rensselaer Polytechnic on xmas eve!! hop.gif ) at any rate I am working on the next phase of my project where I need a more dynamic robotic control system. I have made this prototype code to just see what needs to be included. Essentially the new protocol I want to follow is a series of numbers sent from the computer. Basically 3 numbers are sent, the servo number, followed by the angle followed by 0x0D. I am not sure if this would pick up the LF value sent as well and put it in the array so if you could look over this I would be much appreciative since the final computer program that links to it will not be ready for quite some time. Thanks!-Signol
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-01-08 09:19
    I changed your main() a little to what·I think you·try to do.
    regards peter
  • WaldoDTDWaldoDTD Posts: 142
    edited 2006-01-08 18:16
    thanks!-Signol
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-01-24 16:26
    The psc class has been updated to receive 6 bytes of reply
    when two psc boards are networked.
    http://groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/peripheral/servo/psc/

    regards peter
Sign In or Register to comment.