2月25日

Dependencies:   uw_28015 mbed ros_lib_kinetic move4wheel2 EC CruizCore_R6093U CruizCore_R1370P

Committer:
yuki0701
Date:
Tue Feb 25 01:20:43 2020 +0000
Revision:
0:44f9a43e4ab2
a;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yuki0701 0:44f9a43e4ab2 1 #include "mbed.h"
yuki0701 0:44f9a43e4ab2 2 #include "PathFollowing.h"
yuki0701 0:44f9a43e4ab2 3 #include "movement.h"
yuki0701 0:44f9a43e4ab2 4 #include "manual.h"
yuki0701 0:44f9a43e4ab2 5 #include "can.h"
yuki0701 0:44f9a43e4ab2 6
yuki0701 0:44f9a43e4ab2 7 CAN can1(p30,p29);
yuki0701 0:44f9a43e4ab2 8 Ticker can_ticker; //can用ticker
yuki0701 0:44f9a43e4ab2 9
yuki0701 0:44f9a43e4ab2 10 DigitalOut cansend_led(LED1); //cansend -> on
yuki0701 0:44f9a43e4ab2 11 DigitalOut canread_led(LED2); //canread -> on
yuki0701 0:44f9a43e4ab2 12
yuki0701 0:44f9a43e4ab2 13 int t1_r=0, T1=0; //動作番号(受け取った値、送信する値(int型))
yuki0701 0:44f9a43e4ab2 14 int k = 0;
yuki0701 0:44f9a43e4ab2 15
yuki0701 0:44f9a43e4ab2 16 void can_readsend()
yuki0701 0:44f9a43e4ab2 17 {
yuki0701 0:44f9a43e4ab2 18 CANMessage msg;
yuki0701 0:44f9a43e4ab2 19 if(can1.read(msg)) {
yuki0701 0:44f9a43e4ab2 20 //printf(" CAN success\n\r");
yuki0701 0:44f9a43e4ab2 21 if(msg.id == 2) {
yuki0701 0:44f9a43e4ab2 22 t1_r = msg.data[0];
yuki0701 0:44f9a43e4ab2 23 //printf("main T1 = %d t1_r = %d\n\r",T1,t1_r);
yuki0701 0:44f9a43e4ab2 24 }
yuki0701 0:44f9a43e4ab2 25
yuki0701 0:44f9a43e4ab2 26 } else {
yuki0701 0:44f9a43e4ab2 27 canread_led = 0;
yuki0701 0:44f9a43e4ab2 28 //printf("fale\n\r");
yuki0701 0:44f9a43e4ab2 29 }
yuki0701 0:44f9a43e4ab2 30 /* if(k > 100){
yuki0701 0:44f9a43e4ab2 31 printf("T1 in can_read = %d\n\r",T1);
yuki0701 0:44f9a43e4ab2 32 k = 0;
yuki0701 0:44f9a43e4ab2 33 }
yuki0701 0:44f9a43e4ab2 34 k++;*/
yuki0701 0:44f9a43e4ab2 35 can_num[0] = T1; //動作番号(id節約のため、can_ashileddata[]と一緒に送る)
yuki0701 0:44f9a43e4ab2 36 //can_num[0] = 1;
yuki0701 0:44f9a43e4ab2 37
yuki0701 0:44f9a43e4ab2 38 can_ashileddata2[0] = m1 >> 8;
yuki0701 0:44f9a43e4ab2 39 can_ashileddata2[1] = m1 &255;
yuki0701 0:44f9a43e4ab2 40
yuki0701 0:44f9a43e4ab2 41 can_ashileddata2[2] = m2 >> 8;
yuki0701 0:44f9a43e4ab2 42 can_ashileddata2[3] = m2 &255;
yuki0701 0:44f9a43e4ab2 43
yuki0701 0:44f9a43e4ab2 44 can_ashileddata2[4] = m3 >> 8;
yuki0701 0:44f9a43e4ab2 45 can_ashileddata2[5] = m3 &255;
yuki0701 0:44f9a43e4ab2 46
yuki0701 0:44f9a43e4ab2 47 can_ashileddata2[6] = m4 >> 8;
yuki0701 0:44f9a43e4ab2 48 can_ashileddata2[7] = m4 &255;
yuki0701 0:44f9a43e4ab2 49
yuki0701 0:44f9a43e4ab2 50
yuki0701 0:44f9a43e4ab2 51 if(can1.write(CANMessage(1,can_num,1))) {
yuki0701 0:44f9a43e4ab2 52 cansend_led = 1;
yuki0701 0:44f9a43e4ab2 53 }
yuki0701 0:44f9a43e4ab2 54
yuki0701 0:44f9a43e4ab2 55 if(can1.write(CANMessage(4,can_ashileddata2,8))) { //IDを4にして送信
yuki0701 0:44f9a43e4ab2 56 //printf("success : %d \n\r",m1);
yuki0701 0:44f9a43e4ab2 57 cansend_led = 1;
yuki0701 0:44f9a43e4ab2 58 }
yuki0701 0:44f9a43e4ab2 59
yuki0701 0:44f9a43e4ab2 60 if(t1_r > T1) {
yuki0701 0:44f9a43e4ab2 61 T1 = t1_r;
yuki0701 0:44f9a43e4ab2 62 }
yuki0701 0:44f9a43e4ab2 63
yuki0701 0:44f9a43e4ab2 64 }
yuki0701 0:44f9a43e4ab2 65
yuki0701 0:44f9a43e4ab2 66 void can_start()
yuki0701 0:44f9a43e4ab2 67 {
yuki0701 0:44f9a43e4ab2 68
yuki0701 0:44f9a43e4ab2 69 while(1) {
yuki0701 0:44f9a43e4ab2 70
yuki0701 0:44f9a43e4ab2 71 CANMessage msg;
yuki0701 0:44f9a43e4ab2 72
yuki0701 0:44f9a43e4ab2 73 // debug_printf("wait\n\r");
yuki0701 0:44f9a43e4ab2 74 printf("wait\n\r");
yuki0701 0:44f9a43e4ab2 75 wait(0.1);
yuki0701 0:44f9a43e4ab2 76 if(can1.read(msg)) {
yuki0701 0:44f9a43e4ab2 77 break;
yuki0701 0:44f9a43e4ab2 78 }
yuki0701 0:44f9a43e4ab2 79 }
yuki0701 0:44f9a43e4ab2 80 }
yuki0701 0:44f9a43e4ab2 81
yuki0701 0:44f9a43e4ab2 82 void UserLoopSetting_can()
yuki0701 0:44f9a43e4ab2 83 {
yuki0701 0:44f9a43e4ab2 84 can1.frequency(1000000);
yuki0701 0:44f9a43e4ab2 85 can_ticker.attach(&can_readsend,0.01); //遅かったら早める
yuki0701 0:44f9a43e4ab2 86 }