PWM/Direction Motor Driver compatible with VNH3SP30 Motor Driver Carrier MD01B

Dependents:   RoboCup_2015

Committer:
OPSHUD
Date:
Mon Sep 29 17:15:29 2014 +0000
Revision:
1:4b1582384e71
Parent:
0:be45415ffe07
Child:
2:b00b27b2573d
motor controls through arduino message

Who changed what in which revision?

UserRevisionLine numberNew contents of line
OPSHUD 0:be45415ffe07 1 #include "MotorDriver.h"
OPSHUD 0:be45415ffe07 2 #include "mbed.h"
OPSHUD 1:4b1582384e71 3 MotorDriver::MotorDriver(PinName PWMPin, PinName directionPin1, PinName directionPin2) : mPWM(PWMPin), mDir1(directionPin1), mDir2(directionPin2) {
OPSHUD 0:be45415ffe07 4 this->SetValue(0);
OPSHUD 0:be45415ffe07 5 }
OPSHUD 0:be45415ffe07 6 void MotorDriver::SetValue(float value) {
OPSHUD 1:4b1582384e71 7 if(value > 1.0) value = 1.0;
OPSHUD 1:4b1582384e71 8 else if(value < -1.0) value = -1.0;
OPSHUD 1:4b1582384e71 9
OPSHUD 0:be45415ffe07 10 this->mValue = value;
OPSHUD 1:4b1582384e71 11
OPSHUD 1:4b1582384e71 12 this->mDir2 = 0; // Prevent driving 1 on both pins.
OPSHUD 1:4b1582384e71 13 this->mDir1 = value > 0;
OPSHUD 0:be45415ffe07 14 this->mDir2 = !this->mDir1;
OPSHUD 1:4b1582384e71 15
OPSHUD 1:4b1582384e71 16 this->mPWM = value;
OPSHUD 0:be45415ffe07 17 }
OPSHUD 0:be45415ffe07 18 MotorDriver& MotorDriver::operator=(float value) {
OPSHUD 0:be45415ffe07 19 this->SetValue(value);
OPSHUD 0:be45415ffe07 20 return *this;
OPSHUD 0:be45415ffe07 21 }
OPSHUD 0:be45415ffe07 22 float MotorDriver::GetValue() const {
OPSHUD 0:be45415ffe07 23 return this->mValue;
OPSHUD 1:4b1582384e71 24 }