Skip to content

Commit

Permalink
make some encoder methods const
Browse files Browse the repository at this point in the history
  • Loading branch information
SizzinSeal committed Jan 18, 2025
1 parent 50f8ad7 commit 7ba7c85
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 73 deletions.
6 changes: 3 additions & 3 deletions include/hardware/Encoder/ADIEncoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class ADIEncoder : public Encoder {
* @return INT_MAX if there is an error, setting errno
*/
[[deprecated("This function is not implemented due to hardware limitations")]]
int isConnected() override;
int32_t isConnected() const override;
/**
* @brief Get the relative angle measured by the encoder
*
Expand All @@ -109,7 +109,7 @@ class ADIEncoder : public Encoder {
* }
* @endcode
*/
Angle getAngle() override;
Angle getAngle() const override;
/**
* @brief Set the relative angle of the encoder
*
Expand Down Expand Up @@ -138,7 +138,7 @@ class ADIEncoder : public Encoder {
* }
* @endcode
*/
int setAngle(Angle angle) override;
int32_t setAngle(Angle angle) override;
private:
mutable pros::Mutex m_mutex;
pros::adi::Encoder m_encoder;
Expand Down
6 changes: 3 additions & 3 deletions include/hardware/Encoder/Encoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Encoder {
* }
* @endcode
*/
virtual int isConnected() = 0;
virtual int32_t isConnected() const = 0;
/**
* @brief Get the relative angle measured by the encoder
*
Expand All @@ -56,7 +56,7 @@ class Encoder {
* }
* @endcode
*/
virtual Angle getAngle() = 0;
virtual Angle getAngle() const = 0;
/**
* @brief Set the relative angle of the encoder
*
Expand All @@ -80,7 +80,7 @@ class Encoder {
* }
* @endcode
*/
virtual int setAngle(Angle angle) = 0;
virtual int32_t setAngle(Angle angle) = 0;
virtual ~Encoder() = default;
};
} // namespace lemlib
10 changes: 5 additions & 5 deletions include/hardware/Encoder/V5RotationSensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class V5RotationSensor : public Encoder {
* }
* @endcode
*/
int isConnected() override;
int32_t isConnected() const override;
/**
* @brief Get the relative angle measured by the V5 Rotation Sensor
*
Expand Down Expand Up @@ -96,7 +96,7 @@ class V5RotationSensor : public Encoder {
* }
* @endcode
*/
Angle getAngle() override;
Angle getAngle() const override;
/**
* @brief Set the relative angle of the V5 Rotation Sensor
*
Expand Down Expand Up @@ -125,7 +125,7 @@ class V5RotationSensor : public Encoder {
* }
* @endcode
*/
int setAngle(Angle angle) override;
int32_t setAngle(Angle angle) override;
/**
* @brief returns whether the V5 Rotation Sensor is reversed or not
*
Expand All @@ -145,7 +145,7 @@ class V5RotationSensor : public Encoder {
* }
* @endcode
*/
int isReversed() const;
int32_t isReversed() const;
/**
* @brief Set whether the V5 Rotation Sensor is reversed or not
*
Expand All @@ -166,7 +166,7 @@ class V5RotationSensor : public Encoder {
* }
* @endcode
*/
int setReversed(bool reversed);
int32_t setReversed(bool reversed);
private:
mutable pros::Mutex m_mutex;
Angle m_offset = 0_stRot;
Expand Down
28 changes: 14 additions & 14 deletions include/hardware/Motor/Motor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Motor : public Encoder {
* }
* @endcode
*/
int move(Number percent);
int32_t move(Number percent);
/**
* @brief move the motor at a given angular velocity
*
Expand All @@ -103,7 +103,7 @@ class Motor : public Encoder {
* }
* @endcode
*/
int moveVelocity(AngularVelocity velocity);
int32_t moveVelocity(AngularVelocity velocity);
/**
* @brief brake the motor
*
Expand All @@ -127,7 +127,7 @@ class Motor : public Encoder {
* }
* @endcode
*/
int brake();
int32_t brake();
/**
* @brief set the brake mode of the motor
*
Expand All @@ -153,7 +153,7 @@ class Motor : public Encoder {
* }
* @endcode
*/
int setBrakeMode(BrakeMode mode);
int32_t setBrakeMode(BrakeMode mode);
/**
* @brief get the brake mode of the motor
*
Expand Down Expand Up @@ -203,7 +203,7 @@ class Motor : public Encoder {
* }
* @endcode
*/
int isConnected() override;
int32_t isConnected() const override;
/**
* @brief Get the relative angle measured by the motor
*
Expand All @@ -230,7 +230,7 @@ class Motor : public Encoder {
* }
* @endcode
*/
Angle getAngle() override;
Angle getAngle() const override;
/**
* @brief Set the relative angle of the motor
*
Expand Down Expand Up @@ -261,7 +261,7 @@ class Motor : public Encoder {
* }
* @endcode
*/
int setAngle(Angle angle) override;
int32_t setAngle(Angle angle) override;
/**
* @brief Get the offset of the motor encoder
*
Expand Down Expand Up @@ -312,7 +312,7 @@ class Motor : public Encoder {
* }
* @endcode
*/
int setOffset(Angle offset);
int32_t setOffset(Angle offset);
/**
* @brief Get the type of the motor
*
Expand Down Expand Up @@ -343,7 +343,7 @@ class Motor : public Encoder {
* }
* @endcode
*/
MotorType getType();
MotorType getType() const;
/**
* @brief get whether the motor is reversed
*
Expand All @@ -364,7 +364,7 @@ class Motor : public Encoder {
* }
* @endcode
*/
int isReversed() const;
int32_t isReversed() const;
/**
* @brief set whether the motor should be reversed or not
*
Expand All @@ -380,7 +380,7 @@ class Motor : public Encoder {
* }
* @endcode
*/
int setReversed(bool reversed);
int32_t setReversed(bool reversed);
/**
* @brief Get the port the motor is connected to
*
Expand Down Expand Up @@ -445,7 +445,7 @@ class Motor : public Encoder {
* }
* @endcode
*/
int setCurrentLimit(Current limit);
int32_t setCurrentLimit(Current limit);
/**
* @brief Get the temperature of the motor
*
Expand Down Expand Up @@ -488,7 +488,7 @@ class Motor : public Encoder {
* }
* @endcode
*/
int setOutputVelocity(AngularVelocity outputVelocity);
int32_t setOutputVelocity(AngularVelocity outputVelocity);
/**
* @brief Get the output velocity of the motor
*
Expand All @@ -503,7 +503,7 @@ class Motor : public Encoder {
* }
* @endcode
*/
AngularVelocity getOutputVelocity();
AngularVelocity getOutputVelocity() const;
private:
mutable pros::Mutex m_mutex;
AngularVelocity m_outputVelocity;
Expand Down
26 changes: 13 additions & 13 deletions include/hardware/Motor/MotorGroup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class MotorGroup : public Encoder {
* }
* @endcode
*/
int move(Number percent);
int32_t move(Number percent);
/**
* @brief move the motors at a given angular velocity
*
Expand All @@ -117,7 +117,7 @@ class MotorGroup : public Encoder {
* }
* @endcode
*/
int moveVelocity(AngularVelocity velocity);
int32_t moveVelocity(AngularVelocity velocity);
/**
* @brief brake the motors
*
Expand All @@ -142,7 +142,7 @@ class MotorGroup : public Encoder {
* }
* @endcode
*/
int brake();
int32_t brake();
/**
* @brief set the brake mode of the motors
*
Expand All @@ -163,7 +163,7 @@ class MotorGroup : public Encoder {
* }
* @endcode
*/
int setBrakeMode(BrakeMode mode);
int32_t setBrakeMode(BrakeMode mode);
/**
* @brief get the brake mode of the motor group
*
Expand Down Expand Up @@ -210,7 +210,7 @@ class MotorGroup : public Encoder {
* }
* @endcode
*/
int isConnected() override;
int32_t isConnected() const override;
/**
* @brief Get the average relative angle measured by the motors
*
Expand Down Expand Up @@ -238,7 +238,7 @@ class MotorGroup : public Encoder {
* }
* @endcode
*/
Angle getAngle() override;
Angle getAngle() const override;
/**
* @brief Set the relative angle of all the motors
*
Expand Down Expand Up @@ -267,7 +267,7 @@ class MotorGroup : public Encoder {
* }
* @endcode
*/
int setAngle(Angle angle) override;
int32_t setAngle(Angle angle) override;
/**
* @brief Get the combined current limit of all motors in the group
*
Expand Down Expand Up @@ -318,7 +318,7 @@ class MotorGroup : public Encoder {
* }
* @endcode
*/
int setCurrentLimit(Current limit);
int32_t setCurrentLimit(Current limit);
/**
* @brief Get the temperatures of the motors in the motor group
*
Expand Down Expand Up @@ -363,7 +363,7 @@ class MotorGroup : public Encoder {
* }
* @endcode
*/
int setOutputVelocity(AngularVelocity outputVelocity);
int32_t setOutputVelocity(AngularVelocity outputVelocity);
/**
* @brief Get the output velocity of the motor group
*
Expand Down Expand Up @@ -392,7 +392,7 @@ class MotorGroup : public Encoder {
* }
* @endcode
*/
int getSize() const;
int32_t getSize() const;
/**
* @brief Add a motor to the motor group
*
Expand Down Expand Up @@ -421,7 +421,7 @@ class MotorGroup : public Encoder {
* }
* @endcode
*/
int addMotor(ReversibleSmartPort port);
int32_t addMotor(ReversibleSmartPort port);
/**
* @brief Add a motor to the motor group
*
Expand All @@ -446,7 +446,7 @@ class MotorGroup : public Encoder {
* }
* @endcode
*/
int addMotor(Motor motor);
int32_t addMotor(Motor motor);
/**
* @brief Add a motor to the motor group
*
Expand All @@ -472,7 +472,7 @@ class MotorGroup : public Encoder {
* }
* @endcode
*/
int addMotor(Motor motor, bool reversed);
int32_t addMotor(Motor motor, bool reversed);
/**
* @brief Remove a motor from the motor group
*
Expand Down
6 changes: 3 additions & 3 deletions src/hardware/Encoder/ADIEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ADIEncoder::ADIEncoder(const ADIEncoder& other)
: m_encoder(other.m_encoder),
m_offset(other.m_offset) {}

int ADIEncoder::isConnected() {
int32_t ADIEncoder::isConnected() const {
// it's not possible to check if the ADIEncoder is connected, so we just return 1 to indicate that it is
// we do run a simple test however to check if the ports are valid
if (m_encoder.get_value() == INT_MAX) {
Expand All @@ -29,7 +29,7 @@ int ADIEncoder::isConnected() {
return 1;
}

Angle ADIEncoder::getAngle() {
Angle ADIEncoder::getAngle() const {
std::unique_lock lock(m_mutex);
const int raw = m_encoder.get_value();
// check for errors
Expand All @@ -41,7 +41,7 @@ Angle ADIEncoder::getAngle() {
return from_stDeg(raw) + m_offset;
}

int ADIEncoder::setAngle(Angle angle) {
int32_t ADIEncoder::setAngle(Angle angle) {
std::unique_lock lock(m_mutex);
// the Vex SDK does not support setting the relative angle of an ADI encoder to a specific value
// but we can overcome this limitation by resetting the relative angle to zero and saving an offset
Expand Down
Loading

0 comments on commit 7ba7c85

Please sign in to comment.