From 9b342b386c9d3fc792a1d6ff31bd1d71d3daa8ba Mon Sep 17 00:00:00 2001 From: toxicdefender404 Date: Sun, 13 Apr 2025 20:40:43 +0100 Subject: [PATCH 1/2] add getPort --- include/hardware/IMU/V5InertialSensor.hpp | 16 ++++++++++++++++ src/hardware/IMU/V5InertialSensor.cpp | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/include/hardware/IMU/V5InertialSensor.hpp b/include/hardware/IMU/V5InertialSensor.hpp index f202ad3..53c7d0e 100644 --- a/include/hardware/IMU/V5InertialSensor.hpp +++ b/include/hardware/IMU/V5InertialSensor.hpp @@ -46,6 +46,22 @@ class V5InertialSensor : public IMU { * @endcode */ static V5InertialSensor from_pros_imu(pros::Imu imu, Number scalar = 1.0); + /** + * @brief Get the port the inertial sensor is connected to + * + * This function returns the port number of the inertial sensor. + * + * @return SmartPort the port the inertial sensor is connected to + * + * @b Example: + * @code {.cpp} + * void initialize() { + * lemlib::V5InertialSensor imu(1); + * std::cout << "Inertial sensor is connected to port " << imu.getPort() << std::endl; + * } + * @endcode + */ + SmartPort getPort() const; /** * @brief calibrate the V5 Inertial Sensor * diff --git a/src/hardware/IMU/V5InertialSensor.cpp b/src/hardware/IMU/V5InertialSensor.cpp index 992a4b2..abcb4b2 100644 --- a/src/hardware/IMU/V5InertialSensor.cpp +++ b/src/hardware/IMU/V5InertialSensor.cpp @@ -1,6 +1,7 @@ #include "hardware/IMU/V5InertialSensor.hpp" #include "hardware/Port.hpp" #include "pros/imu.hpp" +#include #include namespace lemlib { @@ -17,6 +18,12 @@ V5InertialSensor V5InertialSensor::from_pros_imu(pros::IMU imu, Number scalar) { return V5InertialSensor({imu.get_port(), runtime_check_port}, scalar); } +SmartPort V5InertialSensor::getPort() const { + std::lock_guard lock(m_mutex); + SmartPort port(m_imu.get_port(),DynamicPort{}); + return port; +} + int32_t V5InertialSensor::calibrate() { std::lock_guard lock(m_mutex); m_offset = 0_stRot; From c6a4e780400d3c4efd307269c3c93bbc0bb70e30 Mon Sep 17 00:00:00 2001 From: toxicdefender404 Date: Sun, 13 Apr 2025 20:46:21 +0100 Subject: [PATCH 2/2] fix formatting --- include/hardware/IMU/V5InertialSensor.hpp | 28 +++++++++++------------ src/hardware/IMU/V5InertialSensor.cpp | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/include/hardware/IMU/V5InertialSensor.hpp b/include/hardware/IMU/V5InertialSensor.hpp index 53c7d0e..67c12a9 100644 --- a/include/hardware/IMU/V5InertialSensor.hpp +++ b/include/hardware/IMU/V5InertialSensor.hpp @@ -47,20 +47,20 @@ class V5InertialSensor : public IMU { */ static V5InertialSensor from_pros_imu(pros::Imu imu, Number scalar = 1.0); /** - * @brief Get the port the inertial sensor is connected to - * - * This function returns the port number of the inertial sensor. - * - * @return SmartPort the port the inertial sensor is connected to - * - * @b Example: - * @code {.cpp} - * void initialize() { - * lemlib::V5InertialSensor imu(1); - * std::cout << "Inertial sensor is connected to port " << imu.getPort() << std::endl; - * } - * @endcode - */ + * @brief Get the port the inertial sensor is connected to + * + * This function returns the port number of the inertial sensor. + * + * @return SmartPort the port the inertial sensor is connected to + * + * @b Example: + * @code {.cpp} + * void initialize() { + * lemlib::V5InertialSensor imu(1); + * std::cout << "Inertial sensor is connected to port " << imu.getPort() << std::endl; + * } + * @endcode + */ SmartPort getPort() const; /** * @brief calibrate the V5 Inertial Sensor diff --git a/src/hardware/IMU/V5InertialSensor.cpp b/src/hardware/IMU/V5InertialSensor.cpp index abcb4b2..41e410a 100644 --- a/src/hardware/IMU/V5InertialSensor.cpp +++ b/src/hardware/IMU/V5InertialSensor.cpp @@ -20,7 +20,7 @@ V5InertialSensor V5InertialSensor::from_pros_imu(pros::IMU imu, Number scalar) { SmartPort V5InertialSensor::getPort() const { std::lock_guard lock(m_mutex); - SmartPort port(m_imu.get_port(),DynamicPort{}); + SmartPort port(m_imu.get_port(), DynamicPort {}); return port; }