feat: BlueROV2 Heavy updated control (attitude and position) and model (#25052)

* rft: clean merge to PX4

* fix: formatting

* fix: extra line

* fix: moved submarine out of "is_ground_vehicle", added proper check for center-throttle

* feat: updated gazebo models to include bluerov update

* fix: use 'is_uuv_vehicle', remove FW_MM/LLC from uuv build

* fix: added saturation to thrust and torque messages via param

* doc: updated parameters documentation for uuv

* fix: formatting

* feat: matching hardware reference

* fix: thrusters kg

* rft: removed commented lines

* fix: update gz reference given hw setup

* fix: hardware references

* fix: recommendations

* fix: updated settings to match hardware

* rft: check only for fixed and rotary wing for high throttle

Co-authored-by: Daniel Agar <daniel@agar.ca>

* fix: commit oupsie

* fix: format

* rft: remove is_uuv

* fix: hw parameters, uuv build target for v6x

* feat: added support for D-pad attitude changes in stabilized position control

* fix: position setpoint update and parametrized trajectory age and att change

* fix: format

* fix: removed duplicated call to check_validity_setpoint

* fix: setpoint update on arming logic

* fix: setpoint initialization for stabilized mode

---------

Co-authored-by: Daniel Agar <daniel@agar.ca>
This commit is contained in:
Pedro Roque
2025-07-23 10:29:22 -07:00
committed by GitHub
co-authored by Daniel Agar
parent 09fe34af0e
commit e14eea5615
23 changed files with 2891 additions and 201 deletions
+191 -57
View File
@@ -90,61 +90,172 @@ void UUVPOSControl::parameters_update(bool force)
}
}
void UUVPOSControl::publish_attitude_setpoint(const float thrust_x, const float thrust_y, const float thrust_z,
const float roll_des, const float pitch_des, const float yaw_des)
{
//watch if inputs are not to high
vehicle_attitude_setpoint_s vehicle_attitude_setpoint = {};
vehicle_attitude_setpoint.timestamp = hrt_absolute_time();
const Quatf attitude_setpoint(Eulerf(roll_des, pitch_des, yaw_des));
attitude_setpoint.copyTo(vehicle_attitude_setpoint.q_d);
vehicle_attitude_setpoint.thrust_body[0] = thrust_x;
vehicle_attitude_setpoint.thrust_body[1] = thrust_y;
vehicle_attitude_setpoint.thrust_body[2] = thrust_z;
_att_sp_pub.publish(vehicle_attitude_setpoint);
}
void UUVPOSControl::pose_controller_6dof(const Vector3f &pos_des,
const float roll_des, const float pitch_des, const float yaw_des,
vehicle_attitude_s &vehicle_attitude, vehicle_local_position_s &vlocal_pos)
void UUVPOSControl::pose_controller_6dof(const Vector3f &pos_des, vehicle_attitude_s &vehicle_attitude,
vehicle_local_position_s &vlocal_pos, bool altitude_mode)
{
//get current rotation of vehicle
Quatf q_att(vehicle_attitude.q);
// Assumes target 0 velocity
Vector3f p_control_output = Vector3f(_param_pose_gain_x.get() * (pos_des(0) - vlocal_pos.x) - _param_pose_gain_d_x.get()
* vlocal_pos.vx,
_param_pose_gain_y.get() * (pos_des(1) - vlocal_pos.y) - _param_pose_gain_d_y.get() * vlocal_pos.vy,
_param_pose_gain_z.get() * (pos_des(2) - vlocal_pos.z) - _param_pose_gain_d_z.get() * vlocal_pos.vz);
Vector3f rotated_input = q_att.rotateVectorInverse(p_control_output);//rotate the coord.sys (from global to body)
if (altitude_mode) {
// In altitude mode, we only control the z-axis
p_control_output(0) = 0.0f;
p_control_output(1) = 0.0f;
}
publish_attitude_setpoint(rotated_input(0),
rotated_input(1),
rotated_input(2),
roll_des, pitch_des, yaw_des);
Vector3f rotated_input = q_att.rotateVectorInverse(p_control_output); //rotate the coord.sys (from global to body)
_attitude_setpoint.timestamp = hrt_absolute_time();
_attitude_setpoint.q_d[0] = _trajectory_setpoint.quaternion[0];
_attitude_setpoint.q_d[1] = _trajectory_setpoint.quaternion[1];
_attitude_setpoint.q_d[2] = _trajectory_setpoint.quaternion[2];
_attitude_setpoint.q_d[3] = _trajectory_setpoint.quaternion[3];
_attitude_setpoint.thrust_body[0] = rotated_input(0);
_attitude_setpoint.thrust_body[1] = rotated_input(1);
_attitude_setpoint.thrust_body[2] = rotated_input(2);
}
void UUVPOSControl::stabilization_controller_6dof(const Vector3f &pos_des,
const float roll_des, const float pitch_des, const float yaw_des,
vehicle_attitude_s &vehicle_attitude, vehicle_local_position_s &vlocal_pos)
void UUVPOSControl::check_setpoint_validity(vehicle_local_position_s &vlocal_pos)
{
//get current rotation of vehicle
const float _setpoint_age = (hrt_absolute_time() - _trajectory_setpoint.timestamp) * 1e-6f;
if (_setpoint_age < 0.0f || _setpoint_age > _param_setpoint_max_age.get()) {
reset_trajectory_setpoint(vlocal_pos);
}
if (!PX4_ISFINITE(_trajectory_setpoint.position[0]) ||
!PX4_ISFINITE(_trajectory_setpoint.position[1]) ||
!PX4_ISFINITE(_trajectory_setpoint.position[2]) ||
!PX4_ISFINITE(_trajectory_setpoint.quaternion[0]) ||
!PX4_ISFINITE(_trajectory_setpoint.quaternion[1]) ||
!PX4_ISFINITE(_trajectory_setpoint.quaternion[2]) ||
!PX4_ISFINITE(_trajectory_setpoint.quaternion[3])) {
reset_trajectory_setpoint(vlocal_pos);
}
}
void UUVPOSControl::generate_trajectory_setpoint(vehicle_local_position_s &vlocal_pos,
vehicle_attitude_s &vehicle_attitude,
float dt)
{
float roll = Eulerf(matrix::Quatf(_trajectory_setpoint.quaternion)).phi();
float pitch = Eulerf(matrix::Quatf(_trajectory_setpoint.quaternion)).theta();
float yaw = Eulerf(matrix::Quatf(_trajectory_setpoint.quaternion)).psi();
// Integrate manual control inputs
// Info:
// - throttle is Z, roll is Y, pitch is X
// - if param_stab_mode == 1:
// - roll = 0
// - pitch = 0
// - if param_stab_mode == 0:
// - roll can be updated with D-pad (joystick)
// - pitch can be updated with D-pad (joystick)
float roll_setpoint = roll;
float pitch_setpoint = pitch;
if (_param_stab_mode.get()) {
roll_setpoint = 0.0;
pitch_setpoint = 0.0;
} else {
// Update target roll and pitch setpoint with D-pad
switch (_manual_control_setpoint.buttons) {
case 2048:
pitch_setpoint -= dt * _param_sgm_pitch.get();
break;
case 4096:
pitch_setpoint += dt * _param_sgm_pitch.get();
break;
case 8192:
roll_setpoint -= dt * _param_sgm_roll.get();
break;
case 16384:
roll_setpoint += dt * _param_sgm_roll.get();
break;
default:
break;
}
}
float yaw_setpoint = yaw + _manual_control_setpoint.yaw * dt * _param_sgm_yaw.get();
// Update position setpoints based on manual control inputs
float vx_sp = 0.0;
if (_manual_control_setpoint.pitch > _param_pos_stick_db.get()
|| _manual_control_setpoint.pitch < -_param_pos_stick_db.get()) {
// If pitch is not zero, we use it to set the roll setpoint
vx_sp = _manual_control_setpoint.pitch * _param_pgm_vel.get();
}
float vy_sp = 0.0;
if (_manual_control_setpoint.roll > _param_pos_stick_db.get()
|| _manual_control_setpoint.roll < -_param_pos_stick_db.get()) {
// If roll is not zero, we use it to set the pitch setpoint
vy_sp = _manual_control_setpoint.roll * _param_pgm_vel.get();
}
float vz_sp = 0.0;
if (_manual_control_setpoint.throttle > _param_pos_stick_db.get()
|| _manual_control_setpoint.throttle < -_param_pos_stick_db.get()) {
// If throttle is not zero, we use it to set the vertical velocity
vz_sp = -_manual_control_setpoint.throttle * _param_pgm_vel.get();
}
// rotate velocity setpoint in body frame to global frame
Vector3f velocity_setpoint(vx_sp, vy_sp, vz_sp);
Quatf q_att(vehicle_attitude.q);
Vector3f rotated_velocity_setpoint = q_att.rotateVector(velocity_setpoint);
Vector3f p_control_output = Vector3f(0,
0,
_param_pose_gain_z.get() * (pos_des(2) - vlocal_pos.z));
//potential d controller missing
Vector3f rotated_input = q_att.rotateVectorInverse(p_control_output);//rotate the coord.sys (from global to body)
// Generate target quaternion
Eulerf euler_sp(roll_setpoint, pitch_setpoint, yaw_setpoint);
Quatf q_sp = euler_sp;
publish_attitude_setpoint(rotated_input(0) + pos_des(0), rotated_input(1) + pos_des(1), rotated_input(2),
roll_des, pitch_des, yaw_des);
// Normalize the quaternion to avoid numerical issues
q_sp.normalize();
q_sp.copyTo(_trajectory_setpoint.quaternion);
_trajectory_setpoint.timestamp = hrt_absolute_time();
if (!_param_pos_mode.get()) {
_trajectory_setpoint.position[0] = _trajectory_setpoint.position[0] + vx_sp * dt; // X in world frame
_trajectory_setpoint.position[1] = _trajectory_setpoint.position[1] + vy_sp * dt; // Y in world frame
_trajectory_setpoint.position[2] = _trajectory_setpoint.position[2] + vz_sp * dt; // Z in world frame
} else {
_trajectory_setpoint.position[0] = _trajectory_setpoint.position[0] + rotated_velocity_setpoint(
0) * dt; // X in body frame
_trajectory_setpoint.position[1] = _trajectory_setpoint.position[1] + rotated_velocity_setpoint(
1) * dt; // Y in body frame
_trajectory_setpoint.position[2] = _trajectory_setpoint.position[2] + rotated_velocity_setpoint(
2) * dt; // Z in body frame
}
}
void UUVPOSControl::reset_trajectory_setpoint(vehicle_local_position_s &vlocal_pos)
{
// Reset trajectory setpoint to current position and attitude
_trajectory_setpoint.timestamp = hrt_absolute_time();
_trajectory_setpoint.position[0] = vlocal_pos.x;
_trajectory_setpoint.position[1] = vlocal_pos.y;
_trajectory_setpoint.position[2] = vlocal_pos.z;
_trajectory_setpoint.quaternion[0] = _vehicle_attitude.q[0];
_trajectory_setpoint.quaternion[1] = _vehicle_attitude.q[1];
_trajectory_setpoint.quaternion[2] = _vehicle_attitude.q[2];
_trajectory_setpoint.quaternion[3] = _vehicle_attitude.q[3];
}
void UUVPOSControl::Run()
@@ -160,7 +271,6 @@ void UUVPOSControl::Run()
/* check vehicle control mode for changes to publication state */
_vcontrol_mode_sub.update(&_vcontrol_mode);
/* update parameters from storage */
parameters_update();
@@ -169,34 +279,58 @@ void UUVPOSControl::Run()
/* only run controller if local_pos changed */
if (_vehicle_local_position_sub.update(&vlocal_pos)) {
const float dt = math::constrain(((vlocal_pos.timestamp_sample - _last_run) * 1e-6f), 0.0002f, 0.02f);
_last_run = vlocal_pos.timestamp_sample;
/* Run geometric attitude controllers if NOT manual mode*/
if (!_vcontrol_mode.flag_control_manual_enabled
&& _vcontrol_mode.flag_control_attitude_enabled
&& _vcontrol_mode.flag_control_rates_enabled) {
// Update vehicle attitude
_vehicle_attitude_sub.update(&_vehicle_attitude);
_vehicle_attitude_sub.update(&_vehicle_attitude);//get current vehicle attitude
/* Run position or altitude mode from manual setpoints*/
if (_vcontrol_mode.flag_control_manual_enabled
&& (_vcontrol_mode.flag_control_altitude_enabled
|| _vcontrol_mode.flag_control_position_enabled)
&& _vcontrol_mode.flag_armed) {
/* Update manual setpoints */
const bool altitude_only_flag = _vcontrol_mode.flag_control_altitude_enabled
&& ! _vcontrol_mode.flag_control_position_enabled;
_manual_control_setpoint_sub.update(&_manual_control_setpoint);
// Ensure no nan and sufficiently recent setpoint
check_setpoint_validity(vlocal_pos);
// Generate _trajectory_setpoint -> creates _trajectory_setpoint
generate_trajectory_setpoint(vlocal_pos, _vehicle_attitude, dt);
pose_controller_6dof(Vector3f(_trajectory_setpoint.position), _vehicle_attitude,
vlocal_pos, altitude_only_flag);
} else if (!_vcontrol_mode.flag_control_manual_enabled
&& (_vcontrol_mode.flag_control_altitude_enabled
|| _vcontrol_mode.flag_control_position_enabled)
&& _vcontrol_mode.flag_armed) {
/* Autonomous position mode - no manual inputs are used */
const bool altitude_only_flag = _vcontrol_mode.flag_control_altitude_enabled
&& ! _vcontrol_mode.flag_control_position_enabled;
// get manual control setpoint
_trajectory_setpoint_sub.update(&_trajectory_setpoint);
float roll_des = 0;
float pitch_des = 0;
float yaw_des = _trajectory_setpoint.yaw;
pose_controller_6dof(Vector3f(_trajectory_setpoint.position), _vehicle_attitude,
vlocal_pos, altitude_only_flag);
//stabilization controller(keep pos and hold depth + angle) vs position controller(global + yaw)
if (_param_stabilization.get() == 0) {
pose_controller_6dof(Vector3f(_trajectory_setpoint.position),
roll_des, pitch_des, yaw_des, _vehicle_attitude, vlocal_pos);
} else {
stabilization_controller_6dof(Vector3f(_trajectory_setpoint.position),
roll_des, pitch_des, yaw_des, _vehicle_attitude, vlocal_pos);
}
} else {
// Reset if not in a valid mode (like attitude, rate, manual) to clear setpoint
check_setpoint_validity(vlocal_pos);
}
}
/* Only publish if any of the proper modes are enabled */
if (_vcontrol_mode.flag_control_manual_enabled ||
_vcontrol_mode.flag_control_attitude_enabled) {
if (_vcontrol_mode.flag_control_position_enabled ||
_vcontrol_mode.flag_control_altitude_enabled) {
// Print attitude setpoint
_att_sp_pub.publish(_attitude_setpoint);
}
perf_end(_loop_perf);
+21 -10
View File
@@ -59,8 +59,9 @@
#include <uORB/Subscription.hpp>
#include <uORB/SubscriptionCallback.hpp>
#include <uORB/Publication.hpp>
#include <uORB/topics/manual_control_setpoint.h>
#include <uORB/topics/parameter_update.h>
#include <uORB/topics/trajectory_setpoint.h>
#include <uORB/topics/trajectory_setpoint6dof.h>
#include <uORB/topics/vehicle_attitude.h>
#include <uORB/topics/vehicle_local_position.h>
#include <uORB/topics/vehicle_attitude_setpoint.h>
@@ -101,16 +102,20 @@ private:
uORB::SubscriptionInterval _parameter_update_sub{ORB_ID(parameter_update), 1_s};
uORB::Subscription _vehicle_attitude_sub{ORB_ID(vehicle_attitude)};
uORB::Subscription _trajectory_setpoint_sub{ORB_ID(trajectory_setpoint)};
uORB::Subscription _trajectory_setpoint_sub{ORB_ID(trajectory_setpoint6dof)};
uORB::Subscription _vcontrol_mode_sub{ORB_ID(vehicle_control_mode)};
uORB::Subscription _manual_control_setpoint_sub{ORB_ID(manual_control_setpoint)}; /**< notification of manual control updates */
uORB::SubscriptionCallbackWorkItem _vehicle_local_position_sub{this, ORB_ID(vehicle_local_position)};
vehicle_attitude_s _vehicle_attitude{};
trajectory_setpoint_s _trajectory_setpoint{};
trajectory_setpoint6dof_s _trajectory_setpoint{};
manual_control_setpoint_s _manual_control_setpoint{};
vehicle_control_mode_s _vcontrol_mode{};
vehicle_attitude_setpoint_s _attitude_setpoint{};
perf_counter_t _loop_perf;
hrt_abstime _last_run{0};
DEFINE_PARAMETERS(
(ParamFloat<px4::params::UUV_GAIN_X_P>) _param_pose_gain_x,
@@ -119,10 +124,14 @@ private:
(ParamFloat<px4::params::UUV_GAIN_X_D>) _param_pose_gain_d_x,
(ParamFloat<px4::params::UUV_GAIN_Y_D>) _param_pose_gain_d_y,
(ParamFloat<px4::params::UUV_GAIN_Z_D>) _param_pose_gain_d_z,
(ParamInt<px4::params::UUV_INPUT_MODE>) _param_input_mode,
(ParamInt<px4::params::UUV_STAB_MODE>) _param_stabilization,
(ParamInt<px4::params::UUV_SKIP_CTRL>) _param_skip_ctrl
(ParamInt<px4::params::UUV_STAB_MODE>) _param_stab_mode,
(ParamFloat<px4::params::UUV_POS_STICK_DB>) _param_pos_stick_db,
(ParamFloat<px4::params::UUV_PGM_VEL>) _param_pgm_vel,
(ParamFloat<px4::params::UUV_SGM_ROLL>) _param_sgm_roll,
(ParamFloat<px4::params::UUV_SGM_PITCH>) _param_sgm_pitch,
(ParamFloat<px4::params::UUV_SGM_YAW>) _param_sgm_yaw,
(ParamFloat<px4::params::UUV_SP_MAX_AGE>) _param_setpoint_max_age,
(ParamInt<px4::params::UUV_POS_MODE>) _param_pos_mode
)
void Run() override;
@@ -136,10 +145,12 @@ private:
*/
void publish_attitude_setpoint(const float thrust_x, const float thrust_y, const float thrust_z,
const float roll_des, const float pitch_des, const float yaw_des);
void pose_controller_6dof(const Vector3f &pos_des,
const float roll_des, const float pitch_des, const float yaw_des,
vehicle_attitude_s &vehicle_attitude, vehicle_local_position_s &vlocal_pos);
void pose_controller_6dof(const Vector3f &pos_des, vehicle_attitude_s &vehicle_attitude,
vehicle_local_position_s &vlocal_pos, bool altitude_mode);
void stabilization_controller_6dof(const Vector3f &pos_des,
const float roll_des, const float pitch_des, const float yaw_des,
vehicle_attitude_s &vehicle_attitude, vehicle_local_position_s &vlocal_pos);
void generate_trajectory_setpoint(vehicle_local_position_s &vlocal_pos, vehicle_attitude_s &vehicle_attitude, float dt);
void reset_trajectory_setpoint(vehicle_local_position_s &vlocal_pos);
void check_setpoint_validity(vehicle_local_position_s &vlocal_pos);
};
@@ -90,8 +90,31 @@ PARAM_DEFINE_FLOAT(UUV_GAIN_Z_D, 0.2f);
/**
* Stabilization mode(1) or Position Control(0)
*
* @value 0 Position Control
* @value 1 Stabilization Mode
* @value 0 Tracks previous attitude setpoint
* @value 1 Tracks horizontal attitude (allows yaw change)
* @group UUV Position Control
*/
PARAM_DEFINE_INT32(UUV_STAB_MODE, 1);
/**
* Deadband for changing position setpoint
*
* @group UUV Position Control
*/
PARAM_DEFINE_FLOAT(UUV_POS_STICK_DB, 0.1f);
/**
* Gain for position control velocity setpoint update
*
* @group UUV Position Control
*/
PARAM_DEFINE_FLOAT(UUV_PGM_VEL, 0.5f);
/**
* Stabilization mode(1) or Position Control(0)
*
* @value 0 Moves position setpoint in world frame
* @value 1 Moves position setpoint in body frame
* @group UUV Position Control
*/
PARAM_DEFINE_INT32(UUV_POS_MODE, 1);