2月25日
Dependencies: uw_28015 mbed ros_lib_kinetic move4wheel2 EC CruizCore_R6093U CruizCore_R1370P
Diff: can/can.cpp
- Revision:
- 0:44f9a43e4ab2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/can/can.cpp Tue Feb 25 01:20:43 2020 +0000 @@ -0,0 +1,86 @@ +#include "mbed.h" +#include "PathFollowing.h" +#include "movement.h" +#include "manual.h" +#include "can.h" + +CAN can1(p30,p29); +Ticker can_ticker; //can用ticker + +DigitalOut cansend_led(LED1); //cansend -> on +DigitalOut canread_led(LED2); //canread -> on + +int t1_r=0, T1=0; //動作番号(受け取った値、送信する値(int型)) +int k = 0; + +void can_readsend() +{ + CANMessage msg; + if(can1.read(msg)) { + //printf(" CAN success\n\r"); + if(msg.id == 2) { + t1_r = msg.data[0]; + //printf("main T1 = %d t1_r = %d\n\r",T1,t1_r); + } + + } else { + canread_led = 0; + //printf("fale\n\r"); + } + /* if(k > 100){ + printf("T1 in can_read = %d\n\r",T1); + k = 0; + } + k++;*/ + can_num[0] = T1; //動作番号(id節約のため、can_ashileddata[]と一緒に送る) + //can_num[0] = 1; + + can_ashileddata2[0] = m1 >> 8; + can_ashileddata2[1] = m1 &255; + + can_ashileddata2[2] = m2 >> 8; + can_ashileddata2[3] = m2 &255; + + can_ashileddata2[4] = m3 >> 8; + can_ashileddata2[5] = m3 &255; + + can_ashileddata2[6] = m4 >> 8; + can_ashileddata2[7] = m4 &255; + + + if(can1.write(CANMessage(1,can_num,1))) { + cansend_led = 1; + } + + if(can1.write(CANMessage(4,can_ashileddata2,8))) { //IDを4にして送信 + //printf("success : %d \n\r",m1); + cansend_led = 1; + } + + if(t1_r > T1) { + T1 = t1_r; + } + +} + +void can_start() +{ + + while(1) { + + CANMessage msg; + +// debug_printf("wait\n\r"); + printf("wait\n\r"); + wait(0.1); + if(can1.read(msg)) { + break; + } + } +} + +void UserLoopSetting_can() +{ + can1.frequency(1000000); + can_ticker.attach(&can_readsend,0.01); //遅かったら早める +} \ No newline at end of file