Skip to content

Commit

Permalink
switch back to shared_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
SizzinSeal committed Oct 17, 2023
1 parent fd8903f commit 691c8c6
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions include/lemlib/devices/encoder/motor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MotorEncoder : public Encoder {
* @param motors pointer to the motor group to be used
* @param rpm output rpm
*/
MotorEncoder(std::unique_ptr<pros::MotorGroup>&& motors, float rpm);
MotorEncoder(std::shared_ptr<pros::MotorGroup> motors, float rpm);

/**
* @brief Get the angle rotated by the motor encoders, in radians
Expand All @@ -31,7 +31,7 @@ class MotorEncoder : public Encoder {
*/
bool reset() const override;
private:
std::unique_ptr<pros::MotorGroup> motors;
std::shared_ptr<pros::MotorGroup> motors;
const float rpm;
};
} // namespace lemlib
2 changes: 1 addition & 1 deletion include/lemlib/devices/trackingWheel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class TrackingWheel {
* @param offset distance between the wheel and the tracking center, in inches
* @param rpm of the rpm of the wheels the motor group is driving
*/
TrackingWheel(std::unique_ptr<pros::MotorGroup>&& motors, float diameter, float offset, float rpm);
TrackingWheel(std::shared_ptr<pros::MotorGroup> motors, float diameter, float offset, float rpm);
/**
* @brief Create a new optical encoder tracking wheel
*
Expand Down
4 changes: 2 additions & 2 deletions src/lemlib/chassis/odom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ void Odometry::calibrate(bool calibrateIMU) {
}
// substitute tracking wheels with a side of the drivetrain if needed
if (sensors.vertical1 == nullptr)
sensors.vertical1 = new TrackingWheel(std::unique_ptr<pros::MotorGroup>(drive.leftMotors), drive.wheelDiameter,
sensors.vertical1 = new TrackingWheel(std::shared_ptr<pros::MotorGroup>(drive.leftMotors), drive.wheelDiameter,
-(drive.trackWidth / 2), drive.rpm);
if (sensors.vertical2 == nullptr)
sensors.vertical2 = new TrackingWheel(std::unique_ptr<pros::MotorGroup>(drive.rightMotors), drive.wheelDiameter,
sensors.vertical2 = new TrackingWheel(std::shared_ptr<pros::MotorGroup>(drive.rightMotors), drive.wheelDiameter,
drive.trackWidth / 2, drive.rpm);
// calibrate the tracking wheels
sensors.vertical1->reset();
Expand Down
2 changes: 1 addition & 1 deletion src/lemlib/devices/encoder/motor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* a reference, due to limitations in PROS 3. This is fixed in PROS 4, but
* we have to deal with this for now.
*/
lemlib::MotorEncoder::MotorEncoder(std::unique_ptr<pros::MotorGroup>&& motors, float rpm)
lemlib::MotorEncoder::MotorEncoder(std::shared_ptr<pros::MotorGroup> motors, float rpm)
: motors(std::move(motors)),
rpm(rpm) {}

Expand Down
5 changes: 2 additions & 3 deletions src/lemlib/devices/trackingWheel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ lemlib::TrackingWheel::TrackingWheel(std::shared_ptr<Encoder> encoder, float dia
* We pass a pointer to a motor group instead of a reference motor group due to a
* limitation of PROS 3. This is fixed in PROS 4, but its not ready for release yet
*/
lemlib::TrackingWheel::TrackingWheel(std::unique_ptr<pros::MotorGroup>&& motors, float diameter, float offset,
float rpm)
: encoder(new MotorEncoder(std::move(motors), rpm)),
lemlib::TrackingWheel::TrackingWheel(std::shared_ptr<pros::MotorGroup> motors, float diameter, float offset, float rpm)
: encoder(std::make_shared<MotorEncoder>(MotorEncoder(motors, rpm))),
diameter(diameter),
offset(offset) {}

Expand Down

0 comments on commit 691c8c6

Please sign in to comment.