PDA

View Full Version : [Discussion] Python Project Sharing and help Thread



ROBOTMAN
01-10-2009, 11:58 PM
If you have a cool program in python or need help learning about python post here!
No question is to stupid to ask!
Also you can share your robot project but only if its programmed in python!:wink:

ROBOTMAN
01-17-2009, 12:42 PM
Can somebody give me a link to where to download tutorials and software for speech recognition in Python2.6.1 all I can find is 2.4 and 2.5.

lnxfergy
01-17-2009, 12:51 PM
2.6 shouldn't be much different from 2.5, which speech engine do you want to use? SAPI 5.1?

-Fergs

ROBOTMAN
01-17-2009, 01:09 PM
Yes SAPI 5.1 sounds right.

ROBOTMAN
01-17-2009, 01:10 PM
Would their be a difference in code between 2.5 and 2.6?

lnxfergy
01-17-2009, 01:30 PM
Would their be a difference in code between 2.5 and 2.6?

There really shouldn't be, there are no real new features in 2.6, just bug fixes I believe.

-Fergs

ROBOTMAN
01-17-2009, 01:31 PM
Ok thanks!:tongue:

lnxfergy
01-17-2009, 01:40 PM
Ok thanks!:tongue:

Yeah, try it out, if you get an error, post it here and we can help out...

-Fergs

Connor
01-17-2009, 02:54 PM
For speech, this is what you want.

http://code.google.com/p/pyspeech/

and

http://tinyurl.com/5ezco9 (pywin32 for python 2.5, which is the version I'm using)

Some links that talk about the speach module.
http://surguy.net/articles/speechrecognition.xml <-- Original implementation before the module
http://code.activestate.com/recipes/93025/ <--- Info on someone turning the above info into a module

I found that most of the modules are use are based on 2.5, I had some issues finding those same modules for 2.6.

Thanks, Connor

ROBOTMAN
01-18-2009, 04:11 PM
I am using python 2.6 when I install the pywin32 it gives me an error saying no python version 2.5 detected and cancels the installation.

ROBOTMAN
01-18-2009, 04:14 PM
Also I was wondering if their are any good tutorials on how to read on single digital input with the phidgets 8/8/8 using python the one that I have only reads all the sensors and I cant figure out how it dose it.

jes1510
01-18-2009, 06:38 PM
Download the one for 2.6 here:
http://sourceforge.net/project/platformdownload.php?group_id=78018

Post the code for the phidgets stuff if you want us to look at it.

Connor
01-19-2009, 12:25 AM
Also I was wondering if their are any good tutorials on how to read on single digital input with the phidgets 8/8/8 using python the one that I have only reads all the sensors and I cant figure out how it dose it.



#Phidget specific imports
from Phidgets.PhidgetException import *
from Phidgets.Events.Events import *
from Phidgets.Devices.InterfaceKit import *

#Create an interfacekit object
interfaceKit = InterfaceKit()
interfaceKit.openPhidget()

interfaceKit.setRatiometric(True) # Set for sensor type on analog needed.

print interfaceKit.getSensorValue(0) # Get value for analog port 0

print interfaceKit.getInputState(0,False) # Print output for Digital input 0

print interfaceKit.getOutputState(0,False) # Print output for Digital output 0


interfaceKit.setOutputState(0,True) # Set output for Digital output to 1


A few bits of code to get you started.

Thanks, Connor

ROBOTMAN
01-24-2009, 11:14 AM
Thanks for your help that was what I was looking for!

Also thanks for the help with python speech I works great now!

