Skip to content

Commit ef61ebf

Browse files
snktshrmapeterbarker
authored andcommitted
SITL: Added damping factor to the tether dynamics
1 parent bc48455 commit ef61ebf

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

libraries/SITL/SIM_Tether.cpp

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ const AP_Param::GroupInfo TetherSim::var_info[] = {
7575
// @User: Advanced
7676
AP_GROUPINFO("SPGCNST", 6, TetherSim, tether_spring_constant, 100),
7777

78+
// @Param: DMPCNST
79+
// @DisplayName: Tether Damping Constant
80+
// @Description: Damping constant for the tether to simulate resistance based on change in stretch
81+
// @Range: 0 255
82+
// @User: Advanced
83+
AP_GROUPINFO("DMPCNST", 7, TetherSim, tether_damping_constant, 10),
84+
7885
AP_GROUPEND
7986
};
8087

@@ -266,33 +273,40 @@ void TetherSim::update_tether_force(const Location& veh_pos, float dt)
266273
// Calculate the stretch beyond the maximum length
267274
float stretch = MAX(tether_length - max_line_length, 0.0f);
268275

269-
// Apply a spring-like penalty force proportional to the stretch
270-
float penalty_force_magnitude = tether_spring_constant * stretch;
276+
// Calculate the stretch rate beyond the maximum length
277+
float stretch_rate = (stretch - prev_stretch)/dt;
278+
279+
// Apply a spring and damping penalty force proportional to the stretch
280+
float penalty_force_magnitude = tether_spring_constant * stretch + tether_damping_constant * stretch_rate;
271281

272282
// Direction of force is along the tether, pulling toward the anchor
273-
veh_forces_ef = tether_vector.normalized() * penalty_force_magnitude;
283+
veh_forces_teth = tether_vector.normalized() * penalty_force_magnitude;
274284

275285
GCS_SEND_TEXT(MAV_SEVERITY_WARNING, "Tether: Exceeded maximum length.");
276286

277-
return;
278-
}
287+
prev_stretch = stretch;
279288

280-
if (tether_stuck) {
289+
} else if (tether_stuck) {
281290

282291
// Calculate the stretch beyond the maximum length
283292
float stretch = MAX(tether_length - tether_not_stuck_length, 0.0f);
284293

294+
// Calculate the stretch rate beyond the maximum length
295+
float stretch_rate = (stretch - prev_stretch)/dt;
296+
285297
// Apply a spring-like penalty force proportional to the stretch
286-
float penalty_force_magnitude = tether_spring_constant * stretch;
298+
float penalty_force_magnitude = tether_spring_constant * stretch + tether_damping_constant * stretch_rate;
287299

288300
// Direction of force is directly along the tether, towards the tether anchor point
289-
veh_forces_ef = tether_vector.normalized() * penalty_force_magnitude;
301+
veh_forces_teth = tether_vector.normalized() * penalty_force_magnitude;
290302

291303
GCS_SEND_TEXT(MAV_SEVERITY_WARNING, "Tether: Stuck.");
292304

293-
return;
305+
prev_stretch = stretch;
306+
294307
} else {
295308
tether_not_stuck_length = tether_length;
309+
veh_forces_teth.zero();
296310
}
297311

298312
// Step 3: Calculate the weight of the tether being lifted
@@ -302,8 +316,8 @@ void TetherSim::update_tether_force(const Location& veh_pos, float dt)
302316
// Step 4: Calculate the tension force
303317
Vector3f tension_force_NED = tether_vector.normalized() * tether_weight_force;
304318

305-
// Step 5: Apply the force to the vehicle
306-
veh_forces_ef = tension_force_NED;
319+
// Step 5: Apply the total force to the vehicle
320+
veh_forces_ef = veh_forces_teth + tension_force_NED;
307321
}
308322

309323
#endif

libraries/SITL/SIM_Tether.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class TetherSim {
5555
AP_Int8 sys_id; // MAVLink system ID for GCS reporting
5656
AP_Int8 tether_stuck; // Set to 1 to simulate a stuck tether
5757
AP_Float tether_spring_constant; // Spring constant for modeling tether stretch
58+
AP_Float tether_damping_constant; // Damping constant
5859

5960
// Send MAVLink messages to the GCS
6061
void send_report();
@@ -85,7 +86,9 @@ class TetherSim {
8586
mavlink_status_t mav_status; // Status of MAVLink communication
8687

8788
// Tether simulation variables
88-
Vector3f veh_forces_ef; // Earth-frame forces on the vehicle due to the tether
89+
float prev_stretch = 0.0f; // store stretch beyond maximum in last calculation
90+
Vector3f veh_forces_ef; // Effective Earth-frame forces on the vehicle due to the tether
91+
Vector3f veh_forces_teth; // Earth-frame forces on the vehicle due to the spring and damping forces on tether
8992
float tether_length = 0.0f; // Current tether length in meters
9093
float tether_not_stuck_length = 0.0f; // Tether length when the tether is not stuck
9194
};

0 commit comments

Comments
 (0)