Python and SSC-32, consistent motion

Hi, I have followed the “Python/SSC-32 Example” thread to write a short test program to control my servo (HS-785HB Winch Servo) with the SSC-32 motor controller and python (Macbook Pro OS X 10.6, Python 2.6, PySerial 2.5). I am using a Dynex USB to Serial Adapter Cable, connecting the SSC-32 to my usb port and a PL2303 driver for OS X 10.6.

import serial
SSC32_Port = "/dev/tty.usbserial";
ssc32 = serial.Serial(SSC32_Port, 115200);

result = ssc32.write("# 0 P 1500 \r") # P: 500-2500, 1500 is center
print result
result = ssc32.write("# 0 P 1200 \r") # P: 500-2500, 1500 is center
print result
result = ssc32.write("# 0 P 1800\r") # P: 500-2500, 1500 is center
print result

ssc32.close();

When I type each command into the terminal individually, I am able to get the expected behavior. However, when I run the entire program, the servo does not move. The terminal executes the three print statements, and then the program crashes my computer, presumably before it has a chance to close the serial port. Does anyone know what might be happening and what I can do to get consistent motion/behavior programmatically?

Thanks in advance!

Just a quick thought. You might want to add /n (line feeds) to your commands.

Alan KM6VV

Thanks for the tip KM6VV. What is the “\n” for in this case? I’ve added it, but it doesn’t seem to change the behavior.

I’ve noticed that adding time.sleep(5) statements helps to run and execute all the commands:

import serial
import time

SSC32_Port = "/dev/tty.usbserial";
ssc32 = serial.Serial(SSC32_Port, 115200);

result = ssc32.write("# 0 P 1500 \r\n") # P: 500-2500, 1500 is center
print result
time.sleep(5)
result = ssc32.write("# 0 P 1200 \r\n") # P: 500-2500, 1500 is center
print result
time.sleep(5)
result = ssc32.write("# 0 P 2000 \r\n") # P: 500-2500, 1500 is center
print result
time.sleep(5)

ssc32.close();

Perhaps there is a more elegant way to know when the servo is done with it’s motion?

Terminals often send CRLF, and I saw that you were only sending \r in your program. I can never remember which one the SSC-32 wants, so it was just a quick shot. (Carriage Return, Line Feed).

Alan KM6VV