From 637aec00853015eaaccab40217a6338164cffce1 Mon Sep 17 00:00:00 2001 From: muramura Date: Fri, 27 Sep 2024 12:59:50 +1000 Subject: [PATCH] SITL: Change division to multiplication --- libraries/SITL/SIM_Gripper_EPM.cpp | 8 ++++---- libraries/SITL/SIM_Gripper_Servo.cpp | 2 +- libraries/SITL/SIM_RF_LightWareSerial.cpp | 2 +- libraries/SITL/SIM_RF_NMEA.cpp | 2 +- libraries/SITL/SIM_RF_Wasp.cpp | 2 +- libraries/SITL/SIM_Sprayer.cpp | 2 +- libraries/SITL/SITL.cpp | 10 +++++----- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/libraries/SITL/SIM_Gripper_EPM.cpp b/libraries/SITL/SIM_Gripper_EPM.cpp index 09f73102a4..c2b4e91b35 100644 --- a/libraries/SITL/SIM_Gripper_EPM.cpp +++ b/libraries/SITL/SIM_Gripper_EPM.cpp @@ -68,16 +68,16 @@ void Gripper_EPM::update_from_demand() const float dt = (now - last_update_us) * 1.0e-6f; // decay the field - field_strength = field_strength * (100.0f - field_decay_rate * dt) / 100.0f; + field_strength = field_strength * (100.0f - field_decay_rate * dt) * 0.01f; // note that "demand" here is just an on/off switch; we only care // about which range it falls into if (demand > 0.6f) { // we are instructed to grip harder - field_strength = field_strength + (100.0f - field_strength) * field_strength_slew_rate / 100.0f * dt; + field_strength = field_strength + (100.0f - field_strength) * field_strength_slew_rate * 0.01f * dt; } else if (demand < 0.4f) { // we are instructed to loosen grip - field_strength = field_strength * (100.0f - field_degauss_rate * dt) / 100.0f; + field_strength = field_strength * (100.0f - field_degauss_rate * dt) * 0.01f; } else { // neutral; no demanded change } @@ -121,5 +121,5 @@ float Gripper_EPM::tesla() const // https://en.wikipedia.org/wiki/Orders_of_magnitude_(magnetic_field) // 200N lifting capacity ~= 2.5T const float percentage_to_tesla = 0.25f; - return static_cast(percentage_to_tesla * field_strength / 100.0f); + return static_cast(percentage_to_tesla * field_strength * 0.01f); } diff --git a/libraries/SITL/SIM_Gripper_Servo.cpp b/libraries/SITL/SIM_Gripper_Servo.cpp index 2237e69a12..d1b95c394d 100644 --- a/libraries/SITL/SIM_Gripper_Servo.cpp +++ b/libraries/SITL/SIM_Gripper_Servo.cpp @@ -89,7 +89,7 @@ void Gripper_Servo::update(const struct sitl_input &input) position_demand = position; } - const float position_max_change = position_slew_rate / 100.0f * dt; + const float position_max_change = position_slew_rate * 0.01f * dt; position = constrain_float(position_demand, position - position_max_change, position + position_max_change); float jaw_gap; if ((release_pwm < grab_pwm && reverse) || (release_pwm > grab_pwm && !reverse)) { diff --git a/libraries/SITL/SIM_RF_LightWareSerial.cpp b/libraries/SITL/SIM_RF_LightWareSerial.cpp index bf44e40806..fefa21c4ba 100644 --- a/libraries/SITL/SIM_RF_LightWareSerial.cpp +++ b/libraries/SITL/SIM_RF_LightWareSerial.cpp @@ -55,5 +55,5 @@ uint32_t RF_LightWareSerial::packet_for_alt(uint16_t alt_cm, uint8_t *buffer, ui alt_cm = 13000; // from datasheet } - return snprintf((char*)buffer, buflen, "%0.2f\r", alt_cm / 100.0f); // note tragic lack of snprintf return checking + return snprintf((char*)buffer, buflen, "%0.2f\r", alt_cm * 0.01f); // note tragic lack of snprintf return checking } diff --git a/libraries/SITL/SIM_RF_NMEA.cpp b/libraries/SITL/SIM_RF_NMEA.cpp index 6f5f1aceff..4da7a2769d 100644 --- a/libraries/SITL/SIM_RF_NMEA.cpp +++ b/libraries/SITL/SIM_RF_NMEA.cpp @@ -30,7 +30,7 @@ uint32_t RF_NMEA::packet_for_alt(uint16_t alt_cm, uint8_t *buffer, uint8_t bufle // Format 2 DBT NMEA mode (e.g. $SMDBT,5.94,f,1.81,M,67) // Format 3 DPT NMEA mode (e.g. $SMDPT,1.81,0.066) - ssize_t ret = snprintf((char*)buffer, buflen, "$SMDPT,%f,%f", alt_cm/100.0f, 0.01f); + ssize_t ret = snprintf((char*)buffer, buflen, "$SMDPT,%f,%f", alt_cm*0.01f, 0.01f); uint8_t checksum = 0; for (uint8_t i=1; i