forked from Archive/PX4-Autopilot
Various fixes to attitude control, flyable, needs parameter tuning
This commit is contained in:
parent
e4645c0a41
commit
2d631fb005
|
@ -195,7 +195,7 @@ mc_thread_main(int argc, char *argv[])
|
|||
rates_sp.roll = manual.roll;
|
||||
|
||||
rates_sp.pitch = manual.pitch;
|
||||
rates_sp.yaw = manual.yaw;
|
||||
rates_sp.yaw = att.yaw + manual.yaw * 2.0f;
|
||||
rates_sp.thrust = manual.throttle;
|
||||
//printf("rates\n");
|
||||
rates_sp.timestamp = hrt_absolute_time();
|
||||
|
|
|
@ -235,20 +235,21 @@ void multirotor_control_attitude(const struct vehicle_attitude_setpoint_s *att_s
|
|||
// pid_set_parameters(&yaw_speed_controller, p.yawrate_p, p.yawrate_i, p.yawrate_d, p.yawrate_awu);
|
||||
pid_set_parameters(&pitch_controller, p.att_p, p.att_i, p.att_d, p.att_awu);
|
||||
pid_set_parameters(&roll_controller, p.att_p, p.att_i, p.att_d, p.att_awu);
|
||||
printf("delays: %d us sens->ctrl, rate: %d Hz, input: %d Hz\n", sensor_delay, (int)(1.0f/deltaT), (int)(1.0f/dT_input));
|
||||
printf("att ctrl: delays: %d us sens->ctrl, rate: %d Hz, input: %d Hz\n", sensor_delay, (int)(1.0f/deltaT), (int)(1.0f/dT_input));
|
||||
}
|
||||
|
||||
/* calculate current control outputs */
|
||||
|
||||
/* control pitch (forward) output */
|
||||
rates_sp->pitch = pid_calculate(&pitch_controller, att_sp->pitch_body + p.att_xoff,
|
||||
att->pitch, att->pitchspeed, deltaT)*1/10.0f;
|
||||
att->pitch, att->pitchspeed, deltaT);
|
||||
|
||||
/* control roll (left/right) output */
|
||||
rates_sp->roll = pid_calculate(&roll_controller, att_sp->roll_body + p.att_yoff,
|
||||
att->roll, att->rollspeed, deltaT)*1/10.0f;
|
||||
att->roll, att->rollspeed, deltaT);
|
||||
|
||||
/* control yaw rate */
|
||||
//float yaw_rate_control = pid_calculate(&yaw_speed_controller, att_sp->yaw_body, att->yawspeed, 0.0f, deltaT)*1/10.0f;
|
||||
rates_sp->yaw= deltaT * p.yaw_p * atan2f(sinf(att->yaw - att_sp->yaw_body),cos(att->yaw - att_sp->yaw_body));
|
||||
rates_sp->yaw= deltaT * p.yaw_p * atan2f(sinf(att->yaw - att_sp->yaw_body), cosf(att->yaw - att_sp->yaw_body));
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -153,6 +153,13 @@ void multirotor_control_rates(const struct vehicle_rates_setpoint_s *rate_sp,
|
|||
static float pitch_control_last = 0;
|
||||
static uint64_t last_run = 0;
|
||||
const float deltaT = (hrt_absolute_time() - last_run) / 1000000.0f;
|
||||
static uint64_t last_input = 0;
|
||||
|
||||
float dT_input = (hrt_absolute_time() - last_input) / 1000000.0f;
|
||||
if (last_input != rate_sp->timestamp) {
|
||||
last_input = rate_sp->timestamp;
|
||||
}
|
||||
|
||||
last_run = hrt_absolute_time();
|
||||
|
||||
static int motor_skip_counter = 0;
|
||||
|
@ -173,7 +180,8 @@ void multirotor_control_rates(const struct vehicle_rates_setpoint_s *rate_sp,
|
|||
if (motor_skip_counter % 2500 == 0) {
|
||||
/* update parameters from storage */
|
||||
parameters_update(&h, &p);
|
||||
printf("p.yawrate_p: %8.4f\n", (double)p.yawrate_p);
|
||||
printf("rate ctrl: p.yawrate_p: %8.4f, loop: %d Hz, input: %d Hz\n",
|
||||
(double)p.yawrate_p, (int)(1.0f/deltaT), (int)(1.0f/dT_input));
|
||||
}
|
||||
|
||||
/* calculate current control outputs */
|
||||
|
@ -185,6 +193,7 @@ void multirotor_control_rates(const struct vehicle_rates_setpoint_s *rate_sp,
|
|||
pitch_control_last = pitch_control;
|
||||
} else {
|
||||
pitch_control = 0.0f;
|
||||
printf("rej. NaN ctrl pitch\n");
|
||||
}
|
||||
|
||||
/* control roll (left/right) output */
|
||||
|
@ -194,10 +203,11 @@ void multirotor_control_rates(const struct vehicle_rates_setpoint_s *rate_sp,
|
|||
roll_control_last = roll_control;
|
||||
} else {
|
||||
roll_control = 0.0f;
|
||||
printf("rej. NaN ctrl roll\n");
|
||||
}
|
||||
|
||||
/* control yaw rate */
|
||||
float yaw_rate_control = p.yawrate_p * deltaT * ((rate_sp->yaw)*p.attrate_lim-rates[2]);
|
||||
float yaw_rate_control = p.yawrate_p * deltaT * ((rate_sp->yaw)*p.yawrate_lim-rates[2]);
|
||||
|
||||
actuators->control[0] = roll_control;
|
||||
actuators->control[1] = pitch_control;
|
||||
|
|
Loading…
Reference in New Issue