Roomba Python test script not working

Inside the Roomba and Scooba and more, Cool mods, Repair and Upgrades - including the all new iRobot Create Kit. Let's void that warranty baby!

Roomba Python test script not working

Postby huitlacoche » March 3rd, 2013, 3:07 pm

Hi,

I'm trying to get my roomba Discovery to work via a python script but nothing seems to make it respond.
I know that my bot has the updated firmware and I've gotten it to function over an arduino but I'd rather make things leaner and go the python route.

Here's the code:

Code: Select all
import serial

ser = serial.Serial('COM4', 57600) # open serial port 4
print( '%s is in use.' %(ser.portstr) ) # check to see if port is open

#start Roomba commands


ser.write(b'/x80') # 128: start command
ser.write(b'/x82') # 130: control command
ser.write(b'/x87') # 135: clean command


##ser.write( bytes('/x80', encoding='ascii') ) # 128: start command
##ser.write( bytes('/x82', encoding='ascii') ) # 130: control command
##ser.write( bytes('/x87', encoding='ascii') ) # 135: clean command


ser.close() # close port


I'm using Python 3.3, as well. I did some investigating to see if the syntax has changed...that's why there is two different versions of the same command.
Has anyone else run into the problem and found a way around it?
I know that my usb to serial device is working as I can get things to function in Roomba Status.

Thanks!
-- Mark
huitlacoche
 
Posts: 21
Joined: January 31st, 2013, 1:49 pm

Re: Roomba Python test script not working

Postby huitlacoche » March 3rd, 2013, 7:42 pm

So I realize now that it *is* waking up. Device detect seems to be working but I still can't send commands.
I checked to see if perhaps my usb to serial device wasn't working with an Arduino. I created a short python script with a ser.read() and it returned byte info...I'm still thinking my syntax is incorrect between python and roomba.
huitlacoche
 
Posts: 21
Joined: January 31st, 2013, 1:49 pm

Re: Roomba Python test script not working

Postby vic7767 » March 3rd, 2013, 8:50 pm

Is the power on prior to sending commands ?
Roomba and Neato Mods, come visit: http://www.vic7767.com/

http://www.Robot-Doc.com/
User avatar
vic7767
Robot Master
 
Posts: 11935
Joined: January 14th, 2006, 8:31 pm
Location: Haughton Louisiana - USA

Re: Roomba Python test script not working

Postby huitlacoche » March 3rd, 2013, 9:09 pm

No, power is off.
So a bit of an update after playing around, I modified the code a bit:

Code: Select all
import serial
import time

ser = serial.Serial('COM4', 57600)

ser.setRTS(0)
time.sleep(0.1)
ser.setRTS(1)
time.sleep(0.75)

ser.write(b"\x80") # 128: start command
ser.write(b"\x84") # 130: control command
ser.write(b"\x87") # 135: clean command

ser.close()


I had originally tried setting the baud to 19200 and using just 'ser.setRTS(0)'
To my delight, it started to vacuum...once.
I'm not sure why it woke up that one time and not again but I pasted in the rest of the wake up sequence and it started working consistently. I had to pull the battery to get it working at 57600 as well.
I didn't think I had changed the baud rate with just a simple ser.setRTS(0). I figured i had to pulse the device detect as it says in the SCI manual. In short, it seems to consistently vacuum now. I need to figure out if this is something that will work for other commands.

I'm still pretty new to this so I'm just throwing together strings of code in a fashion that I think might work...
Code: Select all
ser.setRTS(0)
time.sleep(0.1)
ser.setRTS(1)
time.sleep(0.75)


All this does is wake up the roomba, correct? I've seen it in snippets of code and I've seen others without. I apparently need this in my code to make my roomba do anything. Is there a reason other people get theirs to work without this?

Thanks!
-- Mark
huitlacoche
 
Posts: 21
Joined: January 31st, 2013, 1:49 pm

Re: Roomba Python test script not working

Postby huitlacoche » March 3rd, 2013, 9:12 pm

Oh, and another problem is the fact that i had a forward slash instead of a backslash in my byte code.
Luckily I caught that error before I ran in too many circles. :D
huitlacoche
 
Posts: 21
Joined: January 31st, 2013, 1:49 pm

Re: Roomba Python test script not working

Postby mfortuna » March 3rd, 2013, 10:49 pm

The roomba can be powered on manually before SCI commands are sent. It doesn't need to be woken up if it is powered on.
Mike
Reds x 3, Dirt Dog, Disco (now a parts bot), Create, Scooba 350, and Security Dawg
Evolution Mint
Neato XV-11
User avatar
mfortuna
Robot Master
 
Posts: 5218
Joined: February 5th, 2006, 10:35 am
Location: NH


Return to Robotic Hacking

Who is online

Users browsing this forum: mfortuna, vic7767 and 211 guests