mit

Dependencies:   QEI mbed-src

Committer:
abuchan
Date:
Tue Nov 24 03:56:22 2015 +0000
Revision:
4:5ae9f8b3a16f
Child:
5:e90c8b57811c
Decoupled position and current control working.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
abuchan 4:5ae9f8b3a16f 1 #include "HBridge.h"
abuchan 4:5ae9f8b3a16f 2
abuchan 4:5ae9f8b3a16f 3 HBridge::HBridge(PinName pwm_pin, PinName min_1_pin, PinName min_2_pin, float pwm_period): pwm_pin_(pwm_pin), min_1_pin_(min_1_pin), min_2_pin_(min_2_pin) {
abuchan 4:5ae9f8b3a16f 4 pwm_pin_.period(pwm_period);
abuchan 4:5ae9f8b3a16f 5 }
abuchan 4:5ae9f8b3a16f 6
abuchan 4:5ae9f8b3a16f 7 //Input of -1 means full reverse, 1 means full forward
abuchan 4:5ae9f8b3a16f 8 //An input of magnitude > 1 gets reduced to 1 (or -1) by the pwm.write function
abuchan 4:5ae9f8b3a16f 9 void HBridge::set_output(float output) {
abuchan 4:5ae9f8b3a16f 10 this->output = output;
abuchan 4:5ae9f8b3a16f 11 if (output > 0) {
abuchan 4:5ae9f8b3a16f 12 min_1_pin_.write(0);
abuchan 4:5ae9f8b3a16f 13 min_2_pin_.write(1);
abuchan 4:5ae9f8b3a16f 14 pwm_pin_.write(output);
abuchan 4:5ae9f8b3a16f 15 } else if (output < 0) {
abuchan 4:5ae9f8b3a16f 16 min_1_pin_.write(1);
abuchan 4:5ae9f8b3a16f 17 min_2_pin_.write(0);
abuchan 4:5ae9f8b3a16f 18 pwm_pin_.write(output * -1);
abuchan 4:5ae9f8b3a16f 19 } else {
abuchan 4:5ae9f8b3a16f 20 min_1_pin_.write(0);
abuchan 4:5ae9f8b3a16f 21 min_2_pin_.write(0);
abuchan 4:5ae9f8b3a16f 22 pwm_pin_.write(0.0);
abuchan 4:5ae9f8b3a16f 23 }
abuchan 4:5ae9f8b3a16f 24 }