User Tools

Site Tools


misc:hacks:rasberrypi

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
misc:hacks:rasberrypi [2013-06-10 01:29]
absoloodle37
misc:hacks:rasberrypi [2021-06-24 16:45] (current)
kimberly
Line 1: Line 1:
 +<WRAP center round important 60%>
 +This page has deprecated and will be archived. Please go to [[https://www.bitcraze.io/]].
 +</WRAP>
 ====== Using the Raspberry Pi as a base station for flying ====== ====== Using the Raspberry Pi as a base station for flying ======
  
-You should setup the CF Headless client (see [[#current_state_of_the_headless_client|below]]) instead of the regular PC client on your Pi, since the UI seems to a bit too heavyweight for the Pi (controlling got **very** laggy during tests).+In order to make it easy for users that have a Raspberry Pi to test out our headless client we prepared an SD-card image that is ready to use out of the box. 
 + 
 +The full SD-card image, and instructions on how to install it are located [[http://wiki.bitcraze.se/projects:crazyflie:binaries:raspberrypi|here.]] 
 + 
 +Instead of the official Python headless client, there is also a working Ruby version of the headless client, developed by a user.  This version, called Crubyflie, can be installed on top of the SD-card image described above or on a standalone version of Linux/Debian/Raspbian.  It allows you to adjust control variables (like X-mode or max thrust) by changing the values in a configuration file.  For more information visit [[https://github.com/hsanjuan/crubyflie|the Crubyflie installation page.]] 
 + 
 +====== Manual Installation ===== 
 + 
 +As an alternative to a full SD-card image, you can manually install the headless Python client as a program on your Pi.  You should setup the CF Headless client (see [[#current_state_of_the_headless_client|below]]) instead of the regular PC client on your Pi, since the UI seems to a bit too heavyweight for the Pi (controlling got **very** laggy during tests).
  
 For the following installation instructions it is assumed that you are running the popular [[http://www.raspbian.org|Raspbian]] distrubution on your Pi.  For the following installation instructions it is assumed that you are running the popular [[http://www.raspbian.org|Raspbian]] distrubution on your Pi. 
Line 26: Line 37:
      
 and start it: ''sudo xboxdrv'' and start it: ''sudo xboxdrv''
 +
 +<WRAP center round tip 80%>
 +**NOTE**
 +
 +All modern Linux distribution now have a kernel driver for the x-box gamepad. Thus it is unlikely the //xboxdrv// user-space driver is needed.
 +</WRAP>
  
 Plugin your Crazyradio and your controller, power up the Crazyflie and start the client (via SSH and Ethernet or by using an USB hub to connect Crazyradio, controller and keyboard)((If you get an error message that ''python2'' could not be found, edit ''~/crazyflie-pc-client/bin/cfheadless'' and change the ''python2'' in the first line to ''python'')): Plugin your Crazyradio and your controller, power up the Crazyflie and start the client (via SSH and Ethernet or by using an USB hub to connect Crazyradio, controller and keyboard)((If you get an error message that ''python2'' could not be found, edit ''~/crazyflie-pc-client/bin/cfheadless'' and change the ''python2'' in the first line to ''python'')):
Line 83: Line 100:
 </code> </code>
  
-**Note**: If you created a customized .json file for your xbox controller using a Windows PC and the cfclient GUI and are planning to copy it over to your Raspberry Pi, here is some advice:+===== Manually Customizing Your .json Configuration File ===== 
 +If you created a customized .json file for your xbox controller using a Windows PC and the cfclient GUI and are planning to copy it over to your Raspberry Pi, here is some advice:
  
 -save the new .json file as something different than the default, so you can recognize it easily.  e.g. xbox360new.json -save the new .json file as something different than the default, so you can recognize it easily.  e.g. xbox360new.json
Line 89: Line 107:
 -the new .json file is not located in the Program Files(x64)/cfclient/input folder along with all the other default .json files; it's actually located in a hidden folder in your home directory.  Use the run... command from the start menu to get to it.  Type C:\Users\<your user name>\AppData\Roaming\cfclient\input\ to get to the right location of your new .json file -the new .json file is not located in the Program Files(x64)/cfclient/input folder along with all the other default .json files; it's actually located in a hidden folder in your home directory.  Use the run... command from the start menu to get to it.  Type C:\Users\<your user name>\AppData\Roaming\cfclient\input\ to get to the right location of your new .json file
  
--copy your new .json file into the correct RPi folder: /crazyflie-pc-client/conf/input/ Getting your customized .json file from your windows pc to your raspberry pi can be tricky.  Emailing it to yourself and accessing it using a RPi internet browser (like Midori) won't work because most email sites (hotmail, Gmail, etc.) require Java to access and RPi can't use Java.  USB flash drives need to be formatted correctly and that's a pain.  Not sure if you can ssh into your RPi from your Windows machine and copy the file over somehow using a Linux command Found a solution if you have access to a Mac-- install Netatalk on your Mac (http://gettingstartedwithraspberrypi.tumblr.com/post/24398167109/file-sharing-with-afp-and-auto-discovery-with-bonjour) and your RPi will show up magically in the finder window on your Mac.  On your windows machine, copy your new .json file to a flash drive and plug it into your Mac. Then you can just drag/drop your new .json file from the flash drive into the /crazyflie-pc-client/conf/input/ folder using your Mac (thanks to Netatalk).  +-copy your new .json file into the correct RPi folder: /crazyflie-pc-client/conf/input/ Getting your customized .json file from your windows pc to your raspberry pi can be tricky.  Emailing it to yourself and accessing it using a RPi internet browser (like Midori) won't work because most email sites (hotmail, Gmail, etc.) require Java to access and RPi can't use Java.  USB flash drives need to be formatted correctly and that's a pain.  Try using WinSCP to move files from your Windows PC to the RPi: (http://winscp.net/eng/index.php) I also found a solution if you have access to a Mac-- install Netatalk on your Mac (http://gettingstartedwithraspberrypi.tumblr.com/post/24398167109/file-sharing-with-afp-and-auto-discovery-with-bonjour) and your RPi will show up magically in the finder window on your Mac.  
  
--the cfheadless client on RPi may not recognize the same controller channel "id" numbers that were correct for your .json file when it worked on your Windows machine.  Mine didn't recognize the roll command, so when I flew, the CF just had pitch, yaw, and thrust using the controller sticks--no roll, but the right trigger would roll the CF hard to the right.  Using nano <my xbox config file>.json, I viewed/edited my .json file to identify which "id" was associated with the Right trigger and swapped it with the roll "id" number:  Had to change the roll "id" from 4 to 0 and whatever input was associated with 4, I changed the "id" of that one to 0.  Bottom line: If your .json file isn't controlling your CF correctly, experiment with the "id" numbers in your .json file.  Just remember not to duplicate any "id" numbers.  A number can only be used once in the file.+<code>sudo apt-get install netatalk</code>
  
 +Verify netatalk was installed successfully on your RPi by checking the Finder window on your Mac for a "Raspberry Pi" shared drive. On your windows machine, copy your new .json file to a flash drive and plug it into your Mac. Then you can just drag/drop your new .json file from the flash drive into the /crazyflie-pc-client/conf/input/ folder using your Mac (thanks to Netatalk).  
 +
 +-the cfheadless client on RPi may not recognize the same controller channel "id" numbers that were correct for your .json file when it worked on your Windows machine.  Mine didn't recognize the roll command, so when I flew, the CF just had pitch, yaw, and thrust using the controller sticks--no roll, but the right trigger would roll the CF hard to the right.  Using nano <my xbox config file>.json, I viewed/edited my .json file to identify which "id" was associated with the Right trigger and swapped it with the roll "id" number:  Had to change the roll "id" from 4 to 0 and whatever input was associated with 4, I changed the "id" of that one to 0.  Bottom line: If your .json file isn't controlling your CF correctly, experiment with the "id" numbers in your .json file.  Just remember not to duplicate any "id" numbers.  A number can only be used once in the file.  Here's what worked for me:
 +
 +Xbox Controller Input = id#
 +
 +Left stick vertical = 1
 +
 +Left stick horizontal = 0
 +
 +Right stick vertical = 3
 +
 +Right stick horizontal = 2
 +
 +Right trigger = 4
 +
 +Customize your flying configuration anyway you like using the inputs/id's above as a reference.
  
 **Note**: If you have more than one controller attached, you can select the one to use using the commandline parameter ''-c''. See ''cfheadless -h'' for available command line options: **Note**: If you have more than one controller attached, you can select the one to use using the commandline parameter ''-c''. See ''cfheadless -h'' for available command line options:
Line 124: Line 159:
  
 [[http://forum.bitcraze.se/viewtopic.php?p=417#p417|Marcus added]] the following things to note when using the headless client since it is a very early version: [[http://forum.bitcraze.se/viewtopic.php?p=417#p417|Marcus added]] the following things to note when using the headless client since it is a very early version:
-  * Still dependent on QT (the plan is to remove this very soon) +  * <del>Still dependent on QT (the plan is to remove this very soon)</del> Not dependent on QT anymore 
-  * Not much error handling yet (the plan is to improve this)+  * <del>Not much error handling yet (the plan is to improve this)</del> Better error handling. If something does wrong the client exists.
   * <del>Values are still hardcoded in the script (like mapping and URI for Crazyflie). They can be changed at the bottom in lib/cfheadless.py</del> -> **Update** [[https://bitbucket.org/bitcraze/crazyflie-pc-client/pull-request/7/command-line-options-for-radio-uri/diff|A pull request]] adding some command line options for setting the input mapping and radio URI to use has been accepted, update your client to use that.   * <del>Values are still hardcoded in the script (like mapping and URI for Crazyflie). They can be changed at the bottom in lib/cfheadless.py</del> -> **Update** [[https://bitbucket.org/bitcraze/crazyflie-pc-client/pull-request/7/command-line-options-for-radio-uri/diff|A pull request]] adding some command line options for setting the input mapping and radio URI to use has been accepted, update your client to use that.
   * <del>The headless client will open the first input-device found (so don't plug more than one)</del> -> **Update** [[https://bitbucket.org/bitcraze/crazyflie-pc-client/pull-request/7/command-line-options-for-radio-uri/diff|A pull request]] adding some command line option for selecting the used input device has been accepted, update your client to use that.   * <del>The headless client will open the first input-device found (so don't plug more than one)</del> -> **Update** [[https://bitbucket.org/bitcraze/crazyflie-pc-client/pull-request/7/command-line-options-for-radio-uri/diff|A pull request]] adding some command line option for selecting the used input device has been accepted, update your client to use that.
-  * No good way to quit it yet so you will have to kill the process+  * <del>No good way to quit it yet so you will have to kill the process</del> Press Ctrl-C or pull the dongle
 ===== Make the client startup automatically on Crazyradio plug in ===== ===== Make the client startup automatically on Crazyradio plug in =====
  
Line 139: Line 174:
 </code> </code>
  
-and (as root) create a file ''/root/bin/cfheadless'' with the following contents:+and (as root) you will create a file ''/root/bin/cfheadless'' using the instructions below, with the following contents:
  
 <code bash> <code bash>
Line 157: Line 192:
 </code> </code>
  
-You can only create the cfheadless file above in the /root/bin/ folder by being root--not pi or any other user name.  Switch to root: ''sudo -i'' and then navigate to the /root/bin/ folder: ''cd /root/bin/'' Create the cfheadless file by typing: ''touch cfheadless'' to create the file.  Then ''nano cfheadless'' to edit the file with the code shown above ('sudo' prefix not needed because you're already root).  Use the same method for the xbox360 file described in the section belowif using a xbox360 controller.  Don't forget to make your files executable after you've created them: ''chmod +x /root/bin/cfheadless'' and ''chmod +x /root/bin/xbox360''. Once you've created the cfheadless file (and xbox360 file, if needed), exit the root mode by typing Ctl + D.  You may have to restart your RPi in order for all new udev rules to take effect. Rather than unplug/replug your RPi, consider the following command:+You can only create the cfheadless file above in the /root/bin/ folder by being root--not pi or any other user name.  Switch to root: ''sudo -i'' and then navigate to the /root/bin/ folder: ''cd /bin/'' Create the cfheadless file by typing: <code bash>touch cfheadless</code> to create the file.  Then <code bash>nano cfheadless</code> to edit the file, adding the code shown above ('sudo' prefix not needed because you're already root).  Remember to substitute your desired config file in the appropriate place in the code above (replace: <your input config...>).  Use the same method for the xbox360 file described in the section below if using a xbox360 controller: 
  
-<code bash>sudo shutdown -h now -r +For the XBox360 Controller (after an "apt-get install xboxdrv"):
-</code> +
- +
-The -h halts all processes, the -r is the command to reboot after shutdown.   +
- +
-This should now take care to startup the headless client when you plug in the dongle and (hopefully ;-)) kill it again when you unplug. If you need any additional setup to get your controller working, you can add a similar udev-rule for that to take care of everything upon plugging in the controller as well. An example for the Microsoft Wireless XBox360 controller for PC can be found [[http://forum.bitcraze.se/viewtopic.php?p=490#p490|in this forums post]] or as detailed below. +
- +
-And for the XBox360 Controller (after an "apt-get install xboxdrv"):+
  
 Create a udev file ''/etc/udev/rules.d/99-xbox360.rules'' with contents (if using a Microsoft wireless gaming receiver): Create a udev file ''/etc/udev/rules.d/99-xbox360.rules'' with contents (if using a Microsoft wireless gaming receiver):
Line 179: Line 207:
         killall -9 xboxdrv         killall -9 xboxdrv
 fi</code> fi</code>
 +
 +Don't forget to make your files executable after you've created them: ''chmod +x /bin/cfheadless'' and ''chmod +x /bin/xbox360''. Once you've created the cfheadless file (and xbox360 file, if needed), exit the root mode by typing Ctl + D.  You may have to restart your RPi in order for all new udev rules to take effect. Rather than unplug/replug your RPi, consider the following command:
 +
 +<code bash>sudo shutdown -h now -r
 +</code>
 +
 +The -h halts all processes, the -r is the command to reboot after shutdown.  
 +
 +This should now take care to startup the headless client when you plug in the dongle and (hopefully ;-)) kill it again when you unplug. If you need any additional setup to get your controller working, you can add a similar udev-rule for that to take care of everything upon plugging in the controller as well. 
  
 :!: **Important** :!: Due to the current state of the client, you **must** make sure to first connect your controller and power up the Crazyflie before connecting the Crazyradio dongle and thus starting the client. If the client can't find either controller or Crazyflie, it will just hang and you'll have to re-plug the dongle again. :!: **Important** :!: Due to the current state of the client, you **must** make sure to first connect your controller and power up the Crazyflie before connecting the Crazyradio dongle and thus starting the client. If the client can't find either controller or Crazyflie, it will just hang and you'll have to re-plug the dongle again.
misc/hacks/rasberrypi.1370820558.txt.gz · Last modified: 2015-07-15 16:30 (external edit)