Firmware for an Android accessory electric bicycle. See http://www.danielcasner.org/tag/ebike/ for some more information on my build.
Dependencies: AndroidAccessory mbed
throttle.cpp
00001 #include "throttle.h" 00002 00003 AnalogIn gripThrottle(p17); 00004 AnalogOut throttleOut(p18); 00005 DigitalIn gripButton(p6); 00006 00007 Throttle* Throttle::instance = NULL; 00008 00009 Throttle *Throttle::getThrottle(float *I, float *v_f, float *v_r, float *cadence, AnalogIn* break_l, AnalogIn *break_r) { 00010 if (instance == NULL) { 00011 instance = new Throttle(I, v_f, v_r, cadence, break_l, break_r); 00012 } 00013 return instance; 00014 } 00015 00016 Throttle::Throttle(float *I, float *v_f, float *v_r, float *cadence, AnalogIn* break_l, AnalogIn *break_r) : 00017 mode(off), state(waiting), 00018 I(I), v_f(v_f), v_r(v_r), cadence(cadence), 00019 brkl(break_l), brkr(break_r), 00020 target(0.0f), iLimit(0.0f), speedLimit(0.0f), 00021 enforceSpeedLimit(false) 00022 { 00023 throttleOut = 0.0f; 00024 gripButton.mode(PullUp); 00025 tick.attach(this, &Throttle::onTick, 0.001); 00026 } 00027 00028 Throttle::~Throttle() { 00029 tick.detach(); 00030 throttleOut = 0.0f; 00031 } 00032 00033 void Throttle::onTick() { 00034 if (brkl->read() < break_inhibit_threshold && brkr->read() < break_inhibit_threshold) { 00035 switch(mode) { 00036 case off: 00037 throttleOut = 0.0f; 00038 break; 00039 case raw: 00040 throttleOut = gripThrottle; 00041 break; 00042 case cruise_raw: 00043 throttleOut = target; 00044 break; 00045 default: 00046 throttleOut = 0.0f; 00047 } 00048 } 00049 else { 00050 state = inhibited; 00051 } 00052 } 00053 00054 void Throttle::setMode(ThrottleMode m) { mode = m; } 00055 00056 void Throttle::setILimit(float I) { iLimit = I; } 00057 00058 void Throttle::setSpeedLimit(float v, bool enforce) { 00059 speedLimit = v; 00060 enforceSpeedLimit = enforce; 00061 } 00062
Generated on Tue Jul 12 2022 18:57:28 by 1.7.2