Page 1 of 7

Android client with basic support for PS3 controller

Posted: Sun Jun 16, 2013 11:38 pm
by derf
Hi all,

First of all thanks a lot to the CrazyFlie team for creating this awesome little toy!

I worked on the Android client and tried to fix a few things and add some features.

New features include:
-preferences for selecting the radio channel, the bandwidth/datarate, mode, deadzone (very useful, when using the PS3 controller)
-connect/disconnect radio
-show values for pitch,roll,thrust,yaw on-screen
-basic support for using a PS3 controller as input device instead of the on-screen controls

How to set up the Android client with the PS3 controller:
For phones/tablets without root access:
01. Get the APK here: https://bitbucket.org/fredg02/crazyflie ... -06-17.apk
02. Connect a USB Host (OTG) adapter to your Android device
03. Connect a Y-cable with the USB Host adapter
04. Connect a wall-plug with the (red) power plug of the Y-cable (you need external power)
05. Connect the upstream port of a USB hub with the socket of the Y-cable
06. Plug the PS3 controller and the CrazyRadio into the USB hub
07. The CrazyFlie Android client should say "Using external PS3 controller" and the CrazyRadio's LEDs should light up for a second
08. Press the "PS" button and move the analog sticks (the pitch/roll/thrust/yaw on-screen values should change)
09. Make sure the right radio channel is set in the preferences (default is 10)
10. Click the connect menu item in the context menu (the CrazyRadio LEDs should light up red)
11. Switch on your CrazyFlie (the CrazyRadio LEDs should light up green)
12. Lift off and have fun!

if no PS3 controller is connected, the on-screen controls work as expected.

If you have an Android phone/table with root access it's possible to use the Sixpair app and connect the PS3 controller via bluetooth.
I'll provide a special APK in the next days for that (right now I'm only checking if the PS3 controller is connected via USB).

Disclaimer:
As the CrazyFlie Android client is my first Android project there is a good chance that parts of the code are ugly, crazy or just plain wrong. ;)
Hopefully someone who's more familiar with Android can help improve the code.
I've tested it successfully with a Galaxy Nexus (4.2.2, not rooted), minimum API level is 14.
I'm NOT responsible if you crash your CrazyFlie into the furniture, so please fly carefully, especially with the on-screen controls!

Looking forward to bug reports and success stories. :)

TL;DR: Get the APK and don't expect too much!

Regards,

Fred

Re: Android client with basic support for PS3 controller

Posted: Mon Jun 17, 2013 6:40 am
by DesTinY
Great Fred! I can't wait to try your app (if i'm back at home)! I want to do the same with the usb Ps3 controller and android app. (http://forum.bitcraze.se/viewtopic.php? ... +ps3#p1320)
If it's working as aspected it's time to root my S3 :D

Re: Android client with basic support for PS3 controller

Posted: Mon Jun 17, 2013 7:45 am
by tobias
Awesome!
Will try as soon as I get a chance. I have a Sony tablet S with PS3 gamepad support which will be interesting to try. Just have to get the Crazyradio working with it as well.

Re: Android client with basic support for PS3 controller

Posted: Mon Jun 17, 2013 6:30 pm
by DesTinY
Totally awesome!
Fred you are my hero! Sorry but in my opinion it flys better than the PC client :D
Tomorrow I will definitely root my S3 to fly via bluetooth :lol:
But flying with the screen pads is still not recommended!!!
Even so to fly with an empty phone akku :? I lost connection during the empty bat (15 %) message. :shock:
But after the flight the ps3 controller was full charged again :lol:

Re: Android client with basic support for PS3 controller

Posted: Tue Jun 18, 2013 7:23 am
by tobias
OK, now I really really have to get it working on my Tablet S!

You don't have to be sorry you think it's better then the PC client, that is just great! ;).

Fred, we would like to give you write access to the bitbucket Android repo as we haven't got much time to maintain it anyway, interested?

Re: Android client with basic support for PS3 controller

Posted: Tue Jun 18, 2013 11:16 pm
by derf
@DesTinY
Glad, that it works for you. :)

@tobias
I'll keep my fingers crossed that you'll find a solution to get your Tablet S connected. Hopefully that fixes my issue with the HP Touchpad too.

Sure, I'll be happy to contribute my code.
I know you guys are mostly dealing with Python or C code, but do you prefer any special Java coding/formatting standards?
While working on the Android client, a few questions came up for which I did not find answers in the wiki - at first glance at least.
I'll try to dig into the CrazyFlie Python API (and maybe port it), but maybe you can shed some light on this in the meantime:
-Why is "Thrust" a char and not a float like Roll/Pitch/Yaw?
-How did you work out the factors for each axis (Roll/Pitch = 20, Yaw = 150, Thrust = 40000 + 20000)?

Re: Android client with basic support for PS3 controller

Posted: Wed Jun 19, 2013 7:41 am
by tobias
Sure, I'll be happy to contribute my code.
Can you send me your bitbucket user name so I can give you write access.
do you prefer any special Java coding/formatting standards?
We haven't discussed that at all so you get to set the standard if you want. ;)
Why is "Thrust" a char and not a float like Roll/Pitch/Yaw?
It is because of the internal representation in the Crazyflie firmware. The roll/pitch/yaw are represented with floats and the thrust with a uint16. It also makes the radio packet a bit smaller. Any problem in Android with this representation?
How did you work out the factors for each axis (Roll/Pitch = 20, Yaw = 150, Thrust = 40000 + 20000)?
Don't really understand your question, can you elaborate?

Re: Android client with basic support for PS3 controller

Posted: Wed Jun 19, 2013 12:40 pm
by Mohero
Looking forward to the code on this. In my Android client I've already increased the Roll/Pitch to 30 and Yaw to 300, though I've been flying for a while and I'm rather insane :)

With these settings I can tilt the copter over at full power and it stays pretty much perfectly level, though, apparently not many other people (even experienced heli flyers) are able to control it on their first attempt.

One thing I was looking at adding is a "D/R switch" - to change the flight mode from "nice and gentle" to "Oh my god how are you controlling that" - which is how generally how I have my big helis.

Nice work, though - looking forward to testing this!

J

Re: Android client with basic support for PS3 controller

Posted: Wed Jun 19, 2013 2:47 pm
by timsson
just for me a xbox360 controller- please
its very hard to fly with the pad ;)
Thx!!!!!"

Re: Android client with basic support for PS3 controller

Posted: Wed Jun 19, 2013 11:17 pm
by derf
@tobias
My BitBucket username is fredg02.
No problem with the char, just wondering.

I was referring to the factors that were used here:
https://bitbucket.org/bitcraze/crazyfli ... ult#cl-205
https://bitbucket.org/bitcraze/crazyfli ... ult#cl-234

Are those factors related to min/max values for roll/pitch/thrust/yaw or just picked by trial and error? ;)

@Mohero
Sounds like a new feature request (eg. "Crazy mode"). :)

@timsson
I don't have a XBox360 controller at hand to test it, but I'll try to generalize the joystick interface.