Firmware for an Android accessory electric bicycle. See http://www.danielcasner.org/tag/ebike/ for some more information on my build.

Dependencies:   AndroidAccessory mbed

Committer:
DanielC
Date:
Mon Aug 20 05:18:03 2012 +0000
Revision:
2:e2c3c7340fb3
Child:
3:dc564aaf8a81
Something that might actually work as a throttle pass through at least

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DanielC 2:e2c3c7340fb3 1 #include "throttle.h"
DanielC 2:e2c3c7340fb3 2
DanielC 2:e2c3c7340fb3 3 AnalogIn gripThrottle(p17);
DanielC 2:e2c3c7340fb3 4 AnalogOut throttleOut(p18);
DanielC 2:e2c3c7340fb3 5
DanielC 2:e2c3c7340fb3 6 Throttle* Throttle::instance = NULL;
DanielC 2:e2c3c7340fb3 7
DanielC 2:e2c3c7340fb3 8 Throttle *Throttle::getThrottle(float *I, float *v_f, float *v_r, float *cadence, AnalogIn* break_l, AnalogIn *break_r) {
DanielC 2:e2c3c7340fb3 9 if (instance == NULL) {
DanielC 2:e2c3c7340fb3 10 instance = new Throttle(I, v_f, v_r, cadence, break_l, break_r);
DanielC 2:e2c3c7340fb3 11 }
DanielC 2:e2c3c7340fb3 12 return instance;
DanielC 2:e2c3c7340fb3 13 }
DanielC 2:e2c3c7340fb3 14
DanielC 2:e2c3c7340fb3 15 Throttle::Throttle(float *I, float *v_f, float *v_r, float *cadence, AnalogIn* break_l, AnalogIn *break_r) :
DanielC 2:e2c3c7340fb3 16 mode(off), state(waiting),
DanielC 2:e2c3c7340fb3 17 I(I), v_f(v_f), v_r(v_r), cadence(cadence),
DanielC 2:e2c3c7340fb3 18 brkl(break_l), brkr(break_r),
DanielC 2:e2c3c7340fb3 19 target(0.0f), iLimit(0.0f), speedLimit(0.0f),
DanielC 2:e2c3c7340fb3 20 enforceSpeedLimit(false)
DanielC 2:e2c3c7340fb3 21 {
DanielC 2:e2c3c7340fb3 22 throttleOut = 0.0f;
DanielC 2:e2c3c7340fb3 23 tick.attach(this, &Throttle::onTick, 0.001);
DanielC 2:e2c3c7340fb3 24 }
DanielC 2:e2c3c7340fb3 25
DanielC 2:e2c3c7340fb3 26 Throttle::~Throttle() {
DanielC 2:e2c3c7340fb3 27 tick.detach();
DanielC 2:e2c3c7340fb3 28 throttleOut = 0.0f;
DanielC 2:e2c3c7340fb3 29 }
DanielC 2:e2c3c7340fb3 30
DanielC 2:e2c3c7340fb3 31 void Throttle::onTick() {
DanielC 2:e2c3c7340fb3 32 if (brkl->read() < break_inhibit_threshold && brkr->read() < break_inhibit_threshold) {
DanielC 2:e2c3c7340fb3 33 switch(mode) {
DanielC 2:e2c3c7340fb3 34 case off:
DanielC 2:e2c3c7340fb3 35 throttleOut = 0.0f;
DanielC 2:e2c3c7340fb3 36 break;
DanielC 2:e2c3c7340fb3 37 case raw:
DanielC 2:e2c3c7340fb3 38 throttleOut = gripThrottle;
DanielC 2:e2c3c7340fb3 39 break;
DanielC 2:e2c3c7340fb3 40 case cruise_raw:
DanielC 2:e2c3c7340fb3 41 throttleOut = target;
DanielC 2:e2c3c7340fb3 42 break;
DanielC 2:e2c3c7340fb3 43 default:
DanielC 2:e2c3c7340fb3 44 throttleOut = 0.0f;
DanielC 2:e2c3c7340fb3 45 }
DanielC 2:e2c3c7340fb3 46 }
DanielC 2:e2c3c7340fb3 47 else {
DanielC 2:e2c3c7340fb3 48 state = inhibited;
DanielC 2:e2c3c7340fb3 49 }
DanielC 2:e2c3c7340fb3 50 }
DanielC 2:e2c3c7340fb3 51
DanielC 2:e2c3c7340fb3 52 void Throttle::setMode(ThrottleMode m) { mode = m; }
DanielC 2:e2c3c7340fb3 53
DanielC 2:e2c3c7340fb3 54 void Throttle::setILimit(float I) { iLimit = I; }
DanielC 2:e2c3c7340fb3 55
DanielC 2:e2c3c7340fb3 56 void Throttle::setSpeedLimit(float v, bool enforce) {
DanielC 2:e2c3c7340fb3 57 speedLimit = v;
DanielC 2:e2c3c7340fb3 58 enforceSpeedLimit = enforce;
DanielC 2:e2c3c7340fb3 59 }
DanielC 2:e2c3c7340fb3 60