Ok this might sound a little advanced for a beginner to python but I want to give it a try I it is even possible. Right now I am working on the robot butler project (http://letsmakerobots.com/node/1904 (http://letsmakerobots.com/node/1904)) and I was wondering what if I wanted the robot to store a rough map of say my room. Then could it to figure out where it was and go from the left side to the right side without having to bump into obstacles. Also could you create a program that recorded the robots wheel movements and drew lines on a "map". This looks really tough and I doubt it is possible to do in python but somebody might know differently.:o

Adrenalynn
01-24-2009, 11:33 AM
What kind of wheel encoders are you using?

ROBOTMAN
01-24-2009, 11:36 AM
I was thinking about using a encoder that dose 1 click per rotation would that be to inaccurate?

Adrenalynn
01-24-2009, 11:38 AM
About 3000 times as inaccurate as a pretty standard hobby robotics encoder... And one aint gonna cut it. One per drive wheel, at least.

ROBOTMAN
01-24-2009, 11:41 AM
I will have one per drive wheel I am using the phidgets 8/8/8 and I heard that encoders don't work well with it.

ROBOTMAN
01-24-2009, 12:30 PM
My robot is large so I didn't see the point in expensive precise encoders.

Adrenalynn
01-24-2009, 01:09 PM
I don't know the Phidgets boards at all. They've never impressed me, so I've never given them a second glance.

That said - you'd probably want a couple quadrature encoders regardless of what else you're using. I'm using the Serializer to read these: http://www.active-robots.com/products/motorcon/quad-encoder/enc300.pdf

They're only 300 CPR which is not nearly what I'd like to have - but it works.

The larger a robot is the more precise the encoding should be. One wheel revolution with a 10" wheel is a LOT more distance than one wheel revolution with a 1" wheel. And it's never 100&#37; accurate. How'd you like to come up 20" short near that cabinet full of fine china with a big heavy robot? ;)

ROBOTMAN
01-24-2009, 01:41 PM
For now I don't need my robot to be that precise I will look into the encoders though. I want to get with in a foot or so say for greeting people at the door or something like that. As for hitting cases of china I want the robot to use its sensors all the time so if it dose get off the rout it can still avoid obstacles and still have a general idea of where it is. I want the robot to us its map to get from room to room once it reaches a room I am hoping to use roborealm and distance sensors to avoid things like china closets and reach its goal.

P.S
I also need to get some money before I can buy any encoders.

Adrenalynn
01-24-2009, 01:48 PM
What happens if you're off one degree and drive 100ft?

lnxfergy
01-24-2009, 03:09 PM
RM,

Encoders are absolutely necessary - and precision ones. See my long-winded post on mapping here: http://forums.trossenrobotics.com/showpost.php?p=24580&postcount=45

-Fergs

P.S. If I could, I'd +rep you Adrenalynn

lnxfergy
01-24-2009, 03:10 PM
What happens if you're off one degree and drive 100ft?

When did we end up back in the seventies? Even Shakey didn't drive 100ft without an update.... :veryhappy:

-Fergs

ROBOTMAN
01-24-2009, 03:49 PM
Ok I give up I'll fork up for some encoders. But for now I am using my custom 1 click encoders on robot butler prototype 2. 3 will get the encoders.

lnxfergy
01-24-2009, 04:22 PM
Ok, this is definitely just me thinking out loud... the information below is defiantly un-proven and shouldn't leave a lab yet... but...

You might be able throw all encoders out the window -- and replace it with high frame rate of sensory data and some fairly advanced statistical modeling. Unfortunately, in order to get the frames to mesh with the previous data in a highly reliable way, the statistical modeling is gonna eat up a huge amount of processing power (anyone with math background, I'm basically thinking MCMC to generate possible movements, then use an MLE to pick the one we "did")

I'm gonna be trying to use this on MechDAR to incorporate previous frames into a more global map... but with some hacks

-Fergs

ROBOTMAN
01-24-2009, 04:46 PM
Wow ok I'll stick with the encoders for now because I didn't understand one thing you said but if this works for you go ahead and post it then explain it in terms we can all understand.

lnxfergy
01-24-2009, 06:09 PM
Wow ok I'll stick with the encoders for now because I didn't understand one thing you said but if this works for you go ahead and post it then explain it in terms we can all understand.

That's pretty much the reason I suggest encoders - its the more common and proven way -- and also easier..

-Fergs

ROBOTMAN
01-24-2009, 06:12 PM
Today I was trying to get my 8/8/8 to work and I ran into the same problem I did last time I don't understand the code. Connor last time you gave me some easy sample code to work with it worked the first time but now it wont work!



#Phidget specific imports
from Phidgets.PhidgetException import *
from Phidgets.Events.Events import *
from Phidgets.Devices.InterfaceKit import *

#Create an interfacekit object
interfaceKit = InterfaceKit()
interfaceKit.openPhidget()

interfaceKit.setRatiometric(True) # Set for sensor type on analog needed.

print interfaceKit.getSensorValue(0) # Get value for analog port 0

print interfaceKit.getInputState(0,False) # Print output for Digital input 0

print interfaceKit.getOutputState(0,False) # Print output for Digital output 0


interfaceKit.setOutputState(0,True) # Set output for Digital output to 1


It says



Traceback (most recent call last):
File "C:\Users\Owner\Documents\Demo.py", line 10, in <module>
interfaceKit.setRatiometric(True) # Set for sensor type on analog needed.
File "C:\Python26\lib\Phidgets\Devices\InterfaceKit.py", line 378, in setRatiometric
raise PhidgetException(result)
PhidgetException



Also can somebody tell me the absolutely necessary parts of this code?



#Basic imports
from threading import *
from ctypes import *
import sys
#Phidget specific imports
from Phidgets.PhidgetException import *
from Phidgets.Events.Events import *
from Phidgets.Devices.InterfaceKit import *
#Create an interfacekit object
interfaceKit = InterfaceKit()
#Information Display Function
def displayDeviceInfo():
print "|------------|----------------------------------|--------------|------------|"
print "|- Attached -|- Type -|- Serial No. -|- Version -|"
print "|------------|----------------------------------|--------------|------------|"
print "|- &#37;8s -|- %30s -|- %10d -|- %8d -|" % (interfaceKit.isAttached(), interfaceKit.getDeviceType(), interfaceKit.getSerialNum(), interfaceKit.getDeviceVersion())
print "|------------|----------------------------------|--------------|------------|"
return 0
#Event Handler Callback Functions
def inferfaceKitAttached(e):
attached = e.device
print "InterfaceKit %i Attached!" % (attached.getSerialNum())
return 0
def interfaceKitDetached(e):
detached = e.device
print "InterfaceKit %i Detached!" % (detached.getSerialNum())
return 0
def interfaceKitError(e):
print "Phidget Error %i: %s" % (e.eCode, e.description)
return 0
def interfaceKitInputChanged(e):
if e.index == 7 and e.state == True:
print "true"
else:
print "false"
return 0
def interfaceKitSensorChanged(e):
print "Sensor %i: %i" % (e.index, e.value)
return 0
def interfaceKitOutputChanged(e):
print "Output %i: %s" % (e.index, e.state)
return 0
#Main Program Code
class In:
try:
interfaceKit.setOnAttachHandler(inferfaceKitAttach ed)
interfaceKit.setOnDetachHandler(interfaceKitDetach ed)
interfaceKit.setOnErrorhandler(interfaceKitError)
interfaceKit.setOnInputChangeHandler(interfaceKitI nputChanged)
interfaceKit.setOnOutputChangeHandler(interfaceKit OutputChanged)
interfaceKit.setOnSensorChangeHandler(interfaceKit SensorChanged)
except PhidgetException, e:
print "Phidget Exception %i: %s" % (e.code, e.message)
print "Exiting...."
exit(1)
print "Opening phidget object...."
try:
interfaceKit.openPhidget()
except PhidgetException, e:
print "Phidget Exception %i: %s" % (e.code, e.message)
print "Exiting...."
exit(1)
print "Waiting for attach...."
try:
interfaceKit.waitForAttach(10000)
except PhidgetException, e:
print "Phidget Exception %i: %s" % (e.code, e.message)
try:
interfaceKit.closePhidget()
except PhidgetException, e:
print "Phidget Exception %i: %s" % (e.code, e.message)
print "Exiting...."
exit(1)
print "Exiting...."
exit(1)
else:
displayDeviceInfo()
print "Press Enter to quit...."
chr = sys.stdin.read(1)
print "Closing..."
try:
interfaceKit.closePhidget()
except PhidgetException, e:
print "Phidget Exception %i: %s" % (e.code, e.message)
print "Exiting...."
exit(1)
print "Done."
exit(0)
In()



Its long and some of it looks useless all I want it to do is read some digital inputs!

jes1510
01-24-2009, 06:19 PM
If you're going to use Python for programming I really suggest you learn the basics of the language before you dive into reading other peoples code. Start with "Hello World" and work your way up. Things will make a lot more sense.

ROBOTMAN
01-24-2009, 06:39 PM
Thanks.

A lot.

Adrenalynn
01-24-2009, 06:55 PM
Thanks, Jes. I'm glad it was you who wrote it. I was tip-toeing around that statement above.

ROBOTMAN
01-24-2009, 06:58 PM
Never mind I'll figure it out myself.

DresnerRobotics
01-24-2009, 07:03 PM
Just to clarify, I don't think its so much that others are telling you to just "figure it out yourself", but a lot of your questions would be self explanatory if you had a more solid understanding of the language you're trying to use. It's near impossible to teach someone to code over a forum, and also would be incredibly time consuming. We're always willing to help, but there's also an individual's responsibility to learn some things for themselves (such as programming basics) for their own benefit as well as the sanity of those trying to help them.

ROBOTMAN
01-24-2009, 07:25 PM
You are right I have been reluctant to go threw the tutorials because a lot of it I already know like converting int's and things like that and I don't have a tone of time. Now I will go threw the tutorials and if I still don't get it I'll post what I know and you can figure it out.

Connor
01-24-2009, 07:31 PM
import time
#Phidget specific imports
from Phidgets.PhidgetException import *
from Phidgets.Events.Events import *
from Phidgets.Devices.InterfaceKit import *

interfaceKit = InterfaceKit()
interfaceKit.openPhidget()

time.sleep(.25)
interfaceKit.setRatiometric(True)
time.sleep(.25)

while True:
print int(1848/((float(interfaceKit.getSensorValue(2)))-34))
time.sleep(.25)

This is a test code I just wrote to read analog port 3 for a IR sensor. This is ALL that's needed.
However, I only have a single phidgets 8/8/8 device.

Thanks, Connor

ROBOTMAN
01-24-2009, 07:48 PM
Ok threw much frustration I used what I knew form past programing and the python tutorials and discovered what was reading the sensors and I now understand the code! Thanks for your help!

ROBOTMAN
01-25-2009, 01:32 PM
About encoders I looks like there are no encoders for the type of motor I have "BaneBots 36mm gearbox 10mm shaft" so far I looks like its been discontinued!

Adrenalynn
01-25-2009, 03:47 PM
You just need to pick up pre-printed high resolution encoder disks and mount the sensor where it can see 'em.

I've been known to just print my own on the laser printer, transfer them to card stock, and mount 'em up.

Two different styles: one with slots cut in 'em, and the other with just high resolution alternating black and white lines. At the end of the day, all it is in an IR LED and an IR photocell measuring either passthrough (slotted) or reflectance (banded) of the light as the encoder wheel turns. Dirt simple stuff.

ROBOTMAN
01-26-2009, 12:10 AM
Don't computer mouses have built in encoders? How hard would I be to customize a mouse to work like an encoder? Do you think a custom mouse encoder would have enough ticks per revolution?

lnxfergy
01-26-2009, 12:26 AM
Sorry just trying to avoid buying an encoder reader. I have one more idea this is the last one I promise What about the encoders inside of servos?

Servos use potentiometers == can't rotate a full rotation.

-Fergs

ROBOTMAN
01-26-2009, 12:36 AM
Sorry I tried to delete that post as soon as possible I already knew that. It was a stupid question.

Adrenalynn
01-26-2009, 12:44 AM
theoretically, yes, a mouse encoder would work.

ROBOTMAN
01-29-2009, 11:00 PM
I was planing on using the Phidgets 8 servo motor controller for my robot butler project but I was wondering? How hard would it be to make a custom servo controller and interface with it in python, would it cost more or less than the Phidgets 8 servo motor controller "$80 about".

DresnerRobotics
01-29-2009, 11:44 PM
First of all, why?

You've got an SSC-32 for $40 that can talk to Python (or anything that can talk to a serial port).

Adrenalynn
01-30-2009, 01:16 AM
^^^ What he said.

Alex
01-30-2009, 09:18 AM
Sure Phidgets are a bit on the pricier side of hobby electronics, BUT, the true beauty behind the Phidgets' boards is all about their abstraction layers and encapsulation. The way that Phidgets has encapsulated all of the lower level communication between servo and servo controller makes communicating with something like servos as simple and object oriented as:

ServoController s = new ServoController();
s.open();
s.servos[x].position = 50;

Try doing that with any servo controller that talks directly to the serial port:p Sure there are wrappers out there, but still.

Now, if you're not really interested in using encapsulated data and wish to get a much deeper understanding on how communication works between servo and servo controller, then Phidgets are definitely not for you.

Adrenalynn
01-30-2009, 11:17 AM
That'd doesn't look like Python to me. :tongue:



System.IO.Ports.SerialPort serialPort = new System.IO.Ports.SerialPort();
serialPort.PortName = "COM1";
serialPort.BaudRate = 38400;
serialPort.Open();
serialPort.Write("#0 P1500\r");
serialPort.Close();


That's all it takes in C# (I think that's what you were referencing) to control a servo with the SSC32. I'm not sure with something that simple how much a heavy API really buys.

jes1510
01-30-2009, 11:37 AM
Here's the python equivalent to the C# code (assuming you have pyserial) and using com1 with a 1 second timeout.

First it sends the data that Alex listed (I have no idea what it does) then it listens on the com port for one byte to be sent back just as an example of how to read the port. Note that reading the com port will block until the timeout so you should put it off into it's own thread if you need to do other things:



import serial

ser = serial.Serial(0, 38400, timeout = 1)
ser.write("#0 P1500\r")
datum = ser.read()
ser.close()

Note that I don't have a phidgets and have never worked with one. I simply translated what Alex wrote above to the Python equivalent.

Adrenalynn
01-30-2009, 01:22 PM
Actually - I think that's my C# for the SSC32. Alex' was for the Phidgets Abstraction Layer/API. What you translated centers a servo on Channel 0 with the SSC32.

jes1510
01-30-2009, 01:49 PM
Ah yes. That's what I get for not paying attention. Thanks for the correction.

Adrenalynn
01-30-2009, 02:01 PM
>> Edit: Man I need to lay off the caffeine

Aha - maybe you're just not intaking enough

ROBOTMAN
02-01-2009, 08:01 PM
How hard is it for python to communicate with a usb servo controller?

DresnerRobotics
02-01-2009, 08:09 PM
Just as hard as talking to any serial port.

Resilient
02-02-2009, 11:57 AM
The project is this:

I want to communicate with a netbook that is riding on top of my roomba via my desktop (and eventually via the interwebs).

I have a server written using the asyncore and asynchat modules that accepts and responds to Realtem so I know the server side is atleast sort of working.

I am having a hard time getting the client side to work.



from asyncore import dispatcher
from asynchat import async_chat
import socket, asyncore


class ClientDispatcherConnection(asyncore.dispatcher):
def __init__(self, host, port):
asyncore.dispatcher.__init__(self)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.connect((host, port))
self.buffer = 'Hello?'

def handle_connect(self):
pass


def handle_write(self):
self.send(self.buffer)
asyncore.poll(timeout=0)



a = ClientDispatcherConnection("127.0.0.1",5005)
a.handle_write()
I run this and it throws this error:


Traceback (most recent call last):
File "D:\Python25\RoombaProj\clienttest.py", line 29, in <module>
a.handle_write()
File "D:\Python25\RoombaProj\clienttest.py", line 24, in handle_write
sent = self.send(self.buffer)
File "D:\Python25\lib\asyncore.py", line 331, in send
result = self.socket.send(data)
error: (10057, 'Socket is not connected')What am I doing wrong here? A terminal connects fine.

Edit: It seems that it works every once in awhile, so I must not be freeing the socket after I run the program or something?

Edit: not any more... I dont know why it worked once...

jes1510
02-02-2009, 01:28 PM
Out of curiosity, why are you using the asynchat stuff and not just the raw sockets? I've had real good results just streaming via sockets over the web.

Resilient
02-02-2009, 01:46 PM
Because I am a noob when it comes networking and the tutorials I could find used async. :)

jes1510
02-02-2009, 01:56 PM
Here is a pretty good tutorial on socket programming in python:
http://www.amk.ca/python/howto/sockets/

I assume that you are already familiar with the language.

Resilient
02-02-2009, 02:01 PM
That looks perfect. Thanks! I'll work on it when I get home today.

jes1510
02-02-2009, 02:53 PM
Somewhat relevant to Python and robotics:

http://imgs.xkcd.com/comics/new_pet.png

Resilient
02-02-2009, 04:05 PM
That particular strip is actually what got me going on this project :P

Resilient
02-02-2009, 10:05 PM
Ok, I am really close.

This all works if I replace socket.gethostname() with 'localhost' in the server and replace 'trogdor-lappy' with 'localhost' in the client and do it all on one computer. I have also tried the laptops ip address.

The laptop is running Ubuntu and the client is running Win XP if that matters.

When I try the IP address, it times out, when I do 'trogdor-lappy' it throws the following error:


Traceback (most recent call last):
File "D:\Python25\RoombaProj\roogui.pyw", line 187, in forward
self.robot.drive(self.currentSpeed*50,self.current Speed*50)
File "D:\Python25\RoombaProj\roofunct.py", line 160, in drive
self.roombaWrite(byteArray)
File "D:\Python25\RoombaProj\roofunct.py", line 140, in roombaWrite
conn = MySocket()
File "D:\Python25\RoombaProj\roofunct.py", line 110, in __init__
self.s.connect((server,port))
File "<string>", line 1, in connect
socket.gaierror: (11001, 'getaddrinfo failed')
I got the following code on the server side.

import socket
import serial
import time
SERVER = socket.gethostname()
PORT = 5004
NAME = 'RooServe'
COM = 3
BAUD=19200

class Roomba:
def __init__(self,port,baud):
self.ser = serial.Serial(0, baud, timeout=1)
#This seems critical on my roomba, if yours doesnt respond try
removing ser.setRTS(0),
#others seem to work this way
self.ser.setRTS(0)
self.ser.flushOutput()

#Initalizes sets it ready for input
self.ser.write(chr(128))
time.sleep(.2)
self.ser.write(chr(128))
time.sleep(.2)
self.ser.write(chr(128))
time.sleep(.2)
self.ser.write(chr(131))
time.sleep(.2)


def roombaWrite(self,byteList):
self.ser.write(byteList)

def close(self):
self.ser.close()


class MyConnection:
def __init__(self,connection,robot):
self.robot = robot
self.c=connection
tempStr = self.c.recv(100)
self.robot.roombaWrite(tempStr)
print tempStr



class MyServer:
def __init__(self,server=socket.gethostname(),port=500 5,robot=0):
self.robot = robot
self.serversocket=socket.socket(socket.AF_INET,soc ket.SOCK_STREAM)
self.serversocket.bind((server,port))
self.serversocket.listen(5)

def handleConnect(self):
conn,addr=self.serversocket.accept()
self.c = MyConnection(conn,self.robot)
print 'Connection established on port: ', addr

