Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mc_rate_control: publish angular acceleration setpoint #14035

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions msg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ set(msg_files
vehicle_acceleration.msg
vehicle_air_data.msg
vehicle_angular_acceleration.msg
vehicle_angular_acceleration_setpoint.msg
vehicle_angular_velocity.msg
vehicle_attitude.msg
vehicle_attitude_setpoint.msg
Expand Down
2 changes: 2 additions & 0 deletions msg/tools/uorb_rtps_message_ids.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ rtps:
id: 124
- msg: vehicle_angular_acceleration
id: 125
- msg: vehicle_angular_acceleration_setpoint
id: 126
########## multi topics: begin ##########
- msg: actuator_controls_0
id: 150
Expand Down
4 changes: 4 additions & 0 deletions msg/vehicle_angular_acceleration_setpoint.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

uint64 timestamp # time since system start (microseconds)

float32[3] xyz # angular acceleration about X, Y, Z body axis in rad/s^2
4 changes: 4 additions & 0 deletions src/modules/logger/logged_topics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ void LoggedTopics::add_default_topics()
add_topic("fw_virtual_attitude_setpoint");
add_topic("mc_virtual_attitude_setpoint");
add_topic("time_offset");
add_topic("vehicle_angular_acceleration", 10);
add_topic("vehicle_angular_acceleration_setpoint", 10);
add_topic("vehicle_angular_velocity", 10);
add_topic("vehicle_attitude_groundtruth", 10);
add_topic("vehicle_global_position_groundtruth", 100);
Expand All @@ -134,6 +136,8 @@ void LoggedTopics::add_high_rate_topics()
add_topic("manual_control_setpoint");
add_topic("rate_ctrl_status");
add_topic("sensor_combined");
add_topic("vehicle_angular_acceleration");
add_topic("vehicle_angular_acceleration_setpoint");
add_topic("vehicle_angular_velocity");
add_topic("vehicle_attitude");
add_topic("vehicle_attitude_setpoint");
Expand Down
6 changes: 6 additions & 0 deletions src/modules/mc_rate_control/MulticopterRateControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,12 @@ MulticopterRateControl::Run()
// run rate controller
const Vector3f att_control = _rate_control.update(rates, _rates_sp, dt, _maybe_landed || _landed);

// publish angular acceleration setpoint
vehicle_angular_acceleration_setpoint_s v_angular_accel_sp;
_rate_control.getAngularAccelerationSetpoint().copyTo(v_angular_accel_sp.xyz);
v_angular_accel_sp.timestamp = hrt_absolute_time();
_vehicle_angular_acceleration_setpoint_pub.publish(v_angular_accel_sp);

// publish rate controller status
rate_ctrl_status_s rate_ctrl_status{};
_rate_control.getRateControlStatus(rate_ctrl_status);
Expand Down
2 changes: 2 additions & 0 deletions src/modules/mc_rate_control/MulticopterRateControl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include <uORB/topics/multirotor_motor_limits.h>
#include <uORB/topics/parameter_update.h>
#include <uORB/topics/rate_ctrl_status.h>
#include <uORB/topics/vehicle_angular_acceleration_setpoint.h>
#include <uORB/topics/vehicle_angular_velocity.h>
#include <uORB/topics/vehicle_control_mode.h>
#include <uORB/topics/vehicle_land_detected.h>
Expand Down Expand Up @@ -107,6 +108,7 @@ class MulticopterRateControl : public ModuleBase<MulticopterRateControl>, public

uORB::Publication<actuator_controls_s> _actuators_0_pub;
uORB::PublicationMulti<rate_ctrl_status_s> _controller_status_pub{ORB_ID(rate_ctrl_status), ORB_PRIO_DEFAULT}; /**< controller status publication */
uORB::Publication<vehicle_angular_acceleration_setpoint_s> _vehicle_angular_acceleration_setpoint_pub{ORB_ID(vehicle_angular_acceleration_setpoint)};
uORB::Publication<landing_gear_s> _landing_gear_pub{ORB_ID(landing_gear)};
uORB::Publication<vehicle_rates_setpoint_s> _v_rates_sp_pub{ORB_ID(vehicle_rates_setpoint)}; /**< rate setpoint publication */

Expand Down
10 changes: 7 additions & 3 deletions src/modules/mc_rate_control/RateControl/RateControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,13 @@ Vector3f RateControl::update(const Vector3f &rate, const Vector3f &rate_sp, cons
rate_d = (rate_filtered - _rate_prev_filtered) / dt;
}

// PID control with feed forward
const Vector3f torque = _gain_p.emult(rate_error) + _rate_int - _gain_d.emult(rate_d) + _gain_ff.emult(rate_sp);
// P + D control
_angular_accel_sp = _gain_p.emult(rate_error) - _gain_d.emult(rate_d);

// I + FF control
const Vector3f torque_feedforward = _rate_int + _gain_ff.emult(rate_sp);

// save states
_rate_prev = rate;
_rate_prev_filtered = rate_filtered;

Expand All @@ -90,7 +94,7 @@ Vector3f RateControl::update(const Vector3f &rate, const Vector3f &rate_sp, cons
updateIntegral(rate_error, dt);
}

return torque;
return _angular_accel_sp + torque_feedforward;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dagar This does not make sense to me. It seems like we are mixing torque and angular acceleration.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dagar Let's add a comment indicating that we are assuming an identity inertia matrix, then I think it will be more clear.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}

void RateControl::updateIntegral(Vector3f &rate_error, const float dt)
Expand Down
9 changes: 9 additions & 0 deletions src/modules/mc_rate_control/RateControl/RateControl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ class RateControl
matrix::Vector3f update(const matrix::Vector3f &rate, const matrix::Vector3f &rate_sp, const float dt,
const bool landed);

/**
* Get the desired angular acceleration
* @see _angular_accel_sp
*/
const matrix::Vector3f &getAngularAccelerationSetpoint() const { return _angular_accel_sp; };

/**
* Set the integral term to 0 to prevent windup
* @see _rate_int
Expand Down Expand Up @@ -125,4 +131,7 @@ class RateControl
math::LowPassFilter2pVector3f _lp_filters_d{0.f, 0.f}; ///< low-pass filters for D-term (roll, pitch & yaw)
bool _mixer_saturation_positive[3] {};
bool _mixer_saturation_negative[3] {};

// Output
matrix::Vector3f _angular_accel_sp{0.f, 0.f, 0.f}; //< Angular acceleration setpoint computed using P and D gains
};