Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SITL support for skid-steering boat #27560

Merged
merged 2 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Tools/autotest/pysim/vehicleinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,12 @@ def __init__(self):
"default_params_filename": ["default_params/rover.parm",
"default_params/motorboat.parm"],
},
"motorboat-skid": {
"waf_target": "bin/ardurover",
"default_params_filename": ["default_params/rover.parm",
"default_params/motorboat.parm",
"default_params/rover-skid.parm"],
},
"sailboat": {
"waf_target": "bin/ardurover",
"default_params_filename": ["default_params/rover.parm",
Expand Down
40 changes: 31 additions & 9 deletions libraries/SITL/SIM_Sailboat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ namespace SITL {
#define STEERING_SERVO_CH 0 // steering controlled by servo output 1
#define MAINSAIL_SERVO_CH 3 // main sail controlled by servo output 4
#define THROTTLE_SERVO_CH 2 // throttle controlled by servo output 3
#define MOTORLEFT_SERVO_CH 0 // skid-steering left motor controlled by servo output 1
#define MOTORRIGHT_SERVO_CH 2 // skid-steering right motor controlled by servo output 3
#define DIRECT_WING_SERVO_CH 4

// very roughly sort of a stability factors for waves
Expand All @@ -45,6 +47,7 @@ Sailboat::Sailboat(const char *frame_str) :
sail_area(1.0)
{
motor_connected = (strcmp(frame_str, "sailboat-motor") == 0);
skid_steering = strstr(frame_str, "skid") != nullptr;
lock_step_scheduled = true;
}

Expand Down Expand Up @@ -97,13 +100,19 @@ float Sailboat::get_turn_circle(float steering) const
// return yaw rate in deg/sec given a steering input (in the range -1 to +1) and speed in m/s
float Sailboat::get_yaw_rate(float steering, float speed) const
{
if (is_zero(steering) || is_zero(speed)) {
return 0;
float rate = 0.0f;
if (is_zero(steering) || (!skid_steering && is_zero(speed))) {
return rate;
}

if (is_zero(speed) && skid_steering) {
rate = steering * M_PI * 5;
} else {
float d = get_turn_circle(steering);
float c = M_PI * d;
float t = c / speed;
rate = 360.0f / t;
}
float d = get_turn_circle(steering);
float c = M_PI * d;
float t = c / speed;
float rate = 360.0f / t;
return rate;
}

Expand Down Expand Up @@ -179,7 +188,14 @@ void Sailboat::update(const struct sitl_input &input)
update_wind(input);

// in sailboats the steering controls the rudder, the throttle controls the main sail position
float steering = 2*((input.servos[STEERING_SERVO_CH]-1000)/1000.0f - 0.5f);
float steering = 0.0f;
if (skid_steering) {
float steering_left = 2.0f*((input.servos[MOTORLEFT_SERVO_CH]-1000)/1000.0f - 0.5f);
float steering_right = 2.0f*((input.servos[MOTORRIGHT_SERVO_CH]-1000)/1000.0f - 0.5f);
steering = steering_left - steering_right;
} else {
steering = 2*((input.servos[STEERING_SERVO_CH]-1000)/1000.0f - 0.5f);
}

// calculate apparent wind in earth-frame (this is the direction the wind is coming from)
// Note than the SITL wind direction is defined as the direction the wind is travelling to
Expand Down Expand Up @@ -257,8 +273,14 @@ void Sailboat::update(const struct sitl_input &input)
// gives throttle force == hull drag at 10m/s
float throttle_force = 0.0f;
if (motor_connected) {
const uint16_t throttle_out = constrain_int16(input.servos[THROTTLE_SERVO_CH], 1000, 2000);
throttle_force = (throttle_out-1500) * 0.1f;
if (skid_steering) {
const uint16_t throttle_left = constrain_int16(input.servos[MOTORLEFT_SERVO_CH], 1000, 2000);
const uint16_t throttle_right = constrain_int16(input.servos[MOTORRIGHT_SERVO_CH], 1000, 2000);
throttle_force = (0.5f*(throttle_left + throttle_right)-1500) * 0.1f;
} else {
const uint16_t throttle_out = constrain_int16(input.servos[THROTTLE_SERVO_CH], 1000, 2000);
throttle_force = (throttle_out-1500) * 0.1f;
}
}

// accel in body frame due acceleration from sail and deceleration from hull friction
Expand Down
1 change: 1 addition & 0 deletions libraries/SITL/SIM_Sailboat.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Sailboat : public Aircraft {

protected:
bool motor_connected; // true if this frame has a motor
bool skid_steering; // true if this vehicle is a skid-steering vehicle
float sail_area; // 1.0 for normal area

private:
Expand Down
Loading