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
Next revision Both sides next revision
misc:hacks:rasberrypi [2013-06-09 23:31]
absoloodle37 Clarified how to create the cfheadless and xbox360 executable files in the /root/bin folder
misc:hacks:rasberrypi [2013-06-10 00:54]
absoloodle37 corrected typo
Line 29: Line 29:
 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'')):
  
-  python ~/crazyflie-pc-client/bin/cfheadless -u radio://0/10/250K -i <your input config>+  python ~/crazyflie-pc-client/bin/cfheadless -u radio://0/10/250K -i <your input config (without the .json suffix)>
  
 The client should start up, hopefully find your Crazyradio dongle, your Crazyflie and your controller and start accepting commands: The client should start up, hopefully find your Crazyradio dongle, your Crazyflie and your controller and start accepting commands:
Line 82: Line 82:
 INFO:cflib.crazyflie:Callback->Connection setup finished [radio://0/10/250K] INFO:cflib.crazyflie:Callback->Connection setup finished [radio://0/10/250K]
 </code> </code>
 +
 +**Note**: If you used a Windows 7 PC and the cfclient GUI to create a customized .json file for your xbox controller and plan 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
 +
 +-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 MacPorts on your Mac (http://www.macports.org/install.php) 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 MacPorts).  
 +
 +-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.
 +
  
 **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 146: Line 157:
 </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 by typing: sudo -i and then navigating 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 above (sudo prefix not needed because you're already root).  Use the same method for the xbox360 file, if using a xbox360 controller.  Don't forget to make your files executable: ''chmod +x /root/bin/cfheadless'' and ''chmod +x /root/bin/xbox360''. Once you've created the cfheadless (and xbox360 file, if needed), exit the root mode by typing Ctl + D.  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.+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 ('sudoprefix not needed because you're already root).  Use the same method for the xbox360 file described in the section below, if 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.  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"): And for the XBox360 Controller (after an "apt-get install xboxdrv"):
Line 164: Line 175:
 :!: **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.
  
-**Troubleshooting** If it still doesn't appear to work, try looking at the logs in the each of the following areas: +**Troubleshooting**  
-  * /tmp/cfheadless.log+If it still doesn't appear to work, try looking at the logs in the each of the following areas: 
 +  * /tmp/cfheadless.log (If this log indicates that there's no reference to Python2, edit crazyflie-pc-client/bin/cfheadless in order to change the 'python2' to 'python' in the beginning lines of the code.)
   * /var/log/syslog   * /var/log/syslog
 +
 +Also, if xboxdrv can't be run without the sudo command, or there are other permissions issues with the xbox wireless usb controller, try adding the the xbox360 wireless receiver to a group that has root privileges.  This can be done by adding: GROUP="plugdev", to the 99-xbox360.rules udev rule (similar to the code in the crazyradio udev rule).
 +
 +Also, if running the xboxdrv command from a terminal window gives you the following error: 'Error couldn't claim the USB interface: LIBUSB_ERROR_BUSY' your controller may very well have already started automatically per the udev rule you created above and could be working correctly and currently is in use.  Make sure your wireless controller is powered on and connected (green arc showing), turn on your crazyflie and then plug in your crazyradio.  Once the green light on your crazyflie flashes on, you have a connection and are ready to fly!
 +
 ===== Make your base station portable ===== ===== Make your base station portable =====
  
misc/hacks/rasberrypi.txt · Last modified: 2021-06-24 16:45 by kimberly