I was just playing around with the SSC-32. I have an SSC-32 connected to W.A.L.T.E.R. without the Atom Bot Board on COM1 (Linux /dev/ttyS0).
I first started working with it using minicom, and got it setup and working (/dev/ttyS0). I got minicom talking to the SSC-32 after I set the port to 115200 on /dev/ttyS0.
Then I decided to take a try at getting Python to talk to it, so I installed the Python Serial module and read the README file to find out what the new commands are. I got the port and am able to write to it.
Next, I wrote a small Python script to try and read back the response from the SSC-32 version command.
Now my project is to write an actual Python script to do a full conversation with the SSC-32, including sending a command and getting a response if any.
#!/usr/bin/python
# Import the Serial module
import serial;
#
# Open the port at 115200 Bps - defaults to 8N1
#
# Right now I am depending on the port time out to
# get the input, since the SSC-32 sends just a CR rather
# than a CR/LF pair to terminate a line. The readline()
# command looks for a linefeed to terminate a line.
#
ssc32 = serial.Serial('/dev/ttyS0', 115200, timeout=1);
# Send the version command
ssc32.write("ver\r");
# Read back the response
inp = ssc32.readline();
# Show what we got back
print inp;
# Close the port
ssc32.close();
The output is:
quark ~ # ./ssc32.py
SSC32X V1.03
quark ~ #
I will see if I can write a single character input routine to read from the SSC-32. Maybe I can just read characters until I see a CR and then end the read.
This is exciting! I wish I could have my Linux PC read the sensors on W.A.L.T.E.R. now.
I couldn’t sleep, so got up and decided to fiddle with the SSC-32 and Python some more. I knew it had to be possible to read a response from the SSC-32 without having to depend on a serial port time out. I have done this many times with various languages. I defined a function to read characters from the SSC-32 until a CR is encountered and then return the result.
[code]#!/usr/bin/python
Import the Serial module
import serial;
Reads single characters until a CR is read
def Response(port):
ich = “”;
inp = “”;
while (ich <> '\r'):
ich = port.read(1);
if (ich <> '\r'):
inp = inp + ich;
return inp;
Open the port at 115200 Bps - defaults to 8N1
ssc32 = serial.Serial(’/dev/ttyS0’, 115200);
Send the version command
ssc32.write(“ver\r”);
Read the response
inp = Response(ssc32);
Show what we got back
print inp;
Close the port
ssc32.close();
[/code]
Notice the Response() function I defined at the top of the program and that I have removed the “timeout=1” parameter to the port open statement. This function just reads a single character from the serial port the SSC-32 is on until it reads a CR, and then stops and returns the result.
Python uses indenting to tell what statements are part of a block, so everything between the ‘while’ and the return statement is part of the ‘while’ block. Everything indented further than the ‘if’ is part of the ‘if’ block.
This program returns immediately after the last character of the SSC-32’s response has been read - when it reads a CR. There is no delay between sending the ‘ver’ command and getting the response now.
Why can’t your linux PC read the sensors from your WALTER robot? I would assume the sensors are either analog or digital out, you could use an inexpensive phidgets interface kit. I have one running off my gentoo-slug. If it works on one of those, it’ll work on any linux box. I’m using C++ to communicate with it, but I think they’ve got a python interface in the beta phases now.
I picked the “higher end” phidgets interface with an LCD screen, 8 digital inputs, 8 analog inputs, and 8 digital outs (tinyurl.com/yxc6c5) and it was about $115. The interface kit minus the lcd is cheaper, and they have a few variants.
Might be worth looking into if you want to roll your own software with the sensors and the ssc-32 being controlled/read from the same program, which is what I’m gonna be doing (writing that software over christmas break).
I’ve used some phidgets stuff at work, seems pretty solid. Pretty happy with it, and it’s a lot cheaper for some applications than the National Instruments cards we were using at work (build flight sims for the navy for me day job).
The usenet python group had a similar situation where serial data needed to be read from a CMUcam1. The below was used to get the complete byte string sent from the cam. I can post the rest of the code if needed.
Yes, the sensors are analog and digital inputs. I have 3 analog Sharp IR Rangers, a PING Ultrasonic, and an IRPD hanging off W.A.L.T.E.R. now. Actually, since you showed off your nifty LCD/Analog/Digital Phidgit interface, I have been looking more closely at the Phidgets stuff. I would like to hang one of those LCD modules like you have on W.A.L.T.E.R. at some point.
I will certainly be checking into this further.
I like the idea of having the LCD, 8 Digital ins, and 8 Analog ins, all in a single module. The LCD would sure make it easier to debug W.A.L.T.E.R. at times and I could hang a few more IR Rangers on him too (one for each of his 8 sides + the 3 he already has).
I can see the possibility of using one or more of the Phidgets interfaces for my upcoming Walk 'N Roll project after I finish my BRAT. I am leaning strongly towards Walk 'N Roll have a Gumstix Linux computer as the master controller and one or more PIC (and maybe some Phidgets) based boards as slaves.
I’d like to get one of those Phidget LCD and I/O modules, but I need to finish up some stuff on W.A.L.T.E.R. and complete my BRAT first. I have two SSC-32’s now, one for W.A.L.T.E.R. and the other for my BRAT.
I prefer my single character input routine though, since I can modify it slightly to look for any character I choose with an additional parameter. Of coruse, this method you show would probably work for any eol character also.
Below is the code for those that might be interested in robot vision.
########################################
# This program reads a serial port hookup up to a CMUcam1.
# It tracks the middle of a green object and provides a
#confidence estimate
import serial
ser=serial.Serial('com1',baudrate=115200, bytesize=8,
parity='N', stopbits=1,xonxoff=0, timeout=1)
#Below line orders the CMUcam to track green
ser.write("TC 016 240 100 240 016 240\r\n")
for i in range(0,100,1):
reading = ser.readline(eol="\r")
components = reading.split()
mx = int(components[1])
my = int(components[2])
confidence = int(components[8])
print mx, my, confidence
ser.close
########################################
#This code will read 5-6 frames per second, which should be
#plenty for most vision processing applications.
I seriously considered a gumstix computer myself, but I figured I’d save money and just get the linksys nslu2 for $80 off of newegg. That gets you a 266 mhz xscale (after you pop off a resistor on the circuitboard, takes 2 minutes), 32 mb ram, ethernet port, and 2 USB 2.0 slots.
I added a 40 gig hard drive (usb powered), usb hub, phidgets interface kit, usb->serial converter (with ssc-32), openslug and gentoo and now I’ve got a sweet little 5 volt embedded computer system to run everything, with spare usb ports for future upgrades.
Definitely not as small or as slick as the gumstix (and not as fast as the high-end one), but maybe worth considering especially with the price and ease of putting gentoo on there. You get native gcc development, and being a gentoo box you got your python.
Just thought I’d put in a good word for the 'ole slug since I’ve had such good luck with it. I’m probably gonna pull all this stuff and rehost it in a project box at some point, until then it’ll remain strewn about my living room floor.
Hmmmm, OK, I’m thinking… This might be a nice replacement ‘brain’ for W.A.L.T.E.R… Hmmmmm… The price is sure right and sounds like it has decent features.
You found a USB -> Serial converter that works reliably! I can think of a lot of things to use those USB ports for too.
OK, OK, let me arm go now… Stop twisting! ::rolls eyes:: Ha ha! I’m going to check this out today.
Ah, that would be nice. I should contact linksys and fire 'em up for a Christmas bonus. Or maybe a new wrt-54g
I know there’s a bunch of usb->serial adapters that DON’T work, but I’m using the Belkin F5U109 USB to Serial adaptor which is supported. I found one online for $15. The thing is that even though you’re running gentoo, you’re booting the openslug kernel (which then calls init on the gentoo partition).
If you’re interested in what peripherals would be supported check out the tinyurl.com/jvm7z) to get it working, then copied the kernel modules over to my gentoo installed and added 'em to /etc/modules.autoload.d/kernel-2.6. Voila. I’ll post some pics after christmas…
You also got me thinking SLUG. I have a WRT54GS, so I know how nice embedded Linux can be. The only issue is the WRT is a tad too big to mount on my Scout. I need some webspace, but I have pics of my mod. I added a 4x20 character lcd screen, 5V regulator, and did an SD mod to add 1Gb of flash.
However, all this talk has got me thinking as to the size of the SLUG… How does it compare to the SCC-32? The thing that always got me, was to make the SLUG useful, I’d need a USB hub, at least a 1GB USB flash, at least 2 USB-to-RS-232 adaptors, and some kind of USB WiFi card. With all that equipment, the SLUG seemed to be just as big as my WRT. I.e. I couldn’t fit it on my bot.
As far as USB-to-RS-232 adaptors, I haven’t had too much trouble. I have a number of FTDI based ones. I think one of the issues might be advanced UART support in your kernel?
The Slug is significantly smaller than the wrt54g, but you’re right, it does add up once you start adding hubs and usb to serial converters. I have a very small hub, but the serial converter is rather large. That’s one of the reasons I’m thinking of rehosting all this into a project box. Anyway, here’s a few photos with a slug and an ssc-32 to give you a reference:
You’ll notice I’ve strapped a USB hard drive to the top of the slug, so it’s bigger than usual. I would have gone with a flash drive, but I really wanted a nice swap space (which would kill a flash drive quick) for compiling.
I wouldn’t be surprised if you could find a much smaller usb to serial converter than that one…