Firmware for an Android accessory electric bicycle. See http://www.danielcasner.org/tag/ebike/ for some more information on my build.
Dependencies: AndroidAccessory mbed
Revision 3:dc564aaf8a81, committed 2012-08-25
- Comitter:
- DanielC
- Date:
- Sat Aug 25 20:09:35 2012 +0000
- Parent:
- 2:e2c3c7340fb3
- Commit message:
- A first public commit. This isn't working code yet but I think it's enough to share to show the structure of what I am developing.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
throttle.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Aug 20 05:18:03 2012 +0000 +++ b/main.cpp Sat Aug 25 20:09:35 2012 +0000 @@ -71,7 +71,7 @@ void DroidCycleMbed::onTick() { blink_counter++; if (blink_counter < 10) l_running = 1; - else if (blink_counter < 100) l_running = 0; + else if (blink_counter < 200) l_running = 0; else blink_counter = 0; }
--- a/throttle.cpp Mon Aug 20 05:18:03 2012 +0000 +++ b/throttle.cpp Sat Aug 25 20:09:35 2012 +0000 @@ -1,60 +1,62 @@ -#include "throttle.h" - -AnalogIn gripThrottle(p17); -AnalogOut throttleOut(p18); - -Throttle* Throttle::instance = NULL; - -Throttle *Throttle::getThrottle(float *I, float *v_f, float *v_r, float *cadence, AnalogIn* break_l, AnalogIn *break_r) { - if (instance == NULL) { - instance = new Throttle(I, v_f, v_r, cadence, break_l, break_r); - } - return instance; -} - -Throttle::Throttle(float *I, float *v_f, float *v_r, float *cadence, AnalogIn* break_l, AnalogIn *break_r) : - mode(off), state(waiting), - I(I), v_f(v_f), v_r(v_r), cadence(cadence), - brkl(break_l), brkr(break_r), - target(0.0f), iLimit(0.0f), speedLimit(0.0f), - enforceSpeedLimit(false) - { - throttleOut = 0.0f; - tick.attach(this, &Throttle::onTick, 0.001); -} - -Throttle::~Throttle() { - tick.detach(); - throttleOut = 0.0f; -} - -void Throttle::onTick() { - if (brkl->read() < break_inhibit_threshold && brkr->read() < break_inhibit_threshold) { - switch(mode) { - case off: - throttleOut = 0.0f; - break; - case raw: - throttleOut = gripThrottle; - break; - case cruise_raw: - throttleOut = target; - break; - default: - throttleOut = 0.0f; - } - } - else { - state = inhibited; - } -} - -void Throttle::setMode(ThrottleMode m) { mode = m; } - -void Throttle::setILimit(float I) { iLimit = I; } - -void Throttle::setSpeedLimit(float v, bool enforce) { - speedLimit = v; - enforceSpeedLimit = enforce; -} - +#include "throttle.h" + +AnalogIn gripThrottle(p17); +AnalogOut throttleOut(p18); +DigitalIn gripButton(p6); + +Throttle* Throttle::instance = NULL; + +Throttle *Throttle::getThrottle(float *I, float *v_f, float *v_r, float *cadence, AnalogIn* break_l, AnalogIn *break_r) { + if (instance == NULL) { + instance = new Throttle(I, v_f, v_r, cadence, break_l, break_r); + } + return instance; +} + +Throttle::Throttle(float *I, float *v_f, float *v_r, float *cadence, AnalogIn* break_l, AnalogIn *break_r) : + mode(off), state(waiting), + I(I), v_f(v_f), v_r(v_r), cadence(cadence), + brkl(break_l), brkr(break_r), + target(0.0f), iLimit(0.0f), speedLimit(0.0f), + enforceSpeedLimit(false) + { + throttleOut = 0.0f; + gripButton.mode(PullUp); + tick.attach(this, &Throttle::onTick, 0.001); +} + +Throttle::~Throttle() { + tick.detach(); + throttleOut = 0.0f; +} + +void Throttle::onTick() { + if (brkl->read() < break_inhibit_threshold && brkr->read() < break_inhibit_threshold) { + switch(mode) { + case off: + throttleOut = 0.0f; + break; + case raw: + throttleOut = gripThrottle; + break; + case cruise_raw: + throttleOut = target; + break; + default: + throttleOut = 0.0f; + } + } + else { + state = inhibited; + } +} + +void Throttle::setMode(ThrottleMode m) { mode = m; } + +void Throttle::setILimit(float I) { iLimit = I; } + +void Throttle::setSpeedLimit(float v, bool enforce) { + speedLimit = v; + enforceSpeedLimit = enforce; +} +