mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-01 10:21:36 +08:00
Fixed code style for multirotor_att_control app
This commit is contained in:
@@ -171,6 +171,7 @@ mc_thread_main(int argc, char *argv[])
|
|||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
/* poll error, count it in perf */
|
/* poll error, count it in perf */
|
||||||
perf_count(mc_err_perf);
|
perf_count(mc_err_perf);
|
||||||
|
|
||||||
} else if (ret == 0) {
|
} else if (ret == 0) {
|
||||||
/* no return value, ignore */
|
/* no return value, ignore */
|
||||||
} else {
|
} else {
|
||||||
@@ -193,9 +194,11 @@ mc_thread_main(int argc, char *argv[])
|
|||||||
/* get a local copy of system state */
|
/* get a local copy of system state */
|
||||||
bool updated;
|
bool updated;
|
||||||
orb_check(state_sub, &updated);
|
orb_check(state_sub, &updated);
|
||||||
|
|
||||||
if (updated) {
|
if (updated) {
|
||||||
orb_copy(ORB_ID(vehicle_status), state_sub, &state);
|
orb_copy(ORB_ID(vehicle_status), state_sub, &state);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get a local copy of manual setpoint */
|
/* get a local copy of manual setpoint */
|
||||||
orb_copy(ORB_ID(manual_control_setpoint), manual_sub, &manual);
|
orb_copy(ORB_ID(manual_control_setpoint), manual_sub, &manual);
|
||||||
/* get a local copy of attitude */
|
/* get a local copy of attitude */
|
||||||
@@ -204,9 +207,11 @@ mc_thread_main(int argc, char *argv[])
|
|||||||
orb_copy(ORB_ID(vehicle_attitude_setpoint), att_setpoint_sub, &att_sp);
|
orb_copy(ORB_ID(vehicle_attitude_setpoint), att_setpoint_sub, &att_sp);
|
||||||
/* get a local copy of rates setpoint */
|
/* get a local copy of rates setpoint */
|
||||||
orb_check(setpoint_sub, &updated);
|
orb_check(setpoint_sub, &updated);
|
||||||
|
|
||||||
if (updated) {
|
if (updated) {
|
||||||
orb_copy(ORB_ID(offboard_control_setpoint), setpoint_sub, &offboard_sp);
|
orb_copy(ORB_ID(offboard_control_setpoint), setpoint_sub, &offboard_sp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get a local copy of the current sensor values */
|
/* get a local copy of the current sensor values */
|
||||||
orb_copy(ORB_ID(sensor_combined), sensor_sub, &raw);
|
orb_copy(ORB_ID(sensor_combined), sensor_sub, &raw);
|
||||||
|
|
||||||
@@ -222,6 +227,7 @@ mc_thread_main(int argc, char *argv[])
|
|||||||
// printf("thrust_rate=%8.4f\n",offboard_sp.p4);
|
// printf("thrust_rate=%8.4f\n",offboard_sp.p4);
|
||||||
rates_sp.timestamp = hrt_absolute_time();
|
rates_sp.timestamp = hrt_absolute_time();
|
||||||
orb_publish(ORB_ID(vehicle_rates_setpoint), rates_sp_pub, &rates_sp);
|
orb_publish(ORB_ID(vehicle_rates_setpoint), rates_sp_pub, &rates_sp);
|
||||||
|
|
||||||
} else if (offboard_sp.mode == OFFBOARD_CONTROL_MODE_DIRECT_ATTITUDE) {
|
} else if (offboard_sp.mode == OFFBOARD_CONTROL_MODE_DIRECT_ATTITUDE) {
|
||||||
att_sp.roll_body = offboard_sp.p1;
|
att_sp.roll_body = offboard_sp.p1;
|
||||||
att_sp.pitch_body = offboard_sp.p2;
|
att_sp.pitch_body = offboard_sp.p2;
|
||||||
@@ -264,6 +270,7 @@ mc_thread_main(int argc, char *argv[])
|
|||||||
*/
|
*/
|
||||||
if (isfinite(manual.throttle) && manual.throttle > 0.2f) {
|
if (isfinite(manual.throttle) && manual.throttle > 0.2f) {
|
||||||
att_sp.thrust = failsafe_throttle;
|
att_sp.thrust = failsafe_throttle;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
att_sp.thrust = 0.0f;
|
att_sp.thrust = 0.0f;
|
||||||
}
|
}
|
||||||
@@ -295,6 +302,7 @@ mc_thread_main(int argc, char *argv[])
|
|||||||
if (state.manual_sas_mode == VEHICLE_MANUAL_SAS_MODE_ROLL_PITCH_ABS_YAW_RATE) {
|
if (state.manual_sas_mode == VEHICLE_MANUAL_SAS_MODE_ROLL_PITCH_ABS_YAW_RATE) {
|
||||||
rates_sp.yaw = manual.yaw;
|
rates_sp.yaw = manual.yaw;
|
||||||
control_yaw_position = false;
|
control_yaw_position = false;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
* This mode SHOULD be the default mode, which is:
|
* This mode SHOULD be the default mode, which is:
|
||||||
@@ -309,11 +317,13 @@ mc_thread_main(int argc, char *argv[])
|
|||||||
rates_sp.yaw = manual.yaw;
|
rates_sp.yaw = manual.yaw;
|
||||||
control_yaw_position = false;
|
control_yaw_position = false;
|
||||||
first_time_after_yaw_speed_control = true;
|
first_time_after_yaw_speed_control = true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (first_time_after_yaw_speed_control) {
|
if (first_time_after_yaw_speed_control) {
|
||||||
att_sp.yaw_body = att.yaw;
|
att_sp.yaw_body = att.yaw;
|
||||||
first_time_after_yaw_speed_control = false;
|
first_time_after_yaw_speed_control = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
control_yaw_position = true;
|
control_yaw_position = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -367,6 +377,7 @@ mc_thread_main(int argc, char *argv[])
|
|||||||
/* get current rate setpoint */
|
/* get current rate setpoint */
|
||||||
bool rates_sp_valid = false;
|
bool rates_sp_valid = false;
|
||||||
orb_check(rates_sp_sub, &rates_sp_valid);
|
orb_check(rates_sp_sub, &rates_sp_valid);
|
||||||
|
|
||||||
if (rates_sp_valid) {
|
if (rates_sp_valid) {
|
||||||
orb_copy(ORB_ID(vehicle_rates_setpoint), rates_sp_sub, &rates_sp);
|
orb_copy(ORB_ID(vehicle_rates_setpoint), rates_sp_sub, &rates_sp);
|
||||||
}
|
}
|
||||||
@@ -394,6 +405,7 @@ mc_thread_main(int argc, char *argv[])
|
|||||||
/* kill all outputs */
|
/* kill all outputs */
|
||||||
for (unsigned i = 0; i < NUM_ACTUATOR_CONTROLS; i++)
|
for (unsigned i = 0; i < NUM_ACTUATOR_CONTROLS; i++)
|
||||||
actuators.control[i] = 0.0f;
|
actuators.control[i] = 0.0f;
|
||||||
|
|
||||||
orb_publish(ORB_ID_VEHICLE_ATTITUDE_CONTROLS, actuator_pub, &actuators);
|
orb_publish(ORB_ID_VEHICLE_ATTITUDE_CONTROLS, actuator_pub, &actuators);
|
||||||
|
|
||||||
|
|
||||||
@@ -415,6 +427,7 @@ usage(const char *reason)
|
|||||||
{
|
{
|
||||||
if (reason)
|
if (reason)
|
||||||
fprintf(stderr, "%s\n", reason);
|
fprintf(stderr, "%s\n", reason);
|
||||||
|
|
||||||
fprintf(stderr, "usage: multirotor_att_control [-m <mode>] [-t] {start|status|stop}\n");
|
fprintf(stderr, "usage: multirotor_att_control [-m <mode>] [-t] {start|status|stop}\n");
|
||||||
fprintf(stderr, " <mode> is 'rates' or 'attitude'\n");
|
fprintf(stderr, " <mode> is 'rates' or 'attitude'\n");
|
||||||
fprintf(stderr, " -t enables motor test mode with 10%% thrust\n");
|
fprintf(stderr, " -t enables motor test mode with 10%% thrust\n");
|
||||||
@@ -432,15 +445,18 @@ int multirotor_att_control_main(int argc, char *argv[])
|
|||||||
motor_test_mode = true;
|
motor_test_mode = true;
|
||||||
optioncount += 1;
|
optioncount += 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ':':
|
case ':':
|
||||||
usage("missing parameter");
|
usage("missing parameter");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "option: -%c\n", ch);
|
fprintf(stderr, "option: -%c\n", ch);
|
||||||
usage("unrecognized option");
|
usage("unrecognized option");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
argc -= optioncount;
|
argc -= optioncount;
|
||||||
//argv += optioncount;
|
//argv += optioncount;
|
||||||
|
|
||||||
|
|||||||
@@ -165,9 +165,11 @@ void multirotor_control_attitude(const struct vehicle_attitude_setpoint_s *att_s
|
|||||||
float deltaT = (hrt_absolute_time() - last_run) / 1000000.0f;
|
float deltaT = (hrt_absolute_time() - last_run) / 1000000.0f;
|
||||||
float dT_input = (hrt_absolute_time() - last_input) / 1000000.0f;
|
float dT_input = (hrt_absolute_time() - last_input) / 1000000.0f;
|
||||||
last_run = hrt_absolute_time();
|
last_run = hrt_absolute_time();
|
||||||
|
|
||||||
if (last_input != att_sp->timestamp) {
|
if (last_input != att_sp->timestamp) {
|
||||||
last_input = att_sp->timestamp;
|
last_input = att_sp->timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sensor_delay;
|
static int sensor_delay;
|
||||||
sensor_delay = hrt_absolute_time() - att->timestamp;
|
sensor_delay = hrt_absolute_time() - att->timestamp;
|
||||||
|
|
||||||
@@ -233,12 +235,14 @@ void multirotor_control_attitude(const struct vehicle_attitude_setpoint_s *att_s
|
|||||||
|
|
||||||
if (yaw_error > M_PI_F) {
|
if (yaw_error > M_PI_F) {
|
||||||
yaw_error -= M_TWOPI_F;
|
yaw_error -= M_TWOPI_F;
|
||||||
|
|
||||||
} else if (yaw_error < -M_PI_F) {
|
} else if (yaw_error < -M_PI_F) {
|
||||||
yaw_error += M_TWOPI_F;
|
yaw_error += M_TWOPI_F;
|
||||||
}
|
}
|
||||||
|
|
||||||
rates_sp->yaw = p.yaw_p * (yaw_error) - (p.yaw_d * att->yawspeed);
|
rates_sp->yaw = p.yaw_p * (yaw_error) - (p.yaw_d * att->yawspeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
rates_sp->thrust = att_sp->thrust;
|
rates_sp->thrust = att_sp->thrust;
|
||||||
|
|
||||||
motor_skip_counter++;
|
motor_skip_counter++;
|
||||||
|
|||||||
@@ -157,6 +157,7 @@ void multirotor_control_rates(const struct vehicle_rates_setpoint_s *rate_sp,
|
|||||||
static uint64_t last_input = 0;
|
static uint64_t last_input = 0;
|
||||||
|
|
||||||
float dT_input = (hrt_absolute_time() - last_input) / 1000000.0f;
|
float dT_input = (hrt_absolute_time() - last_input) / 1000000.0f;
|
||||||
|
|
||||||
if (last_input != rate_sp->timestamp) {
|
if (last_input != rate_sp->timestamp) {
|
||||||
last_input = rate_sp->timestamp;
|
last_input = rate_sp->timestamp;
|
||||||
}
|
}
|
||||||
@@ -189,9 +190,11 @@ void multirotor_control_rates(const struct vehicle_rates_setpoint_s *rate_sp,
|
|||||||
|
|
||||||
/* control pitch (forward) output */
|
/* control pitch (forward) output */
|
||||||
float pitch_control = p.attrate_p * (rate_sp->pitch - rates[1]) - (p.attrate_d * pitch_control_last);
|
float pitch_control = p.attrate_p * (rate_sp->pitch - rates[1]) - (p.attrate_d * pitch_control_last);
|
||||||
|
|
||||||
/* increase resilience to faulty control inputs */
|
/* increase resilience to faulty control inputs */
|
||||||
if (isfinite(pitch_control)) {
|
if (isfinite(pitch_control)) {
|
||||||
pitch_control_last = pitch_control;
|
pitch_control_last = pitch_control;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
pitch_control = 0.0f;
|
pitch_control = 0.0f;
|
||||||
warnx("rej. NaN ctrl pitch");
|
warnx("rej. NaN ctrl pitch");
|
||||||
@@ -199,9 +202,11 @@ void multirotor_control_rates(const struct vehicle_rates_setpoint_s *rate_sp,
|
|||||||
|
|
||||||
/* control roll (left/right) output */
|
/* control roll (left/right) output */
|
||||||
float roll_control = p.attrate_p * (rate_sp->roll - rates[0]) - (p.attrate_d * roll_control_last);
|
float roll_control = p.attrate_p * (rate_sp->roll - rates[0]) - (p.attrate_d * roll_control_last);
|
||||||
|
|
||||||
/* increase resilience to faulty control inputs */
|
/* increase resilience to faulty control inputs */
|
||||||
if (isfinite(roll_control)) {
|
if (isfinite(roll_control)) {
|
||||||
roll_control_last = roll_control;
|
roll_control_last = roll_control;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
roll_control = 0.0f;
|
roll_control = 0.0f;
|
||||||
warnx("rej. NaN ctrl roll");
|
warnx("rej. NaN ctrl roll");
|
||||||
@@ -209,6 +214,7 @@ void multirotor_control_rates(const struct vehicle_rates_setpoint_s *rate_sp,
|
|||||||
|
|
||||||
/* control yaw rate */
|
/* control yaw rate */
|
||||||
float yaw_rate_control = p.yawrate_p * (rate_sp->yaw - rates[2]);
|
float yaw_rate_control = p.yawrate_p * (rate_sp->yaw - rates[2]);
|
||||||
|
|
||||||
/* increase resilience to faulty control inputs */
|
/* increase resilience to faulty control inputs */
|
||||||
if (!isfinite(yaw_rate_control)) {
|
if (!isfinite(yaw_rate_control)) {
|
||||||
yaw_rate_control = 0.0f;
|
yaw_rate_control = 0.0f;
|
||||||
|
|||||||
Reference in New Issue
Block a user