Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed move4wheel2 EC CruizCore_R1370P
can.cpp
00001 #include "mbed.h" 00002 #include "PathFollowing.h" 00003 #include "movement.h" 00004 #include "maxonsetting.h" 00005 #include "manual.h" 00006 #include "can.h" 00007 00008 CAN can1(p30,p29,1000000); 00009 Ticker can_ticker; //can用ticker 00010 00011 DigitalOut canread_led(LED1); //canread -> on 00012 DigitalOut cansend_led(LED2); //cansend -> on 00013 00014 void can_readsend() 00015 { 00016 CANMessage msg; 00017 00018 if(can1.read(msg)) { 00019 canread_led = 1; 00020 00021 if(msg.id == 1) { //from main 00022 00023 id1_value[0] = msg.data[0]; //decide mode(1~3) 00024 id1_value[1] = msg.data[1]; //angle of left joystick(0~359) 00025 id1_value[2] = msg.data[2]; 00026 id1_value[3] = msg.data[3]; //BOTTONR1 off/on(0 or 1) 00027 id1_value[4] = msg.data[4]; //state of right joystick(1~3) 00028 id1_value[5] = msg.data[5]; //left joystick neutral position(0 or 1) 00029 00030 //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]); 00031 } 00032 00033 if(msg.id == 3) { 00034 usw_data1 = 0.1 * (short)((msg.data[0]<<8) | msg.data[1]); 00035 //debug_printf("usw_data1 = %f\n\r",usw_data1); 00036 } 00037 00038 if(msg.id == 4){ 00039 usw_data2 = 0.1 * (short)((msg.data[0]<<8) | msg.data[1]); 00040 //debug_printf("usw_data2 = %f\n\r",usw_data2); 00041 } 00042 00043 if(msg.id == 5){ 00044 usw_data3 = 0.1 * (short)((msg.data[0]<<8) | msg.data[1]); 00045 //debug_printf("usw_data3 = %f\n\r",usw_data3); 00046 } 00047 00048 if(msg.id == 6) { 00049 usw_data4 = 0.1 * (short)((msg.data[0]<<8) | msg.data[1]); 00050 //debug_printf("usw_data4 = %f\n\r",usw_data4); 00051 } 00052 00053 } else { 00054 canread_led = 0; 00055 } 00056 00057 if(can1.write(CANMessage(7,ashi_data,4))) { //IDを7にして送信 00058 cansend_led = 1; 00059 } else { 00060 cansend_led = 0; 00061 } 00062 00063 } 00064 void can_start() 00065 { 00066 00067 while(1) { 00068 00069 CANMessage msg; 00070 00071 debug_printf("wait\n\r"); 00072 wait(0.1); 00073 if(can1.read(msg)) { 00074 break; 00075 } 00076 } 00077 } 00078 00079 void UserLoopSetting_can() 00080 { 00081 00082 can1.frequency(1000000); 00083 can_ticker.attach(&can_readsend,0.01); //遅かったら早める 00084 }
Generated on Sat Jul 16 2022 00:32:08 by
1.7.2