premiere ebauche

Dependencies:   mbed PinDetect

Committer:
shovelcat
Date:
Fri Nov 16 17:47:35 2018 +0000
Revision:
10:f0b382368614
Parent:
6:1a4ed88c9a4b
Child:
12:cf97590d9df2
"Plan B" pour tests routiers

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 4:a8c9f6a13633 53 if (msg.id == 0x185) {
shovelcat 10:f0b382368614 54 // float pedal = (msg.data[1] << 8 | msg.data[0]) * 0.00390625;
shovelcat 4:a8c9f6a13633 55 float speed = (msg.data[6] << 8 | msg.data[7]) * 0.1;
shovelcat 4:a8c9f6a13633 56
shovelcat 4:a8c9f6a13633 57 if (speed < 45) {
shovelcat 4:a8c9f6a13633 58 // pc.printf("Pedal: %.3f\tSpeed: %.3f\n\r", pedal, speed);
shovelcat 4:a8c9f6a13633 59 speedLimiter.setMeasuredSpeed(speed);
shovelcat 4:a8c9f6a13633 60 }
shovelcat 5:aef1fc6c0df1 61 } else if(msg.id == 0x181) {
shovelcat 5:aef1fc6c0df1 62
shovelcat 4:a8c9f6a13633 63 }
shovelcat 4:a8c9f6a13633 64 }
shovelcat 4:a8c9f6a13633 65 }
shovelcat 4:a8c9f6a13633 66
shovelcat 3:4da392d2bae8 67 int main()
shovelcat 3:4da392d2bae8 68 {
shovelcat 10:f0b382368614 69 speedLimiter.setParcours(&parcours);
shovelcat 10:f0b382368614 70 speedLimiter.setReferenceSpeed(0.0);
shovelcat 4:a8c9f6a13633 71 can.attach(&canCallback, CAN::RxIrq);
shovelcat 4:a8c9f6a13633 72 ticker.attach(callback(&speedLimiter, &SpeedLimiter::ipControllerTransferFunction), SpeedLimiter::TRANSFER_FUNCTION_PERIOD);
shovelcat 10:f0b382368614 73 pushButton.mode(PullUp);
shovelcat 10:f0b382368614 74 pushButton.attach_deasserted(&parcours, &Parcours::incrementIndex);
shovelcat 10:f0b382368614 75 pushButton.setSampleFrequency();
shovelcat 10:f0b382368614 76 // pushButton.rise(callback(&parcours, &Parcours::incrementIndex));
shovelcat 5:aef1fc6c0df1 77
shovelcat 5:aef1fc6c0df1 78 pc.printf("Start!");
shovelcat 0:011f69c1276c 79
shovelcat 3:4da392d2bae8 80 while(1) {
shovelcat 3:4da392d2bae8 81 led1 = true;
shovelcat 3:4da392d2bae8 82 wait(1.0);
shovelcat 3:4da392d2bae8 83 led1 = false;
shovelcat 3:4da392d2bae8 84 led2 = true;
shovelcat 3:4da392d2bae8 85 wait(1.0);
shovelcat 3:4da392d2bae8 86 led2 = false;
shovelcat 3:4da392d2bae8 87 led3 = true;
shovelcat 3:4da392d2bae8 88 wait(1.0);
shovelcat 3:4da392d2bae8 89 led3 = false;
shovelcat 4:a8c9f6a13633 90 wait(0.01);
shovelcat 5:aef1fc6c0df1 91
shovelcat 5:aef1fc6c0df1 92 // pout = !pout;
shovelcat 5:aef1fc6c0df1 93 // speedLimiter.ecoEnabledAlgorithm();
shovelcat 1:c6b4ccebd483 94 }
shovelcat 5:aef1fc6c0df1 95 }