PWM/Direction Motor Driver compatible with VNH3SP30 Motor Driver Carrier MD01B
MotorDriver.cpp@2:b00b27b2573d, 2014-09-29 (annotated)
- Committer:
- OPSHUD
- Date:
- Mon Sep 29 17:20:59 2014 +0000
- Revision:
- 2:b00b27b2573d
- Parent:
- 1:4b1582384e71
updated format;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
OPSHUD | 0:be45415ffe07 | 1 | #include "MotorDriver.h" |
OPSHUD | 0:be45415ffe07 | 2 | #include "mbed.h" |
OPSHUD | 2:b00b27b2573d | 3 | MotorDriver::MotorDriver(PinName PWMPin, PinName directionPin1, PinName directionPin2) : |
OPSHUD | 2:b00b27b2573d | 4 | mPWM(PWMPin), mDir1(directionPin1), mDir2(directionPin2) { |
OPSHUD | 0:be45415ffe07 | 5 | this->SetValue(0); |
OPSHUD | 0:be45415ffe07 | 6 | } |
OPSHUD | 0:be45415ffe07 | 7 | void MotorDriver::SetValue(float value) { |
OPSHUD | 1:4b1582384e71 | 8 | if(value > 1.0) value = 1.0; |
OPSHUD | 1:4b1582384e71 | 9 | else if(value < -1.0) value = -1.0; |
OPSHUD | 1:4b1582384e71 | 10 | |
OPSHUD | 0:be45415ffe07 | 11 | this->mValue = value; |
OPSHUD | 1:4b1582384e71 | 12 | |
OPSHUD | 1:4b1582384e71 | 13 | this->mDir2 = 0; // Prevent driving 1 on both pins. |
OPSHUD | 1:4b1582384e71 | 14 | this->mDir1 = value > 0; |
OPSHUD | 0:be45415ffe07 | 15 | this->mDir2 = !this->mDir1; |
OPSHUD | 1:4b1582384e71 | 16 | |
OPSHUD | 1:4b1582384e71 | 17 | this->mPWM = value; |
OPSHUD | 0:be45415ffe07 | 18 | } |
OPSHUD | 0:be45415ffe07 | 19 | MotorDriver& MotorDriver::operator=(float value) { |
OPSHUD | 0:be45415ffe07 | 20 | this->SetValue(value); |
OPSHUD | 0:be45415ffe07 | 21 | return *this; |
OPSHUD | 0:be45415ffe07 | 22 | } |
OPSHUD | 0:be45415ffe07 | 23 | float MotorDriver::GetValue() const { |
OPSHUD | 0:be45415ffe07 | 24 | return this->mValue; |
OPSHUD | 1:4b1582384e71 | 25 | } |