Altitude hold design
Posted: Fri May 27, 2016 11:41 am
Hello,
I'm looking at adding an ultrasound sensor to the crazyflie to determine the height of the copter and enhancing the firmware to make use of this and hold an exact altitude. I want to get the copter to a specific height, then enable a "keep this altitude" functionality, and then let go of the thrust and just move the copter around with roll,pitch,yaw.
Using the prototyping board, I've succeeded in adding a sonar and using the Deck API I got the firmware to get sonar data and log it with the logging API.
Now I'm looking at the code to have the copter use that altitude information but I'm a bit confused on several things:
It seems there is already code for this, named "althold" that uses the barometer data. Enabling it however doesn't seem to work. When I enable it the copter will just slowly got to the ground and stop (I'm flying it indoors). Is this expected?
I see the position_controller is there to calculate attitude/thrust to approach a given 3d point. I can use that to set a z coordinate. But what is the "thrustBase" for?
To keep an altitude, I would expect that the mode is "modeAbs" with the "setpoint->position.z" set from when the "althold" mode is enabled. However, the mode is set to "modeVelocity":
Why is the velocity only set? Why is the "rawThrust" normalised like this?
Which brings me to my next question, what is exactly "modeVelocity" ?
And what does it mean in the context of the "setpoint_t" struct: what is the difference between setting a mode for x,y,z and for roll,pitch,yaw?
Thanks for your help, and sorry if I missed something obvious.
Perhaps I misunderstood what "althold" is.
What I'm going to do is modify the code to set the state position.z from the sonar directly and then set the setpoint position.z (and mode.z to modeAbs) and believe the position_controller should it's magic to keep the copter at the same height. Is this the correct approach?
Do you have any suggestion how to do this from the Deck API?
Thanks again.
I'm looking at adding an ultrasound sensor to the crazyflie to determine the height of the copter and enhancing the firmware to make use of this and hold an exact altitude. I want to get the copter to a specific height, then enable a "keep this altitude" functionality, and then let go of the thrust and just move the copter around with roll,pitch,yaw.
Using the prototyping board, I've succeeded in adding a sonar and using the Deck API I got the firmware to get sonar data and log it with the logging API.
Now I'm looking at the code to have the copter use that altitude information but I'm a bit confused on several things:
It seems there is already code for this, named "althold" that uses the barometer data. Enabling it however doesn't seem to work. When I enable it the copter will just slowly got to the ground and stop (I'm flying it indoors). Is this expected?
I see the position_controller is there to calculate attitude/thrust to approach a given 3d point. I can use that to set a z coordinate. But what is the "thrustBase" for?
Code: Select all
float newThrust = runPid(state->position.z, &this.pidZ, setpoint->mode.z, setpoint->position.z, setpoint->velocity.z, DT);
*thrust = newThrust + this.thrustBase;
Code: Select all
if (altHoldMode) {
setpoint->thrust = 0;
setpoint->mode.z = modeVelocity;
setpoint->velocity.z = ((float) rawThrust - 32767.f) / 32767.f;
}
Which brings me to my next question, what is exactly "modeVelocity" ?
And what does it mean in the context of the "setpoint_t" struct: what is the difference between setting a mode for x,y,z and for roll,pitch,yaw?
Thanks for your help, and sorry if I missed something obvious.
Perhaps I misunderstood what "althold" is.
What I'm going to do is modify the code to set the state position.z from the sonar directly and then set the setpoint position.z (and mode.z to modeAbs) and believe the position_controller should it's magic to keep the copter at the same height. Is this the correct approach?
Do you have any suggestion how to do this from the Deck API?
Thanks again.