55 ModuleParams(nullptr),
56 WorkItem(MODULE_NAME,
px4::wq_configurations::att_pos_ctrl),
59 _vehicle_status.vehicle_type = vehicle_status_s::VEHICLE_TYPE_ROTARY_WING;
77 PX4_ERR(
"vehicle_attitude callback registration failed!");
93 radians(_param_mc_yawrate_max.get())));
108 int32_t vt_type = -1;
127 switch (_param_mpc_thr_curve.get()) {
129 return throttle_min + throttle_stick_input * (_param_mpc_thr_max.get() - throttle_min);
132 if (throttle_stick_input < 0.5
f) {
133 return (_param_mpc_thr_hover.get() - throttle_min) / 0.5
f * throttle_stick_input +
137 return (_param_mpc_thr_max.get() - _param_mpc_thr_hover.get()) / 0.5
f * (throttle_stick_input - 1.0
f) +
138 _param_mpc_thr_max.get();
155 const float yaw_rate =
math::radians(_param_mpc_man_y_max.get());
175 float v_norm = v.
norm();
182 Eulerf euler_sp = q_sp_rpy;
183 attitude_setpoint.roll_body = euler_sp(0);
184 attitude_setpoint.pitch_body = euler_sp(1);
189 attitude_setpoint.yaw_body =
_man_yaw_sp + euler_sp(2);
207 float yaw_error =
wrap_pi(attitude_setpoint.yaw_body - yaw);
212 Dcmf R_sp_roll_pitch =
Eulerf(attitude_setpoint.roll_body, attitude_setpoint.pitch_body, 0.0f);
213 Vector3f z_roll_pitch_sp = R_sp_roll_pitch * zB;
219 z_roll_pitch_sp = R_yaw_correction * z_roll_pitch_sp;
224 attitude_setpoint.roll_body = -asinf(z_roll_pitch_sp(1));
225 attitude_setpoint.pitch_body = atan2f(z_roll_pitch_sp(0), z_roll_pitch_sp(2));
229 Quatf q_sp =
Eulerf(attitude_setpoint.roll_body, attitude_setpoint.pitch_body, attitude_setpoint.yaw_body);
230 q_sp.
copyTo(attitude_setpoint.q_d);
231 attitude_setpoint.q_d_valid =
true;
261 v_rates_sp.thrust_body[0] =
_v_att_sp.thrust_body[0];
262 v_rates_sp.thrust_body[1] =
_v_att_sp.thrust_body[1];
263 v_rates_sp.thrust_body[2] =
_v_att_sp.thrust_body[2];
291 const uint8_t prev_quat_reset_counter =
_v_att.quat_reset_counter;
296 if (prev_quat_reset_counter !=
_v_att.quat_reset_counter) {
322 bool attitude_setpoint_generated =
false;
324 const bool is_hovering =
_vehicle_status.vehicle_type == vehicle_status_s::VEHICLE_TYPE_ROTARY_WING
328 const bool is_tailsitter_transition =
_vehicle_status.in_transition_mode && _is_tailsitter;
330 bool run_att_ctrl =
_v_control_mode.flag_control_attitude_enabled && (is_hovering || is_tailsitter_transition);
340 attitude_setpoint_generated =
true;
371 _object.store(instance);
372 _task_id = task_id_is_work_queue;
374 if (instance->
init()) {
379 PX4_ERR(
"alloc failed");
383 _object.store(
nullptr);
406 PX4_WARN(
"%s\n", reason);
409 PRINT_MODULE_DESCRIPTION(
412 This implements the multicopter attitude controller. It takes attitude 413 setpoints (`vehicle_attitude_setpoint`) as inputs and outputs a rate setpoint. 415 The controller has a P loop for angular error 417 Publication documenting the implemented Quaternion Attitude Control: 418 Nonlinear Quadrocopter Attitude Control (2013) 419 by Dario Brescianini, Markus Hehn and Raffaello D'Andrea 420 Institute for Dynamic Systems and Control (IDSC), ETH Zurich 422 https://www.research-collection.ethz.ch/bitstream/handle/20.500.11850/154099/eth-7387-01.pdf 426 PRINT_MODULE_USAGE_NAME("mc_att_control",
"controller");
427 PRINT_MODULE_USAGE_COMMAND(
"start");
428 PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
constexpr _Tp constrain(_Tp val, _Tp min_val, _Tp max_val)
float _man_tilt_max
maximum tilt allowed for manual flight [rad]
uORB::Subscription _v_att_sp_sub
vehicle attitude setpoint subscription
measure the time elapsed performing an event
bool update(void *dst)
Copy the struct if updated.
__EXPORT int param_get(param_t param, void *val)
Copy the value of a parameter.
void publish_rates_setpoint()
matrix::Vector3f update(matrix::Quatf q, matrix::Quatf qd, float yawspeed_feedforward)
Run one control loop cycle calculation.
int main(int argc, char **argv)
orb_advert_t _vehicle_attitude_setpoint_pub
uORB::Subscription _vehicle_land_detected_sub
vehicle land detected subscription
Limiting / constrain helper functions.
void copyTo(Type dst[M *N]) const
High-resolution timer with callouts and timekeeping.
uORB::Subscription _v_rates_sp_sub
vehicle rates setpoint subscription
uORB::SubscriptionCallbackWorkItem _vehicle_attitude_sub
collection of rather simple mathematical functions that get used over and over again ...
matrix::Vector3f _rates_sp
angular rates setpoint
float throttle_curve(float throttle_stick_input)
int print_status() override
#define ORB_ID(_name)
Generates a pointer to the uORB metadata structure for a given topic.
uORB::Subscription _v_control_mode_sub
vehicle control mode subscription
void parameters_updated()
initialize some vectors/matrices from parameters
bool publish(const T &data)
Publish the struct.
void perf_free(perf_counter_t handle)
Free a counter.
orb_id_t _attitude_sp_id
pointer to correct attitude setpoint uORB metadata structure
constexpr T radians(T degrees)
Vector< float, 6 > f(float t, const Matrix< float, 6, 1 > &, const Matrix< float, 3, 1 > &)
Vector2< float > Vector2f
void generate_attitude_setpoint(float dt, bool reset_yaw_sp)
Generate & publish an attitude setpoint from stick inputs.
void perf_end(perf_counter_t handle)
End a performance event.
void setProportionalGain(const matrix::Vector3f &proportional_gain)
Set proportional attitude control gain.
bool updated()
Check if there is a new update.
__BEGIN_DECLS typedef uint64_t hrt_abstime
Absolute time, in microsecond units.
uORB::Subscription _params_sub
parameter updates subscription
int mc_att_control_main(int argc, char *argv[])
Multicopter attitude control app start / stop handling function.
Type wrap_pi(Type x)
Wrap value in range [-π, π)
__EXPORT param_t param_find(const char *name)
Look up a parameter by name.
MulticopterAttitudeControl()
Vector3< float > Vector3f
Quaternion< float > Quatf
float _man_yaw_sp
current yaw setpoint in manual mode
void perf_print_counter(perf_counter_t handle)
Print one performance counter to stdout.
void setRateLimit(const matrix::Vector3f &rate_limit)
Set hard limit for output rate setpoints.
void unregisterCallback()
AxisAngle< float > AxisAnglef
perf_counter_t _loop_perf
loop duration performance counter
uORB::Publication< vehicle_rates_setpoint_s > _v_rates_sp_pub
rate setpoint publication
bool update(void *dst)
Update the struct.
uORB::Subscription _vehicle_status_sub
vehicle status subscription
static int print_usage(const char *reason=nullptr)
static int task_spawn(int argc, char *argv[])
static int custom_command(int argc, char *argv[])
virtual ~MulticopterAttitudeControl()
AttitudeControl _attitude_control
class for attitude control calculations
uORB::Subscription _manual_control_sp_sub
manual control setpoint subscription
void control_attitude()
Attitude controller.
bool copy(void *dst)
Copy the struct.
void perf_begin(perf_counter_t handle)
Begin a performance event.
vehicle attitude setpoint
__EXPORT hrt_abstime hrt_absolute_time(void)
Get absolute time in [us] (does not wrap).
static int orb_publish_auto(const struct orb_metadata *meta, orb_advert_t *handle, const void *data, int *instance, int priority)
Advertise as the publisher of a topic.
void vehicle_status_poll()