3 Parallax servos via the PSC
PitchingOne
Posts: 24
Hello·everyone,
···· I·am new to·Parallax products.··I am currently trying to control 3 Parallax servos via the PSC.··
·····
·The first thing that I want to do is get a verification number from the PSC, of which I tried to do in·the following·code:
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 ;i++){
··········· buffer.append((char)uart.receiveByte());
········· }
······· System.out.println(buffer.toString());
···· uart.setDirection(0);· //write mode
}//end getVersion
Then, I want to get the current position of the servos 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 ;i++){··················· //Three byte response expected for version command
········ buffer.append((char)uart.receiveByte());
········· }
······· System.out.println(buffer.toString());
··· uart.setDirection(0);·························· //write mode
}
then, I set the baudrate to 38400
· public void setBaudRate(){
·//Set PSC Baud rate to 38400
··· CPU.delay(5000);············· //Wait for servo controler to boot
··· uart.sendString("!SCSBR");····· //Set baud
··· uart.sendByte(1);·············· //Set baud to 38400
··· uart.sendByte(0x0D);··········· //End Byte
··· CPU.delay(5000);············· //Wait for servo controler to get new baud
·· uart.restart(Uart.dirTransmit,CPU.pin4,Uart.dontInvert,
······ Uart.speed38400,Uart.stop1);
}
Finally, I·command them to·move:
··public void move(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
··· }
·
·The only thing that works is that the PSC flashes a green light when I send serial data to it. Please help me!!!····
Post Edited By Moderator (Joshua Donelson (Parallax)) : 10/23/2009 4:22:25 AM GMT
···· I·am new to·Parallax products.··I am currently trying to control 3 Parallax servos via the PSC.··
·····
·The first thing that I want to do is get a verification number from the PSC, of which I tried to do in·the following·code:
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 ;i++){
··········· buffer.append((char)uart.receiveByte());
········· }
······· System.out.println(buffer.toString());
···· uart.setDirection(0);· //write mode
}//end getVersion
Then, I want to get the current position of the servos 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 ;i++){··················· //Three byte response expected for version command
········ buffer.append((char)uart.receiveByte());
········· }
······· System.out.println(buffer.toString());
··· uart.setDirection(0);·························· //write mode
}
then, I set the baudrate to 38400
· public void setBaudRate(){
·//Set PSC Baud rate to 38400
··· CPU.delay(5000);············· //Wait for servo controler to boot
··· uart.sendString("!SCSBR");····· //Set baud
··· uart.sendByte(1);·············· //Set baud to 38400
··· uart.sendByte(0x0D);··········· //End Byte
··· CPU.delay(5000);············· //Wait for servo controler to get new baud
·· uart.restart(Uart.dirTransmit,CPU.pin4,Uart.dontInvert,
······ Uart.speed38400,Uart.stop1);
}
Finally, I·command them to·move:
··public void move(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
··· }
·
·The only thing that works is that the PSC flashes a green light when I send serial data to it. Please help me!!!····
Post Edited By Moderator (Joshua Donelson (Parallax)) : 10/23/2009 4:22:25 AM GMT
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com