-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Add boat SIH #24778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add boat SIH #24778
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/bin/sh | ||
# @name Boat (Ackermann style) | ||
# @type Boat | ||
# @class Boat | ||
|
||
. ${R}etc/init.d/rc.boat_defaults | ||
|
||
set VEHICLE_TYPE boat | ||
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 | ||
|
||
|
||
PX4_SIMULATOR=${PX4_SIMULATOR:=sihsim} | ||
PX4_SIM_MODEL=${PX4_SIM_MODEL:=boat} | ||
|
||
param set-default SIH_VEHICLE_TYPE 4 # sih as boat | ||
|
||
#param set-default SIH_MASS 3.0 | ||
#param set-default SIH_IXX 0.00402 | ||
#param set-default SIH_IYY 0.0144 | ||
#param set-default SIH_IZZ 0.0177 | ||
#param set-default SIH_IXZ 0.00046 | ||
#param set-default SIH_KDV 0.2 | ||
|
||
param set-default PWM_MAIN_FUNC1 201 # Steering | ||
param set-default PWM_MAIN_FUNC2 101 # Throttle | ||
|
||
param set-default SENS_EN_GPSSIM 1 | ||
param set-default SENS_EN_BAROSIM 1 | ||
param set-default SENS_EN_MAGSIM 1 | ||
#param set-default SENS_EN_ARSPDSIM 1 | ||
|
||
param set-default NAV_ACC_RAD 0.5 | ||
|
||
# Ackermann Parameters | ||
param set-default RA_WHEEL_BASE 0.321 | ||
param set-default RA_ACC_RAD_GAIN 2 | ||
param set-default RA_ACC_RAD_MAX 3 | ||
param set-default RA_MAX_STR_ANG 0.5236 | ||
param set-default RA_STR_RATE_LIM 360 | ||
|
||
# Rover Control Parameters | ||
param set-default RO_ACCEL_LIM 3 | ||
param set-default RO_DECEL_LIM 6 | ||
param set-default RO_JERK_LIM 15 | ||
param set-default RO_MAX_THR_SPEED 3.1 | ||
|
||
# Rover Rate Control Parameters | ||
param set-default RO_YAW_RATE_I 0.1 | ||
param set-default RO_YAW_RATE_P 1 | ||
param set-default RO_YAW_RATE_LIM 180 | ||
|
||
# Rover Attitude Control Parameters | ||
param set-default RO_YAW_P 3 | ||
|
||
# Rover Position Control Parameters | ||
param set-default RO_SPEED_LIM 3 | ||
param set-default RO_SPEED_I 0.1 | ||
param set-default RO_SPEED_P 1 | ||
|
||
# Pure Pursuit parameters | ||
param set-default PP_LOOKAHD_GAIN 1 | ||
param set-default PP_LOOKAHD_MAX 10 | ||
param set-default PP_LOOKAHD_MIN 1 | ||
|
||
# Wheels | ||
param set-default SIM_GZ_WH_FUNC1 101 | ||
param set-default SIM_GZ_WH_MIN1 0 | ||
param set-default SIM_GZ_WH_MAX1 200 | ||
param set-default SIM_GZ_WH_DIS1 100 | ||
|
||
# Steering | ||
param set-default SIM_GZ_SV_MAXA1 30 | ||
param set-default SIM_GZ_SV_MINA1 -30 | ||
param set-default CA_SV_CS_COUNT 1 | ||
param set-default SIM_GZ_SV_FUNC1 201 | ||
param set-default SIM_GZ_SV_REV 1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/sh | ||
# Standard apps for an boat. | ||
|
||
# Start rover ackermann module. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add comment that this is only short-term until we have boat controller. |
||
rover_ackermann start | ||
|
||
# Start Land Detector. | ||
land_detector start rover |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ if(PX4_PLATFORM MATCHES "posix") | |
quadx | ||
xvert | ||
standard_vtol | ||
boat | ||
) | ||
|
||
# find corresponding airframes | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,15 @@ menuconfig MODULES_SIMULATION_SIMULATOR_SIH | |
---help--- | ||
Enable support for simulator_sih | ||
|
||
if MODULES_SIMULATION_SIMULATOR_SIH | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is that necessary? I don't see the same kconfig options for the other SIH vehicle types. |
||
config SIH_SIM_BOAT | ||
bool "Enable Boat Simulation features (SIH)" | ||
default n | ||
depends on MODULES_SIMULATION_SIMULATOR_SIH | ||
---help--- | ||
Enable boat support for SIH simulator. | ||
endif # MODULES_SIMULATION_SIMULATOR_SIH | ||
|
||
menuconfig USER_SIH | ||
bool "simulator_sih running as userspace module" | ||
default y | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,7 +76,7 @@ void Sih::run() | |
_airspeed_time = task_start; | ||
_dist_snsr_time = task_start; | ||
_vehicle = (VehicleType)constrain(_sih_vtype.get(), static_cast<typeof _sih_vtype.get()>(0), | ||
static_cast<typeof _sih_vtype.get()>(3)); | ||
static_cast<typeof _sih_vtype.get()>(5)); | ||
|
||
_actuator_out_sub = uORB::Subscription{ORB_ID(actuator_outputs_sim)}; | ||
|
||
|
@@ -351,9 +351,66 @@ void Sih::generate_force_and_torques() | |
// thrust 0 because it is already contained in _T_B. in | ||
// equations_of_motion they are all summed into sum_of_forces_E | ||
generate_fw_aerodynamics(_u[4], _u[5], _u[6], 0); | ||
|
||
} else if (_vehicle == VehicleType::Boat) { | ||
// _T_B = Vector3f(_T_MAX * _u[1], 0.0f, 0.0f); // forward thruster | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove dead code. |
||
// _Mt_B = Vector3f(_Q_MAX*_u[3], 0.0f,0.0f); // thruster torque | ||
// _Mt_B = Vector3f(); | ||
// _Mt_B = Vector3f(0.f, 0.f, _Q_MAX * _u[3] * (+_u[0])); | ||
generate_boat_dynamics(_u[1], _u[0]); | ||
|
||
_Fa_E = -_KDV * _v_E; // first order drag to slow down the vehicle | ||
_Ma_B = -_KDW * _w_B; // first order angular damper | ||
|
||
} | ||
} | ||
|
||
void Sih::generate_boat_dynamics(const float throttle_cmd, const float steering_cmd) | ||
{ | ||
const float MAX_FORCE = 100.0f; // [N] | ||
const float MAX_STEER_ANGLE = 1.2f; // [rad] (=68.7°) | ||
const float MOMENT_EFFECTIVENESS = 0.08f; // unitless (0..1) | ||
const float ENGINE_TO_COG = 1.0f; // [m] | ||
|
||
const float DAMPING_X = 2.0f; // forward drag [N·s/m] | ||
const float DAMPING_Y = 8.0f; // lateral drag [N·s/m] | ||
const float YAW_DAMPING = 1.0f; // yaw damping [Nm·s/rad] | ||
const float LATERAL_RESISTANCE = 20.0f; // keel-like resistance [N·s/m] | ||
|
||
// --- Convert nav velocity to body frame --- | ||
const matrix::Dcmf R_nb(_q); // body to nav frame | ||
const matrix::Vector3f v_B = R_nb.T() * _v_N; // nav -> body | ||
|
||
// --- Compute input-based thrust --- | ||
const float steering_angle = MAX_STEER_ANGLE * steering_cmd; | ||
const float force = MAX_FORCE * throttle_cmd; | ||
|
||
_T_B = matrix::Vector3f( | ||
std::cos(steering_angle) * force, | ||
std::sin(steering_angle) * force, | ||
0.0f | ||
); | ||
|
||
// --- Compute yaw moment from steering (scaled by speed) --- | ||
const float speed = v_B.norm(); | ||
const float steer_eff = math::constrain(speed / 10.0f, 0.0f, 1.0f); // more effective at higher speeds | ||
|
||
_Mt_B = matrix::Vector3f( | ||
0.0f, | ||
0.0f, | ||
std::sin(steering_angle) * ENGINE_TO_COG * force * MOMENT_EFFECTIVENESS * steer_eff | ||
); | ||
|
||
// --- Apply drag damping --- | ||
_T_B(0) -= DAMPING_X * v_B(0); // forward resistance | ||
_T_B(1) -= DAMPING_Y * v_B(1); // lateral resistance | ||
_T_B(1) -= LATERAL_RESISTANCE * v_B(1); // extra "keel" effect | ||
|
||
// --- Angular damping (if you have _w_B) --- | ||
_Mt_B(2) -= YAW_DAMPING * _w_B(2); // oppose yaw rotation | ||
} | ||
|
||
|
||
void Sih::generate_fw_aerodynamics(const float roll_cmd, const float pitch_cmd, const float yaw_cmd, | ||
const float throttle_cmd) | ||
{ | ||
|
@@ -452,6 +509,18 @@ void Sih::equations_of_motion(const float dt) | |
ground_force_E += down_u * (-_v_N(2) / dt) * _MASS; | ||
} | ||
|
||
_grounded = true; | ||
|
||
} else if (_vehicle == VehicleType::Boat) { | ||
Vector3f down_u = _R_N2E.col(2); | ||
ground_force_E = -down_u * sum_of_forces_E * down_u; | ||
|
||
if (!_grounded) { | ||
// if we just hit the floor | ||
// compute the force that will stop the vehicle in one time step | ||
ground_force_E += down_u * (-_v_N(2) / dt) * _MASS; | ||
} | ||
|
||
_grounded = true; | ||
} | ||
|
||
|
@@ -729,6 +798,10 @@ int Sih::print_status() | |
|
||
} else if (_vehicle == VehicleType::StandardVTOL) { | ||
PX4_INFO("Running Standard VTOL"); | ||
|
||
} else if (_vehicle == VehicleType::Boat) { | ||
PX4_INFO("Running Boat"); | ||
|
||
} | ||
|
||
PX4_INFO("vehicle landed: %d", _grounded); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better delete unused parameters