Hardcoding height hold mode in crazyflie when using ZRanger module

Discussions and questions about the Crazyflie Nano Quadcopter
Post Reply
abhishekkumar1902
Beginner
Posts: 8
Joined: Thu Aug 03, 2017 5:46 am

Hardcoding height hold mode in crazyflie when using ZRanger module

Post by abhishekkumar1902 » Tue Sep 05, 2017 6:59 am

Hello, I have the following doubts:

1. Provided will be using a ZRanger module, is there a way to hardcode height hold mode in the crazyflie firmware so that whenever we power ON the crazyflie, it starts hovering automatically in height hold mode. If yes, can you please tell me the package where we can actually hard code this mode?

2. Where exactly in the crazyflie's firmware, the default height of height hold mode is stored?

Thanks in advance!

arnaud
Bitcraze
Posts: 1212
Joined: Tue Feb 06, 2007 12:36 pm

Re: Hardcoding height hold mode in crazyflie when using ZRanger module

Post by arnaud » Tue Sep 05, 2017 8:32 am

Hi,

Using Z-ranger the Crazyflie will drift away in X-Y so you have to be a bit careful with the fully autonomous functionalities.

To answer your questions without making too many assuption:
1. Yes it is possible. You need to call the commanderSetSetpoint function with the setpoint you want: https://github.com/bitcraze/crazyflie-f ... nder.h#L46. The priority parameter allows to set if the setpoint can be overwritten by setpoints received via the radio.

2. The default height when flying from the Crazyflie client is not defined in the firmware, it is set from within the client.

I am trying not to make too many assumption. For me to be more precise you need to tell a bit more what is your end goal. Do you want to completely disable the radio setpoint or do you just want to set the height and send only roll pitch by radio? Do you want to implement more complex autonomous behavior or just set the height?

abhishekkumar1902
Beginner
Posts: 8
Joined: Thu Aug 03, 2017 5:46 am

Re: Hardcoding height hold mode in crazyflie when using ZRanger module

Post by abhishekkumar1902 » Tue Sep 05, 2017 9:28 am

Thanks for the reply arnaud!

My main goal is to set some default (example something like 1m well measurable by the ZRanger module) height of the quad and then just to send the ROLL, YAW and PITCH commands from the client (from android client specifically via BLE). Thus we want the quad to by default start hovering at some specific height, so the pilot do not need to bother about setting and holding the thrust all the time and so that he can just maneuver the quad with ROLL/YAW/PITCH commands.

1. Thus I also was curious to know about like how exactly to command the quad to start hovering at that set DEFAULT HEIGHT. From the function crtpCommanderRpytDecodeSetpoint(), it looks to me like we have to give some thrust value to set the default height. Is it true? and then set thrustLocked = true or something.

2. I see some if statements defined in the function crtpCommanderRpytDecodeSetpoint(), based on boolean values like the following:
static bool thrustLocked = true;
static bool altHoldMode = false; (I believe this is the one for height hold that I might need to set)
static bool posHoldMode = false;
static bool posSetMode = false;

Can you tell me a little about these? like where exactly these things are set in the crazyflie firmware (I believe these come from the clients like when from the drop down menu you select the flight mode)? and do I need to bother setting these when hardcoding HEIGHT HOLD mode?

3. Can you also tell me a little about the three priority modes that we have declared - COMMANDER_PRIORITY_DISABLE, COMMANDER_PRIORITY_CRTP, and OMMANDER_PRIORITY_EXTRX?

4. In the function crtpCommanderRpytDecodeSetpoint() in crtp_commander_rpyt.c, can you tell me what exactly are these velocity modes defined in the enum mode_e i.e. being set to mode.z in the following code t line 159:

Code: Select all

  if (altHoldMode) {
    setpoint->thrust = 0;
    setpoint->mode.z = modeVelocity;
    setpoint->velocity.z = ((float) rawThrust - 32767.f) / 32767.f;
  } else {
    setpoint->mode.z = modeDisable;
  }

arnaud
Bitcraze
Posts: 1212
Joined: Tue Feb 06, 2007 12:36 pm

Re: Hardcoding height hold mode in crazyflie when using ZRanger module

Post by arnaud » Wed Sep 06, 2017 9:00 am

Hi,

Thanks for describing your high-level goal, it makes it much easier for me to help you :-).

There is no such things as default height defined in the firmware. All setpoint are currently sent from the ground.

I will answer your question first and then propose a better way to go forward:

1. This variable implements a trust lock to avoid having the crazyflie jumping uppon connection if your gamepad is lock to max thrust (this can happen with PS3 gamepads before pressing the PS button ...).

2. These variables are used to pass X/Y/Z position setpoint in the roll/pitch/yaw commander packet. This was a hack and you should certainly not use that anymore (see bellow).

3. The priorities allows to have multiple setpoint source enabled but not affecting each other. The highest priority will set the setpoint, if no setpoint is sent for one second, a lower priority source can take over. This can be useful to implement an internal sequencer but keep a way to take over from the ground. Though this is a hard switch: there is no mixing between source, it is one or another.

4. This piece of code will set the Z controller in velocity mode, the Z velocity is "setpoint->velocity.z" in m/s. As said earlier, this is a hack to pass position or velocity data in a roll/pitch/yaw/thrust packet. This should be considered legacy code.


Now for the better way: there is now a 'generic' commander packet that is aimed at sending setpoints in there original unit without having to hack around with parameter and roll/pitch/yaw packets. It is implemented there: https://github.com/bitcraze/crazyflie-f ... _generic.c. You can try to find a packet that fits your needs or create a new one.

From your description, I think the packet you need is zDistance: https://github.com/bitcraze/crazyflie-f ... #L113-L144. It is used in the client for height-hold mode. It will allow you to send an absolute height (ie. 1 meter) and send the roll/pitch/yaw setpoints from the user.

If you want an example on how to send the packet from Android, you can look at this pull request: https://github.com/bitcraze/crazyflie-a ... nt/pull/67. It is an implementation of altitude hold for the andoid client, it is using a generic commander packet already and it should be fairly easy to modify it to send a zDistance packet instead: https://github.com/bitcraze/crazyflie-a ... 6918bdR776.

arnaud
Bitcraze
Posts: 1212
Joined: Tue Feb 06, 2007 12:36 pm

Re: Hardcoding height hold mode in crazyflie when using ZRanger module

Post by arnaud » Wed Sep 13, 2017 8:24 am

Hi abhishekkumar1902,

Any news on this project, have you managed to control the Crazyflie the way you wanted?

Post Reply