print socket.gethostname()
r=Roomba(COM,BAUD)
s=MyServer(SERVER,PORT,r)

while True:
try:
s.handleConnect()
except (KeyboardInterrupt,SystemExit):
r.close()
And the relevent code on the client side:



class MySocket:
def __init__(self,server='trogdor-lappy',port=5004):
self.s=socket.socket(socket.AF_INET,socket.SOCK_ST REAM)
self.s.connect((server,port))

def send(self,sendMe):
self.s.send(sendMe)

jes1510
02-02-2009, 10:29 PM
It will always fail with the host name "trogdor-lappy" unless you have a dns server. Use the IP address instead. Can you ping the two separate machines?

For some reason I want to sing about thatched roofs and "He comes in the niiiiiiiiiiiiiiiiiight"

Resilient
02-02-2009, 11:11 PM
Huh, I though I tried that. Guess I must of miss-typed the ip or something, because it works now. Thanks! Is there a function to automatically get the IP address? socket.gethostname() just returns trogdor-lappy.

Im ok entering it in the client, but it would be nice if the server would tell me what it is and set its self up. We are on a wireless network and the IPs change depending on who logged in first.

jes1510
02-02-2009, 11:33 PM
Edited: You already are grabbing the incoming IP in the server side here:


def handleConnect(self):
conn,addr=self.serversocket.accept()
self.c = MyConnection(conn,self.robot)
print 'Connection established on port: ', addr
The addr variable should be the incoming IP address

If you are trying to find you local IP see here:
http://commandline.org.uk/python/how-to-find-out-ip-address-in-python/

Resilient
02-05-2009, 02:02 AM
Thanks for the help, i got all that pretty much working now. The last remaining piece of this project I want to tackle is to add video.

I don't know where to begin to look for where to start with this though. I would love to integrate it into my current wxPython GUI.

Has anyone done something like this before who might be able to point me in a useful direction?

Thanks

DresnerRobotics
02-05-2009, 08:04 AM
I know lnxfergy is working on bringing in a wifi IP camera into a console using PyGame and was successful as of last night, might ask him about it.

lnxfergy
02-05-2009, 09:11 AM
Thanks for the help, i got all that pretty much working now. The last remaining piece of this project I want to tackle is to add video.

I don't know where to begin to look for where to start with this though. I would love to integrate it into my current wxPython GUI.

Has anyone done something like this before who might be able to point me in a useful direction?

Thanks

I've not used wxPython, but I would assume that you have a way of loading a jpeg into a window. Getting that jpeg depends on what type of camera you have: webcam or IP cam. I've used OpenCV to load webcam images into a pygame application, if you are working under windows you could also use videoCapture. IP cams are even easier, as you can use httplib.

http://videocapture.sourceforge.net/ -- windows only approach, I used this a while back but haven't lately.
http://www.jperla.com/blog/2007/09/26/capturing-frames-from-a-webcam-on-linux/ -- OpenCV approach (will work under windows as well as linux)
http://mail.python.org/pipermail/python-list/2006-June/387258.html -- this is what I'm using in pyMech

-Fergs

ROBOTMAN
02-22-2009, 11:31 AM
Dose anybody know a good tutorial for communicating with the ssc-32 servo controller in python 2.6? I looked around but I could not find any.

Adrenalynn
02-23-2009, 12:30 AM
I doubt one exists.

You know how to write to the serial port.
You know how to format commands to the SSC32.

What else would a tutorial give you? That's 100&#37; of everything required.

ROBOTMAN
02-23-2009, 12:37 AM
I wish I knew how to format to SSC32! But I don't.:0 And what commands would I send? Servo 7, 255? Or something like that? It is to bad phidgets dose not sell a 32 servo board! Do you know a website that talks about SSC32 or the basic commands I would need to move a servo?

DresnerRobotics
02-23-2009, 01:02 AM
http://www.trossenrobotics.com/store/p/3191-SSC-32-Servo-Controller.aspx

There is a link to the user manual, read it and you shall find the answers you seek. Generally speaking, that's the first place I start when dealing with new hardware.

Adrenalynn
02-23-2009, 01:33 PM
The printed manual that comes with it is good too. Identical to it, in fact. ;)

I'm tempted to write "RTFM" - but I won't. :)

Connor
02-23-2009, 01:42 PM
Okay, I'm going to be a little nicer than Tyberius and Adrenalynn.. but, next time, try google. It's faster. :)

have a look at this.. Some really good info in it regarding python and the SSC-32

http://www.lynxmotion.net/viewtopic.php?t=1520

Thanks, Connor

ROBOTMAN
02-23-2009, 05:36 PM
Ok maby RTFM is ok to say. I suck at google so sorry.:o

DresnerRobotics
02-23-2009, 05:54 PM
Here, it's easy!

http://lmgtfy.com/?q=python+ssc-32

:D

ROBOTMAN
02-23-2009, 06:00 PM
Thats cool!:) How do you get that!

Adrenalynn
02-23-2009, 06:45 PM
Ok maby RTFM is ok to say. I suck at google so sorry.:o

Did they not include the paper manual? Then I apologize. I thought they gave that to everyone.

On the three copies that came with my controllers, there's a page titled "Command Formatting for the SSC-32" - and it's like the third page.

If you can find one of those, definitely grab it. It's pretty helpful.

ROBOTMAN
02-23-2009, 07:46 PM
Ok I'll print one. Thanks for the help! :)

lnxfergy
02-23-2009, 08:30 PM
Did they not include the paper manual? Then I apologize. I thought they gave that to everyone.

On the three copies that came with my controllers, there's a page titled "Command Formatting for the SSC-32" - and it's like the third page.

If you can find one of those, definitely grab it. It's pretty helpful.

I think Lynxmotion has stopped shipping printed manuals these days, I know they list that in their larger kits.

-Fergs

ROBOTMAN
02-23-2009, 10:31 PM
Hay I have a question about this thread. Should I delete it and start a new one? If not how many pages should I go to before I start a new one? It seems like 8 pages is kind of a lot for people to go threw.

- make that 9

Adrenalynn
02-24-2009, 12:31 AM
Ahh. Thanks for the heads-up! I must have gotten the last one with a printed manual or close to it a couple weeks ago.

Adrenalynn
02-24-2009, 12:33 AM
Hay I have a question about this thread. Should I delete it and start a new one? If not how many pages should I go to before I start a new one? It seems like 8 pages is kind of a lot for people to go threw.

- make that 9

It would be more for them to go through if it were scattered around in multiple places.

It's not kosher to start a new thread on the same topic.

ROBOTMAN
02-24-2009, 07:29 PM
Ok got it. :)

ROBOTMAN
02-26-2009, 10:57 PM
I am trying to get my python code to work with arduino but I have a problem.:genmad: I just want python to send one bite to the arduino and then read that byte back plus one. but the code freezes up on the ser.read() part. I found out why it is because of the highlighted statement in my arduino code.

int serialVal = 0;
int ledPin = 12;
void setup ()
{
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop ()
{
if (Serial.available() > 0):sad:
{
digitalWrite(ledPin, HIGH);
serialVal = Serial.read();
Serial.print(serialVal+1, BYTE);
}
}

This is good news but it also poses a problem. I need my program to weight for it to receive a byte from the python code, but since this dose not work I don't know how. Any body have any recommendations?:confused:

jes1510
02-26-2009, 11:06 PM
Does the LED come on? If it does then it is indeed receiving the data.

Edit: also note that your led will never go off after it receives the first byte

ROBOTMAN
02-26-2009, 11:08 PM
No I put that in to check; thats how I knew it was the if (Serial.available() > 0) statement.

jes1510
02-26-2009, 11:17 PM
Does the RX led on the Arduino blink? You may not be receiving data at all.

ROBOTMAN
02-26-2009, 11:20 PM
Yes the RX led blinks once the python code works just fine until it tries to read the port. I discovered this is because no value is ever sent back to it so I just sits and weights patiently for one to come.

jes1510
02-27-2009, 12:12 AM
Try this (from the arduino page):


int incomingByte = 0; // for incoming serial data

void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}

void loop() {

// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();

// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}
}

Adrenalynn
02-27-2009, 01:13 AM
Are we sure that the baudrate and framing on the PC side are correct? Just because it's getting data doesn't mean it's getting good data.

ROBOTMAN
02-27-2009, 06:57 PM
I tried the code from the arduino site it didn't work. I know my baudrate is correct but what do you mean by framing? I am pretty sure that the if statement is the problem. When I remove it the code works well.

Adrenalynn
02-27-2009, 10:31 PM
Have you tried printing the return value of Serial.available() to see if it's >0?

Framing is number of stop bits, start bits, word length, etc.

Like 9600, 8, N, 1

Don't forget that both sides (computer and PC) have to match!

ROBOTMAN
02-27-2009, 11:07 PM
Well normally serial available is 0 but from what I got from the serial monitor in arduino it dose change to a value above 1 when it receives a serial command. However my python code wont work because the arduino prints a new value before my python code can read it this is why I need it to only print a serial value when it receives one.

ROBOTMAN
02-28-2009, 12:03 AM
I am having a bad day for code! I am trying to get python speech to work using python 2.6.1 but it wont work here is my code.

import speech
import time

response = speech.input("Say something, please.")
speech.say("You said " + response)

def callback(phrase, listener):
if phrase == "goodbye":
listener.stoplistening()
speech.say(phrase)

listener = speech.listenforanything(callback)
while listener.islistening():
time.sleep(.5)

It keeps telling me that their is no module named speech.

lnxfergy
02-28-2009, 11:42 AM
Well normally serial available is 0 but from what I got from the serial monitor in arduino it dose change to a value above 1 when it receives a serial command. However my python code wont work because the arduino prints a new value before my python code can read it this is why I need it to only print a serial value when it receives one.

Have you tried your code in Python 2.5? There are quite a few packages that don't support 2.6 fully, but I know that pyserial has full support in 2.5. Just a thought, since this seems like it should work.

-Fergs

ROBOTMAN
02-28-2009, 01:28 PM
Well this is the weird part of the problem. When I type the code into the IDLE it works fine! So I think that 2.6.1 works. The problem occurs when I try to run it from a .py file. Then the problems described kick in. I think my computer is cursed never to work the first second or third time! Unfortunately I need my python code to work with phidgets so 2.5.1 is out of the question anyways. If only coding was as easy as building the robot!:) If anybody has communicated with the arduino threw python 2.6.1 please post your code.

lnxfergy
02-28-2009, 07:02 PM
Well this is the weird part of the problem. When I type the code into the IDLE it works fine! So I think that 2.6.1 works. The problem occurs when I try to run it from a .py file. Then the problems described kick in. I think my computer is cursed never to work the first second or third time! Unfortunately I need my python code to work with phidgets so 2.5.1 is out of the question anyways. If only coding was as easy as building the robot!:) If anybody has communicated with the arduino threw python 2.6.1 please post your code.

Ok, so looking back through the thread, I see your arduino code, but what is the exact python code you are running on your PC, cause it doesnt appear you ever posted it...

-Fergs

lnxfergy
02-28-2009, 07:04 PM
I am having a bad day for code! I am trying to get python speech to work using python 2.6.1 but it wont work here is my code.

import speech
import time

response = speech.input("Say something, please.")
speech.say("You said " + response)

def callback(phrase, listener):
if phrase == "goodbye":
listener.stoplistening()
speech.say(phrase)

listener = speech.listenforanything(callback)
while listener.islistening():
time.sleep(.5)

It keeps telling me that their is no module named speech.

So it says there is no module named speech, did you install pyspeech and SAPI? Are they on the path (you check what your path is by doing:
import sys
print sys.path )

-Fergs

ROBOTMAN
02-28-2009, 07:36 PM
Here is my python code.

