mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-25 12:17:35 +08:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 79043dd5c7 | |||
| 9c38602c12 | |||
| fb05dedb7b | |||
| ae65b33ba0 | |||
| 7670989769 |
@@ -54,6 +54,13 @@ if(CONFIG_MODULES_AIRSHIP_ATT_CONTROL)
|
||||
)
|
||||
endif()
|
||||
|
||||
if(CONFIG_MODULES_BOAT_RUDDER)
|
||||
px4_add_romfs_files(
|
||||
rc.boat_rudder_apps
|
||||
rc.boat_rudder_defaults
|
||||
)
|
||||
endif()
|
||||
|
||||
if(CONFIG_MODULES_FW_RATE_CONTROL)
|
||||
px4_add_romfs_files(
|
||||
rc.fw_apps
|
||||
@@ -83,13 +90,6 @@ if(CONFIG_MODULES_ROVER_ACKERMANN)
|
||||
)
|
||||
endif()
|
||||
|
||||
if(CONFIG_MODULES_SPACECRAFT)
|
||||
px4_add_romfs_files(
|
||||
rc.sc_apps
|
||||
rc.sc_defaults
|
||||
)
|
||||
endif()
|
||||
|
||||
if(CONFIG_MODULES_ROVER_MECANUM)
|
||||
px4_add_romfs_files(
|
||||
rc.rover_mecanum_apps
|
||||
@@ -97,6 +97,13 @@ if(CONFIG_MODULES_ROVER_MECANUM)
|
||||
)
|
||||
endif()
|
||||
|
||||
if(CONFIG_MODULES_SPACECRAFT)
|
||||
px4_add_romfs_files(
|
||||
rc.sc_apps
|
||||
rc.sc_defaults
|
||||
)
|
||||
endif()
|
||||
|
||||
if(CONFIG_MODULES_UUV_ATT_CONTROL)
|
||||
px4_add_romfs_files(
|
||||
rc.uuv_apps
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
# Standard apps for a boat rudder.
|
||||
|
||||
# Start boat rudder module.
|
||||
boat_rudder start
|
||||
|
||||
# Start Land Detector.
|
||||
land_detector start rover
|
||||
@@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
# Rudder-steered boats parameters.
|
||||
|
||||
set VEHICLE_TYPE boat
|
||||
param set-default MAV_TYPE 10 # MAV_TYPE_GROUND_ROVER
|
||||
param set-default CA_AIRFRAME 5 # Rover (Ackermann)
|
||||
param set-default CA_R_REV 1 # Motor is assumed to be reversible
|
||||
param set-default EKF2_MAG_TYPE 1 # Make sure magnetometer is fused even when not flying
|
||||
param set-default NAV_ACC_RAD 0.5 # Waypoint acceptance radius
|
||||
param set-default EKF2_GBIAS_INIT 0.01
|
||||
param set-default EKF2_ANGERR_INIT 0.01
|
||||
+9
-9
@@ -176,15 +176,6 @@ set(msg_files
|
||||
RateCtrlStatus.msg
|
||||
RcChannels.msg
|
||||
RcParameterMap.msg
|
||||
RoverAttitudeSetpoint.msg
|
||||
RoverAttitudeStatus.msg
|
||||
RoverPositionSetpoint.msg
|
||||
RoverRateSetpoint.msg
|
||||
RoverRateStatus.msg
|
||||
RoverSpeedSetpoint.msg
|
||||
RoverSpeedStatus.msg
|
||||
RoverSteeringSetpoint.msg
|
||||
RoverThrottleSetpoint.msg
|
||||
Rpm.msg
|
||||
RtlStatus.msg
|
||||
RtlTimeEstimate.msg
|
||||
@@ -208,6 +199,15 @@ set(msg_files
|
||||
SensorsStatusImu.msg
|
||||
SensorUwb.msg
|
||||
SensorAirflow.msg
|
||||
SurfaceVehicleAttitudeSetpoint.msg
|
||||
SurfaceVehicleAttitudeStatus.msg
|
||||
SurfaceVehiclePositionSetpoint.msg
|
||||
SurfaceVehicleRateSetpoint.msg
|
||||
SurfaceVehicleRateStatus.msg
|
||||
SurfaceVehicleSpeedSetpoint.msg
|
||||
SurfaceVehicleSpeedStatus.msg
|
||||
SurfaceVehicleSteeringSetpoint.msg
|
||||
SurfaceVehicleThrottleSetpoint.msg
|
||||
SystemPower.msg
|
||||
TakeoffStatus.msg
|
||||
TaskStackInfo.msg
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Rover Attitude Setpoint
|
||||
# Surface Vehicle Attitude Setpoint
|
||||
|
||||
uint64 timestamp # [us] Time since system start
|
||||
float32 yaw_setpoint # [rad] [@range -inf, inf] [@frame NED] Yaw setpoint
|
||||
@@ -1,5 +1,5 @@
|
||||
# Rover Attitude Status
|
||||
# Surface Vehicle Attitude Status
|
||||
|
||||
uint64 timestamp # [us] Time since system start
|
||||
float32 measured_yaw # [rad] [@range -pi, pi] [@frame NED]Measured yaw
|
||||
float32 measured_yaw # [rad] [@range -pi, pi] [@frame NED] Measured yaw
|
||||
float32 adjusted_yaw_setpoint # [rad] [@range -pi, pi] [@frame NED] Yaw setpoint that is being tracked (Applied slew rates)
|
||||
@@ -1,8 +1,8 @@
|
||||
# Rover Position Setpoint
|
||||
# Surface Vehicle Position Setpoint
|
||||
|
||||
uint64 timestamp # [us] Time since system start
|
||||
float32[2] position_ned # [m] [@range -inf, inf] [@frame NED] Target position
|
||||
float32[2] start_ned # [m] [@range -inf, inf] [@frame NED] [@invalid NaN Defaults to vehicle position] Start position which specifies a line for the rover to track
|
||||
float32 cruising_speed # [m/s] [@range 0, inf] [@invalid NaN Defaults to maximum speed] Cruising speed
|
||||
float32 arrival_speed # [m/s] [@range 0, inf] [@invalid NaN Defaults to 0] Speed the rover should arrive at the target with
|
||||
float32 yaw # [rad] [@range -pi,pi] [@frame NED] [@invalid NaN Defaults to vehicle yaw] Mecanum only: Specify vehicle yaw during travel
|
||||
float32 arrival_speed # [m/s] [@range 0, inf] [@invalid NaN Defaults to 0] Speed the vehicle should arrive at the target with
|
||||
float32 yaw # [rad] [@range -pi,pi] [@frame NED] [@invalid NaN Defaults to vehicle yaw] Omnidirectional only: Specify vehicle yaw during travel
|
||||
@@ -1,4 +1,4 @@
|
||||
# Rover Rate setpoint
|
||||
# Surface Vehicle Rate setpoint
|
||||
|
||||
uint64 timestamp # [us] Time since system start
|
||||
float32 yaw_rate_setpoint # [rad/s] [@range -inf, inf] [@frame NED] Yaw rate setpoint
|
||||
@@ -1,4 +1,4 @@
|
||||
# Rover Rate Status
|
||||
# Surface Vehicle Rate Status
|
||||
|
||||
uint64 timestamp # [us] Time since system start
|
||||
float32 measured_yaw_rate # [rad/s] [@range -inf, inf] [@frame NED] Measured yaw rate
|
||||
@@ -1,5 +1,5 @@
|
||||
# Rover Speed Setpoint
|
||||
# Surface Vehicle Speed Setpoint
|
||||
|
||||
uint64 timestamp # [us] Time since system start
|
||||
float32 speed_body_x # [m/s] [@range -inf (Backwards), inf (Forwards)] [@frame Body] Speed setpoint in body x direction
|
||||
float32 speed_body_y # [m/s] [@range -inf (Left), inf (Right)] [@frame Body] [@invalid NaN If not mecanum] Mecanum only: Speed setpoint in body y direction
|
||||
float32 speed_body_y # [m/s] [@range -inf (Left), inf (Right)] [@frame Body] [@invalid NaN If not omnidirectional] Omnidirectional only: Speed setpoint in body y direction
|
||||
@@ -1,9 +1,9 @@
|
||||
# Rover Velocity Status
|
||||
# Surface Vehicle Velocity Status
|
||||
|
||||
uint64 timestamp # [us] Time since system start
|
||||
float32 measured_speed_body_x # [m/s] [@range -inf (Backwards), inf (Forwards)] [@frame Body] Measured speed in body x direction
|
||||
float32 adjusted_speed_body_x_setpoint # [m/s] [@range -inf (Backwards), inf (Forwards)] [@frame Body] Speed setpoint in body x direction that is being tracked (Applied slew rates)
|
||||
float32 pid_throttle_body_x_integral # [] [@range -1, 1] Integral of the PID for the closed loop controller of the speed in body x direction
|
||||
float32 measured_speed_body_y # [m/s] [@range -inf (Left), inf (Right)] [@frame Body] [@invalid NaN If not mecanum] Mecanum only: Measured speed in body y direction
|
||||
float32 adjusted_speed_body_y_setpoint # [m/s] [@range -inf (Left), inf (Right)] [@frame Body] [@invalid NaN If not mecanum] Mecanum only: Speed setpoint in body y direction that is being tracked (Applied slew rates)
|
||||
float32 pid_throttle_body_y_integral # [] [@range -1, 1] [@invalid NaN If not mecanum] Mecanum only: Integral of the PID for the closed loop controller of the speed in body y direction
|
||||
float32 measured_speed_body_y # [m/s] [@range -inf (Left), inf (Right)] [@frame Body] [@invalid NaN If not omnidirectional] Omnidirectional only: Measured speed in body y direction
|
||||
float32 adjusted_speed_body_y_setpoint # [m/s] [@range -inf (Left), inf (Right)] [@frame Body] [@invalid NaN If not omnidirectional] Omnidirectional only: Speed setpoint in body y direction that is being tracked (Applied slew rates)
|
||||
float32 pid_throttle_body_y_integral # [] [@range -1, 1] [@invalid NaN If not omnidirectional] Omnidirectional only: Integral of the PID for the closed loop controller of the speed in body y direction
|
||||
@@ -1,4 +1,4 @@
|
||||
# Rover Steering setpoint
|
||||
# Surface Vehicle Steering setpoint
|
||||
|
||||
uint64 timestamp # [us] Time since system start
|
||||
float32 normalized_steering_setpoint # [@range -1 (Left), 1 (Right)] [@frame Body] Ackermann: Normalized steering angle, Differential/Mecanum: Normalized speed difference between the left and right wheels
|
||||
float32 normalized_steering_setpoint # [@range -1 (Left), 1 (Right)] [@frame Body] Ackermann: Normalized steering angle, Differential/Omnidirectional: Normalized speed difference between the left and right wheels
|
||||
@@ -1,5 +1,5 @@
|
||||
# Rover Throttle setpoint
|
||||
# Surface Vehicle Throttle setpoint
|
||||
|
||||
uint64 timestamp # [us] Time since system start
|
||||
float32 throttle_body_x # [] [@range -1 (Backwards), 1 (Forwards)] [@frame Body] Throttle setpoint along body X axis
|
||||
float32 throttle_body_y # [] [@range -1 (Left), 1 (Right)] [@frame Body] [@invalid NaN If not mecanum] Mecanum only: Throttle setpoint along body Y axis
|
||||
float32 throttle_body_y # [] [@range -1 (Left), 1 (Right)] [@frame Body] [@invalid NaN If not omnidirectional] Omnidirectional only: Throttle setpoint along body Y axis
|
||||
@@ -67,11 +67,11 @@ add_subdirectory(pure_pursuit EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(rate_control EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(rc EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(ringbuffer EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(rover_control EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(rtl EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(sensor_calibration EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(slew_rate EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(stick_yaw EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(surface_vehicle_control EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(systemlib EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(system_identification EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(tecs EXCLUDE_FROM_ALL)
|
||||
|
||||
@@ -55,7 +55,7 @@ RtlTimeEstimator::RtlTimeEstimator() : ModuleParams(nullptr)
|
||||
_param_fw_sink_rate = param_find("FW_T_SINK_R_SP");
|
||||
_param_fw_airspeed_trim = param_find("FW_AIRSPD_TRIM");
|
||||
_param_mpc_xy_cruise = param_find("MPC_XY_CRUISE");
|
||||
_param_rover_cruise_speed = param_find("RO_SPEED_LIM");
|
||||
_param_rover_cruise_speed = param_find("SV_SPEED_LIM");
|
||||
};
|
||||
|
||||
rtl_time_estimate_s RtlTimeEstimator::getEstimate() const
|
||||
|
||||
+6
-6
@@ -31,11 +31,11 @@
|
||||
#
|
||||
############################################################################
|
||||
|
||||
px4_add_library(rover_control
|
||||
RoverControl.cpp
|
||||
RoverControl.hpp
|
||||
px4_add_library(surface_vehicle_control
|
||||
SurfaceVehicleControl.cpp
|
||||
SurfaceVehicleControl.hpp
|
||||
)
|
||||
|
||||
target_link_libraries(rover_control PUBLIC PID)
|
||||
target_link_libraries(rover_control PUBLIC geo)
|
||||
px4_add_unit_gtest(SRC RoverControlTest.cpp LINKLIBS rover_control)
|
||||
target_link_libraries(surface_vehicle_control PUBLIC PID)
|
||||
target_link_libraries(surface_vehicle_control PUBLIC geo)
|
||||
px4_add_unit_gtest(SRC SurfaceVehicleControlTest.cpp LINKLIBS surface_vehicle_control)
|
||||
+3
-3
@@ -31,9 +31,9 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "RoverControl.hpp"
|
||||
#include "SurfaceVehicleControl.hpp"
|
||||
using namespace matrix;
|
||||
namespace RoverControl
|
||||
namespace SurfaceVehicleControl
|
||||
{
|
||||
float throttleControl(SlewRate<float> &motor_setpoint, const float throttle_setpoint,
|
||||
const float current_motor_setpoint, const float max_accel, const float max_decel, const float max_thr_spd,
|
||||
@@ -265,4 +265,4 @@ float calcWaypointTransitionAngle(Vector2f &prev_wp_ned, Vector2f &curr_wp_ned,
|
||||
return acosf(cosin);
|
||||
}
|
||||
|
||||
} // RoverControl
|
||||
} // SurfaceVehicleControl
|
||||
+8
-7
@@ -32,10 +32,10 @@
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file RoverControl.hpp
|
||||
* @file SurfaceVehicleControl.hpp
|
||||
*
|
||||
* Functions that are shared among the different rover modules.
|
||||
* Also includes the parameters that are shared among the rover modules.
|
||||
* Functions that are shared among the different surface vehicles.
|
||||
* Also includes the parameters that are shared among them.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
@@ -47,7 +47,7 @@
|
||||
#include <lib/geo/geo.h>
|
||||
|
||||
using namespace matrix;
|
||||
namespace RoverControl
|
||||
namespace SurfaceVehicleControl
|
||||
{
|
||||
/**
|
||||
* Applies acceleration/deceleration slew rate to a throttle setpoint.
|
||||
@@ -56,7 +56,7 @@ namespace RoverControl
|
||||
* @param current_motor_setpoint Currently applied motor input [-1, 1]
|
||||
* @param max_accel Maximum allowed acceleration [m/s^2]
|
||||
* @param max_decel Maximum allowed deceleration [m/s^2]
|
||||
* @param max_thr_spd Speed the rover drives at maximum throttle [m/s]
|
||||
* @param max_thr_spd Speed the vehicle drives at maximum throttle [m/s]
|
||||
* @param dt Time since last update [s]
|
||||
* @return Motor Setpoint [-1, 1]
|
||||
*/
|
||||
@@ -76,6 +76,7 @@ float throttleControl(SlewRate<float> &motor_setpoint, float throttle_setpoint,
|
||||
*/
|
||||
float attitudeControl(SlewRateYaw<float> &adjusted_yaw_setpoint, PID &pid_yaw, float yaw_slew_rate,
|
||||
float vehicle_yaw, float yaw_setpoint, float dt);
|
||||
|
||||
/**
|
||||
* Applies acceleration/deceleration slew rate to a speed setpoint and calculates the necessary throttle setpoint
|
||||
* using a feed forward term and PID controller.
|
||||
@@ -95,7 +96,7 @@ float speedControl(SlewRate<float> &speed_with_rate_limit, PID &pid_speed, float
|
||||
/**
|
||||
* Applies yaw acceleration slew rate to a yaw rate setpoint and calculates the necessary speed diff setpoint
|
||||
* using a feedforward term and/or a PID controller.
|
||||
* Note: This function is only for rovers that control the rate through a speed difference between the left/right wheels.
|
||||
* Note: This function is only for vehicles that control the rate through a speed difference between the left/right wheels.
|
||||
* @param adjusted_yaw_rate_setpoint Yaw rate setpoint with applied slew rate [-1, 1] (Updated by this function).
|
||||
* @param pid_yaw_rate Yaw rate PID (Updated by this function).
|
||||
* @param yaw_rate_setpoint Yaw rate setpoint [rad/s].
|
||||
@@ -119,7 +120,7 @@ float rateControl(SlewRate<float> &adjusted_yaw_rate_setpoint, PID &pid_yaw_rate
|
||||
* @param prev_wp_ned Previous waypoint in NED frame (Updated by this function)
|
||||
* @param next_wp_ned Next waypoint in NED frame (Updated by this function)
|
||||
* @param position_setpoint_triplet Position Setpoint Triplet
|
||||
* @param curr_pos Current position of the rover in global frame
|
||||
* @param curr_pos Current position of the vehicle in global frame
|
||||
* @param global_ned_proj_ref Global to ned projection
|
||||
*/
|
||||
void globalToLocalSetpointTriplet(Vector2f &curr_wp_ned, Vector2f &prev_wp_ned, Vector2f &next_wp_ned,
|
||||
+11
-11
@@ -33,24 +33,24 @@
|
||||
|
||||
/******************************************************************
|
||||
* Test code for the Pure Pursuit algorithm
|
||||
* Run this test only using "make tests TESTFILTER=RoverControl"
|
||||
* Run this test only using "make tests TESTFILTER=SurfaceVehicleControl"
|
||||
******************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "RoverControl.hpp"
|
||||
#include "SurfaceVehicleControl.hpp"
|
||||
|
||||
TEST(calcWaypointTransitionAngle, invalidInputs)
|
||||
{
|
||||
Vector2f prev_wp_ned(NAN, NAN);
|
||||
Vector2f curr_wp_ned(10.f, 10.f);
|
||||
Vector2f next_wp_ned(10.f, 10.f);
|
||||
float prevInvalid = RoverControl::calcWaypointTransitionAngle(prev_wp_ned, curr_wp_ned, next_wp_ned);
|
||||
float prevInvalid = SurfaceVehicleControl::calcWaypointTransitionAngle(prev_wp_ned, curr_wp_ned, next_wp_ned);
|
||||
prev_wp_ned = Vector2f(10.f, 10.f);
|
||||
curr_wp_ned = Vector2f(NAN, NAN);
|
||||
float currInvalid = RoverControl::calcWaypointTransitionAngle(prev_wp_ned, curr_wp_ned, next_wp_ned);
|
||||
float currInvalid = SurfaceVehicleControl::calcWaypointTransitionAngle(prev_wp_ned, curr_wp_ned, next_wp_ned);
|
||||
curr_wp_ned = Vector2f(10.f, 10.f);
|
||||
next_wp_ned = Vector2f(NAN, NAN);
|
||||
float nextInvalid = RoverControl::calcWaypointTransitionAngle(prev_wp_ned, curr_wp_ned, next_wp_ned);
|
||||
float nextInvalid = SurfaceVehicleControl::calcWaypointTransitionAngle(prev_wp_ned, curr_wp_ned, next_wp_ned);
|
||||
EXPECT_FALSE(PX4_ISFINITE(prevInvalid));
|
||||
EXPECT_FALSE(PX4_ISFINITE(currInvalid));
|
||||
EXPECT_FALSE(PX4_ISFINITE(nextInvalid));
|
||||
@@ -63,7 +63,7 @@ TEST(calcWaypointTransitionAngle, validInputs)
|
||||
Vector2f prev_wp_ned(0.f, 0.f);
|
||||
Vector2f curr_wp_ned(10.f, 0.f);
|
||||
Vector2f next_wp_ned(20.f, 0.f);
|
||||
const float angle1 = RoverControl::calcWaypointTransitionAngle(prev_wp_ned, curr_wp_ned, next_wp_ned);
|
||||
const float angle1 = SurfaceVehicleControl::calcWaypointTransitionAngle(prev_wp_ned, curr_wp_ned, next_wp_ned);
|
||||
EXPECT_FLOAT_EQ(angle1, M_PI_F);
|
||||
|
||||
/**
|
||||
@@ -74,7 +74,7 @@ TEST(calcWaypointTransitionAngle, validInputs)
|
||||
prev_wp_ned = Vector2f(0.f, 0.f);
|
||||
curr_wp_ned = Vector2f(10.f, 0.f);
|
||||
next_wp_ned = Vector2f(20.f, 10.f);
|
||||
const float angle2 = RoverControl::calcWaypointTransitionAngle(prev_wp_ned, curr_wp_ned, next_wp_ned);
|
||||
const float angle2 = SurfaceVehicleControl::calcWaypointTransitionAngle(prev_wp_ned, curr_wp_ned, next_wp_ned);
|
||||
EXPECT_FLOAT_EQ(angle2, M_PI_F - M_PI_4_F);
|
||||
|
||||
/**
|
||||
@@ -85,7 +85,7 @@ TEST(calcWaypointTransitionAngle, validInputs)
|
||||
prev_wp_ned = Vector2f(0.f, 0.f);
|
||||
curr_wp_ned = Vector2f(10.f, 0.f);
|
||||
next_wp_ned = Vector2f(10.f, 10.f);
|
||||
const float angle3 = RoverControl::calcWaypointTransitionAngle(prev_wp_ned, curr_wp_ned, next_wp_ned);
|
||||
const float angle3 = SurfaceVehicleControl::calcWaypointTransitionAngle(prev_wp_ned, curr_wp_ned, next_wp_ned);
|
||||
EXPECT_FLOAT_EQ(angle3, M_PI_2_F);
|
||||
|
||||
/**
|
||||
@@ -96,20 +96,20 @@ TEST(calcWaypointTransitionAngle, validInputs)
|
||||
prev_wp_ned = Vector2f(0.f, 0.f);
|
||||
curr_wp_ned = Vector2f(10.f, 0.f);
|
||||
next_wp_ned = Vector2f(0.f, 10.f);
|
||||
const float angle4 = RoverControl::calcWaypointTransitionAngle(prev_wp_ned, curr_wp_ned, next_wp_ned);
|
||||
const float angle4 = SurfaceVehicleControl::calcWaypointTransitionAngle(prev_wp_ned, curr_wp_ned, next_wp_ned);
|
||||
EXPECT_FLOAT_EQ(angle4, M_PI_4_F);
|
||||
|
||||
// P/C -- N
|
||||
prev_wp_ned = Vector2f(0.f, 0.f);
|
||||
curr_wp_ned = Vector2f(0.f, 0.f);
|
||||
next_wp_ned = Vector2f(10.f, 0.f);
|
||||
const float angle5 = RoverControl::calcWaypointTransitionAngle(prev_wp_ned, curr_wp_ned, next_wp_ned);
|
||||
const float angle5 = SurfaceVehicleControl::calcWaypointTransitionAngle(prev_wp_ned, curr_wp_ned, next_wp_ned);
|
||||
EXPECT_FALSE(PX4_ISFINITE(angle5));
|
||||
|
||||
// P -- C/N
|
||||
prev_wp_ned = Vector2f(0.f, 0.f);
|
||||
curr_wp_ned = Vector2f(10.f, 0.f);
|
||||
next_wp_ned = Vector2f(10.f, 0.f);
|
||||
const float angle6 = RoverControl::calcWaypointTransitionAngle(prev_wp_ned, curr_wp_ned, next_wp_ned);
|
||||
const float angle6 = SurfaceVehicleControl::calcWaypointTransitionAngle(prev_wp_ned, curr_wp_ned, next_wp_ned);
|
||||
EXPECT_FALSE(PX4_ISFINITE(angle6));
|
||||
}
|
||||
+50
-50
@@ -32,9 +32,9 @@
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file rovercontrol_params.c
|
||||
* @file surface_vehicle_params.c
|
||||
*
|
||||
* Parameters defined by the rover control lib.
|
||||
* Parameters defined by the surface vehicle control lib.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -46,9 +46,9 @@
|
||||
* @max 1
|
||||
* @increment 0.01
|
||||
* @decimal 2
|
||||
* @group Rover Rate Control
|
||||
* @group SV Rate Control
|
||||
*/
|
||||
PARAM_DEFINE_FLOAT(RO_YAW_STICK_DZ, 0.1f);
|
||||
PARAM_DEFINE_FLOAT(SV_YAW_STICK_DZ, 0.1f);
|
||||
|
||||
/**
|
||||
* Yaw rate expo factor
|
||||
@@ -61,14 +61,14 @@ PARAM_DEFINE_FLOAT(RO_YAW_STICK_DZ, 0.1f);
|
||||
* @min 0
|
||||
* @max 1
|
||||
* @decimal 2
|
||||
* @group Rover Rate Control
|
||||
* @group SV Rate Control
|
||||
*/
|
||||
PARAM_DEFINE_FLOAT(RO_YAW_EXPO, 0.f);
|
||||
PARAM_DEFINE_FLOAT(SV_YAW_EXPO, 0.f);
|
||||
|
||||
/**
|
||||
* Yaw rate super expo factor
|
||||
*
|
||||
* "Superexponential" factor for refining the input curve shape tuned using RO_YAW_EXPO.
|
||||
* "Superexponential" factor for refining the input curve shape tuned using SV_YAW_EXPO.
|
||||
*
|
||||
* 0 Pure Expo function
|
||||
* 0.7 reasonable shape enhancement for intuitive stick feel
|
||||
@@ -77,9 +77,9 @@ PARAM_DEFINE_FLOAT(RO_YAW_EXPO, 0.f);
|
||||
* @min 0
|
||||
* @max 0.95
|
||||
* @decimal 2
|
||||
* @group Rover Rate Control
|
||||
* @group SV Rate Control
|
||||
*/
|
||||
PARAM_DEFINE_FLOAT(RO_YAW_SUPEXPO, 0.f);
|
||||
PARAM_DEFINE_FLOAT(SV_YAW_SUPEXPO, 0.f);
|
||||
|
||||
/**
|
||||
* Yaw rate measurement threshold
|
||||
@@ -91,9 +91,9 @@ PARAM_DEFINE_FLOAT(RO_YAW_SUPEXPO, 0.f);
|
||||
* @max 100
|
||||
* @increment 0.01
|
||||
* @decimal 2
|
||||
* @group Rover Rate Control
|
||||
* @group SV Rate Control
|
||||
*/
|
||||
PARAM_DEFINE_FLOAT(RO_YAW_RATE_TH, 3.f);
|
||||
PARAM_DEFINE_FLOAT(SV_YAW_RATE_TH, 3.f);
|
||||
|
||||
/**
|
||||
* Proportional gain for closed loop yaw rate controller
|
||||
@@ -102,9 +102,9 @@ PARAM_DEFINE_FLOAT(RO_YAW_RATE_TH, 3.f);
|
||||
* @max 100
|
||||
* @increment 0.01
|
||||
* @decimal 3
|
||||
* @group Rover Rate Control
|
||||
* @group SV Rate Control
|
||||
*/
|
||||
PARAM_DEFINE_FLOAT(RO_YAW_RATE_P, 0.f);
|
||||
PARAM_DEFINE_FLOAT(SV_YAW_RATE_P, 0.f);
|
||||
|
||||
/**
|
||||
* Integral gain for closed loop yaw rate controller
|
||||
@@ -113,9 +113,9 @@ PARAM_DEFINE_FLOAT(RO_YAW_RATE_P, 0.f);
|
||||
* @max 100
|
||||
* @increment 0.01
|
||||
* @decimal 3
|
||||
* @group Rover Rate Control
|
||||
* @group SV Rate Control
|
||||
*/
|
||||
PARAM_DEFINE_FLOAT(RO_YAW_RATE_I, 0.f);
|
||||
PARAM_DEFINE_FLOAT(SV_YAW_RATE_I, 0.f);
|
||||
|
||||
/**
|
||||
* Yaw rate limit
|
||||
@@ -128,9 +128,9 @@ PARAM_DEFINE_FLOAT(RO_YAW_RATE_I, 0.f);
|
||||
* @max 10000
|
||||
* @increment 0.01
|
||||
* @decimal 2
|
||||
* @group Rover Rate Control
|
||||
* @group SV Rate Control
|
||||
*/
|
||||
PARAM_DEFINE_FLOAT(RO_YAW_RATE_LIM, 0.f);
|
||||
PARAM_DEFINE_FLOAT(SV_YAW_RATE_LIM, 0.f);
|
||||
|
||||
/**
|
||||
* Yaw acceleration limit
|
||||
@@ -143,9 +143,9 @@ PARAM_DEFINE_FLOAT(RO_YAW_RATE_LIM, 0.f);
|
||||
* @max 10000
|
||||
* @increment 0.01
|
||||
* @decimal 2
|
||||
* @group Rover Rate Control
|
||||
* @group SV Rate Control
|
||||
*/
|
||||
PARAM_DEFINE_FLOAT(RO_YAW_ACCEL_LIM, -1.f);
|
||||
PARAM_DEFINE_FLOAT(SV_YAW_ACCEL_LIM, -1.f);
|
||||
|
||||
/**
|
||||
* Yaw deceleration limit
|
||||
@@ -158,9 +158,9 @@ PARAM_DEFINE_FLOAT(RO_YAW_ACCEL_LIM, -1.f);
|
||||
* @max 10000
|
||||
* @increment 0.01
|
||||
* @decimal 2
|
||||
* @group Rover Rate Control
|
||||
* @group SV Rate Control
|
||||
*/
|
||||
PARAM_DEFINE_FLOAT(RO_YAW_DECEL_LIM, -1.f);
|
||||
PARAM_DEFINE_FLOAT(SV_YAW_DECEL_LIM, -1.f);
|
||||
|
||||
/**
|
||||
* Yaw rate correction factor
|
||||
@@ -174,9 +174,9 @@ PARAM_DEFINE_FLOAT(RO_YAW_DECEL_LIM, -1.f);
|
||||
* @max 10000
|
||||
* @increment 0.01
|
||||
* @decimal 2
|
||||
* @group Rover Rate Control
|
||||
* @group SV Rate Control
|
||||
*/
|
||||
PARAM_DEFINE_FLOAT(RO_YAW_RATE_CORR, 1.f);
|
||||
PARAM_DEFINE_FLOAT(SV_YAW_RATE_CORR, 1.f);
|
||||
|
||||
/**
|
||||
* Proportional gain for closed loop yaw controller
|
||||
@@ -185,12 +185,12 @@ PARAM_DEFINE_FLOAT(RO_YAW_RATE_CORR, 1.f);
|
||||
* @max 100
|
||||
* @increment 0.01
|
||||
* @decimal 3
|
||||
* @group Rover Attitude Control
|
||||
* @group SV Attitude Control
|
||||
*/
|
||||
PARAM_DEFINE_FLOAT(RO_YAW_P, 0.f);
|
||||
PARAM_DEFINE_FLOAT(SV_YAW_P, 0.f);
|
||||
|
||||
/**
|
||||
* Speed the rover drives at maximum throttle
|
||||
* Speed the vehicle drives at maximum throttle
|
||||
*
|
||||
* Used to linearly map speeds [m/s] to throttle values [-1. 1].
|
||||
*
|
||||
@@ -199,9 +199,9 @@ PARAM_DEFINE_FLOAT(RO_YAW_P, 0.f);
|
||||
* @unit m/s
|
||||
* @increment 0.01
|
||||
* @decimal 2
|
||||
* @group Rover Velocity Control
|
||||
* @group SV Speed Control
|
||||
*/
|
||||
PARAM_DEFINE_FLOAT(RO_MAX_THR_SPEED, 0.f);
|
||||
PARAM_DEFINE_FLOAT(SV_MAX_THR_SPEED, 0.f);
|
||||
|
||||
/**
|
||||
* Proportional gain for ground speed controller
|
||||
@@ -210,9 +210,9 @@ PARAM_DEFINE_FLOAT(RO_MAX_THR_SPEED, 0.f);
|
||||
* @max 100
|
||||
* @increment 0.01
|
||||
* @decimal 2
|
||||
* @group Rover Velocity Control
|
||||
* @group SV Speed Control
|
||||
*/
|
||||
PARAM_DEFINE_FLOAT(RO_SPEED_P, 0.f);
|
||||
PARAM_DEFINE_FLOAT(SV_SPEED_P, 0.f);
|
||||
|
||||
/**
|
||||
* Integral gain for ground speed controller
|
||||
@@ -221,9 +221,9 @@ PARAM_DEFINE_FLOAT(RO_SPEED_P, 0.f);
|
||||
* @max 100
|
||||
* @increment 0.001
|
||||
* @decimal 3
|
||||
* @group Rover Velocity Control
|
||||
* @group SV Speed Control
|
||||
*/
|
||||
PARAM_DEFINE_FLOAT(RO_SPEED_I, 0.f);
|
||||
PARAM_DEFINE_FLOAT(SV_SPEED_I, 0.f);
|
||||
|
||||
/**
|
||||
* Speed limit
|
||||
@@ -235,56 +235,56 @@ PARAM_DEFINE_FLOAT(RO_SPEED_I, 0.f);
|
||||
* @max 100
|
||||
* @increment 0.01
|
||||
* @decimal 2
|
||||
* @group Rover Velocity Control
|
||||
* @group SV Speed Control
|
||||
*/
|
||||
PARAM_DEFINE_FLOAT(RO_SPEED_LIM, -1.f);
|
||||
PARAM_DEFINE_FLOAT(SV_SPEED_LIM, -1.f);
|
||||
|
||||
/**
|
||||
* Acceleration limit
|
||||
*
|
||||
* Set to -1 to disable.
|
||||
* For mecanum rovers this limit is used for longitudinal and lateral acceleration.
|
||||
* For omnidirectional vehicles this limit is used for longitudinal and lateral acceleration.
|
||||
*
|
||||
* @unit m/s^2
|
||||
* @min -1
|
||||
* @max 100
|
||||
* @increment 0.01
|
||||
* @decimal 2
|
||||
* @group Rover Velocity Control
|
||||
* @group SV Speed Control
|
||||
*/
|
||||
PARAM_DEFINE_FLOAT(RO_ACCEL_LIM, -1.f);
|
||||
PARAM_DEFINE_FLOAT(SV_ACCEL_LIM, -1.f);
|
||||
|
||||
/**
|
||||
* Deceleration limit
|
||||
*
|
||||
* Set to -1 to disable.
|
||||
* Note that if it is disabled the rover will not slow down when approaching waypoints in auto modes.
|
||||
* For mecanum rovers this limit is used for longitudinal and lateral deceleration.
|
||||
* Note that if it is disabled the vehicle will not slow down when approaching waypoints in auto modes.
|
||||
* For omnidirectional vehicles this limit is used for longitudinal and lateral deceleration.
|
||||
*
|
||||
* @unit m/s^2
|
||||
* @min -1
|
||||
* @max 100
|
||||
* @increment 0.01
|
||||
* @decimal 2
|
||||
* @group Rover Velocity Control
|
||||
* @group SV Speed Control
|
||||
*/
|
||||
PARAM_DEFINE_FLOAT(RO_DECEL_LIM, -1.f);
|
||||
PARAM_DEFINE_FLOAT(SV_DECEL_LIM, -1.f);
|
||||
|
||||
/**
|
||||
* Jerk limit
|
||||
*
|
||||
* Set to -1 to disable.
|
||||
* Note that if it is disabled the rover will not slow down when approaching waypoints in auto modes.
|
||||
* For mecanum rovers this limit is used for longitudinal and lateral jerk.
|
||||
* Note that if it is disabled the vehicle will not slow down when approaching waypoints in auto modes.
|
||||
* For omnidirectional vehicles this limit is used for longitudinal and lateral jerk.
|
||||
*
|
||||
* @unit m/s^3
|
||||
* @min -1
|
||||
* @max 100
|
||||
* @increment 0.01
|
||||
* @decimal 2
|
||||
* @group Rover Velocity Control
|
||||
* @group SV Speed Control
|
||||
*/
|
||||
PARAM_DEFINE_FLOAT(RO_JERK_LIM, -1.f);
|
||||
PARAM_DEFINE_FLOAT(SV_JERK_LIM, -1.f);
|
||||
|
||||
/**
|
||||
* Speed measurement threshold
|
||||
@@ -297,14 +297,14 @@ PARAM_DEFINE_FLOAT(RO_JERK_LIM, -1.f);
|
||||
* @max 100
|
||||
* @increment 0.01
|
||||
* @decimal 2
|
||||
* @group Rover Velocity Control
|
||||
* @group SV Speed Control
|
||||
*/
|
||||
PARAM_DEFINE_FLOAT(RO_SPEED_TH, 0.1f);
|
||||
PARAM_DEFINE_FLOAT(SV_SPEED_TH, 0.1f);
|
||||
|
||||
/**
|
||||
* Tuning parameter for the speed reduction based on the course error
|
||||
*
|
||||
* Reduced_speed = RO_MAX_THR_SPEED * (1 - normalized_course_error * RO_SPEED_RED)
|
||||
* Reduced_speed = SV_MAX_THR_SPEED * (1 - normalized_course_error * SV_SPEED_RED)
|
||||
* The normalized course error is the angle between the current course and the bearing setpoint
|
||||
* interpolated from [0, 180] -> [0, 1].
|
||||
* Higher value -> More speed reduction.
|
||||
@@ -315,6 +315,6 @@ PARAM_DEFINE_FLOAT(RO_SPEED_TH, 0.1f);
|
||||
* @max 100
|
||||
* @increment 0.01
|
||||
* @decimal 2
|
||||
* @group Rover Velocity Control
|
||||
* @group SV Speed Control
|
||||
*/
|
||||
PARAM_DEFINE_FLOAT(RO_SPEED_RED, -1.f);
|
||||
PARAM_DEFINE_FLOAT(SV_SPEED_RED, -1.f);
|
||||
@@ -0,0 +1,241 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "BoatRudder.hpp"
|
||||
|
||||
using namespace time_literals;
|
||||
|
||||
BoatRudder::BoatRudder() :
|
||||
ModuleParams(nullptr),
|
||||
ScheduledWorkItem(MODULE_NAME, px4::wq_configurations::rate_ctrl)
|
||||
{
|
||||
updateParams();
|
||||
}
|
||||
|
||||
bool BoatRudder::init()
|
||||
{
|
||||
ScheduleOnInterval(10_ms); // 100 Hz
|
||||
return true;
|
||||
}
|
||||
|
||||
void BoatRudder::updateParams()
|
||||
{
|
||||
ModuleParams::updateParams();
|
||||
}
|
||||
|
||||
void BoatRudder::Run()
|
||||
{
|
||||
if (_parameter_update_sub.updated()) {
|
||||
parameter_update_s param_update{};
|
||||
_parameter_update_sub.copy(¶m_update);
|
||||
updateParams();
|
||||
runSanityChecks();
|
||||
}
|
||||
|
||||
if (_vehicle_control_mode_sub.updated()) {
|
||||
vehicle_control_mode_s vehicle_control_mode{};
|
||||
_vehicle_control_mode_sub.copy(&vehicle_control_mode);
|
||||
|
||||
// Run sanity checks if the control mode changes (Note: This has to be done this way, because the topic is periodically updated at 2 Hz)
|
||||
if (_vehicle_control_mode.flag_control_position_enabled != vehicle_control_mode.flag_control_position_enabled ||
|
||||
_vehicle_control_mode.flag_control_velocity_enabled != vehicle_control_mode.flag_control_velocity_enabled ||
|
||||
_vehicle_control_mode.flag_control_attitude_enabled != vehicle_control_mode.flag_control_attitude_enabled ||
|
||||
_vehicle_control_mode.flag_control_rates_enabled != vehicle_control_mode.flag_control_rates_enabled ||
|
||||
_vehicle_control_mode.flag_control_allocation_enabled != vehicle_control_mode.flag_control_allocation_enabled) {
|
||||
_vehicle_control_mode = vehicle_control_mode;
|
||||
runSanityChecks();
|
||||
reset();
|
||||
|
||||
} else {
|
||||
_vehicle_control_mode = vehicle_control_mode;
|
||||
}
|
||||
}
|
||||
|
||||
if (_vehicle_control_mode.flag_armed && _sanity_checks_passed) {
|
||||
_was_armed = true;
|
||||
generateSetpoints();
|
||||
updateControllers();
|
||||
|
||||
} else if (_was_armed) { // Reset all controllers and stop the vehicle
|
||||
reset();
|
||||
_boat_rudder_act_control.stopVehicle();
|
||||
_was_armed = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void BoatRudder::generateSetpoints()
|
||||
{
|
||||
vehicle_status_s vehicle_status{};
|
||||
_vehicle_status_sub.copy(&vehicle_status);
|
||||
|
||||
switch (vehicle_status.nav_state) {
|
||||
case vehicle_status_s::NAVIGATION_STATE_AUTO_MISSION:
|
||||
case vehicle_status_s::NAVIGATION_STATE_AUTO_LOITER:
|
||||
case vehicle_status_s::NAVIGATION_STATE_AUTO_RTL:
|
||||
_boat_rudder_auto_mode.autoControl();
|
||||
break;
|
||||
|
||||
case vehicle_status_s::NAVIGATION_STATE_OFFBOARD:
|
||||
_boat_rudder_offboard_mode.offboardControl();
|
||||
break;
|
||||
|
||||
case vehicle_status_s::NAVIGATION_STATE_MANUAL:
|
||||
_boat_rudder_manual_mode.manual();
|
||||
break;
|
||||
|
||||
case vehicle_status_s::NAVIGATION_STATE_ACRO:
|
||||
_boat_rudder_manual_mode.acro();
|
||||
break;
|
||||
|
||||
case vehicle_status_s::NAVIGATION_STATE_STAB:
|
||||
_boat_rudder_manual_mode.stab();
|
||||
break;
|
||||
|
||||
case vehicle_status_s::NAVIGATION_STATE_POSCTL:
|
||||
_boat_rudder_manual_mode.position();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void BoatRudder::updateControllers()
|
||||
{
|
||||
if (_vehicle_control_mode.flag_control_position_enabled) {
|
||||
_boat_rudder_pos_control.updatePosControl();
|
||||
}
|
||||
|
||||
if (_vehicle_control_mode.flag_control_velocity_enabled) {
|
||||
_boat_rudder_speed_control.updateSpeedControl();
|
||||
}
|
||||
|
||||
if (_vehicle_control_mode.flag_control_attitude_enabled) {
|
||||
_boat_rudder_att_control.updateAttControl();
|
||||
}
|
||||
|
||||
if (_vehicle_control_mode.flag_control_rates_enabled) {
|
||||
_boat_rudder_rate_control.updateRateControl();
|
||||
}
|
||||
|
||||
if (_vehicle_control_mode.flag_control_allocation_enabled) {
|
||||
_boat_rudder_act_control.updateActControl();
|
||||
}
|
||||
}
|
||||
|
||||
void BoatRudder::runSanityChecks()
|
||||
{
|
||||
if (_vehicle_control_mode.flag_control_rates_enabled && !_boat_rudder_rate_control.runSanityChecks()) {
|
||||
_sanity_checks_passed = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_vehicle_control_mode.flag_control_attitude_enabled && !_boat_rudder_att_control.runSanityChecks()) {
|
||||
_sanity_checks_passed = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_vehicle_control_mode.flag_control_velocity_enabled && !_boat_rudder_speed_control.runSanityChecks()) {
|
||||
_sanity_checks_passed = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_vehicle_control_mode.flag_control_position_enabled && !_boat_rudder_pos_control.runSanityChecks()) {
|
||||
_sanity_checks_passed = false;
|
||||
return;
|
||||
}
|
||||
|
||||
_sanity_checks_passed = true;
|
||||
}
|
||||
|
||||
void BoatRudder::reset()
|
||||
{
|
||||
_boat_rudder_pos_control.reset();
|
||||
_boat_rudder_speed_control.reset();
|
||||
_boat_rudder_att_control.reset();
|
||||
_boat_rudder_rate_control.reset();
|
||||
_boat_rudder_manual_mode.reset();
|
||||
}
|
||||
|
||||
int BoatRudder::task_spawn(int argc, char *argv[])
|
||||
{
|
||||
BoatRudder *instance = new BoatRudder();
|
||||
|
||||
if (instance) {
|
||||
_object.store(instance);
|
||||
_task_id = task_id_is_work_queue;
|
||||
|
||||
if (instance->init()) {
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
} else {
|
||||
PX4_ERR("alloc failed");
|
||||
}
|
||||
|
||||
delete instance;
|
||||
_object.store(nullptr);
|
||||
_task_id = -1;
|
||||
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
int BoatRudder::custom_command(int argc, char *argv[])
|
||||
{
|
||||
return print_usage("unknown command");
|
||||
}
|
||||
|
||||
int BoatRudder::print_usage(const char *reason)
|
||||
{
|
||||
if (reason) {
|
||||
PX4_ERR("%s\n", reason);
|
||||
}
|
||||
|
||||
PRINT_MODULE_DESCRIPTION(
|
||||
R"DESCR_STR(
|
||||
### Description
|
||||
Module for rudder-steered boats.
|
||||
)DESCR_STR");
|
||||
|
||||
PRINT_MODULE_USAGE_NAME("boat_rudder", "controller");
|
||||
PRINT_MODULE_USAGE_COMMAND("start");
|
||||
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" __EXPORT int boat_rudder_main(int argc, char *argv[])
|
||||
{
|
||||
return BoatRudder::main(argc, argv);
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
// PX4 includes
|
||||
#include <px4_platform_common/px4_config.h>
|
||||
#include <px4_platform_common/defines.h>
|
||||
#include <px4_platform_common/module.h>
|
||||
#include <px4_platform_common/module_params.h>
|
||||
#include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp>
|
||||
|
||||
// Library includes
|
||||
#include <math.h>
|
||||
|
||||
// uORB includes
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/topics/parameter_update.h>
|
||||
#include <uORB/topics/vehicle_control_mode.h>
|
||||
#include <uORB/topics/vehicle_status.h>
|
||||
|
||||
// Local includes
|
||||
#include "BoatRudderActControl/BoatRudderActControl.hpp"
|
||||
#include "BoatRudderRateControl/BoatRudderRateControl.hpp"
|
||||
#include "BoatRudderAttControl/BoatRudderAttControl.hpp"
|
||||
#include "BoatRudderSpeedControl/BoatRudderSpeedControl.hpp"
|
||||
#include "BoatRudderPosControl/BoatRudderPosControl.hpp"
|
||||
#include "BoatRudderDriveModes/BoatRudderAutoMode/BoatRudderAutoMode.hpp"
|
||||
#include "BoatRudderDriveModes/BoatRudderManualMode/BoatRudderManualMode.hpp"
|
||||
#include "BoatRudderDriveModes/BoatRudderOffboardMode/BoatRudderOffboardMode.hpp"
|
||||
|
||||
class BoatRudder : public ModuleBase<BoatRudder>, public ModuleParams,
|
||||
public px4::ScheduledWorkItem
|
||||
{
|
||||
public:
|
||||
BoatRudder();
|
||||
~BoatRudder() override = default;
|
||||
|
||||
/** @see ModuleBase */
|
||||
static int task_spawn(int argc, char *argv[]);
|
||||
|
||||
/** @see ModuleBase */
|
||||
static int custom_command(int argc, char *argv[]);
|
||||
|
||||
/** @see ModuleBase */
|
||||
static int print_usage(const char *reason = nullptr);
|
||||
|
||||
bool init();
|
||||
|
||||
protected:
|
||||
void updateParams() override;
|
||||
|
||||
private:
|
||||
void Run() override;
|
||||
|
||||
/**
|
||||
* @brief Generate surface vehicle setpoints if the vehicle is in a
|
||||
* supported PX4 internal mode.
|
||||
* Note: The surface vehicle setpoints are expected to be published from outside this module
|
||||
* if the vehicle is not in a PX4 internal mode.
|
||||
*/
|
||||
void generateSetpoints();
|
||||
|
||||
void updateControllers();
|
||||
|
||||
/**
|
||||
* @brief Check proper parameter setup for the controllers
|
||||
*
|
||||
* Modifies:
|
||||
*
|
||||
* - _sanity_checks_passed: true if checks for all active controllers pass
|
||||
*/
|
||||
void runSanityChecks();
|
||||
|
||||
/**
|
||||
* @brief Reset controllers and manual mode variables.
|
||||
*/
|
||||
void reset();
|
||||
|
||||
// uORB subscriptions
|
||||
uORB::Subscription _parameter_update_sub{ORB_ID(parameter_update)};
|
||||
uORB::Subscription _vehicle_status_sub{ORB_ID(vehicle_status)};
|
||||
uORB::Subscription _vehicle_control_mode_sub{ORB_ID(vehicle_control_mode)};
|
||||
vehicle_control_mode_s _vehicle_control_mode{};
|
||||
|
||||
// Class instances
|
||||
BoatRudderActControl _boat_rudder_act_control{this};
|
||||
BoatRudderRateControl _boat_rudder_rate_control{this};
|
||||
BoatRudderAttControl _boat_rudder_att_control{this};
|
||||
BoatRudderSpeedControl _boat_rudder_speed_control{this};
|
||||
BoatRudderPosControl _boat_rudder_pos_control{this};
|
||||
BoatRudderAutoMode _boat_rudder_auto_mode{this};
|
||||
BoatRudderManualMode _boat_rudder_manual_mode{this};
|
||||
BoatRudderOffboardMode _boat_rudder_offboard_mode{this};
|
||||
|
||||
// Variables
|
||||
bool _sanity_checks_passed{true}; // True if checks for all active controllers pass
|
||||
bool _was_armed{false}; // True if the vehicle was armed before the last reset
|
||||
};
|
||||
@@ -0,0 +1,125 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "BoatRudderActControl.hpp"
|
||||
|
||||
using namespace time_literals;
|
||||
|
||||
BoatRudderActControl::BoatRudderActControl(ModuleParams *parent) : ModuleParams(parent)
|
||||
{
|
||||
updateParams();
|
||||
}
|
||||
|
||||
void BoatRudderActControl::updateParams()
|
||||
{
|
||||
ModuleParams::updateParams();
|
||||
|
||||
if (_param_br_str_rate_limit.get() > FLT_EPSILON && _param_br_max_str_ang.get() > FLT_EPSILON) {
|
||||
_servo_setpoint.setSlewRate((M_DEG_TO_RAD_F * _param_br_str_rate_limit.get()) / _param_br_max_str_ang.get());
|
||||
}
|
||||
|
||||
if (_param_sv_accel_limit.get() > FLT_EPSILON && _param_sv_max_thr_speed.get() > FLT_EPSILON) {
|
||||
_motor_setpoint.setSlewRate(_param_sv_accel_limit.get() / _param_sv_max_thr_speed.get());
|
||||
}
|
||||
}
|
||||
|
||||
void BoatRudderActControl::updateActControl()
|
||||
{
|
||||
const hrt_abstime timestamp_prev = _timestamp;
|
||||
_timestamp = hrt_absolute_time();
|
||||
const float dt = math::constrain(_timestamp - timestamp_prev, 1_ms, 10_ms) * 1e-6f;
|
||||
|
||||
// Motor control
|
||||
if (_surface_vehicle_throttle_setpoint_sub.updated()) {
|
||||
surface_vehicle_throttle_setpoint_s surface_vehicle_throttle_setpoint{};
|
||||
_surface_vehicle_throttle_setpoint_sub.copy(&surface_vehicle_throttle_setpoint);
|
||||
_throttle_setpoint = surface_vehicle_throttle_setpoint.throttle_body_x;
|
||||
}
|
||||
|
||||
if (PX4_ISFINITE(_throttle_setpoint)) {
|
||||
actuator_motors_s actuator_motors_sub{};
|
||||
_actuator_motors_sub.copy(&actuator_motors_sub);
|
||||
actuator_motors_s actuator_motors{};
|
||||
actuator_motors.reversible_flags = _param_r_rev.get();
|
||||
actuator_motors.control[0] = SurfaceVehicleControl::throttleControl(_motor_setpoint,
|
||||
_throttle_setpoint, actuator_motors_sub.control[0], _param_sv_accel_limit.get(),
|
||||
_param_sv_decel_limit.get(), _param_sv_max_thr_speed.get(), dt);
|
||||
actuator_motors.timestamp = _timestamp;
|
||||
_actuator_motors_pub.publish(actuator_motors);
|
||||
|
||||
}
|
||||
|
||||
// Servo control
|
||||
if (_surface_vehicle_steering_setpoint_sub.updated()) {
|
||||
surface_vehicle_steering_setpoint_s surface_vehicle_steering_setpoint{};
|
||||
_surface_vehicle_steering_setpoint_sub.copy(&surface_vehicle_steering_setpoint);
|
||||
_steering_setpoint = surface_vehicle_steering_setpoint.normalized_steering_setpoint;
|
||||
}
|
||||
|
||||
if (PX4_ISFINITE(_steering_setpoint)) {
|
||||
actuator_servos_s actuator_servos_sub{};
|
||||
_actuator_servos_sub.copy(&actuator_servos_sub);
|
||||
|
||||
if (_param_br_str_rate_limit.get() > FLT_EPSILON
|
||||
&& _param_br_max_str_ang.get() > FLT_EPSILON) { // Apply slew rate if configured
|
||||
if (fabsf(_servo_setpoint.getState() - actuator_servos_sub.control[0]) > fabsf(
|
||||
_steering_setpoint -
|
||||
actuator_servos_sub.control[0])) {
|
||||
_servo_setpoint.setForcedValue(actuator_servos_sub.control[0]);
|
||||
}
|
||||
|
||||
_servo_setpoint.update(_steering_setpoint, dt);
|
||||
|
||||
} else {
|
||||
_servo_setpoint.setForcedValue(_steering_setpoint);
|
||||
}
|
||||
|
||||
actuator_servos_s actuator_servos{};
|
||||
actuator_servos.control[0] = _servo_setpoint.getState();
|
||||
actuator_servos.timestamp = _timestamp;
|
||||
_actuator_servos_pub.publish(actuator_servos);
|
||||
}
|
||||
}
|
||||
|
||||
void BoatRudderActControl::stopVehicle()
|
||||
{
|
||||
actuator_motors_s actuator_motors{};
|
||||
actuator_motors.reversible_flags = _param_r_rev.get();
|
||||
actuator_motors.control[0] = 0.f;
|
||||
actuator_motors.timestamp = _timestamp;
|
||||
_actuator_motors_pub.publish(actuator_motors);
|
||||
actuator_servos_s actuator_servos{};
|
||||
actuator_servos.control[0] = 0.f;
|
||||
actuator_servos.timestamp = _timestamp;
|
||||
_actuator_servos_pub.publish(actuator_servos);
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
// PX4 includes
|
||||
#include <px4_platform_common/module_params.h>
|
||||
|
||||
// Libraries
|
||||
#include <lib/surface_vehicle_control/SurfaceVehicleControl.hpp>
|
||||
#include <lib/slew_rate/SlewRate.hpp>
|
||||
#include <math.h>
|
||||
|
||||
// uORB includes
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/topics/actuator_motors.h>
|
||||
#include <uORB/topics/actuator_servos.h>
|
||||
#include <uORB/topics/surface_vehicle_steering_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_throttle_setpoint.h>
|
||||
|
||||
/**
|
||||
* @brief Class for actuator control of rudder-steered boats.
|
||||
*/
|
||||
class BoatRudderActControl : public ModuleParams
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor for BoatRudderActControl.
|
||||
* @param parent The parent ModuleParams object.
|
||||
*/
|
||||
BoatRudderActControl(ModuleParams *parent);
|
||||
~BoatRudderActControl() = default;
|
||||
|
||||
/**
|
||||
* @brief Generate and publish actuatorMotors/actuatorServos setpoints from SurfaceVehicleThrottleSetpoint/SurfaceVehicleSteeringSetpoint.
|
||||
*/
|
||||
void updateActControl();
|
||||
|
||||
/**
|
||||
* @brief Stop the vehicle by sending 0 commands to motors and servos.
|
||||
*/
|
||||
void stopVehicle();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Update the parameters of the module.
|
||||
*/
|
||||
void updateParams() override;
|
||||
|
||||
private:
|
||||
|
||||
// uORB subscriptions
|
||||
uORB::Subscription _actuator_servos_sub{ORB_ID(actuator_servos)};
|
||||
uORB::Subscription _actuator_motors_sub{ORB_ID(actuator_motors)};
|
||||
uORB::Subscription _surface_vehicle_steering_setpoint_sub{ORB_ID(surface_vehicle_steering_setpoint)};
|
||||
uORB::Subscription _surface_vehicle_throttle_setpoint_sub{ORB_ID(surface_vehicle_throttle_setpoint)};
|
||||
|
||||
// uORB publications
|
||||
uORB::Publication<actuator_motors_s> _actuator_motors_pub{ORB_ID(actuator_motors)};
|
||||
uORB::Publication<actuator_servos_s> _actuator_servos_pub{ORB_ID(actuator_servos)};
|
||||
|
||||
// Variables
|
||||
hrt_abstime _timestamp{0};
|
||||
float _throttle_setpoint{NAN};
|
||||
float _steering_setpoint{NAN};
|
||||
|
||||
// Controllers
|
||||
SlewRate<float> _servo_setpoint{0.f};
|
||||
SlewRate<float> _motor_setpoint{0.f};
|
||||
|
||||
// Parameters
|
||||
DEFINE_PARAMETERS(
|
||||
(ParamInt<px4::params::CA_R_REV>) _param_r_rev,
|
||||
(ParamFloat<px4::params::BR_STR_RATE_LIM>) _param_br_str_rate_limit,
|
||||
(ParamFloat<px4::params::BR_MAX_STR_ANG>) _param_br_max_str_ang,
|
||||
(ParamFloat<px4::params::SV_ACCEL_LIM>) _param_sv_accel_limit,
|
||||
(ParamFloat<px4::params::SV_DECEL_LIM>) _param_sv_decel_limit,
|
||||
(ParamFloat<px4::params::SV_MAX_THR_SPEED>) _param_sv_max_thr_speed
|
||||
)
|
||||
};
|
||||
@@ -0,0 +1,38 @@
|
||||
############################################################################
|
||||
#
|
||||
# Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name PX4 nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
px4_add_library(BoatRudderActControl
|
||||
BoatRudderActControl.cpp
|
||||
)
|
||||
|
||||
target_include_directories(BoatRudderActControl PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
@@ -0,0 +1,140 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "BoatRudderAttControl.hpp"
|
||||
|
||||
using namespace time_literals;
|
||||
|
||||
BoatRudderAttControl::BoatRudderAttControl(ModuleParams *parent) : ModuleParams(parent)
|
||||
{
|
||||
_surface_vehicle_rate_setpoint_pub.advertise();
|
||||
_surface_vehicle_attitude_status_pub.advertise();
|
||||
updateParams();
|
||||
}
|
||||
|
||||
void BoatRudderAttControl::updateParams()
|
||||
{
|
||||
ModuleParams::updateParams();
|
||||
|
||||
if (_param_sv_yaw_rate_limit.get() > FLT_EPSILON) {
|
||||
_max_yaw_rate = _param_sv_yaw_rate_limit.get() * M_DEG_TO_RAD_F;
|
||||
}
|
||||
|
||||
// Set up PID controller
|
||||
_pid_yaw.setGains(_param_sv_yaw_p.get(), 0.f, 0.f);
|
||||
_pid_yaw.setIntegralLimit(0.f);
|
||||
_pid_yaw.setOutputLimit(_max_yaw_rate);
|
||||
|
||||
// Set up slew rate
|
||||
_adjusted_yaw_setpoint.setSlewRate(_max_yaw_rate);
|
||||
}
|
||||
|
||||
void BoatRudderAttControl::updateAttControl()
|
||||
{
|
||||
updateSubscriptions();
|
||||
|
||||
hrt_abstime timestamp_prev = _timestamp;
|
||||
_timestamp = hrt_absolute_time();
|
||||
const float dt = math::constrain(_timestamp - timestamp_prev, 1_ms, 10_ms) * 1e-6f;
|
||||
|
||||
if (PX4_ISFINITE(_yaw_setpoint)) {
|
||||
// Calculate yaw rate limit for slew rate
|
||||
float max_possible_yaw_rate = fabsf(_estimated_speed_body_x) * tanf(_param_br_max_str_ang.get()) /
|
||||
_param_br_wheel_base.get(); // Maximum possible yaw rate at current velocity
|
||||
float yaw_slew_rate = math::min(max_possible_yaw_rate, _max_yaw_rate);
|
||||
|
||||
float yaw_rate_setpoint = SurfaceVehicleControl::attitudeControl(_adjusted_yaw_setpoint, _pid_yaw, yaw_slew_rate,
|
||||
_vehicle_yaw, _yaw_setpoint, dt);
|
||||
|
||||
surface_vehicle_rate_setpoint_s surface_vehicle_rate_setpoint{};
|
||||
surface_vehicle_rate_setpoint.timestamp = _timestamp;
|
||||
surface_vehicle_rate_setpoint.yaw_rate_setpoint = math::constrain(yaw_rate_setpoint, -_max_yaw_rate, _max_yaw_rate);
|
||||
_surface_vehicle_rate_setpoint_pub.publish(surface_vehicle_rate_setpoint);
|
||||
|
||||
}
|
||||
|
||||
// Publish attitude controller status (logging only)
|
||||
surface_vehicle_attitude_status_s surface_vehicle_attitude_status;
|
||||
surface_vehicle_attitude_status.timestamp = _timestamp;
|
||||
surface_vehicle_attitude_status.measured_yaw = _vehicle_yaw;
|
||||
surface_vehicle_attitude_status.adjusted_yaw_setpoint = matrix::wrap_pi(_adjusted_yaw_setpoint.getState());
|
||||
_surface_vehicle_attitude_status_pub.publish(surface_vehicle_attitude_status);
|
||||
|
||||
}
|
||||
|
||||
void BoatRudderAttControl::updateSubscriptions()
|
||||
{
|
||||
if (_vehicle_attitude_sub.updated()) {
|
||||
vehicle_attitude_s vehicle_attitude{};
|
||||
_vehicle_attitude_sub.copy(&vehicle_attitude);
|
||||
matrix::Quatf vehicle_attitude_quaternion = matrix::Quatf(vehicle_attitude.q);
|
||||
_vehicle_yaw = matrix::Eulerf(vehicle_attitude_quaternion).psi();
|
||||
}
|
||||
|
||||
// Estimate forward speed based on throttle
|
||||
if (_actuator_motors_sub.updated()) {
|
||||
actuator_motors_s actuator_motors;
|
||||
_actuator_motors_sub.copy(&actuator_motors);
|
||||
_estimated_speed_body_x = math::interpolate<float> (actuator_motors.control[0], -1.f, 1.f,
|
||||
-_param_sv_max_thr_speed.get(), _param_sv_max_thr_speed.get());
|
||||
}
|
||||
|
||||
if (_surface_vehicle_attitude_setpoint_sub.updated()) {
|
||||
surface_vehicle_attitude_setpoint_s surface_vehicle_attitude_setpoint{};
|
||||
_surface_vehicle_attitude_setpoint_sub.copy(&surface_vehicle_attitude_setpoint);
|
||||
_yaw_setpoint = surface_vehicle_attitude_setpoint.yaw_setpoint;
|
||||
}
|
||||
}
|
||||
|
||||
bool BoatRudderAttControl::runSanityChecks()
|
||||
{
|
||||
bool ret = true;
|
||||
|
||||
if (_param_sv_max_thr_speed.get() < FLT_EPSILON) {
|
||||
ret = false;
|
||||
}
|
||||
|
||||
if (_param_br_wheel_base.get() < FLT_EPSILON) {
|
||||
ret = false;
|
||||
}
|
||||
|
||||
if (_param_br_max_str_ang.get() < FLT_EPSILON) {
|
||||
ret = false;
|
||||
}
|
||||
|
||||
if (_param_sv_yaw_rate_limit.get() < FLT_EPSILON) {
|
||||
ret = false;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
// PX4 includes
|
||||
#include <px4_platform_common/module_params.h>
|
||||
|
||||
// Library includes
|
||||
#include <lib/surface_vehicle_control/SurfaceVehicleControl.hpp>
|
||||
#include <lib/pid/PID.hpp>
|
||||
#include <lib/slew_rate/SlewRateYaw.hpp>
|
||||
#include <math.h>
|
||||
#include <matrix/matrix/math.hpp>
|
||||
|
||||
// uORB includes
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/topics/surface_vehicle_rate_setpoint.h>
|
||||
#include <uORB/topics/vehicle_attitude.h>
|
||||
#include <uORB/topics/surface_vehicle_attitude_status.h>
|
||||
#include <uORB/topics/surface_vehicle_attitude_setpoint.h>
|
||||
#include <uORB/topics/actuator_motors.h>
|
||||
|
||||
/**
|
||||
* @brief Class for attitude control of rudder-steered boats.
|
||||
*/
|
||||
class BoatRudderAttControl : public ModuleParams
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor for BoatRudderAttControl.
|
||||
* @param parent The parent ModuleParams object.
|
||||
*/
|
||||
BoatRudderAttControl(ModuleParams *parent);
|
||||
~BoatRudderAttControl() = default;
|
||||
|
||||
/**
|
||||
* @brief Generate and publish SurfaceVehicleRateSetpoint from SurfaceVehicleAttitudeSetpoint.
|
||||
*/
|
||||
void updateAttControl();
|
||||
|
||||
/**
|
||||
* @brief Reset attitude controller.
|
||||
*/
|
||||
void reset() {_pid_yaw.resetIntegral(); _yaw_setpoint = NAN;};
|
||||
|
||||
/**
|
||||
* @brief Check if the necessary parameters are set.
|
||||
* @return True if all checks pass.
|
||||
*/
|
||||
bool runSanityChecks();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Update the parameters of the module.
|
||||
*/
|
||||
void updateParams() override;
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Update uORB subscriptions used in attitude controller.
|
||||
*/
|
||||
void updateSubscriptions();
|
||||
|
||||
// uORB subscriptions
|
||||
uORB::Subscription _vehicle_attitude_sub{ORB_ID(vehicle_attitude)};
|
||||
uORB::Subscription _actuator_motors_sub{ORB_ID(actuator_motors)};
|
||||
uORB::Subscription _surface_vehicle_attitude_setpoint_sub{ORB_ID(surface_vehicle_attitude_setpoint)};
|
||||
|
||||
// uORB publications
|
||||
uORB::Publication<surface_vehicle_rate_setpoint_s> _surface_vehicle_rate_setpoint_pub{ORB_ID(surface_vehicle_rate_setpoint)};
|
||||
uORB::Publication<surface_vehicle_attitude_status_s> _surface_vehicle_attitude_status_pub{ORB_ID(surface_vehicle_attitude_status)};
|
||||
|
||||
// Variables
|
||||
float _vehicle_yaw{0.f};
|
||||
hrt_abstime _timestamp{0};
|
||||
float _max_yaw_rate{0.f};
|
||||
float _estimated_speed_body_x{0.f}; /*Vehicle speed estimated by interpolating [actuatorMotorSetpoint, _estimated_speed_body_x]
|
||||
between [0, 0] and [1, _param_sv_max_thr_speed].*/
|
||||
float _yaw_setpoint{NAN};
|
||||
|
||||
// Controllers
|
||||
PID _pid_yaw;
|
||||
SlewRateYaw<float> _adjusted_yaw_setpoint;
|
||||
|
||||
// Parameters
|
||||
DEFINE_PARAMETERS(
|
||||
(ParamFloat<px4::params::SV_MAX_THR_SPEED>) _param_sv_max_thr_speed,
|
||||
(ParamFloat<px4::params::BR_WHEEL_BASE>) _param_br_wheel_base,
|
||||
(ParamFloat<px4::params::BR_MAX_STR_ANG>) _param_br_max_str_ang,
|
||||
(ParamFloat<px4::params::SV_YAW_RATE_LIM>) _param_sv_yaw_rate_limit,
|
||||
(ParamFloat<px4::params::SV_YAW_P>) _param_sv_yaw_p,
|
||||
(ParamFloat<px4::params::SV_YAW_STICK_DZ>) _param_sv_yaw_stick_dz
|
||||
)
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
############################################################################
|
||||
#
|
||||
# Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name PX4 nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
px4_add_library(BoatRudderAttControl
|
||||
BoatRudderAttControl.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(BoatRudderAttControl PUBLIC PID)
|
||||
target_include_directories(BoatRudderAttControl PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
+157
@@ -0,0 +1,157 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "BoatRudderAutoMode.hpp"
|
||||
|
||||
using namespace time_literals;
|
||||
|
||||
BoatRudderAutoMode::BoatRudderAutoMode(ModuleParams *parent) : ModuleParams(parent)
|
||||
{
|
||||
updateParams();
|
||||
_surface_vehicle_position_setpoint_pub.advertise();
|
||||
}
|
||||
|
||||
void BoatRudderAutoMode::updateParams()
|
||||
{
|
||||
ModuleParams::updateParams();
|
||||
_max_yaw_rate = _param_sv_yaw_rate_limit.get() * M_DEG_TO_RAD_F;
|
||||
|
||||
if (_param_br_wheel_base.get() > FLT_EPSILON && _max_yaw_rate > FLT_EPSILON
|
||||
&& _param_br_max_str_ang.get() > FLT_EPSILON) {
|
||||
_min_speed = _param_br_wheel_base.get() * _max_yaw_rate / tanf(_param_br_max_str_ang.get());
|
||||
}
|
||||
}
|
||||
|
||||
void BoatRudderAutoMode::autoControl()
|
||||
{
|
||||
if (_position_setpoint_triplet_sub.updated()) {
|
||||
if (_vehicle_local_position_sub.updated()) {
|
||||
vehicle_local_position_s vehicle_local_position{};
|
||||
_vehicle_local_position_sub.copy(&vehicle_local_position);
|
||||
|
||||
if (!_global_ned_proj_ref.isInitialized()
|
||||
|| (_global_ned_proj_ref.getProjectionReferenceTimestamp() != vehicle_local_position.ref_timestamp)) {
|
||||
_global_ned_proj_ref.initReference(vehicle_local_position.ref_lat, vehicle_local_position.ref_lon,
|
||||
vehicle_local_position.ref_timestamp);
|
||||
}
|
||||
|
||||
_curr_pos_ned = Vector2f(vehicle_local_position.x, vehicle_local_position.y);
|
||||
}
|
||||
|
||||
updateWaypointsAndAcceptanceRadius();
|
||||
|
||||
surface_vehicle_position_setpoint_s surface_vehicle_position_setpoint{};
|
||||
surface_vehicle_position_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_position_setpoint.position_ned[0] = _curr_wp_ned(0);
|
||||
surface_vehicle_position_setpoint.position_ned[1] = _curr_wp_ned(1);
|
||||
surface_vehicle_position_setpoint.start_ned[0] = _prev_wp_ned(0);
|
||||
surface_vehicle_position_setpoint.start_ned[1] = _prev_wp_ned(1);
|
||||
surface_vehicle_position_setpoint.arrival_speed = arrivalSpeed(_cruising_speed, _min_speed, _acceptance_radius,
|
||||
_curr_wp_type,
|
||||
_waypoint_transition_angle, _max_yaw_rate);
|
||||
surface_vehicle_position_setpoint.cruising_speed = _cruising_speed;
|
||||
surface_vehicle_position_setpoint.yaw = NAN;
|
||||
_surface_vehicle_position_setpoint_pub.publish(surface_vehicle_position_setpoint);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void BoatRudderAutoMode::updateWaypointsAndAcceptanceRadius()
|
||||
{
|
||||
position_setpoint_triplet_s position_setpoint_triplet{};
|
||||
_position_setpoint_triplet_sub.copy(&position_setpoint_triplet);
|
||||
_curr_wp_type = position_setpoint_triplet.current.type;
|
||||
|
||||
SurfaceVehicleControl::globalToLocalSetpointTriplet(_curr_wp_ned, _prev_wp_ned, _next_wp_ned, position_setpoint_triplet,
|
||||
_curr_pos_ned, _global_ned_proj_ref);
|
||||
|
||||
_waypoint_transition_angle = SurfaceVehicleControl::calcWaypointTransitionAngle(_prev_wp_ned, _curr_wp_ned,
|
||||
_next_wp_ned);
|
||||
|
||||
// Update acceptance radius
|
||||
if (_param_br_acc_rad_max.get() >= _param_nav_acc_rad.get()) {
|
||||
_acceptance_radius = updateAcceptanceRadius(_waypoint_transition_angle, _param_nav_acc_rad.get(),
|
||||
_param_br_acc_rad_gain.get(), _param_br_acc_rad_max.get(), _param_br_wheel_base.get(), _param_br_max_str_ang.get());
|
||||
|
||||
} else {
|
||||
_acceptance_radius = _param_nav_acc_rad.get();
|
||||
}
|
||||
|
||||
// Waypoint cruising speed
|
||||
_cruising_speed = position_setpoint_triplet.current.cruising_speed > 0.f ? math::constrain(
|
||||
position_setpoint_triplet.current.cruising_speed, 0.f, _param_sv_speed_limit.get()) : _param_sv_speed_limit.get();
|
||||
}
|
||||
|
||||
float BoatRudderAutoMode::updateAcceptanceRadius(const float waypoint_transition_angle,
|
||||
const float default_acceptance_radius, const float acceptance_radius_gain,
|
||||
const float acceptance_radius_max, const float wheel_base, const float max_steer_angle)
|
||||
{
|
||||
// Calculate acceptance radius s.t. the rover cuts the corner tangential to the current and next line segment
|
||||
float acceptance_radius = default_acceptance_radius;
|
||||
|
||||
if (PX4_ISFINITE(_waypoint_transition_angle)) {
|
||||
const float theta = waypoint_transition_angle / 2.f;
|
||||
const float min_turning_radius = wheel_base / sinf(max_steer_angle);
|
||||
const float acceptance_radius_temp = min_turning_radius / tanf(theta);
|
||||
const float acceptance_radius_temp_scaled = acceptance_radius_gain *
|
||||
acceptance_radius_temp; // Scale geometric ideal acceptance radius to account for kinematic and dynamic effects
|
||||
acceptance_radius = math::constrain<float>(acceptance_radius_temp_scaled, default_acceptance_radius,
|
||||
acceptance_radius_max);
|
||||
}
|
||||
|
||||
// Publish updated acceptance radius
|
||||
position_controller_status_s pos_ctrl_status{};
|
||||
pos_ctrl_status.acceptance_radius = acceptance_radius;
|
||||
pos_ctrl_status.timestamp = hrt_absolute_time();
|
||||
_position_controller_status_pub.publish(pos_ctrl_status);
|
||||
return acceptance_radius;
|
||||
}
|
||||
|
||||
float BoatRudderAutoMode::arrivalSpeed(const float cruising_speed, const float min_speed, const float acc_rad,
|
||||
const int curr_wp_type, const float waypoint_transition_angle, const float max_yaw_rate)
|
||||
{
|
||||
if (!PX4_ISFINITE(waypoint_transition_angle)
|
||||
|| curr_wp_type == position_setpoint_s::SETPOINT_TYPE_LAND
|
||||
|| curr_wp_type == position_setpoint_s::SETPOINT_TYPE_IDLE) {
|
||||
return 0.f; // Stop at the waypoint
|
||||
|
||||
} else if (_param_sv_speed_red.get() > FLT_EPSILON) {
|
||||
const float speed_reduction = math::constrain(_param_sv_speed_red.get() * math::interpolate(
|
||||
M_PI_F - waypoint_transition_angle,
|
||||
0.f, M_PI_F, 0.f, 1.f), 0.f, 1.f);
|
||||
return math::constrain(_param_sv_max_thr_speed.get() * (1.f - speed_reduction), min_speed,
|
||||
cruising_speed); // Slow down for cornering
|
||||
}
|
||||
|
||||
return cruising_speed; // Fallthrough
|
||||
}
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
// PX4 includes
|
||||
#include <px4_platform_common/module_params.h>
|
||||
|
||||
// Libraries
|
||||
#include <lib/surface_vehicle_control/SurfaceVehicleControl.hpp>
|
||||
#include <math.h>
|
||||
|
||||
// uORB includes
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/topics/vehicle_local_position.h>
|
||||
#include <uORB/topics/position_setpoint_triplet.h>
|
||||
#include <uORB/topics/position_controller_status.h>
|
||||
#include <uORB/topics/surface_vehicle_position_setpoint.h>
|
||||
|
||||
/**
|
||||
* @brief Class for auto mode for rudder-steered boats.
|
||||
*/
|
||||
class BoatRudderAutoMode : public ModuleParams
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor for auto mode.
|
||||
* @param parent The parent ModuleParams object.
|
||||
*/
|
||||
BoatRudderAutoMode(ModuleParams *parent);
|
||||
~BoatRudderAutoMode() = default;
|
||||
|
||||
/**
|
||||
* @brief Generate and publish SurfaceVehiclePositionSetpoint from positionSetpointTriplet.
|
||||
*/
|
||||
void autoControl();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Update the parameters of the module.
|
||||
*/
|
||||
void updateParams() override;
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Update global/NED waypoint coordinates and acceptance radius.
|
||||
*/
|
||||
void updateWaypointsAndAcceptanceRadius();
|
||||
|
||||
/**
|
||||
* @brief Publish the acceptance radius for current waypoint based on the angle between a line segment
|
||||
* from the previous to the current waypoint/current to the next waypoint and maximum steer angle of the vehicle.
|
||||
* @param waypoint_transition_angle Angle between the prevWP-currWP and currWP-nextWP line segments [rad]
|
||||
* @param default_acceptance_radius Default acceptance radius for waypoints [m].
|
||||
* @param acceptance_radius_gain Tuning parameter that scales the geometric optimal acceptance radius for the corner cutting [-].
|
||||
* @param acceptance_radius_max Maximum value for the acceptance radius [m].
|
||||
* @param wheel_base Rover wheelbase [m].
|
||||
* @param max_steer_angle Rover maximum steer angle [rad].
|
||||
* @return Updated acceptance radius [m].
|
||||
*/
|
||||
float updateAcceptanceRadius(float waypoint_transition_angle, float default_acceptance_radius,
|
||||
float acceptance_radius_gain, float acceptance_radius_max, float wheel_base, float max_steer_angle);
|
||||
|
||||
/**
|
||||
* @brief Calculate the speed at which the rover should arrive at the current waypoint based on the upcoming corner.
|
||||
* @param cruising_speed Cruising speed [m/s].
|
||||
* @param min_speed Minimum speed setpoint [m/s].
|
||||
* @param acc_rad Acceptance radius of the current waypoint [m].
|
||||
* @param curr_wp_type Type of the current waypoint.
|
||||
* @param waypoint_transition_angle Angle between the prevWP-currWP and currWP-nextWP line segments [rad]
|
||||
* @param max_yaw_rate Maximum yaw rate setpoint [rad/s]
|
||||
* @return Speed setpoint [m/s].
|
||||
*/
|
||||
float arrivalSpeed(float cruising_speed, float min_speed, float acc_rad, int curr_wp_type,
|
||||
float waypoint_transition_angle, float max_yaw_rate);
|
||||
|
||||
// uORB subscriptions
|
||||
uORB::Subscription _vehicle_local_position_sub{ORB_ID(vehicle_local_position)};
|
||||
uORB::Subscription _position_setpoint_triplet_sub{ORB_ID(position_setpoint_triplet)};
|
||||
|
||||
// uORB publications
|
||||
uORB::Publication<surface_vehicle_position_setpoint_s> _surface_vehicle_position_setpoint_pub{ORB_ID(surface_vehicle_position_setpoint)};
|
||||
uORB::Publication<position_controller_status_s> _position_controller_status_pub{ORB_ID(position_controller_status)};
|
||||
|
||||
// Variables
|
||||
MapProjection _global_ned_proj_ref{}; // Transform global to NED coordinates
|
||||
Vector2f _curr_wp_ned{NAN, NAN};
|
||||
Vector2f _prev_wp_ned{NAN, NAN};
|
||||
Vector2f _next_wp_ned{NAN, NAN};
|
||||
Vector2f _curr_pos_ned{NAN, NAN};
|
||||
float _acceptance_radius{0.5f};
|
||||
float _cruising_speed{0.f};
|
||||
float _waypoint_transition_angle{0.f}; // Angle between the prevWP-currWP and currWP-nextWP line segments [rad]
|
||||
float _max_yaw_rate{NAN};
|
||||
float _min_speed{NAN}; // Speed at which the maximum yaw rate limit is enforced given the maximum steer angle and wheel base.
|
||||
int _curr_wp_type{position_setpoint_s::SETPOINT_TYPE_IDLE};
|
||||
|
||||
DEFINE_PARAMETERS(
|
||||
(ParamFloat<px4::params::SV_YAW_RATE_LIM>) _param_sv_yaw_rate_limit,
|
||||
(ParamFloat<px4::params::SV_SPEED_LIM>) _param_sv_speed_limit,
|
||||
(ParamFloat<px4::params::BR_WHEEL_BASE>) _param_br_wheel_base,
|
||||
(ParamFloat<px4::params::BR_MAX_STR_ANG>) _param_br_max_str_ang,
|
||||
(ParamFloat<px4::params::NAV_ACC_RAD>) _param_nav_acc_rad,
|
||||
(ParamFloat<px4::params::BR_ACC_RAD_MAX>) _param_br_acc_rad_max,
|
||||
(ParamFloat<px4::params::BR_ACC_RAD_GAIN>) _param_br_acc_rad_gain,
|
||||
(ParamFloat<px4::params::SV_SPEED_RED>) _param_sv_speed_red,
|
||||
(ParamFloat<px4::params::SV_MAX_THR_SPEED>) _param_sv_max_thr_speed
|
||||
)
|
||||
};
|
||||
@@ -0,0 +1,38 @@
|
||||
############################################################################
|
||||
#
|
||||
# Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name PX4 nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
px4_add_library(BoatRudderAutoMode
|
||||
BoatRudderAutoMode.cpp
|
||||
)
|
||||
|
||||
target_include_directories(BoatRudderAutoMode PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
+227
@@ -0,0 +1,227 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "BoatRudderManualMode.hpp"
|
||||
|
||||
using namespace time_literals;
|
||||
|
||||
BoatRudderManualMode::BoatRudderManualMode(ModuleParams *parent) : ModuleParams(parent)
|
||||
{
|
||||
updateParams();
|
||||
_surface_vehicle_throttle_setpoint_pub.advertise();
|
||||
_surface_vehicle_steering_setpoint_pub.advertise();
|
||||
_surface_vehicle_rate_setpoint_pub.advertise();
|
||||
_surface_vehicle_attitude_setpoint_pub.advertise();
|
||||
_surface_vehicle_speed_setpoint_pub.advertise();
|
||||
_surface_vehicle_position_setpoint_pub.advertise();
|
||||
}
|
||||
|
||||
void BoatRudderManualMode::updateParams()
|
||||
{
|
||||
ModuleParams::updateParams();
|
||||
_max_yaw_rate = _param_sv_yaw_rate_limit.get() * M_DEG_TO_RAD_F;
|
||||
}
|
||||
|
||||
void BoatRudderManualMode::manual()
|
||||
{
|
||||
manual_control_setpoint_s manual_control_setpoint{};
|
||||
_manual_control_setpoint_sub.copy(&manual_control_setpoint);
|
||||
surface_vehicle_steering_setpoint_s surface_vehicle_steering_setpoint{};
|
||||
surface_vehicle_steering_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_steering_setpoint.normalized_steering_setpoint = manual_control_setpoint.roll;
|
||||
_surface_vehicle_steering_setpoint_pub.publish(surface_vehicle_steering_setpoint);
|
||||
surface_vehicle_throttle_setpoint_s surface_vehicle_throttle_setpoint{};
|
||||
surface_vehicle_throttle_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_throttle_setpoint.throttle_body_x = manual_control_setpoint.throttle;
|
||||
surface_vehicle_throttle_setpoint.throttle_body_y = 0.f;
|
||||
_surface_vehicle_throttle_setpoint_pub.publish(surface_vehicle_throttle_setpoint);
|
||||
}
|
||||
|
||||
void BoatRudderManualMode::acro()
|
||||
{
|
||||
manual_control_setpoint_s manual_control_setpoint{};
|
||||
_manual_control_setpoint_sub.copy(&manual_control_setpoint);
|
||||
surface_vehicle_throttle_setpoint_s surface_vehicle_throttle_setpoint{};
|
||||
surface_vehicle_throttle_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_throttle_setpoint.throttle_body_x = manual_control_setpoint.throttle;
|
||||
surface_vehicle_throttle_setpoint.throttle_body_y = 0.f;
|
||||
_surface_vehicle_throttle_setpoint_pub.publish(surface_vehicle_throttle_setpoint);
|
||||
surface_vehicle_rate_setpoint_s surface_vehicle_rate_setpoint{};
|
||||
surface_vehicle_rate_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_rate_setpoint.yaw_rate_setpoint = matrix::sign(manual_control_setpoint.throttle) * _max_yaw_rate *
|
||||
math::superexpo<float>
|
||||
(manual_control_setpoint.roll, _param_sv_yaw_expo.get(), _param_sv_yaw_supexpo.get());
|
||||
_surface_vehicle_rate_setpoint_pub.publish(surface_vehicle_rate_setpoint);
|
||||
}
|
||||
|
||||
void BoatRudderManualMode::stab()
|
||||
{
|
||||
if (_vehicle_attitude_sub.updated()) {
|
||||
vehicle_attitude_s vehicle_attitude{};
|
||||
_vehicle_attitude_sub.copy(&vehicle_attitude);
|
||||
_vehicle_attitude_quaternion = matrix::Quatf(vehicle_attitude.q);
|
||||
_vehicle_yaw = matrix::Eulerf(_vehicle_attitude_quaternion).psi();
|
||||
}
|
||||
|
||||
manual_control_setpoint_s manual_control_setpoint{};
|
||||
_manual_control_setpoint_sub.copy(&manual_control_setpoint);
|
||||
surface_vehicle_throttle_setpoint_s surface_vehicle_throttle_setpoint{};
|
||||
surface_vehicle_throttle_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_throttle_setpoint.throttle_body_x = manual_control_setpoint.throttle;
|
||||
surface_vehicle_throttle_setpoint.throttle_body_y = 0.f;
|
||||
_surface_vehicle_throttle_setpoint_pub.publish(surface_vehicle_throttle_setpoint);
|
||||
|
||||
if (fabsf(manual_control_setpoint.roll) > FLT_EPSILON
|
||||
|| fabsf(surface_vehicle_throttle_setpoint.throttle_body_x) < FLT_EPSILON) {
|
||||
_stab_yaw_setpoint = NAN;
|
||||
|
||||
// Rate control
|
||||
surface_vehicle_rate_setpoint_s surface_vehicle_rate_setpoint{};
|
||||
surface_vehicle_rate_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_rate_setpoint.yaw_rate_setpoint = matrix::sign(manual_control_setpoint.throttle) * _max_yaw_rate *
|
||||
math::superexpo<float>(math::deadzone(manual_control_setpoint.roll,
|
||||
_param_sv_yaw_stick_dz.get()), _param_sv_yaw_expo.get(), _param_sv_yaw_supexpo.get());
|
||||
_surface_vehicle_rate_setpoint_pub.publish(surface_vehicle_rate_setpoint);
|
||||
|
||||
// Set uncontrolled setpoint invalid
|
||||
surface_vehicle_attitude_setpoint_s surface_vehicle_attitude_setpoint{};
|
||||
surface_vehicle_attitude_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_attitude_setpoint.yaw_setpoint = NAN;
|
||||
_surface_vehicle_attitude_setpoint_pub.publish(surface_vehicle_attitude_setpoint);
|
||||
|
||||
} else { // Heading control
|
||||
if (!PX4_ISFINITE(_stab_yaw_setpoint)) {
|
||||
_stab_yaw_setpoint = _vehicle_yaw;
|
||||
}
|
||||
|
||||
surface_vehicle_attitude_setpoint_s surface_vehicle_attitude_setpoint{};
|
||||
surface_vehicle_attitude_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_attitude_setpoint.yaw_setpoint = _stab_yaw_setpoint;
|
||||
_surface_vehicle_attitude_setpoint_pub.publish(surface_vehicle_attitude_setpoint);
|
||||
}
|
||||
}
|
||||
|
||||
void BoatRudderManualMode::position()
|
||||
{
|
||||
if (_vehicle_attitude_sub.updated()) {
|
||||
vehicle_attitude_s vehicle_attitude{};
|
||||
_vehicle_attitude_sub.copy(&vehicle_attitude);
|
||||
_vehicle_attitude_quaternion = matrix::Quatf(vehicle_attitude.q);
|
||||
_vehicle_yaw = matrix::Eulerf(_vehicle_attitude_quaternion).psi();
|
||||
}
|
||||
|
||||
if (_vehicle_local_position_sub.updated()) {
|
||||
vehicle_local_position_s vehicle_local_position{};
|
||||
_vehicle_local_position_sub.copy(&vehicle_local_position);
|
||||
|
||||
if (!_global_ned_proj_ref.isInitialized()
|
||||
|| (_global_ned_proj_ref.getProjectionReferenceTimestamp() != vehicle_local_position.ref_timestamp)) {
|
||||
_global_ned_proj_ref.initReference(vehicle_local_position.ref_lat, vehicle_local_position.ref_lon,
|
||||
vehicle_local_position.ref_timestamp);
|
||||
}
|
||||
|
||||
_curr_pos_ned = Vector2f(vehicle_local_position.x, vehicle_local_position.y);
|
||||
}
|
||||
|
||||
manual_control_setpoint_s manual_control_setpoint{};
|
||||
_manual_control_setpoint_sub.copy(&manual_control_setpoint);
|
||||
|
||||
const float speed_setpoint = math::interpolate<float>(manual_control_setpoint.throttle,
|
||||
-1.f, 1.f, -_param_sv_speed_limit.get(), _param_sv_speed_limit.get());
|
||||
|
||||
if (fabsf(manual_control_setpoint.roll) > FLT_EPSILON
|
||||
|| fabsf(speed_setpoint) < FLT_EPSILON) {
|
||||
_pos_ctl_course_direction = Vector2f(NAN, NAN);
|
||||
|
||||
// Speed control
|
||||
surface_vehicle_speed_setpoint_s surface_vehicle_speed_setpoint{};
|
||||
surface_vehicle_speed_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_speed_setpoint.speed_body_x = speed_setpoint;
|
||||
_surface_vehicle_speed_setpoint_pub.publish(surface_vehicle_speed_setpoint);
|
||||
|
||||
// Rate control
|
||||
surface_vehicle_rate_setpoint_s surface_vehicle_rate_setpoint{};
|
||||
surface_vehicle_rate_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_rate_setpoint.yaw_rate_setpoint = matrix::sign(manual_control_setpoint.throttle) * _max_yaw_rate *
|
||||
math::superexpo<float>(math::deadzone(manual_control_setpoint.roll,
|
||||
_param_sv_yaw_stick_dz.get()), _param_sv_yaw_expo.get(), _param_sv_yaw_supexpo.get());
|
||||
_surface_vehicle_rate_setpoint_pub.publish(surface_vehicle_rate_setpoint);
|
||||
|
||||
// Set uncontrolled setpoints invalid
|
||||
surface_vehicle_attitude_setpoint_s surface_vehicle_attitude_setpoint{};
|
||||
surface_vehicle_attitude_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_attitude_setpoint.yaw_setpoint = NAN;
|
||||
_surface_vehicle_attitude_setpoint_pub.publish(surface_vehicle_attitude_setpoint);
|
||||
|
||||
surface_vehicle_position_setpoint_s surface_vehicle_position_setpoint{};
|
||||
surface_vehicle_position_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_position_setpoint.position_ned[0] = NAN;
|
||||
surface_vehicle_position_setpoint.position_ned[1] = NAN;
|
||||
surface_vehicle_position_setpoint.start_ned[0] = NAN;
|
||||
surface_vehicle_position_setpoint.start_ned[1] = NAN;
|
||||
surface_vehicle_position_setpoint.arrival_speed = NAN;
|
||||
surface_vehicle_position_setpoint.cruising_speed = NAN;
|
||||
surface_vehicle_position_setpoint.yaw = NAN;
|
||||
_surface_vehicle_position_setpoint_pub.publish(surface_vehicle_position_setpoint);
|
||||
|
||||
} else { // Course control
|
||||
if (!_pos_ctl_course_direction.isAllFinite()) {
|
||||
_pos_ctl_course_direction = Vector2f(cos(_vehicle_yaw), sin(_vehicle_yaw));
|
||||
_pos_ctl_start_position_ned = _curr_pos_ned;
|
||||
}
|
||||
|
||||
// Construct a 'target waypoint' for course control s.t. it is never within the maximum lookahead of the rover
|
||||
const Vector2f start_to_curr_pos = _curr_pos_ned - _pos_ctl_start_position_ned;
|
||||
const float vector_scaling = fabsf(start_to_curr_pos * _pos_ctl_course_direction) + _param_pp_lookahd_max.get();
|
||||
const Vector2f target_waypoint_ned = _pos_ctl_start_position_ned + sign(speed_setpoint) *
|
||||
vector_scaling * _pos_ctl_course_direction;
|
||||
surface_vehicle_position_setpoint_s surface_vehicle_position_setpoint{};
|
||||
surface_vehicle_position_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_position_setpoint.position_ned[0] = target_waypoint_ned(0);
|
||||
surface_vehicle_position_setpoint.position_ned[1] = target_waypoint_ned(1);
|
||||
surface_vehicle_position_setpoint.start_ned[0] = _pos_ctl_start_position_ned(0);
|
||||
surface_vehicle_position_setpoint.start_ned[1] = _pos_ctl_start_position_ned(1);
|
||||
surface_vehicle_position_setpoint.arrival_speed = NAN;
|
||||
surface_vehicle_position_setpoint.cruising_speed = speed_setpoint;
|
||||
surface_vehicle_position_setpoint.yaw = NAN;
|
||||
_surface_vehicle_position_setpoint_pub.publish(surface_vehicle_position_setpoint);
|
||||
}
|
||||
}
|
||||
|
||||
void BoatRudderManualMode::reset()
|
||||
{
|
||||
_stab_yaw_setpoint = NAN;
|
||||
_pos_ctl_course_direction = Vector2f(NAN, NAN);
|
||||
_pos_ctl_start_position_ned = Vector2f(NAN, NAN);
|
||||
_curr_pos_ned = Vector2f(NAN, NAN);
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
// PX4 includes
|
||||
#include <px4_platform_common/module_params.h>
|
||||
|
||||
// Libraries
|
||||
#include <lib/surface_vehicle_control/SurfaceVehicleControl.hpp>
|
||||
#include <math.h>
|
||||
|
||||
// uORB includes
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/topics/manual_control_setpoint.h>
|
||||
#include <uORB/topics/vehicle_status.h>
|
||||
#include <uORB/topics/vehicle_attitude.h>
|
||||
#include <uORB/topics/vehicle_local_position.h>
|
||||
#include <uORB/topics/surface_vehicle_throttle_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_steering_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_rate_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_attitude_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_speed_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_position_setpoint.h>
|
||||
|
||||
/**
|
||||
* @brief Class for manual modes for rudder-steered boats.
|
||||
*/
|
||||
class BoatRudderManualMode : public ModuleParams
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor for BoatRudderManualMode.
|
||||
* @param parent The parent ModuleParams object.
|
||||
*/
|
||||
BoatRudderManualMode(ModuleParams *parent);
|
||||
~BoatRudderManualMode() = default;
|
||||
|
||||
/**
|
||||
* @brief Publish SurfaceVehicleThrottleSetpoint and SurfaceVehicleSteeringSetpoint from manualControlSetpoint.
|
||||
*/
|
||||
void manual();
|
||||
|
||||
/**
|
||||
* @brief Generate and publish SurfaceVehicleThrottleSetpoint and SurfaceVehicleRateSetpoint from manualControlSetpoint.
|
||||
*/
|
||||
void acro();
|
||||
|
||||
/**
|
||||
* @brief Generate and publish SurfaceVehicleThrottleSetpoint and SurfaceVehicleAttitudeSetpoint from manualControlSetpoint.
|
||||
*/
|
||||
void stab();
|
||||
|
||||
/**
|
||||
* @brief Generate and publish SurfaceVehicleSpeedSetpoint/SurfaceVehicleRateSetpoint or SurfaceVehiclePositionSetpoint from manualControlSetpoint.
|
||||
*/
|
||||
void position();
|
||||
|
||||
/**
|
||||
* @brief Reset manual mode variables.
|
||||
*/
|
||||
void reset();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Update the parameters of the module.
|
||||
*/
|
||||
void updateParams() override;
|
||||
|
||||
private:
|
||||
// uORB subscriptions
|
||||
uORB::Subscription _vehicle_attitude_sub{ORB_ID(vehicle_attitude)};
|
||||
uORB::Subscription _manual_control_setpoint_sub{ORB_ID(manual_control_setpoint)};
|
||||
uORB::Subscription _vehicle_local_position_sub{ORB_ID(vehicle_local_position)};
|
||||
|
||||
// uORB publications
|
||||
uORB::Publication<surface_vehicle_throttle_setpoint_s> _surface_vehicle_throttle_setpoint_pub{ORB_ID(surface_vehicle_throttle_setpoint)};
|
||||
uORB::Publication<surface_vehicle_steering_setpoint_s> _surface_vehicle_steering_setpoint_pub{ORB_ID(surface_vehicle_steering_setpoint)};
|
||||
uORB::Publication<surface_vehicle_rate_setpoint_s> _surface_vehicle_rate_setpoint_pub{ORB_ID(surface_vehicle_rate_setpoint)};
|
||||
uORB::Publication<surface_vehicle_attitude_setpoint_s> _surface_vehicle_attitude_setpoint_pub{ORB_ID(surface_vehicle_attitude_setpoint)};
|
||||
uORB::Publication<surface_vehicle_speed_setpoint_s> _surface_vehicle_speed_setpoint_pub{ORB_ID(surface_vehicle_speed_setpoint)};
|
||||
uORB::Publication<surface_vehicle_position_setpoint_s> _surface_vehicle_position_setpoint_pub{ORB_ID(surface_vehicle_position_setpoint)};
|
||||
|
||||
// Variables
|
||||
MapProjection _global_ned_proj_ref{}; // Transform global to NED coordinates
|
||||
Quatf _vehicle_attitude_quaternion{};
|
||||
Vector2f _pos_ctl_course_direction{NAN, NAN};
|
||||
Vector2f _pos_ctl_start_position_ned{NAN, NAN};
|
||||
Vector2f _curr_pos_ned{NAN, NAN};
|
||||
float _stab_yaw_setpoint{NAN};
|
||||
float _vehicle_yaw{NAN};
|
||||
float _max_yaw_rate{NAN};
|
||||
|
||||
DEFINE_PARAMETERS(
|
||||
(ParamFloat<px4::params::SV_YAW_RATE_LIM>) _param_sv_yaw_rate_limit,
|
||||
(ParamFloat<px4::params::SV_YAW_P>) _param_sv_yaw_p,
|
||||
(ParamFloat<px4::params::SV_YAW_STICK_DZ>) _param_sv_yaw_stick_dz,
|
||||
(ParamFloat<px4::params::SV_YAW_EXPO>) _param_sv_yaw_expo,
|
||||
(ParamFloat<px4::params::SV_YAW_SUPEXPO>) _param_sv_yaw_supexpo,
|
||||
(ParamFloat<px4::params::PP_LOOKAHD_MAX>) _param_pp_lookahd_max,
|
||||
(ParamFloat<px4::params::SV_SPEED_LIM>) _param_sv_speed_limit
|
||||
)
|
||||
};
|
||||
@@ -0,0 +1,38 @@
|
||||
############################################################################
|
||||
#
|
||||
# Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name PX4 nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
px4_add_library(BoatRudderManualMode
|
||||
BoatRudderManualMode.cpp
|
||||
)
|
||||
|
||||
target_include_directories(BoatRudderManualMode PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "BoatRudderOffboardMode.hpp"
|
||||
|
||||
using namespace time_literals;
|
||||
|
||||
BoatRudderOffboardMode::BoatRudderOffboardMode(ModuleParams *parent) : ModuleParams(parent)
|
||||
{
|
||||
updateParams();
|
||||
_surface_vehicle_speed_setpoint_pub.advertise();
|
||||
_surface_vehicle_position_setpoint_pub.advertise();
|
||||
_surface_vehicle_attitude_setpoint_pub.advertise();
|
||||
}
|
||||
|
||||
void BoatRudderOffboardMode::updateParams()
|
||||
{
|
||||
ModuleParams::updateParams();
|
||||
}
|
||||
|
||||
void BoatRudderOffboardMode::offboardControl()
|
||||
{
|
||||
offboard_control_mode_s offboard_control_mode{};
|
||||
_offboard_control_mode_sub.copy(&offboard_control_mode);
|
||||
|
||||
trajectory_setpoint_s trajectory_setpoint{};
|
||||
_trajectory_setpoint_sub.copy(&trajectory_setpoint);
|
||||
|
||||
if (offboard_control_mode.position) {
|
||||
surface_vehicle_position_setpoint_s surface_vehicle_position_setpoint{};
|
||||
surface_vehicle_position_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_position_setpoint.position_ned[0] = trajectory_setpoint.position[0];
|
||||
surface_vehicle_position_setpoint.position_ned[1] = trajectory_setpoint.position[1];
|
||||
surface_vehicle_position_setpoint.start_ned[0] = NAN;
|
||||
surface_vehicle_position_setpoint.start_ned[1] = NAN;
|
||||
surface_vehicle_position_setpoint.cruising_speed = NAN;
|
||||
surface_vehicle_position_setpoint.arrival_speed = NAN;
|
||||
surface_vehicle_position_setpoint.yaw = NAN;
|
||||
_surface_vehicle_position_setpoint_pub.publish(surface_vehicle_position_setpoint);
|
||||
|
||||
} else if (offboard_control_mode.velocity) {
|
||||
const Vector2f velocity_ned(trajectory_setpoint.velocity[0], trajectory_setpoint.velocity[1]);
|
||||
surface_vehicle_speed_setpoint_s surface_vehicle_speed_setpoint{};
|
||||
surface_vehicle_speed_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_speed_setpoint.speed_body_x = velocity_ned.norm();
|
||||
_surface_vehicle_speed_setpoint_pub.publish(surface_vehicle_speed_setpoint);
|
||||
surface_vehicle_attitude_setpoint_s surface_vehicle_attitude_setpoint{};
|
||||
surface_vehicle_attitude_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_attitude_setpoint.yaw_setpoint = atan2f(velocity_ned(1), velocity_ned(0));
|
||||
_surface_vehicle_attitude_setpoint_pub.publish(surface_vehicle_attitude_setpoint);
|
||||
}
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
// PX4 includes
|
||||
#include <px4_platform_common/module_params.h>
|
||||
|
||||
// Libraries
|
||||
#include <math.h>
|
||||
#include <matrix/matrix/math.hpp>
|
||||
|
||||
// uORB includes
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/topics/surface_vehicle_speed_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_attitude_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_position_setpoint.h>
|
||||
#include <uORB/topics/offboard_control_mode.h>
|
||||
#include <uORB/topics/trajectory_setpoint.h>
|
||||
|
||||
using namespace matrix;
|
||||
|
||||
/**
|
||||
* @brief Class for offboard mode for rudder-steered boats.
|
||||
*/
|
||||
class BoatRudderOffboardMode : public ModuleParams
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor for BoatRudderOffboardMode.
|
||||
* @param parent The parent ModuleParams object.
|
||||
*/
|
||||
BoatRudderOffboardMode(ModuleParams *parent);
|
||||
~BoatRudderOffboardMode() = default;
|
||||
|
||||
/**
|
||||
* @brief Generate and publish roverSetpoints from trajectorySetpoint.
|
||||
*/
|
||||
void offboardControl();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Update the parameters of the module.
|
||||
*/
|
||||
void updateParams() override;
|
||||
|
||||
private:
|
||||
// uORB subscriptions
|
||||
uORB::Subscription _trajectory_setpoint_sub{ORB_ID(trajectory_setpoint)};
|
||||
uORB::Subscription _offboard_control_mode_sub{ORB_ID(offboard_control_mode)};
|
||||
|
||||
// uORB publications
|
||||
uORB::Publication<surface_vehicle_speed_setpoint_s> _surface_vehicle_speed_setpoint_pub{ORB_ID(surface_vehicle_speed_setpoint)};
|
||||
uORB::Publication<surface_vehicle_position_setpoint_s> _surface_vehicle_position_setpoint_pub{ORB_ID(surface_vehicle_position_setpoint)};
|
||||
uORB::Publication<surface_vehicle_attitude_setpoint_s> _surface_vehicle_attitude_setpoint_pub{ORB_ID(surface_vehicle_attitude_setpoint)};
|
||||
};
|
||||
@@ -0,0 +1,38 @@
|
||||
############################################################################
|
||||
#
|
||||
# Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name PX4 nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
px4_add_library(BoatRudderOffboardMode
|
||||
BoatRudderOffboardMode.cpp
|
||||
)
|
||||
|
||||
target_include_directories(BoatRudderOffboardMode PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
@@ -0,0 +1,36 @@
|
||||
############################################################################
|
||||
#
|
||||
# Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name PX4 nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
add_subdirectory(BoatRudderAutoMode)
|
||||
add_subdirectory(BoatRudderManualMode)
|
||||
add_subdirectory(BoatRudderOffboardMode)
|
||||
@@ -0,0 +1,176 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "BoatRudderPosControl.hpp"
|
||||
|
||||
using namespace time_literals;
|
||||
|
||||
BoatRudderPosControl::BoatRudderPosControl(ModuleParams *parent) : ModuleParams(parent)
|
||||
{
|
||||
_pure_pursuit_status_pub.advertise();
|
||||
_surface_vehicle_speed_setpoint_pub.advertise();
|
||||
_surface_vehicle_attitude_setpoint_pub.advertise();
|
||||
|
||||
updateParams();
|
||||
}
|
||||
|
||||
void BoatRudderPosControl::updateParams()
|
||||
{
|
||||
ModuleParams::updateParams();
|
||||
_max_yaw_rate = _param_sv_yaw_rate_limit.get() * M_DEG_TO_RAD_F;
|
||||
_min_speed = _param_br_wheel_base.get() * _max_yaw_rate / tanf(_param_br_max_str_ang.get());
|
||||
|
||||
}
|
||||
|
||||
void BoatRudderPosControl::updatePosControl()
|
||||
{
|
||||
updateSubscriptions();
|
||||
|
||||
hrt_abstime timestamp = hrt_absolute_time();
|
||||
|
||||
if (_target_waypoint_ned.isAllFinite()) {
|
||||
float distance_to_target = (_target_waypoint_ned - _curr_pos_ned).norm();
|
||||
|
||||
if (_arrival_speed > FLT_EPSILON) {
|
||||
distance_to_target -= _acceptance_radius; // shift target to the edge of the acceptance radius if arrival speed not zero
|
||||
}
|
||||
|
||||
if (distance_to_target > _acceptance_radius || _arrival_speed > FLT_EPSILON) {
|
||||
|
||||
float speed_setpoint = math::trajectory::computeMaxSpeedFromDistance(_param_sv_jerk_limit.get(),
|
||||
_param_sv_decel_limit.get(), distance_to_target, fabsf(_arrival_speed));
|
||||
speed_setpoint = math::min(speed_setpoint, _cruising_speed);
|
||||
|
||||
pure_pursuit_status_s pure_pursuit_status{};
|
||||
pure_pursuit_status.timestamp = timestamp;
|
||||
|
||||
const float bearing_setpoint = PurePursuit::calcTargetBearing(pure_pursuit_status, _param_pp_lookahd_gain.get(),
|
||||
_param_pp_lookahd_max.get(), _param_pp_lookahd_min.get(), _target_waypoint_ned, _start_ned,
|
||||
_curr_pos_ned, fabsf(speed_setpoint));
|
||||
|
||||
if (_param_sv_speed_red.get() > FLT_EPSILON) {
|
||||
const float course_error = fabsf(matrix::wrap_pi(bearing_setpoint - _vehicle_yaw));
|
||||
const float speed_reduction = math::constrain(_param_sv_speed_red.get() * math::interpolate(course_error,
|
||||
0.f, M_PI_F, 0.f, 1.f), 0.f, 1.f);
|
||||
const float max_speed = math::constrain(_param_sv_max_thr_speed.get() * (1.f - speed_reduction), _min_speed,
|
||||
_param_sv_max_thr_speed.get());
|
||||
speed_setpoint = math::constrain(speed_setpoint, -max_speed, max_speed);
|
||||
}
|
||||
|
||||
_pure_pursuit_status_pub.publish(pure_pursuit_status);
|
||||
surface_vehicle_speed_setpoint_s surface_vehicle_speed_setpoint{};
|
||||
surface_vehicle_speed_setpoint.timestamp = timestamp;
|
||||
surface_vehicle_speed_setpoint.speed_body_x = speed_setpoint;
|
||||
_surface_vehicle_speed_setpoint_pub.publish(surface_vehicle_speed_setpoint);
|
||||
surface_vehicle_attitude_setpoint_s surface_vehicle_attitude_setpoint{};
|
||||
surface_vehicle_attitude_setpoint.timestamp = timestamp;
|
||||
surface_vehicle_attitude_setpoint.yaw_setpoint = speed_setpoint > -FLT_EPSILON ? bearing_setpoint : matrix::wrap_pi(
|
||||
bearing_setpoint + M_PI_F);
|
||||
_surface_vehicle_attitude_setpoint_pub.publish(surface_vehicle_attitude_setpoint);
|
||||
|
||||
} else {
|
||||
surface_vehicle_speed_setpoint_s surface_vehicle_speed_setpoint{};
|
||||
surface_vehicle_speed_setpoint.timestamp = timestamp;
|
||||
surface_vehicle_speed_setpoint.speed_body_x = 0.f;
|
||||
_surface_vehicle_speed_setpoint_pub.publish(surface_vehicle_speed_setpoint);
|
||||
surface_vehicle_attitude_setpoint_s surface_vehicle_attitude_setpoint{};
|
||||
surface_vehicle_attitude_setpoint.timestamp = timestamp;
|
||||
surface_vehicle_attitude_setpoint.yaw_setpoint = _vehicle_yaw;
|
||||
_surface_vehicle_attitude_setpoint_pub.publish(surface_vehicle_attitude_setpoint);
|
||||
|
||||
if (!_stopped && fabsf(_vehicle_speed) < FLT_EPSILON) {
|
||||
_stopped = true;
|
||||
_target_waypoint_ned = _curr_pos_ned;
|
||||
}
|
||||
|
||||
if (_stopped && _updated_reset_counter != _reset_counter) {
|
||||
_target_waypoint_ned = _curr_pos_ned;
|
||||
_reset_counter = _updated_reset_counter;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BoatRudderPosControl::updateSubscriptions()
|
||||
{
|
||||
if (_position_controller_status_sub.updated()) {
|
||||
position_controller_status_s position_controller_status{};
|
||||
_position_controller_status_sub.copy(&position_controller_status);
|
||||
_acceptance_radius = position_controller_status.acceptance_radius;
|
||||
}
|
||||
|
||||
if (_vehicle_attitude_sub.updated()) {
|
||||
vehicle_attitude_s vehicle_attitude{};
|
||||
_vehicle_attitude_sub.copy(&vehicle_attitude);
|
||||
_vehicle_attitude_quaternion = matrix::Quatf(vehicle_attitude.q);
|
||||
_vehicle_yaw = matrix::Eulerf(_vehicle_attitude_quaternion).psi();
|
||||
}
|
||||
|
||||
if (_vehicle_local_position_sub.updated()) {
|
||||
vehicle_local_position_s vehicle_local_position{};
|
||||
_vehicle_local_position_sub.copy(&vehicle_local_position);
|
||||
_updated_reset_counter = vehicle_local_position.xy_reset_counter;
|
||||
_curr_pos_ned = Vector2f(vehicle_local_position.x, vehicle_local_position.y);
|
||||
Vector3f velocity_ned(vehicle_local_position.vx, vehicle_local_position.vy, vehicle_local_position.vz);
|
||||
Vector3f velocity_xyz = _vehicle_attitude_quaternion.rotateVectorInverse(velocity_ned);
|
||||
Vector2f velocity_2d = Vector2f(velocity_xyz(0), velocity_xyz(1));
|
||||
_vehicle_speed = velocity_2d.norm() > _param_sv_speed_th.get() ? sign(velocity_2d(0)) * velocity_2d.norm() : 0.f;
|
||||
}
|
||||
|
||||
if (_surface_vehicle_position_setpoint_sub.updated()) {
|
||||
surface_vehicle_position_setpoint_s surface_vehicle_position_setpoint;
|
||||
_surface_vehicle_position_setpoint_sub.copy(&surface_vehicle_position_setpoint);
|
||||
_start_ned = Vector2f(surface_vehicle_position_setpoint.start_ned[0], surface_vehicle_position_setpoint.start_ned[1]);
|
||||
_start_ned = _start_ned.isAllFinite() ? _start_ned : _curr_pos_ned;
|
||||
_arrival_speed = PX4_ISFINITE(surface_vehicle_position_setpoint.arrival_speed) ?
|
||||
surface_vehicle_position_setpoint.arrival_speed : 0.f;
|
||||
_cruising_speed = PX4_ISFINITE(surface_vehicle_position_setpoint.cruising_speed) ?
|
||||
surface_vehicle_position_setpoint.cruising_speed :
|
||||
_param_sv_speed_limit.get();
|
||||
_target_waypoint_ned = Vector2f(surface_vehicle_position_setpoint.position_ned[0],
|
||||
surface_vehicle_position_setpoint.position_ned[1]);
|
||||
_stopped = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool BoatRudderPosControl::runSanityChecks()
|
||||
{
|
||||
bool ret = true;
|
||||
|
||||
if (_param_sv_speed_limit.get() < FLT_EPSILON) {
|
||||
ret = false;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
// PX4 includes
|
||||
#include <px4_platform_common/module_params.h>
|
||||
#include <px4_platform_common/events.h>
|
||||
|
||||
// Library includes
|
||||
#include <matrix/matrix/math.hpp>
|
||||
#include <lib/pure_pursuit/PurePursuit.hpp>
|
||||
#include <math.h>
|
||||
|
||||
// uORB includes
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/topics/surface_vehicle_position_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_speed_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_attitude_setpoint.h>
|
||||
#include <uORB/topics/vehicle_attitude.h>
|
||||
#include <uORB/topics/vehicle_local_position.h>
|
||||
#include <uORB/topics/position_controller_status.h>
|
||||
#include <uORB/topics/pure_pursuit_status.h>
|
||||
|
||||
using namespace matrix;
|
||||
|
||||
/**
|
||||
* @brief Class for position control of rudder-steered boats.
|
||||
*/
|
||||
class BoatRudderPosControl : public ModuleParams
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor for BoatRudderPosControl.
|
||||
* @param parent The parent ModuleParams object.
|
||||
*/
|
||||
BoatRudderPosControl(ModuleParams *parent);
|
||||
~BoatRudderPosControl() = default;
|
||||
|
||||
/**
|
||||
* @brief Generate and publish SurfaceVehicleSpeedSetpoint and SurfaceVehicleAttitudeSetpoint from SurfaceVehiclePositionSetpoint.
|
||||
*/
|
||||
void updatePosControl();
|
||||
|
||||
/**
|
||||
* @brief Check if the necessary parameters are set.
|
||||
* @return True if all checks pass.
|
||||
*/
|
||||
bool runSanityChecks();
|
||||
|
||||
/**
|
||||
* @brief Reset position controller.
|
||||
*/
|
||||
void reset() {_start_ned = Vector2f{NAN, NAN}; _target_waypoint_ned = Vector2f{NAN, NAN}; _arrival_speed = 0.f; _cruising_speed = _param_sv_speed_limit.get(); _stopped = false;};
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Update the parameters of the module.
|
||||
*/
|
||||
void updateParams() override;
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Update uORB subscriptions used in position controller.
|
||||
*/
|
||||
void updateSubscriptions();
|
||||
|
||||
// uORB subscriptions
|
||||
uORB::Subscription _vehicle_attitude_sub{ORB_ID(vehicle_attitude)};
|
||||
uORB::Subscription _vehicle_local_position_sub{ORB_ID(vehicle_local_position)};
|
||||
uORB::Subscription _surface_vehicle_position_setpoint_sub{ORB_ID(surface_vehicle_position_setpoint)};
|
||||
uORB::Subscription _position_controller_status_sub{ORB_ID(position_controller_status)};
|
||||
|
||||
// uORB publications
|
||||
uORB::Publication<surface_vehicle_speed_setpoint_s> _surface_vehicle_speed_setpoint_pub{ORB_ID(surface_vehicle_speed_setpoint)};
|
||||
uORB::Publication<surface_vehicle_attitude_setpoint_s> _surface_vehicle_attitude_setpoint_pub{ORB_ID(surface_vehicle_attitude_setpoint)};
|
||||
uORB::Publication<pure_pursuit_status_s> _pure_pursuit_status_pub{ORB_ID(pure_pursuit_status)};
|
||||
|
||||
// Variables
|
||||
Quatf _vehicle_attitude_quaternion{};
|
||||
Vector2f _curr_pos_ned{};
|
||||
Vector2f _start_ned{};
|
||||
Vector2f _target_waypoint_ned{};
|
||||
float _arrival_speed{0.f};
|
||||
float _vehicle_yaw{0.f};
|
||||
float _max_yaw_rate{0.f};
|
||||
float _acceptance_radius{0.f}; // Acceptance radius for the waypoint.
|
||||
float _min_speed{NAN};
|
||||
float _vehicle_speed{0.f};
|
||||
float _cruising_speed{NAN};
|
||||
bool _stopped{false};
|
||||
uint8_t _reset_counter{0}; /**< counter for estimator resets in xy-direction */
|
||||
uint8_t _updated_reset_counter{0}; /**< counter for estimator resets in xy-direction */
|
||||
|
||||
DEFINE_PARAMETERS(
|
||||
(ParamFloat<px4::params::SV_MAX_THR_SPEED>) _param_sv_max_thr_speed,
|
||||
(ParamFloat<px4::params::SV_SPEED_RED>) _param_sv_speed_red,
|
||||
(ParamFloat<px4::params::SV_DECEL_LIM>) _param_sv_decel_limit,
|
||||
(ParamFloat<px4::params::SV_JERK_LIM>) _param_sv_jerk_limit,
|
||||
(ParamFloat<px4::params::SV_SPEED_LIM>) _param_sv_speed_limit,
|
||||
(ParamFloat<px4::params::PP_LOOKAHD_GAIN>) _param_pp_lookahd_gain,
|
||||
(ParamFloat<px4::params::PP_LOOKAHD_MAX>) _param_pp_lookahd_max,
|
||||
(ParamFloat<px4::params::PP_LOOKAHD_MIN>) _param_pp_lookahd_min,
|
||||
(ParamFloat<px4::params::SV_YAW_RATE_LIM>) _param_sv_yaw_rate_limit,
|
||||
(ParamFloat<px4::params::BR_WHEEL_BASE>) _param_br_wheel_base,
|
||||
(ParamFloat<px4::params::BR_MAX_STR_ANG>) _param_br_max_str_ang,
|
||||
(ParamFloat<px4::params::SV_SPEED_TH>) _param_sv_speed_th
|
||||
)
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
############################################################################
|
||||
#
|
||||
# Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name PX4 nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
px4_add_library(BoatRudderPosControl
|
||||
BoatRudderPosControl.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(BoatRudderPosControl PUBLIC PID)
|
||||
target_include_directories(BoatRudderPosControl PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
@@ -0,0 +1,182 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "BoatRudderRateControl.hpp"
|
||||
|
||||
using namespace time_literals;
|
||||
|
||||
BoatRudderRateControl::BoatRudderRateControl(ModuleParams *parent) : ModuleParams(parent)
|
||||
{
|
||||
_surface_vehicle_steering_setpoint_pub.advertise();
|
||||
_surface_vehicle_rate_status_pub.advertise();
|
||||
updateParams();
|
||||
}
|
||||
|
||||
void BoatRudderRateControl::updateParams()
|
||||
{
|
||||
ModuleParams::updateParams();
|
||||
_max_yaw_rate = _param_sv_yaw_rate_limit.get() * M_DEG_TO_RAD_F;
|
||||
|
||||
// Set up PID controller
|
||||
_pid_yaw_rate.setGains(_param_sv_yaw_rate_p.get(), _param_sv_yaw_rate_i.get(), 0.f);
|
||||
_pid_yaw_rate.setIntegralLimit(1.f);
|
||||
_pid_yaw_rate.setOutputLimit(1.f);
|
||||
|
||||
// Set up slew rate
|
||||
_adjusted_yaw_rate_setpoint.setSlewRate(_param_sv_yaw_accel_limit.get() * M_DEG_TO_RAD_F);
|
||||
}
|
||||
|
||||
void BoatRudderRateControl::updateRateControl()
|
||||
{
|
||||
updateSubscriptions();
|
||||
|
||||
hrt_abstime timestamp_prev = _timestamp;
|
||||
_timestamp = hrt_absolute_time();
|
||||
const float dt = math::constrain(_timestamp - timestamp_prev, 1_ms, 10_ms) * 1e-6f;
|
||||
|
||||
if (PX4_ISFINITE(_yaw_rate_setpoint)) {
|
||||
if (fabsf(_estimated_speed) > FLT_EPSILON) {
|
||||
// Set up feasible yaw rate setpoint
|
||||
float steering_setpoint{0.f};
|
||||
float max_possible_yaw_rate = fabsf(_estimated_speed) * tanf(_param_br_max_str_ang.get()) /
|
||||
_param_br_wheel_base.get(); // Maximum possible yaw rate at current velocity
|
||||
float yaw_rate_limit = math::min(max_possible_yaw_rate, _max_yaw_rate);
|
||||
float constrained_yaw_rate = math::constrain(_yaw_rate_setpoint, -yaw_rate_limit, yaw_rate_limit);
|
||||
|
||||
if (_param_sv_yaw_accel_limit.get() > FLT_EPSILON) { // Apply slew rate if configured
|
||||
if (fabsf(_adjusted_yaw_rate_setpoint.getState() - _vehicle_yaw_rate) > fabsf(constrained_yaw_rate -
|
||||
_vehicle_yaw_rate)) {
|
||||
_adjusted_yaw_rate_setpoint.setForcedValue(_vehicle_yaw_rate);
|
||||
}
|
||||
|
||||
_adjusted_yaw_rate_setpoint.update(constrained_yaw_rate, dt);
|
||||
|
||||
} else {
|
||||
_adjusted_yaw_rate_setpoint.setForcedValue(constrained_yaw_rate);
|
||||
}
|
||||
|
||||
// Feed forward
|
||||
steering_setpoint = atanf(_adjusted_yaw_rate_setpoint.getState() * _param_br_wheel_base.get() / _estimated_speed) *
|
||||
_param_sv_yaw_rate_corr.get();
|
||||
|
||||
// Feedback (Only when driving forwards because backwards driving is NMP and can introduce instability)
|
||||
if (_estimated_speed > FLT_EPSILON) {
|
||||
_pid_yaw_rate.setSetpoint(_adjusted_yaw_rate_setpoint.getState());
|
||||
steering_setpoint += _pid_yaw_rate.update(_vehicle_yaw_rate, dt);
|
||||
}
|
||||
|
||||
surface_vehicle_steering_setpoint_s surface_vehicle_steering_setpoint{};
|
||||
surface_vehicle_steering_setpoint.timestamp = _timestamp;
|
||||
surface_vehicle_steering_setpoint.normalized_steering_setpoint = math::interpolate<float>(steering_setpoint,
|
||||
-_param_br_max_str_ang.get(), _param_br_max_str_ang.get(), -1.f, 1.f); // Normalize steering setpoint
|
||||
_surface_vehicle_steering_setpoint_pub.publish(surface_vehicle_steering_setpoint);
|
||||
|
||||
} else {
|
||||
_pid_yaw_rate.resetIntegral();
|
||||
surface_vehicle_steering_setpoint_s surface_vehicle_steering_setpoint{};
|
||||
surface_vehicle_steering_setpoint.timestamp = _timestamp;
|
||||
surface_vehicle_steering_setpoint.normalized_steering_setpoint = 0.f;
|
||||
_surface_vehicle_steering_setpoint_pub.publish(surface_vehicle_steering_setpoint);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Publish rate controller status (logging only)
|
||||
surface_vehicle_rate_status_s surface_vehicle_rate_status;
|
||||
surface_vehicle_rate_status.timestamp = _timestamp;
|
||||
surface_vehicle_rate_status.measured_yaw_rate = _vehicle_yaw_rate;
|
||||
surface_vehicle_rate_status.adjusted_yaw_rate_setpoint = _adjusted_yaw_rate_setpoint.getState();
|
||||
surface_vehicle_rate_status.pid_yaw_rate_integral = _pid_yaw_rate.getIntegral();
|
||||
_surface_vehicle_rate_status_pub.publish(surface_vehicle_rate_status);
|
||||
|
||||
}
|
||||
|
||||
void BoatRudderRateControl::updateSubscriptions()
|
||||
{
|
||||
if (_vehicle_angular_velocity_sub.updated()) {
|
||||
vehicle_angular_velocity_s vehicle_angular_velocity{};
|
||||
_vehicle_angular_velocity_sub.copy(&vehicle_angular_velocity);
|
||||
_vehicle_yaw_rate = fabsf(vehicle_angular_velocity.xyz[2]) > _param_sv_yaw_rate_th.get() * M_DEG_TO_RAD_F ?
|
||||
vehicle_angular_velocity.xyz[2] : 0.f;
|
||||
}
|
||||
|
||||
// Estimate forward speed based on throttle
|
||||
if (_actuator_motors_sub.updated()) {
|
||||
actuator_motors_s actuator_motors;
|
||||
_actuator_motors_sub.copy(&actuator_motors);
|
||||
_estimated_speed = math::interpolate<float>(actuator_motors.control[0], -1.f, 1.f,
|
||||
-_param_sv_max_thr_speed.get(), _param_sv_max_thr_speed.get());
|
||||
_estimated_speed = fabsf(_estimated_speed) > _param_sv_speed_th.get() ? _estimated_speed : 0.f;
|
||||
}
|
||||
|
||||
if (_surface_vehicle_rate_setpoint_sub.updated()) {
|
||||
surface_vehicle_rate_setpoint_s surface_vehicle_rate_setpoint{};
|
||||
_surface_vehicle_rate_setpoint_sub.copy(&surface_vehicle_rate_setpoint);
|
||||
_yaw_rate_setpoint = surface_vehicle_rate_setpoint.yaw_rate_setpoint;
|
||||
}
|
||||
}
|
||||
|
||||
bool BoatRudderRateControl::runSanityChecks()
|
||||
{
|
||||
bool ret = true;
|
||||
|
||||
if (_param_sv_max_thr_speed.get() < FLT_EPSILON) {
|
||||
ret = false;
|
||||
events::send<float>(events::ID("boat_rudder_rate_control_conf_invalid_max_thr_speed"), events::Log::Error,
|
||||
"Invalid configuration of necessary parameter SV_MAX_THR_SPEED", _param_sv_max_thr_speed.get());
|
||||
|
||||
}
|
||||
|
||||
if (_param_br_wheel_base.get() < FLT_EPSILON) {
|
||||
ret = false;
|
||||
events::send<float>(events::ID("boat_rudder_rate_control_conf_invalid_wheel_base"), events::Log::Error,
|
||||
"Invalid configuration of necessary parameter RA_WHEEL_BASE", _param_br_wheel_base.get());
|
||||
|
||||
}
|
||||
|
||||
if (_param_br_max_str_ang.get() < FLT_EPSILON) {
|
||||
ret = false;
|
||||
events::send<float>(events::ID("boat_rudder_rate_control_conf_invalid_max_str_ang"), events::Log::Error,
|
||||
"Invalid configuration of necessary parameter RA_MAX_STR_ANG", _param_br_max_str_ang.get());
|
||||
|
||||
}
|
||||
|
||||
if (_param_sv_yaw_rate_limit.get() < FLT_EPSILON) {
|
||||
ret = false;
|
||||
events::send<float>(events::ID("boat_rudder_rate_control_conf_invalid_yaw_rate_lim"), events::Log::Error,
|
||||
"Invalid configuration of necessary parameter SV_YAW_RATE_LIM", _param_sv_yaw_rate_limit.get());
|
||||
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
// PX4 includes
|
||||
#include <px4_platform_common/module_params.h>
|
||||
#include <px4_platform_common/events.h>
|
||||
|
||||
// Libraries
|
||||
#include <lib/surface_vehicle_control/SurfaceVehicleControl.hpp>
|
||||
#include <lib/pid/PID.hpp>
|
||||
#include <lib/slew_rate/SlewRate.hpp>
|
||||
#include <math.h>
|
||||
|
||||
// uORB includes
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/topics/surface_vehicle_rate_setpoint.h>
|
||||
#include <uORB/topics/vehicle_angular_velocity.h>
|
||||
#include <uORB/topics/surface_vehicle_steering_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_rate_status.h>
|
||||
#include <uORB/topics/actuator_motors.h>
|
||||
|
||||
/**
|
||||
* @brief Class for rate control of rudder-steered boats.
|
||||
*/
|
||||
class BoatRudderRateControl : public ModuleParams
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor for BoatRudderRateControl.
|
||||
* @param parent The parent ModuleParams object.
|
||||
*/
|
||||
BoatRudderRateControl(ModuleParams *parent);
|
||||
~BoatRudderRateControl() = default;
|
||||
|
||||
/**
|
||||
* @brief Generate and publish SurfaceVehicleSteeringSetpoint from SurfaceVehicleRateSetpoint.
|
||||
*/
|
||||
void updateRateControl();
|
||||
|
||||
/**
|
||||
* @brief Check if the necessary parameters are set.
|
||||
* @return True if all checks pass.
|
||||
*/
|
||||
bool runSanityChecks();
|
||||
|
||||
/**
|
||||
* @brief Reset rate controller.
|
||||
*/
|
||||
void reset() {_pid_yaw_rate.resetIntegral(); _yaw_rate_setpoint = NAN;};
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Update the parameters of the module.
|
||||
*/
|
||||
void updateParams() override;
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Update uORB subscriptions used in rate controller.
|
||||
*/
|
||||
void updateSubscriptions();
|
||||
|
||||
// uORB subscriptions
|
||||
uORB::Subscription _surface_vehicle_rate_setpoint_sub{ORB_ID(surface_vehicle_rate_setpoint)};
|
||||
uORB::Subscription _vehicle_angular_velocity_sub{ORB_ID(vehicle_angular_velocity)};
|
||||
uORB::Subscription _actuator_motors_sub{ORB_ID(actuator_motors)};
|
||||
|
||||
// uORB publications
|
||||
uORB::Publication<surface_vehicle_steering_setpoint_s> _surface_vehicle_steering_setpoint_pub{ORB_ID(surface_vehicle_steering_setpoint)};
|
||||
uORB::Publication<surface_vehicle_rate_status_s> _surface_vehicle_rate_status_pub{ORB_ID(surface_vehicle_rate_status)};
|
||||
|
||||
// Variables
|
||||
float _estimated_speed{0.f}; /*Vehicle speed estimated by interpolating [actuatorMotorSetpoint, _estimated_speed]
|
||||
between [0, 0] and [1, _param_sv_max_thr_speed].*/
|
||||
float _max_yaw_rate{0.f};
|
||||
float _vehicle_yaw_rate{0.f};
|
||||
float _yaw_rate_setpoint{NAN};
|
||||
hrt_abstime _timestamp{0};
|
||||
|
||||
// Controllers
|
||||
PID _pid_yaw_rate;
|
||||
SlewRate<float> _adjusted_yaw_rate_setpoint{0.f};
|
||||
|
||||
DEFINE_PARAMETERS(
|
||||
(ParamFloat<px4::params::SV_MAX_THR_SPEED>) _param_sv_max_thr_speed,
|
||||
(ParamFloat<px4::params::BR_WHEEL_BASE>) _param_br_wheel_base,
|
||||
(ParamFloat<px4::params::BR_MAX_STR_ANG>) _param_br_max_str_ang,
|
||||
(ParamFloat<px4::params::SV_YAW_RATE_LIM>) _param_sv_yaw_rate_limit,
|
||||
(ParamFloat<px4::params::SV_YAW_RATE_TH>) _param_sv_yaw_rate_th,
|
||||
(ParamFloat<px4::params::SV_YAW_RATE_P>) _param_sv_yaw_rate_p,
|
||||
(ParamFloat<px4::params::SV_YAW_RATE_I>) _param_sv_yaw_rate_i,
|
||||
(ParamFloat<px4::params::SV_YAW_ACCEL_LIM>) _param_sv_yaw_accel_limit,
|
||||
(ParamFloat<px4::params::SV_SPEED_TH>) _param_sv_speed_th,
|
||||
(ParamFloat<px4::params::SV_YAW_RATE_CORR>) _param_sv_yaw_rate_corr
|
||||
)
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
############################################################################
|
||||
#
|
||||
# Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name PX4 nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
px4_add_library(BoatRudderRateControl
|
||||
BoatRudderRateControl.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(BoatRudderRateControl PUBLIC PID)
|
||||
target_include_directories(BoatRudderRateControl PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
@@ -0,0 +1,134 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "BoatRudderSpeedControl.hpp"
|
||||
|
||||
using namespace time_literals;
|
||||
|
||||
BoatRudderSpeedControl::BoatRudderSpeedControl(ModuleParams *parent) : ModuleParams(parent)
|
||||
{
|
||||
_surface_vehicle_throttle_setpoint_pub.advertise();
|
||||
_surface_vehicle_speed_status_pub.advertise();
|
||||
updateParams();
|
||||
}
|
||||
|
||||
void BoatRudderSpeedControl::updateParams()
|
||||
{
|
||||
ModuleParams::updateParams();
|
||||
|
||||
// Set up PID controller
|
||||
_pid_speed.setGains(_param_sv_speed_p.get(), _param_sv_speed_i.get(), 0.f);
|
||||
_pid_speed.setIntegralLimit(1.f);
|
||||
_pid_speed.setOutputLimit(1.f);
|
||||
|
||||
// Set up slew rate
|
||||
if (_param_sv_accel_limit.get() > FLT_EPSILON) {
|
||||
_adjusted_speed_setpoint.setSlewRate(_param_sv_accel_limit.get());
|
||||
}
|
||||
}
|
||||
|
||||
void BoatRudderSpeedControl::updateSpeedControl()
|
||||
{
|
||||
updateSubscriptions();
|
||||
|
||||
const hrt_abstime timestamp_prev = _timestamp;
|
||||
_timestamp = hrt_absolute_time();
|
||||
const float dt = math::constrain(_timestamp - timestamp_prev, 1_ms, 10_ms) * 1e-6f;
|
||||
|
||||
// Throttle Setpoint
|
||||
if (PX4_ISFINITE(_speed_setpoint)) {
|
||||
const float speed_setpoint = math::constrain(_speed_setpoint, -_param_sv_speed_limit.get(),
|
||||
_param_sv_speed_limit.get());
|
||||
surface_vehicle_throttle_setpoint_s surface_vehicle_throttle_setpoint{};
|
||||
surface_vehicle_throttle_setpoint.timestamp = _timestamp;
|
||||
surface_vehicle_throttle_setpoint.throttle_body_x = SurfaceVehicleControl::speedControl(_adjusted_speed_setpoint,
|
||||
_pid_speed,
|
||||
speed_setpoint, _vehicle_speed, _param_sv_accel_limit.get(), _param_sv_decel_limit.get(),
|
||||
_param_sv_max_thr_speed.get(), dt);
|
||||
surface_vehicle_throttle_setpoint.throttle_body_y = NAN;
|
||||
_surface_vehicle_throttle_setpoint_pub.publish(surface_vehicle_throttle_setpoint);
|
||||
}
|
||||
|
||||
// Publish speed controller status (logging only)
|
||||
surface_vehicle_speed_status_s surface_vehicle_speed_status;
|
||||
surface_vehicle_speed_status.timestamp = _timestamp;
|
||||
surface_vehicle_speed_status.measured_speed_body_x = _vehicle_speed;
|
||||
surface_vehicle_speed_status.adjusted_speed_body_x_setpoint = _adjusted_speed_setpoint.getState();
|
||||
surface_vehicle_speed_status.pid_throttle_body_x_integral = _pid_speed.getIntegral();
|
||||
surface_vehicle_speed_status.measured_speed_body_y = NAN;
|
||||
surface_vehicle_speed_status.adjusted_speed_body_y_setpoint = NAN;
|
||||
surface_vehicle_speed_status.pid_throttle_body_y_integral = NAN;
|
||||
_surface_vehicle_speed_status_pub.publish(surface_vehicle_speed_status);
|
||||
}
|
||||
|
||||
void BoatRudderSpeedControl::updateSubscriptions()
|
||||
{
|
||||
if (_vehicle_attitude_sub.updated()) {
|
||||
vehicle_attitude_s vehicle_attitude{};
|
||||
_vehicle_attitude_sub.copy(&vehicle_attitude);
|
||||
_vehicle_attitude_quaternion = matrix::Quatf(vehicle_attitude.q);
|
||||
}
|
||||
|
||||
if (_vehicle_local_position_sub.updated()) {
|
||||
vehicle_local_position_s vehicle_local_position{};
|
||||
_vehicle_local_position_sub.copy(&vehicle_local_position);
|
||||
Vector3f velocity_ned(vehicle_local_position.vx, vehicle_local_position.vy, vehicle_local_position.vz);
|
||||
Vector3f velocity_xyz = _vehicle_attitude_quaternion.rotateVectorInverse(velocity_ned);
|
||||
Vector2f velocity_2d = Vector2f(velocity_xyz(0), velocity_xyz(1));
|
||||
_vehicle_speed = velocity_2d.norm() > _param_sv_speed_th.get() ? sign(velocity_2d(0)) * velocity_2d.norm() : 0.f;
|
||||
}
|
||||
|
||||
if (_surface_vehicle_speed_setpoint_sub.updated()) {
|
||||
surface_vehicle_speed_setpoint_s surface_vehicle_speed_setpoint;
|
||||
_surface_vehicle_speed_setpoint_sub.copy(&surface_vehicle_speed_setpoint);
|
||||
_speed_setpoint = surface_vehicle_speed_setpoint.speed_body_x;
|
||||
}
|
||||
}
|
||||
|
||||
bool BoatRudderSpeedControl::runSanityChecks()
|
||||
{
|
||||
bool ret = true;
|
||||
|
||||
if (_param_sv_max_thr_speed.get() < FLT_EPSILON) {
|
||||
ret = false;
|
||||
}
|
||||
|
||||
if (_param_sv_speed_limit.get() < FLT_EPSILON) {
|
||||
ret = false;
|
||||
events::send<float>(events::ID("boat_rudder_speed_control_conf_invalid_speed_lim"), events::Log::Error,
|
||||
"Invalid configuration of necessary parameter SV_SPEED_LIM", _param_sv_speed_limit.get());
|
||||
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
// PX4 includes
|
||||
#include <px4_platform_common/module_params.h>
|
||||
#include <px4_platform_common/events.h>
|
||||
|
||||
// Library includes
|
||||
#include <lib/surface_vehicle_control/SurfaceVehicleControl.hpp>
|
||||
#include <lib/pid/PID.hpp>
|
||||
#include <matrix/matrix/math.hpp>
|
||||
#include <lib/slew_rate/SlewRate.hpp>
|
||||
#include <math.h>
|
||||
|
||||
// uORB includes
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/topics/surface_vehicle_throttle_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_speed_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_speed_status.h>
|
||||
#include <uORB/topics/vehicle_attitude.h>
|
||||
#include <uORB/topics/vehicle_local_position.h>
|
||||
|
||||
using namespace matrix;
|
||||
|
||||
/**
|
||||
* @brief Class for speed control of rudder-steered boats.
|
||||
*/
|
||||
class BoatRudderSpeedControl : public ModuleParams
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor for BoatRudderSpeedControl.
|
||||
* @param parent The parent ModuleParams object.
|
||||
*/
|
||||
BoatRudderSpeedControl(ModuleParams *parent);
|
||||
~BoatRudderSpeedControl() = default;
|
||||
|
||||
/**
|
||||
* @brief Generate and publish SurfaceVehicleThrottleSetpoint from SurfaceVehicleSpeedSetpoint.
|
||||
*/
|
||||
void updateSpeedControl();
|
||||
|
||||
/**
|
||||
* @brief Check if the necessary parameters are set.
|
||||
* @return True if all checks pass.
|
||||
*/
|
||||
bool runSanityChecks();
|
||||
|
||||
/**
|
||||
* @brief Reset speed controller.
|
||||
*/
|
||||
void reset() {_pid_speed.resetIntegral(); _speed_setpoint = NAN; _adjusted_speed_setpoint.setForcedValue(0.f);};
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Update the parameters of the module.
|
||||
*/
|
||||
void updateParams() override;
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Update uORB subscriptions used in speed controller.
|
||||
*/
|
||||
void updateSubscriptions();
|
||||
|
||||
// uORB subscriptions
|
||||
uORB::Subscription _vehicle_attitude_sub{ORB_ID(vehicle_attitude)};
|
||||
uORB::Subscription _vehicle_local_position_sub{ORB_ID(vehicle_local_position)};
|
||||
uORB::Subscription _surface_vehicle_speed_setpoint_sub{ORB_ID(surface_vehicle_speed_setpoint)};
|
||||
|
||||
// uORB publications
|
||||
uORB::Publication<surface_vehicle_throttle_setpoint_s> _surface_vehicle_throttle_setpoint_pub{ORB_ID(surface_vehicle_throttle_setpoint)};
|
||||
uORB::Publication<surface_vehicle_speed_status_s> _surface_vehicle_speed_status_pub{ORB_ID(surface_vehicle_speed_status)};
|
||||
|
||||
// Variables
|
||||
hrt_abstime _timestamp{0};
|
||||
Quatf _vehicle_attitude_quaternion{};
|
||||
float _vehicle_speed{0.f}; // [m/s] Positiv: Forwards, Negativ: Backwards
|
||||
float _speed_setpoint{NAN};
|
||||
|
||||
// Controllers
|
||||
PID _pid_speed;
|
||||
SlewRate<float> _adjusted_speed_setpoint{0.f};
|
||||
|
||||
DEFINE_PARAMETERS(
|
||||
(ParamFloat<px4::params::SV_MAX_THR_SPEED>) _param_sv_max_thr_speed,
|
||||
(ParamFloat<px4::params::SV_SPEED_P>) _param_sv_speed_p,
|
||||
(ParamFloat<px4::params::SV_SPEED_I>) _param_sv_speed_i,
|
||||
(ParamFloat<px4::params::SV_ACCEL_LIM>) _param_sv_accel_limit,
|
||||
(ParamFloat<px4::params::SV_DECEL_LIM>) _param_sv_decel_limit,
|
||||
(ParamFloat<px4::params::SV_JERK_LIM>) _param_sv_jerk_limit,
|
||||
(ParamFloat<px4::params::SV_SPEED_LIM>) _param_sv_speed_limit,
|
||||
(ParamFloat<px4::params::SV_SPEED_TH>) _param_sv_speed_th
|
||||
)
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
############################################################################
|
||||
#
|
||||
# Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name PX4 nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
px4_add_library(BoatRudderSpeedControl
|
||||
BoatRudderSpeedControl.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(BoatRudderSpeedControl PUBLIC PID)
|
||||
target_include_directories(BoatRudderSpeedControl PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
@@ -0,0 +1,61 @@
|
||||
############################################################################
|
||||
#
|
||||
# Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name PX4 nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
add_subdirectory(BoatRudderActControl)
|
||||
add_subdirectory(BoatRudderRateControl)
|
||||
add_subdirectory(BoatRudderAttControl)
|
||||
add_subdirectory(BoatRudderSpeedControl)
|
||||
add_subdirectory(BoatRudderPosControl)
|
||||
add_subdirectory(BoatRudderDriveModes)
|
||||
|
||||
px4_add_module(
|
||||
MODULE modules__boat_rudder
|
||||
MAIN boat_rudder
|
||||
SRCS
|
||||
BoatRudder.cpp
|
||||
BoatRudder.hpp
|
||||
DEPENDS
|
||||
BoatRudderActControl
|
||||
BoatRudderRateControl
|
||||
BoatRudderAttControl
|
||||
BoatRudderSpeedControl
|
||||
BoatRudderPosControl
|
||||
BoatRudderAutoMode
|
||||
BoatRudderManualMode
|
||||
BoatRudderOffboardMode
|
||||
px4_work_queue
|
||||
surface_vehicle_control
|
||||
pure_pursuit
|
||||
MODULE_CONFIG
|
||||
module.yaml
|
||||
)
|
||||
@@ -0,0 +1,5 @@
|
||||
menuconfig MODULES_BOAT_RUDDER
|
||||
bool "boat_rudder"
|
||||
default n
|
||||
---help---
|
||||
Enable support for rudder-steered boats
|
||||
@@ -0,0 +1,69 @@
|
||||
module_name: Boat Rudder
|
||||
|
||||
parameters:
|
||||
- group: Boat Rudder
|
||||
definitions:
|
||||
BR_WHEEL_BASE:
|
||||
description:
|
||||
short: Wheel base
|
||||
long: Distance from the front to the rear axle.
|
||||
type: float
|
||||
unit: m
|
||||
min: 0
|
||||
max: 100
|
||||
increment: 0.001
|
||||
decimal: 3
|
||||
default: 0
|
||||
|
||||
BR_MAX_STR_ANG:
|
||||
description:
|
||||
short: Maximum steering angle
|
||||
type: float
|
||||
unit: rad
|
||||
min: 0
|
||||
max: 1.5708
|
||||
increment: 0.01
|
||||
decimal: 2
|
||||
default: 0
|
||||
|
||||
BR_STR_RATE_LIM:
|
||||
description:
|
||||
short: Steering rate limit
|
||||
long: Set to -1 to disable.
|
||||
type: float
|
||||
unit: deg/s
|
||||
min: -1
|
||||
max: 1000
|
||||
increment: 0.01
|
||||
decimal: 2
|
||||
default: -1
|
||||
|
||||
BR_ACC_RAD_MAX:
|
||||
description:
|
||||
short: Maximum acceptance radius for the waypoints
|
||||
long: |
|
||||
The controller scales the acceptance radius based on the angle between
|
||||
the previous, current and next waypoint.
|
||||
Higher value -> smoother trajectory at the cost of how close the rover gets
|
||||
to the waypoint (Set to -1 to disable corner cutting).
|
||||
type: float
|
||||
unit: m
|
||||
min: -1
|
||||
max: 100
|
||||
increment: 0.01
|
||||
decimal: 2
|
||||
default: -1
|
||||
|
||||
BR_ACC_RAD_GAIN:
|
||||
description:
|
||||
short: Tuning parameter for corner cutting
|
||||
long: |
|
||||
The geometric ideal acceptance radius is multiplied by this factor
|
||||
to account for kinematic and dynamic effects.
|
||||
Higher value -> The rover starts to cut the corner earlier.
|
||||
type: float
|
||||
min: 1
|
||||
max: 100
|
||||
increment: 0.01
|
||||
decimal: 2
|
||||
default: 1
|
||||
@@ -106,15 +106,15 @@ void LoggedTopics::add_default_topics()
|
||||
add_topic("position_setpoint_triplet", 200);
|
||||
add_optional_topic("px4io_status");
|
||||
add_topic("radio_status");
|
||||
add_optional_topic("rover_attitude_setpoint", 100);
|
||||
add_optional_topic("rover_attitude_status", 100);
|
||||
add_optional_topic("rover_position_setpoint", 100);
|
||||
add_optional_topic("rover_rate_setpoint", 100);
|
||||
add_optional_topic("rover_rate_status", 100);
|
||||
add_optional_topic("rover_speed_setpoint", 100);
|
||||
add_optional_topic("rover_speed_status", 100);
|
||||
add_optional_topic("rover_steering_setpoint", 100);
|
||||
add_optional_topic("rover_throttle_setpoint", 100);
|
||||
add_optional_topic("surface_vehicle_attitude_setpoint", 100);
|
||||
add_optional_topic("surface_vehicle_attitude_status", 100);
|
||||
add_optional_topic("surface_vehicle_position_setpoint", 100);
|
||||
add_optional_topic("surface_vehicle_rate_setpoint", 100);
|
||||
add_optional_topic("surface_vehicle_rate_status", 100);
|
||||
add_optional_topic("surface_vehicle_speed_setpoint", 100);
|
||||
add_optional_topic("surface_vehicle_speed_status", 100);
|
||||
add_optional_topic("surface_vehicle_steering_setpoint", 100);
|
||||
add_optional_topic("surface_vehicle_throttle_setpoint", 100);
|
||||
add_topic("rtl_time_estimate", 1000);
|
||||
add_topic("rtl_status", 2000);
|
||||
add_optional_topic("sensor_airflow", 100);
|
||||
|
||||
@@ -48,8 +48,8 @@ void AckermannActControl::updateParams()
|
||||
_servo_setpoint.setSlewRate((M_DEG_TO_RAD_F * _param_ra_str_rate_limit.get()) / _param_ra_max_str_ang.get());
|
||||
}
|
||||
|
||||
if (_param_ro_accel_limit.get() > FLT_EPSILON && _param_ro_max_thr_speed.get() > FLT_EPSILON) {
|
||||
_motor_setpoint.setSlewRate(_param_ro_accel_limit.get() / _param_ro_max_thr_speed.get());
|
||||
if (_param_sv_accel_limit.get() > FLT_EPSILON && _param_sv_max_thr_speed.get() > FLT_EPSILON) {
|
||||
_motor_setpoint.setSlewRate(_param_sv_accel_limit.get() / _param_sv_max_thr_speed.get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,10 +60,10 @@ void AckermannActControl::updateActControl()
|
||||
const float dt = math::constrain(_timestamp - timestamp_prev, 1_ms, 10_ms) * 1e-6f;
|
||||
|
||||
// Motor control
|
||||
if (_rover_throttle_setpoint_sub.updated()) {
|
||||
rover_throttle_setpoint_s rover_throttle_setpoint{};
|
||||
_rover_throttle_setpoint_sub.copy(&rover_throttle_setpoint);
|
||||
_throttle_setpoint = rover_throttle_setpoint.throttle_body_x;
|
||||
if (_surface_vehicle_throttle_setpoint_sub.updated()) {
|
||||
surface_vehicle_throttle_setpoint_s surface_vehicle_throttle_setpoint{};
|
||||
_surface_vehicle_throttle_setpoint_sub.copy(&surface_vehicle_throttle_setpoint);
|
||||
_throttle_setpoint = surface_vehicle_throttle_setpoint.throttle_body_x;
|
||||
}
|
||||
|
||||
if (PX4_ISFINITE(_throttle_setpoint)) {
|
||||
@@ -71,19 +71,19 @@ void AckermannActControl::updateActControl()
|
||||
_actuator_motors_sub.copy(&actuator_motors_sub);
|
||||
actuator_motors_s actuator_motors{};
|
||||
actuator_motors.reversible_flags = _param_r_rev.get();
|
||||
actuator_motors.control[0] = RoverControl::throttleControl(_motor_setpoint,
|
||||
_throttle_setpoint, actuator_motors_sub.control[0], _param_ro_accel_limit.get(),
|
||||
_param_ro_decel_limit.get(), _param_ro_max_thr_speed.get(), dt);
|
||||
actuator_motors.control[0] = SurfaceVehicleControl::throttleControl(_motor_setpoint,
|
||||
_throttle_setpoint, actuator_motors_sub.control[0], _param_sv_accel_limit.get(),
|
||||
_param_sv_decel_limit.get(), _param_sv_max_thr_speed.get(), dt);
|
||||
actuator_motors.timestamp = _timestamp;
|
||||
_actuator_motors_pub.publish(actuator_motors);
|
||||
|
||||
}
|
||||
|
||||
// Servo control
|
||||
if (_rover_steering_setpoint_sub.updated()) {
|
||||
rover_steering_setpoint_s rover_steering_setpoint{};
|
||||
_rover_steering_setpoint_sub.copy(&rover_steering_setpoint);
|
||||
_steering_setpoint = rover_steering_setpoint.normalized_steering_setpoint;
|
||||
if (_surface_vehicle_steering_setpoint_sub.updated()) {
|
||||
surface_vehicle_steering_setpoint_s surface_vehicle_steering_setpoint{};
|
||||
_surface_vehicle_steering_setpoint_sub.copy(&surface_vehicle_steering_setpoint);
|
||||
_steering_setpoint = surface_vehicle_steering_setpoint.normalized_steering_setpoint;
|
||||
}
|
||||
|
||||
if (PX4_ISFINITE(_steering_setpoint)) {
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
#include <px4_platform_common/module_params.h>
|
||||
|
||||
// Libraries
|
||||
#include <lib/rover_control/RoverControl.hpp>
|
||||
#include <lib/surface_vehicle_control/SurfaceVehicleControl.hpp>
|
||||
#include <lib/slew_rate/SlewRate.hpp>
|
||||
#include <math.h>
|
||||
|
||||
@@ -46,8 +46,8 @@
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/topics/actuator_motors.h>
|
||||
#include <uORB/topics/actuator_servos.h>
|
||||
#include <uORB/topics/rover_steering_setpoint.h>
|
||||
#include <uORB/topics/rover_throttle_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_steering_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_throttle_setpoint.h>
|
||||
|
||||
/**
|
||||
* @brief Class for ackermann actuator control.
|
||||
@@ -63,7 +63,7 @@ public:
|
||||
~AckermannActControl() = default;
|
||||
|
||||
/**
|
||||
* @brief Generate and publish actuatorMotors/actuatorServos setpoints from roverThrottleSetpoint/roverSteeringSetpoint.
|
||||
* @brief Generate and publish actuatorMotors/actuatorServos setpoints from SurfaceVehicleThrottleSetpoint/SurfaceVehicleSteeringSetpoint.
|
||||
*/
|
||||
void updateActControl();
|
||||
|
||||
@@ -83,8 +83,8 @@ private:
|
||||
// uORB subscriptions
|
||||
uORB::Subscription _actuator_servos_sub{ORB_ID(actuator_servos)};
|
||||
uORB::Subscription _actuator_motors_sub{ORB_ID(actuator_motors)};
|
||||
uORB::Subscription _rover_steering_setpoint_sub{ORB_ID(rover_steering_setpoint)};
|
||||
uORB::Subscription _rover_throttle_setpoint_sub{ORB_ID(rover_throttle_setpoint)};
|
||||
uORB::Subscription _surface_vehicle_steering_setpoint_sub{ORB_ID(surface_vehicle_steering_setpoint)};
|
||||
uORB::Subscription _surface_vehicle_throttle_setpoint_sub{ORB_ID(surface_vehicle_throttle_setpoint)};
|
||||
|
||||
// uORB publications
|
||||
uORB::Publication<actuator_motors_s> _actuator_motors_pub{ORB_ID(actuator_motors)};
|
||||
@@ -104,8 +104,8 @@ private:
|
||||
(ParamInt<px4::params::CA_R_REV>) _param_r_rev,
|
||||
(ParamFloat<px4::params::RA_STR_RATE_LIM>) _param_ra_str_rate_limit,
|
||||
(ParamFloat<px4::params::RA_MAX_STR_ANG>) _param_ra_max_str_ang,
|
||||
(ParamFloat<px4::params::RO_ACCEL_LIM>) _param_ro_accel_limit,
|
||||
(ParamFloat<px4::params::RO_DECEL_LIM>) _param_ro_decel_limit,
|
||||
(ParamFloat<px4::params::RO_MAX_THR_SPEED>) _param_ro_max_thr_speed
|
||||
(ParamFloat<px4::params::SV_ACCEL_LIM>) _param_sv_accel_limit,
|
||||
(ParamFloat<px4::params::SV_DECEL_LIM>) _param_sv_decel_limit,
|
||||
(ParamFloat<px4::params::SV_MAX_THR_SPEED>) _param_sv_max_thr_speed
|
||||
)
|
||||
};
|
||||
|
||||
@@ -37,8 +37,8 @@ using namespace time_literals;
|
||||
|
||||
AckermannAttControl::AckermannAttControl(ModuleParams *parent) : ModuleParams(parent)
|
||||
{
|
||||
_rover_rate_setpoint_pub.advertise();
|
||||
_rover_attitude_status_pub.advertise();
|
||||
_surface_vehicle_rate_setpoint_pub.advertise();
|
||||
_surface_vehicle_attitude_status_pub.advertise();
|
||||
updateParams();
|
||||
}
|
||||
|
||||
@@ -46,12 +46,12 @@ void AckermannAttControl::updateParams()
|
||||
{
|
||||
ModuleParams::updateParams();
|
||||
|
||||
if (_param_ro_yaw_rate_limit.get() > FLT_EPSILON) {
|
||||
_max_yaw_rate = _param_ro_yaw_rate_limit.get() * M_DEG_TO_RAD_F;
|
||||
if (_param_sv_yaw_rate_limit.get() > FLT_EPSILON) {
|
||||
_max_yaw_rate = _param_sv_yaw_rate_limit.get() * M_DEG_TO_RAD_F;
|
||||
}
|
||||
|
||||
// Set up PID controller
|
||||
_pid_yaw.setGains(_param_ro_yaw_p.get(), 0.f, 0.f);
|
||||
_pid_yaw.setGains(_param_sv_yaw_p.get(), 0.f, 0.f);
|
||||
_pid_yaw.setIntegralLimit(0.f);
|
||||
_pid_yaw.setOutputLimit(_max_yaw_rate);
|
||||
|
||||
@@ -73,22 +73,22 @@ void AckermannAttControl::updateAttControl()
|
||||
_param_ra_wheel_base.get(); // Maximum possible yaw rate at current velocity
|
||||
float yaw_slew_rate = math::min(max_possible_yaw_rate, _max_yaw_rate);
|
||||
|
||||
float yaw_rate_setpoint = RoverControl::attitudeControl(_adjusted_yaw_setpoint, _pid_yaw, yaw_slew_rate,
|
||||
float yaw_rate_setpoint = SurfaceVehicleControl::attitudeControl(_adjusted_yaw_setpoint, _pid_yaw, yaw_slew_rate,
|
||||
_vehicle_yaw, _yaw_setpoint, dt);
|
||||
|
||||
rover_rate_setpoint_s rover_rate_setpoint{};
|
||||
rover_rate_setpoint.timestamp = _timestamp;
|
||||
rover_rate_setpoint.yaw_rate_setpoint = math::constrain(yaw_rate_setpoint, -_max_yaw_rate, _max_yaw_rate);
|
||||
_rover_rate_setpoint_pub.publish(rover_rate_setpoint);
|
||||
surface_vehicle_rate_setpoint_s surface_vehicle_rate_setpoint{};
|
||||
surface_vehicle_rate_setpoint.timestamp = _timestamp;
|
||||
surface_vehicle_rate_setpoint.yaw_rate_setpoint = math::constrain(yaw_rate_setpoint, -_max_yaw_rate, _max_yaw_rate);
|
||||
_surface_vehicle_rate_setpoint_pub.publish(surface_vehicle_rate_setpoint);
|
||||
|
||||
}
|
||||
|
||||
// Publish attitude controller status (logging only)
|
||||
rover_attitude_status_s rover_attitude_status;
|
||||
rover_attitude_status.timestamp = _timestamp;
|
||||
rover_attitude_status.measured_yaw = _vehicle_yaw;
|
||||
rover_attitude_status.adjusted_yaw_setpoint = matrix::wrap_pi(_adjusted_yaw_setpoint.getState());
|
||||
_rover_attitude_status_pub.publish(rover_attitude_status);
|
||||
surface_vehicle_attitude_status_s surface_vehicle_attitude_status;
|
||||
surface_vehicle_attitude_status.timestamp = _timestamp;
|
||||
surface_vehicle_attitude_status.measured_yaw = _vehicle_yaw;
|
||||
surface_vehicle_attitude_status.adjusted_yaw_setpoint = matrix::wrap_pi(_adjusted_yaw_setpoint.getState());
|
||||
_surface_vehicle_attitude_status_pub.publish(surface_vehicle_attitude_status);
|
||||
|
||||
}
|
||||
|
||||
@@ -106,13 +106,13 @@ void AckermannAttControl::updateSubscriptions()
|
||||
actuator_motors_s actuator_motors;
|
||||
_actuator_motors_sub.copy(&actuator_motors);
|
||||
_estimated_speed_body_x = math::interpolate<float> (actuator_motors.control[0], -1.f, 1.f,
|
||||
-_param_ro_max_thr_speed.get(), _param_ro_max_thr_speed.get());
|
||||
-_param_sv_max_thr_speed.get(), _param_sv_max_thr_speed.get());
|
||||
}
|
||||
|
||||
if (_rover_attitude_setpoint_sub.updated()) {
|
||||
rover_attitude_setpoint_s rover_attitude_setpoint{};
|
||||
_rover_attitude_setpoint_sub.copy(&rover_attitude_setpoint);
|
||||
_yaw_setpoint = rover_attitude_setpoint.yaw_setpoint;
|
||||
if (_surface_vehicle_attitude_setpoint_sub.updated()) {
|
||||
surface_vehicle_attitude_setpoint_s surface_vehicle_attitude_setpoint{};
|
||||
_surface_vehicle_attitude_setpoint_sub.copy(&surface_vehicle_attitude_setpoint);
|
||||
_yaw_setpoint = surface_vehicle_attitude_setpoint.yaw_setpoint;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ bool AckermannAttControl::runSanityChecks()
|
||||
{
|
||||
bool ret = true;
|
||||
|
||||
if (_param_ro_max_thr_speed.get() < FLT_EPSILON) {
|
||||
if (_param_sv_max_thr_speed.get() < FLT_EPSILON) {
|
||||
ret = false;
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ bool AckermannAttControl::runSanityChecks()
|
||||
ret = false;
|
||||
}
|
||||
|
||||
if (_param_ro_yaw_rate_limit.get() < FLT_EPSILON) {
|
||||
if (_param_sv_yaw_rate_limit.get() < FLT_EPSILON) {
|
||||
ret = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
#include <px4_platform_common/module_params.h>
|
||||
|
||||
// Library includes
|
||||
#include <lib/rover_control/RoverControl.hpp>
|
||||
#include <lib/surface_vehicle_control/SurfaceVehicleControl.hpp>
|
||||
#include <lib/pid/PID.hpp>
|
||||
#include <lib/slew_rate/SlewRateYaw.hpp>
|
||||
#include <math.h>
|
||||
@@ -46,10 +46,10 @@
|
||||
// uORB includes
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/topics/rover_rate_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_rate_setpoint.h>
|
||||
#include <uORB/topics/vehicle_attitude.h>
|
||||
#include <uORB/topics/rover_attitude_status.h>
|
||||
#include <uORB/topics/rover_attitude_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_attitude_status.h>
|
||||
#include <uORB/topics/surface_vehicle_attitude_setpoint.h>
|
||||
#include <uORB/topics/actuator_motors.h>
|
||||
|
||||
/**
|
||||
@@ -66,7 +66,7 @@ public:
|
||||
~AckermannAttControl() = default;
|
||||
|
||||
/**
|
||||
* @brief Generate and publish roverRateSetpoint from roverAttitudeSetpoint.
|
||||
* @brief Generate and publish SurfaceVehicleRateSetpoint from SurfaceVehicleAttitudeSetpoint.
|
||||
*/
|
||||
void updateAttControl();
|
||||
|
||||
@@ -96,18 +96,18 @@ private:
|
||||
// uORB subscriptions
|
||||
uORB::Subscription _vehicle_attitude_sub{ORB_ID(vehicle_attitude)};
|
||||
uORB::Subscription _actuator_motors_sub{ORB_ID(actuator_motors)};
|
||||
uORB::Subscription _rover_attitude_setpoint_sub{ORB_ID(rover_attitude_setpoint)};
|
||||
uORB::Subscription _surface_vehicle_attitude_setpoint_sub{ORB_ID(surface_vehicle_attitude_setpoint)};
|
||||
|
||||
// uORB publications
|
||||
uORB::Publication<rover_rate_setpoint_s> _rover_rate_setpoint_pub{ORB_ID(rover_rate_setpoint)};
|
||||
uORB::Publication<rover_attitude_status_s> _rover_attitude_status_pub{ORB_ID(rover_attitude_status)};
|
||||
uORB::Publication<surface_vehicle_rate_setpoint_s> _surface_vehicle_rate_setpoint_pub{ORB_ID(surface_vehicle_rate_setpoint)};
|
||||
uORB::Publication<surface_vehicle_attitude_status_s> _surface_vehicle_attitude_status_pub{ORB_ID(surface_vehicle_attitude_status)};
|
||||
|
||||
// Variables
|
||||
float _vehicle_yaw{0.f};
|
||||
hrt_abstime _timestamp{0};
|
||||
float _max_yaw_rate{0.f};
|
||||
float _estimated_speed_body_x{0.f}; /*Vehicle speed estimated by interpolating [actuatorMotorSetpoint, _estimated_speed_body_x]
|
||||
between [0, 0] and [1, _param_ro_max_thr_speed].*/
|
||||
between [0, 0] and [1, _param_sv_max_thr_speed].*/
|
||||
float _yaw_setpoint{NAN};
|
||||
|
||||
// Controllers
|
||||
@@ -116,11 +116,11 @@ private:
|
||||
|
||||
// Parameters
|
||||
DEFINE_PARAMETERS(
|
||||
(ParamFloat<px4::params::RO_MAX_THR_SPEED>) _param_ro_max_thr_speed,
|
||||
(ParamFloat<px4::params::SV_MAX_THR_SPEED>) _param_sv_max_thr_speed,
|
||||
(ParamFloat<px4::params::RA_WHEEL_BASE>) _param_ra_wheel_base,
|
||||
(ParamFloat<px4::params::RA_MAX_STR_ANG>) _param_ra_max_str_ang,
|
||||
(ParamFloat<px4::params::RO_YAW_RATE_LIM>) _param_ro_yaw_rate_limit,
|
||||
(ParamFloat<px4::params::RO_YAW_P>) _param_ro_yaw_p,
|
||||
(ParamFloat<px4::params::RO_YAW_STICK_DZ>) _param_ro_yaw_stick_dz
|
||||
(ParamFloat<px4::params::SV_YAW_RATE_LIM>) _param_sv_yaw_rate_limit,
|
||||
(ParamFloat<px4::params::SV_YAW_P>) _param_sv_yaw_p,
|
||||
(ParamFloat<px4::params::SV_YAW_STICK_DZ>) _param_sv_yaw_stick_dz
|
||||
)
|
||||
};
|
||||
|
||||
+21
-19
@@ -38,13 +38,13 @@ using namespace time_literals;
|
||||
AckermannAutoMode::AckermannAutoMode(ModuleParams *parent) : ModuleParams(parent)
|
||||
{
|
||||
updateParams();
|
||||
_rover_position_setpoint_pub.advertise();
|
||||
_surface_vehicle_position_setpoint_pub.advertise();
|
||||
}
|
||||
|
||||
void AckermannAutoMode::updateParams()
|
||||
{
|
||||
ModuleParams::updateParams();
|
||||
_max_yaw_rate = _param_ro_yaw_rate_limit.get() * M_DEG_TO_RAD_F;
|
||||
_max_yaw_rate = _param_sv_yaw_rate_limit.get() * M_DEG_TO_RAD_F;
|
||||
|
||||
if (_param_ra_wheel_base.get() > FLT_EPSILON && _max_yaw_rate > FLT_EPSILON
|
||||
&& _param_ra_max_str_ang.get() > FLT_EPSILON) {
|
||||
@@ -70,17 +70,18 @@ void AckermannAutoMode::autoControl()
|
||||
|
||||
updateWaypointsAndAcceptanceRadius();
|
||||
|
||||
rover_position_setpoint_s rover_position_setpoint{};
|
||||
rover_position_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_position_setpoint.position_ned[0] = _curr_wp_ned(0);
|
||||
rover_position_setpoint.position_ned[1] = _curr_wp_ned(1);
|
||||
rover_position_setpoint.start_ned[0] = _prev_wp_ned(0);
|
||||
rover_position_setpoint.start_ned[1] = _prev_wp_ned(1);
|
||||
rover_position_setpoint.arrival_speed = arrivalSpeed(_cruising_speed, _min_speed, _acceptance_radius, _curr_wp_type,
|
||||
_waypoint_transition_angle, _max_yaw_rate);
|
||||
rover_position_setpoint.cruising_speed = _cruising_speed;
|
||||
rover_position_setpoint.yaw = NAN;
|
||||
_rover_position_setpoint_pub.publish(rover_position_setpoint);
|
||||
surface_vehicle_position_setpoint_s surface_vehicle_position_setpoint{};
|
||||
surface_vehicle_position_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_position_setpoint.position_ned[0] = _curr_wp_ned(0);
|
||||
surface_vehicle_position_setpoint.position_ned[1] = _curr_wp_ned(1);
|
||||
surface_vehicle_position_setpoint.start_ned[0] = _prev_wp_ned(0);
|
||||
surface_vehicle_position_setpoint.start_ned[1] = _prev_wp_ned(1);
|
||||
surface_vehicle_position_setpoint.arrival_speed = arrivalSpeed(_cruising_speed, _min_speed, _acceptance_radius,
|
||||
_curr_wp_type,
|
||||
_waypoint_transition_angle, _max_yaw_rate);
|
||||
surface_vehicle_position_setpoint.cruising_speed = _cruising_speed;
|
||||
surface_vehicle_position_setpoint.yaw = NAN;
|
||||
_surface_vehicle_position_setpoint_pub.publish(surface_vehicle_position_setpoint);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -91,10 +92,11 @@ void AckermannAutoMode::updateWaypointsAndAcceptanceRadius()
|
||||
_position_setpoint_triplet_sub.copy(&position_setpoint_triplet);
|
||||
_curr_wp_type = position_setpoint_triplet.current.type;
|
||||
|
||||
RoverControl::globalToLocalSetpointTriplet(_curr_wp_ned, _prev_wp_ned, _next_wp_ned, position_setpoint_triplet,
|
||||
SurfaceVehicleControl::globalToLocalSetpointTriplet(_curr_wp_ned, _prev_wp_ned, _next_wp_ned, position_setpoint_triplet,
|
||||
_curr_pos_ned, _global_ned_proj_ref);
|
||||
|
||||
_waypoint_transition_angle = RoverControl::calcWaypointTransitionAngle(_prev_wp_ned, _curr_wp_ned, _next_wp_ned);
|
||||
_waypoint_transition_angle = SurfaceVehicleControl::calcWaypointTransitionAngle(_prev_wp_ned, _curr_wp_ned,
|
||||
_next_wp_ned);
|
||||
|
||||
// Update acceptance radius
|
||||
if (_param_ra_acc_rad_max.get() >= _param_nav_acc_rad.get()) {
|
||||
@@ -107,7 +109,7 @@ void AckermannAutoMode::updateWaypointsAndAcceptanceRadius()
|
||||
|
||||
// Waypoint cruising speed
|
||||
_cruising_speed = position_setpoint_triplet.current.cruising_speed > 0.f ? math::constrain(
|
||||
position_setpoint_triplet.current.cruising_speed, 0.f, _param_ro_speed_limit.get()) : _param_ro_speed_limit.get();
|
||||
position_setpoint_triplet.current.cruising_speed, 0.f, _param_sv_speed_limit.get()) : _param_sv_speed_limit.get();
|
||||
}
|
||||
|
||||
float AckermannAutoMode::updateAcceptanceRadius(const float waypoint_transition_angle,
|
||||
@@ -143,11 +145,11 @@ float AckermannAutoMode::arrivalSpeed(const float cruising_speed, const float mi
|
||||
|| curr_wp_type == position_setpoint_s::SETPOINT_TYPE_IDLE) {
|
||||
return 0.f; // Stop at the waypoint
|
||||
|
||||
} else if (_param_ro_speed_red.get() > FLT_EPSILON) {
|
||||
const float speed_reduction = math::constrain(_param_ro_speed_red.get() * math::interpolate(
|
||||
} else if (_param_sv_speed_red.get() > FLT_EPSILON) {
|
||||
const float speed_reduction = math::constrain(_param_sv_speed_red.get() * math::interpolate(
|
||||
M_PI_F - waypoint_transition_angle,
|
||||
0.f, M_PI_F, 0.f, 1.f), 0.f, 1.f);
|
||||
return math::constrain(_param_ro_max_thr_speed.get() * (1.f - speed_reduction), min_speed,
|
||||
return math::constrain(_param_sv_max_thr_speed.get() * (1.f - speed_reduction), min_speed,
|
||||
cruising_speed); // Slow down for cornering
|
||||
}
|
||||
|
||||
|
||||
+8
-8
@@ -37,7 +37,7 @@
|
||||
#include <px4_platform_common/module_params.h>
|
||||
|
||||
// Libraries
|
||||
#include <lib/rover_control/RoverControl.hpp>
|
||||
#include <lib/surface_vehicle_control/SurfaceVehicleControl.hpp>
|
||||
#include <math.h>
|
||||
|
||||
// uORB includes
|
||||
@@ -46,7 +46,7 @@
|
||||
#include <uORB/topics/vehicle_local_position.h>
|
||||
#include <uORB/topics/position_setpoint_triplet.h>
|
||||
#include <uORB/topics/position_controller_status.h>
|
||||
#include <uORB/topics/rover_position_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_position_setpoint.h>
|
||||
|
||||
/**
|
||||
* @brief Class for ackermann auto mode.
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
~AckermannAutoMode() = default;
|
||||
|
||||
/**
|
||||
* @brief Generate and publish roverPositionSetpoint from positionSetpointTriplet.
|
||||
* @brief Generate and publish SurfaceVehiclePositionSetpoint from positionSetpointTriplet.
|
||||
*/
|
||||
void autoControl();
|
||||
|
||||
@@ -110,7 +110,7 @@ private:
|
||||
uORB::Subscription _position_setpoint_triplet_sub{ORB_ID(position_setpoint_triplet)};
|
||||
|
||||
// uORB publications
|
||||
uORB::Publication<rover_position_setpoint_s> _rover_position_setpoint_pub{ORB_ID(rover_position_setpoint)};
|
||||
uORB::Publication<surface_vehicle_position_setpoint_s> _surface_vehicle_position_setpoint_pub{ORB_ID(surface_vehicle_position_setpoint)};
|
||||
uORB::Publication<position_controller_status_s> _position_controller_status_pub{ORB_ID(position_controller_status)};
|
||||
|
||||
// Variables
|
||||
@@ -127,14 +127,14 @@ private:
|
||||
int _curr_wp_type{position_setpoint_s::SETPOINT_TYPE_IDLE};
|
||||
|
||||
DEFINE_PARAMETERS(
|
||||
(ParamFloat<px4::params::RO_YAW_RATE_LIM>) _param_ro_yaw_rate_limit,
|
||||
(ParamFloat<px4::params::RO_SPEED_LIM>) _param_ro_speed_limit,
|
||||
(ParamFloat<px4::params::SV_YAW_RATE_LIM>) _param_sv_yaw_rate_limit,
|
||||
(ParamFloat<px4::params::SV_SPEED_LIM>) _param_sv_speed_limit,
|
||||
(ParamFloat<px4::params::RA_WHEEL_BASE>) _param_ra_wheel_base,
|
||||
(ParamFloat<px4::params::RA_MAX_STR_ANG>) _param_ra_max_str_ang,
|
||||
(ParamFloat<px4::params::NAV_ACC_RAD>) _param_nav_acc_rad,
|
||||
(ParamFloat<px4::params::RA_ACC_RAD_MAX>) _param_ra_acc_rad_max,
|
||||
(ParamFloat<px4::params::RA_ACC_RAD_GAIN>) _param_ra_acc_rad_gain,
|
||||
(ParamFloat<px4::params::RO_SPEED_RED>) _param_ro_speed_red,
|
||||
(ParamFloat<px4::params::RO_MAX_THR_SPEED>) _param_ro_max_thr_speed
|
||||
(ParamFloat<px4::params::SV_SPEED_RED>) _param_sv_speed_red,
|
||||
(ParamFloat<px4::params::SV_MAX_THR_SPEED>) _param_sv_max_thr_speed
|
||||
)
|
||||
};
|
||||
|
||||
+82
-82
@@ -38,50 +38,50 @@ using namespace time_literals;
|
||||
AckermannManualMode::AckermannManualMode(ModuleParams *parent) : ModuleParams(parent)
|
||||
{
|
||||
updateParams();
|
||||
_rover_throttle_setpoint_pub.advertise();
|
||||
_rover_steering_setpoint_pub.advertise();
|
||||
_rover_rate_setpoint_pub.advertise();
|
||||
_rover_attitude_setpoint_pub.advertise();
|
||||
_rover_speed_setpoint_pub.advertise();
|
||||
_rover_position_setpoint_pub.advertise();
|
||||
_surface_vehicle_throttle_setpoint_pub.advertise();
|
||||
_surface_vehicle_steering_setpoint_pub.advertise();
|
||||
_surface_vehicle_rate_setpoint_pub.advertise();
|
||||
_surface_vehicle_attitude_setpoint_pub.advertise();
|
||||
_surface_vehicle_speed_setpoint_pub.advertise();
|
||||
_surface_vehicle_position_setpoint_pub.advertise();
|
||||
}
|
||||
|
||||
void AckermannManualMode::updateParams()
|
||||
{
|
||||
ModuleParams::updateParams();
|
||||
_max_yaw_rate = _param_ro_yaw_rate_limit.get() * M_DEG_TO_RAD_F;
|
||||
_max_yaw_rate = _param_sv_yaw_rate_limit.get() * M_DEG_TO_RAD_F;
|
||||
}
|
||||
|
||||
void AckermannManualMode::manual()
|
||||
{
|
||||
manual_control_setpoint_s manual_control_setpoint{};
|
||||
_manual_control_setpoint_sub.copy(&manual_control_setpoint);
|
||||
rover_steering_setpoint_s rover_steering_setpoint{};
|
||||
rover_steering_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_steering_setpoint.normalized_steering_setpoint = manual_control_setpoint.roll;
|
||||
_rover_steering_setpoint_pub.publish(rover_steering_setpoint);
|
||||
rover_throttle_setpoint_s rover_throttle_setpoint{};
|
||||
rover_throttle_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_throttle_setpoint.throttle_body_x = manual_control_setpoint.throttle;
|
||||
rover_throttle_setpoint.throttle_body_y = 0.f;
|
||||
_rover_throttle_setpoint_pub.publish(rover_throttle_setpoint);
|
||||
surface_vehicle_steering_setpoint_s surface_vehicle_steering_setpoint{};
|
||||
surface_vehicle_steering_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_steering_setpoint.normalized_steering_setpoint = manual_control_setpoint.roll;
|
||||
_surface_vehicle_steering_setpoint_pub.publish(surface_vehicle_steering_setpoint);
|
||||
surface_vehicle_throttle_setpoint_s surface_vehicle_throttle_setpoint{};
|
||||
surface_vehicle_throttle_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_throttle_setpoint.throttle_body_x = manual_control_setpoint.throttle;
|
||||
surface_vehicle_throttle_setpoint.throttle_body_y = 0.f;
|
||||
_surface_vehicle_throttle_setpoint_pub.publish(surface_vehicle_throttle_setpoint);
|
||||
}
|
||||
|
||||
void AckermannManualMode::acro()
|
||||
{
|
||||
manual_control_setpoint_s manual_control_setpoint{};
|
||||
_manual_control_setpoint_sub.copy(&manual_control_setpoint);
|
||||
rover_throttle_setpoint_s rover_throttle_setpoint{};
|
||||
rover_throttle_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_throttle_setpoint.throttle_body_x = manual_control_setpoint.throttle;
|
||||
rover_throttle_setpoint.throttle_body_y = 0.f;
|
||||
_rover_throttle_setpoint_pub.publish(rover_throttle_setpoint);
|
||||
rover_rate_setpoint_s rover_rate_setpoint{};
|
||||
rover_rate_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_rate_setpoint.yaw_rate_setpoint = matrix::sign(manual_control_setpoint.throttle) * _max_yaw_rate *
|
||||
math::superexpo<float>
|
||||
(manual_control_setpoint.roll, _param_ro_yaw_expo.get(), _param_ro_yaw_supexpo.get());
|
||||
_rover_rate_setpoint_pub.publish(rover_rate_setpoint);
|
||||
surface_vehicle_throttle_setpoint_s surface_vehicle_throttle_setpoint{};
|
||||
surface_vehicle_throttle_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_throttle_setpoint.throttle_body_x = manual_control_setpoint.throttle;
|
||||
surface_vehicle_throttle_setpoint.throttle_body_y = 0.f;
|
||||
_surface_vehicle_throttle_setpoint_pub.publish(surface_vehicle_throttle_setpoint);
|
||||
surface_vehicle_rate_setpoint_s surface_vehicle_rate_setpoint{};
|
||||
surface_vehicle_rate_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_rate_setpoint.yaw_rate_setpoint = matrix::sign(manual_control_setpoint.throttle) * _max_yaw_rate *
|
||||
math::superexpo<float>
|
||||
(manual_control_setpoint.roll, _param_sv_yaw_expo.get(), _param_sv_yaw_supexpo.get());
|
||||
_surface_vehicle_rate_setpoint_pub.publish(surface_vehicle_rate_setpoint);
|
||||
}
|
||||
|
||||
void AckermannManualMode::stab()
|
||||
@@ -95,39 +95,39 @@ void AckermannManualMode::stab()
|
||||
|
||||
manual_control_setpoint_s manual_control_setpoint{};
|
||||
_manual_control_setpoint_sub.copy(&manual_control_setpoint);
|
||||
rover_throttle_setpoint_s rover_throttle_setpoint{};
|
||||
rover_throttle_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_throttle_setpoint.throttle_body_x = manual_control_setpoint.throttle;
|
||||
rover_throttle_setpoint.throttle_body_y = 0.f;
|
||||
_rover_throttle_setpoint_pub.publish(rover_throttle_setpoint);
|
||||
surface_vehicle_throttle_setpoint_s surface_vehicle_throttle_setpoint{};
|
||||
surface_vehicle_throttle_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_throttle_setpoint.throttle_body_x = manual_control_setpoint.throttle;
|
||||
surface_vehicle_throttle_setpoint.throttle_body_y = 0.f;
|
||||
_surface_vehicle_throttle_setpoint_pub.publish(surface_vehicle_throttle_setpoint);
|
||||
|
||||
if (fabsf(manual_control_setpoint.roll) > FLT_EPSILON
|
||||
|| fabsf(rover_throttle_setpoint.throttle_body_x) < FLT_EPSILON) {
|
||||
|| fabsf(surface_vehicle_throttle_setpoint.throttle_body_x) < FLT_EPSILON) {
|
||||
_stab_yaw_setpoint = NAN;
|
||||
|
||||
// Rate control
|
||||
rover_rate_setpoint_s rover_rate_setpoint{};
|
||||
rover_rate_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_rate_setpoint.yaw_rate_setpoint = matrix::sign(manual_control_setpoint.throttle) * _max_yaw_rate *
|
||||
math::superexpo<float>(math::deadzone(manual_control_setpoint.roll,
|
||||
_param_ro_yaw_stick_dz.get()), _param_ro_yaw_expo.get(), _param_ro_yaw_supexpo.get());
|
||||
_rover_rate_setpoint_pub.publish(rover_rate_setpoint);
|
||||
surface_vehicle_rate_setpoint_s surface_vehicle_rate_setpoint{};
|
||||
surface_vehicle_rate_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_rate_setpoint.yaw_rate_setpoint = matrix::sign(manual_control_setpoint.throttle) * _max_yaw_rate *
|
||||
math::superexpo<float>(math::deadzone(manual_control_setpoint.roll,
|
||||
_param_sv_yaw_stick_dz.get()), _param_sv_yaw_expo.get(), _param_sv_yaw_supexpo.get());
|
||||
_surface_vehicle_rate_setpoint_pub.publish(surface_vehicle_rate_setpoint);
|
||||
|
||||
// Set uncontrolled setpoint invalid
|
||||
rover_attitude_setpoint_s rover_attitude_setpoint{};
|
||||
rover_attitude_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_attitude_setpoint.yaw_setpoint = NAN;
|
||||
_rover_attitude_setpoint_pub.publish(rover_attitude_setpoint);
|
||||
surface_vehicle_attitude_setpoint_s surface_vehicle_attitude_setpoint{};
|
||||
surface_vehicle_attitude_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_attitude_setpoint.yaw_setpoint = NAN;
|
||||
_surface_vehicle_attitude_setpoint_pub.publish(surface_vehicle_attitude_setpoint);
|
||||
|
||||
} else { // Heading control
|
||||
if (!PX4_ISFINITE(_stab_yaw_setpoint)) {
|
||||
_stab_yaw_setpoint = _vehicle_yaw;
|
||||
}
|
||||
|
||||
rover_attitude_setpoint_s rover_attitude_setpoint{};
|
||||
rover_attitude_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_attitude_setpoint.yaw_setpoint = _stab_yaw_setpoint;
|
||||
_rover_attitude_setpoint_pub.publish(rover_attitude_setpoint);
|
||||
surface_vehicle_attitude_setpoint_s surface_vehicle_attitude_setpoint{};
|
||||
surface_vehicle_attitude_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_attitude_setpoint.yaw_setpoint = _stab_yaw_setpoint;
|
||||
_surface_vehicle_attitude_setpoint_pub.publish(surface_vehicle_attitude_setpoint);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,42 +157,42 @@ void AckermannManualMode::position()
|
||||
_manual_control_setpoint_sub.copy(&manual_control_setpoint);
|
||||
|
||||
const float speed_setpoint = math::interpolate<float>(manual_control_setpoint.throttle,
|
||||
-1.f, 1.f, -_param_ro_speed_limit.get(), _param_ro_speed_limit.get());
|
||||
-1.f, 1.f, -_param_sv_speed_limit.get(), _param_sv_speed_limit.get());
|
||||
|
||||
if (fabsf(manual_control_setpoint.roll) > FLT_EPSILON
|
||||
|| fabsf(speed_setpoint) < FLT_EPSILON) {
|
||||
_pos_ctl_course_direction = Vector2f(NAN, NAN);
|
||||
|
||||
// Speed control
|
||||
rover_speed_setpoint_s rover_speed_setpoint{};
|
||||
rover_speed_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_speed_setpoint.speed_body_x = speed_setpoint;
|
||||
_rover_speed_setpoint_pub.publish(rover_speed_setpoint);
|
||||
surface_vehicle_speed_setpoint_s surface_vehicle_speed_setpoint{};
|
||||
surface_vehicle_speed_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_speed_setpoint.speed_body_x = speed_setpoint;
|
||||
_surface_vehicle_speed_setpoint_pub.publish(surface_vehicle_speed_setpoint);
|
||||
|
||||
// Rate control
|
||||
rover_rate_setpoint_s rover_rate_setpoint{};
|
||||
rover_rate_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_rate_setpoint.yaw_rate_setpoint = matrix::sign(manual_control_setpoint.throttle) * _max_yaw_rate *
|
||||
math::superexpo<float>(math::deadzone(manual_control_setpoint.roll,
|
||||
_param_ro_yaw_stick_dz.get()), _param_ro_yaw_expo.get(), _param_ro_yaw_supexpo.get());
|
||||
_rover_rate_setpoint_pub.publish(rover_rate_setpoint);
|
||||
surface_vehicle_rate_setpoint_s surface_vehicle_rate_setpoint{};
|
||||
surface_vehicle_rate_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_rate_setpoint.yaw_rate_setpoint = matrix::sign(manual_control_setpoint.throttle) * _max_yaw_rate *
|
||||
math::superexpo<float>(math::deadzone(manual_control_setpoint.roll,
|
||||
_param_sv_yaw_stick_dz.get()), _param_sv_yaw_expo.get(), _param_sv_yaw_supexpo.get());
|
||||
_surface_vehicle_rate_setpoint_pub.publish(surface_vehicle_rate_setpoint);
|
||||
|
||||
// Set uncontrolled setpoints invalid
|
||||
rover_attitude_setpoint_s rover_attitude_setpoint{};
|
||||
rover_attitude_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_attitude_setpoint.yaw_setpoint = NAN;
|
||||
_rover_attitude_setpoint_pub.publish(rover_attitude_setpoint);
|
||||
surface_vehicle_attitude_setpoint_s surface_vehicle_attitude_setpoint{};
|
||||
surface_vehicle_attitude_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_attitude_setpoint.yaw_setpoint = NAN;
|
||||
_surface_vehicle_attitude_setpoint_pub.publish(surface_vehicle_attitude_setpoint);
|
||||
|
||||
rover_position_setpoint_s rover_position_setpoint{};
|
||||
rover_position_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_position_setpoint.position_ned[0] = NAN;
|
||||
rover_position_setpoint.position_ned[1] = NAN;
|
||||
rover_position_setpoint.start_ned[0] = NAN;
|
||||
rover_position_setpoint.start_ned[1] = NAN;
|
||||
rover_position_setpoint.arrival_speed = NAN;
|
||||
rover_position_setpoint.cruising_speed = NAN;
|
||||
rover_position_setpoint.yaw = NAN;
|
||||
_rover_position_setpoint_pub.publish(rover_position_setpoint);
|
||||
surface_vehicle_position_setpoint_s surface_vehicle_position_setpoint{};
|
||||
surface_vehicle_position_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_position_setpoint.position_ned[0] = NAN;
|
||||
surface_vehicle_position_setpoint.position_ned[1] = NAN;
|
||||
surface_vehicle_position_setpoint.start_ned[0] = NAN;
|
||||
surface_vehicle_position_setpoint.start_ned[1] = NAN;
|
||||
surface_vehicle_position_setpoint.arrival_speed = NAN;
|
||||
surface_vehicle_position_setpoint.cruising_speed = NAN;
|
||||
surface_vehicle_position_setpoint.yaw = NAN;
|
||||
_surface_vehicle_position_setpoint_pub.publish(surface_vehicle_position_setpoint);
|
||||
|
||||
} else { // Course control
|
||||
if (!_pos_ctl_course_direction.isAllFinite()) {
|
||||
@@ -205,16 +205,16 @@ void AckermannManualMode::position()
|
||||
const float vector_scaling = fabsf(start_to_curr_pos * _pos_ctl_course_direction) + _param_pp_lookahd_max.get();
|
||||
const Vector2f target_waypoint_ned = _pos_ctl_start_position_ned + sign(speed_setpoint) *
|
||||
vector_scaling * _pos_ctl_course_direction;
|
||||
rover_position_setpoint_s rover_position_setpoint{};
|
||||
rover_position_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_position_setpoint.position_ned[0] = target_waypoint_ned(0);
|
||||
rover_position_setpoint.position_ned[1] = target_waypoint_ned(1);
|
||||
rover_position_setpoint.start_ned[0] = _pos_ctl_start_position_ned(0);
|
||||
rover_position_setpoint.start_ned[1] = _pos_ctl_start_position_ned(1);
|
||||
rover_position_setpoint.arrival_speed = NAN;
|
||||
rover_position_setpoint.cruising_speed = speed_setpoint;
|
||||
rover_position_setpoint.yaw = NAN;
|
||||
_rover_position_setpoint_pub.publish(rover_position_setpoint);
|
||||
surface_vehicle_position_setpoint_s surface_vehicle_position_setpoint{};
|
||||
surface_vehicle_position_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_position_setpoint.position_ned[0] = target_waypoint_ned(0);
|
||||
surface_vehicle_position_setpoint.position_ned[1] = target_waypoint_ned(1);
|
||||
surface_vehicle_position_setpoint.start_ned[0] = _pos_ctl_start_position_ned(0);
|
||||
surface_vehicle_position_setpoint.start_ned[1] = _pos_ctl_start_position_ned(1);
|
||||
surface_vehicle_position_setpoint.arrival_speed = NAN;
|
||||
surface_vehicle_position_setpoint.cruising_speed = speed_setpoint;
|
||||
surface_vehicle_position_setpoint.yaw = NAN;
|
||||
_surface_vehicle_position_setpoint_pub.publish(surface_vehicle_position_setpoint);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+23
-23
@@ -37,7 +37,7 @@
|
||||
#include <px4_platform_common/module_params.h>
|
||||
|
||||
// Libraries
|
||||
#include <lib/rover_control/RoverControl.hpp>
|
||||
#include <lib/surface_vehicle_control/SurfaceVehicleControl.hpp>
|
||||
#include <math.h>
|
||||
|
||||
// uORB includes
|
||||
@@ -47,12 +47,12 @@
|
||||
#include <uORB/topics/vehicle_status.h>
|
||||
#include <uORB/topics/vehicle_attitude.h>
|
||||
#include <uORB/topics/vehicle_local_position.h>
|
||||
#include <uORB/topics/rover_throttle_setpoint.h>
|
||||
#include <uORB/topics/rover_steering_setpoint.h>
|
||||
#include <uORB/topics/rover_rate_setpoint.h>
|
||||
#include <uORB/topics/rover_attitude_setpoint.h>
|
||||
#include <uORB/topics/rover_speed_setpoint.h>
|
||||
#include <uORB/topics/rover_position_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_throttle_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_steering_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_rate_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_attitude_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_speed_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_position_setpoint.h>
|
||||
|
||||
/**
|
||||
* @brief Class for ackermann manual mode.
|
||||
@@ -68,22 +68,22 @@ public:
|
||||
~AckermannManualMode() = default;
|
||||
|
||||
/**
|
||||
* @brief Publish roverThrottleSetpoint and roverSteeringSetpoint from manualControlSetpoint.
|
||||
* @brief Publish SurfaceVehicleThrottleSetpoint and SurfaceVehicleSteeringSetpoint from manualControlSetpoint.
|
||||
*/
|
||||
void manual();
|
||||
|
||||
/**
|
||||
* @brief Generate and publish roverThrottleSetpoint and RoverRateSetpoint from manualControlSetpoint.
|
||||
* @brief Generate and publish SurfaceVehicleThrottleSetpoint and SurfaceVehicleRateSetpoint from manualControlSetpoint.
|
||||
*/
|
||||
void acro();
|
||||
|
||||
/**
|
||||
* @brief Generate and publish roverThrottleSetpoint and RoverAttitudeSetpoint from manualControlSetpoint.
|
||||
* @brief Generate and publish SurfaceVehicleThrottleSetpoint and SurfaceVehicleAttitudeSetpoint from manualControlSetpoint.
|
||||
*/
|
||||
void stab();
|
||||
|
||||
/**
|
||||
* @brief Generate and publish roverSpeedSetpoint/roverRateSetpoint or roverPositionSetpoint from manualControlSetpoint.
|
||||
* @brief Generate and publish SurfaceVehicleSpeedSetpoint/SurfaceVehicleRateSetpoint or SurfaceVehiclePositionSetpoint from manualControlSetpoint.
|
||||
*/
|
||||
void position();
|
||||
|
||||
@@ -105,12 +105,12 @@ private:
|
||||
uORB::Subscription _vehicle_local_position_sub{ORB_ID(vehicle_local_position)};
|
||||
|
||||
// uORB publications
|
||||
uORB::Publication<rover_throttle_setpoint_s> _rover_throttle_setpoint_pub{ORB_ID(rover_throttle_setpoint)};
|
||||
uORB::Publication<rover_steering_setpoint_s> _rover_steering_setpoint_pub{ORB_ID(rover_steering_setpoint)};
|
||||
uORB::Publication<rover_rate_setpoint_s> _rover_rate_setpoint_pub{ORB_ID(rover_rate_setpoint)};
|
||||
uORB::Publication<rover_attitude_setpoint_s> _rover_attitude_setpoint_pub{ORB_ID(rover_attitude_setpoint)};
|
||||
uORB::Publication<rover_speed_setpoint_s> _rover_speed_setpoint_pub{ORB_ID(rover_speed_setpoint)};
|
||||
uORB::Publication<rover_position_setpoint_s> _rover_position_setpoint_pub{ORB_ID(rover_position_setpoint)};
|
||||
uORB::Publication<surface_vehicle_throttle_setpoint_s> _surface_vehicle_throttle_setpoint_pub{ORB_ID(surface_vehicle_throttle_setpoint)};
|
||||
uORB::Publication<surface_vehicle_steering_setpoint_s> _surface_vehicle_steering_setpoint_pub{ORB_ID(surface_vehicle_steering_setpoint)};
|
||||
uORB::Publication<surface_vehicle_rate_setpoint_s> _surface_vehicle_rate_setpoint_pub{ORB_ID(surface_vehicle_rate_setpoint)};
|
||||
uORB::Publication<surface_vehicle_attitude_setpoint_s> _surface_vehicle_attitude_setpoint_pub{ORB_ID(surface_vehicle_attitude_setpoint)};
|
||||
uORB::Publication<surface_vehicle_speed_setpoint_s> _surface_vehicle_speed_setpoint_pub{ORB_ID(surface_vehicle_speed_setpoint)};
|
||||
uORB::Publication<surface_vehicle_position_setpoint_s> _surface_vehicle_position_setpoint_pub{ORB_ID(surface_vehicle_position_setpoint)};
|
||||
|
||||
// Variables
|
||||
MapProjection _global_ned_proj_ref{}; // Transform global to NED coordinates
|
||||
@@ -123,12 +123,12 @@ private:
|
||||
float _max_yaw_rate{NAN};
|
||||
|
||||
DEFINE_PARAMETERS(
|
||||
(ParamFloat<px4::params::RO_YAW_RATE_LIM>) _param_ro_yaw_rate_limit,
|
||||
(ParamFloat<px4::params::RO_YAW_P>) _param_ro_yaw_p,
|
||||
(ParamFloat<px4::params::RO_YAW_STICK_DZ>) _param_ro_yaw_stick_dz,
|
||||
(ParamFloat<px4::params::RO_YAW_EXPO>) _param_ro_yaw_expo,
|
||||
(ParamFloat<px4::params::RO_YAW_SUPEXPO>) _param_ro_yaw_supexpo,
|
||||
(ParamFloat<px4::params::SV_YAW_RATE_LIM>) _param_sv_yaw_rate_limit,
|
||||
(ParamFloat<px4::params::SV_YAW_P>) _param_sv_yaw_p,
|
||||
(ParamFloat<px4::params::SV_YAW_STICK_DZ>) _param_sv_yaw_stick_dz,
|
||||
(ParamFloat<px4::params::SV_YAW_EXPO>) _param_sv_yaw_expo,
|
||||
(ParamFloat<px4::params::SV_YAW_SUPEXPO>) _param_sv_yaw_supexpo,
|
||||
(ParamFloat<px4::params::PP_LOOKAHD_MAX>) _param_pp_lookahd_max,
|
||||
(ParamFloat<px4::params::RO_SPEED_LIM>) _param_ro_speed_limit
|
||||
(ParamFloat<px4::params::SV_SPEED_LIM>) _param_sv_speed_limit
|
||||
)
|
||||
};
|
||||
|
||||
+21
-21
@@ -38,9 +38,9 @@ using namespace time_literals;
|
||||
AckermannOffboardMode::AckermannOffboardMode(ModuleParams *parent) : ModuleParams(parent)
|
||||
{
|
||||
updateParams();
|
||||
_rover_speed_setpoint_pub.advertise();
|
||||
_rover_position_setpoint_pub.advertise();
|
||||
_rover_attitude_setpoint_pub.advertise();
|
||||
_surface_vehicle_speed_setpoint_pub.advertise();
|
||||
_surface_vehicle_position_setpoint_pub.advertise();
|
||||
_surface_vehicle_attitude_setpoint_pub.advertise();
|
||||
}
|
||||
|
||||
void AckermannOffboardMode::updateParams()
|
||||
@@ -57,26 +57,26 @@ void AckermannOffboardMode::offboardControl()
|
||||
_trajectory_setpoint_sub.copy(&trajectory_setpoint);
|
||||
|
||||
if (offboard_control_mode.position) {
|
||||
rover_position_setpoint_s rover_position_setpoint{};
|
||||
rover_position_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_position_setpoint.position_ned[0] = trajectory_setpoint.position[0];
|
||||
rover_position_setpoint.position_ned[1] = trajectory_setpoint.position[1];
|
||||
rover_position_setpoint.start_ned[0] = NAN;
|
||||
rover_position_setpoint.start_ned[1] = NAN;
|
||||
rover_position_setpoint.cruising_speed = NAN;
|
||||
rover_position_setpoint.arrival_speed = NAN;
|
||||
rover_position_setpoint.yaw = NAN;
|
||||
_rover_position_setpoint_pub.publish(rover_position_setpoint);
|
||||
surface_vehicle_position_setpoint_s surface_vehicle_position_setpoint{};
|
||||
surface_vehicle_position_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_position_setpoint.position_ned[0] = trajectory_setpoint.position[0];
|
||||
surface_vehicle_position_setpoint.position_ned[1] = trajectory_setpoint.position[1];
|
||||
surface_vehicle_position_setpoint.start_ned[0] = NAN;
|
||||
surface_vehicle_position_setpoint.start_ned[1] = NAN;
|
||||
surface_vehicle_position_setpoint.cruising_speed = NAN;
|
||||
surface_vehicle_position_setpoint.arrival_speed = NAN;
|
||||
surface_vehicle_position_setpoint.yaw = NAN;
|
||||
_surface_vehicle_position_setpoint_pub.publish(surface_vehicle_position_setpoint);
|
||||
|
||||
} else if (offboard_control_mode.velocity) {
|
||||
const Vector2f velocity_ned(trajectory_setpoint.velocity[0], trajectory_setpoint.velocity[1]);
|
||||
rover_speed_setpoint_s rover_speed_setpoint{};
|
||||
rover_speed_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_speed_setpoint.speed_body_x = velocity_ned.norm();
|
||||
_rover_speed_setpoint_pub.publish(rover_speed_setpoint);
|
||||
rover_attitude_setpoint_s rover_attitude_setpoint{};
|
||||
rover_attitude_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_attitude_setpoint.yaw_setpoint = atan2f(velocity_ned(1), velocity_ned(0));
|
||||
_rover_attitude_setpoint_pub.publish(rover_attitude_setpoint);
|
||||
surface_vehicle_speed_setpoint_s surface_vehicle_speed_setpoint{};
|
||||
surface_vehicle_speed_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_speed_setpoint.speed_body_x = velocity_ned.norm();
|
||||
_surface_vehicle_speed_setpoint_pub.publish(surface_vehicle_speed_setpoint);
|
||||
surface_vehicle_attitude_setpoint_s surface_vehicle_attitude_setpoint{};
|
||||
surface_vehicle_attitude_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_attitude_setpoint.yaw_setpoint = atan2f(velocity_ned(1), velocity_ned(0));
|
||||
_surface_vehicle_attitude_setpoint_pub.publish(surface_vehicle_attitude_setpoint);
|
||||
}
|
||||
}
|
||||
|
||||
+6
-6
@@ -43,9 +43,9 @@
|
||||
// uORB includes
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/topics/rover_speed_setpoint.h>
|
||||
#include <uORB/topics/rover_attitude_setpoint.h>
|
||||
#include <uORB/topics/rover_position_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_speed_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_attitude_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_position_setpoint.h>
|
||||
#include <uORB/topics/offboard_control_mode.h>
|
||||
#include <uORB/topics/trajectory_setpoint.h>
|
||||
|
||||
@@ -81,7 +81,7 @@ private:
|
||||
uORB::Subscription _offboard_control_mode_sub{ORB_ID(offboard_control_mode)};
|
||||
|
||||
// uORB publications
|
||||
uORB::Publication<rover_speed_setpoint_s> _rover_speed_setpoint_pub{ORB_ID(rover_speed_setpoint)};
|
||||
uORB::Publication<rover_position_setpoint_s> _rover_position_setpoint_pub{ORB_ID(rover_position_setpoint)};
|
||||
uORB::Publication<rover_attitude_setpoint_s> _rover_attitude_setpoint_pub{ORB_ID(rover_attitude_setpoint)};
|
||||
uORB::Publication<surface_vehicle_speed_setpoint_s> _surface_vehicle_speed_setpoint_pub{ORB_ID(surface_vehicle_speed_setpoint)};
|
||||
uORB::Publication<surface_vehicle_position_setpoint_s> _surface_vehicle_position_setpoint_pub{ORB_ID(surface_vehicle_position_setpoint)};
|
||||
uORB::Publication<surface_vehicle_attitude_setpoint_s> _surface_vehicle_attitude_setpoint_pub{ORB_ID(surface_vehicle_attitude_setpoint)};
|
||||
};
|
||||
|
||||
@@ -38,8 +38,8 @@ using namespace time_literals;
|
||||
AckermannPosControl::AckermannPosControl(ModuleParams *parent) : ModuleParams(parent)
|
||||
{
|
||||
_pure_pursuit_status_pub.advertise();
|
||||
_rover_speed_setpoint_pub.advertise();
|
||||
_rover_attitude_setpoint_pub.advertise();
|
||||
_surface_vehicle_speed_setpoint_pub.advertise();
|
||||
_surface_vehicle_attitude_setpoint_pub.advertise();
|
||||
|
||||
updateParams();
|
||||
}
|
||||
@@ -47,7 +47,7 @@ AckermannPosControl::AckermannPosControl(ModuleParams *parent) : ModuleParams(pa
|
||||
void AckermannPosControl::updateParams()
|
||||
{
|
||||
ModuleParams::updateParams();
|
||||
_max_yaw_rate = _param_ro_yaw_rate_limit.get() * M_DEG_TO_RAD_F;
|
||||
_max_yaw_rate = _param_sv_yaw_rate_limit.get() * M_DEG_TO_RAD_F;
|
||||
_min_speed = _param_ra_wheel_base.get() * _max_yaw_rate / tanf(_param_ra_max_str_ang.get());
|
||||
|
||||
}
|
||||
@@ -67,8 +67,8 @@ void AckermannPosControl::updatePosControl()
|
||||
|
||||
if (distance_to_target > _acceptance_radius || _arrival_speed > FLT_EPSILON) {
|
||||
|
||||
float speed_setpoint = math::trajectory::computeMaxSpeedFromDistance(_param_ro_jerk_limit.get(),
|
||||
_param_ro_decel_limit.get(), distance_to_target, fabsf(_arrival_speed));
|
||||
float speed_setpoint = math::trajectory::computeMaxSpeedFromDistance(_param_sv_jerk_limit.get(),
|
||||
_param_sv_decel_limit.get(), distance_to_target, fabsf(_arrival_speed));
|
||||
speed_setpoint = math::min(speed_setpoint, _cruising_speed);
|
||||
|
||||
pure_pursuit_status_s pure_pursuit_status{};
|
||||
@@ -78,35 +78,35 @@ void AckermannPosControl::updatePosControl()
|
||||
_param_pp_lookahd_max.get(), _param_pp_lookahd_min.get(), _target_waypoint_ned, _start_ned,
|
||||
_curr_pos_ned, fabsf(speed_setpoint));
|
||||
|
||||
if (_param_ro_speed_red.get() > FLT_EPSILON) {
|
||||
if (_param_sv_speed_red.get() > FLT_EPSILON) {
|
||||
const float course_error = fabsf(matrix::wrap_pi(bearing_setpoint - _vehicle_yaw));
|
||||
const float speed_reduction = math::constrain(_param_ro_speed_red.get() * math::interpolate(course_error,
|
||||
const float speed_reduction = math::constrain(_param_sv_speed_red.get() * math::interpolate(course_error,
|
||||
0.f, M_PI_F, 0.f, 1.f), 0.f, 1.f);
|
||||
const float max_speed = math::constrain(_param_ro_max_thr_speed.get() * (1.f - speed_reduction), _min_speed,
|
||||
_param_ro_max_thr_speed.get());
|
||||
const float max_speed = math::constrain(_param_sv_max_thr_speed.get() * (1.f - speed_reduction), _min_speed,
|
||||
_param_sv_max_thr_speed.get());
|
||||
speed_setpoint = math::constrain(speed_setpoint, -max_speed, max_speed);
|
||||
}
|
||||
|
||||
_pure_pursuit_status_pub.publish(pure_pursuit_status);
|
||||
rover_speed_setpoint_s rover_speed_setpoint{};
|
||||
rover_speed_setpoint.timestamp = timestamp;
|
||||
rover_speed_setpoint.speed_body_x = speed_setpoint;
|
||||
_rover_speed_setpoint_pub.publish(rover_speed_setpoint);
|
||||
rover_attitude_setpoint_s rover_attitude_setpoint{};
|
||||
rover_attitude_setpoint.timestamp = timestamp;
|
||||
rover_attitude_setpoint.yaw_setpoint = speed_setpoint > -FLT_EPSILON ? bearing_setpoint : matrix::wrap_pi(
|
||||
bearing_setpoint + M_PI_F);
|
||||
_rover_attitude_setpoint_pub.publish(rover_attitude_setpoint);
|
||||
surface_vehicle_speed_setpoint_s surface_vehicle_speed_setpoint{};
|
||||
surface_vehicle_speed_setpoint.timestamp = timestamp;
|
||||
surface_vehicle_speed_setpoint.speed_body_x = speed_setpoint;
|
||||
_surface_vehicle_speed_setpoint_pub.publish(surface_vehicle_speed_setpoint);
|
||||
surface_vehicle_attitude_setpoint_s surface_vehicle_attitude_setpoint{};
|
||||
surface_vehicle_attitude_setpoint.timestamp = timestamp;
|
||||
surface_vehicle_attitude_setpoint.yaw_setpoint = speed_setpoint > -FLT_EPSILON ? bearing_setpoint : matrix::wrap_pi(
|
||||
bearing_setpoint + M_PI_F);
|
||||
_surface_vehicle_attitude_setpoint_pub.publish(surface_vehicle_attitude_setpoint);
|
||||
|
||||
} else {
|
||||
rover_speed_setpoint_s rover_speed_setpoint{};
|
||||
rover_speed_setpoint.timestamp = timestamp;
|
||||
rover_speed_setpoint.speed_body_x = 0.f;
|
||||
_rover_speed_setpoint_pub.publish(rover_speed_setpoint);
|
||||
rover_attitude_setpoint_s rover_attitude_setpoint{};
|
||||
rover_attitude_setpoint.timestamp = timestamp;
|
||||
rover_attitude_setpoint.yaw_setpoint = _vehicle_yaw;
|
||||
_rover_attitude_setpoint_pub.publish(rover_attitude_setpoint);
|
||||
surface_vehicle_speed_setpoint_s surface_vehicle_speed_setpoint{};
|
||||
surface_vehicle_speed_setpoint.timestamp = timestamp;
|
||||
surface_vehicle_speed_setpoint.speed_body_x = 0.f;
|
||||
_surface_vehicle_speed_setpoint_pub.publish(surface_vehicle_speed_setpoint);
|
||||
surface_vehicle_attitude_setpoint_s surface_vehicle_attitude_setpoint{};
|
||||
surface_vehicle_attitude_setpoint.timestamp = timestamp;
|
||||
surface_vehicle_attitude_setpoint.yaw_setpoint = _vehicle_yaw;
|
||||
_surface_vehicle_attitude_setpoint_pub.publish(surface_vehicle_attitude_setpoint);
|
||||
|
||||
if (!_stopped && fabsf(_vehicle_speed) < FLT_EPSILON) {
|
||||
_stopped = true;
|
||||
@@ -144,18 +144,21 @@ void AckermannPosControl::updateSubscriptions()
|
||||
Vector3f velocity_ned(vehicle_local_position.vx, vehicle_local_position.vy, vehicle_local_position.vz);
|
||||
Vector3f velocity_xyz = _vehicle_attitude_quaternion.rotateVectorInverse(velocity_ned);
|
||||
Vector2f velocity_2d = Vector2f(velocity_xyz(0), velocity_xyz(1));
|
||||
_vehicle_speed = velocity_2d.norm() > _param_ro_speed_th.get() ? sign(velocity_2d(0)) * velocity_2d.norm() : 0.f;
|
||||
_vehicle_speed = velocity_2d.norm() > _param_sv_speed_th.get() ? sign(velocity_2d(0)) * velocity_2d.norm() : 0.f;
|
||||
}
|
||||
|
||||
if (_rover_position_setpoint_sub.updated()) {
|
||||
rover_position_setpoint_s rover_position_setpoint;
|
||||
_rover_position_setpoint_sub.copy(&rover_position_setpoint);
|
||||
_start_ned = Vector2f(rover_position_setpoint.start_ned[0], rover_position_setpoint.start_ned[1]);
|
||||
if (_surface_vehicle_position_setpoint_sub.updated()) {
|
||||
surface_vehicle_position_setpoint_s surface_vehicle_position_setpoint;
|
||||
_surface_vehicle_position_setpoint_sub.copy(&surface_vehicle_position_setpoint);
|
||||
_start_ned = Vector2f(surface_vehicle_position_setpoint.start_ned[0], surface_vehicle_position_setpoint.start_ned[1]);
|
||||
_start_ned = _start_ned.isAllFinite() ? _start_ned : _curr_pos_ned;
|
||||
_arrival_speed = PX4_ISFINITE(rover_position_setpoint.arrival_speed) ? rover_position_setpoint.arrival_speed : 0.f;
|
||||
_cruising_speed = PX4_ISFINITE(rover_position_setpoint.cruising_speed) ? rover_position_setpoint.cruising_speed :
|
||||
_param_ro_speed_limit.get();
|
||||
_target_waypoint_ned = Vector2f(rover_position_setpoint.position_ned[0], rover_position_setpoint.position_ned[1]);
|
||||
_arrival_speed = PX4_ISFINITE(surface_vehicle_position_setpoint.arrival_speed) ?
|
||||
surface_vehicle_position_setpoint.arrival_speed : 0.f;
|
||||
_cruising_speed = PX4_ISFINITE(surface_vehicle_position_setpoint.cruising_speed) ?
|
||||
surface_vehicle_position_setpoint.cruising_speed :
|
||||
_param_sv_speed_limit.get();
|
||||
_target_waypoint_ned = Vector2f(surface_vehicle_position_setpoint.position_ned[0],
|
||||
surface_vehicle_position_setpoint.position_ned[1]);
|
||||
_stopped = false;
|
||||
}
|
||||
|
||||
@@ -165,7 +168,7 @@ bool AckermannPosControl::runSanityChecks()
|
||||
{
|
||||
bool ret = true;
|
||||
|
||||
if (_param_ro_speed_limit.get() < FLT_EPSILON) {
|
||||
if (_param_sv_speed_limit.get() < FLT_EPSILON) {
|
||||
ret = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,9 +45,9 @@
|
||||
// uORB includes
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/topics/rover_position_setpoint.h>
|
||||
#include <uORB/topics/rover_speed_setpoint.h>
|
||||
#include <uORB/topics/rover_attitude_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_position_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_speed_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_attitude_setpoint.h>
|
||||
#include <uORB/topics/vehicle_attitude.h>
|
||||
#include <uORB/topics/vehicle_local_position.h>
|
||||
#include <uORB/topics/position_controller_status.h>
|
||||
@@ -69,7 +69,7 @@ public:
|
||||
~AckermannPosControl() = default;
|
||||
|
||||
/**
|
||||
* @brief Generate and publish roverSpeedSetpoint and roverAttitudeSetpoint from roverPositionSetpoint.
|
||||
* @brief Generate and publish SurfaceVehicleSpeedSetpoint and SurfaceVehicleAttitudeSetpoint from SurfaceVehiclePositionSetpoint.
|
||||
*/
|
||||
void updatePosControl();
|
||||
|
||||
@@ -82,7 +82,7 @@ public:
|
||||
/**
|
||||
* @brief Reset position controller.
|
||||
*/
|
||||
void reset() {_start_ned = Vector2f{NAN, NAN}; _target_waypoint_ned = Vector2f{NAN, NAN}; _arrival_speed = 0.f; _cruising_speed = _param_ro_speed_limit.get(); _stopped = false;};
|
||||
void reset() {_start_ned = Vector2f{NAN, NAN}; _target_waypoint_ned = Vector2f{NAN, NAN}; _arrival_speed = 0.f; _cruising_speed = _param_sv_speed_limit.get(); _stopped = false;};
|
||||
|
||||
protected:
|
||||
/**
|
||||
@@ -99,12 +99,12 @@ private:
|
||||
// uORB subscriptions
|
||||
uORB::Subscription _vehicle_attitude_sub{ORB_ID(vehicle_attitude)};
|
||||
uORB::Subscription _vehicle_local_position_sub{ORB_ID(vehicle_local_position)};
|
||||
uORB::Subscription _rover_position_setpoint_sub{ORB_ID(rover_position_setpoint)};
|
||||
uORB::Subscription _surface_vehicle_position_setpoint_sub{ORB_ID(surface_vehicle_position_setpoint)};
|
||||
uORB::Subscription _position_controller_status_sub{ORB_ID(position_controller_status)};
|
||||
|
||||
// uORB publications
|
||||
uORB::Publication<rover_speed_setpoint_s> _rover_speed_setpoint_pub{ORB_ID(rover_speed_setpoint)};
|
||||
uORB::Publication<rover_attitude_setpoint_s> _rover_attitude_setpoint_pub{ORB_ID(rover_attitude_setpoint)};
|
||||
uORB::Publication<surface_vehicle_speed_setpoint_s> _surface_vehicle_speed_setpoint_pub{ORB_ID(surface_vehicle_speed_setpoint)};
|
||||
uORB::Publication<surface_vehicle_attitude_setpoint_s> _surface_vehicle_attitude_setpoint_pub{ORB_ID(surface_vehicle_attitude_setpoint)};
|
||||
uORB::Publication<pure_pursuit_status_s> _pure_pursuit_status_pub{ORB_ID(pure_pursuit_status)};
|
||||
|
||||
// Variables
|
||||
@@ -124,17 +124,17 @@ private:
|
||||
uint8_t _updated_reset_counter{0}; /**< counter for estimator resets in xy-direction */
|
||||
|
||||
DEFINE_PARAMETERS(
|
||||
(ParamFloat<px4::params::RO_MAX_THR_SPEED>) _param_ro_max_thr_speed,
|
||||
(ParamFloat<px4::params::RO_SPEED_RED>) _param_ro_speed_red,
|
||||
(ParamFloat<px4::params::RO_DECEL_LIM>) _param_ro_decel_limit,
|
||||
(ParamFloat<px4::params::RO_JERK_LIM>) _param_ro_jerk_limit,
|
||||
(ParamFloat<px4::params::RO_SPEED_LIM>) _param_ro_speed_limit,
|
||||
(ParamFloat<px4::params::SV_MAX_THR_SPEED>) _param_sv_max_thr_speed,
|
||||
(ParamFloat<px4::params::SV_SPEED_RED>) _param_sv_speed_red,
|
||||
(ParamFloat<px4::params::SV_DECEL_LIM>) _param_sv_decel_limit,
|
||||
(ParamFloat<px4::params::SV_JERK_LIM>) _param_sv_jerk_limit,
|
||||
(ParamFloat<px4::params::SV_SPEED_LIM>) _param_sv_speed_limit,
|
||||
(ParamFloat<px4::params::PP_LOOKAHD_GAIN>) _param_pp_lookahd_gain,
|
||||
(ParamFloat<px4::params::PP_LOOKAHD_MAX>) _param_pp_lookahd_max,
|
||||
(ParamFloat<px4::params::PP_LOOKAHD_MIN>) _param_pp_lookahd_min,
|
||||
(ParamFloat<px4::params::RO_YAW_RATE_LIM>) _param_ro_yaw_rate_limit,
|
||||
(ParamFloat<px4::params::SV_YAW_RATE_LIM>) _param_sv_yaw_rate_limit,
|
||||
(ParamFloat<px4::params::RA_WHEEL_BASE>) _param_ra_wheel_base,
|
||||
(ParamFloat<px4::params::RA_MAX_STR_ANG>) _param_ra_max_str_ang,
|
||||
(ParamFloat<px4::params::RO_SPEED_TH>) _param_ro_speed_th
|
||||
(ParamFloat<px4::params::SV_SPEED_TH>) _param_sv_speed_th
|
||||
)
|
||||
};
|
||||
|
||||
@@ -37,23 +37,23 @@ using namespace time_literals;
|
||||
|
||||
AckermannRateControl::AckermannRateControl(ModuleParams *parent) : ModuleParams(parent)
|
||||
{
|
||||
_rover_steering_setpoint_pub.advertise();
|
||||
_rover_rate_status_pub.advertise();
|
||||
_surface_vehicle_steering_setpoint_pub.advertise();
|
||||
_surface_vehicle_rate_status_pub.advertise();
|
||||
updateParams();
|
||||
}
|
||||
|
||||
void AckermannRateControl::updateParams()
|
||||
{
|
||||
ModuleParams::updateParams();
|
||||
_max_yaw_rate = _param_ro_yaw_rate_limit.get() * M_DEG_TO_RAD_F;
|
||||
_max_yaw_rate = _param_sv_yaw_rate_limit.get() * M_DEG_TO_RAD_F;
|
||||
|
||||
// Set up PID controller
|
||||
_pid_yaw_rate.setGains(_param_ro_yaw_rate_p.get(), _param_ro_yaw_rate_i.get(), 0.f);
|
||||
_pid_yaw_rate.setGains(_param_sv_yaw_rate_p.get(), _param_sv_yaw_rate_i.get(), 0.f);
|
||||
_pid_yaw_rate.setIntegralLimit(1.f);
|
||||
_pid_yaw_rate.setOutputLimit(1.f);
|
||||
|
||||
// Set up slew rate
|
||||
_adjusted_yaw_rate_setpoint.setSlewRate(_param_ro_yaw_accel_limit.get() * M_DEG_TO_RAD_F);
|
||||
_adjusted_yaw_rate_setpoint.setSlewRate(_param_sv_yaw_accel_limit.get() * M_DEG_TO_RAD_F);
|
||||
}
|
||||
|
||||
void AckermannRateControl::updateRateControl()
|
||||
@@ -73,7 +73,7 @@ void AckermannRateControl::updateRateControl()
|
||||
float yaw_rate_limit = math::min(max_possible_yaw_rate, _max_yaw_rate);
|
||||
float constrained_yaw_rate = math::constrain(_yaw_rate_setpoint, -yaw_rate_limit, yaw_rate_limit);
|
||||
|
||||
if (_param_ro_yaw_accel_limit.get() > FLT_EPSILON) { // Apply slew rate if configured
|
||||
if (_param_sv_yaw_accel_limit.get() > FLT_EPSILON) { // Apply slew rate if configured
|
||||
if (fabsf(_adjusted_yaw_rate_setpoint.getState() - _vehicle_yaw_rate) > fabsf(constrained_yaw_rate -
|
||||
_vehicle_yaw_rate)) {
|
||||
_adjusted_yaw_rate_setpoint.setForcedValue(_vehicle_yaw_rate);
|
||||
@@ -87,7 +87,7 @@ void AckermannRateControl::updateRateControl()
|
||||
|
||||
// Feed forward
|
||||
steering_setpoint = atanf(_adjusted_yaw_rate_setpoint.getState() * _param_ra_wheel_base.get() / _estimated_speed) *
|
||||
_param_ro_yaw_rate_corr.get();
|
||||
_param_sv_yaw_rate_corr.get();
|
||||
|
||||
// Feedback (Only when driving forwards because backwards driving is NMP and can introduce instability)
|
||||
if (_estimated_speed > FLT_EPSILON) {
|
||||
@@ -95,29 +95,29 @@ void AckermannRateControl::updateRateControl()
|
||||
steering_setpoint += _pid_yaw_rate.update(_vehicle_yaw_rate, dt);
|
||||
}
|
||||
|
||||
rover_steering_setpoint_s rover_steering_setpoint{};
|
||||
rover_steering_setpoint.timestamp = _timestamp;
|
||||
rover_steering_setpoint.normalized_steering_setpoint = math::interpolate<float>(steering_setpoint,
|
||||
surface_vehicle_steering_setpoint_s surface_vehicle_steering_setpoint{};
|
||||
surface_vehicle_steering_setpoint.timestamp = _timestamp;
|
||||
surface_vehicle_steering_setpoint.normalized_steering_setpoint = math::interpolate<float>(steering_setpoint,
|
||||
-_param_ra_max_str_ang.get(), _param_ra_max_str_ang.get(), -1.f, 1.f); // Normalize steering setpoint
|
||||
_rover_steering_setpoint_pub.publish(rover_steering_setpoint);
|
||||
_surface_vehicle_steering_setpoint_pub.publish(surface_vehicle_steering_setpoint);
|
||||
|
||||
} else {
|
||||
_pid_yaw_rate.resetIntegral();
|
||||
rover_steering_setpoint_s rover_steering_setpoint{};
|
||||
rover_steering_setpoint.timestamp = _timestamp;
|
||||
rover_steering_setpoint.normalized_steering_setpoint = 0.f;
|
||||
_rover_steering_setpoint_pub.publish(rover_steering_setpoint);
|
||||
surface_vehicle_steering_setpoint_s surface_vehicle_steering_setpoint{};
|
||||
surface_vehicle_steering_setpoint.timestamp = _timestamp;
|
||||
surface_vehicle_steering_setpoint.normalized_steering_setpoint = 0.f;
|
||||
_surface_vehicle_steering_setpoint_pub.publish(surface_vehicle_steering_setpoint);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Publish rate controller status (logging only)
|
||||
rover_rate_status_s rover_rate_status;
|
||||
rover_rate_status.timestamp = _timestamp;
|
||||
rover_rate_status.measured_yaw_rate = _vehicle_yaw_rate;
|
||||
rover_rate_status.adjusted_yaw_rate_setpoint = _adjusted_yaw_rate_setpoint.getState();
|
||||
rover_rate_status.pid_yaw_rate_integral = _pid_yaw_rate.getIntegral();
|
||||
_rover_rate_status_pub.publish(rover_rate_status);
|
||||
surface_vehicle_rate_status_s surface_vehicle_rate_status;
|
||||
surface_vehicle_rate_status.timestamp = _timestamp;
|
||||
surface_vehicle_rate_status.measured_yaw_rate = _vehicle_yaw_rate;
|
||||
surface_vehicle_rate_status.adjusted_yaw_rate_setpoint = _adjusted_yaw_rate_setpoint.getState();
|
||||
surface_vehicle_rate_status.pid_yaw_rate_integral = _pid_yaw_rate.getIntegral();
|
||||
_surface_vehicle_rate_status_pub.publish(surface_vehicle_rate_status);
|
||||
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ void AckermannRateControl::updateSubscriptions()
|
||||
if (_vehicle_angular_velocity_sub.updated()) {
|
||||
vehicle_angular_velocity_s vehicle_angular_velocity{};
|
||||
_vehicle_angular_velocity_sub.copy(&vehicle_angular_velocity);
|
||||
_vehicle_yaw_rate = fabsf(vehicle_angular_velocity.xyz[2]) > _param_ro_yaw_rate_th.get() * M_DEG_TO_RAD_F ?
|
||||
_vehicle_yaw_rate = fabsf(vehicle_angular_velocity.xyz[2]) > _param_sv_yaw_rate_th.get() * M_DEG_TO_RAD_F ?
|
||||
vehicle_angular_velocity.xyz[2] : 0.f;
|
||||
}
|
||||
|
||||
@@ -135,14 +135,14 @@ void AckermannRateControl::updateSubscriptions()
|
||||
actuator_motors_s actuator_motors;
|
||||
_actuator_motors_sub.copy(&actuator_motors);
|
||||
_estimated_speed = math::interpolate<float>(actuator_motors.control[0], -1.f, 1.f,
|
||||
-_param_ro_max_thr_speed.get(), _param_ro_max_thr_speed.get());
|
||||
_estimated_speed = fabsf(_estimated_speed) > _param_ro_speed_th.get() ? _estimated_speed : 0.f;
|
||||
-_param_sv_max_thr_speed.get(), _param_sv_max_thr_speed.get());
|
||||
_estimated_speed = fabsf(_estimated_speed) > _param_sv_speed_th.get() ? _estimated_speed : 0.f;
|
||||
}
|
||||
|
||||
if (_rover_rate_setpoint_sub.updated()) {
|
||||
rover_rate_setpoint_s rover_rate_setpoint{};
|
||||
_rover_rate_setpoint_sub.copy(&rover_rate_setpoint);
|
||||
_yaw_rate_setpoint = rover_rate_setpoint.yaw_rate_setpoint;
|
||||
if (_surface_vehicle_rate_setpoint_sub.updated()) {
|
||||
surface_vehicle_rate_setpoint_s surface_vehicle_rate_setpoint{};
|
||||
_surface_vehicle_rate_setpoint_sub.copy(&surface_vehicle_rate_setpoint);
|
||||
_yaw_rate_setpoint = surface_vehicle_rate_setpoint.yaw_rate_setpoint;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,10 +150,10 @@ bool AckermannRateControl::runSanityChecks()
|
||||
{
|
||||
bool ret = true;
|
||||
|
||||
if (_param_ro_max_thr_speed.get() < FLT_EPSILON) {
|
||||
if (_param_sv_max_thr_speed.get() < FLT_EPSILON) {
|
||||
ret = false;
|
||||
events::send<float>(events::ID("ackermann_rate_control_conf_invalid_max_thr_speed"), events::Log::Error,
|
||||
"Invalid configuration of necessary parameter RO_MAX_THR_SPEED", _param_ro_max_thr_speed.get());
|
||||
"Invalid configuration of necessary parameter SV_MAX_THR_SPEED", _param_sv_max_thr_speed.get());
|
||||
|
||||
}
|
||||
|
||||
@@ -171,10 +171,10 @@ bool AckermannRateControl::runSanityChecks()
|
||||
|
||||
}
|
||||
|
||||
if (_param_ro_yaw_rate_limit.get() < FLT_EPSILON) {
|
||||
if (_param_sv_yaw_rate_limit.get() < FLT_EPSILON) {
|
||||
ret = false;
|
||||
events::send<float>(events::ID("ackermann_rate_control_conf_invalid_yaw_rate_lim"), events::Log::Error,
|
||||
"Invalid configuration of necessary parameter RO_YAW_RATE_LIM", _param_ro_yaw_rate_limit.get());
|
||||
"Invalid configuration of necessary parameter SV_YAW_RATE_LIM", _param_sv_yaw_rate_limit.get());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
#include <px4_platform_common/events.h>
|
||||
|
||||
// Libraries
|
||||
#include <lib/rover_control/RoverControl.hpp>
|
||||
#include <lib/surface_vehicle_control/SurfaceVehicleControl.hpp>
|
||||
#include <lib/pid/PID.hpp>
|
||||
#include <lib/slew_rate/SlewRate.hpp>
|
||||
#include <math.h>
|
||||
@@ -46,10 +46,10 @@
|
||||
// uORB includes
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/topics/rover_rate_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_rate_setpoint.h>
|
||||
#include <uORB/topics/vehicle_angular_velocity.h>
|
||||
#include <uORB/topics/rover_steering_setpoint.h>
|
||||
#include <uORB/topics/rover_rate_status.h>
|
||||
#include <uORB/topics/surface_vehicle_steering_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_rate_status.h>
|
||||
#include <uORB/topics/actuator_motors.h>
|
||||
|
||||
/**
|
||||
@@ -66,7 +66,7 @@ public:
|
||||
~AckermannRateControl() = default;
|
||||
|
||||
/**
|
||||
* @brief Generate and publish roverSteeringSetpoint from roverRateSetpoint.
|
||||
* @brief Generate and publish SurfaceVehicleSteeringSetpoint from SurfaceVehicleRateSetpoint.
|
||||
*/
|
||||
void updateRateControl();
|
||||
|
||||
@@ -94,17 +94,17 @@ private:
|
||||
void updateSubscriptions();
|
||||
|
||||
// uORB subscriptions
|
||||
uORB::Subscription _rover_rate_setpoint_sub{ORB_ID(rover_rate_setpoint)};
|
||||
uORB::Subscription _surface_vehicle_rate_setpoint_sub{ORB_ID(surface_vehicle_rate_setpoint)};
|
||||
uORB::Subscription _vehicle_angular_velocity_sub{ORB_ID(vehicle_angular_velocity)};
|
||||
uORB::Subscription _actuator_motors_sub{ORB_ID(actuator_motors)};
|
||||
|
||||
// uORB publications
|
||||
uORB::Publication<rover_steering_setpoint_s> _rover_steering_setpoint_pub{ORB_ID(rover_steering_setpoint)};
|
||||
uORB::Publication<rover_rate_status_s> _rover_rate_status_pub{ORB_ID(rover_rate_status)};
|
||||
uORB::Publication<surface_vehicle_steering_setpoint_s> _surface_vehicle_steering_setpoint_pub{ORB_ID(surface_vehicle_steering_setpoint)};
|
||||
uORB::Publication<surface_vehicle_rate_status_s> _surface_vehicle_rate_status_pub{ORB_ID(surface_vehicle_rate_status)};
|
||||
|
||||
// Variables
|
||||
float _estimated_speed{0.f}; /*Vehicle speed estimated by interpolating [actuatorMotorSetpoint, _estimated_speed]
|
||||
between [0, 0] and [1, _param_ro_max_thr_speed].*/
|
||||
between [0, 0] and [1, _param_sv_max_thr_speed].*/
|
||||
float _max_yaw_rate{0.f};
|
||||
float _vehicle_yaw_rate{0.f};
|
||||
float _yaw_rate_setpoint{NAN};
|
||||
@@ -115,15 +115,15 @@ private:
|
||||
SlewRate<float> _adjusted_yaw_rate_setpoint{0.f};
|
||||
|
||||
DEFINE_PARAMETERS(
|
||||
(ParamFloat<px4::params::RO_MAX_THR_SPEED>) _param_ro_max_thr_speed,
|
||||
(ParamFloat<px4::params::SV_MAX_THR_SPEED>) _param_sv_max_thr_speed,
|
||||
(ParamFloat<px4::params::RA_WHEEL_BASE>) _param_ra_wheel_base,
|
||||
(ParamFloat<px4::params::RA_MAX_STR_ANG>) _param_ra_max_str_ang,
|
||||
(ParamFloat<px4::params::RO_YAW_RATE_LIM>) _param_ro_yaw_rate_limit,
|
||||
(ParamFloat<px4::params::RO_YAW_RATE_TH>) _param_ro_yaw_rate_th,
|
||||
(ParamFloat<px4::params::RO_YAW_RATE_P>) _param_ro_yaw_rate_p,
|
||||
(ParamFloat<px4::params::RO_YAW_RATE_I>) _param_ro_yaw_rate_i,
|
||||
(ParamFloat<px4::params::RO_YAW_ACCEL_LIM>) _param_ro_yaw_accel_limit,
|
||||
(ParamFloat<px4::params::RO_SPEED_TH>) _param_ro_speed_th,
|
||||
(ParamFloat<px4::params::RO_YAW_RATE_CORR>) _param_ro_yaw_rate_corr
|
||||
(ParamFloat<px4::params::SV_YAW_RATE_LIM>) _param_sv_yaw_rate_limit,
|
||||
(ParamFloat<px4::params::SV_YAW_RATE_TH>) _param_sv_yaw_rate_th,
|
||||
(ParamFloat<px4::params::SV_YAW_RATE_P>) _param_sv_yaw_rate_p,
|
||||
(ParamFloat<px4::params::SV_YAW_RATE_I>) _param_sv_yaw_rate_i,
|
||||
(ParamFloat<px4::params::SV_YAW_ACCEL_LIM>) _param_sv_yaw_accel_limit,
|
||||
(ParamFloat<px4::params::SV_SPEED_TH>) _param_sv_speed_th,
|
||||
(ParamFloat<px4::params::SV_YAW_RATE_CORR>) _param_sv_yaw_rate_corr
|
||||
)
|
||||
};
|
||||
|
||||
@@ -37,8 +37,8 @@ using namespace time_literals;
|
||||
|
||||
AckermannSpeedControl::AckermannSpeedControl(ModuleParams *parent) : ModuleParams(parent)
|
||||
{
|
||||
_rover_throttle_setpoint_pub.advertise();
|
||||
_rover_speed_status_pub.advertise();
|
||||
_surface_vehicle_throttle_setpoint_pub.advertise();
|
||||
_surface_vehicle_speed_status_pub.advertise();
|
||||
updateParams();
|
||||
}
|
||||
|
||||
@@ -47,13 +47,13 @@ void AckermannSpeedControl::updateParams()
|
||||
ModuleParams::updateParams();
|
||||
|
||||
// Set up PID controller
|
||||
_pid_speed.setGains(_param_ro_speed_p.get(), _param_ro_speed_i.get(), 0.f);
|
||||
_pid_speed.setGains(_param_sv_speed_p.get(), _param_sv_speed_i.get(), 0.f);
|
||||
_pid_speed.setIntegralLimit(1.f);
|
||||
_pid_speed.setOutputLimit(1.f);
|
||||
|
||||
// Set up slew rate
|
||||
if (_param_ro_accel_limit.get() > FLT_EPSILON) {
|
||||
_adjusted_speed_setpoint.setSlewRate(_param_ro_accel_limit.get());
|
||||
if (_param_sv_accel_limit.get() > FLT_EPSILON) {
|
||||
_adjusted_speed_setpoint.setSlewRate(_param_sv_accel_limit.get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,27 +67,28 @@ void AckermannSpeedControl::updateSpeedControl()
|
||||
|
||||
// Throttle Setpoint
|
||||
if (PX4_ISFINITE(_speed_setpoint)) {
|
||||
const float speed_setpoint = math::constrain(_speed_setpoint, -_param_ro_speed_limit.get(),
|
||||
_param_ro_speed_limit.get());
|
||||
rover_throttle_setpoint_s rover_throttle_setpoint{};
|
||||
rover_throttle_setpoint.timestamp = _timestamp;
|
||||
rover_throttle_setpoint.throttle_body_x = RoverControl::speedControl(_adjusted_speed_setpoint, _pid_speed,
|
||||
speed_setpoint, _vehicle_speed, _param_ro_accel_limit.get(), _param_ro_decel_limit.get(),
|
||||
_param_ro_max_thr_speed.get(), dt);
|
||||
rover_throttle_setpoint.throttle_body_y = NAN;
|
||||
_rover_throttle_setpoint_pub.publish(rover_throttle_setpoint);
|
||||
const float speed_setpoint = math::constrain(_speed_setpoint, -_param_sv_speed_limit.get(),
|
||||
_param_sv_speed_limit.get());
|
||||
surface_vehicle_throttle_setpoint_s surface_vehicle_throttle_setpoint{};
|
||||
surface_vehicle_throttle_setpoint.timestamp = _timestamp;
|
||||
surface_vehicle_throttle_setpoint.throttle_body_x = SurfaceVehicleControl::speedControl(_adjusted_speed_setpoint,
|
||||
_pid_speed,
|
||||
speed_setpoint, _vehicle_speed, _param_sv_accel_limit.get(), _param_sv_decel_limit.get(),
|
||||
_param_sv_max_thr_speed.get(), dt);
|
||||
surface_vehicle_throttle_setpoint.throttle_body_y = NAN;
|
||||
_surface_vehicle_throttle_setpoint_pub.publish(surface_vehicle_throttle_setpoint);
|
||||
}
|
||||
|
||||
// Publish speed controller status (logging only)
|
||||
rover_speed_status_s rover_speed_status;
|
||||
rover_speed_status.timestamp = _timestamp;
|
||||
rover_speed_status.measured_speed_body_x = _vehicle_speed;
|
||||
rover_speed_status.adjusted_speed_body_x_setpoint = _adjusted_speed_setpoint.getState();
|
||||
rover_speed_status.pid_throttle_body_x_integral = _pid_speed.getIntegral();
|
||||
rover_speed_status.measured_speed_body_y = NAN;
|
||||
rover_speed_status.adjusted_speed_body_y_setpoint = NAN;
|
||||
rover_speed_status.pid_throttle_body_y_integral = NAN;
|
||||
_rover_speed_status_pub.publish(rover_speed_status);
|
||||
surface_vehicle_speed_status_s surface_vehicle_speed_status;
|
||||
surface_vehicle_speed_status.timestamp = _timestamp;
|
||||
surface_vehicle_speed_status.measured_speed_body_x = _vehicle_speed;
|
||||
surface_vehicle_speed_status.adjusted_speed_body_x_setpoint = _adjusted_speed_setpoint.getState();
|
||||
surface_vehicle_speed_status.pid_throttle_body_x_integral = _pid_speed.getIntegral();
|
||||
surface_vehicle_speed_status.measured_speed_body_y = NAN;
|
||||
surface_vehicle_speed_status.adjusted_speed_body_y_setpoint = NAN;
|
||||
surface_vehicle_speed_status.pid_throttle_body_y_integral = NAN;
|
||||
_surface_vehicle_speed_status_pub.publish(surface_vehicle_speed_status);
|
||||
}
|
||||
|
||||
void AckermannSpeedControl::updateSubscriptions()
|
||||
@@ -104,13 +105,13 @@ void AckermannSpeedControl::updateSubscriptions()
|
||||
Vector3f velocity_ned(vehicle_local_position.vx, vehicle_local_position.vy, vehicle_local_position.vz);
|
||||
Vector3f velocity_xyz = _vehicle_attitude_quaternion.rotateVectorInverse(velocity_ned);
|
||||
Vector2f velocity_2d = Vector2f(velocity_xyz(0), velocity_xyz(1));
|
||||
_vehicle_speed = velocity_2d.norm() > _param_ro_speed_th.get() ? sign(velocity_2d(0)) * velocity_2d.norm() : 0.f;
|
||||
_vehicle_speed = velocity_2d.norm() > _param_sv_speed_th.get() ? sign(velocity_2d(0)) * velocity_2d.norm() : 0.f;
|
||||
}
|
||||
|
||||
if (_rover_speed_setpoint_sub.updated()) {
|
||||
rover_speed_setpoint_s rover_speed_setpoint;
|
||||
_rover_speed_setpoint_sub.copy(&rover_speed_setpoint);
|
||||
_speed_setpoint = rover_speed_setpoint.speed_body_x;
|
||||
if (_surface_vehicle_speed_setpoint_sub.updated()) {
|
||||
surface_vehicle_speed_setpoint_s surface_vehicle_speed_setpoint;
|
||||
_surface_vehicle_speed_setpoint_sub.copy(&surface_vehicle_speed_setpoint);
|
||||
_speed_setpoint = surface_vehicle_speed_setpoint.speed_body_x;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,14 +119,14 @@ bool AckermannSpeedControl::runSanityChecks()
|
||||
{
|
||||
bool ret = true;
|
||||
|
||||
if (_param_ro_max_thr_speed.get() < FLT_EPSILON) {
|
||||
if (_param_sv_max_thr_speed.get() < FLT_EPSILON) {
|
||||
ret = false;
|
||||
}
|
||||
|
||||
if (_param_ro_speed_limit.get() < FLT_EPSILON) {
|
||||
if (_param_sv_speed_limit.get() < FLT_EPSILON) {
|
||||
ret = false;
|
||||
events::send<float>(events::ID("ackermann_speed_control_conf_invalid_speed_lim"), events::Log::Error,
|
||||
"Invalid configuration of necessary parameter RO_SPEED_LIM", _param_ro_speed_limit.get());
|
||||
"Invalid configuration of necessary parameter SV_SPEED_LIM", _param_sv_speed_limit.get());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
#include <px4_platform_common/events.h>
|
||||
|
||||
// Library includes
|
||||
#include <lib/rover_control/RoverControl.hpp>
|
||||
#include <lib/surface_vehicle_control/SurfaceVehicleControl.hpp>
|
||||
#include <lib/pid/PID.hpp>
|
||||
#include <matrix/matrix/math.hpp>
|
||||
#include <lib/slew_rate/SlewRate.hpp>
|
||||
@@ -47,9 +47,9 @@
|
||||
// uORB includes
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/topics/rover_throttle_setpoint.h>
|
||||
#include <uORB/topics/rover_speed_setpoint.h>
|
||||
#include <uORB/topics/rover_speed_status.h>
|
||||
#include <uORB/topics/surface_vehicle_throttle_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_speed_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_speed_status.h>
|
||||
#include <uORB/topics/vehicle_attitude.h>
|
||||
#include <uORB/topics/vehicle_local_position.h>
|
||||
|
||||
@@ -69,7 +69,7 @@ public:
|
||||
~AckermannSpeedControl() = default;
|
||||
|
||||
/**
|
||||
* @brief Generate and publish RoverThrottleSetpoint from roverSpeedSetpoint.
|
||||
* @brief Generate and publish SurfaceVehicleThrottleSetpoint from SurfaceVehicleSpeedSetpoint.
|
||||
*/
|
||||
void updateSpeedControl();
|
||||
|
||||
@@ -99,11 +99,11 @@ private:
|
||||
// uORB subscriptions
|
||||
uORB::Subscription _vehicle_attitude_sub{ORB_ID(vehicle_attitude)};
|
||||
uORB::Subscription _vehicle_local_position_sub{ORB_ID(vehicle_local_position)};
|
||||
uORB::Subscription _rover_speed_setpoint_sub{ORB_ID(rover_speed_setpoint)};
|
||||
uORB::Subscription _surface_vehicle_speed_setpoint_sub{ORB_ID(surface_vehicle_speed_setpoint)};
|
||||
|
||||
// uORB publications
|
||||
uORB::Publication<rover_throttle_setpoint_s> _rover_throttle_setpoint_pub{ORB_ID(rover_throttle_setpoint)};
|
||||
uORB::Publication<rover_speed_status_s> _rover_speed_status_pub{ORB_ID(rover_speed_status)};
|
||||
uORB::Publication<surface_vehicle_throttle_setpoint_s> _surface_vehicle_throttle_setpoint_pub{ORB_ID(surface_vehicle_throttle_setpoint)};
|
||||
uORB::Publication<surface_vehicle_speed_status_s> _surface_vehicle_speed_status_pub{ORB_ID(surface_vehicle_speed_status)};
|
||||
|
||||
// Variables
|
||||
hrt_abstime _timestamp{0};
|
||||
@@ -116,13 +116,13 @@ private:
|
||||
SlewRate<float> _adjusted_speed_setpoint{0.f};
|
||||
|
||||
DEFINE_PARAMETERS(
|
||||
(ParamFloat<px4::params::RO_MAX_THR_SPEED>) _param_ro_max_thr_speed,
|
||||
(ParamFloat<px4::params::RO_SPEED_P>) _param_ro_speed_p,
|
||||
(ParamFloat<px4::params::RO_SPEED_I>) _param_ro_speed_i,
|
||||
(ParamFloat<px4::params::RO_ACCEL_LIM>) _param_ro_accel_limit,
|
||||
(ParamFloat<px4::params::RO_DECEL_LIM>) _param_ro_decel_limit,
|
||||
(ParamFloat<px4::params::RO_JERK_LIM>) _param_ro_jerk_limit,
|
||||
(ParamFloat<px4::params::RO_SPEED_LIM>) _param_ro_speed_limit,
|
||||
(ParamFloat<px4::params::RO_SPEED_TH>) _param_ro_speed_th
|
||||
(ParamFloat<px4::params::SV_MAX_THR_SPEED>) _param_sv_max_thr_speed,
|
||||
(ParamFloat<px4::params::SV_SPEED_P>) _param_sv_speed_p,
|
||||
(ParamFloat<px4::params::SV_SPEED_I>) _param_sv_speed_i,
|
||||
(ParamFloat<px4::params::SV_ACCEL_LIM>) _param_sv_accel_limit,
|
||||
(ParamFloat<px4::params::SV_DECEL_LIM>) _param_sv_decel_limit,
|
||||
(ParamFloat<px4::params::SV_JERK_LIM>) _param_sv_jerk_limit,
|
||||
(ParamFloat<px4::params::SV_SPEED_LIM>) _param_sv_speed_limit,
|
||||
(ParamFloat<px4::params::SV_SPEED_TH>) _param_sv_speed_th
|
||||
)
|
||||
};
|
||||
|
||||
@@ -54,7 +54,7 @@ px4_add_module(
|
||||
AckermannManualMode
|
||||
AckermannOffboardMode
|
||||
px4_work_queue
|
||||
rover_control
|
||||
surface_vehicle_control
|
||||
pure_pursuit
|
||||
MODULE_CONFIG
|
||||
module.yaml
|
||||
|
||||
@@ -54,7 +54,7 @@ px4_add_module(
|
||||
DifferentialManualMode
|
||||
DifferentialOffboardMode
|
||||
px4_work_queue
|
||||
rover_control
|
||||
surface_vehicle_control
|
||||
pure_pursuit
|
||||
MODULE_CONFIG
|
||||
module.yaml
|
||||
|
||||
@@ -44,8 +44,8 @@ void DifferentialActControl::updateParams()
|
||||
{
|
||||
ModuleParams::updateParams();
|
||||
|
||||
if (_param_ro_accel_limit.get() > FLT_EPSILON && _param_ro_max_thr_speed.get() > FLT_EPSILON) {
|
||||
_adjusted_throttle_setpoint.setSlewRate(_param_ro_accel_limit.get() / _param_ro_max_thr_speed.get());
|
||||
if (_param_sv_accel_limit.get() > FLT_EPSILON && _param_sv_max_thr_speed.get() > FLT_EPSILON) {
|
||||
_adjusted_throttle_setpoint.setSlewRate(_param_sv_accel_limit.get() / _param_sv_max_thr_speed.get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,25 +56,25 @@ void DifferentialActControl::updateActControl()
|
||||
const float dt = math::constrain(_timestamp - timestamp_prev, 1_ms, 10_ms) * 1e-6f;
|
||||
|
||||
// Motor control
|
||||
if (_rover_throttle_setpoint_sub.updated()) {
|
||||
rover_throttle_setpoint_s rover_throttle_setpoint{};
|
||||
_rover_throttle_setpoint_sub.copy(&rover_throttle_setpoint);
|
||||
_throttle_setpoint = rover_throttle_setpoint.throttle_body_x;
|
||||
if (_surface_vehicle_throttle_setpoint_sub.updated()) {
|
||||
surface_vehicle_throttle_setpoint_s surface_vehicle_throttle_setpoint{};
|
||||
_surface_vehicle_throttle_setpoint_sub.copy(&surface_vehicle_throttle_setpoint);
|
||||
_throttle_setpoint = surface_vehicle_throttle_setpoint.throttle_body_x;
|
||||
}
|
||||
|
||||
if (_rover_steering_setpoint_sub.updated()) {
|
||||
rover_steering_setpoint_s rover_steering_setpoint{};
|
||||
_rover_steering_setpoint_sub.copy(&rover_steering_setpoint);
|
||||
_speed_diff_setpoint = rover_steering_setpoint.normalized_steering_setpoint;
|
||||
if (_surface_vehicle_steering_setpoint_sub.updated()) {
|
||||
surface_vehicle_steering_setpoint_s surface_vehicle_steering_setpoint{};
|
||||
_surface_vehicle_steering_setpoint_sub.copy(&surface_vehicle_steering_setpoint);
|
||||
_speed_diff_setpoint = surface_vehicle_steering_setpoint.normalized_steering_setpoint;
|
||||
}
|
||||
|
||||
if (PX4_ISFINITE(_throttle_setpoint) && PX4_ISFINITE(_speed_diff_setpoint)) {
|
||||
actuator_motors_s actuator_motors_sub{};
|
||||
_actuator_motors_sub.copy(&actuator_motors_sub);
|
||||
const float current_throttle = (actuator_motors_sub.control[0] + actuator_motors_sub.control[1]) / 2.f;
|
||||
const float adjusted_throttle_setpoint = RoverControl::throttleControl(_adjusted_throttle_setpoint,
|
||||
_throttle_setpoint, current_throttle, _param_ro_accel_limit.get(),
|
||||
_param_ro_decel_limit.get(), _param_ro_max_thr_speed.get(), dt);
|
||||
const float adjusted_throttle_setpoint = SurfaceVehicleControl::throttleControl(_adjusted_throttle_setpoint,
|
||||
_throttle_setpoint, current_throttle, _param_sv_accel_limit.get(),
|
||||
_param_sv_decel_limit.get(), _param_sv_max_thr_speed.get(), dt);
|
||||
actuator_motors_s actuator_motors{};
|
||||
actuator_motors.reversible_flags = _param_r_rev.get();
|
||||
computeInverseKinematics(adjusted_throttle_setpoint, _speed_diff_setpoint).copyTo(actuator_motors.control);
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
#include <px4_platform_common/module_params.h>
|
||||
|
||||
// Libraries
|
||||
#include <lib/rover_control/RoverControl.hpp>
|
||||
#include <lib/surface_vehicle_control/SurfaceVehicleControl.hpp>
|
||||
#include <lib/slew_rate/SlewRate.hpp>
|
||||
#include <math.h>
|
||||
|
||||
@@ -45,8 +45,8 @@
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/topics/actuator_motors.h>
|
||||
#include <uORB/topics/rover_steering_setpoint.h>
|
||||
#include <uORB/topics/rover_throttle_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_steering_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_throttle_setpoint.h>
|
||||
#include <uORB/topics/manual_control_setpoint.h>
|
||||
|
||||
/**
|
||||
@@ -63,7 +63,7 @@ public:
|
||||
~DifferentialActControl() = default;
|
||||
|
||||
/**
|
||||
* @brief Generate and publish actuatorMotors setpoints from roverThrottleSetpoint/roverSteeringSetpoint.
|
||||
* @brief Generate and publish actuatorMotors setpoints from SurfaceVehicleThrottleSetpoint/SurfaceVehicleSteeringSetpoint.
|
||||
*/
|
||||
void updateActControl();
|
||||
|
||||
@@ -89,8 +89,8 @@ private:
|
||||
|
||||
// uORB subscriptions
|
||||
uORB::Subscription _actuator_motors_sub{ORB_ID(actuator_motors)};
|
||||
uORB::Subscription _rover_steering_setpoint_sub{ORB_ID(rover_steering_setpoint)};
|
||||
uORB::Subscription _rover_throttle_setpoint_sub{ORB_ID(rover_throttle_setpoint)};
|
||||
uORB::Subscription _surface_vehicle_steering_setpoint_sub{ORB_ID(surface_vehicle_steering_setpoint)};
|
||||
uORB::Subscription _surface_vehicle_throttle_setpoint_sub{ORB_ID(surface_vehicle_throttle_setpoint)};
|
||||
|
||||
// uORB publications
|
||||
uORB::Publication<actuator_motors_s> _actuator_motors_pub{ORB_ID(actuator_motors)};
|
||||
@@ -106,8 +106,8 @@ private:
|
||||
// Parameters
|
||||
DEFINE_PARAMETERS(
|
||||
(ParamInt<px4::params::CA_R_REV>) _param_r_rev,
|
||||
(ParamFloat<px4::params::RO_ACCEL_LIM>) _param_ro_accel_limit,
|
||||
(ParamFloat<px4::params::RO_DECEL_LIM>) _param_ro_decel_limit,
|
||||
(ParamFloat<px4::params::RO_MAX_THR_SPEED>) _param_ro_max_thr_speed
|
||||
(ParamFloat<px4::params::SV_ACCEL_LIM>) _param_sv_accel_limit,
|
||||
(ParamFloat<px4::params::SV_DECEL_LIM>) _param_sv_decel_limit,
|
||||
(ParamFloat<px4::params::SV_MAX_THR_SPEED>) _param_sv_max_thr_speed
|
||||
)
|
||||
};
|
||||
|
||||
@@ -37,8 +37,8 @@ using namespace time_literals;
|
||||
|
||||
DifferentialAttControl::DifferentialAttControl(ModuleParams *parent) : ModuleParams(parent)
|
||||
{
|
||||
_rover_rate_setpoint_pub.advertise();
|
||||
_rover_attitude_status_pub.advertise();
|
||||
_surface_vehicle_rate_setpoint_pub.advertise();
|
||||
_surface_vehicle_attitude_status_pub.advertise();
|
||||
updateParams();
|
||||
}
|
||||
|
||||
@@ -46,12 +46,12 @@ void DifferentialAttControl::updateParams()
|
||||
{
|
||||
ModuleParams::updateParams();
|
||||
|
||||
if (_param_ro_yaw_rate_limit.get() > FLT_EPSILON) {
|
||||
_max_yaw_rate = _param_ro_yaw_rate_limit.get() * M_DEG_TO_RAD_F;
|
||||
if (_param_sv_yaw_rate_limit.get() > FLT_EPSILON) {
|
||||
_max_yaw_rate = _param_sv_yaw_rate_limit.get() * M_DEG_TO_RAD_F;
|
||||
}
|
||||
|
||||
// Set up PID controller
|
||||
_pid_yaw.setGains(_param_ro_yaw_p.get(), 0.f, 0.f);
|
||||
_pid_yaw.setGains(_param_sv_yaw_p.get(), 0.f, 0.f);
|
||||
_pid_yaw.setIntegralLimit(_max_yaw_rate);
|
||||
_pid_yaw.setOutputLimit(_max_yaw_rate);
|
||||
|
||||
@@ -72,28 +72,28 @@ void DifferentialAttControl::updateAttControl()
|
||||
_vehicle_yaw = matrix::Eulerf(vehicle_attitude_quaternion).psi();
|
||||
}
|
||||
|
||||
if (_rover_attitude_setpoint_sub.updated()) {
|
||||
rover_attitude_setpoint_s rover_attitude_setpoint{};
|
||||
_rover_attitude_setpoint_sub.copy(&rover_attitude_setpoint);
|
||||
_yaw_setpoint = rover_attitude_setpoint.yaw_setpoint;
|
||||
if (_surface_vehicle_attitude_setpoint_sub.updated()) {
|
||||
surface_vehicle_attitude_setpoint_s surface_vehicle_attitude_setpoint{};
|
||||
_surface_vehicle_attitude_setpoint_sub.copy(&surface_vehicle_attitude_setpoint);
|
||||
_yaw_setpoint = surface_vehicle_attitude_setpoint.yaw_setpoint;
|
||||
}
|
||||
|
||||
if (PX4_ISFINITE(_yaw_setpoint)) {
|
||||
const float yaw_rate_setpoint = RoverControl::attitudeControl(_adjusted_yaw_setpoint, _pid_yaw, _max_yaw_rate,
|
||||
const float yaw_rate_setpoint = SurfaceVehicleControl::attitudeControl(_adjusted_yaw_setpoint, _pid_yaw, _max_yaw_rate,
|
||||
_vehicle_yaw, _yaw_setpoint, dt);
|
||||
rover_rate_setpoint_s rover_rate_setpoint{};
|
||||
rover_rate_setpoint.timestamp = _timestamp;
|
||||
rover_rate_setpoint.yaw_rate_setpoint = math::constrain(yaw_rate_setpoint, -_max_yaw_rate, _max_yaw_rate);
|
||||
_rover_rate_setpoint_pub.publish(rover_rate_setpoint);
|
||||
surface_vehicle_rate_setpoint_s surface_vehicle_rate_setpoint{};
|
||||
surface_vehicle_rate_setpoint.timestamp = _timestamp;
|
||||
surface_vehicle_rate_setpoint.yaw_rate_setpoint = math::constrain(yaw_rate_setpoint, -_max_yaw_rate, _max_yaw_rate);
|
||||
_surface_vehicle_rate_setpoint_pub.publish(surface_vehicle_rate_setpoint);
|
||||
|
||||
}
|
||||
|
||||
// Publish attitude controller status (logging only)
|
||||
rover_attitude_status_s rover_attitude_status;
|
||||
rover_attitude_status.timestamp = _timestamp;
|
||||
rover_attitude_status.measured_yaw = _vehicle_yaw;
|
||||
rover_attitude_status.adjusted_yaw_setpoint = matrix::wrap_pi(_adjusted_yaw_setpoint.getState());
|
||||
_rover_attitude_status_pub.publish(rover_attitude_status);
|
||||
surface_vehicle_attitude_status_s surface_vehicle_attitude_status;
|
||||
surface_vehicle_attitude_status.timestamp = _timestamp;
|
||||
surface_vehicle_attitude_status.measured_yaw = _vehicle_yaw;
|
||||
surface_vehicle_attitude_status.adjusted_yaw_setpoint = matrix::wrap_pi(_adjusted_yaw_setpoint.getState());
|
||||
_surface_vehicle_attitude_status_pub.publish(surface_vehicle_attitude_status);
|
||||
|
||||
}
|
||||
|
||||
@@ -101,14 +101,14 @@ bool DifferentialAttControl::runSanityChecks()
|
||||
{
|
||||
bool ret = true;
|
||||
|
||||
if (_param_ro_yaw_rate_limit.get() < FLT_EPSILON) {
|
||||
if (_param_sv_yaw_rate_limit.get() < FLT_EPSILON) {
|
||||
ret = false;
|
||||
}
|
||||
|
||||
if (_param_ro_yaw_p.get() < FLT_EPSILON) {
|
||||
if (_param_sv_yaw_p.get() < FLT_EPSILON) {
|
||||
ret = false;
|
||||
events::send<float>(events::ID("differential_att_control_conf_invalid_yaw_p"), events::Log::Error,
|
||||
"Invalid configuration of necessary parameter RO_YAW_P", _param_ro_yaw_p.get());
|
||||
"Invalid configuration of necessary parameter SV_YAW_P", _param_sv_yaw_p.get());
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
#include <px4_platform_common/events.h>
|
||||
|
||||
// Libraries
|
||||
#include <lib/rover_control/RoverControl.hpp>
|
||||
#include <lib/surface_vehicle_control/SurfaceVehicleControl.hpp>
|
||||
#include <lib/pid/PID.hpp>
|
||||
#include <lib/slew_rate/SlewRateYaw.hpp>
|
||||
#include <math.h>
|
||||
@@ -47,10 +47,10 @@
|
||||
// uORB includes
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/topics/rover_rate_setpoint.h>
|
||||
#include <uORB/topics/rover_attitude_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_rate_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_attitude_setpoint.h>
|
||||
#include <uORB/topics/vehicle_attitude.h>
|
||||
#include <uORB/topics/rover_attitude_status.h>
|
||||
#include <uORB/topics/surface_vehicle_attitude_status.h>
|
||||
|
||||
/**
|
||||
* @brief Class for differential attitude control.
|
||||
@@ -66,7 +66,7 @@ public:
|
||||
~DifferentialAttControl() = default;
|
||||
|
||||
/**
|
||||
* @brief Generate and publish roverRateSetpoint from roverAttitudeSetpoint.
|
||||
* @brief Generate and publish SurfaceVehicleRateSetpoint from SurfaceVehicleAttitudeSetpoint.
|
||||
*/
|
||||
void updateAttControl();
|
||||
|
||||
@@ -90,11 +90,11 @@ protected:
|
||||
private:
|
||||
// uORB subscriptions
|
||||
uORB::Subscription _vehicle_attitude_sub{ORB_ID(vehicle_attitude)};
|
||||
uORB::Subscription _rover_attitude_setpoint_sub{ORB_ID(rover_attitude_setpoint)};
|
||||
uORB::Subscription _surface_vehicle_attitude_setpoint_sub{ORB_ID(surface_vehicle_attitude_setpoint)};
|
||||
|
||||
// uORB publications
|
||||
uORB::Publication<rover_rate_setpoint_s> _rover_rate_setpoint_pub{ORB_ID(rover_rate_setpoint)};
|
||||
uORB::Publication<rover_attitude_status_s> _rover_attitude_status_pub{ORB_ID(rover_attitude_status)};
|
||||
uORB::Publication<surface_vehicle_rate_setpoint_s> _surface_vehicle_rate_setpoint_pub{ORB_ID(surface_vehicle_rate_setpoint)};
|
||||
uORB::Publication<surface_vehicle_attitude_status_s> _surface_vehicle_attitude_status_pub{ORB_ID(surface_vehicle_attitude_status)};
|
||||
|
||||
// Variables
|
||||
float _vehicle_yaw{0.f};
|
||||
@@ -108,8 +108,8 @@ private:
|
||||
|
||||
// Parameters
|
||||
DEFINE_PARAMETERS(
|
||||
(ParamFloat<px4::params::RO_YAW_RATE_LIM>) _param_ro_yaw_rate_limit,
|
||||
(ParamFloat<px4::params::RO_YAW_P>) _param_ro_yaw_p,
|
||||
(ParamFloat<px4::params::RO_YAW_STICK_DZ>) _param_ro_yaw_stick_dz
|
||||
(ParamFloat<px4::params::SV_YAW_RATE_LIM>) _param_sv_yaw_rate_limit,
|
||||
(ParamFloat<px4::params::SV_YAW_P>) _param_sv_yaw_p,
|
||||
(ParamFloat<px4::params::SV_YAW_STICK_DZ>) _param_sv_yaw_stick_dz
|
||||
)
|
||||
};
|
||||
|
||||
+16
-15
@@ -38,7 +38,7 @@ using namespace time_literals;
|
||||
DifferentialAutoMode::DifferentialAutoMode(ModuleParams *parent) : ModuleParams(parent)
|
||||
{
|
||||
updateParams();
|
||||
_rover_position_setpoint_pub.advertise();
|
||||
_surface_vehicle_position_setpoint_pub.advertise();
|
||||
}
|
||||
|
||||
void DifferentialAutoMode::updateParams()
|
||||
@@ -69,26 +69,27 @@ void DifferentialAutoMode::autoControl()
|
||||
Vector2f prev_wp_ned{NAN, NAN};
|
||||
Vector2f next_wp_ned{NAN, NAN};
|
||||
|
||||
RoverControl::globalToLocalSetpointTriplet(curr_wp_ned, prev_wp_ned, next_wp_ned, position_setpoint_triplet,
|
||||
SurfaceVehicleControl::globalToLocalSetpointTriplet(curr_wp_ned, prev_wp_ned, next_wp_ned, position_setpoint_triplet,
|
||||
curr_pos_ned, global_ned_proj_ref);
|
||||
|
||||
float waypoint_transition_angle = RoverControl::calcWaypointTransitionAngle(prev_wp_ned, curr_wp_ned, next_wp_ned);
|
||||
float waypoint_transition_angle = SurfaceVehicleControl::calcWaypointTransitionAngle(prev_wp_ned, curr_wp_ned,
|
||||
next_wp_ned);
|
||||
|
||||
// Waypoint cruising speed
|
||||
float cruising_speed = position_setpoint_triplet.current.cruising_speed > 0.f ? math::constrain(
|
||||
position_setpoint_triplet.current.cruising_speed, 0.f, _param_ro_speed_limit.get()) : _param_ro_speed_limit.get();
|
||||
position_setpoint_triplet.current.cruising_speed, 0.f, _param_sv_speed_limit.get()) : _param_sv_speed_limit.get();
|
||||
|
||||
rover_position_setpoint_s rover_position_setpoint{};
|
||||
rover_position_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_position_setpoint.position_ned[0] = curr_wp_ned(0);
|
||||
rover_position_setpoint.position_ned[1] = curr_wp_ned(1);
|
||||
rover_position_setpoint.start_ned[0] = prev_wp_ned(0);
|
||||
rover_position_setpoint.start_ned[1] = prev_wp_ned(1);
|
||||
rover_position_setpoint.arrival_speed = arrivalSpeed(cruising_speed, waypoint_transition_angle,
|
||||
_param_ro_speed_limit.get(), _param_rd_trans_drv_trn.get(), _param_ro_speed_red.get(), curr_wp_type);
|
||||
rover_position_setpoint.cruising_speed = cruising_speed;
|
||||
rover_position_setpoint.yaw = NAN;
|
||||
_rover_position_setpoint_pub.publish(rover_position_setpoint);
|
||||
surface_vehicle_position_setpoint_s surface_vehicle_position_setpoint{};
|
||||
surface_vehicle_position_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_position_setpoint.position_ned[0] = curr_wp_ned(0);
|
||||
surface_vehicle_position_setpoint.position_ned[1] = curr_wp_ned(1);
|
||||
surface_vehicle_position_setpoint.start_ned[0] = prev_wp_ned(0);
|
||||
surface_vehicle_position_setpoint.start_ned[1] = prev_wp_ned(1);
|
||||
surface_vehicle_position_setpoint.arrival_speed = arrivalSpeed(cruising_speed, waypoint_transition_angle,
|
||||
_param_sv_speed_limit.get(), _param_rd_trans_drv_trn.get(), _param_sv_speed_red.get(), curr_wp_type);
|
||||
surface_vehicle_position_setpoint.cruising_speed = cruising_speed;
|
||||
surface_vehicle_position_setpoint.yaw = NAN;
|
||||
_surface_vehicle_position_setpoint_pub.publish(surface_vehicle_position_setpoint);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-6
@@ -37,7 +37,7 @@
|
||||
#include <px4_platform_common/module_params.h>
|
||||
|
||||
// Libraries
|
||||
#include <lib/rover_control/RoverControl.hpp>
|
||||
#include <lib/surface_vehicle_control/SurfaceVehicleControl.hpp>
|
||||
#include <math.h>
|
||||
|
||||
// uORB includes
|
||||
@@ -45,7 +45,7 @@
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/topics/vehicle_local_position.h>
|
||||
#include <uORB/topics/position_setpoint_triplet.h>
|
||||
#include <uORB/topics/rover_position_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_position_setpoint.h>
|
||||
|
||||
/**
|
||||
* @brief Class for differential auto mode.
|
||||
@@ -61,7 +61,7 @@ public:
|
||||
~DifferentialAutoMode() = default;
|
||||
|
||||
/**
|
||||
* @brief Generate and publish roverPositionSetpoint from positionSetpointTriplet.
|
||||
* @brief Generate and publish SurfaceVehiclePositionSetpoint from positionSetpointTriplet.
|
||||
*/
|
||||
void autoControl();
|
||||
|
||||
@@ -91,11 +91,11 @@ private:
|
||||
uORB::Subscription _position_setpoint_triplet_sub{ORB_ID(position_setpoint_triplet)};
|
||||
|
||||
// uORB publications
|
||||
uORB::Publication<rover_position_setpoint_s> _rover_position_setpoint_pub{ORB_ID(rover_position_setpoint)};
|
||||
uORB::Publication<surface_vehicle_position_setpoint_s> _surface_vehicle_position_setpoint_pub{ORB_ID(surface_vehicle_position_setpoint)};
|
||||
|
||||
DEFINE_PARAMETERS(
|
||||
(ParamFloat<px4::params::RO_SPEED_LIM>) _param_ro_speed_limit,
|
||||
(ParamFloat<px4::params::RO_SPEED_RED>) _param_ro_speed_red,
|
||||
(ParamFloat<px4::params::SV_SPEED_LIM>) _param_sv_speed_limit,
|
||||
(ParamFloat<px4::params::SV_SPEED_RED>) _param_sv_speed_red,
|
||||
(ParamFloat<px4::params::RD_TRANS_DRV_TRN>) _param_rd_trans_drv_trn
|
||||
)
|
||||
};
|
||||
|
||||
+80
-80
@@ -38,50 +38,50 @@ using namespace time_literals;
|
||||
DifferentialManualMode::DifferentialManualMode(ModuleParams *parent) : ModuleParams(parent)
|
||||
{
|
||||
updateParams();
|
||||
_rover_throttle_setpoint_pub.advertise();
|
||||
_rover_steering_setpoint_pub.advertise();
|
||||
_rover_rate_setpoint_pub.advertise();
|
||||
_rover_attitude_setpoint_pub.advertise();
|
||||
_rover_speed_setpoint_pub.advertise();
|
||||
_rover_position_setpoint_pub.advertise();
|
||||
_surface_vehicle_throttle_setpoint_pub.advertise();
|
||||
_surface_vehicle_steering_setpoint_pub.advertise();
|
||||
_surface_vehicle_rate_setpoint_pub.advertise();
|
||||
_surface_vehicle_attitude_setpoint_pub.advertise();
|
||||
_surface_vehicle_speed_setpoint_pub.advertise();
|
||||
_surface_vehicle_position_setpoint_pub.advertise();
|
||||
}
|
||||
|
||||
void DifferentialManualMode::updateParams()
|
||||
{
|
||||
ModuleParams::updateParams();
|
||||
_max_yaw_rate = _param_ro_yaw_rate_limit.get() * M_DEG_TO_RAD_F;
|
||||
_max_yaw_rate = _param_sv_yaw_rate_limit.get() * M_DEG_TO_RAD_F;
|
||||
}
|
||||
|
||||
void DifferentialManualMode::manual()
|
||||
{
|
||||
manual_control_setpoint_s manual_control_setpoint{};
|
||||
_manual_control_setpoint_sub.copy(&manual_control_setpoint);
|
||||
rover_steering_setpoint_s rover_steering_setpoint{};
|
||||
rover_steering_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_steering_setpoint.normalized_steering_setpoint = _param_rd_yaw_stk_gain.get() * math::superexpo<float>
|
||||
(manual_control_setpoint.roll, _param_ro_yaw_expo.get(), _param_ro_yaw_supexpo.get());
|
||||
_rover_steering_setpoint_pub.publish(rover_steering_setpoint);
|
||||
rover_throttle_setpoint_s rover_throttle_setpoint{};
|
||||
rover_throttle_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_throttle_setpoint.throttle_body_x = manual_control_setpoint.throttle;
|
||||
rover_throttle_setpoint.throttle_body_y = 0.f;
|
||||
_rover_throttle_setpoint_pub.publish(rover_throttle_setpoint);
|
||||
surface_vehicle_steering_setpoint_s surface_vehicle_steering_setpoint{};
|
||||
surface_vehicle_steering_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_steering_setpoint.normalized_steering_setpoint = _param_rd_yaw_stk_gain.get() * math::superexpo<float>
|
||||
(manual_control_setpoint.roll, _param_sv_yaw_expo.get(), _param_sv_yaw_supexpo.get());
|
||||
_surface_vehicle_steering_setpoint_pub.publish(surface_vehicle_steering_setpoint);
|
||||
surface_vehicle_throttle_setpoint_s surface_vehicle_throttle_setpoint{};
|
||||
surface_vehicle_throttle_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_throttle_setpoint.throttle_body_x = manual_control_setpoint.throttle;
|
||||
surface_vehicle_throttle_setpoint.throttle_body_y = 0.f;
|
||||
_surface_vehicle_throttle_setpoint_pub.publish(surface_vehicle_throttle_setpoint);
|
||||
}
|
||||
|
||||
void DifferentialManualMode::acro()
|
||||
{
|
||||
manual_control_setpoint_s manual_control_setpoint{};
|
||||
_manual_control_setpoint_sub.copy(&manual_control_setpoint);
|
||||
rover_throttle_setpoint_s rover_throttle_setpoint{};
|
||||
rover_throttle_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_throttle_setpoint.throttle_body_x = manual_control_setpoint.throttle;
|
||||
rover_throttle_setpoint.throttle_body_y = 0.f;
|
||||
_rover_throttle_setpoint_pub.publish(rover_throttle_setpoint);
|
||||
rover_rate_setpoint_s rover_rate_setpoint{};
|
||||
rover_rate_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_rate_setpoint.yaw_rate_setpoint = _max_yaw_rate * math::superexpo<float>(manual_control_setpoint.roll,
|
||||
_param_ro_yaw_expo.get(), _param_ro_yaw_supexpo.get());
|
||||
_rover_rate_setpoint_pub.publish(rover_rate_setpoint);
|
||||
surface_vehicle_throttle_setpoint_s surface_vehicle_throttle_setpoint{};
|
||||
surface_vehicle_throttle_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_throttle_setpoint.throttle_body_x = manual_control_setpoint.throttle;
|
||||
surface_vehicle_throttle_setpoint.throttle_body_y = 0.f;
|
||||
_surface_vehicle_throttle_setpoint_pub.publish(surface_vehicle_throttle_setpoint);
|
||||
surface_vehicle_rate_setpoint_s surface_vehicle_rate_setpoint{};
|
||||
surface_vehicle_rate_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_rate_setpoint.yaw_rate_setpoint = _max_yaw_rate * math::superexpo<float>(manual_control_setpoint.roll,
|
||||
_param_sv_yaw_expo.get(), _param_sv_yaw_supexpo.get());
|
||||
_surface_vehicle_rate_setpoint_pub.publish(surface_vehicle_rate_setpoint);
|
||||
}
|
||||
|
||||
void DifferentialManualMode::stab()
|
||||
@@ -95,38 +95,38 @@ void DifferentialManualMode::stab()
|
||||
|
||||
manual_control_setpoint_s manual_control_setpoint{};
|
||||
_manual_control_setpoint_sub.copy(&manual_control_setpoint);
|
||||
rover_throttle_setpoint_s rover_throttle_setpoint{};
|
||||
rover_throttle_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_throttle_setpoint.throttle_body_x = manual_control_setpoint.throttle;
|
||||
rover_throttle_setpoint.throttle_body_y = 0.f;
|
||||
_rover_throttle_setpoint_pub.publish(rover_throttle_setpoint);
|
||||
surface_vehicle_throttle_setpoint_s surface_vehicle_throttle_setpoint{};
|
||||
surface_vehicle_throttle_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_throttle_setpoint.throttle_body_x = manual_control_setpoint.throttle;
|
||||
surface_vehicle_throttle_setpoint.throttle_body_y = 0.f;
|
||||
_surface_vehicle_throttle_setpoint_pub.publish(surface_vehicle_throttle_setpoint);
|
||||
|
||||
if (fabsf(manual_control_setpoint.roll) > FLT_EPSILON
|
||||
|| fabsf(rover_throttle_setpoint.throttle_body_x) < FLT_EPSILON) {
|
||||
|| fabsf(surface_vehicle_throttle_setpoint.throttle_body_x) < FLT_EPSILON) {
|
||||
_stab_yaw_setpoint = NAN;
|
||||
|
||||
// Rate control
|
||||
rover_rate_setpoint_s rover_rate_setpoint{};
|
||||
rover_rate_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_rate_setpoint.yaw_rate_setpoint = _max_yaw_rate * math::superexpo<float>(math::deadzone(
|
||||
manual_control_setpoint.roll, _param_ro_yaw_stick_dz.get()), _param_ro_yaw_expo.get(), _param_ro_yaw_supexpo.get());
|
||||
_rover_rate_setpoint_pub.publish(rover_rate_setpoint);
|
||||
surface_vehicle_rate_setpoint_s surface_vehicle_rate_setpoint{};
|
||||
surface_vehicle_rate_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_rate_setpoint.yaw_rate_setpoint = _max_yaw_rate * math::superexpo<float>(math::deadzone(
|
||||
manual_control_setpoint.roll, _param_sv_yaw_stick_dz.get()), _param_sv_yaw_expo.get(), _param_sv_yaw_supexpo.get());
|
||||
_surface_vehicle_rate_setpoint_pub.publish(surface_vehicle_rate_setpoint);
|
||||
|
||||
// Set uncontrolled setpoint invalid
|
||||
rover_attitude_setpoint_s rover_attitude_setpoint{};
|
||||
rover_attitude_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_attitude_setpoint.yaw_setpoint = NAN;
|
||||
_rover_attitude_setpoint_pub.publish(rover_attitude_setpoint);
|
||||
surface_vehicle_attitude_setpoint_s surface_vehicle_attitude_setpoint{};
|
||||
surface_vehicle_attitude_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_attitude_setpoint.yaw_setpoint = NAN;
|
||||
_surface_vehicle_attitude_setpoint_pub.publish(surface_vehicle_attitude_setpoint);
|
||||
|
||||
} else { // Heading control
|
||||
if (!PX4_ISFINITE(_stab_yaw_setpoint)) {
|
||||
_stab_yaw_setpoint = _vehicle_yaw;
|
||||
}
|
||||
|
||||
rover_attitude_setpoint_s rover_attitude_setpoint{};
|
||||
rover_attitude_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_attitude_setpoint.yaw_setpoint = _stab_yaw_setpoint;
|
||||
_rover_attitude_setpoint_pub.publish(rover_attitude_setpoint);
|
||||
surface_vehicle_attitude_setpoint_s surface_vehicle_attitude_setpoint{};
|
||||
surface_vehicle_attitude_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_attitude_setpoint.yaw_setpoint = _stab_yaw_setpoint;
|
||||
_surface_vehicle_attitude_setpoint_pub.publish(surface_vehicle_attitude_setpoint);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,41 +149,41 @@ void DifferentialManualMode::position()
|
||||
_manual_control_setpoint_sub.copy(&manual_control_setpoint);
|
||||
|
||||
const float speed_setpoint = math::interpolate<float>(manual_control_setpoint.throttle,
|
||||
-1.f, 1.f, -_param_ro_speed_limit.get(), _param_ro_speed_limit.get());
|
||||
-1.f, 1.f, -_param_sv_speed_limit.get(), _param_sv_speed_limit.get());
|
||||
|
||||
if (fabsf(manual_control_setpoint.roll) > FLT_EPSILON
|
||||
|| fabsf(speed_setpoint) < FLT_EPSILON) {
|
||||
_pos_ctl_course_direction = Vector2f(NAN, NAN);
|
||||
|
||||
// Speed control
|
||||
rover_speed_setpoint_s rover_speed_setpoint{};
|
||||
rover_speed_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_speed_setpoint.speed_body_x = speed_setpoint;
|
||||
_rover_speed_setpoint_pub.publish(rover_speed_setpoint);
|
||||
surface_vehicle_speed_setpoint_s surface_vehicle_speed_setpoint{};
|
||||
surface_vehicle_speed_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_speed_setpoint.speed_body_x = speed_setpoint;
|
||||
_surface_vehicle_speed_setpoint_pub.publish(surface_vehicle_speed_setpoint);
|
||||
|
||||
// Rate control
|
||||
rover_rate_setpoint_s rover_rate_setpoint{};
|
||||
rover_rate_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_rate_setpoint.yaw_rate_setpoint = _max_yaw_rate * math::superexpo<float>(math::deadzone(
|
||||
manual_control_setpoint.roll, _param_ro_yaw_stick_dz.get()), _param_ro_yaw_expo.get(), _param_ro_yaw_supexpo.get());
|
||||
_rover_rate_setpoint_pub.publish(rover_rate_setpoint);
|
||||
surface_vehicle_rate_setpoint_s surface_vehicle_rate_setpoint{};
|
||||
surface_vehicle_rate_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_rate_setpoint.yaw_rate_setpoint = _max_yaw_rate * math::superexpo<float>(math::deadzone(
|
||||
manual_control_setpoint.roll, _param_sv_yaw_stick_dz.get()), _param_sv_yaw_expo.get(), _param_sv_yaw_supexpo.get());
|
||||
_surface_vehicle_rate_setpoint_pub.publish(surface_vehicle_rate_setpoint);
|
||||
|
||||
// Set uncontrolled setpoints invalid
|
||||
rover_attitude_setpoint_s rover_attitude_setpoint{};
|
||||
rover_attitude_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_attitude_setpoint.yaw_setpoint = NAN;
|
||||
_rover_attitude_setpoint_pub.publish(rover_attitude_setpoint);
|
||||
surface_vehicle_attitude_setpoint_s surface_vehicle_attitude_setpoint{};
|
||||
surface_vehicle_attitude_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_attitude_setpoint.yaw_setpoint = NAN;
|
||||
_surface_vehicle_attitude_setpoint_pub.publish(surface_vehicle_attitude_setpoint);
|
||||
|
||||
rover_position_setpoint_s rover_position_setpoint{};
|
||||
rover_position_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_position_setpoint.position_ned[0] = NAN;
|
||||
rover_position_setpoint.position_ned[1] = NAN;
|
||||
rover_position_setpoint.start_ned[0] = NAN;
|
||||
rover_position_setpoint.start_ned[1] = NAN;
|
||||
rover_position_setpoint.arrival_speed = NAN;
|
||||
rover_position_setpoint.cruising_speed = NAN;
|
||||
rover_position_setpoint.yaw = NAN;
|
||||
_rover_position_setpoint_pub.publish(rover_position_setpoint);
|
||||
surface_vehicle_position_setpoint_s surface_vehicle_position_setpoint{};
|
||||
surface_vehicle_position_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_position_setpoint.position_ned[0] = NAN;
|
||||
surface_vehicle_position_setpoint.position_ned[1] = NAN;
|
||||
surface_vehicle_position_setpoint.start_ned[0] = NAN;
|
||||
surface_vehicle_position_setpoint.start_ned[1] = NAN;
|
||||
surface_vehicle_position_setpoint.arrival_speed = NAN;
|
||||
surface_vehicle_position_setpoint.cruising_speed = NAN;
|
||||
surface_vehicle_position_setpoint.yaw = NAN;
|
||||
_surface_vehicle_position_setpoint_pub.publish(surface_vehicle_position_setpoint);
|
||||
|
||||
} else { // Course control
|
||||
if (!_pos_ctl_course_direction.isAllFinite()) {
|
||||
@@ -196,16 +196,16 @@ void DifferentialManualMode::position()
|
||||
const float vector_scaling = fabsf(start_to_curr_pos * _pos_ctl_course_direction) + _param_pp_lookahd_max.get();
|
||||
const Vector2f target_waypoint_ned = _pos_ctl_start_position_ned + sign(speed_setpoint) *
|
||||
vector_scaling * _pos_ctl_course_direction;
|
||||
rover_position_setpoint_s rover_position_setpoint{};
|
||||
rover_position_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_position_setpoint.position_ned[0] = target_waypoint_ned(0);
|
||||
rover_position_setpoint.position_ned[1] = target_waypoint_ned(1);
|
||||
rover_position_setpoint.start_ned[0] = _pos_ctl_start_position_ned(0);
|
||||
rover_position_setpoint.start_ned[1] = _pos_ctl_start_position_ned(1);
|
||||
rover_position_setpoint.arrival_speed = NAN;
|
||||
rover_position_setpoint.cruising_speed = speed_setpoint;
|
||||
rover_position_setpoint.yaw = NAN;
|
||||
_rover_position_setpoint_pub.publish(rover_position_setpoint);
|
||||
surface_vehicle_position_setpoint_s surface_vehicle_position_setpoint{};
|
||||
surface_vehicle_position_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_position_setpoint.position_ned[0] = target_waypoint_ned(0);
|
||||
surface_vehicle_position_setpoint.position_ned[1] = target_waypoint_ned(1);
|
||||
surface_vehicle_position_setpoint.start_ned[0] = _pos_ctl_start_position_ned(0);
|
||||
surface_vehicle_position_setpoint.start_ned[1] = _pos_ctl_start_position_ned(1);
|
||||
surface_vehicle_position_setpoint.arrival_speed = NAN;
|
||||
surface_vehicle_position_setpoint.cruising_speed = speed_setpoint;
|
||||
surface_vehicle_position_setpoint.yaw = NAN;
|
||||
_surface_vehicle_position_setpoint_pub.publish(surface_vehicle_position_setpoint);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+19
-19
@@ -46,12 +46,12 @@
|
||||
#include <uORB/topics/manual_control_setpoint.h>
|
||||
#include <uORB/topics/vehicle_attitude.h>
|
||||
#include <uORB/topics/vehicle_local_position.h>
|
||||
#include <uORB/topics/rover_throttle_setpoint.h>
|
||||
#include <uORB/topics/rover_steering_setpoint.h>
|
||||
#include <uORB/topics/rover_rate_setpoint.h>
|
||||
#include <uORB/topics/rover_attitude_setpoint.h>
|
||||
#include <uORB/topics/rover_speed_setpoint.h>
|
||||
#include <uORB/topics/rover_position_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_throttle_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_steering_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_rate_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_attitude_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_speed_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_position_setpoint.h>
|
||||
|
||||
using namespace matrix;
|
||||
|
||||
@@ -69,12 +69,12 @@ public:
|
||||
~DifferentialManualMode() = default;
|
||||
|
||||
/**
|
||||
* @brief Publish roverThrottleSetpoint and roverSteeringSetpoint from manualControlSetpoint.
|
||||
* @brief Publish SurfaceVehicleThrottleSetpoint and SurfaceVehicleSteeringSetpoint from manualControlSetpoint.
|
||||
*/
|
||||
void manual();
|
||||
|
||||
/**
|
||||
* @brief Generate and publish roverThrottleSetpoint/RoverRateSetpoint from manualControlSetpoint.
|
||||
* @brief Generate and publish SurfaceVehicleThrottleSetpoint/SurfaceVehicleRateSetpoint from manualControlSetpoint.
|
||||
*/
|
||||
void acro();
|
||||
|
||||
@@ -106,12 +106,12 @@ private:
|
||||
uORB::Subscription _vehicle_local_position_sub{ORB_ID(vehicle_local_position)};
|
||||
|
||||
// uORB publications
|
||||
uORB::Publication<rover_throttle_setpoint_s> _rover_throttle_setpoint_pub{ORB_ID(rover_throttle_setpoint)};
|
||||
uORB::Publication<rover_steering_setpoint_s> _rover_steering_setpoint_pub{ORB_ID(rover_steering_setpoint)};
|
||||
uORB::Publication<rover_rate_setpoint_s> _rover_rate_setpoint_pub{ORB_ID(rover_rate_setpoint)};
|
||||
uORB::Publication<rover_attitude_setpoint_s> _rover_attitude_setpoint_pub{ORB_ID(rover_attitude_setpoint)};
|
||||
uORB::Publication<rover_speed_setpoint_s> _rover_speed_setpoint_pub{ORB_ID(rover_speed_setpoint)};
|
||||
uORB::Publication<rover_position_setpoint_s> _rover_position_setpoint_pub{ORB_ID(rover_position_setpoint)};
|
||||
uORB::Publication<surface_vehicle_throttle_setpoint_s> _surface_vehicle_throttle_setpoint_pub{ORB_ID(surface_vehicle_throttle_setpoint)};
|
||||
uORB::Publication<surface_vehicle_steering_setpoint_s> _surface_vehicle_steering_setpoint_pub{ORB_ID(surface_vehicle_steering_setpoint)};
|
||||
uORB::Publication<surface_vehicle_rate_setpoint_s> _surface_vehicle_rate_setpoint_pub{ORB_ID(surface_vehicle_rate_setpoint)};
|
||||
uORB::Publication<surface_vehicle_attitude_setpoint_s> _surface_vehicle_attitude_setpoint_pub{ORB_ID(surface_vehicle_attitude_setpoint)};
|
||||
uORB::Publication<surface_vehicle_speed_setpoint_s> _surface_vehicle_speed_setpoint_pub{ORB_ID(surface_vehicle_speed_setpoint)};
|
||||
uORB::Publication<surface_vehicle_position_setpoint_s> _surface_vehicle_position_setpoint_pub{ORB_ID(surface_vehicle_position_setpoint)};
|
||||
|
||||
// Variables
|
||||
Vector2f _pos_ctl_course_direction{NAN, NAN};
|
||||
@@ -122,12 +122,12 @@ private:
|
||||
float _max_yaw_rate{NAN};
|
||||
|
||||
DEFINE_PARAMETERS(
|
||||
(ParamFloat<px4::params::RO_YAW_RATE_LIM>) _param_ro_yaw_rate_limit,
|
||||
(ParamFloat<px4::params::RO_YAW_STICK_DZ>) _param_ro_yaw_stick_dz,
|
||||
(ParamFloat<px4::params::RO_YAW_EXPO>) _param_ro_yaw_expo,
|
||||
(ParamFloat<px4::params::RO_YAW_SUPEXPO>) _param_ro_yaw_supexpo,
|
||||
(ParamFloat<px4::params::SV_YAW_RATE_LIM>) _param_sv_yaw_rate_limit,
|
||||
(ParamFloat<px4::params::SV_YAW_STICK_DZ>) _param_sv_yaw_stick_dz,
|
||||
(ParamFloat<px4::params::SV_YAW_EXPO>) _param_sv_yaw_expo,
|
||||
(ParamFloat<px4::params::SV_YAW_SUPEXPO>) _param_sv_yaw_supexpo,
|
||||
(ParamFloat<px4::params::RD_YAW_STK_GAIN>) _param_rd_yaw_stk_gain,
|
||||
(ParamFloat<px4::params::PP_LOOKAHD_MAX>) _param_pp_lookahd_max,
|
||||
(ParamFloat<px4::params::RO_SPEED_LIM>) _param_ro_speed_limit
|
||||
(ParamFloat<px4::params::SV_SPEED_LIM>) _param_sv_speed_limit
|
||||
)
|
||||
};
|
||||
|
||||
+30
-30
@@ -38,10 +38,10 @@ using namespace time_literals;
|
||||
DifferentialOffboardMode::DifferentialOffboardMode(ModuleParams *parent) : ModuleParams(parent)
|
||||
{
|
||||
updateParams();
|
||||
_rover_rate_setpoint_pub.advertise();
|
||||
_rover_attitude_setpoint_pub.advertise();
|
||||
_rover_speed_setpoint_pub.advertise();
|
||||
_rover_position_setpoint_pub.advertise();
|
||||
_surface_vehicle_rate_setpoint_pub.advertise();
|
||||
_surface_vehicle_attitude_setpoint_pub.advertise();
|
||||
_surface_vehicle_speed_setpoint_pub.advertise();
|
||||
_surface_vehicle_position_setpoint_pub.advertise();
|
||||
}
|
||||
|
||||
void DifferentialOffboardMode::updateParams()
|
||||
@@ -58,38 +58,38 @@ void DifferentialOffboardMode::offboardControl()
|
||||
_trajectory_setpoint_sub.copy(&trajectory_setpoint);
|
||||
|
||||
if (offboard_control_mode.position) {
|
||||
rover_position_setpoint_s rover_position_setpoint{};
|
||||
rover_position_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_position_setpoint.position_ned[0] = trajectory_setpoint.position[0];
|
||||
rover_position_setpoint.position_ned[1] = trajectory_setpoint.position[1];
|
||||
rover_position_setpoint.start_ned[0] = NAN;
|
||||
rover_position_setpoint.start_ned[1] = NAN;
|
||||
rover_position_setpoint.cruising_speed = NAN;
|
||||
rover_position_setpoint.arrival_speed = NAN;
|
||||
rover_position_setpoint.yaw = NAN;
|
||||
_rover_position_setpoint_pub.publish(rover_position_setpoint);
|
||||
surface_vehicle_position_setpoint_s surface_vehicle_position_setpoint{};
|
||||
surface_vehicle_position_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_position_setpoint.position_ned[0] = trajectory_setpoint.position[0];
|
||||
surface_vehicle_position_setpoint.position_ned[1] = trajectory_setpoint.position[1];
|
||||
surface_vehicle_position_setpoint.start_ned[0] = NAN;
|
||||
surface_vehicle_position_setpoint.start_ned[1] = NAN;
|
||||
surface_vehicle_position_setpoint.cruising_speed = NAN;
|
||||
surface_vehicle_position_setpoint.arrival_speed = NAN;
|
||||
surface_vehicle_position_setpoint.yaw = NAN;
|
||||
_surface_vehicle_position_setpoint_pub.publish(surface_vehicle_position_setpoint);
|
||||
|
||||
} else if (offboard_control_mode.velocity) {
|
||||
const Vector2f velocity_ned(trajectory_setpoint.velocity[0], trajectory_setpoint.velocity[1]);
|
||||
rover_speed_setpoint_s rover_speed_setpoint{};
|
||||
rover_speed_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_speed_setpoint.speed_body_x = velocity_ned.norm();
|
||||
_rover_speed_setpoint_pub.publish(rover_speed_setpoint);
|
||||
rover_attitude_setpoint_s rover_attitude_setpoint{};
|
||||
rover_attitude_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_attitude_setpoint.yaw_setpoint = atan2f(velocity_ned(1), velocity_ned(0));
|
||||
_rover_attitude_setpoint_pub.publish(rover_attitude_setpoint);
|
||||
surface_vehicle_speed_setpoint_s surface_vehicle_speed_setpoint{};
|
||||
surface_vehicle_speed_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_speed_setpoint.speed_body_x = velocity_ned.norm();
|
||||
_surface_vehicle_speed_setpoint_pub.publish(surface_vehicle_speed_setpoint);
|
||||
surface_vehicle_attitude_setpoint_s surface_vehicle_attitude_setpoint{};
|
||||
surface_vehicle_attitude_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_attitude_setpoint.yaw_setpoint = atan2f(velocity_ned(1), velocity_ned(0));
|
||||
_surface_vehicle_attitude_setpoint_pub.publish(surface_vehicle_attitude_setpoint);
|
||||
|
||||
} else if (offboard_control_mode.attitude) {
|
||||
rover_attitude_setpoint_s rover_attitude_setpoint{};
|
||||
rover_attitude_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_attitude_setpoint.yaw_setpoint = trajectory_setpoint.yaw;
|
||||
_rover_attitude_setpoint_pub.publish(rover_attitude_setpoint);
|
||||
surface_vehicle_attitude_setpoint_s surface_vehicle_attitude_setpoint{};
|
||||
surface_vehicle_attitude_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_attitude_setpoint.yaw_setpoint = trajectory_setpoint.yaw;
|
||||
_surface_vehicle_attitude_setpoint_pub.publish(surface_vehicle_attitude_setpoint);
|
||||
|
||||
} else if (offboard_control_mode.body_rate) {
|
||||
rover_rate_setpoint_s rover_rate_setpoint{};
|
||||
rover_rate_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_rate_setpoint.yaw_rate_setpoint = trajectory_setpoint.yawspeed;
|
||||
_rover_rate_setpoint_pub.publish(rover_rate_setpoint);
|
||||
surface_vehicle_rate_setpoint_s surface_vehicle_rate_setpoint{};
|
||||
surface_vehicle_rate_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_rate_setpoint.yaw_rate_setpoint = trajectory_setpoint.yawspeed;
|
||||
_surface_vehicle_rate_setpoint_pub.publish(surface_vehicle_rate_setpoint);
|
||||
}
|
||||
}
|
||||
|
||||
+8
-8
@@ -43,10 +43,10 @@
|
||||
// uORB includes
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/topics/rover_rate_setpoint.h>
|
||||
#include <uORB/topics/rover_attitude_setpoint.h>
|
||||
#include <uORB/topics/rover_speed_setpoint.h>
|
||||
#include <uORB/topics/rover_position_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_rate_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_attitude_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_speed_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_position_setpoint.h>
|
||||
#include <uORB/topics/offboard_control_mode.h>
|
||||
#include <uORB/topics/trajectory_setpoint.h>
|
||||
|
||||
@@ -82,8 +82,8 @@ private:
|
||||
uORB::Subscription _offboard_control_mode_sub{ORB_ID(offboard_control_mode)};
|
||||
|
||||
// uORB publications
|
||||
uORB::Publication<rover_rate_setpoint_s> _rover_rate_setpoint_pub{ORB_ID(rover_rate_setpoint)};
|
||||
uORB::Publication<rover_attitude_setpoint_s> _rover_attitude_setpoint_pub{ORB_ID(rover_attitude_setpoint)};
|
||||
uORB::Publication<rover_speed_setpoint_s> _rover_speed_setpoint_pub{ORB_ID(rover_speed_setpoint)};
|
||||
uORB::Publication<rover_position_setpoint_s> _rover_position_setpoint_pub{ORB_ID(rover_position_setpoint)};
|
||||
uORB::Publication<surface_vehicle_rate_setpoint_s> _surface_vehicle_rate_setpoint_pub{ORB_ID(surface_vehicle_rate_setpoint)};
|
||||
uORB::Publication<surface_vehicle_attitude_setpoint_s> _surface_vehicle_attitude_setpoint_pub{ORB_ID(surface_vehicle_attitude_setpoint)};
|
||||
uORB::Publication<surface_vehicle_speed_setpoint_s> _surface_vehicle_speed_setpoint_pub{ORB_ID(surface_vehicle_speed_setpoint)};
|
||||
uORB::Publication<surface_vehicle_position_setpoint_s> _surface_vehicle_position_setpoint_pub{ORB_ID(surface_vehicle_position_setpoint)};
|
||||
};
|
||||
|
||||
@@ -38,8 +38,8 @@ using namespace time_literals;
|
||||
DifferentialPosControl::DifferentialPosControl(ModuleParams *parent) : ModuleParams(parent)
|
||||
{
|
||||
_pure_pursuit_status_pub.advertise();
|
||||
_rover_speed_setpoint_pub.advertise();
|
||||
_rover_attitude_setpoint_pub.advertise();
|
||||
_surface_vehicle_speed_setpoint_pub.advertise();
|
||||
_surface_vehicle_attitude_setpoint_pub.advertise();
|
||||
|
||||
updateParams();
|
||||
}
|
||||
@@ -65,8 +65,8 @@ void DifferentialPosControl::updatePosControl()
|
||||
}
|
||||
|
||||
if (distance_to_target > _param_nav_acc_rad.get() || _arrival_speed > FLT_EPSILON) {
|
||||
float speed_setpoint = math::trajectory::computeMaxSpeedFromDistance(_param_ro_jerk_limit.get(),
|
||||
_param_ro_decel_limit.get(), distance_to_target, fabsf(_arrival_speed));
|
||||
float speed_setpoint = math::trajectory::computeMaxSpeedFromDistance(_param_sv_jerk_limit.get(),
|
||||
_param_sv_decel_limit.get(), distance_to_target, fabsf(_arrival_speed));
|
||||
speed_setpoint = math::min(speed_setpoint, _cruising_speed);
|
||||
|
||||
pure_pursuit_status_s pure_pursuit_status{};
|
||||
@@ -89,33 +89,33 @@ void DifferentialPosControl::updatePosControl()
|
||||
if (_current_state == DrivingState::SPOT_TURNING) {
|
||||
speed_setpoint = 0.f; // stop during spot turning
|
||||
|
||||
} else if (_param_ro_speed_red.get() > FLT_EPSILON) {
|
||||
const float speed_reduction = math::constrain(_param_ro_speed_red.get() * math::interpolate(fabsf(heading_error),
|
||||
} else if (_param_sv_speed_red.get() > FLT_EPSILON) {
|
||||
const float speed_reduction = math::constrain(_param_sv_speed_red.get() * math::interpolate(fabsf(heading_error),
|
||||
0.f, M_PI_F, 0.f, 1.f), 0.f, 1.f);
|
||||
const float max_speed = math::constrain(_param_ro_max_thr_speed.get() * (1.f - speed_reduction), 0.f,
|
||||
_param_ro_max_thr_speed.get());
|
||||
const float max_speed = math::constrain(_param_sv_max_thr_speed.get() * (1.f - speed_reduction), 0.f,
|
||||
_param_sv_max_thr_speed.get());
|
||||
speed_setpoint = math::constrain(speed_setpoint, -max_speed, max_speed);
|
||||
}
|
||||
|
||||
rover_speed_setpoint_s rover_speed_setpoint{};
|
||||
rover_speed_setpoint.timestamp = timestamp;
|
||||
rover_speed_setpoint.speed_body_x = speed_setpoint;
|
||||
_rover_speed_setpoint_pub.publish(rover_speed_setpoint);
|
||||
rover_attitude_setpoint_s rover_attitude_setpoint{};
|
||||
rover_attitude_setpoint.timestamp = timestamp;
|
||||
rover_attitude_setpoint.yaw_setpoint = speed_setpoint > -FLT_EPSILON ? yaw_setpoint : matrix::wrap_pi(
|
||||
yaw_setpoint + M_PI_F);
|
||||
_rover_attitude_setpoint_pub.publish(rover_attitude_setpoint);
|
||||
surface_vehicle_speed_setpoint_s surface_vehicle_speed_setpoint{};
|
||||
surface_vehicle_speed_setpoint.timestamp = timestamp;
|
||||
surface_vehicle_speed_setpoint.speed_body_x = speed_setpoint;
|
||||
_surface_vehicle_speed_setpoint_pub.publish(surface_vehicle_speed_setpoint);
|
||||
surface_vehicle_attitude_setpoint_s surface_vehicle_attitude_setpoint{};
|
||||
surface_vehicle_attitude_setpoint.timestamp = timestamp;
|
||||
surface_vehicle_attitude_setpoint.yaw_setpoint = speed_setpoint > -FLT_EPSILON ? yaw_setpoint : matrix::wrap_pi(
|
||||
yaw_setpoint + M_PI_F);
|
||||
_surface_vehicle_attitude_setpoint_pub.publish(surface_vehicle_attitude_setpoint);
|
||||
|
||||
} else {
|
||||
rover_speed_setpoint_s rover_speed_setpoint{};
|
||||
rover_speed_setpoint.timestamp = timestamp;
|
||||
rover_speed_setpoint.speed_body_x = 0.f;
|
||||
_rover_speed_setpoint_pub.publish(rover_speed_setpoint);
|
||||
rover_attitude_setpoint_s rover_attitude_setpoint{};
|
||||
rover_attitude_setpoint.timestamp = timestamp;
|
||||
rover_attitude_setpoint.yaw_setpoint = _vehicle_yaw;
|
||||
_rover_attitude_setpoint_pub.publish(rover_attitude_setpoint);
|
||||
surface_vehicle_speed_setpoint_s surface_vehicle_speed_setpoint{};
|
||||
surface_vehicle_speed_setpoint.timestamp = timestamp;
|
||||
surface_vehicle_speed_setpoint.speed_body_x = 0.f;
|
||||
_surface_vehicle_speed_setpoint_pub.publish(surface_vehicle_speed_setpoint);
|
||||
surface_vehicle_attitude_setpoint_s surface_vehicle_attitude_setpoint{};
|
||||
surface_vehicle_attitude_setpoint.timestamp = timestamp;
|
||||
surface_vehicle_attitude_setpoint.yaw_setpoint = _vehicle_yaw;
|
||||
_surface_vehicle_attitude_setpoint_pub.publish(surface_vehicle_attitude_setpoint);
|
||||
|
||||
if (!_stopped && fabsf(_vehicle_speed) < FLT_EPSILON) {
|
||||
_stopped = true;
|
||||
@@ -150,18 +150,21 @@ void DifferentialPosControl::updateSubscriptions()
|
||||
Vector3f velocity_ned(vehicle_local_position.vx, vehicle_local_position.vy, vehicle_local_position.vz);
|
||||
Vector3f velocity_xyz = _vehicle_attitude_quaternion.rotateVectorInverse(velocity_ned);
|
||||
Vector2f velocity_2d = Vector2f(velocity_xyz(0), velocity_xyz(1));
|
||||
_vehicle_speed = velocity_2d.norm() > _param_ro_speed_th.get() ? sign(velocity_2d(0)) * velocity_2d.norm() : 0.f;
|
||||
_vehicle_speed = velocity_2d.norm() > _param_sv_speed_th.get() ? sign(velocity_2d(0)) * velocity_2d.norm() : 0.f;
|
||||
}
|
||||
|
||||
if (_rover_position_setpoint_sub.updated()) {
|
||||
rover_position_setpoint_s rover_position_setpoint;
|
||||
_rover_position_setpoint_sub.copy(&rover_position_setpoint);
|
||||
_start_ned = Vector2f(rover_position_setpoint.start_ned[0], rover_position_setpoint.start_ned[1]);
|
||||
if (_surface_vehicle_position_setpoint_sub.updated()) {
|
||||
surface_vehicle_position_setpoint_s surface_vehicle_position_setpoint;
|
||||
_surface_vehicle_position_setpoint_sub.copy(&surface_vehicle_position_setpoint);
|
||||
_start_ned = Vector2f(surface_vehicle_position_setpoint.start_ned[0], surface_vehicle_position_setpoint.start_ned[1]);
|
||||
_start_ned = _start_ned.isAllFinite() ? _start_ned : _curr_pos_ned;
|
||||
_arrival_speed = PX4_ISFINITE(rover_position_setpoint.arrival_speed) ? rover_position_setpoint.arrival_speed : 0.f;
|
||||
_cruising_speed = PX4_ISFINITE(rover_position_setpoint.cruising_speed) ? rover_position_setpoint.cruising_speed :
|
||||
_param_ro_speed_limit.get();
|
||||
_target_waypoint_ned = Vector2f(rover_position_setpoint.position_ned[0], rover_position_setpoint.position_ned[1]);
|
||||
_arrival_speed = PX4_ISFINITE(surface_vehicle_position_setpoint.arrival_speed) ?
|
||||
surface_vehicle_position_setpoint.arrival_speed : 0.f;
|
||||
_cruising_speed = PX4_ISFINITE(surface_vehicle_position_setpoint.cruising_speed) ?
|
||||
surface_vehicle_position_setpoint.cruising_speed :
|
||||
_param_sv_speed_limit.get();
|
||||
_target_waypoint_ned = Vector2f(surface_vehicle_position_setpoint.position_ned[0],
|
||||
surface_vehicle_position_setpoint.position_ned[1]);
|
||||
_stopped = false;
|
||||
}
|
||||
}
|
||||
@@ -170,7 +173,7 @@ bool DifferentialPosControl::runSanityChecks()
|
||||
{
|
||||
bool ret = true;
|
||||
|
||||
if (_param_ro_speed_limit.get() < FLT_EPSILON) {
|
||||
if (_param_sv_speed_limit.get() < FLT_EPSILON) {
|
||||
ret = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,10 +45,10 @@
|
||||
// uORB includes
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/topics/rover_speed_setpoint.h>
|
||||
#include <uORB/topics/rover_attitude_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_speed_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_attitude_setpoint.h>
|
||||
#include <uORB/topics/pure_pursuit_status.h>
|
||||
#include <uORB/topics/rover_position_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_position_setpoint.h>
|
||||
#include <uORB/topics/vehicle_attitude.h>
|
||||
#include <uORB/topics/vehicle_local_position.h>
|
||||
|
||||
@@ -76,7 +76,7 @@ public:
|
||||
~DifferentialPosControl() = default;
|
||||
|
||||
/**
|
||||
* @brief Generate and publish roverSpeedSetpoint and roverAttitudeSetpoint from roverPositionSetpoint.
|
||||
* @brief Generate and publish SurfaceVehicleSpeedSetpoint and SurfaceVehicleAttitudeSetpoint from SurfaceVehiclePositionSetpoint.
|
||||
*/
|
||||
void updatePosControl();
|
||||
|
||||
@@ -89,7 +89,7 @@ public:
|
||||
/**
|
||||
* @brief Reset position controller.
|
||||
*/
|
||||
void reset() {_start_ned = Vector2f{NAN, NAN}; _target_waypoint_ned = Vector2f{NAN, NAN}; _arrival_speed = 0.f; _cruising_speed = _param_ro_speed_limit.get(); _stopped = false;};
|
||||
void reset() {_start_ned = Vector2f{NAN, NAN}; _target_waypoint_ned = Vector2f{NAN, NAN}; _arrival_speed = 0.f; _cruising_speed = _param_sv_speed_limit.get(); _stopped = false;};
|
||||
|
||||
protected:
|
||||
/**
|
||||
@@ -106,12 +106,12 @@ private:
|
||||
// uORB subscriptions
|
||||
uORB::Subscription _vehicle_attitude_sub{ORB_ID(vehicle_attitude)};
|
||||
uORB::Subscription _vehicle_local_position_sub{ORB_ID(vehicle_local_position)};
|
||||
uORB::Subscription _rover_position_setpoint_sub{ORB_ID(rover_position_setpoint)};
|
||||
uORB::Subscription _surface_vehicle_position_setpoint_sub{ORB_ID(surface_vehicle_position_setpoint)};
|
||||
|
||||
// uORB publications
|
||||
uORB::Publication<rover_speed_setpoint_s> _rover_speed_setpoint_pub{ORB_ID(rover_speed_setpoint)};
|
||||
uORB::Publication<surface_vehicle_speed_setpoint_s> _surface_vehicle_speed_setpoint_pub{ORB_ID(surface_vehicle_speed_setpoint)};
|
||||
uORB::Publication<pure_pursuit_status_s> _pure_pursuit_status_pub{ORB_ID(pure_pursuit_status)};
|
||||
uORB::Publication<rover_attitude_setpoint_s> _rover_attitude_setpoint_pub{ORB_ID(rover_attitude_setpoint)};
|
||||
uORB::Publication<surface_vehicle_attitude_setpoint_s> _surface_vehicle_attitude_setpoint_pub{ORB_ID(surface_vehicle_attitude_setpoint)};
|
||||
|
||||
// Variables
|
||||
Quatf _vehicle_attitude_quaternion{};
|
||||
@@ -130,15 +130,15 @@ private:
|
||||
DEFINE_PARAMETERS(
|
||||
(ParamFloat<px4::params::RD_TRANS_TRN_DRV>) _param_rd_trans_trn_drv,
|
||||
(ParamFloat<px4::params::RD_TRANS_DRV_TRN>) _param_rd_trans_drv_trn,
|
||||
(ParamFloat<px4::params::RO_MAX_THR_SPEED>) _param_ro_max_thr_speed,
|
||||
(ParamFloat<px4::params::RO_DECEL_LIM>) _param_ro_decel_limit,
|
||||
(ParamFloat<px4::params::RO_JERK_LIM>) _param_ro_jerk_limit,
|
||||
(ParamFloat<px4::params::RO_SPEED_LIM>) _param_ro_speed_limit,
|
||||
(ParamFloat<px4::params::SV_MAX_THR_SPEED>) _param_sv_max_thr_speed,
|
||||
(ParamFloat<px4::params::SV_DECEL_LIM>) _param_sv_decel_limit,
|
||||
(ParamFloat<px4::params::SV_JERK_LIM>) _param_sv_jerk_limit,
|
||||
(ParamFloat<px4::params::SV_SPEED_LIM>) _param_sv_speed_limit,
|
||||
(ParamFloat<px4::params::PP_LOOKAHD_GAIN>) _param_pp_lookahd_gain,
|
||||
(ParamFloat<px4::params::PP_LOOKAHD_MAX>) _param_pp_lookahd_max,
|
||||
(ParamFloat<px4::params::PP_LOOKAHD_MIN>) _param_pp_lookahd_min,
|
||||
(ParamFloat<px4::params::NAV_ACC_RAD>) _param_nav_acc_rad,
|
||||
(ParamFloat<px4::params::RO_SPEED_RED>) _param_ro_speed_red,
|
||||
(ParamFloat<px4::params::RO_SPEED_TH>) _param_ro_speed_th
|
||||
(ParamFloat<px4::params::SV_SPEED_RED>) _param_sv_speed_red,
|
||||
(ParamFloat<px4::params::SV_SPEED_TH>) _param_sv_speed_th
|
||||
)
|
||||
};
|
||||
|
||||
+26
-26
@@ -37,8 +37,8 @@ using namespace time_literals;
|
||||
|
||||
DifferentialRateControl::DifferentialRateControl(ModuleParams *parent) : ModuleParams(parent)
|
||||
{
|
||||
_rover_steering_setpoint_pub.advertise();
|
||||
_rover_rate_status_pub.advertise();
|
||||
_surface_vehicle_steering_setpoint_pub.advertise();
|
||||
_surface_vehicle_rate_status_pub.advertise();
|
||||
updateParams();
|
||||
}
|
||||
|
||||
@@ -47,12 +47,12 @@ void DifferentialRateControl::updateParams()
|
||||
ModuleParams::updateParams();
|
||||
|
||||
// Set up PID controller
|
||||
_pid_yaw_rate.setGains(_param_ro_yaw_rate_p.get(), _param_ro_yaw_rate_i.get(), 0.f);
|
||||
_pid_yaw_rate.setGains(_param_sv_yaw_rate_p.get(), _param_sv_yaw_rate_i.get(), 0.f);
|
||||
_pid_yaw_rate.setIntegralLimit(1.f);
|
||||
_pid_yaw_rate.setOutputLimit(1.f);
|
||||
|
||||
// Set up slew rate
|
||||
_adjusted_yaw_rate_setpoint.setSlewRate(_param_ro_yaw_accel_limit.get() * M_DEG_TO_RAD_F);
|
||||
_adjusted_yaw_rate_setpoint.setSlewRate(_param_sv_yaw_accel_limit.get() * M_DEG_TO_RAD_F);
|
||||
}
|
||||
|
||||
void DifferentialRateControl::updateRateControl()
|
||||
@@ -64,39 +64,39 @@ void DifferentialRateControl::updateRateControl()
|
||||
if (_vehicle_angular_velocity_sub.updated()) {
|
||||
vehicle_angular_velocity_s vehicle_angular_velocity{};
|
||||
_vehicle_angular_velocity_sub.copy(&vehicle_angular_velocity);
|
||||
_vehicle_yaw_rate = fabsf(vehicle_angular_velocity.xyz[2]) > _param_ro_yaw_rate_th.get() * M_DEG_TO_RAD_F ?
|
||||
_vehicle_yaw_rate = fabsf(vehicle_angular_velocity.xyz[2]) > _param_sv_yaw_rate_th.get() * M_DEG_TO_RAD_F ?
|
||||
vehicle_angular_velocity.xyz[2] : 0.f;
|
||||
}
|
||||
|
||||
if (_rover_rate_setpoint_sub.updated()) {
|
||||
rover_rate_setpoint_s rover_rate_setpoint{};
|
||||
_rover_rate_setpoint_sub.copy(&rover_rate_setpoint);
|
||||
_yaw_rate_setpoint = rover_rate_setpoint.yaw_rate_setpoint;
|
||||
if (_surface_vehicle_rate_setpoint_sub.updated()) {
|
||||
surface_vehicle_rate_setpoint_s surface_vehicle_rate_setpoint{};
|
||||
_surface_vehicle_rate_setpoint_sub.copy(&surface_vehicle_rate_setpoint);
|
||||
_yaw_rate_setpoint = surface_vehicle_rate_setpoint.yaw_rate_setpoint;
|
||||
}
|
||||
|
||||
if (PX4_ISFINITE(_yaw_rate_setpoint)) {
|
||||
const float yaw_rate_setpoint = fabsf(_yaw_rate_setpoint) > _param_ro_yaw_rate_th.get() * M_DEG_TO_RAD_F ?
|
||||
const float yaw_rate_setpoint = fabsf(_yaw_rate_setpoint) > _param_sv_yaw_rate_th.get() * M_DEG_TO_RAD_F ?
|
||||
_yaw_rate_setpoint : 0.f;
|
||||
const float speed_diff_normalized = RoverControl::rateControl(_adjusted_yaw_rate_setpoint, _pid_yaw_rate,
|
||||
yaw_rate_setpoint, _vehicle_yaw_rate, _param_ro_max_thr_speed.get(), _param_ro_yaw_rate_corr.get(),
|
||||
_param_ro_yaw_accel_limit.get() * M_DEG_TO_RAD_F,
|
||||
const float speed_diff_normalized = SurfaceVehicleControl::rateControl(_adjusted_yaw_rate_setpoint, _pid_yaw_rate,
|
||||
yaw_rate_setpoint, _vehicle_yaw_rate, _param_sv_max_thr_speed.get(), _param_sv_yaw_rate_corr.get(),
|
||||
_param_sv_yaw_accel_limit.get() * M_DEG_TO_RAD_F,
|
||||
_param_ro_yaw_decel_limit.get() * M_DEG_TO_RAD_F, _param_rd_wheel_track.get(), dt);
|
||||
rover_steering_setpoint_s rover_steering_setpoint{};
|
||||
rover_steering_setpoint.timestamp = _timestamp;
|
||||
rover_steering_setpoint.normalized_steering_setpoint = speed_diff_normalized;
|
||||
_rover_steering_setpoint_pub.publish(rover_steering_setpoint);
|
||||
surface_vehicle_steering_setpoint_s surface_vehicle_steering_setpoint{};
|
||||
surface_vehicle_steering_setpoint.timestamp = _timestamp;
|
||||
surface_vehicle_steering_setpoint.normalized_steering_setpoint = speed_diff_normalized;
|
||||
_surface_vehicle_steering_setpoint_pub.publish(surface_vehicle_steering_setpoint);
|
||||
|
||||
} else {
|
||||
_pid_yaw_rate.resetIntegral();
|
||||
}
|
||||
|
||||
// Publish rate controller status (logging only)
|
||||
rover_rate_status_s rover_rate_status;
|
||||
rover_rate_status.timestamp = _timestamp;
|
||||
rover_rate_status.measured_yaw_rate = _vehicle_yaw_rate;
|
||||
rover_rate_status.adjusted_yaw_rate_setpoint = _adjusted_yaw_rate_setpoint.getState();
|
||||
rover_rate_status.pid_yaw_rate_integral = _pid_yaw_rate.getIntegral();
|
||||
_rover_rate_status_pub.publish(rover_rate_status);
|
||||
surface_vehicle_rate_status_s surface_vehicle_rate_status;
|
||||
surface_vehicle_rate_status.timestamp = _timestamp;
|
||||
surface_vehicle_rate_status.measured_yaw_rate = _vehicle_yaw_rate;
|
||||
surface_vehicle_rate_status.adjusted_yaw_rate_setpoint = _adjusted_yaw_rate_setpoint.getState();
|
||||
surface_vehicle_rate_status.pid_yaw_rate_integral = _pid_yaw_rate.getIntegral();
|
||||
_surface_vehicle_rate_status_pub.publish(surface_vehicle_rate_status);
|
||||
|
||||
}
|
||||
|
||||
@@ -104,12 +104,12 @@ bool DifferentialRateControl::runSanityChecks()
|
||||
{
|
||||
bool ret = true;
|
||||
|
||||
if ((_param_rd_wheel_track.get() < FLT_EPSILON || _param_ro_max_thr_speed.get() < FLT_EPSILON)
|
||||
&& _param_ro_yaw_rate_p.get() < FLT_EPSILON) {
|
||||
if ((_param_rd_wheel_track.get() < FLT_EPSILON || _param_sv_max_thr_speed.get() < FLT_EPSILON)
|
||||
&& _param_sv_yaw_rate_p.get() < FLT_EPSILON) {
|
||||
ret = false;
|
||||
events::send<float, float, float>(events::ID("differential_rate_control_conf_invalid_rate_control"), events::Log::Error,
|
||||
"Invalid configuration for rate control: Neither feed forward nor feedback is setup", _param_rd_wheel_track.get(),
|
||||
_param_ro_max_thr_speed.get(), _param_ro_yaw_rate_p.get());
|
||||
_param_sv_max_thr_speed.get(), _param_sv_yaw_rate_p.get());
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
+15
-15
@@ -38,7 +38,7 @@
|
||||
#include <px4_platform_common/events.h>
|
||||
|
||||
// Libraries
|
||||
#include <lib/rover_control/RoverControl.hpp>
|
||||
#include <lib/surface_vehicle_control/SurfaceVehicleControl.hpp>
|
||||
#include <lib/pid/PID.hpp>
|
||||
#include <lib/slew_rate/SlewRate.hpp>
|
||||
#include <math.h>
|
||||
@@ -46,9 +46,9 @@
|
||||
// uORB includes
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/topics/rover_rate_setpoint.h>
|
||||
#include <uORB/topics/rover_steering_setpoint.h>
|
||||
#include <uORB/topics/rover_rate_status.h>
|
||||
#include <uORB/topics/surface_vehicle_rate_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_steering_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_rate_status.h>
|
||||
#include <uORB/topics/vehicle_angular_velocity.h>
|
||||
|
||||
/**
|
||||
@@ -65,7 +65,7 @@ public:
|
||||
~DifferentialRateControl() = default;
|
||||
|
||||
/**
|
||||
* @brief Generate and publish roverSteeringSetpoint from roverRateSetpoint.
|
||||
* @brief Generate and publish SurfaceVehicleSteeringSetpoint from SurfaceVehicleRateSetpoint.
|
||||
*/
|
||||
void updateRateControl();
|
||||
|
||||
@@ -89,12 +89,12 @@ protected:
|
||||
private:
|
||||
|
||||
// uORB subscriptions
|
||||
uORB::Subscription _rover_rate_setpoint_sub{ORB_ID(rover_rate_setpoint)};
|
||||
uORB::Subscription _surface_vehicle_rate_setpoint_sub{ORB_ID(surface_vehicle_rate_setpoint)};
|
||||
uORB::Subscription _vehicle_angular_velocity_sub{ORB_ID(vehicle_angular_velocity)};
|
||||
|
||||
// uORB publications
|
||||
uORB::Publication<rover_steering_setpoint_s> _rover_steering_setpoint_pub{ORB_ID(rover_steering_setpoint)};
|
||||
uORB::Publication<rover_rate_status_s> _rover_rate_status_pub{ORB_ID(rover_rate_status)};
|
||||
uORB::Publication<surface_vehicle_steering_setpoint_s> _surface_vehicle_steering_setpoint_pub{ORB_ID(surface_vehicle_steering_setpoint)};
|
||||
uORB::Publication<surface_vehicle_rate_status_s> _surface_vehicle_rate_status_pub{ORB_ID(surface_vehicle_rate_status)};
|
||||
|
||||
// Variables
|
||||
float _vehicle_yaw_rate{0.f};
|
||||
@@ -107,12 +107,12 @@ private:
|
||||
|
||||
DEFINE_PARAMETERS(
|
||||
(ParamFloat<px4::params::RD_WHEEL_TRACK>) _param_rd_wheel_track,
|
||||
(ParamFloat<px4::params::RO_YAW_RATE_TH>) _param_ro_yaw_rate_th,
|
||||
(ParamFloat<px4::params::RO_YAW_RATE_P>) _param_ro_yaw_rate_p,
|
||||
(ParamFloat<px4::params::RO_YAW_RATE_I>) _param_ro_yaw_rate_i,
|
||||
(ParamFloat<px4::params::RO_YAW_ACCEL_LIM>) _param_ro_yaw_accel_limit,
|
||||
(ParamFloat<px4::params::RO_YAW_DECEL_LIM>) _param_ro_yaw_decel_limit,
|
||||
(ParamFloat<px4::params::RO_YAW_RATE_CORR>) _param_ro_yaw_rate_corr,
|
||||
(ParamFloat<px4::params::RO_MAX_THR_SPEED>) _param_ro_max_thr_speed
|
||||
(ParamFloat<px4::params::SV_YAW_RATE_TH>) _param_sv_yaw_rate_th,
|
||||
(ParamFloat<px4::params::SV_YAW_RATE_P>) _param_sv_yaw_rate_p,
|
||||
(ParamFloat<px4::params::SV_YAW_RATE_I>) _param_sv_yaw_rate_i,
|
||||
(ParamFloat<px4::params::SV_YAW_ACCEL_LIM>) _param_sv_yaw_accel_limit,
|
||||
(ParamFloat<px4::params::SV_YAW_DECEL_LIM>) _param_ro_yaw_decel_limit,
|
||||
(ParamFloat<px4::params::SV_YAW_RATE_CORR>) _param_sv_yaw_rate_corr,
|
||||
(ParamFloat<px4::params::SV_MAX_THR_SPEED>) _param_sv_max_thr_speed
|
||||
)
|
||||
};
|
||||
|
||||
+39
-38
@@ -37,8 +37,8 @@ using namespace time_literals;
|
||||
|
||||
DifferentialSpeedControl::DifferentialSpeedControl(ModuleParams *parent) : ModuleParams(parent)
|
||||
{
|
||||
_rover_throttle_setpoint_pub.advertise();
|
||||
_rover_speed_status_pub.advertise();
|
||||
_surface_vehicle_throttle_setpoint_pub.advertise();
|
||||
_surface_vehicle_speed_status_pub.advertise();
|
||||
updateParams();
|
||||
}
|
||||
|
||||
@@ -47,13 +47,13 @@ void DifferentialSpeedControl::updateParams()
|
||||
ModuleParams::updateParams();
|
||||
|
||||
// Set up PID controller
|
||||
_pid_speed.setGains(_param_ro_speed_p.get(), _param_ro_speed_i.get(), 0.f);
|
||||
_pid_speed.setGains(_param_sv_speed_p.get(), _param_sv_speed_i.get(), 0.f);
|
||||
_pid_speed.setIntegralLimit(1.f);
|
||||
_pid_speed.setOutputLimit(1.f);
|
||||
|
||||
// Set up slew rate
|
||||
if (_param_ro_accel_limit.get() > FLT_EPSILON) {
|
||||
_adjusted_speed_setpoint.setSlewRate(_param_ro_accel_limit.get());
|
||||
if (_param_sv_accel_limit.get() > FLT_EPSILON) {
|
||||
_adjusted_speed_setpoint.setSlewRate(_param_sv_accel_limit.get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,25 +68,26 @@ void DifferentialSpeedControl::updateSpeedControl()
|
||||
// Throttle Setpoint
|
||||
if (PX4_ISFINITE(_speed_setpoint)) {
|
||||
const float speed_setpoint = calcSpeedSetpoint();
|
||||
rover_throttle_setpoint_s rover_throttle_setpoint{};
|
||||
rover_throttle_setpoint.timestamp = _timestamp;
|
||||
rover_throttle_setpoint.throttle_body_x = RoverControl::speedControl(_adjusted_speed_setpoint, _pid_speed,
|
||||
speed_setpoint, _vehicle_speed, _param_ro_accel_limit.get(), _param_ro_decel_limit.get(),
|
||||
_param_ro_max_thr_speed.get(), dt);
|
||||
rover_throttle_setpoint.throttle_body_y = 0.f;
|
||||
_rover_throttle_setpoint_pub.publish(rover_throttle_setpoint);
|
||||
surface_vehicle_throttle_setpoint_s surface_vehicle_throttle_setpoint{};
|
||||
surface_vehicle_throttle_setpoint.timestamp = _timestamp;
|
||||
surface_vehicle_throttle_setpoint.throttle_body_x = SurfaceVehicleControl::speedControl(_adjusted_speed_setpoint,
|
||||
_pid_speed,
|
||||
speed_setpoint, _vehicle_speed, _param_sv_accel_limit.get(), _param_sv_decel_limit.get(),
|
||||
_param_sv_max_thr_speed.get(), dt);
|
||||
surface_vehicle_throttle_setpoint.throttle_body_y = 0.f;
|
||||
_surface_vehicle_throttle_setpoint_pub.publish(surface_vehicle_throttle_setpoint);
|
||||
}
|
||||
|
||||
// Publish speed controller status (logging only)
|
||||
rover_speed_status_s rover_speed_status;
|
||||
rover_speed_status.timestamp = _timestamp;
|
||||
rover_speed_status.measured_speed_body_x = _vehicle_speed;
|
||||
rover_speed_status.adjusted_speed_body_x_setpoint = _adjusted_speed_setpoint.getState();
|
||||
rover_speed_status.pid_throttle_body_x_integral = _pid_speed.getIntegral();
|
||||
rover_speed_status.measured_speed_body_y = NAN;
|
||||
rover_speed_status.adjusted_speed_body_y_setpoint = NAN;
|
||||
rover_speed_status.pid_throttle_body_y_integral = NAN;
|
||||
_rover_speed_status_pub.publish(rover_speed_status);
|
||||
surface_vehicle_speed_status_s surface_vehicle_speed_status;
|
||||
surface_vehicle_speed_status.timestamp = _timestamp;
|
||||
surface_vehicle_speed_status.measured_speed_body_x = _vehicle_speed;
|
||||
surface_vehicle_speed_status.adjusted_speed_body_x_setpoint = _adjusted_speed_setpoint.getState();
|
||||
surface_vehicle_speed_status.pid_throttle_body_x_integral = _pid_speed.getIntegral();
|
||||
surface_vehicle_speed_status.measured_speed_body_y = NAN;
|
||||
surface_vehicle_speed_status.adjusted_speed_body_y_setpoint = NAN;
|
||||
surface_vehicle_speed_status.pid_throttle_body_y_integral = NAN;
|
||||
_surface_vehicle_speed_status_pub.publish(surface_vehicle_speed_status);
|
||||
}
|
||||
|
||||
void DifferentialSpeedControl::updateSubscriptions()
|
||||
@@ -103,34 +104,34 @@ void DifferentialSpeedControl::updateSubscriptions()
|
||||
Vector3f velocity_ned(vehicle_local_position.vx, vehicle_local_position.vy, vehicle_local_position.vz);
|
||||
Vector3f velocity_xyz = _vehicle_attitude_quaternion.rotateVectorInverse(velocity_ned);
|
||||
Vector2f velocity_2d = Vector2f(velocity_xyz(0), velocity_xyz(1));
|
||||
_vehicle_speed = velocity_2d.norm() > _param_ro_speed_th.get() ? sign(velocity_2d(0)) * velocity_2d.norm() : 0.f;
|
||||
_vehicle_speed = velocity_2d.norm() > _param_sv_speed_th.get() ? sign(velocity_2d(0)) * velocity_2d.norm() : 0.f;
|
||||
}
|
||||
|
||||
if (_rover_speed_setpoint_sub.updated()) {
|
||||
rover_speed_setpoint_s rover_speed_setpoint;
|
||||
_rover_speed_setpoint_sub.copy(&rover_speed_setpoint);
|
||||
_speed_setpoint = rover_speed_setpoint.speed_body_x;
|
||||
if (_surface_vehicle_speed_setpoint_sub.updated()) {
|
||||
surface_vehicle_speed_setpoint_s surface_vehicle_speed_setpoint;
|
||||
_surface_vehicle_speed_setpoint_sub.copy(&surface_vehicle_speed_setpoint);
|
||||
_speed_setpoint = surface_vehicle_speed_setpoint.speed_body_x;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
float DifferentialSpeedControl::calcSpeedSetpoint()
|
||||
{
|
||||
float speed_setpoint = math::constrain(_speed_setpoint, -_param_ro_speed_limit.get(), _param_ro_speed_limit.get());
|
||||
float speed_setpoint = math::constrain(_speed_setpoint, -_param_sv_speed_limit.get(), _param_sv_speed_limit.get());
|
||||
|
||||
const float speed_setpoint_normalized = math::interpolate<float>(speed_setpoint,
|
||||
-_param_ro_max_thr_speed.get(), _param_ro_max_thr_speed.get(), -1.f, 1.f);
|
||||
-_param_sv_max_thr_speed.get(), _param_sv_max_thr_speed.get(), -1.f, 1.f);
|
||||
|
||||
if (_rover_steering_setpoint_sub.updated()) {
|
||||
rover_steering_setpoint_s rover_steering_setpoint{};
|
||||
_rover_steering_setpoint_sub.copy(&rover_steering_setpoint);
|
||||
_normalized_speed_diff = rover_steering_setpoint.normalized_steering_setpoint;
|
||||
if (_surface_vehicle_steering_setpoint_sub.updated()) {
|
||||
surface_vehicle_steering_setpoint_s surface_vehicle_steering_setpoint{};
|
||||
_surface_vehicle_steering_setpoint_sub.copy(&surface_vehicle_steering_setpoint);
|
||||
_normalized_speed_diff = surface_vehicle_steering_setpoint.normalized_steering_setpoint;
|
||||
}
|
||||
|
||||
if (fabsf(speed_setpoint_normalized) > 1.f - fabsf(
|
||||
_normalized_speed_diff)) { // Adjust speed setpoint if it is infeasible due to the desired speed difference of the left/right wheels
|
||||
speed_setpoint = math::interpolate<float>(sign(speed_setpoint_normalized) * (1.f - fabsf(_normalized_speed_diff)), -1.f,
|
||||
1.f, -_param_ro_max_thr_speed.get(), _param_ro_max_thr_speed.get());
|
||||
1.f, -_param_sv_max_thr_speed.get(), _param_sv_max_thr_speed.get());
|
||||
}
|
||||
|
||||
return speed_setpoint;
|
||||
@@ -140,17 +141,17 @@ bool DifferentialSpeedControl::runSanityChecks()
|
||||
{
|
||||
bool ret = true;
|
||||
|
||||
if (_param_ro_speed_limit.get() < FLT_EPSILON) {
|
||||
if (_param_sv_speed_limit.get() < FLT_EPSILON) {
|
||||
ret = false;
|
||||
events::send<float>(events::ID("differential_speed_control_conf_invalid_speed_lim"), events::Log::Error,
|
||||
"Invalid configuration of necessary parameter RO_SPEED_LIM", _param_ro_speed_limit.get());
|
||||
"Invalid configuration of necessary parameter SV_SPEED_LIM", _param_sv_speed_limit.get());
|
||||
}
|
||||
|
||||
if (_param_ro_max_thr_speed.get() < FLT_EPSILON && _param_ro_speed_p.get() < FLT_EPSILON) {
|
||||
if (_param_sv_max_thr_speed.get() < FLT_EPSILON && _param_sv_speed_p.get() < FLT_EPSILON) {
|
||||
ret = false;
|
||||
events::send<float, float>(events::ID("differential_speed_control_conf_invalid_speed_control"), events::Log::Error,
|
||||
"Invalid configuration for speed control: Neither feed forward (RO_MAX_THR_SPEED) nor feedback (RO_SPEED_P) is setup",
|
||||
_param_ro_max_thr_speed.get(), _param_ro_speed_p.get());
|
||||
"Invalid configuration for speed control: Neither feed forward (SV_MAX_THR_SPEED) nor feedback (SV_SPEED_P) is setup",
|
||||
_param_sv_max_thr_speed.get(), _param_sv_speed_p.get());
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
+18
-18
@@ -38,7 +38,7 @@
|
||||
#include <px4_platform_common/events.h>
|
||||
|
||||
// Libraries
|
||||
#include <lib/rover_control/RoverControl.hpp>
|
||||
#include <lib/surface_vehicle_control/SurfaceVehicleControl.hpp>
|
||||
#include <lib/pid/PID.hpp>
|
||||
#include <matrix/matrix/math.hpp>
|
||||
#include <lib/slew_rate/SlewRate.hpp>
|
||||
@@ -47,10 +47,10 @@
|
||||
// uORB includes
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/topics/rover_throttle_setpoint.h>
|
||||
#include <uORB/topics/rover_speed_status.h>
|
||||
#include <uORB/topics/rover_speed_setpoint.h>
|
||||
#include <uORB/topics/rover_steering_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_throttle_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_speed_status.h>
|
||||
#include <uORB/topics/surface_vehicle_speed_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_steering_setpoint.h>
|
||||
#include <uORB/topics/vehicle_attitude.h>
|
||||
#include <uORB/topics/vehicle_local_position.h>
|
||||
|
||||
@@ -70,7 +70,7 @@ public:
|
||||
~DifferentialSpeedControl() = default;
|
||||
|
||||
/**
|
||||
* @brief Generate and publish RoverThrottleSetpoint from roverSpeedSetpoint.
|
||||
* @brief Generate and publish SurfaceVehicleThrottleSetpoint from SurfaceVehicleSpeedSetpoint.
|
||||
*/
|
||||
void updateSpeedControl();
|
||||
|
||||
@@ -106,12 +106,12 @@ private:
|
||||
// uORB subscriptions
|
||||
uORB::Subscription _vehicle_attitude_sub{ORB_ID(vehicle_attitude)};
|
||||
uORB::Subscription _vehicle_local_position_sub{ORB_ID(vehicle_local_position)};
|
||||
uORB::Subscription _rover_speed_setpoint_sub{ORB_ID(rover_speed_setpoint)};
|
||||
uORB::Subscription _rover_steering_setpoint_sub{ORB_ID(rover_steering_setpoint)};
|
||||
uORB::Subscription _surface_vehicle_speed_setpoint_sub{ORB_ID(surface_vehicle_speed_setpoint)};
|
||||
uORB::Subscription _surface_vehicle_steering_setpoint_sub{ORB_ID(surface_vehicle_steering_setpoint)};
|
||||
|
||||
// uORB publications
|
||||
uORB::Publication<rover_throttle_setpoint_s> _rover_throttle_setpoint_pub{ORB_ID(rover_throttle_setpoint)};
|
||||
uORB::Publication<rover_speed_status_s> _rover_speed_status_pub{ORB_ID(rover_speed_status)};
|
||||
uORB::Publication<surface_vehicle_throttle_setpoint_s> _surface_vehicle_throttle_setpoint_pub{ORB_ID(surface_vehicle_throttle_setpoint)};
|
||||
uORB::Publication<surface_vehicle_speed_status_s> _surface_vehicle_speed_status_pub{ORB_ID(surface_vehicle_speed_status)};
|
||||
|
||||
// Variables
|
||||
hrt_abstime _timestamp{0};
|
||||
@@ -125,13 +125,13 @@ private:
|
||||
SlewRate<float> _adjusted_speed_setpoint{0.f};
|
||||
|
||||
DEFINE_PARAMETERS(
|
||||
(ParamFloat<px4::params::RO_MAX_THR_SPEED>) _param_ro_max_thr_speed,
|
||||
(ParamFloat<px4::params::RO_SPEED_P>) _param_ro_speed_p,
|
||||
(ParamFloat<px4::params::RO_SPEED_I>) _param_ro_speed_i,
|
||||
(ParamFloat<px4::params::RO_ACCEL_LIM>) _param_ro_accel_limit,
|
||||
(ParamFloat<px4::params::RO_DECEL_LIM>) _param_ro_decel_limit,
|
||||
(ParamFloat<px4::params::RO_JERK_LIM>) _param_ro_jerk_limit,
|
||||
(ParamFloat<px4::params::RO_SPEED_LIM>) _param_ro_speed_limit,
|
||||
(ParamFloat<px4::params::RO_SPEED_TH>) _param_ro_speed_th
|
||||
(ParamFloat<px4::params::SV_MAX_THR_SPEED>) _param_sv_max_thr_speed,
|
||||
(ParamFloat<px4::params::SV_SPEED_P>) _param_sv_speed_p,
|
||||
(ParamFloat<px4::params::SV_SPEED_I>) _param_sv_speed_i,
|
||||
(ParamFloat<px4::params::SV_ACCEL_LIM>) _param_sv_accel_limit,
|
||||
(ParamFloat<px4::params::SV_DECEL_LIM>) _param_sv_decel_limit,
|
||||
(ParamFloat<px4::params::SV_JERK_LIM>) _param_sv_jerk_limit,
|
||||
(ParamFloat<px4::params::SV_SPEED_LIM>) _param_sv_speed_limit,
|
||||
(ParamFloat<px4::params::SV_SPEED_TH>) _param_sv_speed_th
|
||||
)
|
||||
};
|
||||
|
||||
@@ -54,7 +54,7 @@ px4_add_module(
|
||||
MecanumManualMode
|
||||
MecanumOffboardMode
|
||||
px4_work_queue
|
||||
rover_control
|
||||
surface_vehicle_control
|
||||
pure_pursuit
|
||||
MODULE_CONFIG
|
||||
module.yaml
|
||||
|
||||
@@ -44,9 +44,9 @@ void MecanumActControl::updateParams()
|
||||
{
|
||||
ModuleParams::updateParams();
|
||||
|
||||
if (_param_ro_accel_limit.get() > FLT_EPSILON && _param_ro_max_thr_speed.get() > FLT_EPSILON) {
|
||||
_adjusted_throttle_x_setpoint.setSlewRate(_param_ro_accel_limit.get() / _param_ro_max_thr_speed.get());
|
||||
_adjusted_throttle_y_setpoint.setSlewRate(_param_ro_accel_limit.get() / _param_ro_max_thr_speed.get());
|
||||
if (_param_sv_accel_limit.get() > FLT_EPSILON && _param_sv_max_thr_speed.get() > FLT_EPSILON) {
|
||||
_adjusted_throttle_x_setpoint.setSlewRate(_param_sv_accel_limit.get() / _param_sv_max_thr_speed.get());
|
||||
_adjusted_throttle_y_setpoint.setSlewRate(_param_sv_accel_limit.get() / _param_sv_max_thr_speed.get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,17 +57,17 @@ void MecanumActControl::updateActControl()
|
||||
const float dt = math::constrain(_timestamp - timestamp_prev, 1_ms, 10_ms) * 1e-6f;
|
||||
|
||||
// Motor control
|
||||
if (_rover_throttle_setpoint_sub.updated()) {
|
||||
rover_throttle_setpoint_s rover_throttle_setpoint{};
|
||||
_rover_throttle_setpoint_sub.copy(&rover_throttle_setpoint);
|
||||
_throttle_x_setpoint = rover_throttle_setpoint.throttle_body_x;
|
||||
_throttle_y_setpoint = rover_throttle_setpoint.throttle_body_y;
|
||||
if (_surface_vehicle_throttle_setpoint_sub.updated()) {
|
||||
surface_vehicle_throttle_setpoint_s surface_vehicle_throttle_setpoint{};
|
||||
_surface_vehicle_throttle_setpoint_sub.copy(&surface_vehicle_throttle_setpoint);
|
||||
_throttle_x_setpoint = surface_vehicle_throttle_setpoint.throttle_body_x;
|
||||
_throttle_y_setpoint = surface_vehicle_throttle_setpoint.throttle_body_y;
|
||||
}
|
||||
|
||||
if (_rover_steering_setpoint_sub.updated()) {
|
||||
rover_steering_setpoint_s rover_steering_setpoint{};
|
||||
_rover_steering_setpoint_sub.copy(&rover_steering_setpoint);
|
||||
_speed_diff_setpoint = rover_steering_setpoint.normalized_steering_setpoint;
|
||||
if (_surface_vehicle_steering_setpoint_sub.updated()) {
|
||||
surface_vehicle_steering_setpoint_s surface_vehicle_steering_setpoint{};
|
||||
_surface_vehicle_steering_setpoint_sub.copy(&surface_vehicle_steering_setpoint);
|
||||
_speed_diff_setpoint = surface_vehicle_steering_setpoint.normalized_steering_setpoint;
|
||||
}
|
||||
|
||||
if (PX4_ISFINITE(_throttle_x_setpoint) && PX4_ISFINITE(_throttle_y_setpoint) && PX4_ISFINITE(_speed_diff_setpoint)) {
|
||||
@@ -75,12 +75,12 @@ void MecanumActControl::updateActControl()
|
||||
_actuator_motors_sub.copy(&actuator_motors_sub);
|
||||
const float current_throttle_x = (actuator_motors_sub.control[0] + actuator_motors_sub.control[1]) / 2.f;
|
||||
const float current_throttle_y = (actuator_motors_sub.control[2] - actuator_motors_sub.control[0]) / 2.f;
|
||||
const float adjusted_throttle_x_setpoint = RoverControl::throttleControl(_adjusted_throttle_x_setpoint,
|
||||
_throttle_x_setpoint, current_throttle_x, _param_ro_accel_limit.get(),
|
||||
_param_ro_decel_limit.get(), _param_ro_max_thr_speed.get(), dt);
|
||||
const float adjusted_throttle_y_setpoint = RoverControl::throttleControl(_adjusted_throttle_y_setpoint,
|
||||
_throttle_y_setpoint, current_throttle_y, _param_ro_accel_limit.get(),
|
||||
_param_ro_decel_limit.get(), _param_ro_max_thr_speed.get(), dt);
|
||||
const float adjusted_throttle_x_setpoint = SurfaceVehicleControl::throttleControl(_adjusted_throttle_x_setpoint,
|
||||
_throttle_x_setpoint, current_throttle_x, _param_sv_accel_limit.get(),
|
||||
_param_sv_decel_limit.get(), _param_sv_max_thr_speed.get(), dt);
|
||||
const float adjusted_throttle_y_setpoint = SurfaceVehicleControl::throttleControl(_adjusted_throttle_y_setpoint,
|
||||
_throttle_y_setpoint, current_throttle_y, _param_sv_accel_limit.get(),
|
||||
_param_sv_decel_limit.get(), _param_sv_max_thr_speed.get(), dt);
|
||||
actuator_motors_s actuator_motors{};
|
||||
actuator_motors.reversible_flags = _param_r_rev.get();
|
||||
computeInverseKinematics(adjusted_throttle_x_setpoint, adjusted_throttle_y_setpoint,
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
#include <px4_platform_common/module_params.h>
|
||||
|
||||
// Libraries
|
||||
#include <lib/rover_control/RoverControl.hpp>
|
||||
#include <lib/surface_vehicle_control/SurfaceVehicleControl.hpp>
|
||||
#include <lib/slew_rate/SlewRate.hpp>
|
||||
#include <math.h>
|
||||
|
||||
@@ -45,8 +45,8 @@
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/topics/actuator_motors.h>
|
||||
#include <uORB/topics/rover_steering_setpoint.h>
|
||||
#include <uORB/topics/rover_throttle_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_steering_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_throttle_setpoint.h>
|
||||
|
||||
/**
|
||||
* @brief Class for mecanum actuator control.
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
~MecanumActControl() = default;
|
||||
|
||||
/**
|
||||
* @brief Generate and publish actuatorMotors setpoints from roverThrottleSetpoint/roverSteeringSetpoint.
|
||||
* @brief Generate and publish actuatorMotors setpoints from SurfaceVehicleThrottleSetpoint/SurfaceVehicleSteeringSetpoint.
|
||||
*/
|
||||
void updateActControl();
|
||||
|
||||
@@ -89,8 +89,8 @@ private:
|
||||
|
||||
// uORB subscriptions
|
||||
uORB::Subscription _actuator_motors_sub{ORB_ID(actuator_motors)};
|
||||
uORB::Subscription _rover_steering_setpoint_sub{ORB_ID(rover_steering_setpoint)};
|
||||
uORB::Subscription _rover_throttle_setpoint_sub{ORB_ID(rover_throttle_setpoint)};
|
||||
uORB::Subscription _surface_vehicle_steering_setpoint_sub{ORB_ID(surface_vehicle_steering_setpoint)};
|
||||
uORB::Subscription _surface_vehicle_throttle_setpoint_sub{ORB_ID(surface_vehicle_throttle_setpoint)};
|
||||
|
||||
// uORB publications
|
||||
uORB::Publication<actuator_motors_s> _actuator_motors_pub{ORB_ID(actuator_motors)};
|
||||
@@ -108,8 +108,8 @@ private:
|
||||
// Parameters
|
||||
DEFINE_PARAMETERS(
|
||||
(ParamInt<px4::params::CA_R_REV>) _param_r_rev,
|
||||
(ParamFloat<px4::params::RO_ACCEL_LIM>) _param_ro_accel_limit,
|
||||
(ParamFloat<px4::params::RO_DECEL_LIM>) _param_ro_decel_limit,
|
||||
(ParamFloat<px4::params::RO_MAX_THR_SPEED>) _param_ro_max_thr_speed
|
||||
(ParamFloat<px4::params::SV_ACCEL_LIM>) _param_sv_accel_limit,
|
||||
(ParamFloat<px4::params::SV_DECEL_LIM>) _param_sv_decel_limit,
|
||||
(ParamFloat<px4::params::SV_MAX_THR_SPEED>) _param_sv_max_thr_speed
|
||||
)
|
||||
};
|
||||
|
||||
@@ -37,8 +37,8 @@ using namespace time_literals;
|
||||
|
||||
MecanumAttControl::MecanumAttControl(ModuleParams *parent) : ModuleParams(parent)
|
||||
{
|
||||
_rover_rate_setpoint_pub.advertise();
|
||||
_rover_attitude_status_pub.advertise();
|
||||
_surface_vehicle_rate_setpoint_pub.advertise();
|
||||
_surface_vehicle_attitude_status_pub.advertise();
|
||||
updateParams();
|
||||
}
|
||||
|
||||
@@ -46,12 +46,12 @@ void MecanumAttControl::updateParams()
|
||||
{
|
||||
ModuleParams::updateParams();
|
||||
|
||||
if (_param_ro_yaw_rate_limit.get() > FLT_EPSILON) {
|
||||
_max_yaw_rate = _param_ro_yaw_rate_limit.get() * M_DEG_TO_RAD_F;
|
||||
if (_param_sv_yaw_rate_limit.get() > FLT_EPSILON) {
|
||||
_max_yaw_rate = _param_sv_yaw_rate_limit.get() * M_DEG_TO_RAD_F;
|
||||
}
|
||||
|
||||
// Set up PID controller
|
||||
_pid_yaw.setGains(_param_ro_yaw_p.get(), 0.f, 0.f);
|
||||
_pid_yaw.setGains(_param_sv_yaw_p.get(), 0.f, 0.f);
|
||||
_pid_yaw.setIntegralLimit(_max_yaw_rate);
|
||||
_pid_yaw.setOutputLimit(_max_yaw_rate);
|
||||
|
||||
@@ -72,28 +72,28 @@ void MecanumAttControl::updateAttControl()
|
||||
_vehicle_yaw = matrix::Eulerf(vehicle_attitude_quaternion).psi();
|
||||
}
|
||||
|
||||
if (_rover_attitude_setpoint_sub.updated()) {
|
||||
rover_attitude_setpoint_s rover_attitude_setpoint{};
|
||||
_rover_attitude_setpoint_sub.copy(&rover_attitude_setpoint);
|
||||
_yaw_setpoint = rover_attitude_setpoint.yaw_setpoint;
|
||||
if (_surface_vehicle_attitude_setpoint_sub.updated()) {
|
||||
surface_vehicle_attitude_setpoint_s surface_vehicle_attitude_setpoint{};
|
||||
_surface_vehicle_attitude_setpoint_sub.copy(&surface_vehicle_attitude_setpoint);
|
||||
_yaw_setpoint = surface_vehicle_attitude_setpoint.yaw_setpoint;
|
||||
}
|
||||
|
||||
if (PX4_ISFINITE(_yaw_setpoint)) {
|
||||
const float yaw_rate_setpoint = RoverControl::attitudeControl(_adjusted_yaw_setpoint, _pid_yaw, _max_yaw_rate,
|
||||
const float yaw_rate_setpoint = SurfaceVehicleControl::attitudeControl(_adjusted_yaw_setpoint, _pid_yaw, _max_yaw_rate,
|
||||
_vehicle_yaw, _yaw_setpoint, dt);
|
||||
rover_rate_setpoint_s rover_rate_setpoint{};
|
||||
rover_rate_setpoint.timestamp = _timestamp;
|
||||
rover_rate_setpoint.yaw_rate_setpoint = math::constrain(yaw_rate_setpoint, -_max_yaw_rate, _max_yaw_rate);
|
||||
_rover_rate_setpoint_pub.publish(rover_rate_setpoint);
|
||||
surface_vehicle_rate_setpoint_s surface_vehicle_rate_setpoint{};
|
||||
surface_vehicle_rate_setpoint.timestamp = _timestamp;
|
||||
surface_vehicle_rate_setpoint.yaw_rate_setpoint = math::constrain(yaw_rate_setpoint, -_max_yaw_rate, _max_yaw_rate);
|
||||
_surface_vehicle_rate_setpoint_pub.publish(surface_vehicle_rate_setpoint);
|
||||
|
||||
}
|
||||
|
||||
// Publish attitude controller status (logging only)
|
||||
rover_attitude_status_s rover_attitude_status;
|
||||
rover_attitude_status.timestamp = _timestamp;
|
||||
rover_attitude_status.measured_yaw = _vehicle_yaw;
|
||||
rover_attitude_status.adjusted_yaw_setpoint = matrix::wrap_pi(_adjusted_yaw_setpoint.getState());
|
||||
_rover_attitude_status_pub.publish(rover_attitude_status);
|
||||
surface_vehicle_attitude_status_s surface_vehicle_attitude_status;
|
||||
surface_vehicle_attitude_status.timestamp = _timestamp;
|
||||
surface_vehicle_attitude_status.measured_yaw = _vehicle_yaw;
|
||||
surface_vehicle_attitude_status.adjusted_yaw_setpoint = matrix::wrap_pi(_adjusted_yaw_setpoint.getState());
|
||||
_surface_vehicle_attitude_status_pub.publish(surface_vehicle_attitude_status);
|
||||
|
||||
}
|
||||
|
||||
@@ -101,14 +101,14 @@ bool MecanumAttControl::runSanityChecks()
|
||||
{
|
||||
bool ret = true;
|
||||
|
||||
if (_param_ro_yaw_rate_limit.get() < FLT_EPSILON) {
|
||||
if (_param_sv_yaw_rate_limit.get() < FLT_EPSILON) {
|
||||
ret = false;
|
||||
}
|
||||
|
||||
if (_param_ro_yaw_p.get() < FLT_EPSILON) {
|
||||
if (_param_sv_yaw_p.get() < FLT_EPSILON) {
|
||||
ret = false;
|
||||
events::send<float>(events::ID("mecanum_att_control_conf_invalid_yaw_p"), events::Log::Error,
|
||||
"Invalid configuration of necessary parameter RO_YAW_P", _param_ro_yaw_p.get());
|
||||
"Invalid configuration of necessary parameter SV_YAW_P", _param_sv_yaw_p.get());
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
#include <px4_platform_common/events.h>
|
||||
|
||||
// Libraries
|
||||
#include <lib/rover_control/RoverControl.hpp>
|
||||
#include <lib/surface_vehicle_control/SurfaceVehicleControl.hpp>
|
||||
#include <lib/pid/PID.hpp>
|
||||
#include <lib/slew_rate/SlewRateYaw.hpp>
|
||||
#include <math.h>
|
||||
@@ -47,10 +47,10 @@
|
||||
// uORB includes
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/topics/rover_rate_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_rate_setpoint.h>
|
||||
#include <uORB/topics/vehicle_attitude.h>
|
||||
#include <uORB/topics/rover_attitude_status.h>
|
||||
#include <uORB/topics/rover_attitude_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_attitude_status.h>
|
||||
#include <uORB/topics/surface_vehicle_attitude_setpoint.h>
|
||||
|
||||
/**
|
||||
* @brief Class for mecanum attitude control.
|
||||
@@ -66,7 +66,7 @@ public:
|
||||
~MecanumAttControl() = default;
|
||||
|
||||
/**
|
||||
* @brief Generate and publish roverRateSetpoint from roverAttitudeSetpoint.
|
||||
* @brief Generate and publish SurfaceVehicleRateSetpoint from SurfaceVehicleAttitudeSetpoint.
|
||||
*/
|
||||
void updateAttControl();
|
||||
|
||||
@@ -91,11 +91,11 @@ private:
|
||||
|
||||
// uORB subscriptions
|
||||
uORB::Subscription _vehicle_attitude_sub{ORB_ID(vehicle_attitude)};
|
||||
uORB::Subscription _rover_attitude_setpoint_sub{ORB_ID(rover_attitude_setpoint)};
|
||||
uORB::Subscription _surface_vehicle_attitude_setpoint_sub{ORB_ID(surface_vehicle_attitude_setpoint)};
|
||||
|
||||
// uORB publications
|
||||
uORB::Publication<rover_rate_setpoint_s> _rover_rate_setpoint_pub{ORB_ID(rover_rate_setpoint)};
|
||||
uORB::Publication<rover_attitude_status_s> _rover_attitude_status_pub{ORB_ID(rover_attitude_status)};
|
||||
uORB::Publication<surface_vehicle_rate_setpoint_s> _surface_vehicle_rate_setpoint_pub{ORB_ID(surface_vehicle_rate_setpoint)};
|
||||
uORB::Publication<surface_vehicle_attitude_status_s> _surface_vehicle_attitude_status_pub{ORB_ID(surface_vehicle_attitude_status)};
|
||||
|
||||
// Variables
|
||||
float _vehicle_yaw{0.f};
|
||||
@@ -109,8 +109,8 @@ private:
|
||||
|
||||
// Parameters
|
||||
DEFINE_PARAMETERS(
|
||||
(ParamFloat<px4::params::RO_YAW_RATE_LIM>) _param_ro_yaw_rate_limit,
|
||||
(ParamFloat<px4::params::RO_YAW_P>) _param_ro_yaw_p,
|
||||
(ParamFloat<px4::params::RO_YAW_STICK_DZ>) _param_ro_yaw_stick_dz
|
||||
(ParamFloat<px4::params::SV_YAW_RATE_LIM>) _param_sv_yaw_rate_limit,
|
||||
(ParamFloat<px4::params::SV_YAW_P>) _param_sv_yaw_p,
|
||||
(ParamFloat<px4::params::SV_YAW_STICK_DZ>) _param_sv_yaw_stick_dz
|
||||
)
|
||||
};
|
||||
|
||||
@@ -38,7 +38,7 @@ using namespace time_literals;
|
||||
MecanumAutoMode::MecanumAutoMode(ModuleParams *parent) : ModuleParams(parent)
|
||||
{
|
||||
updateParams();
|
||||
_rover_position_setpoint_pub.advertise();
|
||||
_surface_vehicle_position_setpoint_pub.advertise();
|
||||
}
|
||||
|
||||
void MecanumAutoMode::updateParams()
|
||||
@@ -69,27 +69,28 @@ void MecanumAutoMode::autoControl()
|
||||
Vector2f prev_wp_ned{NAN, NAN};
|
||||
Vector2f next_wp_ned{NAN, NAN};
|
||||
|
||||
RoverControl::globalToLocalSetpointTriplet(curr_wp_ned, prev_wp_ned, next_wp_ned, position_setpoint_triplet,
|
||||
SurfaceVehicleControl::globalToLocalSetpointTriplet(curr_wp_ned, prev_wp_ned, next_wp_ned, position_setpoint_triplet,
|
||||
curr_pos_ned, global_ned_proj_ref);
|
||||
|
||||
float waypoint_transition_angle = RoverControl::calcWaypointTransitionAngle(prev_wp_ned, curr_wp_ned, next_wp_ned);
|
||||
float waypoint_transition_angle = SurfaceVehicleControl::calcWaypointTransitionAngle(prev_wp_ned, curr_wp_ned,
|
||||
next_wp_ned);
|
||||
|
||||
// Waypoint cruising speed
|
||||
float cruising_speed = position_setpoint_triplet.current.cruising_speed > 0.f ? math::constrain(
|
||||
position_setpoint_triplet.current.cruising_speed, 0.f, _param_ro_speed_limit.get()) : _param_ro_speed_limit.get();
|
||||
position_setpoint_triplet.current.cruising_speed, 0.f, _param_sv_speed_limit.get()) : _param_sv_speed_limit.get();
|
||||
|
||||
rover_position_setpoint_s rover_position_setpoint{};
|
||||
rover_position_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_position_setpoint.position_ned[0] = curr_wp_ned(0);
|
||||
rover_position_setpoint.position_ned[1] = curr_wp_ned(1);
|
||||
rover_position_setpoint.start_ned[0] = prev_wp_ned(0);
|
||||
rover_position_setpoint.start_ned[1] = prev_wp_ned(1);
|
||||
rover_position_setpoint.arrival_speed = arrivalSpeed(cruising_speed, waypoint_transition_angle,
|
||||
_param_ro_speed_limit.get(), _param_ro_speed_red.get(), curr_wp_type);
|
||||
rover_position_setpoint.cruising_speed = cruising_speed;
|
||||
rover_position_setpoint.yaw = PX4_ISFINITE(position_setpoint_triplet.current.yaw) ?
|
||||
position_setpoint_triplet.current.yaw : NAN;
|
||||
_rover_position_setpoint_pub.publish(rover_position_setpoint);
|
||||
surface_vehicle_position_setpoint_s surface_vehicle_position_setpoint{};
|
||||
surface_vehicle_position_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_position_setpoint.position_ned[0] = curr_wp_ned(0);
|
||||
surface_vehicle_position_setpoint.position_ned[1] = curr_wp_ned(1);
|
||||
surface_vehicle_position_setpoint.start_ned[0] = prev_wp_ned(0);
|
||||
surface_vehicle_position_setpoint.start_ned[1] = prev_wp_ned(1);
|
||||
surface_vehicle_position_setpoint.arrival_speed = arrivalSpeed(cruising_speed, waypoint_transition_angle,
|
||||
_param_sv_speed_limit.get(), _param_sv_speed_red.get(), curr_wp_type);
|
||||
surface_vehicle_position_setpoint.cruising_speed = cruising_speed;
|
||||
surface_vehicle_position_setpoint.yaw = PX4_ISFINITE(position_setpoint_triplet.current.yaw) ?
|
||||
position_setpoint_triplet.current.yaw : NAN;
|
||||
_surface_vehicle_position_setpoint_pub.publish(surface_vehicle_position_setpoint);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
#include <px4_platform_common/module_params.h>
|
||||
|
||||
// Libraries
|
||||
#include <lib/rover_control/RoverControl.hpp>
|
||||
#include <lib/surface_vehicle_control/SurfaceVehicleControl.hpp>
|
||||
#include <math.h>
|
||||
|
||||
// uORB includes
|
||||
@@ -45,7 +45,7 @@
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/topics/vehicle_local_position.h>
|
||||
#include <uORB/topics/position_setpoint_triplet.h>
|
||||
#include <uORB/topics/rover_position_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_position_setpoint.h>
|
||||
|
||||
/**
|
||||
* @brief Class for Mecanum auto mode.
|
||||
@@ -61,7 +61,7 @@ public:
|
||||
~MecanumAutoMode() = default;
|
||||
|
||||
/**
|
||||
* @brief Generate and publish roverPositionSetpoint from positionSetpointTriplet.
|
||||
* @brief Generate and publish SurfaceVehiclePositionSetpoint from positionSetpointTriplet.
|
||||
*/
|
||||
void autoControl();
|
||||
|
||||
@@ -90,10 +90,10 @@ private:
|
||||
uORB::Subscription _position_setpoint_triplet_sub{ORB_ID(position_setpoint_triplet)};
|
||||
|
||||
// uORB publications
|
||||
uORB::Publication<rover_position_setpoint_s> _rover_position_setpoint_pub{ORB_ID(rover_position_setpoint)};
|
||||
uORB::Publication<surface_vehicle_position_setpoint_s> _surface_vehicle_position_setpoint_pub{ORB_ID(surface_vehicle_position_setpoint)};
|
||||
|
||||
DEFINE_PARAMETERS(
|
||||
(ParamFloat<px4::params::RO_SPEED_LIM>) _param_ro_speed_limit,
|
||||
(ParamFloat<px4::params::RO_SPEED_RED>) _param_ro_speed_red
|
||||
(ParamFloat<px4::params::SV_SPEED_LIM>) _param_sv_speed_limit,
|
||||
(ParamFloat<px4::params::SV_SPEED_RED>) _param_sv_speed_red
|
||||
)
|
||||
};
|
||||
|
||||
+81
-81
@@ -38,50 +38,50 @@ using namespace time_literals;
|
||||
MecanumManualMode::MecanumManualMode(ModuleParams *parent) : ModuleParams(parent)
|
||||
{
|
||||
updateParams();
|
||||
_rover_throttle_setpoint_pub.advertise();
|
||||
_rover_steering_setpoint_pub.advertise();
|
||||
_rover_rate_setpoint_pub.advertise();
|
||||
_rover_attitude_setpoint_pub.advertise();
|
||||
_rover_speed_setpoint_pub.advertise();
|
||||
_rover_position_setpoint_pub.advertise();
|
||||
_surface_vehicle_throttle_setpoint_pub.advertise();
|
||||
_surface_vehicle_steering_setpoint_pub.advertise();
|
||||
_surface_vehicle_rate_setpoint_pub.advertise();
|
||||
_surface_vehicle_attitude_setpoint_pub.advertise();
|
||||
_surface_vehicle_speed_setpoint_pub.advertise();
|
||||
_surface_vehicle_position_setpoint_pub.advertise();
|
||||
}
|
||||
|
||||
void MecanumManualMode::updateParams()
|
||||
{
|
||||
ModuleParams::updateParams();
|
||||
_max_yaw_rate = _param_ro_yaw_rate_limit.get() * M_DEG_TO_RAD_F;
|
||||
_max_yaw_rate = _param_sv_yaw_rate_limit.get() * M_DEG_TO_RAD_F;
|
||||
}
|
||||
|
||||
void MecanumManualMode::manual()
|
||||
{
|
||||
manual_control_setpoint_s manual_control_setpoint{};
|
||||
_manual_control_setpoint_sub.copy(&manual_control_setpoint);
|
||||
rover_steering_setpoint_s rover_steering_setpoint{};
|
||||
rover_steering_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_steering_setpoint.normalized_steering_setpoint = _param_rm_yaw_stk_gain.get() * math::superexpo<float>
|
||||
(manual_control_setpoint.yaw, _param_ro_yaw_expo.get(), _param_ro_yaw_supexpo.get());
|
||||
_rover_steering_setpoint_pub.publish(rover_steering_setpoint);
|
||||
rover_throttle_setpoint_s rover_throttle_setpoint{};
|
||||
rover_throttle_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_throttle_setpoint.throttle_body_x = manual_control_setpoint.throttle;
|
||||
rover_throttle_setpoint.throttle_body_y = manual_control_setpoint.roll;
|
||||
_rover_throttle_setpoint_pub.publish(rover_throttle_setpoint);
|
||||
surface_vehicle_steering_setpoint_s surface_vehicle_steering_setpoint{};
|
||||
surface_vehicle_steering_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_steering_setpoint.normalized_steering_setpoint = _param_rm_yaw_stk_gain.get() * math::superexpo<float>
|
||||
(manual_control_setpoint.yaw, _param_sv_yaw_expo.get(), _param_sv_yaw_supexpo.get());
|
||||
_surface_vehicle_steering_setpoint_pub.publish(surface_vehicle_steering_setpoint);
|
||||
surface_vehicle_throttle_setpoint_s surface_vehicle_throttle_setpoint{};
|
||||
surface_vehicle_throttle_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_throttle_setpoint.throttle_body_x = manual_control_setpoint.throttle;
|
||||
surface_vehicle_throttle_setpoint.throttle_body_y = manual_control_setpoint.roll;
|
||||
_surface_vehicle_throttle_setpoint_pub.publish(surface_vehicle_throttle_setpoint);
|
||||
}
|
||||
|
||||
void MecanumManualMode::acro()
|
||||
{
|
||||
manual_control_setpoint_s manual_control_setpoint{};
|
||||
_manual_control_setpoint_sub.copy(&manual_control_setpoint);
|
||||
rover_throttle_setpoint_s rover_throttle_setpoint{};
|
||||
rover_throttle_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_throttle_setpoint.throttle_body_x = manual_control_setpoint.throttle;
|
||||
rover_throttle_setpoint.throttle_body_y = manual_control_setpoint.roll;
|
||||
_rover_throttle_setpoint_pub.publish(rover_throttle_setpoint);
|
||||
rover_rate_setpoint_s rover_rate_setpoint{};
|
||||
rover_rate_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_rate_setpoint.yaw_rate_setpoint = _max_yaw_rate * math::superexpo<float>(manual_control_setpoint.yaw,
|
||||
_param_ro_yaw_expo.get(), _param_ro_yaw_supexpo.get());
|
||||
_rover_rate_setpoint_pub.publish(rover_rate_setpoint);
|
||||
surface_vehicle_throttle_setpoint_s surface_vehicle_throttle_setpoint{};
|
||||
surface_vehicle_throttle_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_throttle_setpoint.throttle_body_x = manual_control_setpoint.throttle;
|
||||
surface_vehicle_throttle_setpoint.throttle_body_y = manual_control_setpoint.roll;
|
||||
_surface_vehicle_throttle_setpoint_pub.publish(surface_vehicle_throttle_setpoint);
|
||||
surface_vehicle_rate_setpoint_s surface_vehicle_rate_setpoint{};
|
||||
surface_vehicle_rate_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_rate_setpoint.yaw_rate_setpoint = _max_yaw_rate * math::superexpo<float>(manual_control_setpoint.yaw,
|
||||
_param_sv_yaw_expo.get(), _param_sv_yaw_supexpo.get());
|
||||
_surface_vehicle_rate_setpoint_pub.publish(surface_vehicle_rate_setpoint);
|
||||
}
|
||||
|
||||
void MecanumManualMode::stab()
|
||||
@@ -95,37 +95,37 @@ void MecanumManualMode::stab()
|
||||
|
||||
manual_control_setpoint_s manual_control_setpoint{};
|
||||
_manual_control_setpoint_sub.copy(&manual_control_setpoint);
|
||||
rover_throttle_setpoint_s rover_throttle_setpoint{};
|
||||
rover_throttle_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_throttle_setpoint.throttle_body_x = manual_control_setpoint.throttle;
|
||||
rover_throttle_setpoint.throttle_body_y = manual_control_setpoint.roll;
|
||||
_rover_throttle_setpoint_pub.publish(rover_throttle_setpoint);
|
||||
surface_vehicle_throttle_setpoint_s surface_vehicle_throttle_setpoint{};
|
||||
surface_vehicle_throttle_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_throttle_setpoint.throttle_body_x = manual_control_setpoint.throttle;
|
||||
surface_vehicle_throttle_setpoint.throttle_body_y = manual_control_setpoint.roll;
|
||||
_surface_vehicle_throttle_setpoint_pub.publish(surface_vehicle_throttle_setpoint);
|
||||
|
||||
if (fabsf(manual_control_setpoint.yaw) > FLT_EPSILON) {
|
||||
_stab_yaw_setpoint = NAN;
|
||||
|
||||
// Rate control
|
||||
rover_rate_setpoint_s rover_rate_setpoint{};
|
||||
rover_rate_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_rate_setpoint.yaw_rate_setpoint = _max_yaw_rate * math::superexpo<float>(math::deadzone(
|
||||
manual_control_setpoint.yaw, _param_ro_yaw_stick_dz.get()), _param_ro_yaw_expo.get(), _param_ro_yaw_supexpo.get());
|
||||
_rover_rate_setpoint_pub.publish(rover_rate_setpoint);
|
||||
surface_vehicle_rate_setpoint_s surface_vehicle_rate_setpoint{};
|
||||
surface_vehicle_rate_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_rate_setpoint.yaw_rate_setpoint = _max_yaw_rate * math::superexpo<float>(math::deadzone(
|
||||
manual_control_setpoint.yaw, _param_sv_yaw_stick_dz.get()), _param_sv_yaw_expo.get(), _param_sv_yaw_supexpo.get());
|
||||
_surface_vehicle_rate_setpoint_pub.publish(surface_vehicle_rate_setpoint);
|
||||
|
||||
// Set uncontrolled setpoint invalid
|
||||
rover_attitude_setpoint_s rover_attitude_setpoint{};
|
||||
rover_attitude_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_attitude_setpoint.yaw_setpoint = NAN;
|
||||
_rover_attitude_setpoint_pub.publish(rover_attitude_setpoint);
|
||||
surface_vehicle_attitude_setpoint_s surface_vehicle_attitude_setpoint{};
|
||||
surface_vehicle_attitude_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_attitude_setpoint.yaw_setpoint = NAN;
|
||||
_surface_vehicle_attitude_setpoint_pub.publish(surface_vehicle_attitude_setpoint);
|
||||
|
||||
} else { // Heading control
|
||||
if (!PX4_ISFINITE(_stab_yaw_setpoint)) {
|
||||
_stab_yaw_setpoint = _vehicle_yaw;
|
||||
}
|
||||
|
||||
rover_attitude_setpoint_s rover_attitude_setpoint{};
|
||||
rover_attitude_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_attitude_setpoint.yaw_setpoint = _stab_yaw_setpoint;
|
||||
_rover_attitude_setpoint_pub.publish(rover_attitude_setpoint);
|
||||
surface_vehicle_attitude_setpoint_s surface_vehicle_attitude_setpoint{};
|
||||
surface_vehicle_attitude_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_attitude_setpoint.yaw_setpoint = _stab_yaw_setpoint;
|
||||
_surface_vehicle_attitude_setpoint_pub.publish(surface_vehicle_attitude_setpoint);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,44 +149,44 @@ void MecanumManualMode::position()
|
||||
|
||||
Vector3f velocity_setpoint_body{};
|
||||
velocity_setpoint_body(0) = math::interpolate<float>(manual_control_setpoint.throttle,
|
||||
-1.f, 1.f, -_param_ro_speed_limit.get(), _param_ro_speed_limit.get());
|
||||
-1.f, 1.f, -_param_sv_speed_limit.get(), _param_sv_speed_limit.get());
|
||||
velocity_setpoint_body(1) = math::interpolate<float>(manual_control_setpoint.roll,
|
||||
-1.f, 1.f, -_param_ro_speed_limit.get(), _param_ro_speed_limit.get());
|
||||
-1.f, 1.f, -_param_sv_speed_limit.get(), _param_sv_speed_limit.get());
|
||||
velocity_setpoint_body(2) = 0.f;
|
||||
|
||||
if (fabsf(manual_control_setpoint.yaw) > FLT_EPSILON || velocity_setpoint_body.norm() < FLT_EPSILON) {
|
||||
_pos_ctl_yaw_setpoint = NAN;
|
||||
|
||||
// Speed control
|
||||
rover_speed_setpoint_s rover_speed_setpoint{};
|
||||
rover_speed_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_speed_setpoint.speed_body_x = velocity_setpoint_body(0);
|
||||
rover_speed_setpoint.speed_body_y = velocity_setpoint_body(1);
|
||||
_rover_speed_setpoint_pub.publish(rover_speed_setpoint);
|
||||
surface_vehicle_speed_setpoint_s surface_vehicle_speed_setpoint{};
|
||||
surface_vehicle_speed_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_speed_setpoint.speed_body_x = velocity_setpoint_body(0);
|
||||
surface_vehicle_speed_setpoint.speed_body_y = velocity_setpoint_body(1);
|
||||
_surface_vehicle_speed_setpoint_pub.publish(surface_vehicle_speed_setpoint);
|
||||
|
||||
// Rate control
|
||||
rover_rate_setpoint_s rover_rate_setpoint{};
|
||||
rover_rate_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_rate_setpoint.yaw_rate_setpoint = _max_yaw_rate * math::superexpo<float>(math::deadzone(
|
||||
manual_control_setpoint.yaw, _param_ro_yaw_stick_dz.get()), _param_ro_yaw_expo.get(), _param_ro_yaw_supexpo.get());
|
||||
_rover_rate_setpoint_pub.publish(rover_rate_setpoint);
|
||||
surface_vehicle_rate_setpoint_s surface_vehicle_rate_setpoint{};
|
||||
surface_vehicle_rate_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_rate_setpoint.yaw_rate_setpoint = _max_yaw_rate * math::superexpo<float>(math::deadzone(
|
||||
manual_control_setpoint.yaw, _param_sv_yaw_stick_dz.get()), _param_sv_yaw_expo.get(), _param_sv_yaw_supexpo.get());
|
||||
_surface_vehicle_rate_setpoint_pub.publish(surface_vehicle_rate_setpoint);
|
||||
|
||||
// Set uncontrolled setpoints invalid
|
||||
rover_attitude_setpoint_s rover_attitude_setpoint{};
|
||||
rover_attitude_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_attitude_setpoint.yaw_setpoint = NAN;
|
||||
_rover_attitude_setpoint_pub.publish(rover_attitude_setpoint);
|
||||
surface_vehicle_attitude_setpoint_s surface_vehicle_attitude_setpoint{};
|
||||
surface_vehicle_attitude_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_attitude_setpoint.yaw_setpoint = NAN;
|
||||
_surface_vehicle_attitude_setpoint_pub.publish(surface_vehicle_attitude_setpoint);
|
||||
|
||||
rover_position_setpoint_s rover_position_setpoint{};
|
||||
rover_position_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_position_setpoint.position_ned[0] = NAN;
|
||||
rover_position_setpoint.position_ned[1] = NAN;
|
||||
rover_position_setpoint.start_ned[0] = NAN;
|
||||
rover_position_setpoint.start_ned[1] = NAN;
|
||||
rover_position_setpoint.arrival_speed = NAN;
|
||||
rover_position_setpoint.cruising_speed = NAN;
|
||||
rover_position_setpoint.yaw = NAN;
|
||||
_rover_position_setpoint_pub.publish(rover_position_setpoint);
|
||||
surface_vehicle_position_setpoint_s surface_vehicle_position_setpoint{};
|
||||
surface_vehicle_position_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_position_setpoint.position_ned[0] = NAN;
|
||||
surface_vehicle_position_setpoint.position_ned[1] = NAN;
|
||||
surface_vehicle_position_setpoint.start_ned[0] = NAN;
|
||||
surface_vehicle_position_setpoint.start_ned[1] = NAN;
|
||||
surface_vehicle_position_setpoint.arrival_speed = NAN;
|
||||
surface_vehicle_position_setpoint.cruising_speed = NAN;
|
||||
surface_vehicle_position_setpoint.yaw = NAN;
|
||||
_surface_vehicle_position_setpoint_pub.publish(surface_vehicle_position_setpoint);
|
||||
|
||||
} else { // Course control
|
||||
const Vector3f velocity_setpoint_ned = _vehicle_attitude_quaternion.rotateVector(velocity_setpoint_body);
|
||||
@@ -210,16 +210,16 @@ void MecanumManualMode::position()
|
||||
const Vector2f start_to_curr_pos = _curr_pos_ned - _pos_ctl_start_position_ned;
|
||||
const float vector_scaling = fabsf(start_to_curr_pos * _pos_ctl_course_direction) + _param_pp_lookahd_max.get();
|
||||
const Vector2f target_waypoint_ned = _pos_ctl_start_position_ned + vector_scaling * _pos_ctl_course_direction;
|
||||
rover_position_setpoint_s rover_position_setpoint{};
|
||||
rover_position_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_position_setpoint.position_ned[0] = target_waypoint_ned(0);
|
||||
rover_position_setpoint.position_ned[1] = target_waypoint_ned(1);
|
||||
rover_position_setpoint.start_ned[0] = NAN;
|
||||
rover_position_setpoint.start_ned[1] = NAN;
|
||||
rover_position_setpoint.arrival_speed = NAN;
|
||||
rover_position_setpoint.cruising_speed = velocity_setpoint_ned.norm();
|
||||
rover_position_setpoint.yaw = _pos_ctl_yaw_setpoint;
|
||||
_rover_position_setpoint_pub.publish(rover_position_setpoint);
|
||||
surface_vehicle_position_setpoint_s surface_vehicle_position_setpoint{};
|
||||
surface_vehicle_position_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_position_setpoint.position_ned[0] = target_waypoint_ned(0);
|
||||
surface_vehicle_position_setpoint.position_ned[1] = target_waypoint_ned(1);
|
||||
surface_vehicle_position_setpoint.start_ned[0] = NAN;
|
||||
surface_vehicle_position_setpoint.start_ned[1] = NAN;
|
||||
surface_vehicle_position_setpoint.arrival_speed = NAN;
|
||||
surface_vehicle_position_setpoint.cruising_speed = velocity_setpoint_ned.norm();
|
||||
surface_vehicle_position_setpoint.yaw = _pos_ctl_yaw_setpoint;
|
||||
_surface_vehicle_position_setpoint_pub.publish(surface_vehicle_position_setpoint);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+19
-19
@@ -46,12 +46,12 @@
|
||||
#include <uORB/topics/manual_control_setpoint.h>
|
||||
#include <uORB/topics/vehicle_attitude.h>
|
||||
#include <uORB/topics/vehicle_local_position.h>
|
||||
#include <uORB/topics/rover_throttle_setpoint.h>
|
||||
#include <uORB/topics/rover_steering_setpoint.h>
|
||||
#include <uORB/topics/rover_rate_setpoint.h>
|
||||
#include <uORB/topics/rover_attitude_setpoint.h>
|
||||
#include <uORB/topics/rover_speed_setpoint.h>
|
||||
#include <uORB/topics/rover_position_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_throttle_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_steering_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_rate_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_attitude_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_speed_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_position_setpoint.h>
|
||||
|
||||
using namespace matrix;
|
||||
|
||||
@@ -69,12 +69,12 @@ public:
|
||||
~MecanumManualMode() = default;
|
||||
|
||||
/**
|
||||
* @brief Publish roverThrottleSetpoint and roverSteeringSetpoint from manualControlSetpoint.
|
||||
* @brief Publish SurfaceVehicleThrottleSetpoint and SurfaceVehicleSteeringSetpoint from manualControlSetpoint.
|
||||
*/
|
||||
void manual();
|
||||
|
||||
/**
|
||||
* @brief Generate and publish roverThrottleSetpoint/RoverRateSetpoint from manualControlSetpoint.
|
||||
* @brief Generate and publish SurfaceVehicleThrottleSetpoint/SurfaceVehicleRateSetpoint from manualControlSetpoint.
|
||||
*/
|
||||
void acro();
|
||||
|
||||
@@ -106,12 +106,12 @@ private:
|
||||
uORB::Subscription _vehicle_local_position_sub{ORB_ID(vehicle_local_position)};
|
||||
|
||||
// uORB publications
|
||||
uORB::Publication<rover_throttle_setpoint_s> _rover_throttle_setpoint_pub{ORB_ID(rover_throttle_setpoint)};
|
||||
uORB::Publication<rover_steering_setpoint_s> _rover_steering_setpoint_pub{ORB_ID(rover_steering_setpoint)};
|
||||
uORB::Publication<rover_rate_setpoint_s> _rover_rate_setpoint_pub{ORB_ID(rover_rate_setpoint)};
|
||||
uORB::Publication<rover_attitude_setpoint_s> _rover_attitude_setpoint_pub{ORB_ID(rover_attitude_setpoint)};
|
||||
uORB::Publication<rover_speed_setpoint_s> _rover_speed_setpoint_pub{ORB_ID(rover_speed_setpoint)};
|
||||
uORB::Publication<rover_position_setpoint_s> _rover_position_setpoint_pub{ORB_ID(rover_position_setpoint)};
|
||||
uORB::Publication<surface_vehicle_throttle_setpoint_s> _surface_vehicle_throttle_setpoint_pub{ORB_ID(surface_vehicle_throttle_setpoint)};
|
||||
uORB::Publication<surface_vehicle_steering_setpoint_s> _surface_vehicle_steering_setpoint_pub{ORB_ID(surface_vehicle_steering_setpoint)};
|
||||
uORB::Publication<surface_vehicle_rate_setpoint_s> _surface_vehicle_rate_setpoint_pub{ORB_ID(surface_vehicle_rate_setpoint)};
|
||||
uORB::Publication<surface_vehicle_attitude_setpoint_s> _surface_vehicle_attitude_setpoint_pub{ORB_ID(surface_vehicle_attitude_setpoint)};
|
||||
uORB::Publication<surface_vehicle_speed_setpoint_s> _surface_vehicle_speed_setpoint_pub{ORB_ID(surface_vehicle_speed_setpoint)};
|
||||
uORB::Publication<surface_vehicle_position_setpoint_s> _surface_vehicle_position_setpoint_pub{ORB_ID(surface_vehicle_position_setpoint)};
|
||||
|
||||
// Variables
|
||||
Vector2f _pos_ctl_course_direction{NAN, NAN};
|
||||
@@ -124,13 +124,13 @@ private:
|
||||
float _max_yaw_rate{NAN};
|
||||
|
||||
DEFINE_PARAMETERS(
|
||||
(ParamFloat<px4::params::RO_YAW_RATE_LIM>) _param_ro_yaw_rate_limit,
|
||||
(ParamFloat<px4::params::RO_YAW_STICK_DZ>) _param_ro_yaw_stick_dz,
|
||||
(ParamFloat<px4::params::RO_YAW_EXPO>) _param_ro_yaw_expo,
|
||||
(ParamFloat<px4::params::RO_YAW_SUPEXPO>) _param_ro_yaw_supexpo,
|
||||
(ParamFloat<px4::params::SV_YAW_RATE_LIM>) _param_sv_yaw_rate_limit,
|
||||
(ParamFloat<px4::params::SV_YAW_STICK_DZ>) _param_sv_yaw_stick_dz,
|
||||
(ParamFloat<px4::params::SV_YAW_EXPO>) _param_sv_yaw_expo,
|
||||
(ParamFloat<px4::params::SV_YAW_SUPEXPO>) _param_sv_yaw_supexpo,
|
||||
(ParamFloat<px4::params::RM_YAW_STK_GAIN>) _param_rm_yaw_stk_gain,
|
||||
(ParamFloat<px4::params::PP_LOOKAHD_MAX>) _param_pp_lookahd_max,
|
||||
(ParamFloat<px4::params::RO_SPEED_LIM>) _param_ro_speed_limit,
|
||||
(ParamFloat<px4::params::SV_SPEED_LIM>) _param_sv_speed_limit,
|
||||
(ParamFloat<px4::params::RM_COURSE_CTL_TH>) _param_rm_course_ctl_th
|
||||
)
|
||||
};
|
||||
|
||||
+31
-31
@@ -38,10 +38,10 @@ using namespace time_literals;
|
||||
MecanumOffboardMode::MecanumOffboardMode(ModuleParams *parent) : ModuleParams(parent)
|
||||
{
|
||||
updateParams();
|
||||
_rover_rate_setpoint_pub.advertise();
|
||||
_rover_attitude_setpoint_pub.advertise();
|
||||
_rover_speed_setpoint_pub.advertise();
|
||||
_rover_position_setpoint_pub.advertise();
|
||||
_surface_vehicle_rate_setpoint_pub.advertise();
|
||||
_surface_vehicle_attitude_setpoint_pub.advertise();
|
||||
_surface_vehicle_speed_setpoint_pub.advertise();
|
||||
_surface_vehicle_position_setpoint_pub.advertise();
|
||||
}
|
||||
|
||||
void MecanumOffboardMode::updateParams()
|
||||
@@ -58,16 +58,16 @@ void MecanumOffboardMode::offboardControl()
|
||||
_trajectory_setpoint_sub.copy(&trajectory_setpoint);
|
||||
|
||||
if (offboard_control_mode.position) {
|
||||
rover_position_setpoint_s rover_position_setpoint{};
|
||||
rover_position_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_position_setpoint.position_ned[0] = trajectory_setpoint.position[0];
|
||||
rover_position_setpoint.position_ned[1] = trajectory_setpoint.position[1];
|
||||
rover_position_setpoint.start_ned[0] = NAN;
|
||||
rover_position_setpoint.start_ned[1] = NAN;
|
||||
rover_position_setpoint.cruising_speed = NAN;
|
||||
rover_position_setpoint.arrival_speed = NAN;
|
||||
rover_position_setpoint.yaw = NAN;
|
||||
_rover_position_setpoint_pub.publish(rover_position_setpoint);
|
||||
surface_vehicle_position_setpoint_s surface_vehicle_position_setpoint{};
|
||||
surface_vehicle_position_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_position_setpoint.position_ned[0] = trajectory_setpoint.position[0];
|
||||
surface_vehicle_position_setpoint.position_ned[1] = trajectory_setpoint.position[1];
|
||||
surface_vehicle_position_setpoint.start_ned[0] = NAN;
|
||||
surface_vehicle_position_setpoint.start_ned[1] = NAN;
|
||||
surface_vehicle_position_setpoint.cruising_speed = NAN;
|
||||
surface_vehicle_position_setpoint.arrival_speed = NAN;
|
||||
surface_vehicle_position_setpoint.yaw = NAN;
|
||||
_surface_vehicle_position_setpoint_pub.publish(surface_vehicle_position_setpoint);
|
||||
|
||||
} else if (offboard_control_mode.velocity) {
|
||||
if (_vehicle_attitude_sub.updated()) {
|
||||
@@ -78,26 +78,26 @@ void MecanumOffboardMode::offboardControl()
|
||||
|
||||
const Vector3f velocity_ned(trajectory_setpoint.velocity[0], trajectory_setpoint.velocity[1], 0.f);
|
||||
const Vector3f velocity_in_body_frame = _vehicle_attitude_quaternion.rotateVectorInverse(velocity_ned);
|
||||
rover_speed_setpoint_s rover_speed_setpoint{};
|
||||
rover_speed_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_speed_setpoint.speed_body_x = velocity_in_body_frame(0);
|
||||
rover_speed_setpoint.speed_body_y = velocity_in_body_frame(1);
|
||||
_rover_speed_setpoint_pub.publish(rover_speed_setpoint);
|
||||
rover_attitude_setpoint_s rover_attitude_setpoint{};
|
||||
rover_attitude_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_attitude_setpoint.yaw_setpoint = atan2f(velocity_ned(1), velocity_ned(0));
|
||||
_rover_attitude_setpoint_pub.publish(rover_attitude_setpoint);
|
||||
surface_vehicle_speed_setpoint_s surface_vehicle_speed_setpoint{};
|
||||
surface_vehicle_speed_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_speed_setpoint.speed_body_x = velocity_in_body_frame(0);
|
||||
surface_vehicle_speed_setpoint.speed_body_y = velocity_in_body_frame(1);
|
||||
_surface_vehicle_speed_setpoint_pub.publish(surface_vehicle_speed_setpoint);
|
||||
surface_vehicle_attitude_setpoint_s surface_vehicle_attitude_setpoint{};
|
||||
surface_vehicle_attitude_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_attitude_setpoint.yaw_setpoint = atan2f(velocity_ned(1), velocity_ned(0));
|
||||
_surface_vehicle_attitude_setpoint_pub.publish(surface_vehicle_attitude_setpoint);
|
||||
|
||||
} else if (offboard_control_mode.attitude) {
|
||||
rover_attitude_setpoint_s rover_attitude_setpoint{};
|
||||
rover_attitude_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_attitude_setpoint.yaw_setpoint = trajectory_setpoint.yaw;
|
||||
_rover_attitude_setpoint_pub.publish(rover_attitude_setpoint);
|
||||
surface_vehicle_attitude_setpoint_s surface_vehicle_attitude_setpoint{};
|
||||
surface_vehicle_attitude_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_attitude_setpoint.yaw_setpoint = trajectory_setpoint.yaw;
|
||||
_surface_vehicle_attitude_setpoint_pub.publish(surface_vehicle_attitude_setpoint);
|
||||
|
||||
} else if (offboard_control_mode.body_rate) {
|
||||
rover_rate_setpoint_s rover_rate_setpoint{};
|
||||
rover_rate_setpoint.timestamp = hrt_absolute_time();
|
||||
rover_rate_setpoint.yaw_rate_setpoint = trajectory_setpoint.yawspeed;
|
||||
_rover_rate_setpoint_pub.publish(rover_rate_setpoint);
|
||||
surface_vehicle_rate_setpoint_s surface_vehicle_rate_setpoint{};
|
||||
surface_vehicle_rate_setpoint.timestamp = hrt_absolute_time();
|
||||
surface_vehicle_rate_setpoint.yaw_rate_setpoint = trajectory_setpoint.yawspeed;
|
||||
_surface_vehicle_rate_setpoint_pub.publish(surface_vehicle_rate_setpoint);
|
||||
}
|
||||
}
|
||||
|
||||
+8
-8
@@ -43,10 +43,10 @@
|
||||
// uORB includes
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/topics/rover_rate_setpoint.h>
|
||||
#include <uORB/topics/rover_attitude_setpoint.h>
|
||||
#include <uORB/topics/rover_speed_setpoint.h>
|
||||
#include <uORB/topics/rover_position_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_rate_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_attitude_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_speed_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_position_setpoint.h>
|
||||
#include <uORB/topics/offboard_control_mode.h>
|
||||
#include <uORB/topics/trajectory_setpoint.h>
|
||||
#include <uORB/topics/vehicle_attitude.h>
|
||||
@@ -84,10 +84,10 @@ private:
|
||||
uORB::Subscription _vehicle_attitude_sub{ORB_ID(vehicle_attitude)};
|
||||
|
||||
// uORB publications
|
||||
uORB::Publication<rover_rate_setpoint_s> _rover_rate_setpoint_pub{ORB_ID(rover_rate_setpoint)};
|
||||
uORB::Publication<rover_attitude_setpoint_s> _rover_attitude_setpoint_pub{ORB_ID(rover_attitude_setpoint)};
|
||||
uORB::Publication<rover_speed_setpoint_s> _rover_speed_setpoint_pub{ORB_ID(rover_speed_setpoint)};
|
||||
uORB::Publication<rover_position_setpoint_s> _rover_position_setpoint_pub{ORB_ID(rover_position_setpoint)};
|
||||
uORB::Publication<surface_vehicle_rate_setpoint_s> _surface_vehicle_rate_setpoint_pub{ORB_ID(surface_vehicle_rate_setpoint)};
|
||||
uORB::Publication<surface_vehicle_attitude_setpoint_s> _surface_vehicle_attitude_setpoint_pub{ORB_ID(surface_vehicle_attitude_setpoint)};
|
||||
uORB::Publication<surface_vehicle_speed_setpoint_s> _surface_vehicle_speed_setpoint_pub{ORB_ID(surface_vehicle_speed_setpoint)};
|
||||
uORB::Publication<surface_vehicle_position_setpoint_s> _surface_vehicle_position_setpoint_pub{ORB_ID(surface_vehicle_position_setpoint)};
|
||||
|
||||
Quatf _vehicle_attitude_quaternion{};
|
||||
};
|
||||
|
||||
@@ -37,9 +37,9 @@ using namespace time_literals;
|
||||
|
||||
MecanumPosControl::MecanumPosControl(ModuleParams *parent) : ModuleParams(parent)
|
||||
{
|
||||
_rover_speed_setpoint_pub.advertise();
|
||||
_surface_vehicle_speed_setpoint_pub.advertise();
|
||||
_pure_pursuit_status_pub.advertise();
|
||||
_rover_attitude_setpoint_pub.advertise();
|
||||
_surface_vehicle_attitude_setpoint_pub.advertise();
|
||||
|
||||
updateParams();
|
||||
}
|
||||
@@ -47,7 +47,7 @@ MecanumPosControl::MecanumPosControl(ModuleParams *parent) : ModuleParams(parent
|
||||
void MecanumPosControl::updateParams()
|
||||
{
|
||||
ModuleParams::updateParams();
|
||||
_max_yaw_rate = _param_ro_yaw_rate_limit.get() * M_DEG_TO_RAD_F;
|
||||
_max_yaw_rate = _param_sv_yaw_rate_limit.get() * M_DEG_TO_RAD_F;
|
||||
|
||||
}
|
||||
|
||||
@@ -68,8 +68,8 @@ void MecanumPosControl::updatePosControl()
|
||||
|
||||
if (distance_to_target > _param_nav_acc_rad.get() || _arrival_speed > FLT_EPSILON) {
|
||||
|
||||
float speed_setpoint = math::trajectory::computeMaxSpeedFromDistance(_param_ro_jerk_limit.get(),
|
||||
_param_ro_decel_limit.get(), distance_to_target, fabsf(_arrival_speed));
|
||||
float speed_setpoint = math::trajectory::computeMaxSpeedFromDistance(_param_sv_jerk_limit.get(),
|
||||
_param_sv_decel_limit.get(), distance_to_target, fabsf(_arrival_speed));
|
||||
speed_setpoint = math::min(speed_setpoint, _cruising_speed);
|
||||
|
||||
pure_pursuit_status_s pure_pursuit_status{};
|
||||
@@ -84,26 +84,26 @@ void MecanumPosControl::updatePosControl()
|
||||
speed_setpoint * sinf(bearing_setpoint), 0.f);
|
||||
const Vector3f velocity_in_body_frame = _vehicle_attitude_quaternion.rotateVectorInverse(velocity_in_local_frame);
|
||||
|
||||
rover_speed_setpoint_s rover_speed_setpoint{};
|
||||
rover_speed_setpoint.timestamp = timestamp;
|
||||
rover_speed_setpoint.speed_body_x = velocity_in_body_frame(0);
|
||||
rover_speed_setpoint.speed_body_y = velocity_in_body_frame(1);
|
||||
_rover_speed_setpoint_pub.publish(rover_speed_setpoint);
|
||||
rover_attitude_setpoint_s rover_attitude_setpoint{};
|
||||
rover_attitude_setpoint.timestamp = timestamp;
|
||||
rover_attitude_setpoint.yaw_setpoint = _yaw_setpoint;
|
||||
_rover_attitude_setpoint_pub.publish(rover_attitude_setpoint);
|
||||
surface_vehicle_speed_setpoint_s surface_vehicle_speed_setpoint{};
|
||||
surface_vehicle_speed_setpoint.timestamp = timestamp;
|
||||
surface_vehicle_speed_setpoint.speed_body_x = velocity_in_body_frame(0);
|
||||
surface_vehicle_speed_setpoint.speed_body_y = velocity_in_body_frame(1);
|
||||
_surface_vehicle_speed_setpoint_pub.publish(surface_vehicle_speed_setpoint);
|
||||
surface_vehicle_attitude_setpoint_s surface_vehicle_attitude_setpoint{};
|
||||
surface_vehicle_attitude_setpoint.timestamp = timestamp;
|
||||
surface_vehicle_attitude_setpoint.yaw_setpoint = _yaw_setpoint;
|
||||
_surface_vehicle_attitude_setpoint_pub.publish(surface_vehicle_attitude_setpoint);
|
||||
|
||||
} else {
|
||||
rover_speed_setpoint_s rover_speed_setpoint{};
|
||||
rover_speed_setpoint.timestamp = timestamp;
|
||||
rover_speed_setpoint.speed_body_x = 0.f;
|
||||
rover_speed_setpoint.speed_body_y = 0.f;
|
||||
_rover_speed_setpoint_pub.publish(rover_speed_setpoint);
|
||||
rover_attitude_setpoint_s rover_attitude_setpoint{};
|
||||
rover_attitude_setpoint.timestamp = timestamp;
|
||||
rover_attitude_setpoint.yaw_setpoint = _vehicle_yaw;
|
||||
_rover_attitude_setpoint_pub.publish(rover_attitude_setpoint);
|
||||
surface_vehicle_speed_setpoint_s surface_vehicle_speed_setpoint{};
|
||||
surface_vehicle_speed_setpoint.timestamp = timestamp;
|
||||
surface_vehicle_speed_setpoint.speed_body_x = 0.f;
|
||||
surface_vehicle_speed_setpoint.speed_body_y = 0.f;
|
||||
_surface_vehicle_speed_setpoint_pub.publish(surface_vehicle_speed_setpoint);
|
||||
surface_vehicle_attitude_setpoint_s surface_vehicle_attitude_setpoint{};
|
||||
surface_vehicle_attitude_setpoint.timestamp = timestamp;
|
||||
surface_vehicle_attitude_setpoint.yaw_setpoint = _vehicle_yaw;
|
||||
_surface_vehicle_attitude_setpoint_pub.publish(surface_vehicle_attitude_setpoint);
|
||||
|
||||
if (!_stopped && fabsf(_vehicle_speed) < FLT_EPSILON) {
|
||||
_stopped = true;
|
||||
@@ -135,18 +135,21 @@ void MecanumPosControl::updateSubscriptions()
|
||||
Vector3f velocity_ned(vehicle_local_position.vx, vehicle_local_position.vy, vehicle_local_position.vz);
|
||||
Vector3f velocity_xyz = _vehicle_attitude_quaternion.rotateVectorInverse(velocity_ned);
|
||||
Vector2f velocity_2d = Vector2f(velocity_xyz(0), velocity_xyz(1));
|
||||
_vehicle_speed = velocity_2d.norm() > _param_ro_speed_th.get() ? sign(velocity_2d(0)) * velocity_2d.norm() : 0.f;
|
||||
_vehicle_speed = velocity_2d.norm() > _param_sv_speed_th.get() ? sign(velocity_2d(0)) * velocity_2d.norm() : 0.f;
|
||||
}
|
||||
|
||||
if (_rover_position_setpoint_sub.updated()) {
|
||||
rover_position_setpoint_s rover_position_setpoint;
|
||||
_rover_position_setpoint_sub.copy(&rover_position_setpoint);
|
||||
_start_ned = Vector2f(rover_position_setpoint.start_ned[0], rover_position_setpoint.start_ned[1]);
|
||||
if (_surface_vehicle_position_setpoint_sub.updated()) {
|
||||
surface_vehicle_position_setpoint_s surface_vehicle_position_setpoint;
|
||||
_surface_vehicle_position_setpoint_sub.copy(&surface_vehicle_position_setpoint);
|
||||
_start_ned = Vector2f(surface_vehicle_position_setpoint.start_ned[0], surface_vehicle_position_setpoint.start_ned[1]);
|
||||
_start_ned = _start_ned.isAllFinite() ? _start_ned : _curr_pos_ned;
|
||||
_arrival_speed = PX4_ISFINITE(rover_position_setpoint.arrival_speed) ? rover_position_setpoint.arrival_speed : 0.f;
|
||||
_cruising_speed = PX4_ISFINITE(rover_position_setpoint.cruising_speed) ? rover_position_setpoint.cruising_speed :
|
||||
_param_ro_speed_limit.get();
|
||||
_target_waypoint_ned = Vector2f(rover_position_setpoint.position_ned[0], rover_position_setpoint.position_ned[1]);
|
||||
_arrival_speed = PX4_ISFINITE(surface_vehicle_position_setpoint.arrival_speed) ?
|
||||
surface_vehicle_position_setpoint.arrival_speed : 0.f;
|
||||
_cruising_speed = PX4_ISFINITE(surface_vehicle_position_setpoint.cruising_speed) ?
|
||||
surface_vehicle_position_setpoint.cruising_speed :
|
||||
_param_sv_speed_limit.get();
|
||||
_target_waypoint_ned = Vector2f(surface_vehicle_position_setpoint.position_ned[0],
|
||||
surface_vehicle_position_setpoint.position_ned[1]);
|
||||
_stopped = false;
|
||||
}
|
||||
}
|
||||
@@ -155,15 +158,15 @@ bool MecanumPosControl::runSanityChecks()
|
||||
{
|
||||
bool ret = true;
|
||||
|
||||
if (_param_ro_yaw_rate_limit.get() < FLT_EPSILON) {
|
||||
if (_param_sv_yaw_rate_limit.get() < FLT_EPSILON) {
|
||||
ret = false;
|
||||
}
|
||||
|
||||
if (_param_ro_speed_limit.get() < FLT_EPSILON) {
|
||||
if (_param_sv_speed_limit.get() < FLT_EPSILON) {
|
||||
ret = false;
|
||||
}
|
||||
|
||||
if (_param_ro_max_thr_speed.get() < FLT_EPSILON && _param_ro_speed_p.get() < FLT_EPSILON) {
|
||||
if (_param_sv_max_thr_speed.get() < FLT_EPSILON && _param_sv_speed_p.get() < FLT_EPSILON) {
|
||||
ret = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,9 +46,9 @@
|
||||
// uORB includes
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/topics/rover_speed_setpoint.h>
|
||||
#include <uORB/topics/rover_attitude_setpoint.h>
|
||||
#include <uORB/topics/rover_position_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_speed_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_attitude_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_position_setpoint.h>
|
||||
#include <uORB/topics/vehicle_attitude.h>
|
||||
#include <uORB/topics/vehicle_local_position.h>
|
||||
#include <uORB/topics/pure_pursuit_status.h>
|
||||
@@ -69,7 +69,7 @@ public:
|
||||
~MecanumPosControl() = default;
|
||||
|
||||
/**
|
||||
* @brief Generate and publish roverSpeedSetpoint and roverAttitudeSetpoint from roverPositionSetpoint.
|
||||
* @brief Generate and publish SurfaceVehicleSpeedSetpoint and SurfaceVehicleAttitudeSetpoint from SurfaceVehiclePositionSetpoint.
|
||||
*/
|
||||
void updatePosControl();
|
||||
|
||||
@@ -82,7 +82,7 @@ public:
|
||||
/**
|
||||
* @brief Reset position controller.
|
||||
*/
|
||||
void reset() {_start_ned = Vector2f{NAN, NAN}; _target_waypoint_ned = Vector2f{NAN, NAN}; _arrival_speed = 0.f; _cruising_speed = _param_ro_speed_limit.get(); _stopped = false;};
|
||||
void reset() {_start_ned = Vector2f{NAN, NAN}; _target_waypoint_ned = Vector2f{NAN, NAN}; _arrival_speed = 0.f; _cruising_speed = _param_sv_speed_limit.get(); _stopped = false;};
|
||||
|
||||
protected:
|
||||
|
||||
@@ -101,12 +101,12 @@ private:
|
||||
// uORB subscriptions
|
||||
uORB::Subscription _vehicle_attitude_sub{ORB_ID(vehicle_attitude)};
|
||||
uORB::Subscription _vehicle_local_position_sub{ORB_ID(vehicle_local_position)};
|
||||
uORB::Subscription _rover_position_setpoint_sub{ORB_ID(rover_position_setpoint)};
|
||||
uORB::Subscription _surface_vehicle_position_setpoint_sub{ORB_ID(surface_vehicle_position_setpoint)};
|
||||
|
||||
// uORB publications
|
||||
uORB::Publication<rover_speed_setpoint_s> _rover_speed_setpoint_pub{ORB_ID(rover_speed_setpoint)};
|
||||
uORB::Publication<surface_vehicle_speed_setpoint_s> _surface_vehicle_speed_setpoint_pub{ORB_ID(surface_vehicle_speed_setpoint)};
|
||||
uORB::Publication<pure_pursuit_status_s> _pure_pursuit_status_pub{ORB_ID(pure_pursuit_status)};
|
||||
uORB::Publication<rover_attitude_setpoint_s> _rover_attitude_setpoint_pub{ORB_ID(rover_attitude_setpoint)};
|
||||
uORB::Publication<surface_vehicle_attitude_setpoint_s> _surface_vehicle_attitude_setpoint_pub{ORB_ID(surface_vehicle_attitude_setpoint)};
|
||||
|
||||
// Variables
|
||||
Quatf _vehicle_attitude_quaternion{};
|
||||
@@ -125,20 +125,20 @@ private:
|
||||
|
||||
DEFINE_PARAMETERS(
|
||||
(ParamFloat<px4::params::RM_COURSE_CTL_TH>) _param_rm_course_ctl_th,
|
||||
(ParamFloat<px4::params::RO_MAX_THR_SPEED>) _param_ro_max_thr_speed,
|
||||
(ParamFloat<px4::params::RO_SPEED_P>) _param_ro_speed_p,
|
||||
(ParamFloat<px4::params::RO_SPEED_I>) _param_ro_speed_i,
|
||||
(ParamFloat<px4::params::RO_YAW_STICK_DZ>) _param_ro_yaw_stick_dz,
|
||||
(ParamFloat<px4::params::RO_ACCEL_LIM>) _param_ro_accel_limit,
|
||||
(ParamFloat<px4::params::RO_DECEL_LIM>) _param_ro_decel_limit,
|
||||
(ParamFloat<px4::params::RO_JERK_LIM>) _param_ro_jerk_limit,
|
||||
(ParamFloat<px4::params::RO_SPEED_LIM>) _param_ro_speed_limit,
|
||||
(ParamFloat<px4::params::RO_SPEED_TH>) _param_ro_speed_th,
|
||||
(ParamFloat<px4::params::SV_MAX_THR_SPEED>) _param_sv_max_thr_speed,
|
||||
(ParamFloat<px4::params::SV_SPEED_P>) _param_sv_speed_p,
|
||||
(ParamFloat<px4::params::SV_SPEED_I>) _param_sv_speed_i,
|
||||
(ParamFloat<px4::params::SV_YAW_STICK_DZ>) _param_sv_yaw_stick_dz,
|
||||
(ParamFloat<px4::params::SV_ACCEL_LIM>) _param_sv_accel_limit,
|
||||
(ParamFloat<px4::params::SV_DECEL_LIM>) _param_sv_decel_limit,
|
||||
(ParamFloat<px4::params::SV_JERK_LIM>) _param_sv_jerk_limit,
|
||||
(ParamFloat<px4::params::SV_SPEED_LIM>) _param_sv_speed_limit,
|
||||
(ParamFloat<px4::params::SV_SPEED_TH>) _param_sv_speed_th,
|
||||
(ParamFloat<px4::params::PP_LOOKAHD_GAIN>) _param_pp_lookahd_gain,
|
||||
(ParamFloat<px4::params::PP_LOOKAHD_MAX>) _param_pp_lookahd_max,
|
||||
(ParamFloat<px4::params::PP_LOOKAHD_MIN>) _param_pp_lookahd_min,
|
||||
(ParamFloat<px4::params::RO_YAW_RATE_LIM>) _param_ro_yaw_rate_limit,
|
||||
(ParamFloat<px4::params::RO_YAW_P>) _param_ro_yaw_p,
|
||||
(ParamFloat<px4::params::SV_YAW_RATE_LIM>) _param_sv_yaw_rate_limit,
|
||||
(ParamFloat<px4::params::SV_YAW_P>) _param_sv_yaw_p,
|
||||
(ParamFloat<px4::params::NAV_ACC_RAD>) _param_nav_acc_rad
|
||||
)
|
||||
};
|
||||
|
||||
@@ -37,8 +37,8 @@ using namespace time_literals;
|
||||
|
||||
MecanumRateControl::MecanumRateControl(ModuleParams *parent) : ModuleParams(parent)
|
||||
{
|
||||
_rover_steering_setpoint_pub.advertise();
|
||||
_rover_rate_status_pub.advertise();
|
||||
_surface_vehicle_steering_setpoint_pub.advertise();
|
||||
_surface_vehicle_rate_status_pub.advertise();
|
||||
updateParams();
|
||||
}
|
||||
|
||||
@@ -47,12 +47,12 @@ void MecanumRateControl::updateParams()
|
||||
ModuleParams::updateParams();
|
||||
|
||||
// Set up PID controller
|
||||
_pid_yaw_rate.setGains(_param_ro_yaw_rate_p.get(), _param_ro_yaw_rate_i.get(), 0.f);
|
||||
_pid_yaw_rate.setGains(_param_sv_yaw_rate_p.get(), _param_sv_yaw_rate_i.get(), 0.f);
|
||||
_pid_yaw_rate.setIntegralLimit(1.f);
|
||||
_pid_yaw_rate.setOutputLimit(1.f);
|
||||
|
||||
// Set up slew rate
|
||||
_adjusted_yaw_rate_setpoint.setSlewRate(_param_ro_yaw_accel_limit.get() * M_DEG_TO_RAD_F);
|
||||
_adjusted_yaw_rate_setpoint.setSlewRate(_param_sv_yaw_accel_limit.get() * M_DEG_TO_RAD_F);
|
||||
}
|
||||
|
||||
void MecanumRateControl::updateRateControl()
|
||||
@@ -64,39 +64,39 @@ void MecanumRateControl::updateRateControl()
|
||||
if (_vehicle_angular_velocity_sub.updated()) {
|
||||
vehicle_angular_velocity_s vehicle_angular_velocity{};
|
||||
_vehicle_angular_velocity_sub.copy(&vehicle_angular_velocity);
|
||||
_vehicle_yaw_rate = fabsf(vehicle_angular_velocity.xyz[2]) > _param_ro_yaw_rate_th.get() * M_DEG_TO_RAD_F ?
|
||||
_vehicle_yaw_rate = fabsf(vehicle_angular_velocity.xyz[2]) > _param_sv_yaw_rate_th.get() * M_DEG_TO_RAD_F ?
|
||||
vehicle_angular_velocity.xyz[2] : 0.f;
|
||||
}
|
||||
|
||||
if (_rover_rate_setpoint_sub.updated()) {
|
||||
rover_rate_setpoint_s rover_rate_setpoint{};
|
||||
_rover_rate_setpoint_sub.copy(&rover_rate_setpoint);
|
||||
_yaw_rate_setpoint = rover_rate_setpoint.yaw_rate_setpoint;
|
||||
if (_surface_vehicle_rate_setpoint_sub.updated()) {
|
||||
surface_vehicle_rate_setpoint_s surface_vehicle_rate_setpoint{};
|
||||
_surface_vehicle_rate_setpoint_sub.copy(&surface_vehicle_rate_setpoint);
|
||||
_yaw_rate_setpoint = surface_vehicle_rate_setpoint.yaw_rate_setpoint;
|
||||
}
|
||||
|
||||
if (PX4_ISFINITE(_yaw_rate_setpoint)) {
|
||||
const float yaw_rate_setpoint = fabsf(_yaw_rate_setpoint) > _param_ro_yaw_rate_th.get() * M_DEG_TO_RAD_F ?
|
||||
const float yaw_rate_setpoint = fabsf(_yaw_rate_setpoint) > _param_sv_yaw_rate_th.get() * M_DEG_TO_RAD_F ?
|
||||
_yaw_rate_setpoint : 0.f;
|
||||
const float speed_diff_normalized = RoverControl::rateControl(_adjusted_yaw_rate_setpoint, _pid_yaw_rate,
|
||||
yaw_rate_setpoint, _vehicle_yaw_rate, _param_ro_max_thr_speed.get(), _param_ro_yaw_rate_corr.get(),
|
||||
_param_ro_yaw_accel_limit.get() * M_DEG_TO_RAD_F,
|
||||
const float speed_diff_normalized = SurfaceVehicleControl::rateControl(_adjusted_yaw_rate_setpoint, _pid_yaw_rate,
|
||||
yaw_rate_setpoint, _vehicle_yaw_rate, _param_sv_max_thr_speed.get(), _param_sv_yaw_rate_corr.get(),
|
||||
_param_sv_yaw_accel_limit.get() * M_DEG_TO_RAD_F,
|
||||
_param_ro_yaw_decel_limit.get() * M_DEG_TO_RAD_F, _param_rm_wheel_track.get(), dt);
|
||||
rover_steering_setpoint_s rover_steering_setpoint{};
|
||||
rover_steering_setpoint.timestamp = _timestamp;
|
||||
rover_steering_setpoint.normalized_steering_setpoint = speed_diff_normalized;
|
||||
_rover_steering_setpoint_pub.publish(rover_steering_setpoint);
|
||||
surface_vehicle_steering_setpoint_s surface_vehicle_steering_setpoint{};
|
||||
surface_vehicle_steering_setpoint.timestamp = _timestamp;
|
||||
surface_vehicle_steering_setpoint.normalized_steering_setpoint = speed_diff_normalized;
|
||||
_surface_vehicle_steering_setpoint_pub.publish(surface_vehicle_steering_setpoint);
|
||||
|
||||
} else {
|
||||
_pid_yaw_rate.resetIntegral();
|
||||
}
|
||||
|
||||
// Publish rate controller status (logging only)
|
||||
rover_rate_status_s rover_rate_status;
|
||||
rover_rate_status.timestamp = _timestamp;
|
||||
rover_rate_status.measured_yaw_rate = _vehicle_yaw_rate;
|
||||
rover_rate_status.adjusted_yaw_rate_setpoint = _adjusted_yaw_rate_setpoint.getState();
|
||||
rover_rate_status.pid_yaw_rate_integral = _pid_yaw_rate.getIntegral();
|
||||
_rover_rate_status_pub.publish(rover_rate_status);
|
||||
surface_vehicle_rate_status_s surface_vehicle_rate_status;
|
||||
surface_vehicle_rate_status.timestamp = _timestamp;
|
||||
surface_vehicle_rate_status.measured_yaw_rate = _vehicle_yaw_rate;
|
||||
surface_vehicle_rate_status.adjusted_yaw_rate_setpoint = _adjusted_yaw_rate_setpoint.getState();
|
||||
surface_vehicle_rate_status.pid_yaw_rate_integral = _pid_yaw_rate.getIntegral();
|
||||
_surface_vehicle_rate_status_pub.publish(surface_vehicle_rate_status);
|
||||
|
||||
}
|
||||
|
||||
@@ -104,19 +104,19 @@ bool MecanumRateControl::runSanityChecks()
|
||||
{
|
||||
bool ret = true;
|
||||
|
||||
if (_param_ro_yaw_rate_limit.get() < FLT_EPSILON) {
|
||||
if (_param_sv_yaw_rate_limit.get() < FLT_EPSILON) {
|
||||
ret = false;
|
||||
events::send<float>(events::ID("mecanum_rate_control_conf_invalid_yaw_rate_lim"), events::Log::Error,
|
||||
"Invalid configuration of necessary parameter RO_YAW_RATE_LIM", _param_ro_yaw_rate_limit.get());
|
||||
"Invalid configuration of necessary parameter SV_YAW_RATE_LIM", _param_sv_yaw_rate_limit.get());
|
||||
|
||||
}
|
||||
|
||||
if ((_param_rm_wheel_track.get() < FLT_EPSILON || _param_ro_max_thr_speed.get() < FLT_EPSILON)
|
||||
&& _param_ro_yaw_rate_p.get() < FLT_EPSILON) {
|
||||
if ((_param_rm_wheel_track.get() < FLT_EPSILON || _param_sv_max_thr_speed.get() < FLT_EPSILON)
|
||||
&& _param_sv_yaw_rate_p.get() < FLT_EPSILON) {
|
||||
ret = false;
|
||||
events::send<float, float, float>(events::ID("mecanum_rate_control_conf_invalid_rate_control"), events::Log::Error,
|
||||
"Invalid configuration for rate control: Neither feed forward (RO_MAX_THR_SPEED) nor feedback (RO_YAW_RATE_P) is setup",
|
||||
_param_rm_wheel_track.get(), _param_ro_max_thr_speed.get(), _param_ro_yaw_rate_p.get());
|
||||
"Invalid configuration for rate control: Neither feed forward (SV_MAX_THR_SPEED) nor feedback (SV_YAW_RATE_P) is setup",
|
||||
_param_rm_wheel_track.get(), _param_sv_max_thr_speed.get(), _param_sv_yaw_rate_p.get());
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
#include <px4_platform_common/events.h>
|
||||
|
||||
// Libraries
|
||||
#include <lib/rover_control/RoverControl.hpp>
|
||||
#include <lib/surface_vehicle_control/SurfaceVehicleControl.hpp>
|
||||
#include <lib/pid/PID.hpp>
|
||||
#include <lib/slew_rate/SlewRate.hpp>
|
||||
#include <math.h>
|
||||
@@ -46,10 +46,10 @@
|
||||
// uORB includes
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/topics/rover_rate_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_rate_setpoint.h>
|
||||
#include <uORB/topics/vehicle_angular_velocity.h>
|
||||
#include <uORB/topics/rover_steering_setpoint.h>
|
||||
#include <uORB/topics/rover_rate_status.h>
|
||||
#include <uORB/topics/surface_vehicle_steering_setpoint.h>
|
||||
#include <uORB/topics/surface_vehicle_rate_status.h>
|
||||
|
||||
/**
|
||||
* @brief Class for mecanum rate control.
|
||||
@@ -65,7 +65,7 @@ public:
|
||||
~MecanumRateControl() = default;
|
||||
|
||||
/**
|
||||
* @brief Generate and publish roverSteeringSetpoint from roverRateSetpoint.
|
||||
* @brief Generate and publish SurfaceVehicleSteeringSetpoint from SurfaceVehicleRateSetpoint.
|
||||
*/
|
||||
void updateRateControl();
|
||||
|
||||
@@ -89,12 +89,12 @@ protected:
|
||||
private:
|
||||
|
||||
// uORB subscriptions
|
||||
uORB::Subscription _rover_rate_setpoint_sub{ORB_ID(rover_rate_setpoint)};
|
||||
uORB::Subscription _surface_vehicle_rate_setpoint_sub{ORB_ID(surface_vehicle_rate_setpoint)};
|
||||
uORB::Subscription _vehicle_angular_velocity_sub{ORB_ID(vehicle_angular_velocity)};
|
||||
|
||||
// uORB publications
|
||||
uORB::Publication<rover_steering_setpoint_s> _rover_steering_setpoint_pub{ORB_ID(rover_steering_setpoint)};
|
||||
uORB::Publication<rover_rate_status_s> _rover_rate_status_pub{ORB_ID(rover_rate_status)};
|
||||
uORB::Publication<surface_vehicle_steering_setpoint_s> _surface_vehicle_steering_setpoint_pub{ORB_ID(surface_vehicle_steering_setpoint)};
|
||||
uORB::Publication<surface_vehicle_rate_status_s> _surface_vehicle_rate_status_pub{ORB_ID(surface_vehicle_rate_status)};
|
||||
|
||||
// Variables
|
||||
hrt_abstime _timestamp{0};
|
||||
@@ -107,13 +107,13 @@ private:
|
||||
|
||||
DEFINE_PARAMETERS(
|
||||
(ParamFloat<px4::params::RM_WHEEL_TRACK>) _param_rm_wheel_track,
|
||||
(ParamFloat<px4::params::RO_MAX_THR_SPEED>) _param_ro_max_thr_speed,
|
||||
(ParamFloat<px4::params::RO_YAW_RATE_LIM>) _param_ro_yaw_rate_limit,
|
||||
(ParamFloat<px4::params::RO_YAW_RATE_TH>) _param_ro_yaw_rate_th,
|
||||
(ParamFloat<px4::params::RO_YAW_RATE_P>) _param_ro_yaw_rate_p,
|
||||
(ParamFloat<px4::params::RO_YAW_RATE_I>) _param_ro_yaw_rate_i,
|
||||
(ParamFloat<px4::params::RO_YAW_ACCEL_LIM>) _param_ro_yaw_accel_limit,
|
||||
(ParamFloat<px4::params::RO_YAW_DECEL_LIM>) _param_ro_yaw_decel_limit,
|
||||
(ParamFloat<px4::params::RO_YAW_RATE_CORR>) _param_ro_yaw_rate_corr
|
||||
(ParamFloat<px4::params::SV_MAX_THR_SPEED>) _param_sv_max_thr_speed,
|
||||
(ParamFloat<px4::params::SV_YAW_RATE_LIM>) _param_sv_yaw_rate_limit,
|
||||
(ParamFloat<px4::params::SV_YAW_RATE_TH>) _param_sv_yaw_rate_th,
|
||||
(ParamFloat<px4::params::SV_YAW_RATE_P>) _param_sv_yaw_rate_p,
|
||||
(ParamFloat<px4::params::SV_YAW_RATE_I>) _param_sv_yaw_rate_i,
|
||||
(ParamFloat<px4::params::SV_YAW_ACCEL_LIM>) _param_sv_yaw_accel_limit,
|
||||
(ParamFloat<px4::params::SV_YAW_DECEL_LIM>) _param_ro_yaw_decel_limit,
|
||||
(ParamFloat<px4::params::SV_YAW_RATE_CORR>) _param_sv_yaw_rate_corr
|
||||
)
|
||||
};
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user