forked from LemLib/LemLib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'abstract_motor_pr' into refactor-master
- Loading branch information
Showing
16 changed files
with
623 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#pragma once | ||
#include "lemlib/devices/motor/abstractmotor.hpp" | ||
|
||
namespace lemlib { | ||
|
||
class Abstract_MotorGroup { | ||
protected: | ||
bool isBroken = false; | ||
|
||
std::vector<std::unique_ptr<Abstract_Motor>> motorContainer; | ||
public: | ||
virtual void spinAtVoltage(int voltage) = 0; | ||
|
||
virtual void spinPerc(int percent) = 0; | ||
|
||
virtual void spinJoystick(int joystickValue) = 0; | ||
|
||
virtual void spinAtRPM(int RPM) = 0; | ||
|
||
virtual void spinUntilDegree(int degree, int speedInVoltage) = 0; | ||
|
||
virtual void spinFor(float seconds, int speedInVoltage) = 0; | ||
|
||
virtual void logMotorPerformance() = 0; // Stuff like wattage and temperature, RPM, etc, along with Port Number | ||
|
||
virtual void shutDown() = 0; | ||
|
||
virtual void revive() = 0; | ||
|
||
virtual bool isOverheated() = 0; | ||
|
||
virtual void set_zero_position(int position) = 0; | ||
|
||
virtual std::vector<double> getPositions() = 0; | ||
|
||
virtual std::vector<int> getBaseRPMs() = 0; | ||
|
||
virtual std::vector<std::unique_ptr<Abstract_Motor>>& getMotorContainer() = 0; | ||
}; | ||
|
||
} // namespace lemlib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#pragma once | ||
#include "main.h" | ||
#include "pros/motors.h" | ||
#include "lemlib/pid.hpp" | ||
#include <memory> | ||
|
||
namespace lemlib { | ||
|
||
struct MotorInfo { | ||
int port; | ||
bool reversed; | ||
float gearRatio; | ||
int cartrpm; | ||
|
||
MotorInfo(int port, bool reversed, float gearRatio, int cartrpm) | ||
: port(port), | ||
reversed(reversed), | ||
gearRatio(gearRatio), | ||
cartrpm(cartrpm) {} | ||
}; | ||
|
||
class Abstract_Motor { | ||
protected: | ||
static constexpr int overheatTempCelsius = 55; | ||
|
||
bool isBroken = false; | ||
bool isReversed = false; | ||
bool hasPairMotor = false; | ||
|
||
int voltage = 0; | ||
|
||
float gearRatio = 0; | ||
|
||
float baseRPM = 0; | ||
public: | ||
virtual void spinAtVoltage(int voltage) = 0; | ||
|
||
virtual void spinPerc(int percent) = 0; | ||
|
||
virtual void spinJoystick(int joystickValue) = 0; | ||
|
||
virtual void spinAtRPM(int RPM) = 0; | ||
|
||
virtual void spinUntilDegree(int degree, int speedInVoltage) = 0; | ||
|
||
virtual void spinFor(float seconds, int speedInVoltage) = 0; | ||
|
||
virtual void logMotorPerformance() = 0; // Stuff like wattage and temperature, RPM, etc, along with Port Number | ||
|
||
virtual void set_zero_position(int position) = 0; | ||
|
||
virtual int getPosition() = 0; | ||
|
||
virtual void shutDown() = 0; | ||
|
||
virtual void revive() = 0; | ||
|
||
virtual bool isOverheated() = 0; | ||
|
||
virtual bool getIsBroken() = 0; | ||
|
||
virtual float getRPM() = 0; | ||
|
||
virtual float getVoltage() = 0; | ||
|
||
virtual int getPort() = 0; | ||
|
||
virtual void setGearset(int gearset) = 0; | ||
|
||
virtual int getGearset() = 0; | ||
|
||
virtual void setReversed(bool isReversed) = 0; | ||
|
||
virtual bool getIsReversed() = 0; | ||
|
||
virtual std::shared_ptr<Abstract_Motor> getPairMotor() = 0; | ||
|
||
virtual void setPID(std::shared_ptr<FAPID> pid) = 0; | ||
|
||
virtual std::shared_ptr<FAPID> getPID() = 0; | ||
|
||
virtual void setGearRatio(float gearRatio) = 0; | ||
|
||
virtual float getGearRatio() = 0; | ||
}; | ||
|
||
} // namespace lemlib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#pragma once | ||
|
||
#include "lemlib/pid.hpp" | ||
#include "lemlib/devices/motor/abstractmotor.hpp" | ||
#include "pros/motors.h" | ||
#include <memory> | ||
|
||
namespace lemlib { | ||
|
||
class PROSMotor : public Abstract_Motor { | ||
private: | ||
std::unique_ptr<pros::Motor> motor; | ||
std::shared_ptr<PROSMotor> pairMotor; | ||
|
||
std::shared_ptr<FAPID> pid; | ||
|
||
static constexpr int overheatTempCelsius = 55; | ||
|
||
bool isBroken = false; | ||
bool isReversed = false; | ||
bool hasPairMotor = false; | ||
|
||
int voltage = 0; | ||
|
||
float gearRatio; | ||
|
||
pros::motor_gearset_e gearset = pros::E_MOTOR_GEAR_GREEN; | ||
public: | ||
/** | ||
* @brief Construct a new Motor object | ||
* | ||
* @param port V5 Smart Port number | ||
* @param isReversedArg Defines direction of the motor spinning. True is reversed, false is normal. | ||
* @param gearRatioArg Gear ratio of the motors mechanism. 3:4 = .75 | ||
* @param gearset The PROS motor gearset. | ||
* @param pairMotorArg The motor paired with this motor. For example, leftFront and rightFront motors. | ||
* @param pid Built-in PID Controller for the motor. | ||
*/ | ||
PROSMotor(const uint8_t port, const bool isReversed, const float gearRatio, | ||
const int cartRPM = 600, | ||
std::shared_ptr<PROSMotor> pairMotor = nullptr, std::shared_ptr<FAPID> pid = nullptr); | ||
|
||
void spinAtVoltage(int voltage) override; | ||
|
||
void spinPerc(int percent) override; | ||
|
||
void spinJoystick(int joystickValue) override; | ||
|
||
void spinAtRPM(int RPM) override; | ||
|
||
void spinUntilDegree(int degree, int speedInVoltage) override; | ||
|
||
void spinFor(float seconds, int speedInVoltage) override; | ||
|
||
void logMotorPerformance() override; // Stuff like wattage and temperature, RPM, etc, along with Port Number | ||
|
||
void set_zero_position(int position) override; | ||
|
||
int getPosition() override; | ||
|
||
void shutDown() override; | ||
|
||
void revive() override; | ||
|
||
bool isOverheated() override; | ||
|
||
bool getIsBroken() override; | ||
|
||
float getRPM() override; | ||
|
||
float getVoltage() override; | ||
|
||
int getPort() override; | ||
|
||
void setGearset(int gearset) override; | ||
|
||
int getGearset() override; | ||
|
||
void setReversed(bool isReversed) override; | ||
|
||
bool getIsReversed() override; | ||
|
||
std::shared_ptr<Abstract_Motor> getPairMotor() override; | ||
|
||
void setPID(std::shared_ptr<FAPID> pid) override; | ||
|
||
std::shared_ptr<FAPID> getPID() override; | ||
|
||
void setGearRatio(float gearRatio) override; | ||
|
||
float getGearRatio() override; | ||
|
||
|
||
|
||
}; | ||
|
||
} // namespace lemlib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#pragma once | ||
|
||
#include "abstractgroup.hpp" | ||
#include "lemlib/devices/motor/abstractmotor.hpp" | ||
#include "prosmotor.hpp" | ||
#include <memory> | ||
|
||
namespace lemlib { | ||
|
||
class PROSMotorGroup : public Abstract_MotorGroup { | ||
private: | ||
|
||
public: | ||
PROSMotorGroup(std::vector<std::unique_ptr<PROSMotor>> motorContainerArg); | ||
|
||
PROSMotorGroup(std::vector<MotorInfo> motorParameters); | ||
|
||
void spinAtVoltage(int voltage) override; | ||
|
||
void spinPerc(int percent) override; | ||
|
||
void spinJoystick(int joystickValue) override; | ||
|
||
void spinAtRPM(int RPM) override; | ||
|
||
void spinUntilDegree(int degree, int speedInVoltage) override; | ||
|
||
void spinFor(float seconds, int speedInVoltage) override; | ||
|
||
void logMotorPerformance() override; // Stuff like wattage and temperature, RPM, etc, along with Port Number | ||
|
||
void set_zero_position(int position) override; | ||
|
||
void shutDown() override; | ||
|
||
void revive() override; | ||
|
||
bool isOverheated() override; | ||
|
||
std::vector<bool> getIsBroken(); | ||
|
||
std::vector<float> getAllRPM(); | ||
|
||
std::vector<int> getBaseRPMs() override; | ||
|
||
std::vector<double> getPositions() override; | ||
|
||
float getAverageRPM(); | ||
|
||
float getVoltage(); | ||
|
||
std::vector<std::unique_ptr<Abstract_Motor>>& getMotorContainer() override; | ||
}; | ||
|
||
} // namespace lemlib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.