3/19 23:30
Dependencies: mbed move4wheel2 EC CruizCore_R1370P
can/can.cpp@1:3c11e07da92a, 2019-02-25 (annotated)
- Committer:
- yuki0701
- Date:
- Mon Feb 25 06:18:09 2019 +0000
- Revision:
- 1:3c11e07da92a
- Parent:
- 0:c61c6e4775ca
- Child:
- 2:7cba05e70367
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 | 0:c61c6e4775ca | 8 | CAN can1(p30,p29/*,1000000*/); |
la00noix | 0:c61c6e4775ca | 9 | Ticker can_ticker; //can用ticker |
la00noix | 0:c61c6e4775ca | 10 | |
la00noix | 0:c61c6e4775ca | 11 | DigitalOut canread_led(LED1); //canread -> on |
la00noix | 0:c61c6e4775ca | 12 | DigitalOut cansend_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; |
la00noix | 0:c61c6e4775ca | 17 | |
la00noix | 0:c61c6e4775ca | 18 | if(can1.read(msg)) { |
la00noix | 0:c61c6e4775ca | 19 | canread_led = 1; |
la00noix | 0:c61c6e4775ca | 20 | |
la00noix | 0:c61c6e4775ca | 21 | if(msg.id == 1){ //from main |
la00noix | 0:c61c6e4775ca | 22 | |
la00noix | 0:c61c6e4775ca | 23 | id1_value[0] = msg.data[0]; //decide mode(1~3) |
la00noix | 0:c61c6e4775ca | 24 | id1_value[1] = msg.data[1]; //angle of left joystick(0~359) |
la00noix | 0:c61c6e4775ca | 25 | id1_value[2] = msg.data[2]; |
la00noix | 0:c61c6e4775ca | 26 | id1_value[3] = msg.data[3]; //BOTTONR1 off/on(0 or 1) |
la00noix | 0:c61c6e4775ca | 27 | id1_value[4] = msg.data[4]; //state of right joystick(1~3) |
la00noix | 0:c61c6e4775ca | 28 | id1_value[5] = msg.data[5]; //left joystick neutral position(0 or 1) |
la00noix | 0:c61c6e4775ca | 29 | |
la00noix | 0:c61c6e4775ca | 30 | //debug_printf("[0]=%d [1]=%d [2]=%d [3]=%d [4]=%d [5]=%d\n\r",id1_value[0],id1_value[1],id1_value[2],id1_value[3],id1_value[4],id1_value[5]); |
la00noix | 0:c61c6e4775ca | 31 | } |
la00noix | 0:c61c6e4775ca | 32 | |
la00noix | 0:c61c6e4775ca | 33 | if(msg.id == 3){ |
yuki0701 | 1:3c11e07da92a | 34 | usw_data1 = 0.1 * (short)((msg.data[0]<<8) | msg.data[1]); |
la00noix | 0:c61c6e4775ca | 35 | //printf("usw_data1 = %d:%d,%lf\n\r",msg.data[0],msg.data[1],usw_data1); |
la00noix | 0:c61c6e4775ca | 36 | //debug_printf("%f\n\r",usw_data1); |
la00noix | 0:c61c6e4775ca | 37 | } |
la00noix | 0:c61c6e4775ca | 38 | |
yuki0701 | 1:3c11e07da92a | 39 | /* if(msg.id == 4){ |
yuki0701 | 1:3c11e07da92a | 40 | usw_data2 = 0.1 * (short)((msg.data[0]<<8) | msg.data[1]); |
la00noix | 0:c61c6e4775ca | 41 | //printf("usw_data2 = %d:%d,%d\n\r",msg.data[0],msg.data[1],usw_data2); |
yuki0701 | 1:3c11e07da92a | 42 | }*/ |
la00noix | 0:c61c6e4775ca | 43 | |
la00noix | 0:c61c6e4775ca | 44 | if(msg.id == 5){ |
yuki0701 | 1:3c11e07da92a | 45 | usw_data3 = 0.1 * (short)((msg.data[0]<<8) | msg.data[1]); |
la00noix | 0:c61c6e4775ca | 46 | //printf("usw_data3 = %d:%d,%d\n\r",msg.data[0],msg.data[1],usw_data3); |
la00noix | 0:c61c6e4775ca | 47 | //debug_printf("%f\n\r",usw_data3); |
la00noix | 0:c61c6e4775ca | 48 | } |
la00noix | 0:c61c6e4775ca | 49 | |
yuki0701 | 1:3c11e07da92a | 50 | /*if(msg.id == 6){ |
yuki0701 | 1:3c11e07da92a | 51 | usw_data4 = 0.1 * (short)((msg.data[0]<<8) | msg.data[1]); |
la00noix | 0:c61c6e4775ca | 52 | //printf("usw_data4 = %d:%d,%d\n\r",msg.data[0],msg.data[1],usw_data4); |
yuki0701 | 1:3c11e07da92a | 53 | }*/ |
la00noix | 0:c61c6e4775ca | 54 | |
la00noix | 0:c61c6e4775ca | 55 | }else{ |
la00noix | 0:c61c6e4775ca | 56 | canread_led = 0; |
la00noix | 0:c61c6e4775ca | 57 | } |
la00noix | 0:c61c6e4775ca | 58 | |
yuki0701 | 1:3c11e07da92a | 59 | if(can1.write(CANMessage(7,ashi_data,4))) { //IDを7にして送信 |
la00noix | 0:c61c6e4775ca | 60 | cansend_led = 1; |
la00noix | 0:c61c6e4775ca | 61 | }else{ |
la00noix | 0:c61c6e4775ca | 62 | cansend_led = 0; |
la00noix | 0:c61c6e4775ca | 63 | } |
la00noix | 0:c61c6e4775ca | 64 | } |
la00noix | 0:c61c6e4775ca | 65 | |
la00noix | 0:c61c6e4775ca | 66 | void can_start(){ |
la00noix | 0:c61c6e4775ca | 67 | |
la00noix | 0:c61c6e4775ca | 68 | while(1){ |
la00noix | 0:c61c6e4775ca | 69 | |
la00noix | 0:c61c6e4775ca | 70 | CANMessage msg; |
la00noix | 0:c61c6e4775ca | 71 | |
la00noix | 0:c61c6e4775ca | 72 | if(can1.read(msg)){ |
la00noix | 0:c61c6e4775ca | 73 | break; |
la00noix | 0:c61c6e4775ca | 74 | } |
la00noix | 0:c61c6e4775ca | 75 | } |
la00noix | 0:c61c6e4775ca | 76 | } |
la00noix | 0:c61c6e4775ca | 77 | |
la00noix | 0:c61c6e4775ca | 78 | void UserLoopSetting_can(){ |
la00noix | 0:c61c6e4775ca | 79 | |
la00noix | 0:c61c6e4775ca | 80 | can1.frequency(1000000); |
la00noix | 0:c61c6e4775ca | 81 | can_ticker.attach(&can_readsend,0.01); //遅かったら早める |
la00noix | 0:c61c6e4775ca | 82 | } |