mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-26 01:00:36 +08:00
Merge branch 'main' into breuerpeter/newton
This commit is contained in:
7 files changed
+229
-3
No files matched your search
@@ -64,6 +64,22 @@ ManualSticks mapSticks(const manual_control_setpoint_s &manual_control_setpoint,
|
||||
}
|
||||
}
|
||||
|
||||
bool sticksCommandMotion(const manual_control_setpoint_s &manual_control_setpoint, int32_t stick_map, bool can_drive_sideways,
|
||||
bool tank_style_sticks)
|
||||
{
|
||||
const float arming_stick_threshold = 0.2f;
|
||||
const ManualSticks sticks = mapSticks(manual_control_setpoint, stick_map);
|
||||
const bool lateral = can_drive_sideways && fabsf(sticks.lateral) >= arming_stick_threshold;
|
||||
|
||||
if (tank_style_sticks) {
|
||||
const float left = manual_control_setpoint.throttle;
|
||||
const float right = manual_control_setpoint.pitch;
|
||||
return fabsf(left) >= arming_stick_threshold || fabsf(right) >= arming_stick_threshold || lateral;
|
||||
}
|
||||
|
||||
return fabsf(sticks.forward) >= arming_stick_threshold || lateral;
|
||||
}
|
||||
|
||||
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,
|
||||
const float dt)
|
||||
|
||||
@@ -81,6 +81,18 @@ enum class StickMapping : int32_t {
|
||||
*/
|
||||
ManualSticks mapSticks(const manual_control_setpoint_s &manual_control_setpoint, int32_t stick_map);
|
||||
|
||||
/**
|
||||
* Checks whether the sticks command the rover to drive, used to deny arming with sticks off center.
|
||||
* @param manual_control_setpoint Stick inputs
|
||||
* @param stick_map Selected mapping (RO_STICK_MAP), unknown values use StickMapping::Mode3
|
||||
* @param can_drive_sideways True for rovers that use the lateral stick (mecanum)
|
||||
* @param tank_style_sticks True in manual parking on differential and mecanum rovers, where the left and right
|
||||
* vertical sticks drive the left and right wheels instead of the stick mapping
|
||||
* @return True if a stick that drives the wheels is deflected by 0.2 or more
|
||||
*/
|
||||
bool sticksCommandMotion(const manual_control_setpoint_s &manual_control_setpoint, int32_t stick_map, bool can_drive_sideways,
|
||||
bool tank_style_sticks);
|
||||
|
||||
/**
|
||||
* Applies acceleration/deceleration slew rate to a throttle setpoint.
|
||||
* @param motor_setpoint Throttle setpoint with applied slew rate [-1, 1] (Updated by this function)
|
||||
|
||||
@@ -1223,3 +1223,175 @@ TEST(speedControl, signChangeReverseWithoutDecelerationLimit)
|
||||
// THEN: the acceleration limit applies as before
|
||||
EXPECT_NEAR(adjusted_speed, 1.f - kSignChangeMaxAccel * kDt, 1e-6f);
|
||||
}
|
||||
|
||||
static constexpr int32_t kStickMapMode2 = static_cast<int32_t>(RoverControl::StickMapping::Mode2);
|
||||
static constexpr bool kCanDriveSideways = true; // Mecanum, so the lateral stick is checked too
|
||||
|
||||
TEST(sticksCommandMotion, centeredSticks)
|
||||
{
|
||||
// GIVEN: all sticks centered
|
||||
manual_control_setpoint_s manual_control_setpoint{};
|
||||
|
||||
// WHEN: checked with stick mapping mode 2 (left: yaw, right: forward & lateral)
|
||||
const bool commands_motion = RoverControl::sticksCommandMotion(manual_control_setpoint, kStickMapMode2, kCanDriveSideways, false);
|
||||
|
||||
// THEN: no motion is commanded
|
||||
EXPECT_FALSE(commands_motion);
|
||||
}
|
||||
|
||||
TEST(sticksCommandMotion, forwardOnRightStick)
|
||||
{
|
||||
// GIVEN: the right stick pushed fully forward, with the left vertical stick centered
|
||||
manual_control_setpoint_s manual_control_setpoint{};
|
||||
manual_control_setpoint.pitch = 1.f;
|
||||
|
||||
// WHEN: checked with stick mapping mode 2, where the right vertical stick drives forward
|
||||
const bool commands_motion = RoverControl::sticksCommandMotion(manual_control_setpoint, kStickMapMode2, kCanDriveSideways, false);
|
||||
|
||||
// THEN: motion is commanded
|
||||
EXPECT_TRUE(commands_motion);
|
||||
}
|
||||
|
||||
TEST(sticksCommandMotion, backwardOnRightStick)
|
||||
{
|
||||
// GIVEN: the right stick pulled fully back
|
||||
manual_control_setpoint_s manual_control_setpoint{};
|
||||
manual_control_setpoint.pitch = -1.f;
|
||||
|
||||
// WHEN: checked with stick mapping mode 2
|
||||
const bool commands_motion = RoverControl::sticksCommandMotion(manual_control_setpoint, kStickMapMode2, kCanDriveSideways, false);
|
||||
|
||||
// THEN: motion is commanded
|
||||
EXPECT_TRUE(commands_motion);
|
||||
}
|
||||
|
||||
TEST(sticksCommandMotion, lateralOnRightStick)
|
||||
{
|
||||
// GIVEN: the right stick pushed fully to the side
|
||||
manual_control_setpoint_s manual_control_setpoint{};
|
||||
manual_control_setpoint.roll = 1.f;
|
||||
|
||||
// WHEN: checked with stick mapping mode 2, where the right horizontal stick drives sideways
|
||||
const bool commands_motion = RoverControl::sticksCommandMotion(manual_control_setpoint, kStickMapMode2, kCanDriveSideways, false);
|
||||
|
||||
// THEN: motion is commanded
|
||||
EXPECT_TRUE(commands_motion);
|
||||
}
|
||||
|
||||
TEST(sticksCommandMotion, lateralOnRoverThatCannotDriveSideways)
|
||||
{
|
||||
// GIVEN: the right stick pushed fully to the side
|
||||
manual_control_setpoint_s manual_control_setpoint{};
|
||||
manual_control_setpoint.roll = 1.f;
|
||||
|
||||
// WHEN: checked for a rover that doesn't use the lateral stick (differential, Ackermann)
|
||||
const bool commands_motion = RoverControl::sticksCommandMotion(manual_control_setpoint, kStickMapMode2, false, false);
|
||||
|
||||
// THEN: no motion is commanded
|
||||
EXPECT_FALSE(commands_motion);
|
||||
}
|
||||
|
||||
TEST(sticksCommandMotion, unusedLeftVerticalStick)
|
||||
{
|
||||
// GIVEN: the left vertical stick pushed fully forward, which is the stick commander checked before
|
||||
manual_control_setpoint_s manual_control_setpoint{};
|
||||
manual_control_setpoint.throttle = 1.f;
|
||||
|
||||
// WHEN: checked with stick mapping mode 2, where the left vertical stick is not used
|
||||
const bool commands_motion = RoverControl::sticksCommandMotion(manual_control_setpoint, kStickMapMode2, kCanDriveSideways, false);
|
||||
|
||||
// THEN: no motion is commanded
|
||||
EXPECT_FALSE(commands_motion);
|
||||
}
|
||||
|
||||
TEST(sticksCommandMotion, yawOnly)
|
||||
{
|
||||
// GIVEN: the left stick pushed fully to the side
|
||||
manual_control_setpoint_s manual_control_setpoint{};
|
||||
manual_control_setpoint.yaw = 1.f;
|
||||
|
||||
// WHEN: checked with stick mapping mode 2, where the left horizontal stick turns the rover
|
||||
const bool commands_motion = RoverControl::sticksCommandMotion(manual_control_setpoint, kStickMapMode2, kCanDriveSideways, false);
|
||||
|
||||
// THEN: turning alone does not count as motion
|
||||
EXPECT_FALSE(commands_motion);
|
||||
}
|
||||
|
||||
TEST(sticksCommandMotion, belowThreshold)
|
||||
{
|
||||
// GIVEN: the forward stick deflected just below the 0.2 threshold
|
||||
manual_control_setpoint_s manual_control_setpoint{};
|
||||
manual_control_setpoint.pitch = 0.19f;
|
||||
|
||||
// WHEN: checked with stick mapping mode 2
|
||||
const bool commands_motion = RoverControl::sticksCommandMotion(manual_control_setpoint, kStickMapMode2, kCanDriveSideways, false);
|
||||
|
||||
// THEN: no motion is commanded
|
||||
EXPECT_FALSE(commands_motion);
|
||||
}
|
||||
|
||||
TEST(sticksCommandMotion, atThreshold)
|
||||
{
|
||||
// GIVEN: the forward stick deflected exactly to the 0.2 threshold
|
||||
manual_control_setpoint_s manual_control_setpoint{};
|
||||
manual_control_setpoint.pitch = 0.2f;
|
||||
|
||||
// WHEN: checked with stick mapping mode 2
|
||||
const bool commands_motion = RoverControl::sticksCommandMotion(manual_control_setpoint, kStickMapMode2, kCanDriveSideways, false);
|
||||
|
||||
// THEN: motion is commanded, matching the previous throttle check that only allowed arming below 0.2
|
||||
EXPECT_TRUE(commands_motion);
|
||||
}
|
||||
|
||||
TEST(sticksCommandMotion, parkingLeftStickForward)
|
||||
{
|
||||
// GIVEN: the left stick pushed fully forward
|
||||
manual_control_setpoint_s manual_control_setpoint{};
|
||||
manual_control_setpoint.throttle = 1.f;
|
||||
|
||||
// WHEN: checked in manual parking, where the left vertical stick drives the left wheels whatever the stick mapping
|
||||
const bool commands_motion = RoverControl::sticksCommandMotion(manual_control_setpoint, kStickMapMode2, false, true);
|
||||
|
||||
// THEN: motion is commanded
|
||||
EXPECT_TRUE(commands_motion);
|
||||
}
|
||||
|
||||
TEST(sticksCommandMotion, parkingRightStickForward)
|
||||
{
|
||||
// GIVEN: the right stick pushed fully forward
|
||||
manual_control_setpoint_s manual_control_setpoint{};
|
||||
manual_control_setpoint.pitch = 1.f;
|
||||
|
||||
// WHEN: checked in manual parking, where the right vertical stick drives the right wheels
|
||||
const bool commands_motion = RoverControl::sticksCommandMotion(manual_control_setpoint, kStickMapMode2, false, true);
|
||||
|
||||
// THEN: motion is commanded
|
||||
EXPECT_TRUE(commands_motion);
|
||||
}
|
||||
|
||||
TEST(sticksCommandMotion, parkingTurnOnTheSpot)
|
||||
{
|
||||
// GIVEN: the left stick pushed fully forward and the right stick pulled fully back
|
||||
manual_control_setpoint_s manual_control_setpoint{};
|
||||
manual_control_setpoint.throttle = 1.f;
|
||||
manual_control_setpoint.pitch = -1.f;
|
||||
|
||||
// WHEN: checked in manual parking, where this turns the rover on the spot
|
||||
const bool commands_motion = RoverControl::sticksCommandMotion(manual_control_setpoint, kStickMapMode2, false, true);
|
||||
|
||||
// THEN: motion is commanded, since both sides of wheels are driven
|
||||
EXPECT_TRUE(commands_motion);
|
||||
}
|
||||
|
||||
TEST(sticksCommandMotion, parkingOneStickPartly)
|
||||
{
|
||||
// GIVEN: the left stick pushed to 0.3 and the right stick centered
|
||||
manual_control_setpoint_s manual_control_setpoint{};
|
||||
manual_control_setpoint.throttle = 0.3f;
|
||||
|
||||
// WHEN: checked in manual parking
|
||||
const bool commands_motion = RoverControl::sticksCommandMotion(manual_control_setpoint, kStickMapMode2, false, true);
|
||||
|
||||
// THEN: motion is commanded, since the left wheels are driven
|
||||
EXPECT_TRUE(commands_motion);
|
||||
}
|
||||
@@ -83,6 +83,7 @@ px4_add_module(
|
||||
hysteresis
|
||||
mode_util
|
||||
MulticopterThrowLaunch
|
||||
rover_control
|
||||
sensor_calibration
|
||||
world_magnetic_model
|
||||
atmosphere
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include <drivers/drv_tone_alarm.h>
|
||||
#include <lib/geo/geo.h>
|
||||
#include <lib/rover_control/RoverControl.hpp>
|
||||
#include <mathlib/mathlib.h>
|
||||
#include <px4_platform_common/events.h>
|
||||
#include <px4_platform_common/px4_config.h>
|
||||
@@ -696,8 +697,26 @@ transition_result_t Commander::arm(arm_disarm_reason_t calling_reason, bool run_
|
||||
bool throttle_safe;
|
||||
|
||||
if (_vehicle_status.vehicle_type == vehicle_status_s::VEHICLE_TYPE_ROVER) {
|
||||
// Rovers: center stick = stop, safe to arm near center
|
||||
throttle_safe = (fabsf(_last_manual_throttle) < 0.2f);
|
||||
// Rovers: centered sticks = stop. RO_STICK_MAP decides which sticks drive forward and sideways,
|
||||
// it only exists if a rover module is built, otherwise the default mapping is used.
|
||||
int32_t stick_map = 0;
|
||||
|
||||
if (_param_ro_stick_map != PARAM_INVALID) {
|
||||
param_get(_param_ro_stick_map, &stick_map);
|
||||
}
|
||||
|
||||
// CA_AIRFRAME: 6 = differential rover, 13 = mecanum rover. Only mecanum rovers use the lateral stick.
|
||||
// In manual parking both drive the left and right wheels with the vertical sticks, not RO_STICK_MAP.
|
||||
int32_t airframe = 0;
|
||||
|
||||
if (_param_ca_airframe != PARAM_INVALID) {
|
||||
param_get(_param_ca_airframe, &airframe);
|
||||
}
|
||||
|
||||
const bool can_drive_sideways = (airframe == 13);
|
||||
const bool manual_parking = (_vehicle_status.nav_state == vehicle_status_s::NAVIGATION_STATE_MANUAL_PARKING);
|
||||
const bool tank_style_sticks = manual_parking && (airframe == 6 || airframe == 13);
|
||||
throttle_safe = !RoverControl::sticksCommandMotion(_last_manual_control_setpoint, stick_map, can_drive_sideways, tank_style_sticks);
|
||||
|
||||
} else if (_vehicle_control_mode.flag_control_climb_rate_enabled) {
|
||||
// Climb-rate modes (AltCtl, PosCtl, etc.): center = hover, safe at or below center
|
||||
@@ -834,6 +853,8 @@ Commander::Commander() :
|
||||
param_t param_mav_sys_id = param_find("MAV_SYS_ID");
|
||||
_param_mav_type = param_find("MAV_TYPE");
|
||||
_param_rc_map_fltmode = param_find("RC_MAP_FLTMODE");
|
||||
_param_ro_stick_map = param_find("RO_STICK_MAP");
|
||||
_param_ca_airframe = param_find("CA_AIRFRAME");
|
||||
|
||||
int32_t value_int32 = 0;
|
||||
|
||||
@@ -3184,6 +3205,7 @@ void Commander::manualControlCheck()
|
||||
if (manual_control_updated && manual_control_setpoint.valid) {
|
||||
|
||||
_last_manual_throttle = manual_control_setpoint.throttle;
|
||||
_last_manual_control_setpoint = manual_control_setpoint;
|
||||
|
||||
if (isArmed()) {
|
||||
// Hand control back to the pilot when they override with the sticks (see MAN_OVERRIDE_SPD).
|
||||
|
||||
@@ -285,6 +285,7 @@ private:
|
||||
bool _mode_switch_mapped{false};
|
||||
|
||||
float _last_manual_throttle{-1.f};
|
||||
manual_control_setpoint_s _last_manual_control_setpoint{};
|
||||
bool _manual_control_lost_prev{false}; ///< previous manual_control_signal_lost state, for edge detection
|
||||
|
||||
bool _arm_tune_played{false};
|
||||
@@ -339,6 +340,8 @@ private:
|
||||
// optional parameters
|
||||
param_t _param_mav_type{PARAM_INVALID};
|
||||
param_t _param_rc_map_fltmode{PARAM_INVALID};
|
||||
param_t _param_ro_stick_map{PARAM_INVALID};
|
||||
param_t _param_ca_airframe{PARAM_INVALID};
|
||||
|
||||
DEFINE_PARAMETERS(
|
||||
(ParamFloat<px4::params::COM_DISARM_LAND>) _param_com_disarm_land,
|
||||
|
||||
@@ -1615,7 +1615,7 @@ FixedWingModeManager::control_auto_landing_straight(const hrt_abstime &now, cons
|
||||
fw_lateral_ctrl_sp.lateral_acceleration = sp.lateral_acceleration_feedforward;
|
||||
_lateral_ctrl_sp_pub.publish(fw_lateral_ctrl_sp);
|
||||
|
||||
const float roll_wingtip_strike = getMaxRollAngleNearGround(_current_altitude, _takeoff_ground_alt);
|
||||
const float roll_wingtip_strike = getMaxRollAngleNearGround(_current_altitude, terrain_alt);
|
||||
_ctrl_configuration_handler.setLateralAccelMax(rollAngleToLateralAccel(roll_wingtip_strike));
|
||||
|
||||
/* longitudinal guidance */
|
||||
|
||||
Reference in new issue
Block a user