import serial
from time import sleep
ser = serial.Serial(3, 9600)
print ser.portstr # check which port was really used
ser.write("5")
sleep(2)
print ser.read(1)
sleep(2)
print "Closing..." #print the word closing
ser.close() # close port

As for the python speech library problem. Here is what I get when I type the commands.

>>> import sys
>>> print sys.path
['C:\\Python26\\Lib\\idlelib', 'C:\\Windows\\system32\\python26.zip', 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\\Python26\\lib\\plat-win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\\site-packages', 'C:\\Python26\\lib\\site-packages\\win32', 'C:\\Python26\\lib\\site-packages\\win32\\lib', 'C:\\Python26\\lib\\site-packages\\Pythonwin']

I think this means it is not in my path. How do I put it in my path.

ROBOTMAN
03-06-2009, 11:15 AM
I can not get python speech to work with 2.6. I installed the software but it wont work it just says that it can not find a module named speech every time I tell it to import speech. How do I properly install python speech and what code should I use.

Adrenalynn
03-06-2009, 11:28 AM
People were already helping you with your "speech problem" [;)] in this thread. Let's not start yet another thread for the same problem, let's use the one we already have so we don't start spreading the same problem all over the place.

Thanks!

ROBOTMAN
03-06-2009, 11:34 AM
Ok sorry my computer is just weird about speech no mater what I do it dose not work! I think I am cursed. Dose anybody have any suggestions. I am using vista with python 2.6 and so far it looks like the python speech installer never creates a speech class. I know I need to use pywin32 to make something into a python class but what?

ROBOTMAN
03-06-2009, 12:00 PM
I have a new question how hard is it to make dialog boxes with things like buttons and sliders in python? Please still answer my first one though.

Adrenalynn
03-06-2009, 12:37 PM
I have a new question how hard is it to make dialog boxes with things like buttons and sliders in python? Please still answer my first one though.

http://lmgtfy.com/?q=python+gui

lnxfergy
03-06-2009, 03:24 PM
I have a new question how hard is it to make dialog boxes with things like buttons and sliders in python? Please still answer my first one though.

Tkinter is included in a default installation of python. It's pretty easy to use, but not terribly powerful (compared to any of pyGTK, pyQT, wxPython, or pygame).

