How to change height in height mode

Firmware/software/electronics/mechanics
matthieuleonie
Beginner
Posts: 20
Joined: Mon Nov 13, 2017 11:54 am

How to change height in height mode

Post by matthieuleonie »

Hi,
We would like to change the height held by the drone when using the z-ranger (it is set to 40cm) but we still haven't found where to do that in the code. Can you help us please ?

thank you!
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: How to change height in height mode

Post by tobias »

From where do you want to control the height, e.g. cfclient, pythion-lib, firmware?
matthieuleonie
Beginner
Posts: 20
Joined: Mon Nov 13, 2017 11:54 am

Re: How to change height in height mode

Post by matthieuleonie »

Hi,
Actually, we want to understand how the motors are controlled to maintain 40cm thanks to the altitude send by the Zranger : in the height hold mode, where the setpoints are created and how they are created for the thrust? How it knows how many thrust the drone's need to maintain this altitude (the value of the thrust setpoint). Because we want to land the drone automatically but we don't really know in which way we have to do to decrease the power.
We want to proceed in this way:
-get the current altitude
-create a setpoint (it have to be an altitude or thrust setpoint?) to descend 5cm or 10 (it depends if it is precise) and send it to the drone
-the drone takes action to maintain the desired altitude

Can you help us? Thank you so much for your help!! :)
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: How to change height in height mode

Post by arnaud »

When flying height-hold from the client, the setpoint sent to the Crazyflie is an absolute altitude, in meters.

Very simplified, this is what is happening:
- When in alt-hold, the client generates the current height setpoint in meters. If the 'thrust' axis of the gamepad is moved, the heigth setpoint is increased or decreased accordingly.
- The client send a 'Z-Distance' setpoint packet to the Crazyflie, containing the height setpoint and roll/pitch/yaw setpoints.
- The Crazyflie receives the packet and fills up the setpoint structure with the Z absolute setpoint.
- The Crazyflie controller enables the position controller for Z, it compares the current Z position estimate and the Z setpoint and generates a thrust setpoint to make the Z estimate and Z setpoint closer.

So, the thrust setpoint is generated in the Crazyflie following a Z position setpoint sent from the ground. The easiest and most effective for you would be to send an absolute height setpoint and to not worry about the actual thrust: the Crazyflie onboard control loop has already been implemented and tuned for that (it can be improved but this is another subject ;-)).
matthieuleonie
Beginner
Posts: 20
Joined: Mon Nov 13, 2017 11:54 am

Re: How to change height in height mode

Post by matthieuleonie »

Thank you so much for your detailled answer Arnaud! That help us a lot to understand how to control the drone.

We want to do all the things you advise us to do, however we don't really understand how to send the setpoints after having created them...
Can you guide us? :)
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: How to change height in height mode

Post by arnaud »

The easiest is too look at the examples, for example the flow sequence sync is making the Crazyflie take off and land autonomously: https://github.com/bitcraze/crazyflie-l ... nceSync.py.

This example shows how to send setpoint from python. Then the problem is more of a computer science problem: how do you want the landing fonctionality to work and how should it interact with the user. If you 'just' want to run autonomous take-off and landing sequence the flow example is what you need. If you want to land automatically when the user press a button on the gamepad you will need to modify the client code.
matthieuleonie
Beginner
Posts: 20
Joined: Mon Nov 13, 2017 11:54 am

Re: How to change height in height mode

Post by matthieuleonie »

We understood how to write the setpoints but not how run that (we wrote the command in python but we don't know how to send it to the drone).
We want to activate the autonomous landing after having pressed a button on the gamepad. We watched your video on YT about creating a checkbox on the client to enable or disable the motors. I think it will help us to achieve our project.
And once again thank you for your help :)
matthieuleonie
Beginner
Posts: 20
Joined: Mon Nov 13, 2017 11:54 am

Re: How to change height in height mode

Post by matthieuleonie »

Hi,

We have succeed in sending setpoint to the drone as you told us and that worked perfectly. Thank you so much for your help! :)

Now, we would like to plot the altitude during the landing. However, we don't know how to send setpoints and use the plotter at the same time. So can you help us to achieve that please?

We also need to explain how the altitude control loop works (in the Height-mode) because we have to explain it to our teachers. We took a look at https://github.com/bitcraze/crazyflie-f ... abilizer.c can you tell us where is the thrust setpoint defined in the firmware when the Height mode is used?

Thank you :)
kristoffer
Bitcraze
Posts: 630
Joined: Tue Jun 30, 2015 7:47 am

Re: How to change height in height mode

Post by kristoffer »

If you are using the python lib you will have to set up a subscription to the log variable you are interested in with a callback and update your graph from the callback. The other option would be to store the altitude data in an array and plot it when you have disconnected.
You can find an example of how to set up logging in https://github.com/bitcraze/crazyflie-l ... equence.py, in the start_position_printing() method. If you are using the Z-ranger you should subscribe to the 'range.zrange' log variable instead.

The altitude control is handled by controller_pid.c that calls position_controller_pid.c where the actual PID is implemented.
matthieuleonie
Beginner
Posts: 20
Joined: Mon Nov 13, 2017 11:54 am

Re: How to change height in height mode

Post by matthieuleonie »

kristoffer wrote: Fri May 18, 2018 9:13 am If you are using the python lib you will have to set up a subscription to the log variable you are interested in with a callback and update your graph from the callback. The other option would be to store the altitude data in an array and plot it when you have disconnected.
You can find an example of how to set up logging in https://github.com/bitcraze/crazyflie-l ... equence.py, in the start_position_printing() method. If you are using the Z-ranger you should subscribe to the 'range.zrange' log variable instead.
Okay we will try that! :)
kristoffer wrote: Fri May 18, 2018 9:13 am The altitude control is handled by controller_pid.c that calls position_controller_pid.c where the actual PID is implemented.
We have seen this code however we didn't understand how the position.z setpoint affected here https://github.com/bitcraze/crazyflie-f ... ric.c#L135 is translated into a thrust setpoint used controller_pid.c...
Actually we want to find this function:
arnaud wrote: Mon Mar 26, 2018 8:37 am generates a thrust setpoint to make the Z estimate and Z setpoint closer
Your answer will very help us! Thank you so much once again :)
Post Reply