Wyatt  1.0.1
MotorAdapter.cpp
1 //
2 // Created by Tucker Haydon on 4/25/17.
3 //
4 
5 #include "hardwareinterface/MotorAdapter.h"
6 
7 MotorAdapter::MotorAdapter(AdafruitPWMServoHat* m_pwmHat, int forwardPin, int backwardPin) {
8  this->m_pwmHat = m_pwmHat;
9  this->forwardPin = forwardPin;
10  this->backwardPin = backwardPin;
11 }
12 
14  // Nothing.
15 }
16 
18 
19  if(typeid(*m) != typeid(MotorMessage)) {
21  }
22 
23  MotorMessage* msg = (MotorMessage*)m;
24  int speed = msg->getData();
25  driveMotor(speed);
26  delete msg;
27 }
28 
29 void MotorAdapter::driveMotor(int speed) {
30 
31  if(speed < 0) {
32  m_pwmHat->setMotor(this->forwardPin, abs(speed));
33  m_pwmHat->setMotor(this->backwardPin, 0);
34  } else {
35  m_pwmHat->setMotor(this->forwardPin, 0);
36  m_pwmHat->setMotor(this->backwardPin, abs(speed));
37  }
38 }
void write(IMessage *msg) override
~MotorAdapter() override
MotorAdapter(AdafruitPWMServoHat *m_pwmHat, int forwardPin, int backwardPin)
Definition: MotorAdapter.cpp:7
bool setMotor(int motorID, int speed)