Implemented first Hangar-Service

Dependencies:   CalibrateMagneto QuaternionMath

Fork of SML2 by TobyRich GmbH

Committer:
pvaibhav
Date:
Wed Jan 21 10:34:45 2015 +0000
Revision:
3:ee90a9ada112
Parent:
0:943820483318
Child:
4:e759b8c756da
Motor driver now "stops" the output if voltage is set below 0.48V

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pvaibhav 0:943820483318 1 #include "MotorDriver.h"
pvaibhav 0:943820483318 2 #include <cassert>
pvaibhav 0:943820483318 3 #include <cmath>
pvaibhav 0:943820483318 4
pvaibhav 0:943820483318 5 MotorDriver::MotorDriver(I2C &i2c, const uint8_t address) : I2CPeripheral(i2c, address) {}
pvaibhav 0:943820483318 6
pvaibhav 0:943820483318 7 void MotorDriver::setVoltage(const float voltage) {
pvaibhav 0:943820483318 8 assert(abs(voltage) <= 5.06);
pvaibhav 0:943820483318 9
pvaibhav 3:ee90a9ada112 10 const bool stop = fabs(voltage) < 0.48;
pvaibhav 3:ee90a9ada112 11 const float Vr = 1.285; // internal reference voltage
pvaibhav 0:943820483318 12
pvaibhav 3:ee90a9ada112 13 if (stop) {
pvaibhav 3:ee90a9ada112 14 write_reg(0x00, 0x03); // last 2 bits = 11 = "brake"
pvaibhav 3:ee90a9ada112 15 } else {
pvaibhav 3:ee90a9ada112 16 const uint8_t DAC_val = ceil( (16.0 * fabs(voltage) / Vr) - 1.0 ); // derived from table on DRV8830 datasheet page 10
pvaibhav 3:ee90a9ada112 17 const uint8_t direction = (voltage > 0.0) ? 0x01 : 0x02; // forward or reverse is set through last 2 bits
pvaibhav 3:ee90a9ada112 18 write_reg(0x00, (DAC_val << 2) | direction);
pvaibhav 3:ee90a9ada112 19 }
pvaibhav 0:943820483318 20 }
pvaibhav 0:943820483318 21
pvaibhav 0:943820483318 22 MotorDriver& MotorDriver::operator=(const float voltage) {
pvaibhav 0:943820483318 23 setVoltage(voltage);
pvaibhav 0:943820483318 24 return *this;
pvaibhav 0:943820483318 25 }