Reading Saitek Pro Flight Yoke System Data for UAV Usage

Here is the (Python) code I used for getting my Saitek Pro Flight Yoke (http://www.saitek.com/uk/prod/yoke.htm) data from the device into something usable. Python has a fantasic pygame library which reads joystick data. This is just a simple script that is short and sweet. This code reads all the motion axis (ie. the yoke, hat and throttles, ) and all of the buttons. Feel free to play around with it. I really dont want to use a RC transmitter for my UAV as I can so so much more with this device. Let me know what you think.

And you don't need the Pro Flight Yoke to use this - any joystick will do :)

USAGE NOTE: to execute type 'python filenameyousavethecodeas.py'

######################## START CODE ##############################

import pygame

joy = []

# Handel the joystick event
def handleJoyEvent(e):
# Check for joystick axis movement
if e.type == pygame.JOYAXISMOTION:
axis = "unknown"

if (e.dict['axis'] >= 0):
axis = 'a' + str(e.dict['axis'])

if (axis != "unknown"):
s = "%s|%f" % (axis, e.dict['value'])
print s

# Check for buttons
if e.type == pygame.JOYBUTTONDOWN:
if(e.dict['button'] >= 0):
print 'b' + str(e.dict['button'])

# wait for joystick input
def joystickControl():
while True:
e = pygame.event.wait()

if (e.type == pygame.JOYAXISMOTION or e.type == pygame.JOYBUTTONDOWN):
handleJoyEvent(e)


# main method
def main():
# initialize pygame
pygame.joystick.init()
pygame.display.init()

if not pygame.joystick.get_count():
print "\nPlease connect a joystick and run again.\n"
quit()

print "\n%d joystick(s) detected." % pygame.joystick.get_count()

for i in range(pygame.joystick.get_count()):
myjoy = pygame.joystick.Joystick(i)
myjoy.init()
joy.append(myjoy)
print "Joystick %d: " % (i) + joy[i].get_name()

print "Depress trigger (button 0) to quit.\n"

# run joystick listener loop
joystickControl()


# allow use as a module or standalone script
if __name__ == "__main__":
main()

Views: 232

Comment by Matt Fisher on March 31, 2009 at 4:04pm
Seems like the interface for the site butchers the code - proper indentation is needed. My bad.
Comment by tycinis on April 1, 2009 at 2:31am
why do you try this :

http://www.endurance-rc.com/pctx.html
Comment by Matt Fisher on April 1, 2009 at 5:17am
Very cool device - But I will be using a different freq and device to transmit my radio signal. Regardless, bookmarked the link, thanks.
Comment by Lorentz on April 2, 2009 at 4:19am
Hi Matt, nice job.
I'd like to do something similar, i.e. replacing the RC with PC + joystick + Xbee
but I'm wondering about the delays introduced by the whole system.
Have you got any figures about the time delays ?
thank you
Comment by Matt Fisher on April 2, 2009 at 5:21am
As for data relay delay, because I have around 80 inputs just from my joystick device I am planning on only sending updates of positions that have changed since their last recognized. That way the whole 3KB/s limit on the XBee is met, well, I hope. I will let you know once I get some more test results with beefier code.
Comment by Lorentz on April 2, 2009 at 2:11pm
ok. thank you in advance.
Comment by Matt Fisher on April 2, 2009 at 5:09pm
What kind of input device are you looking at getting Lorentz?
Comment by Lorentz on April 3, 2009 at 3:08am
I haven't a specific input device in mind yet, any suggestions are welcomed.
Comment by Matt Fisher on April 3, 2009 at 5:14am
Well I have to say if your willing to pay for it. The Saitek ProFlight Series has really nice stuff. I have the throttle box and yoke system as mentioned above.
Comment by Noth666 on April 3, 2009 at 7:22am
Which XBee are you using for this? I am working on something very similar but using Saitek Hotas joystick and throttle/rudder with XBee 868. Will prolly make my own tranceivers as I am not impressed with the XBees tho.

Comment

You need to be a member of DIY Drones to add comments!

Join DIY Drones

Social Networking

Contests

Season Two of the Trust Time Trial (T3) Contest has now begun. The fourth round is an accuracy round for multicopters, which requires contestants to fly a cube. The deadline is April 14th.

A list of all T3 contests is here

Groups

Advertisement

© 2013   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service