How to create a new controller for the crazyflie?

Firmware/software/electronics/mechanics
Post Reply
luckpolar
Member
Posts: 30
Joined: Thu Oct 09, 2014 11:04 am

How to create a new controller for the crazyflie?

Post by luckpolar »

Recently, I'm wondering to control crazyflie by leapmotion controller
I have found that someone has done it , and the best way to control crazyflie is creating a new controller in the client.
So, do you have any suggestion or experience for how to create a new controller for crazyflie?
BTW, could you tell me the exact file of controllers?I don't find the wondering file...
Thank you a lot!

Yixiong Xu
whoenig
Expert
Posts: 395
Joined: Mon Oct 27, 2014 2:55 am

Re: How to create a new controller for the crazyflie?

Post by whoenig »

You can find the leapmotion controller as part of the official source tree, just in another branch: https://github.com/bitcraze/crazyflie-c ... leapmotion

To figure out how they did it, you can compare the branch to the master branch: https://github.com/bitcraze/crazyflie-c ... leapmotion
luckpolar
Member
Posts: 30
Joined: Thu Oct 09, 2014 11:04 am

Re: How to create a new controller for the crazyflie?

Post by luckpolar »

whoenig wrote:You can find the leapmotion controller as part of the official source tree, just in another branch: https://github.com/bitcraze/crazyflie-c ... leapmotion

To figure out how they did it, you can compare the branch to the master branch: https://github.com/bitcraze/crazyflie-c ... leapmotion
Thank you!
I still have a question:
What is the purpose of using pygame?
In my opinion, I think the pygame is used to send the cotrol messages to the crazyflie. Am I right?
whoenig
Expert
Posts: 395
Joined: Mon Oct 27, 2014 2:55 am

Re: How to create a new controller for the crazyflie?

Post by whoenig »

The control messages are send using pyusb. Pygame is used for the joystick support (at least on Windows and Mac; Linux seems to have a custom implementation) and I believe the widget which shows you the current orientation of the crazyflie is done using pygame as well.
luckpolar
Member
Posts: 30
Joined: Thu Oct 09, 2014 11:04 am

Re: How to create a new controller for the crazyflie?

Post by luckpolar »

whoenig wrote:The control messages are send using pyusb. Pygame is used for the joystick support (at least on Windows and Mac; Linux seems to have a custom implementation) and I believe the widget which shows you the current orientation of the crazyflie is done using pygame as well.
Thank you a lot.
The pygame is used to support leapmotion for data reading, am I right?
whoenig
Expert
Posts: 395
Joined: Mon Oct 27, 2014 2:55 am

Re: How to create a new controller for the crazyflie?

Post by whoenig »

It uses the official Leap Motion SDK to read the data from leap motion (see http://wiki.bitcraze.se/projects:crazyf ... leapmotion). I didn't look into Bitcraze code into much detail, but it would surprise me if pygame is required just for accessing the leap motion controller.
luckpolar
Member
Posts: 30
Joined: Thu Oct 09, 2014 11:04 am

Re: How to create a new controller for the crazyflie?

Post by luckpolar »

whoenig wrote:It uses the official Leap Motion SDK to read the data from leap motion (see http://wiki.bitcraze.se/projects:crazyf ... leapmotion). I didn't look into Bitcraze code into much detail, but it would surprise me if pygame is required just for accessing the leap motion controller.
I run the dev-leapmotion clients and it is really hard to control the crazyflie.
Also,I have a question.

Code: Select all

            # Pich and roll are mixed up...
            roll = -direction.pitch * Leap.RAD_TO_DEG / 30.0
            pitch = -normal.roll * Leap.RAD_TO_DEG / 30.0
            yaw = direction.yaw * Leap.RAD_TO_DEG / 30.0
            thrust = (hand.palm_position[1] - 80)/150.0
I don't know why the roll(pitch & yaw) angles (detected from leapmotion controller) divided by 30?
When I remove the 30,the angle would be incredible large...
whoenig
Expert
Posts: 395
Joined: Mon Oct 27, 2014 2:55 am

Re: How to create a new controller for the crazyflie?

Post by whoenig »

I guess that is an arbitrary choice. The leap motion SDK gives you back angles in degrees. The crazyflie itself takes numbers from -30 to 30 for roll/pitch, which somehow map to the angle (not sure how exactly - would need to look in the firmware code). The yaw is the angular rate between -200 and 200. Hence, I would expect that those values were empirically determined.
luckpolar
Member
Posts: 30
Joined: Thu Oct 09, 2014 11:04 am

Re: How to create a new controller for the crazyflie?

Post by luckpolar »

whoenig wrote:I guess that is an arbitrary choice. The leap motion SDK gives you back angles in degrees. The crazyflie itself takes numbers from -30 to 30 for roll/pitch, which somehow map to the angle (not sure how exactly - would need to look in the firmware code). The yaw is the angular rate between -200 and 200. Hence, I would expect that those values were empirically determined.
Yeah,I think you are right.
In ADVANCED Flight mode,
The Max angle/rate and Max Yaw angle/rate default numbers are 30 and 200
In the input.py, the raw pitch and raw angles are multiplied by Max angle/rate;the yaw angles are multiplied by Max Yaw angle/rate.
The purpose of divided by 30 may be use the leapmotion raw data as the input data.
I set the Max angle/rate and Max Yaw angle/rate as 1,and use the raw data from leapmotion without any operation.
It seems work!~

Thanks a lot!
Post Reply