22 #include <arpirobot/core/device/MotorController.hpp>
23 #include <arpirobot/core/io/IoDevice.hpp>
28 #include <unordered_map>
44 enum class MotorCommand {FORWARD, BACKWARD, BRAKE, RELEASE};
64 void run(MotorCommand cmd);
75 uint8_t pwm, in1, in2;
81 std::shared_ptr<LowLevelDCMotor> getMotor(
int index);
84 void close()
override;
90 void setPin(uint8_t pin,
bool isHigh);
91 void setPWMFreq(
int freq);
92 void setPWM(uint8_t channel,
int on,
int off);
93 void setAllPWM(
int on,
int off);
96 std::shared_ptr<LowLevelDCMotor> motors[4];
99 const uint8_t __MODE1 = 0x00;
100 const uint8_t __MODE2 = 0x01;
101 const uint8_t __SUBADR1 = 0x02;
102 const uint8_t __SUBADR2 = 0x03;
103 const uint8_t __SUBADR3 = 0x04;
104 const uint8_t __PRESCALE = 0xFE;
105 const uint8_t __LED0_ON_L = 0x06;
106 const uint8_t __LED0_ON_H = 0x07;
107 const uint8_t __LED0_OFF_L = 0x08;
108 const uint8_t __LED0_OFF_H = 0x09;
109 const uint8_t __ALL_LED_ON_L = 0xFA;
110 const uint8_t __ALL_LED_ON_H = 0xFB;
111 const uint8_t __ALL_LED_OFF_L = 0xFC;
112 const uint8_t __ALL_LED_OFF_H = 0xFD;
115 const uint8_t __RESTART = 0x80;
116 const uint8_t __SLEEP = 0x10;
117 const uint8_t __ALLCALL = 0x01;
118 const uint8_t __INVRT = 0x10;
119 const uint8_t __OUTDRV = 0x04;
131 static const int ADAFRUIT_ADDR;
132 static const int GEEKWORM_ADDR;
133 static const int DETECT_ADDR;
148 void begin()
override;
153 static int remapMotorNumber(
int hatAddress,
int motorNum);
154 static int doDetectAddress(
int bus);
156 static std::unordered_map<int, std::shared_ptr<internal::AdafruitMotorHat>> hatMap;
162 std::shared_ptr<internal::AdafruitMotorHat::LowLevelDCMotor> motor;
Definition: AdafruitMotorHatMotor.hpp:128
AdafruitMotorHatMotor(int motorNum, int address=DETECT_ADDR, int bus=-1, bool remapNumbers=true)
Definition: IoDevice.hpp:27
Definition: MotorController.hpp:32
Definition: AdafruitMotorHatMotor.hpp:56
void setSpeed(double speed)
void run(MotorCommand cmd)
Definition: AdafruitMotorHatMotor.hpp:41
Definition: ArduinoDevice.hpp:27