I am trying to make the Crazyflie 2.0 be autonomous such that it can fly up vertically and stay at certain altitude. The following is what I have written to replace the commanderGetSetpoint() in stabiliser task. However, it doesn't work but behaves differently.
The code I wrote is exactly based on the commnderGetSetpoint(). I have assigned all the same variables as what have assigned in the commanderGetSetpoint().
However,
I was trying to let it fly to certain height vertically by setting thrust to 34000 for the first 1600 ticks.
Then, after 1600 ticks, it is expected to stay at that height by setting thrust to 0 and velocity to ((float)32767-32767.f)/32767.f, however, in this case, it falls directly and seems like it doesn't go into alt hold mode. . While it is falling, the four propellers are still spinning.
Could anyone help me solve it? I am not sure if I miss anything important e.g. sensors, wrong value setting? Thank you very much.
Code: Select all
void exampleGetSetpoint(setpoint_t *setpoint, const state_t * state)
{
static int counter = 0;
int ticks;
ticks = xTaskGetTickCount();
static int initial;
if (counter == 0) {
initial = ticks;
}
setpoint->mode.x = modeDisable;
setpoint->mode.y = modeDisable;
setpoint->mode.roll = modeAbs;
setpoint->attitudeRate.roll = 0;
setpoint->attitude.roll = 0;
setpoint->mode.pitch = modeAbs;
setpoint->attitudeRate.pitch = 0;
setpoint->attitude.pitch = 0;
setpoint->velocity.x = 0;
setpoint->velocity.y = 0;
setpoint->attitudeRate.yaw = 0;
setpoint->mode.yaw = modeVelocity;
if (counter == 0) {
setpoint->thrust = 0;
setpoint->mode.z = modeDisable;
}
else if (ticks < (1600+initial)) {
setpoint->thrust = 34000;
setpoint->mode.z = modeDisable;
setpoint->attitude.roll = 1;
setpoint->attitude.pitch = 1;
}
else if ((ticks >= (1600+initial)) && (ticks<(6000+initial))) {
setpoint->thrust = 0;
setpoint->mode.z = modeVelocity;
setpoint->velocity.z = ((float)32767-32767.f)/32767.f;
}
else {
setpoint->thrust = 0;
setpoint->mode.z = modeDisable;
}
counter ++;
}