Here is a great manual for Tkinter: An Introduction to Tkinter (http://www.pythonware.com/media/data/an-introduction-to-tkinter.pdf)

-Fergs

ROBOTMAN
03-11-2009, 10:30 PM
My python speech is still down!:( I just can't figure out what is wrong with it well actually I can. From what I have seen the problem is speech has not properly installed itself because it is not in my path. This brings up the problem how to install it properly! I can't believe nobody has used pyspeech with python 2.6 before! I know my program is failing a the import speech stage because when I say import speech I get a nasty error. I think that maybe the code I need is different for 2.6 specifically the import statement but I can't figure out what the new one is! If anyone has experience with this please post your code.:(

Connor
03-11-2009, 11:03 PM
My python speech is still down!:( I just can't figure out what is wrong with it well actually I can. From what I have seen the problem is speech has not properly installed itself because it is not in my path. This brings up the problem how to install it properly! I can't believe nobody has used pyspeech with python 2.6 before! I know my program is failing a the import speech stage because when I say import speech I get a nasty error. I think that maybe the code I need is different for 2.6 specifically the import statement but I can't figure out what the new one is! If anyone has experience with this please post your code.:(

Dude, told you once, tell you again.. Switch to v2.5 of python. 2.6 will just give you headaches. I've personally tried 2.4, 2.5, 2.6 and 3.0 and found that 2.5 was the best and most supported for what I was trying to do (and in your case, what your trying to do as well.) I have 2.5 working with TTS and speech Recognition without much problem following directions I found via Google. In fact, I had all that working within one night!

Thanks, Connor

ROBOTMAN
03-11-2009, 11:42 PM
I don't think I can switch! Is phidgets api compatible with 2.5? For what I have seen it is not. If it isn't then I cant switch. If it is I'll switch right away!

Connor
03-12-2009, 12:33 AM
I don't think I can switch! Is phidgets api compatible with 2.5? For what I have seen it is not. If it isn't then I cant switch. If it is I'll switch right away!

You sure can, because, I'm using Phidgets as well.. and using their API along with python 2.5

Thanks, Connor

ROBOTMAN
03-12-2009, 11:36 PM
Ok now I now have installed phidgets and python 2.5.4. I hit a problem though the examples won't compile because of this line of code "interfaceKit = InterfaceKit()" it gives me this error.

Traceback (most recent call last):
File "C:\Python25\InterfaceKit-simple.py", line 22, in <module>
interfaceKit = InterfaceKit()
File "C:\Python25\lib\Phidgets\Devices\InterfaceKit.py", line 30, in __init__
Phidget.__init__(self)
File "C:\Python25\lib\Phidgets\Phidget.py", line 59, in __init__
self.dll = windll.LoadLibrary("C:\WINDOWS\system32\phidget21.dll")
File "C:\Python25\lib\ctypes\__init__.py", line 431, in LoadLibrary
return self._dlltype(name)
File "C:\Python25\lib\ctypes\__init__.py", line 348, in __init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found

Any suggestions? This code worked with 2.6.1.

Connor
03-12-2009, 11:51 PM
Ok now I now have installed phidgets and python 2.5.4. I hit a problem though the examples won't compile because of this line of code "interfaceKit = InterfaceKit()" it gives me this error.

Traceback (most recent call last):
File "C:\Python25\InterfaceKit-simple.py", line 22, in <module>
interfaceKit = InterfaceKit()
File "C:\Python25\lib\Phidgets\Devices\InterfaceKit.py", line 30, in __init__
Phidget.__init__(self)
File "C:\Python25\lib\Phidgets\Phidget.py", line 59, in __init__
self.dll = windll.LoadLibrary("C:\WINDOWS\system32\phidget21.dll")
File "C:\Python25\lib\ctypes\__init__.py", line 431, in LoadLibrary
return self._dlltype(name)
File "C:\Python25\lib\ctypes\__init__.py", line 348, in __init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found

Any suggestions? This code worked with 2.6.1.

Make sure this file exists.
C:\WINDOWS\system32\phidget21. dll
and this one..
C:\Python25\lib\Phidgets\Devices\InterfaceKit.py

Did you un-install the 2.6 version of the Phidgets API before installing the 2.5 version?

ROBOTMAN
03-13-2009, 12:02 AM
Ok I feel really stupid! I didn't install the basic phidgets libraries!:) That might just have been the problem.:) Sorry.

ROBOTMAN
03-14-2009, 12:33 AM
I got everything working under 2.5 thanks for the advice. Speech took a wile because I didn't know how eggs worked but my speech program now runs awesome! Thanks for your patience and help.:)

ROBOTMAN
03-14-2009, 12:42 AM
Do you have any example code for a roborealm python face or object recognition program. I can't find one on line.

Connor
03-14-2009, 12:28 PM
Do you have any example code for a roborealm python face or object recognition program. I can't find one on line.

RoboRealm doesn't do face or recognition yet.. You can do some basic shap matching, or image matching.. STeve @ Roborealm is working on those things, I just don't know how long it'll be.

THanks, Connor

ROBOTMAN
03-14-2009, 12:47 PM
Oops sorry I meant image matching! It works with faces and it can identify people verses a chair and so on. Do you have any code for this?

ROBOTMAN
05-10-2009, 01:02 PM
I still have my problem when communicating with the arduino from python! It's hard to explain why it's not working but I'll give as many details as possible and maybe you can help me fix it. First of I am using the default arduino software and python 2.5.1. This is my code:

ARDUINO:


int in = 0;

void setup()
{
Serial.begin(9600);
}

void loop()
{
if (Serial.available() > 0)
{
in = Serial.read();
Serial.println(in);
}
}PYTHON:


import serial
from time import sleep
ser = serial.Serial(3, 9600)
print ser.portstr
ser.write("2")
line = ser.readline()
print line
sleep(5)
ser.close
When I send a 2 with the arduino serial monitor I get this:


50"NOTE: I'm using ASCII so a 2 = 50"

But when I try my python code it says this:


COM4Then it stops!

I know the problem is this line of code:

ARDUINO:


if (Serial.available() > 0)For some reason the serial data the python code sends is NOT grater than zero. Why that happens is a mystery. I still don't know how to find out what python sends or if the arduino sees it at all. If anyone can help me figure out how to get python to send a basic integer that the arduino will recognize and process then post.

Another mystery is that this same code works in the IDEL! It wont work in a .py file but it works in the IDEL! This is all the more confusing. I have a basic theory that when I send serial data in the IDEL it is formated where as when data is sent from the .py file it is raw and there for in a format I dont recognize and there for can't set my arduino up to recognize.

If anyone can help please try! :(

Adrenalynn
05-10-2009, 01:47 PM
COM4 would be something sent by the PC, nothing to do with the Arduino at all. The Arduino has no concept of PC COMmunications ports.

So focus on what you're doing on the PC side. Better yet, build a serial loopback plug, use a decent terminal program like RealTerm, and watch what you're sending.

Adrenalynn
05-10-2009, 02:11 PM
I can envision several problems off the top of my head. The foremost being that we've already seen that the Arduino is expecting ASCII-armored values on the wire, but you're sending it unencoded characters. So in Python, something like: ser.write(chr(50)) would make more sense, right?

You're greedily not waiting for the buffer to fill with more than one character. If you're only sending one character and then you're done, that's ok, otherwise you're going to fall off the end of the buffer.

You're just guessing as to what's actually happening. You need to sniff that serial connection.

Personally, I'd send a start-byte, then the command byte at the very least, so I know the data I'm getting is actionable and not garbage...

Like:
#!/usr/bin/env python

import serial
comport = '3' // Not sure how Python specs comports under Windows. Under linux, that'd be /dev/ttys*

ser = serial.Serial(comport, 9600, timeout=1)
ser.write(chr(255))
ser.write(chr(50))
ser.close


On the Arduino:

void setup()
{
// open serial port
Serial.begin(9600);
}

void loop()
{
// wait for serial input (a minimum of 2 bytes in buffer)
if (Serial.available() > 1)
{
//read the first byte
startByte = Serial.read();
// Let's check if it's really the expected startbyte of (255)
if (startByte == 255)
{
// then get the next byte
inByte = Serial.read();
}

//// Now we can do something with inByte

ROBOTMAN
05-10-2009, 02:44 PM
OK that's the first actual code anyones given me so I'll try it when I get home.

jes1510
05-10-2009, 05:36 PM
Adrenalynn has the right of it so I'll offer a bit of advice about code debugging. Using prints is a great way to figure out what's going on but be sure to print things out in a meaningful way so that
you know what is being printed. Labeling the data coming out will help.

Instead of this:


data = ser.readline()
print data
Do this:


data = ser.readline()
print "Incoming data = " + data

Also keep in mind that this:


if (serial.available > 0) {
Does not mean if what ever is in the buffer is greater than zero. It means if there is something in the buffer period. If you do this:


if (Serial.available > 1) {
You are saying that if there is more than one BYTE in the serial buffer then do something.


Also I assume that you know that the Python starts counting the serial ports at 0 on a Windows machine. Therefore if you want to use com3 then you declare it like so:



ser = serial.Serial(2, 9600)





I still have my problem when communicating with the arduino from python! It's hard to explain why it's not working but I'll give as many details as possible and maybe you can help me fix it. First of I am using the default arduino software and python 2.5.1. This is my code:

ARDUINO:


int in = 0;

void setup()
{
Serial.begin(9600);
}

void loop()
{
if (Serial.available() > 0)
{
in = Serial.read();
Serial.println(in);
}
}PYTHON:


import serial
from time import sleep
ser = serial.Serial(3, 9600)
print ser.portstr
ser.write("2")
line = ser.readline()
print line
sleep(5)
ser.close
When I send a 2 with the arduino serial monitor I get this:


50"NOTE: I'm using ASCII so a 2 = 50"

But when I try my python code it says this:


COM4Then it stops!

I know the problem is this line of code:

ARDUINO:


if (Serial.available() > 0)For some reason the serial data the python code sends is NOT grater than zero. Why that happens is a mystery. I still don't know how to find out what python sends or if the arduino sees it at all. If anyone can help me figure out how to get python to send a basic integer that the arduino will recognize and process then post.

Another mystery is that this same code works in the IDEL! It wont work in a .py file but it works in the IDEL! This is all the more confusing. I have a basic theory that when I send serial data in the IDEL it is formated where as when data is sent from the .py file it is raw and there for in a format I dont recognize and there for can't set my arduino up to recognize.

If anyone can help please try! :(

ROBOTMAN
05-10-2009, 07:52 PM
Ok it works better but it still dosn't work! It gets past the if (Serial.available() > 0)
Part.

But when I try to get the arduino's response it comes up blank here is my edited code.

from time import sleep
import serial
ser = serial.Serial(3, 9600, timeout=1)
ser.write(chr(7))
inByte = ser.readline()
print "Data = " + inByte
sleep(5)
ser.close



int startByte = 0;
int inByte = 0;

void setup()
{
// open serial port
Serial.begin(9600);
}

void loop()
{
if (Serial.available() > 0)
{
startByte = Serial.read();
Serial.println(startByte);
}
}

Here is the arduino serial monitor output when I type the number seven.

55

Here is the python.

IDLE 1.2.4
>>> ================================ RESTART ================================
>>>
Data =
>>>

Can anyone help?

lnxfergy
05-10-2009, 08:08 PM
Can we back up a bit and just check, what port are you connecting to? Are you sure its COM4?

-Fergs

ROBOTMAN
05-10-2009, 09:16 PM
OK I'm not 100&#37; sure. I'll just give you the facts that make me think its COM4 and then you can decide if I'm right. First off in the arduino editor my selected com port is COM4. Second off in device manager COM4 is a "USB serial port" that seem to indicate my arduino.

ROBOTMAN
05-10-2009, 09:26 PM
I would seem that the serial communication problem has to do with format. Here is what I know about the numbers going in and out from the arduino.

1. The arduino serial monitor gathers char data and converts it to ascii data. " I know this from repeated tests imputing 7 and getting 55 back.
2. The python code currently sends a char value weather this is converted is still a mystery.
3. What conversion the arduino receives is also a mystery.

It would seem if I could solve the mystery of what the python code sends and what the arduino receives I could determine why my python code doesn't print a number.

Knowing this it seems would fix all my serial problems and I would be out of your hair! :)

Adrenalynn
05-10-2009, 10:05 PM
So build a serial loopback.

ROBOTMAN
05-10-2009, 10:07 PM
Ya OK I'll google it and see what I find. Will it force me to right a lot more code?

jes1510
05-10-2009, 10:16 PM
No. A loopback is a little dongle with the Tx and Rx lines shorted together. Send a byte out your serial port and then read the serial port. Use it to verify what you are actually sending and receiving.

ROBOTMAN
05-10-2009, 10:19 PM
Sorry but hows this going to help? There is not much sample code.

jes1510
05-10-2009, 10:22 PM
I'm also pretty sure that you should be casting startByte and inByte as a char() instead of an int



char startByte = 0;
char inByte = 0;

void setup()
{
// open serial port
Serial.begin(9600);
}

void loop()
{
if (Serial.available() > 0)
{
startByte = Serial.read();
Serial.println(startByte);
}
}

ROBOTMAN
05-10-2009, 10:26 PM
OK I get it here is my code. "I pulled this off google"

import serial.serialwin32
import time
oComms1 = serial.serialwin32.Serial(3, baudrate=9600, bytesize=8,
parity='N', stopbits=1, timeout=100,
rtscts=0, writeTimeout=None, dsrdtr=None)
oComms2 = serial.serialwin32.Serial(, baudrate=9600, bytesize=8,
parity='N', stopbits=1, timeout=100,
rtscts=0, writeTimeout=None, dsrdtr=None)
oComms1.write( 'Hello Peter')
nStart = time.time()
while time.time() - nStart < 5:
nRx = oComms2.inWaiting()
if nRx > 0:
print oComms2.read( nRx)


But their is two serial ports. Can I delete one. The second serial port is not real.

lnxfergy
05-10-2009, 10:26 PM
Ok... lets recap:

1) when using the Arduino terminal, you get a return value (forget what that value is, but you at least get something...). Right?
2) when using the python code, you get nothing returned. Right?
3) we have determined that COM4 is the right port.

Sounds like you Arduino code is working, but Python isn't opening the port.

A) Does your Arduino have LEDs on RX/TX? Try sending like 500-5000 characters out the port, using your python code, and see if the LEDs do anything (you probably won't see the fast flash of a single byte, hence sending lots of data)
B) Sounds silly, but is the Arduino terminal closed? Pyserial typically won't throw an error if it is trying to open a port that is already open (but data transmission is totally frigged up). If your Arduino terminal is still open, python can't open the port.

-Fergs

jes1510
05-10-2009, 10:37 PM
Whoa there Nelly. Your jumping the gun. Is the original code you posted working now? If not then can you verify that you have the arduino IDE closed when you are trying to read the port with python?


OK I get it here is my code. "I pulled this off google"

import serial.serialwin32
import time
oComms1 = serial.serialwin32.Serial(3, baudrate=9600, bytesize=8,
parity='N', stopbits=1, timeout=100,
rtscts=0, writeTimeout=None, dsrdtr=None)
oComms2 = serial.serialwin32.Serial(, baudrate=9600, bytesize=8,
parity='N', stopbits=1, timeout=100,
rtscts=0, writeTimeout=None, dsrdtr=None)
oComms1.write( 'Hello Peter')
nStart = time.time()
while time.time() - nStart < 5:
nRx = oComms2.inWaiting()
if nRx > 0:
print oComms2.read( nRx)


But their is two serial ports. Can I delete one. The second serial port is not real.

lnxfergy
05-10-2009, 10:45 PM
Try this.


import serial
ser = serial.Serial(3, 9600)
ser.timeout = 5
print ser.portstr
ser.write("2")
line = ser.readline()
for x in line:
print ord(x)
ser.close


oy... can't make it do indents... print ord(x) should be indented...

Adrenalynn
05-10-2009, 11:38 PM
A loopback has nothing to do with code. It's hardware. As Jes noted. Pins two and three crossed back. Any data going out the serial port comes back in the same serial port.

ROBOTMAN
05-10-2009, 11:47 PM
OK everybody slow down! I tried sending something like this ser.write("457987439857239048753294857934879") but with a lot more numbers. And it worked! The data the arduino printed was something like this Data = -90-09-434-232 but way longer. The numbers I just wrote are not the real numbers. You get the idea. Also I changed the arduino code from int to char. It didn't work at first but then with the huge amount of numbers it worked! Whats this mean?

lnxfergy
05-11-2009, 12:13 AM
OK everybody slow down! I tried sending something like this ser.write("457987439857239048753294857934879") but with a lot more numbers. And it worked! The data the arduino printed was something like this Data = -90-09-434-232 but way longer. The numbers I just wrote are not the real numbers. You get the idea. Also I changed the arduino code from int to char. It didn't work at first but then with the huge amount of numbers it worked! Whats this mean?

Which python/arduino code were you running? There are like 20 versions in here now....

-Fergs

ROBOTMAN
05-11-2009, 07:24 PM
OK here is the exact code I used when it worked.

from time import sleep
import serial
ser = serial.Serial(3, 9600, timeout=1)
ser.write("7090809798768768765875764578648764646537
3746549875092487590287592874590
8327459023875908372450982734598234758973450982734
5098732459872340985720493875098
2347509823740958723408957234987509843275092387459
08237450987249058723490857293847598
23475098273459872498572938475902347598234759273459 82347586")
inByte = ser.readline()
print "Data = " + inByte
sleep(5)
ser.close


char startByte = 0;
char inByte = 0;

void setup()
{
Serial.begin(9600);
}

void loop()
{
if (Serial.available() > 0)
{
startByte = Serial.read();
Serial.print(startByte + '\n');
}
}


Here is the exact output.

Data = -76-44-52-60-100-92-84-116-44-52-76-60-100-116-84-
44-92-52-60-76-116-44-52-100-92-84-60-76-116-
44-52-100-92-60-84-116-44-76-52-60-100-92-84-116-52-44-
76-60-100-92-84-44-52-60-76-116-44-52-84-92-
100-60-76-116-44-100-92-52-60-84-76-44-116-52-100-92-60-
84-76-116-44-52-60-100-84-44-116-76-52-60-100-
92-84-44-116-52-76-60-100-44-92-52-84-60-76-44-52-100-
92-84-60-76-116-44-52-100-60-92-84-76-44-52-60-100-
84-44-52-76-60-100-44-92-52-84-60-76-44-116-100-92-84-60-
76-44-52-100-92-84-60-76-44-100-60-92-84-76-44-52-
100-92-84-60-76-52-688

ROBOTMAN
05-11-2009, 10:25 PM
OK here is an update to my code. This code works every time continuously. I just don't know how to trim it down or why it works this way.



ARDUINO:

char startByte = 0;
char inByte = 0;
void setup()
{
Serial.begin(9600);
}

void loop()
{
if (Serial.available() > 0)
{
startByte = Serial.read();
Serial.print(startByte + '\n');
}
}




PYTHON:

from time import sleep
import serial
ser = serial.Serial(3, 9600, timeout=1)
ser.write("709080979876876876587576457864876464653 73746549875092487590287592874590832745902387590837 2450982734598234758973450982734509873")
inByte = ser.readline()
print "Data = " + inByte
ser.close


This prints this every time when running from a .py file witch is what I want it to run from.



Data = 8


Why that long string of numbers equals eight confuses me.

Any help will get major + rep.

jes1510
05-11-2009, 10:34 PM
Change the super long number to "2" and post the output.



from time import sleep
import serial
ser = serial.Serial(3, 9600, timeout=1)
ser.write("2")
inByte = ser.readline()
print "Data = " + inByte
ser.close

ROBOTMAN
05-11-2009, 10:36 PM
Nothing much just another blank "Data = " line. This is annoying me!

jes1510
05-11-2009, 10:39 PM
Now lets try this:


from time import sleep
import serial
ser = serial.Serial(3, 9600, timeout=1)
ser.write("2")
inByte = chr(ser.readline())
print "Data = " + inByte
ser.close

ROBOTMAN
05-11-2009, 10:41 PM
Also just to review the tx/rx lines do flash when I send data. Another interesting fact is that as far is I can tell and don't think this is 100&#37; accurate. The numbers I send don't mater! Like I said though don't focus on this because I haven't worked on it much yet.

ROBOTMAN
05-11-2009, 10:43 PM
That code just gives a blank "Data = " line.

ROBOTMAN
05-11-2009, 10:45 PM
Wow sorry there posts confusing me. OK I tried the new code and got this error message.

Traceback (most recent call last):
File "C:\Users\Owner\Documents\Python\Serial.py", line 5, in <module>
inByte = chr(ser.readline())
TypeError: an integer is required

jes1510
05-11-2009, 10:46 PM
Ok one more thing to try:



from time import sleep
import serial
ser = serial.Serial(3, 9600, timeout=1)
ser.write("a")
inByte = ser.readline()
if not inByte :
print "inByte timed out"

print "Data = " + inByte
ser.close

ROBOTMAN
05-11-2009, 10:54 PM
inByte timed out
Data =

hope that was not your last idea!

lnxfergy
05-11-2009, 10:55 PM
Data = 8
Why that long string of numbers equals eight confuses me.

Any help will get major + rep.

Why you only get 8, is because your arduino code reads 1 byte, then prints that byte + a newline. Readline only reads one line. If you loop doing ser.readline() repeatedly, you'll get more values.

-Fergs

ROBOTMAN
05-11-2009, 10:56 PM
Oh data timed out I kind of get it but explain what it means.

ROBOTMAN
05-11-2009, 10:56 PM
Awsome I'll try some new code.

jes1510
05-11-2009, 10:59 PM
Are you sure the baud rates are the same? Something funky is going on here. According your results from the last two tests the python script is not receiving anything at all. Your python script is set for 9600, 8, N, 1. Verify that BOTH of the led's on the Arduino flash.

lnxfergy
05-11-2009, 11:03 PM
Ok.. this works here, on an Arduino I have lying around.


int val = 0;

void setup(){
Serial.begin(9600);
}

void loop(){
if (Serial.available() > 0){
val = Serial.read();
Serial.println(val,BYTE);
}
}
import serial
s = serial.Serial("/dev/ttyUSB0",9600,timeout=1)
s.write("123456789")
inbyte = s.readline()
while inbyte != '':
print inbyte,
inbyte = s.readline()This will print:
1
2
3
4
5
6
7
8
9

EDIT: also... make sure you are actually closing and reopening the ports! Every time you download code to the Arduino it opens the serial port, if your python code is then running while that goes on, stuff gets all screwed up.

-Fergs

jes1510
05-11-2009, 11:10 PM
Fergs makes a good point. Make ABSOLUTELY sure that you don't have the serial port open somewhere else. Make sure that the Arduino IDE is closed.

ROBOTMAN
05-11-2009, 11:36 PM
All right it works! I'll post my code for anyone who has the same problem.

PYTHON CODE:



from time import sleep
import serial
ser = serial.Serial(3, 9600, timeout=1)
i = 0
while i <= 5:
ser.write("7")
inByte = ser.readline()
i = i + 1
print "Data = " + inByte
ser.close


The "while i <= 5:" is put in because when sending a single number the number is printed on line 5 don't ask why I still need help getting it to print on line 1.

This waits till line 5 to run.

Here is my final arduino code.

ARDUINO CODE:



char startByte = 0;
char inByte = 0;
void setup()
{
Serial.begin(9600);
}

void loop()
{
if (Serial.available() > 0)
{
startByte = Serial.read();
if (startByte == 55)
{
Serial.print(startByte);
}
}
}


As I have said if anyone knows how to get the first line python reads to be the line the number is on tell me! Right now the python code takes a lot of time printing the number value. In a robot program that needs to poll encoder values every few seconds this just wont work! Thanks everybody for the help. I'll try the new code you gave me and see if this helps. :D

ROBOTMAN
05-11-2009, 11:44 PM
The new code dose not work! It just dose not print anything!

ROBOTMAN
05-11-2009, 11:47 PM
This is what works for python.

import serial
s = serial.Serial(3,9600,timeout=1)
inbyte = s.readline()
while True:
s.write("123456789")
inbyte = s.readline()
print "Data = " + inbyte,
s.close


And the first six lines are strange characters.

Sorry about lack of indentation tabs wont work!

jes1510
05-12-2009, 11:02 AM
Wait, does it work or not?

ROBOTMAN
05-12-2009, 07:15 PM
Yes this code works.

import serial
s = serial.Serial(3,9600,timeout=1)
inbyte = s.readline()
while True:
s.write("123456789")
inbyte = s.readline()
print "Data = " + inbyte,
s.close


not this

import serial
s = serial.Serial("/dev/ttyUSB0",9600,timeout=1)
s.write("123456789")
inbyte = s.readline()
while inbyte != '':
print inbyte,
inbyte = s.readline()

lnxfergy
05-12-2009, 07:53 PM
Yes this code works.

import serial
s = serial.Serial(3,9600,timeout=1)
inbyte = s.readline()
while True:
s.write("123456789")
inbyte = s.readline()
print "Data = " + inbyte,
s.close


not this

import serial
s = serial.Serial("/dev/ttyUSB0",9600,timeout=1)
s.write("123456789")
inbyte = s.readline()
while inbyte != '':
print inbyte,
inbyte = s.readline()

Please tell me you changed the "/dev/ttyUSB0" to your port name/number....

-Fergs

ROBOTMAN
05-12-2009, 07:55 PM
Oh ya I did I was just being lazy and copying in from this page.

Adrenalynn
05-12-2009, 11:24 PM
:) That's what you get for posting Linux code... :tongue:

@Robotman: What do you see with the loopback plug?

ROBOTMAN
05-12-2009, 11:37 PM
Not sure never tried it. To busy working on the code that kind of worked. I posted some code I got off of google. I don't have time to research it now but I didn't know what to do about the second serial port it had. Check it out I think its on page 15.

Adrenalynn
05-13-2009, 01:48 AM
I think I mentioned back then: a loopback has nothing to do with code. At all. period. fine'. A loopback plug will work best if you don't put any code on it. The weight of the printouts might break the wires.

And as I pointed out back then: without a loopback or an xray you're only guessing at what's actually happening.

ROBOTMAN
05-30-2009, 04:49 PM
OK I got it working! Here is my code and now I know what I am getting. This code gets a basic dits per tick from the encoder and prints it to a serial port. Next my python code reads this data and prints it out exactly as it is received! It works quite consistently. There are a few bugs and the dit per tick rate isn't always perfect but it dose give a fairly accurate speed reading.

Arduino:


int port = 4;
int spead = 0;
long val = 0;
int time = 0;

void setup()
{
Serial.begin(9600);
}

void loop()
{
while (time <=16)
{
spead = analogRead(port);
if (spead <= 60)
{
while (spead <= 60)
{
val++;
spead = analogRead(port);
}
if (val > 80)
{
Serial.println(val);
val = 0;
}
val = 0;
}
}
}

Python:


from time import sleep
import serial
ser = serial.Serial(3, 9600, timeout=1)
i = 0
while i <= 5:
inByte = ser.readline()
print "Data = " + inByte
sleep(5)
i = i + 1
ser.close


Output In Python NOT in Arduino:


>>>
Data =
Data = 1122


Data = 1573


Data = 1555


Data = 1488


Data = 1586


>>>


As you can see all the readings but the two warm up readings are accurate speed readings.
Now for another one of my annoying problems!:eek::(

So now lets say I want to have my robot run at the fast speed of 400 dits per tick. I need to take my current dits per tick "1500" for arguments sake and figure out the difference between it and 400.

1500 - 400

right?

That will roughly tell me how much to speed up right?

However the data I gather over the serial port is a string.

I need to convert it to an int to do math with it. In my code I use the value inByte so lets use that.


i = inByte - 400

Wont work

How do I convert inByte from a string to and int?:confused:

lnxfergy
05-30-2009, 07:07 PM
int(inByte) or possibly int(inByte.rstrip()) (to remove the \n characters)

-Fergs

ROBOTMAN
05-30-2009, 07:15 PM
Both give this error.


Traceback (most recent call last):
File "C:\Users\Owner\Documents\Python\Serial.py", line 10, in <module>
i = int(inByte.rstrip()) - 400
ValueError: invalid literal for int() with base 10: ''


Traceback (most recent call last):
File "C:\Users\Owner\Documents\Python\Serial.py", line 10, in <module>
i = int(inByte) - 400
ValueError: invalid literal for int() with base 10: ''

lnxfergy
05-30-2009, 08:21 PM
Clearly, that means you have a blank line.... int() only works on strings like "1", "312", "-1500", it can't handle things like "5\n", or, in your case "" (a blank string). In other words, nothing was found on the serial port... I suggest trying something like

inByte = inByte.rstrip() # this will remove whitespace (spaces and new lines) from the right side of string
if inByte != "":
# do whatever with int(inByte)

Seriously though, rushing off to post to a forum every time you have an error is going to majorly crimp your development... Try reading the error, and maybe googling around to see how to a particular feature.

ROBOTMAN
05-30-2009, 08:26 PM
Actually I had googled it and found the code you gave me. Your right about the blank line part though! Ill fix it and try again.

ROBOTMAN
05-31-2009, 05:30 PM
The new code gives this error.

Traceback (most recent call last):
File "C:\Users\Owner\Documents\Python\Serial.py", line 14, in <module>
print "Speed increas required = " + i
TypeError: cannot concatenate 'str' and 'int' objects

lnxfergy
05-31-2009, 05:47 PM
The new code gives this error.

Traceback (most recent call last):
File "C:\Users\Owner\Documents\Python\Serial.py", line 14, in <module>
print "Speed increas required = " + i
TypeError: cannot concatenate 'str' and 'int' objects

print "this is a string" + str(i)

Pretty basic stuff.. typs and conversions between types... I seriously suggest reading up on a Python tutorial.

-Fergs

ROBOTMAN
05-31-2009, 05:52 PM
Oh wow I read my error message totally wrong! I though it said that this part of the code was the problem.

i = int(inByte) - 400

Sorry for the trouble. This could have been fixed long ago if I had only read more carefully!

ROBOTMAN
05-31-2009, 06:08 PM
Problem Solved!

Adrenalynn
06-01-2009, 04:14 AM
You really do need to start at ground zero and read a book on python programming. This isn't the way to learn how to program.

Noodle
06-01-2009, 07:12 AM
Twittering from python is fun. But debugging usually bugs your friends. And that's something you can't debug. Haha. I love lame jokes.

Python is suprisingly fun. I've picked it up sorta in a few weeks. Not too difficult, but not extremely easy. Also, it's a cool language.

robologist
06-02-2009, 12:59 AM
<jedi programmer mind trick>

You really do need to start at ground zero and read a book on python programming.
... I really need to start at ground zero and read a book on Python programming ...

This isn't the way to learn how to program.
... This isn't the way to learn how to program ...

You can go about your business.
... I can go about my business ...

Move along
... Move along ...
</jedi>

;)

Adrenalynn
06-02-2009, 01:02 AM
These are not the source-codes you're looking for... All your base... :tongue:

ROBOTMAN
07-14-2009, 01:44 PM
OK I'm working my way through a book on python that is really helpful if anyone else is looking for a good beginners guid to python 2.5.1 check this one out "http://oreilly.com/catalog/9780596002817/".

Noodle
07-16-2009, 04:49 AM
OK I'm working my way through a book on python that is really helpful if anyone else is looking for a good beginners guid to python 2.5.1 check this one out "http://oreilly.com/catalog/9780596002817/".
http://diveintopython.org/toc/index.html
If you haven't encountered it yet. Are you familiar with programming already? It's not an incredibly hard program once you learn it's obscurities.

ROBOTMAN
07-16-2009, 12:00 PM
I did have a head start because I finished a book on java and that was much harder than python also I have been programing my arduino for years. When people told me to switch to python I found I already knew the basics like you said though I still need to learn its obscurities.

ScuD
07-16-2009, 12:07 PM
...also I have been programing my arduino for years....

Start programming that thing in assembly.

That'll grow some hair on your chest! :cool:

:veryhappy:

ROBOTMAN
07-16-2009, 05:34 PM
Just out of curiosity is assembly a good language to learn? I was browsing the internet and it's name came up on a lot of the sights I was going to.

Adrenalynn
07-16-2009, 06:52 PM
Every platform uses a different assembler - so you don't "just learn assembler". Assembly on the AVRs is entirely different than the assembler on an ARM is entirely different than assembler on a PIC, for example. It is good to know some assembler though since it forces you to understand what's actually going on inside those magic black chips.

ROBOTMAN
07-16-2009, 07:33 PM
OK I'll check out some websites on assembler for my arduino!

ROBOTMAN
08-09-2009, 05:49 PM
I interested in getting my robot to create simple maps that I originally create and it then follows. It will know its starting position and will make use of encoders and distance sensors to follow the correct path. The basic thing that I hope to accomplish with this map is allowing the robot to know when it is to close to a obstacle without using any sensors but the encoder and its map. I have a rough idea of how to do this using pygame using a pre made grid map. Each grid would represent 6" by measuring my room I would color the grids to represent obstacles and using my basic knowledge of pygame keep the robot form straying past pre set x,y coronets. My question is will this work effectively? My encoders are extremly accurate and I think they could keep the robot on course I would use the data gathered from the encoders to move a graphic representation of the robot in my map of course. If it would be somewhat effective then I need to know where to find a good tutorial on making grid maps in pygame "Ill get a book on it to...". I have seen some people in trossen robotics create grid maps in pygame so I'm sure someone can help me... I hope all this made sense.

lnxfergy
08-09-2009, 06:38 PM
I would never have a robot navigate on a map alone. You need to continuously use your sensors and the map to plot a course, most effective models out there use a high-level planner to plan the primary path, coupled with a set of low-level behaviors which steer the robot around local obstacles.

Even with extremely accurate encoders, what about wheel slip. Say you have 2-3&#37; error in distance due to wheel slip, if you go 20 feet forward, turn 90 degrees, and go forward 10 feet, the error will be huge. We also aren't talking about speed control, what happens if you roll forward on an arc? You need to continuously localize yourself within the map. I think it has been pretty well proven in industry/academia that this type of problem REQUIRES probabilistic approaches. Localizing yourself inside a map is quite difficult, and most methods require quite a bit of math, specifically probability and either filters or MCMC.

I would also suggest that a 6" grid is probably too little resolution, to effectively map the inside of a house, you might look at 2" or 3" grids, otherwise it will be very difficult to localize yourself.

I have a very brief tutorial (http://forums.trossenrobotics.com/tutorials/introduction-129/an-introduction-to-mapping-and-localization-3274/) on mapping and localization, just to hit the key points and terminology. The resources at the end will steer you towards implementation details.

Edit: also, while you may use pygame for displaying maps, you'll likely want to look at a pacakge like Numpy (numerical python extensions) to implement large, fast-access grids of data storage.

-Fergs

ROBOTMAN
08-09-2009, 06:45 PM
I'v already read your tutorial on mapping "good job by the way" I never planed on navigating by map alone and yes it dose sound like ill need smaller grid sections. My question had more to do with the creation of the map. I plan on having the robot run the course controlled by me at first so it can get distance readings than it will do something like go strait 5 feet on the map or until my ultrasonic sensor detects a distance of 6 feet on both sides and 10ft in frot and things like that. Also because the robot will run on carpet it shouldn't slip to much.

Adrenalynn
08-09-2009, 07:01 PM
Actually - carpet's about the worst thing for wheel slippage you'll find indoors.

Resilient
08-10-2009, 12:36 AM
I duno, that Teflon coating my ChemE friend laid down in my kitchen to "make cleaning it easier" is pretty slick. Its a damn death trap really... :tongue:



(I wish... I bet it would be really fun to slide on with those super slidy socks if such a kitchen floor actually existed)

ROBOTMAN
08-25-2009, 10:55 PM
I created a roborealm program that gets the x/y position and distance of a blue object I want to get it to notify the python code when a blue object is detected and what its x/y position is? I looked for to tutorials but I only found one on the roborealm site and it didn't help. Dose anyone know any good tutorials for this?

jes1510
08-25-2009, 11:43 PM
Create some variables in Roborealm and send them to your python program via a socket. Use "localhost" as the target and you should be good to go.

http://www.roborealm.com/help/Socket_Program.php

edit: I just remembered that the Roborealm API takes care of all of that for you. Download the API for python and take a look at that.

ROBOTMAN
10-25-2009, 05:39 PM
I'm currently working on developing a GUI for my robot in python. I would like it to have simple buttons as well as a basic map preferably made of a 200 by 200 square made up of small squares that change color to represent different things. My experience with pygame and tkinter has been disappointing to say the least. It seems like it would take much too long to develop the mapping program I want. Is there some sort of visual python program like visual basic? So far developing a GUI in python has been a nightmare for me and finding "Visual Python" will make developing much easier.

Adrenalynn
10-25-2009, 05:52 PM
pygame + wxpython (http://www.wxpython.org/) But the gui is the trivial part. The mapping is the hard part.

lnxfergy
10-25-2009, 06:10 PM
pygame + wxpython (http://www.wxpython.org/) But the gui is the trivial part.

I'd stick with either pygame or wxpython, mixing two GUI packages is never fun. As for a "visual basic" like setup, you're looking for a GUI builder, such as wxGlade for wxPython (I'm not aware of a GUI buider for pygame, as any button/widget system is an add-on, not built into pygame).

-Fergs

ROBOTMAN
10-31-2009, 03:44 PM
WxGlade dosn't seem to work well with python 2.5 have you gotten it to work?

ROBOTMAN
11-21-2009, 01:04 PM
I am interested in converting my GUI that I have made in python and placing it on the internet in a way only I can access it. This would hopefully allow me to access it from my phone. I believe the best way to do this would be with localhost but there seem to be lots of modules out there and I'm not sure witch one is best?

Connor
11-21-2009, 01:47 PM
I am interested in converting my GUI that I have made in python and placing it on the internet in a way only I can access it. This would hopefully allow me to access it from my phone. I believe the best way to do this would be with localhost but there seem to be lots of modules out there and I'm not sure witch one is best?

Um, the only way your going to get your GUI to work on a phone over the internet is to have it be a webpage. Did you design your GUI as a webpage or is it a TK type gui?

ROBOTMAN
11-21-2009, 01:51 PM
Its a wxPython GUI but I don't mind creating a new one that's web specific. It just needs to be able to send data back to python.

Connor
11-21-2009, 01:54 PM
Its a wxPython GUI but I don't mind creating a new one that's web specific. It just needs to be able to send data back to python.

Thats where you would start, and then you would either need a module to turn the python web gui into a mini-webserver or a webserver capable of running python.

Adrenalynn
11-21-2009, 03:09 PM
Personally, I'd just abstract the gui out, write the new GUI in Flash ActionScript, and then do a little client/server stub to talk to the server [which is the original code running on the web server]

Connor
11-21-2009, 03:12 PM
Personally, I'd just abstract the gui out, write the new GUI in Flash ActionScript, and then do a little client/server stub to talk to the server [which is the original code running on the web server]

His phone may not do Flash. I don't think my iPhone does.

Adrenalynn
11-21-2009, 03:13 PM
There's a flash interpreter for iPhone, yes.

Flash Pro CS5 supports the iPhone http://www.dotcominfoway.com/blog/flash-professional-cs5-brings-flash-support-for-iphone-apps

ROBOTMAN
11-21-2009, 03:38 PM
I would prefer that it be able to run on almost any platform with a web browser. Where do I find a program or module for creating a web GUI and how to I get it to run on the web server?

Adrenalynn
11-21-2009, 04:22 PM
It's called "html". Java is also a possibility. If you want it to run in any web browser interactively, it's java or the highway. If you don't need real interactivity (ie use a 'push to submit' sorta thing), then you html to a common gateway interface (CGI)

If you can't get html and/or java running in a webserver environment, this is the wrong project for you to undertake.

ROBOTMAN
11-21-2009, 04:52 PM
I will admit being a beginner with a limited background in java I have no idea how to do that. I could create the GUI but the server concept kind of throws me. Also I have no idea how to get the information in python. How can I ever learn to get html/java running in a web server environment if I don't ever try it? There must be a "hello world example" out there for the type of thing I want to do. Html seems like it might be easier but I need to create things like sliders and gauges so I'm not sure if that's what I should use. Although my experience in this is limited I pictured creating something like roborealm creates when you activate the web service. Then when an event happened I could send data about the event over the socket to python.

Adrenalynn
11-21-2009, 06:16 PM
The first question you should ask yourself: What web server running on what hardware?

From there: google is your friend.

MikeG
11-21-2009, 07:12 PM
Take a look at AJAX - asynchronous JavaScript and XML. AJAX uses well established web technologies to create rich UIs for the web.
http://www.ajax.org
http://www.w3schools.com/Ajax/Default.Asp
http://www.asp.net/ajax/
https://developer.mozilla.org/en/AJAX

ROBOTMAN
11-22-2009, 01:51 AM
I doubt I can program this in java from what I have seen and heard. Anything outside of python seems like a bad idea to try. All the examples I have tried so far I cant even connect to with another computer let alone a cell phone. What web server should I use for a computer running windows 7?

Adrenalynn
11-22-2009, 02:24 AM
Anything can be programmed in Java, anything at all.

MikeG
11-22-2009, 12:08 PM
The Windows web server is called IIS - Internet Information System. You probably need Windows 7 professional or ultimate to get IIS, not sure though.

You're trying to create what's called a distributed application. If you're doing this over the web then use HTTP GET or POST to send/receive data from your client app and the server. This is a fairly common thing to do and well documented.

ROBOTMAN
11-22-2009, 12:10 PM
Oops I meant to say that it would be to big of a learning curve to learn java on top of learning arduino and python. I'm surprised that python doesn't have something for this because it seemed to have solutions to everything else. What about something like iron python? I played around with html and it looked solid but I was not sure how to put it into server form. Maybe I left out one point I want this to run along side my robots software on a small laptop running windows 7. So I could press the kill switch on my cell or take control of the bot.

Oops posted just after you said that I'll take a look at it. I have windows seven home.

Connor
11-22-2009, 12:43 PM
Oops I meant to say that it would be to big of a learning curve to learn java on top of learning arduino and python. I'm surprised that python doesn't have something for this because it seemed to have solutions to everything else. What about something like iron python? I played around with html and it looked solid but I was not sure how to put it into server form. Maybe I left out one point I want this to run along side my robots software on a small laptop running windows 7. So I could press the kill switch on my cell or take control of the bot.

Oops posted just after you said that I'll take a look at it. I have windows seven home.

http://pyserv.sourceforge.net/
Is a python servlet module that lets you make a application act as a webserver. You'll need to figure out how to write your gui in HTML or like other sugested, Flash or Java etc..

Thanks, Connor

lnxfergy
11-22-2009, 11:36 PM
See also the "twisted" package, which basically allows you to do anything involving networks or servers in python...

-fergs

ROBOTMAN
11-23-2009, 12:03 AM
I think I might be missing something but I have yet to find something that creates a http address that I can use. No example actually builds the web page and puts it on the internet. They all seem to be the GUI side of the application instead of the server side and I cant access anything from my phone. Occasional programs have worked with localhost on another computer but of course that wont work with a cell phone. I can take care of the GUI part my self what I need is something to create a usable http address such as http://robotman/ that I can access from anywhere in the world on any device with internet access. It would be nice if someone could point me to a hello world example that dose this for one of the programs above.

lnxfergy
11-23-2009, 12:27 AM
Twisted can act as a server, just like Apache (in general), Tomcat (for Java), or any other server. Now, what you are asking is how to set up DNS for that server. That's not a coding thing really -- it's purchasing a domain name, and doing one of the following:

A) also purchasing web hosting with a static IP address (since your home cable/DSL router doesn't have a static IP).
B) setting up dynamic IP address forwarding for your home computer (and configuring your firewall/router correctly for this).

-Fergs

ROBOTMAN
11-23-2009, 09:53 AM
You need to purchase a domain to create a website? I thought that was only if you wanted it to appear on serch engines. I thought the http address was just the address to the computer runing the server software. Kind of like a address to a house.

Connor
11-23-2009, 10:07 AM
You need to purchase a domain to create a website? I thought that was only if you wanted it to appear on serch engines. I thought the http address was just the address to the computer runing the server software. Kind of like a address to a house.

A domain name translates to the IP address.. You can use a IP address, but, it's clunky. Aslo, you need to consider if your IP address changes. Now, If you phone uses Wifi (like iPhone) and you have wifi, it might be possible to fake it so you can use just the machine name, but, it won't work if your trying it over the internet.

lnxfergy
11-23-2009, 11:03 AM
You need to purchase a domain to create a website? I thought that was only if you wanted it to appear on serch engines. I thought the http address was just the address to the computer runing the server software. Kind of like a address to a house.

The computer connected to the internet has an IP address -- but, you're probably talking about running this off a computer in your house, that's connected to something like a cable or DSL modem -- in that case, your IP address changes frequently. As Connor said, you could just type in the ip address http://X.Y.Z.Q, but, your IP address will change often, not ideal.

Normally, a server is connected to a STATIC IP, that is, it doesnt change -- ever. If you have a server with a static IP, you can get to it by http://X.Y.Z.Q and the numbers won't ever change, but to get to it using a name, like http://robotman.com, you either have to setup the host file on your phone/device that is connecting to route http://robotman -> X.Y.Z.Q, or you need to purchase a real domain name and point it at X.Y.Z.Q if you want it to work on any device without any setup.

There are some services out there that will let you point a domain name at their static IP, and then their server does a redirection to your dynamic IP -- you have to add a program to the server that notices when it's IP has changed, so it can let that service know.

-Fergs

Adrenalynn
11-23-2009, 12:51 PM
Yeah, if you use a free dynamic ip service, you don't have to purchase the domain name. So something like robotman.dyndns.com, for example.

But are we really arguing about a $7 domain registration?

What you're really asking here is how to set up a linux or windows server to be visible from the Intarwebz. There's about two quadzillion pages documenting that process.

As was pointed out earlier - there's no "hello world" because this has nothing to do with programming. The programming for that was feature complete decades ago.

ROBOTMAN
11-23-2009, 05:59 PM
Its only $7 dollars? I guess I should have looked up the cost. I was worried about having to pay $30 dollars a month or something like that. Once I register my domain what would I need to do? From what I understand so far I would need to create the program that acts as my server and the html code to act as my GUI. Then I would need to wait for a event change on the website signifying the press of a button or the movement of a slider and pass that on to the tread that controls my robot? Can this all be done in python so that when I ran my bots code the site would become active and allow me to take control from any internet capable device? I believe I have the concept of how this would work down but I'm not 100&#37; sure. There must be some code involved because from what I understand I need to make the website accessible, the GUI appear, and allow my python code to check for events. Are you sure domain registration is only $7? From what it looks like it costs at least $7 a month.

Adrenalynn
11-23-2009, 06:19 PM
http://www.active-domain.com/ $2.85/yr
http://myhosting.com/promotions/2009/08/domain-name-registration/?gclid=CLzZw8erop4CFRhfagodEQhWlQ $6.85/yr

Godaddy, the big boy: http://www.godaddy.com/compare/gdcompare_domain.aspx?isc=goaz3001o $6.99/yr

But that all assumes that whatever the server connection is is NOT dynamic IP (ie. has a fixed IP address). If it's dynamic, then you need a dynamic DNS service, and a dynamic dns client on either your router or your client itself.

You need to research TCP/IP, specifically sockets and ports and forwarding ports, and you need to research how DNS works, then you need to crack open that dusty router manual, log into your router, and figure out how to apply what you've learned. That needs to happen before you even THINK about coding anything. Yuo also need to figure out if you're on a dynamic or static address, whether or not you are on a private network behind your WAN, then figure out what protocol you plan to use, then figure out how best to get a stack onto your device, then, once you have a working stack accepting forwarded packets and handling any potential IP changes on the fly - THEN you need to start architecting your server. Then use something like netcat or similar to send packets to your server, confirm it's delivering the expected results THEN write your client as appropriate.

Whether you use pre-rolled libraries or not, understanding client/server architectures is all about understanding how TCP/IP and subsequently, the Internet, works.

ROBOTMAN
11-23-2009, 06:54 PM
Sounds like a lot of reading. Ill try all of that. I know that my IP is dynamic or at least it changes and I use comcast with a private modem and router so I believe I'm in a private network. I think however that I can configure my router to give my computer a fixed IP address. What if I want to just control it over my home network for now? Is it any easier? I will of course look into what you said but for a short term solution could I easily control my bot over my personal network with my wifi capable tmobile G1?

Adrenalynn
11-23-2009, 07:36 PM
well, "easily" is subjective. You still need to understand how TCP works But you wouldn't need a dynamic domain service or port forwarding over your local network.

ROBOTMAN
11-23-2009, 09:32 PM
So I could access it with my phone? That seems like the better rout for now. Is there a hello world example for doing that or am I on my own?

Adrenalynn
11-23-2009, 09:43 PM
Well, if you mean that your phone is on your local network over wifi, yes.

I published a hello world already, long time ago.

ROBOTMAN
11-23-2009, 11:02 PM
Where can I find that hello world?

MikeG
11-24-2009, 07:43 AM
Get your internet IP address and write it down (This will change!)
Makeup a 4 digit port number like 1024
Setup your router for port forwarding forward all requests from port 1024 to 80 and enter the IP of your web server
Make sure your Windows firewall allows HTTP
Create a new text file
Type "Hello World"
Name the file default.htm or index.htm
Copy the file to your web site root
Verify that you can open the new page via http -> http://localhost/mysite/default.htm
Then try http://your.ip.address.here:1024/mysite/default.htm (http://your.ip.address.here:port/mysite/default.htm)

If you do not have a web server you'll need to get one. You might consider upgrading your Windows 7 or downloading Apache for windows. You can even download C# Express. C# Express comes with a web server and it does out-of-the-box exactly what you're trying to do but it will take some experience before you realize it.

Adrenalynn
11-24-2009, 05:56 PM
That's assuming a PC as a server. I don't know that I'd make that assumption. My XMOS is quite happy on the Intarwebz. So is the Arduino + Wiznet that monitors my electricity utilization. And a SAM7 doing weather collection. And an ARM9 that is my clock radio. etc, so-on, ad naseum - rinse, lather, repeat. If rash persists, discontinue use and consult your sysadmin immediately. Do not taunt happy-fun-stack.

MikeG
11-24-2009, 06:39 PM
I believe ROBOTMAN said he was using a Windows 7 OS and he wanted to grab web pages located on localhost with his WiFi phone.

Adrenalynn
11-24-2009, 10:56 PM
Aha. Missed the Windows 7 part. The thread's too convoluted to go back and read, so I'll surrender. Mea Culpa!

ROBOTMAN
11-27-2009, 11:15 PM
Whats the best way to get the relationship between two objects without creating a complex GUI in pygame. Could this be done with wxPython?

ROBOTMAN
12-03-2009, 08:47 PM
I need to create a program the opens a pdf file on a website when ever a new one is added and prints that pdf file. The pdf file would have a address like http://math/lesson1/page1/anwers.pdf/. The only part of the address that stays the same is the answers.pdf part. Is this possible? I can predict the changes in address but that would be a lot of code to add. The main point that confuses me is opening the pdf online and printing it. You can find the website I want to print from here (http://mrstiglets.com/?cat=12). My teacher posts the answers daily and I want my computer to print them out as they appear.

MikeG
12-03-2009, 09:07 PM
try
f = urllib.urlopen("http://www.mysite.com")
print f.read()

I'd imagine you need a pdf object to actually print the stream like pyPdf?

ROBOTMAN
12-03-2009, 10:44 PM
That just gives an error "NameError: name 'urllib' is not defined". I need to literally print the pdf to my physical printer. I also need a way to check and see if a new pdf is available that has not been printed to my printer.

lnxfergy
12-03-2009, 10:54 PM
That just gives an error "NameError: name 'urllib' is not defined". I need to literally print the pdf to my physical printer. I also need a way to check and see if a new pdf is available that has not been printed to my printer.

Um, import urllib......

Printing will be system dependent (for instance, if you're under *nix, and are using CUPS, you could use PyCUPS)

-Fergs

ROBOTMAN
12-03-2009, 10:59 PM
I'm on a win32 system. I know how to print but I would need to some how get the pdf in a raw text pictures and all. I really need to know how to print the pdf as a pdf.

Adrenalynn
12-03-2009, 11:49 PM
You can't get pictures in raw text. Well, you can - but that's really not what you mean.

Printing the PDF as a PDF can't be done on any physical printer that I've seen. PDF really isn't a printer language, it's a page descriptor. PCL, Postscript, etal - those are printer languages.

In order to print a PDF the PDF has the be translated into a printer language, which is done by the printer's device driver (in cooperation with the OS, of course).

You can't just simply pipe a pdf into a printer and expect it to work.

This really does beg the question - as I've certainly asked before: Have you discovered Google yet? It's really a remarkable tool. If you were to type something totally random like, oh, let's say : python print pdf the very FIRST link that came up would be to a page entitled:
Graham King &#187; Printing Word And PDF files from Python (http://www.darkcoding.net/software/printing-word-and-pdf-files-from-python/)


And, remarkably enough, the exact process you need to go through for dumping PDF from Python is... [GASP!] right there!

Believe it or not: this is a robotics forum. The folks here aren't your personal programming staff "employed" to dump the answers from your homework to your printer in an automated fashion. It's your class. It's your homework. It's your professor. It's your computer. It's your printer. Given all that, don't you think you should at least assume enough responsibility to type "python print pdf" into Google?!?

ROBOTMAN
12-04-2009, 12:51 AM
I did in fact google it and found that website. I tried the code but move on in my search through google witch lasted nearly an hour because I was not sure where to put my url. I'm not sure how to convince you that I do use google quite a bit but often find problems like that with code. Maybe I should have researched that site further but with so many different methods its hard to tell witch one is right. Being new to all this I am still learning and maybe a little to quick to post, I'll work on that but I'm not sure its fair to assume I don't try and research my topics before I ask a question. You have told me more than enough times to do this.:) I never considered anyone my personal programing staff just a group of people with similar interests "robotics" who don't mind sharing their knowledge. I'm not forcing you to post or even read my question I will figure it out at some point if its really that obvious. Thanks for the help you have given me I'm sorry to have bothered you or anyone else...

MikeG
12-04-2009, 07:52 AM
ROBOMAN, it works just like using a mouse.

Look in a folder to find the files you have already downloaded and printed (get the file names already printed from a flat text file or parse a directory of saved pdfs and create a url)

click the link (geturl)
open adobe acrobat (instantiate a pdf object library or write your own)
click the print button (use the object's print driver or write your own)

Save the pdf or write yourself a note (create/open a flat text file and write the file name just printed)

I have to agree with Adrenalynn, your questions are wide open and therefore it appears that you have not done your homework.

lnxfergy
12-04-2009, 08:08 AM
I think the problem here is not so much that you don't look around for answers: it's that you don't know your programming language well enough to even use resources you find. This thread has been characterized by "go out and find some pieces of code, hack them together, oh, it didn't work, post about it". Things like the "NameError" above should be quite explanatory, and easy to fix, to someone who actually understands python.

-Fergs