3/19 23:30
Dependencies: mbed move4wheel2 EC CruizCore_R1370P
can/can.cpp@6:26724c287387, 2019-03-02 (annotated)
- Committer:
- la00noix
- Date:
- Sat Mar 02 07:48:18 2019 +0000
- Revision:
- 6:26724c287387
- Parent:
- 5:6cebe1c458a9
- Child:
- 7:44ce34007499
a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
la00noix | 0:c61c6e4775ca | 1 | #include "mbed.h" |
la00noix | 0:c61c6e4775ca | 2 | #include "PathFollowing.h" |
la00noix | 0:c61c6e4775ca | 3 | #include "movement.h" |
la00noix | 0:c61c6e4775ca | 4 | #include "maxonsetting.h" |
la00noix | 0:c61c6e4775ca | 5 | #include "manual.h" |
la00noix | 0:c61c6e4775ca | 6 | #include "can.h" |
la00noix | 0:c61c6e4775ca | 7 | |
la00noix | 2:7cba05e70367 | 8 | CAN can1(p30,p29,1000000); |
la00noix | 0:c61c6e4775ca | 9 | Ticker can_ticker; //can用ticker |
la00noix | 0:c61c6e4775ca | 10 | |
yuki0701 | 5:6cebe1c458a9 | 11 | DigitalOut cansend_led(LED1); //canread -> on |
yuki0701 | 5:6cebe1c458a9 | 12 | DigitalOut canread_led(LED2); //cansend -> on |
la00noix | 0:c61c6e4775ca | 13 | |
la00noix | 0:c61c6e4775ca | 14 | void can_readsend() |
la00noix | 0:c61c6e4775ca | 15 | { |
la00noix | 0:c61c6e4775ca | 16 | CANMessage msg; |
yuki0701 | 3:8a0faa3b08c3 | 17 | |
la00noix | 0:c61c6e4775ca | 18 | if(can1.read(msg)) { |
la00noix | 0:c61c6e4775ca | 19 | canread_led = 1; |
yuki0701 | 3:8a0faa3b08c3 | 20 | |
yuki0701 | 3:8a0faa3b08c3 | 21 | if(msg.id == 1) { //from main |
yuki0701 | 3:8a0faa3b08c3 | 22 | |
la00noix | 6:26724c287387 | 23 | id1_value[0] = (msg.data[0]>>6)%4; //decide wait/auto/manual(0~2) |
la00noix | 6:26724c287387 | 24 | id1_value[1] = msg.data[1]; //angle of left joystick(0~359) |
la00noix | 0:c61c6e4775ca | 25 | id1_value[2] = msg.data[2]; |
la00noix | 6:26724c287387 | 26 | id1_value[3] = (msg.data[0]>>5)%2; //BOTTONR1 off/on(0 or 1) |
la00noix | 6:26724c287387 | 27 | id1_value[4] = (msg.data[0]>>3)%4; //state of right joystick(1~3) |
la00noix | 6:26724c287387 | 28 | id1_value[5] = (msg.data[0]>>2)%2; //left joystick neutral position(0 or 1) |
la00noix | 6:26724c287387 | 29 | id1_value[6] = (msg.data[0]>>1)%2; //decide right/left(0 or 1) |
la00noix | 0:c61c6e4775ca | 30 | |
la00noix | 6:26724c287387 | 31 | debug_printf("[0]=%d [1]=%d [2]=%d [3]=%d [4]=%d [5]=%d [6]=%d\n\r" |
la00noix | 6:26724c287387 | 32 | ,id1_value[0],id1_value[1],id1_value[2],id1_value[3],id1_value[4],id1_value[5],id1_value[6]); |
la00noix | 0:c61c6e4775ca | 33 | } |
yuki0701 | 3:8a0faa3b08c3 | 34 | |
la00noix | 4:317c53a674fa | 35 | if(msg.id == 3) { |
yuki0701 | 1:3c11e07da92a | 36 | usw_data1 = 0.1 * (short)((msg.data[0]<<8) | msg.data[1]); |
yuki0701 | 5:6cebe1c458a9 | 37 | debug_printf("usw_data1 = %f\n\r",usw_data1); |
yuki0701 | 3:8a0faa3b08c3 | 38 | |
yuki0701 | 5:6cebe1c458a9 | 39 | usw_data2 = 0.1 * (short)((msg.data[2]<<8) | msg.data[3]); |
yuki0701 | 5:6cebe1c458a9 | 40 | debug_printf("usw_data2 = %f\n\r",usw_data2); |
yuki0701 | 3:8a0faa3b08c3 | 41 | |
yuki0701 | 5:6cebe1c458a9 | 42 | usw_data3 = 0.1 * (short)((msg.data[4]<<8) | msg.data[5]); |
yuki0701 | 5:6cebe1c458a9 | 43 | debug_printf("usw_data3 = %f\n\r",usw_data3); |
yuki0701 | 3:8a0faa3b08c3 | 44 | |
yuki0701 | 5:6cebe1c458a9 | 45 | usw_data4 = 0.1 * (short)((msg.data[6]<<8) | msg.data[7]); |
yuki0701 | 5:6cebe1c458a9 | 46 | debug_printf("usw_data4 = %f\n\r",usw_data4); |
yuki0701 | 3:8a0faa3b08c3 | 47 | } |
yuki0701 | 3:8a0faa3b08c3 | 48 | |
yuki0701 | 3:8a0faa3b08c3 | 49 | } else { |
la00noix | 0:c61c6e4775ca | 50 | canread_led = 0; |
la00noix | 0:c61c6e4775ca | 51 | } |
yuki0701 | 3:8a0faa3b08c3 | 52 | |
la00noix | 6:26724c287387 | 53 | if(can1.write(CANMessage(7,can_ashileddata,1))) { //IDを7にして送信 |
la00noix | 0:c61c6e4775ca | 54 | cansend_led = 1; |
yuki0701 | 3:8a0faa3b08c3 | 55 | } else { |
la00noix | 0:c61c6e4775ca | 56 | cansend_led = 0; |
la00noix | 0:c61c6e4775ca | 57 | } |
yuki0701 | 3:8a0faa3b08c3 | 58 | |
yuki0701 | 3:8a0faa3b08c3 | 59 | } |
yuki0701 | 3:8a0faa3b08c3 | 60 | void can_start() |
yuki0701 | 3:8a0faa3b08c3 | 61 | { |
yuki0701 | 3:8a0faa3b08c3 | 62 | |
yuki0701 | 3:8a0faa3b08c3 | 63 | while(1) { |
yuki0701 | 3:8a0faa3b08c3 | 64 | |
yuki0701 | 3:8a0faa3b08c3 | 65 | CANMessage msg; |
yuki0701 | 3:8a0faa3b08c3 | 66 | |
yuki0701 | 3:8a0faa3b08c3 | 67 | debug_printf("wait\n\r"); |
yuki0701 | 3:8a0faa3b08c3 | 68 | wait(0.1); |
yuki0701 | 3:8a0faa3b08c3 | 69 | if(can1.read(msg)) { |
yuki0701 | 3:8a0faa3b08c3 | 70 | break; |
yuki0701 | 3:8a0faa3b08c3 | 71 | } |
yuki0701 | 3:8a0faa3b08c3 | 72 | } |
la00noix | 0:c61c6e4775ca | 73 | } |
la00noix | 0:c61c6e4775ca | 74 | |
yuki0701 | 3:8a0faa3b08c3 | 75 | void UserLoopSetting_can() |
yuki0701 | 3:8a0faa3b08c3 | 76 | { |
la00noix | 0:c61c6e4775ca | 77 | can1.frequency(1000000); |
la00noix | 0:c61c6e4775ca | 78 | can_ticker.attach(&can_readsend,0.01); //遅かったら早める |
la00noix | 0:c61c6e4775ca | 79 | } |