Skip to content

Commit 9b342b3

Browse files
committed
add getPort
1 parent 48e2567 commit 9b342b3

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

include/hardware/IMU/V5InertialSensor.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,22 @@ class V5InertialSensor : public IMU {
4646
* @endcode
4747
*/
4848
static V5InertialSensor from_pros_imu(pros::Imu imu, Number scalar = 1.0);
49+
/**
50+
* @brief Get the port the inertial sensor is connected to
51+
*
52+
* This function returns the port number of the inertial sensor.
53+
*
54+
* @return SmartPort the port the inertial sensor is connected to
55+
*
56+
* @b Example:
57+
* @code {.cpp}
58+
* void initialize() {
59+
* lemlib::V5InertialSensor imu(1);
60+
* std::cout << "Inertial sensor is connected to port " << imu.getPort() << std::endl;
61+
* }
62+
* @endcode
63+
*/
64+
SmartPort getPort() const;
4965
/**
5066
* @brief calibrate the V5 Inertial Sensor
5167
*

src/hardware/IMU/V5InertialSensor.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "hardware/IMU/V5InertialSensor.hpp"
22
#include "hardware/Port.hpp"
33
#include "pros/imu.hpp"
4+
#include <cstdint>
45
#include <mutex>
56

67
namespace lemlib {
@@ -17,6 +18,12 @@ V5InertialSensor V5InertialSensor::from_pros_imu(pros::IMU imu, Number scalar) {
1718
return V5InertialSensor({imu.get_port(), runtime_check_port}, scalar);
1819
}
1920

21+
SmartPort V5InertialSensor::getPort() const {
22+
std::lock_guard lock(m_mutex);
23+
SmartPort port(m_imu.get_port(),DynamicPort{});
24+
return port;
25+
}
26+
2027
int32_t V5InertialSensor::calibrate() {
2128
std::lock_guard lock(m_mutex);
2229
m_offset = 0_stRot;

0 commit comments

Comments
 (0)