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

[offboard control] allow for direct actuator control #22222

Merged
merged 2 commits into from Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion msg/OffboardControlMode.msg
Expand Up @@ -7,4 +7,5 @@ bool velocity
bool acceleration
bool attitude
bool body_rate
bool actuator
bool thrust_and_torque
bool direct_actuator
Expand Up @@ -48,7 +48,7 @@ void OffboardChecks::checkAndReport(const Context &context, Report &reporter)

bool offboard_available = (offboard_control_mode.position || offboard_control_mode.velocity
|| offboard_control_mode.acceleration || offboard_control_mode.attitude || offboard_control_mode.body_rate
|| offboard_control_mode.actuator) && data_is_recent;
|| offboard_control_mode.thrust_and_torque || offboard_control_mode.direct_actuator) && data_is_recent;

if (offboard_control_mode.position && reporter.failsafeFlags().local_position_invalid) {
offboard_available = false;
Expand Down
24 changes: 19 additions & 5 deletions src/modules/commander/ModeUtil/control_mode.cpp
Expand Up @@ -46,19 +46,20 @@ void getVehicleControlMode(uint8_t nav_state, uint8_t vehicle_type,
const offboard_control_mode_s &offboard_control_mode,
vehicle_control_mode_s &vehicle_control_mode)
{
vehicle_control_mode.flag_control_allocation_enabled = true; // Always enabled by default

switch (nav_state) {
case vehicle_status_s::NAVIGATION_STATE_MANUAL:
vehicle_control_mode.flag_control_manual_enabled = true;
vehicle_control_mode.flag_control_rates_enabled = stabilization_required(vehicle_type);
vehicle_control_mode.flag_control_attitude_enabled = stabilization_required(vehicle_type);
vehicle_control_mode.flag_control_allocation_enabled = true;
break;

case vehicle_status_s::NAVIGATION_STATE_STAB:
vehicle_control_mode.flag_control_manual_enabled = true;
vehicle_control_mode.flag_control_rates_enabled = true;
vehicle_control_mode.flag_control_attitude_enabled = true;
vehicle_control_mode.flag_control_allocation_enabled = true;
break;

case vehicle_status_s::NAVIGATION_STATE_ALTCTL:
Expand All @@ -67,6 +68,7 @@ void getVehicleControlMode(uint8_t nav_state, uint8_t vehicle_type,
vehicle_control_mode.flag_control_attitude_enabled = true;
vehicle_control_mode.flag_control_altitude_enabled = true;
vehicle_control_mode.flag_control_climb_rate_enabled = true;
vehicle_control_mode.flag_control_allocation_enabled = true;
break;

case vehicle_status_s::NAVIGATION_STATE_POSCTL:
Expand All @@ -77,6 +79,7 @@ void getVehicleControlMode(uint8_t nav_state, uint8_t vehicle_type,
vehicle_control_mode.flag_control_climb_rate_enabled = true;
vehicle_control_mode.flag_control_position_enabled = true;
vehicle_control_mode.flag_control_velocity_enabled = true;
vehicle_control_mode.flag_control_allocation_enabled = true;
break;

case vehicle_status_s::NAVIGATION_STATE_AUTO_RTL:
Expand All @@ -93,18 +96,21 @@ void getVehicleControlMode(uint8_t nav_state, uint8_t vehicle_type,
vehicle_control_mode.flag_control_climb_rate_enabled = true;
vehicle_control_mode.flag_control_position_enabled = true;
vehicle_control_mode.flag_control_velocity_enabled = true;
vehicle_control_mode.flag_control_allocation_enabled = true;
break;

case vehicle_status_s::NAVIGATION_STATE_ACRO:
vehicle_control_mode.flag_control_manual_enabled = true;
vehicle_control_mode.flag_control_rates_enabled = true;
vehicle_control_mode.flag_control_allocation_enabled = true;
break;

case vehicle_status_s::NAVIGATION_STATE_DESCEND:
vehicle_control_mode.flag_control_auto_enabled = true;
vehicle_control_mode.flag_control_rates_enabled = true;
vehicle_control_mode.flag_control_attitude_enabled = true;
vehicle_control_mode.flag_control_climb_rate_enabled = true;
vehicle_control_mode.flag_control_allocation_enabled = true;
break;

case vehicle_status_s::NAVIGATION_STATE_TERMINATION:
Expand All @@ -121,28 +127,36 @@ void getVehicleControlMode(uint8_t nav_state, uint8_t vehicle_type,
vehicle_control_mode.flag_control_altitude_enabled = true;
vehicle_control_mode.flag_control_climb_rate_enabled = true;
vehicle_control_mode.flag_control_acceleration_enabled = true;
vehicle_control_mode.flag_control_rates_enabled = true;
vehicle_control_mode.flag_control_attitude_enabled = true;
vehicle_control_mode.flag_control_rates_enabled = true;
vehicle_control_mode.flag_control_allocation_enabled = true;

} else if (offboard_control_mode.velocity) {
vehicle_control_mode.flag_control_velocity_enabled = true;
vehicle_control_mode.flag_control_altitude_enabled = true;
vehicle_control_mode.flag_control_climb_rate_enabled = true;
vehicle_control_mode.flag_control_acceleration_enabled = true;
vehicle_control_mode.flag_control_rates_enabled = true;
vehicle_control_mode.flag_control_attitude_enabled = true;
vehicle_control_mode.flag_control_rates_enabled = true;
vehicle_control_mode.flag_control_allocation_enabled = true;

} else if (offboard_control_mode.acceleration) {
vehicle_control_mode.flag_control_acceleration_enabled = true;
vehicle_control_mode.flag_control_rates_enabled = true;
vehicle_control_mode.flag_control_attitude_enabled = true;
vehicle_control_mode.flag_control_rates_enabled = true;
vehicle_control_mode.flag_control_allocation_enabled = true;

} else if (offboard_control_mode.attitude) {
vehicle_control_mode.flag_control_rates_enabled = true;
vehicle_control_mode.flag_control_attitude_enabled = true;
vehicle_control_mode.flag_control_rates_enabled = true;
vehicle_control_mode.flag_control_allocation_enabled = true;

} else if (offboard_control_mode.body_rate) {
vehicle_control_mode.flag_control_rates_enabled = true;
vehicle_control_mode.flag_control_allocation_enabled = true;

} else if (offboard_control_mode.thrust_and_torque) {
vehicle_control_mode.flag_control_allocation_enabled = true;
}

break;
Expand Down
12 changes: 12 additions & 0 deletions src/modules/uxrce_dds_client/dds_topics.yaml
Expand Up @@ -136,5 +136,17 @@ subscriptions:
- topic: /fmu/in/vehicle_trajectory_waypoint
type: px4_msgs::msg::VehicleTrajectoryWaypoint

- topic: /fmu/in/vehicle_thrust_setpoint
type: px4_msgs::msg::VehicleThrustSetpoint

- topic: /fmu/in/vehicle_torque_setpoint
type: px4_msgs::msg::VehicleTorqueSetpoint

- topic: /fmu/in/actuator_motors
type: px4_msgs::msg::ActuatorMotors

- topic: /fmu/in/actuator_servos
type: px4_msgs::msg::ActuatorServos

# Create uORB::PublicationMulti
subscriptions_multi: