premiere ebauche

Dependencies:   mbed PinDetect

Committer:
LipSer
Date:
Mon Dec 17 20:15:19 2018 +0000
Revision:
15:e9560502e463
Parent:
13:47806f4dbfcd
fin

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shovelcat 0:011f69c1276c 1 #include "mbed.h"
shovelcat 2:06f128641b62 2 #include "speedlimiter.hpp"
shovelcat 10:f0b382368614 3 #include "recommendedspeed.hpp"
shovelcat 10:f0b382368614 4 #include "PinDetect.h"
shovelcat 0:011f69c1276c 5
shovelcat 3:4da392d2bae8 6 /*
shovelcat 0:011f69c1276c 7 ##############################
shovelcat 4:a8c9f6a13633 8 CONSTANTS
shovelcat 4:a8c9f6a13633 9 ##############################
shovelcat 4:a8c9f6a13633 10 */
shovelcat 4:a8c9f6a13633 11
shovelcat 4:a8c9f6a13633 12 const PinName pedalInHi = PA_3; // A0 (jaune)
shovelcat 4:a8c9f6a13633 13 const PinName pedalInLo = PC_0; // A1 (vert)
shovelcat 4:a8c9f6a13633 14 const PinName pedalOutHi = PA_4; // D9 (left) (jaune)
shovelcat 4:a8c9f6a13633 15 const PinName pedalOutLo = PA_5; // D13 (right) (vert)
shovelcat 10:f0b382368614 16 //const PinName testAdcIn = PC_3;
shovelcat 4:a8c9f6a13633 17
shovelcat 4:a8c9f6a13633 18 const int CAN_FREQUENCY = 500000;
shovelcat 4:a8c9f6a13633 19
shovelcat 4:a8c9f6a13633 20 Ticker ticker;
shovelcat 10:f0b382368614 21 //InterruptIn button(USER_BUTTON);
shovelcat 4:a8c9f6a13633 22
shovelcat 10:f0b382368614 23
shovelcat 10:f0b382368614 24 Parcours parcours;
shovelcat 4:a8c9f6a13633 25 SpeedLimiter speedLimiter(pedalInHi, pedalInLo, pedalOutHi, pedalOutLo);
shovelcat 4:a8c9f6a13633 26
shovelcat 4:a8c9f6a13633 27 /*
shovelcat 4:a8c9f6a13633 28 ##############################
shovelcat 1:c6b4ccebd483 29 uC I/O
shovelcat 1:c6b4ccebd483 30 ##############################
shovelcat 3:4da392d2bae8 31 */
shovelcat 0:011f69c1276c 32
shovelcat 3:4da392d2bae8 33 //InterruptIn b1(PC_13);
shovelcat 10:f0b382368614 34 //InterruptIn pushButton(PB_3);
shovelcat 10:f0b382368614 35 PinDetect pushButton(PB_4);
shovelcat 3:4da392d2bae8 36 DigitalOut led1(LED1);
shovelcat 3:4da392d2bae8 37 DigitalOut led2(LED2);
shovelcat 3:4da392d2bae8 38 DigitalOut led3(LED3);
shovelcat 5:aef1fc6c0df1 39 DigitalOut pout(PA_7); // D11
shovelcat 4:a8c9f6a13633 40 CAN can(PD_0 /*can1 rd*/, PD_1 /*can1 td*/, CAN_FREQUENCY);
shovelcat 4:a8c9f6a13633 41 Serial pc(USBTX, USBRX);
shovelcat 0:011f69c1276c 42
shovelcat 3:4da392d2bae8 43 /*
shovelcat 4:a8c9f6a13633 44 ##############################
shovelcat 0:011f69c1276c 45
shovelcat 4:a8c9f6a13633 46 ##############################
shovelcat 3:4da392d2bae8 47 */
shovelcat 0:011f69c1276c 48
shovelcat 4:a8c9f6a13633 49 void canCallback()
shovelcat 4:a8c9f6a13633 50 {
shovelcat 4:a8c9f6a13633 51 CANMessage msg;
shovelcat 4:a8c9f6a13633 52 if(can.read(msg)) {
shovelcat 12:cf97590d9df2 53 if (msg.len != 8) {
shovelcat 12:cf97590d9df2 54 ; // drop message
shovelcat 12:cf97590d9df2 55 } else if (msg.id == 0x185) {
shovelcat 12:cf97590d9df2 56 // shift first byte to HI, then fill LO with second byte
shovelcat 4:a8c9f6a13633 57 float speed = (msg.data[6] << 8 | msg.data[7]) * 0.1;
shovelcat 12:cf97590d9df2 58 // float power = (msg.data[5]);
shovelcat 12:cf97590d9df2 59
shovelcat 4:a8c9f6a13633 60 if (speed < 45) {
shovelcat 4:a8c9f6a13633 61 speedLimiter.setMeasuredSpeed(speed);
shovelcat 4:a8c9f6a13633 62 }
shovelcat 5:aef1fc6c0df1 63 } else if(msg.id == 0x181) {
shovelcat 12:cf97590d9df2 64 // float motorCurrent = (msg.data[2] << 8 | msg.data[3]) * 1.0;
shovelcat 12:cf97590d9df2 65 } else if(msg.id == 0x322) {
shovelcat 12:cf97590d9df2 66 // float energySoc = (msg.data[2] << 8 | msg.data[3]);
shovelcat 4:a8c9f6a13633 67 }
shovelcat 4:a8c9f6a13633 68 }
shovelcat 4:a8c9f6a13633 69 }
shovelcat 4:a8c9f6a13633 70
shovelcat 3:4da392d2bae8 71 int main()
shovelcat 3:4da392d2bae8 72 {
shovelcat 10:f0b382368614 73 speedLimiter.setParcours(&parcours);
shovelcat 10:f0b382368614 74 speedLimiter.setReferenceSpeed(0.0);
shovelcat 4:a8c9f6a13633 75 can.attach(&canCallback, CAN::RxIrq);
shovelcat 13:47806f4dbfcd 76 ticker.attach(callback(&speedLimiter, &SpeedLimiter::controllerCallbackFunction), SpeedLimiter::TRANSFER_FUNCTION_PERIOD);
shovelcat 10:f0b382368614 77 pushButton.mode(PullUp);
shovelcat 10:f0b382368614 78 pushButton.attach_deasserted(&parcours, &Parcours::incrementIndex);
shovelcat 10:f0b382368614 79 pushButton.setSampleFrequency();
shovelcat 10:f0b382368614 80 // pushButton.rise(callback(&parcours, &Parcours::incrementIndex));
shovelcat 5:aef1fc6c0df1 81
shovelcat 5:aef1fc6c0df1 82 pc.printf("Start!");
shovelcat 0:011f69c1276c 83
shovelcat 3:4da392d2bae8 84 while(1) {
shovelcat 3:4da392d2bae8 85 led1 = true;
shovelcat 3:4da392d2bae8 86 wait(1.0);
shovelcat 3:4da392d2bae8 87 led1 = false;
shovelcat 3:4da392d2bae8 88 led2 = true;
shovelcat 3:4da392d2bae8 89 wait(1.0);
shovelcat 3:4da392d2bae8 90 led2 = false;
shovelcat 3:4da392d2bae8 91 led3 = true;
shovelcat 3:4da392d2bae8 92 wait(1.0);
shovelcat 3:4da392d2bae8 93 led3 = false;
shovelcat 4:a8c9f6a13633 94 wait(0.01);
shovelcat 5:aef1fc6c0df1 95
shovelcat 5:aef1fc6c0df1 96 // pout = !pout;
shovelcat 5:aef1fc6c0df1 97 // speedLimiter.ecoEnabledAlgorithm();
shovelcat 1:c6b4ccebd483 98 }
shovelcat 5:aef1fc6c0df1 99 }