From 01e6c64523cb8dbd4854143221436d2484e65470 Mon Sep 17 00:00:00 2001 From: alekskl01 Date: Sun, 12 Nov 2023 13:47:24 +0100 Subject: [PATCH] removed non-functioning test file. --- .../tests/test_thruster_interface.cpp | 173 ------------------ 1 file changed, 173 deletions(-) delete mode 100644 motion/thruster_interface/tests/test_thruster_interface.cpp diff --git a/motion/thruster_interface/tests/test_thruster_interface.cpp b/motion/thruster_interface/tests/test_thruster_interface.cpp deleted file mode 100644 index 301ae9a4..00000000 --- a/motion/thruster_interface/tests/test_thruster_interface.cpp +++ /dev/null @@ -1,173 +0,0 @@ -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include -#include - -float desired_force = 0; - -float interpolate(const std::map &pwm_table, float force) { - auto upper_bound = pwm_table.upper_bound(force); - if (upper_bound == pwm_table.end()) { - --upper_bound; - } - auto lower_bound = std::prev(upper_bound); - - if (lower_bound == pwm_table.end()) { - return upper_bound->second; - } - - float force1 = lower_bound->first; - float force2 = upper_bound->first; - float pwm1 = lower_bound->second; - float pwm2 = upper_bound->second; - - if (force1 == force2) { - return pwm1; - } - - return std::round( - pwm1 + ((force - force1) * (pwm2 - pwm1)) / (force2 - force1) + 0.5); -} - -std::vector pwm_to_bytes(const std::vector &pwm_values) { - std::vector bytes; - for (const auto &val : pwm_values) { - // Ensure the value is in the correct range and cast to an integer - int pwm_int = static_cast(std::min(std::max(val, 1100), 1900)); - - // Split the integer into most significant byte (MSB) and least significant - // byte (LSB) - uint8_t msb = (pwm_int >> 8) & 0xFF; - uint8_t lsb = pwm_int & 0xFF; - - // Add MSB and LSB to the bytes vector - bytes.push_back(msb); - bytes.push_back(lsb); - } - return bytes; -} - -// int main() { -// // Create an empty map -// std::map pwm_table; - -// // Open the data file -// std::ifstream data("../config/ThrustMe_P1000_force_mapping.csv"); - -// if (!data.is_open()) { -// std::cerr << "Unable to open file\n"; -// return 1; -// } - -// std::string line; -// // Ignore the header line -// std::getline(data, line); - -// while (std::getline(data, line)) { -// std::istringstream stream(line); - -// std::string force_str, pwm_str; - -// std::getline(stream, force_str, '\t'); -// std::getline(stream, pwm_str); - -// double force = std::stod(force_str); -// double pwm = std::stod(pwm_str); - -// pwm_table[force] = pwm; -// } - -// const int I2C_BUS = 1; -// const int I2C_ADDRESS = 0x21; - -// int file = open("/dev/i2c-1", O_RDWR); -// if (file < 0) { -// std::cerr << "Error opening device\n"; -// return 1; -// } - -// if (ioctl(file, I2C_SLAVE, I2C_ADDRESS) < 0) { -// std::cerr << "Error setting I2C address\n"; -// return 1; -// } - -// for (int i = 0; i <= 10; i++) { -// std::cout << i << ": "; -// float desired_force_thr_1 = 0.0; // 12000 - 250*i; -// float desired_force_thr_2 = 0.0; //-5000 + 500*i; //12000 - 250*i; -// float desired_force_thr_3 = 0.0; //-5000 + 500*i; //0.0; //12000 - 250*i; -// float desired_force_thr_4 = 0.0; //-5000 + 500 * i; // 12000 - 250*i; - -// int pwm_thr_1 = interpolate(pwm_table, desired_force_thr_1); -// int pwm_thr_2 = interpolate(pwm_table, desired_force_thr_2); -// int pwm_thr_3 = interpolate(pwm_table, desired_force_thr_3); -// int pwm_thr_4 = interpolate(pwm_table, desired_force_thr_4); - -// std::vector pwm_values = {pwm_thr_1, pwm_thr_2, pwm_thr_3, -// pwm_thr_4}; std::vector pwm_bytes = pwm_to_bytes(pwm_values); - -// int data_size = pwm_bytes.size(); - -// // Send the I2C message -// auto write_feedback = write(file, pwm_bytes.data(), data_size); -// if (write_feedback != data_size) { -// std::cerr << "Feedback: " << write_feedback << " Data size: " << -// data_size -// << ". Error sending data, ignoring...\n"; -// } else { -// std::cout << "Feedback: " << write_feedback << " Data size: " << -// data_size -// << " Data sent successfully!\n"; -// } - -// close(file); -// std::this_thread::sleep_for(std::chrono::milliseconds(1000)); -// } -// return 0; -// } - -// #include -// #include - -// TEST(ThrusterInterfaceTest, InterpolateTest) { -// ThrusterInterface thruster_interface("mapping_file.txt"); -// std::map pwm_table = {{0.0, 1000.0}, {1.0, 2000.0}}; -// float force = 0.5; -// float expected_pwm = 1500.0; -// float actual_pwm = thruster_interface.interpolate(pwm_table, force); -// EXPECT_FLOAT_EQ(expected_pwm, actual_pwm); -// } - -// TEST(ThrusterInterfaceTest, PwmToBytesTest) { -// ThrusterInterface thruster_interface("mapping_file.txt"); -// std::vector pwm_values = {1000, 1500, 2000}; -// std::vector expected_bytes = {0x03, 0xE8, 0x05, 0xDC, 0x07, 0xD0}; -// std::vector actual_bytes = -// thruster_interface.pwm_to_bytes(pwm_values); EXPECT_EQ(expected_bytes, -// actual_bytes); -// } - -// TEST(ThrusterInterfaceTest, PublishThrustToEscsTest) { -// ThrusterInterface thruster_interface("mapping_file.txt"); -// std::vector forces = {0.0, 0.0, 0.0, 0.0}; -// thruster_interface.publish_thrust_to_escs(forces); -// // TODO: Add expectations for the publish_thrust_to_escs function -// } - -// int main(int argc, char **argv) { -// testing::InitGoogleTest(&argc, argv); -// return RUN_ALL_TESTS(); -// }