Library to control the bike (just basic for now)

Dependents:   TORTUGA_BLE

Committer:
ptuytsch
Date:
Mon Jul 18 13:19:33 2016 +0000
Revision:
1:39f462024f10
Parent:
0:792a8f167ac0
adding full functionallity of tortuga in library (not the most beautiful way)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ptuytsch 1:39f462024f10 1 #ifndef BIKECONTROL_H
ptuytsch 1:39f462024f10 2 #define BIKECONTROL_H
ptuytsch 0:792a8f167ac0 3 #include "mbed.h"
ptuytsch 1:39f462024f10 4 #include "BikeData.h"
ptuytsch 1:39f462024f10 5 #include "BatteryState.h"
ptuytsch 0:792a8f167ac0 6
ptuytsch 0:792a8f167ac0 7 class BikeControl{
ptuytsch 0:792a8f167ac0 8
ptuytsch 0:792a8f167ac0 9 protected:
ptuytsch 0:792a8f167ac0 10 //State machine states definition
ptuytsch 0:792a8f167ac0 11 typedef enum DriveState {
ptuytsch 0:792a8f167ac0 12 DRIVE_START=0,
ptuytsch 0:792a8f167ac0 13 DRIVE_BRAKE,
ptuytsch 0:792a8f167ac0 14 DRIVE_BOOST,
ptuytsch 0:792a8f167ac0 15 DRIVE_RUN,
ptuytsch 0:792a8f167ac0 16 } DriveState_t;
ptuytsch 0:792a8f167ac0 17
ptuytsch 0:792a8f167ac0 18
ptuytsch 0:792a8f167ac0 19 //WHEEL
ptuytsch 0:792a8f167ac0 20 //const float WHEEL_CIRCUMFERENCE = 1.66; //Wheel Circumference
ptuytsch 0:792a8f167ac0 21 //MOTOR
ptuytsch 0:792a8f167ac0 22 //const float GEAR_RATIO = 13.3; //Motor gear ration
ptuytsch 1:39f462024f10 23
ptuytsch 0:792a8f167ac0 24
ptuytsch 0:792a8f167ac0 25 //TRAILER
ptuytsch 1:39f462024f10 26 DigitalOut trailerCtrl;
ptuytsch 0:792a8f167ac0 27
ptuytsch 0:792a8f167ac0 28 //MOTOR
ptuytsch 1:39f462024f10 29 PwmOut motorRightCtrl;
ptuytsch 1:39f462024f10 30 InterruptIn motorRightHall;
ptuytsch 1:39f462024f10 31 uint16_t motorRightCounter;
ptuytsch 1:39f462024f10 32 uint16_t motorRightRpm;
ptuytsch 1:39f462024f10 33 PwmOut motorLeftCtrl;
ptuytsch 1:39f462024f10 34 InterruptIn motorLeftHall;
ptuytsch 1:39f462024f10 35 uint16_t motorLeftCounter;
ptuytsch 1:39f462024f10 36 uint16_t motorLeftRpm;
ptuytsch 0:792a8f167ac0 37
ptuytsch 0:792a8f167ac0 38 //BRAKE
ptuytsch 1:39f462024f10 39 DigitalIn brakeFront;
ptuytsch 1:39f462024f10 40 DigitalIn brakeRear;
ptuytsch 0:792a8f167ac0 41
ptuytsch 0:792a8f167ac0 42 //GENERATOR
ptuytsch 1:39f462024f10 43 InterruptIn generatorHallA;
ptuytsch 1:39f462024f10 44 PwmOut generatorBrake;
ptuytsch 1:39f462024f10 45 uint16_t generatorHallACounter;
ptuytsch 1:39f462024f10 46 uint16_t generatorHallARpm;
ptuytsch 1:39f462024f10 47 InterruptIn generatorHallB;
ptuytsch 1:39f462024f10 48 uint16_t generatorHallBCounter;
ptuytsch 1:39f462024f10 49 uint16_t generatorHallBRpm;
ptuytsch 0:792a8f167ac0 50
ptuytsch 0:792a8f167ac0 51 //BUTTONS ON STEERING
ptuytsch 1:39f462024f10 52 //DigitalIn userButton;
ptuytsch 1:39f462024f10 53 DigitalIn buttonGreen;
ptuytsch 1:39f462024f10 54 DigitalIn buttonRed;
ptuytsch 1:39f462024f10 55 DigitalIn buttonDirectionRight;
ptuytsch 1:39f462024f10 56 DigitalIn buttonDirectionLeft;
ptuytsch 0:792a8f167ac0 57
ptuytsch 0:792a8f167ac0 58 //SWITCH
ptuytsch 1:39f462024f10 59 DigitalIn switchOn;
ptuytsch 1:39f462024f10 60 DigitalIn switchWalk;
ptuytsch 0:792a8f167ac0 61
ptuytsch 0:792a8f167ac0 62 //LIGHT
ptuytsch 1:39f462024f10 63 DigitalOut lightFront;
ptuytsch 1:39f462024f10 64 DigitalOut lightBack;
ptuytsch 1:39f462024f10 65 DigitalOut lightLeft;
ptuytsch 1:39f462024f10 66 DigitalOut lightRight;
ptuytsch 1:39f462024f10 67
ptuytsch 0:792a8f167ac0 68
ptuytsch 1:39f462024f10 69 void generatorHallAPulsed();
ptuytsch 1:39f462024f10 70 void generatorHallBPulsed();
ptuytsch 1:39f462024f10 71 void motorRightPulsed();
ptuytsch 1:39f462024f10 72 void motorLeftPulsed();
ptuytsch 1:39f462024f10 73 void periodicCallback();
ptuytsch 1:39f462024f10 74
ptuytsch 1:39f462024f10 75 Ticker t;
ptuytsch 1:39f462024f10 76 BikeData *bd;
ptuytsch 1:39f462024f10 77 BatteryState *bikeBat, *trailerBat, *auxBat;
ptuytsch 1:39f462024f10 78
ptuytsch 1:39f462024f10 79 public:
ptuytsch 1:39f462024f10 80 BikeControl(BikeData* bikeData, BatteryState* trailerBat, BatteryState* bikeBat, BatteryState* auxBat);
ptuytsch 1:39f462024f10 81 void runTestLight();
ptuytsch 1:39f462024f10 82 void startControlLoop();
ptuytsch 1:39f462024f10 83 void checkStatus();
ptuytsch 0:792a8f167ac0 84 };
ptuytsch 0:792a8f167ac0 85
ptuytsch 0:792a8f167ac0 86 #endif