Implemented first Hangar-Service
Dependencies: CalibrateMagneto QuaternionMath
Fork of SML2 by
MotorDriver.cpp@0:943820483318, 2015-01-13 (annotated)
- Committer:
- pvaibhav
- Date:
- Tue Jan 13 11:23:01 2015 +0000
- Revision:
- 0:943820483318
- Child:
- 3:ee90a9ada112
Initial commit with working LED and motor drivers.
Who changed what in which revision?
User | Revision | Line number | New 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) >= 0.48); |
pvaibhav | 0:943820483318 | 9 | assert(abs(voltage) <= 5.06); |
pvaibhav | 0:943820483318 | 10 | |
pvaibhav | 0:943820483318 | 11 | const uint8_t DAC_val = floor(abs(voltage) / 0.0804) + 1; // derived from table on DRV8830 datasheet page 10 |
pvaibhav | 0:943820483318 | 12 | const uint8_t direction = (voltage >= 0.0) ? 0x01 : 0x02; // forward or reverse is set through last 2 bits |
pvaibhav | 0:943820483318 | 13 | |
pvaibhav | 0:943820483318 | 14 | write_reg(0x00, (DAC_val << 2) | direction); |
pvaibhav | 0:943820483318 | 15 | } |
pvaibhav | 0:943820483318 | 16 | |
pvaibhav | 0:943820483318 | 17 | MotorDriver& MotorDriver::operator=(const float voltage) { |
pvaibhav | 0:943820483318 | 18 | setVoltage(voltage); |
pvaibhav | 0:943820483318 | 19 | return *this; |
pvaibhav | 0:943820483318 | 20 | } |