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

SITL: Add simulator for tethered vehicle #28749

Merged
merged 2 commits into from
Dec 9, 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
52 changes: 52 additions & 0 deletions Tools/autotest/arducopter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6074,7 +6074,7 @@
raise NotAchievedException("Did not detect a motor peak, found %fHz at %fdB" % (freq, peakdb))
else:
if reverse is not None:
raise NotAchievedException(

Check failure on line 6077 in Tools/autotest/arducopter.py

View workflow job for this annotation

GitHub Actions / autotest (sitltest-copter-tests2b)

vehicle_test_suite.NotAchievedException: Detected motor peak at 136.372539Hz, throttle 36.000000%, 8.585033dB

Check failure on line 6077 in Tools/autotest/arducopter.py

View workflow job for this annotation

GitHub Actions / autotest (sitltest-copter-tests2b)

vehicle_test_suite.NotAchievedException: Detected motor peak at 136.372539Hz, throttle 36.000000%, 8.585033dB
"Detected motor peak at %fHz, throttle %f%%, %fdB" %
(freq, hover_throttle, peakdb))
else:
Expand Down Expand Up @@ -6641,7 +6641,7 @@
self.reboot_sitl()

if ex is not None:
raise ex

Check failure on line 6644 in Tools/autotest/arducopter.py

View workflow job for this annotation

GitHub Actions / autotest (sitltest-copter-tests2b)

File "/__w/ardupilot/ardupilot/Tools/autotest/arducopter.py", line 6621, in test_gyro_fft_harmonic

def GyroFFTHarmonic(self):
"""Use dynamic harmonic notch to control motor noise with harmonic matching of the first harmonic."""
Expand Down Expand Up @@ -8304,6 +8304,57 @@

self.do_RTL()

def TestTetherStuck(self):
"""Test tethered vehicle stuck because of tether"""
# Enable tether simulation
self.set_parameters({
"SIM_TETH_ENABLE": 1,
})
self.delay_sim_time(2)
self.reboot_sitl()

# Set tether line length
self.set_parameters({
"SIM_TETH_LINELEN": 10,
})
self.delay_sim_time(2)

# Prepare and take off
self.wait_ready_to_arm()
self.arm_vehicle()
self.takeoff(10, mode='LOITER')

# Simulate vehicle getting stuck by increasing RC throttle
self.set_rc(3, 1900)
self.delay_sim_time(5, reason='let tether get stuck')

# Monitor behavior for 10 seconds
tstart = self.get_sim_time()
initial_alt = self.get_altitude()
stuck = True # Assume it's stuck unless proven otherwise

while self.get_sim_time() - tstart < 10:
# Fetch current altitude
current_alt = self.get_altitude()
self.progress(f"current_alt={current_alt}")

# Fetch and log battery status
battery_status = self.mav.recv_match(type='BATTERY_STATUS', blocking=True, timeout=1)
if battery_status:
self.progress(f"Battery: {battery_status}")

# Check if the vehicle is stuck.
# We assume the vehicle is stuck if the current is high and the altitude is not changing
if battery_status and (battery_status.current_battery < 6500 or abs(current_alt - initial_alt) > 2):
stuck = False # Vehicle moved or current is abnormal
break

if not stuck:
raise NotAchievedException("Vehicle did not get stuck as expected")

# Land and disarm the vehicle to ensure we can go down
self.land_and_disarm()

def fly_rangefinder_drivers_fly(self, rangefinders):
'''ensure rangefinder gives height-above-ground'''
self.change_mode('GUIDED')
Expand Down Expand Up @@ -12330,6 +12381,7 @@
self.MAV_CMD_MISSION_START_p1_p2,
self.ScriptingAHRSSource,
self.CommonOrigin,
self.TestTetherStuck,
])
return ret

Expand Down
29 changes: 21 additions & 8 deletions libraries/SITL/SIM_Aircraft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,11 @@ void Aircraft::update_dynamics(const Vector3f &rot_accel)
sitl->models.slung_payload_sim.update(get_position_relhome(), velocity_ef, accel_earth, wind_ef);
#endif

// update tether
#if AP_SIM_TETHER_ENABLED
sitl->models.tether_sim.update(location);
#endif

// allow for changes in physics step
adjust_frame_time(constrain_float(sitl->loop_rate_hz, rate_hz-1, rate_hz+1));
}
Expand Down Expand Up @@ -1273,18 +1278,26 @@ void Aircraft::add_twist_forces(Vector3f &rot_accel)
}
}

#if AP_SIM_SLUNGPAYLOAD_ENABLED
// add body-frame force due to slung payload
void Aircraft::add_slungpayload_forces(Vector3f &body_accel)
// add body-frame force due to slung payload and tether
void Aircraft::add_external_forces(Vector3f &body_accel)
{
Vector3f forces_ef;
sitl->models.slung_payload_sim.get_forces_on_vehicle(forces_ef);
Vector3f total_force;
#if AP_SIM_SLUNGPAYLOAD_ENABLED
Vector3f forces_ef_slung;
sitl->models.slung_payload_sim.get_forces_on_vehicle(forces_ef_slung);
total_force += forces_ef_slung;
#endif

#if AP_SIM_TETHER_ENABLED
Vector3f forces_ef_tether;
sitl->models.tether_sim.get_forces_on_vehicle(forces_ef_tether);
total_force += forces_ef_tether;
#endif

// convert ef forces to body-frame accelerations (acceleration = force / mass)
const Vector3f accel_bf = dcm.transposed() * forces_ef / mass;
body_accel += accel_bf;
const Vector3f accel_bf_tether = dcm.transposed() * total_force / mass;
body_accel += accel_bf_tether;
}
#endif

/*
get position relative to home
Expand Down
6 changes: 2 additions & 4 deletions libraries/SITL/SIM_Aircraft.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,8 @@ class Aircraft {
void add_shove_forces(Vector3f &rot_accel, Vector3f &body_accel);
void add_twist_forces(Vector3f &rot_accel);

#if AP_SIM_SLUNGPAYLOAD_ENABLED
// add body-frame force due to slung payload
void add_slungpayload_forces(Vector3f &body_accel);
#endif
// add body-frame force due to payload
void add_external_forces(Vector3f &body_accel);

// get local thermal updraft
float get_local_updraft(const Vector3d &currentPos);
Expand Down
8 changes: 3 additions & 5 deletions libraries/SITL/SIM_Multicopter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,10 @@ void MultiCopter::calculate_forces(const struct sitl_input &input, Vector3f &rot
add_shove_forces(rot_accel, body_accel);
add_twist_forces(rot_accel);

#if AP_SIM_SLUNGPAYLOAD_ENABLED
// add forces from slung payload
add_slungpayload_forces(body_accel);
#endif
// add forces from slung payload or tether payload
add_external_forces(body_accel);
}

/*
update the multicopter simulation by one time step
*/
Expand Down
Loading
Loading