Society of Robots - Robot Forum
Software => Software => Topic started by: SeagullOne on January 12, 2011, 07:38:39 PM
-
Anyone have any experience with the SD84 servo controller?
I'm going to use it primarily as a board for NINA's sensor array, but I'm having a bit of trouble trying to get readings from it in Python.
I have been able to find some resources out there for using python with the SD84 using the serial module, but I'm mainly having a hard time getting the SD84 to return anything.
For example, if I try to set analogue channels 1-4 and then check to see if those channels are set using the GET_AD_CNT command, I don't get anything if I try to read it...
Below is the python code I'm using:
#Test script for communicating with the SD84
#Adapted from "Time Sinkers" python interface to the SD84
import serial
sync='\xAA\xA0\x55'
SET_SERVO='\x01'
SET_MODE='\x04'
SET_AD_CNT = '\x06'
GET_VERSION='\x0A'
GET_AD_CNT = '\x07'
def Get_Analogue():
GET_ADC_CHANNELS = ('\xAA\xA0\x55\x07\00\00')
ser.write(GET_ADC_CHANNELS)
Analogue = ser.read(1)
print "Analogue Channels set ="+Analogue
# Open Serial port to FTDI usb serial tty
ser = serial.Serial('com4', baudrate=115200, bytesize=8, parity='N', stopbits=2,timeout=1)
# Send GET_VERSION command
ser.write(sync+GET_VERSION+'\x02\x00')
# Read the returned version and print
ver=ser.read(2)
print "VERSION:"+ver
# set SERVO mode
ser.write(sync+SET_MODE+'\x11\x01\x19')
#set Analogue mode
ser.write(sync+SET_AD_CNT+'\01\04')
Get_Analogue()
#Read return code (should be \x00 if all is well)
ser.read(1)
The version prints okay, just nothing else. Any pointers? Could it also be that I'm not setting the analogue channels correctly?
-
No python expert but:
#set Analogue mode
ser.write(sync+SET_AD_CNT+'\01\04')
Should probably read:
#set Analogue mode
ser.write(sync+SET_AD_CNT+'\x01\x04')
-
Hmm...still no avail. But thanks for the help hopslink.
I'm trying to talk to the SD84 in real time over the command prompt. I notice everytime I write a string through the serial port, the prompt prints "L" followed by the number of items in the string...
When I try to read from the port, no matter what the previous command was, no matter what byte, I always get the same result, " ' ' "
Still not sure how to make sure the SD84 is getting and giving the information I need... :-\
-
It is likely that the shell you are using is mangling incoming characters as it expects ascii. Try a dedicated terminal program, realterm is good on windows, not sure about linux. Set the display options to Hex or Hex + ascii, this should give you a clearer picture of what's going on.