Multiwii + RasPi + PS3 controller = FUN!
Posted: Sun Oct 19, 2014 3:52 pm
So I spent a couple of hours typing out a beautiful guide on how to get them working together and then it went and lost it. Grrrrrrrrrrrrrr!
Here's how I got my multiwii and raspi working together to fly!
##################################
Disclaimer: If you break something by copying me, Ooops! Not my fault
#################################
We need a multiwii and a raspberry pi (version doesn't matter)
We also need some additional software on the raspi soooooooooooooooo
now open a file and call it quad.py (or something easy to figure out)
and paste the following into it
Save and close, don't close and sa-oh shi!
Now add 2 lines to /etc/rc1.d/K01servoblaster so it looks like this
Save and close
/root/flight-recorder.txt will basically be your way of looking back on things to see what might have gone wrong and where but it only records commands sent by the raspi to the Multiwii, not what the Multiwii received.
Things to note:
I am using a usb "PS2"(knockoff) joypad but I plan on implementing either bluetooth PS3(genuine) joypad control or wifi control via a laptop.
Pi Cam recording for flights (easy to do, just need to add raspivid -o filename.mp4 somewhere and make a little frame to mount the camera module)
The joypad needs to be detected before the script tries to run otherwise the script will fail (because it needs a joypad to run)
Obligatory pics of my RasPi + Multiwii breakout board
Idle ////////////// Armed


Top of breakout board + foam ////////////// Bottom of breakout board


Here's how I got my multiwii and raspi working together to fly!
##################################
Disclaimer: If you break something by copying me, Ooops! Not my fault

#################################
We need a multiwii and a raspberry pi (version doesn't matter)
We also need some additional software on the raspi soooooooooooooooo
Code: Select all
## as root ##
root@multi-pi:~# apt-get install joystick
root@multi-pi:~# wget http://github.com/richardghirst/PiBits/archive/master.zip && unzip master.zip && cd PiBits-master/ServoBlaster/user/ && make install
now open a file and call it quad.py (or something easy to figure out)
Code: Select all
root@multi-pi:~# nano quad.py
and paste the following into it
Code: Select all
#!/usr/bin/python
#Python cares about whitespace so don't jiggle anything around unless I've broken it here
#94% of the code here was written by my friend Jnet, I just kept poking him with a stick until it worked :D
#and then I changed all the names and added the comments so hopefully anyone can understand how it works
import pygame #This is the library for joystick inputs
import numpy #This is the library that does range mapping (convert a number from one range into another)
pygame.init()
pygame.joystick.init()
#Open Game Pad
gamepad = [pygame.joystick.Joystick(x) for x in range(pygame.joystick.get_count())]
gamepad[0].init()
done = False
while done == False:
for event in pygame.event.get():
if event.type == pygame.JOYAXISMOTION:
if event.axis == 0: #Event.axis == 0 refers to the first joysticks left-right movement
sblast = open('/dev/servoblaster', 'w') #This opens the "radio" ready to send a signal
roll = numpy.interp(event.value,[-1,1],[100,200]) #This converts the left sticks left to right position to a "radio" value
print("Roll Postion =", roll) #This isn't necessary but is useful for debugging, if you have a screen
sblast.write("1=" + str(int(roll)) + '\n') # "1=" refers to servoblasters 2nd output on pin11 of the raspberry GPIO
sblast.close() #This actually transmits it, don't ask me why but it only tx's on close
if event.axis == 1: #Event.axis == 1 refers to the first joysticks up-down movement
sblast = open('/dev/servoblaster', 'w')
pitch = numpy.interp(event.value,[-1,1],[100,200])
print("Pitch Postion =", pitch)
sblast.write("2=" + str(int(pitch)) + '\n') # "2=" refers to servoblasters 3rd output on pin12 of the raspberry GPIO
sblast.close()
if event.axis == 2: #Event.axis == 2 refers to the 2nd joysticks left-right movement
sblast = open('/dev/servoblaster', 'w')
yaw = numpy.interp(event.value,[-1,1],[101,199])
print("Yaw Postion =", yaw)
sblast.write("3=" + str(int(yaw)) + '\n') # "3=" refers to servoblasters 4th output on pin13 of the raspberry GPIO
sblast.close()
if event.axis == 3: #Event.axis == 3 refers to the 2nd joysticks up-down movement
sblast = open('/dev/servoblaster', 'w')
throttle = numpy.interp(event.value,[-1,1],[90,180])
print("Throttle Postion =", throttle)
sblast.write("0=" + str(int(throttle)) + '\n') # "0=" refers to servoblasters 1st output on pin7 of the raspberry GPIO
sblast.close()
if event.type == pygame.JOYBUTTONDOWN: # If ANY BUTTON is pressed then the throttle is set to MIN and it should come down level-ish
sblast = open('/dev/servoblaster', 'w')
print("ABORT!!!!!")
sblast.write("0=100\n1=150\n2=150\n3=150" + '\n') # If you have a heavy quadcopter change 0=100 to 0=110 or 120 130 or 140 etc so it doesn't crash so hard
sblast.close()
done = True
Save and close, don't close and sa-oh shi!
Now add 2 lines to /etc/rc1.d/K01servoblaster so it looks like this
Code: Select all
case "$1" in
start)
/usr/local/sbin/servod $OPTS >/dev/null
/bin/date >>/root/flight-recorder.txt ####### ADD THIS LINE
/usr/bin/python /root/quad.py >>/root/flight-recorder.txt & ####### AND THIS LINE
;;
Save and close
/root/flight-recorder.txt will basically be your way of looking back on things to see what might have gone wrong and where but it only records commands sent by the raspi to the Multiwii, not what the Multiwii received.
Things to note:
I am using a usb "PS2"(knockoff) joypad but I plan on implementing either bluetooth PS3(genuine) joypad control or wifi control via a laptop.
Pi Cam recording for flights (easy to do, just need to add raspivid -o filename.mp4 somewhere and make a little frame to mount the camera module)
The joypad needs to be detected before the script tries to run otherwise the script will fail (because it needs a joypad to run)
Obligatory pics of my RasPi + Multiwii breakout board
Idle ////////////// Armed


Top of breakout board + foam ////////////// Bottom of breakout board

