premiere ebauche

Dependencies:   mbed PinDetect

Committer:
shovelcat
Date:
Tue Oct 23 14:19:54 2018 +0000
Revision:
4:a8c9f6a13633
Parent:
3:4da392d2bae8
Child:
5:aef1fc6c0df1
updated

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 0:011f69c1276c 3
shovelcat 3:4da392d2bae8 4 /*
shovelcat 0:011f69c1276c 5 ##############################
shovelcat 4:a8c9f6a13633 6 CONSTANTS
shovelcat 4:a8c9f6a13633 7 ##############################
shovelcat 4:a8c9f6a13633 8 */
shovelcat 4:a8c9f6a13633 9
shovelcat 4:a8c9f6a13633 10 const PinName pedalInHi = PA_3; // A0 (jaune)
shovelcat 4:a8c9f6a13633 11 const PinName pedalInLo = PC_0; // A1 (vert)
shovelcat 4:a8c9f6a13633 12 const PinName pedalOutHi = PA_4; // D9 (left) (jaune)
shovelcat 4:a8c9f6a13633 13 const PinName pedalOutLo = PA_5; // D13 (right) (vert)
shovelcat 4:a8c9f6a13633 14
shovelcat 4:a8c9f6a13633 15 const int CAN_FREQUENCY = 500000;
shovelcat 4:a8c9f6a13633 16
shovelcat 4:a8c9f6a13633 17 Ticker ticker;
shovelcat 4:a8c9f6a13633 18
shovelcat 4:a8c9f6a13633 19 SpeedLimiter speedLimiter(pedalInHi, pedalInLo, pedalOutHi, pedalOutLo);
shovelcat 4:a8c9f6a13633 20
shovelcat 4:a8c9f6a13633 21 /*
shovelcat 4:a8c9f6a13633 22 ##############################
shovelcat 1:c6b4ccebd483 23 uC I/O
shovelcat 1:c6b4ccebd483 24 ##############################
shovelcat 3:4da392d2bae8 25 */
shovelcat 0:011f69c1276c 26
shovelcat 3:4da392d2bae8 27 //InterruptIn b1(PC_13);
shovelcat 3:4da392d2bae8 28 DigitalOut led1(LED1);
shovelcat 3:4da392d2bae8 29 DigitalOut led2(LED2);
shovelcat 3:4da392d2bae8 30 DigitalOut led3(LED3);
shovelcat 4:a8c9f6a13633 31 CAN can(PD_0 /*can1 rd*/, PD_1 /*can1 td*/, CAN_FREQUENCY);
shovelcat 4:a8c9f6a13633 32 Serial pc(USBTX, USBRX);
shovelcat 0:011f69c1276c 33
shovelcat 3:4da392d2bae8 34 /*
shovelcat 4:a8c9f6a13633 35 ##############################
shovelcat 0:011f69c1276c 36
shovelcat 4:a8c9f6a13633 37 ##############################
shovelcat 3:4da392d2bae8 38 */
shovelcat 0:011f69c1276c 39
shovelcat 4:a8c9f6a13633 40 void canCallback()
shovelcat 4:a8c9f6a13633 41 {
shovelcat 4:a8c9f6a13633 42 CANMessage msg;
shovelcat 4:a8c9f6a13633 43 if(can.read(msg)) {
shovelcat 4:a8c9f6a13633 44 if (msg.id == 0x185) {
shovelcat 4:a8c9f6a13633 45 float pedal = (msg.data[1] << 8 | msg.data[0]) * 0.00390625;
shovelcat 4:a8c9f6a13633 46 float speed = (msg.data[6] << 8 | msg.data[7]) * 0.1;
shovelcat 4:a8c9f6a13633 47
shovelcat 4:a8c9f6a13633 48 if (speed < 45) {
shovelcat 4:a8c9f6a13633 49 // pc.printf("Pedal: %.3f\tSpeed: %.3f\n\r", pedal, speed);
shovelcat 4:a8c9f6a13633 50 speedLimiter.setMeasuredSpeed(speed);
shovelcat 4:a8c9f6a13633 51 }
shovelcat 4:a8c9f6a13633 52 }
shovelcat 4:a8c9f6a13633 53 }
shovelcat 4:a8c9f6a13633 54 }
shovelcat 4:a8c9f6a13633 55
shovelcat 3:4da392d2bae8 56 int main()
shovelcat 3:4da392d2bae8 57 {
shovelcat 4:a8c9f6a13633 58 speedLimiter.setReferenceSpeed(10.0);
shovelcat 4:a8c9f6a13633 59 can.attach(&canCallback, CAN::RxIrq);
shovelcat 4:a8c9f6a13633 60 ticker.attach(callback(&speedLimiter, &SpeedLimiter::ipControllerTransferFunction), SpeedLimiter::TRANSFER_FUNCTION_PERIOD);
shovelcat 4:a8c9f6a13633 61
shovelcat 0:011f69c1276c 62
shovelcat 3:4da392d2bae8 63 while(1) {
shovelcat 3:4da392d2bae8 64 led1 = true;
shovelcat 3:4da392d2bae8 65 wait(1.0);
shovelcat 3:4da392d2bae8 66 led1 = false;
shovelcat 3:4da392d2bae8 67 led2 = true;
shovelcat 3:4da392d2bae8 68 wait(1.0);
shovelcat 3:4da392d2bae8 69 led2 = false;
shovelcat 3:4da392d2bae8 70 led3 = true;
shovelcat 3:4da392d2bae8 71 wait(1.0);
shovelcat 3:4da392d2bae8 72 led3 = false;
shovelcat 4:a8c9f6a13633 73 wait(0.01);
shovelcat 1:c6b4ccebd483 74 }
shovelcat 1:c6b4ccebd483 75 }