Servos using Uart with the Parallax Servo Controller
Hi, we just started experimenting with the javelin and servos and we were able to get a servo moving using the PWM object. However, we now want to use the servo controller so that wer can free up our processor, but we aren't quite sure how to communicate with it.
We are trying to use the Uart VP but we don't know how to properly format the correct control string to send to the servo controller.
This is our program which we are trying to fix. It sends the data to the servo controller over pin 0 and the servo is on controller channel 0. We're powering the servo off 4 D-cells. The standard servos just twitch, while the continuous rotation ones move at max speed (the speed doesn't change with any coding changes). Any help would be appreciated. Thanks
***Code***
Post Edited (Jonathan H) : 7/31/2004 8:12:17 AM GMT
We are trying to use the Uart VP but we don't know how to properly format the correct control string to send to the servo controller.
This is our program which we are trying to fix. It sends the data to the servo controller over pin 0 and the servo is on controller channel 0. We're powering the servo off 4 D-cells. The standard servos just twitch, while the continuous rotation ones move at max speed (the speed doesn't change with any coding changes). Any help would be appreciated. Thanks

***Code***
import stamp.core.*;
public class pulse_Servo {
final static int SERIAL_TX_PIN = CPU.pin0;
static Uart txUart = new Uart(Uart.dirTransmit,
SERIAL_TX_PIN,
Uart.dontInvert,
Uart.speed2400,
Uart.stop1);
static StringBuffer buffer = new StringBuffer(10);
static char ch = 0x0; // servo 0
static char ra = 0xf; // ramp speed = 15
static int pulse = 500; // pulse width = 1 ms
public static void main(){
// adjust these for correct servo operation
int pause = 500; // 1/20 sec ?
int maxcw = 500; // 1 ms
int maxccw = 1000; // 2 ms
// initialize the string buffer contents
buffer.clear();
buffer.append("!SCcr"); // needs pw cr
buffer.insert(3, ch);
buffer.insert(4, ra);
// do forever
while (true) {
pulse = maxcw; // for safety
// move counterclockwise
while (pulse <= maxccw) {
buffer.append(pulse);
buffer.append("\r");
txUart.sendString(buffer.toString());
buffer.delete(5, 7);
pulse++;
CPU.delay(pause); // slow it down - 20 pps
}
// move clockwise
while (pulse >= maxcw) {
--pulse;
buffer.append(pulse);
buffer.append("\r");
txUart.sendString(buffer.toString());
buffer.delete(5, 7);
CPU.delay(pause);
} // while
} // while (true)
} // main
} // pulse_Servo
Post Edited (Jonathan H) : 7/31/2004 8:12:17 AM GMT

Comments
With a little help from tech support, I've found the code to communicate with the Parallax Servo Controller in the old Yahoo! Groups.
myUart.sendString("!SC"); myUart.sendByte(ch); myUart.sendByte(ra); myUart.sendByte(pulse); myUart.sendByte(pulse>>>8); myUart.sendByte(0x0D);"!SC" opens the communication.
ch is the channel output of the PSC.
ra is the ramp speed of the servo.
pulse is the length of the servo pulse.
and 0x0D is the closing byte.
Here is the finished code:
import stamp.core.*; public class pulse_Servo_uart { final static int SERIAL_TX_PIN = CPU.pin0; static Uart txUart = new Uart(Uart.dirTransmit, SERIAL_TX_PIN, Uart.dontInvert, Uart.speed2400, Uart.stop1); static char ch = 0x0; // servo 0 static char ra = 0xf; // ramp speed = 15 static int pulse = 768; // pulse width = 1 ms public static void main(){ // adjust these for correct servo operation int pause = 500; // 1/20 sec ? int maxcw = 700; // 1 ms int maxccw = 836; // 2 ms // do forever while (true) { // move counterclockwise while (pulse <= maxccw) { txUart.sendString("!SC"); txUart.sendByte(ch); txUart.sendByte(ra); txUart.sendByte(pulse); txUart.sendByte(pulse>>>8); txUart.sendByte(0x0D); pulse++; CPU.delay(pause); // slow it down - 20 pps } // move clockwise while (pulse >= maxcw) { --pulse; txUart.sendString("!SC"); txUart.sendByte(ch); txUart.sendByte(ra); txUart.sendByte(pulse); txUart.sendByte(pulse>>>8); txUart.sendByte(0x0D); CPU.delay(pause); } // while pulse = 700; // for safety } // while (true) } // main } // pulse_ServoI'd like to thank Tech Support.
Bye!