2/24 操舵まいn

Dependencies:   mbed

Fork of Control_Main_Full by albatross

Committer:
YusukeWakuta
Date:
Sat Feb 13 07:17:50 2016 +0000
Revision:
0:b1290ca6c4a2
Child:
1:65a3a2a4f535
???????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
YusukeWakuta 0:b1290ca6c4a2 1 //中央can program
YusukeWakuta 0:b1290ca6c4a2 2
YusukeWakuta 0:b1290ca6c4a2 3 #include "mbed.h"
YusukeWakuta 0:b1290ca6c4a2 4 #define WAIT_LOOP_TIME 0.1
YusukeWakuta 0:b1290ca6c4a2 5 #define YOKUTAN_DATAS_NUM 5
YusukeWakuta 0:b1290ca6c4a2 6 #define IMPUT_DATAS_NUM 2
YusukeWakuta 0:b1290ca6c4a2 7 #define SEND_DATAS_CAN_ID 100
YusukeWakuta 0:b1290ca6c4a2 8
YusukeWakuta 0:b1290ca6c4a2 9 CAN can_R(p9,p10);
YusukeWakuta 0:b1290ca6c4a2 10 CAN can_L(p30,p29);
YusukeWakuta 0:b1290ca6c4a2 11 Serial toKeikiSerial(p28,p27);
YusukeWakuta 0:b1290ca6c4a2 12 Serial pc(USBTX,USBRX);
YusukeWakuta 0:b1290ca6c4a2 13 DigitalIn eruron_R(p7);
YusukeWakuta 0:b1290ca6c4a2 14 DigitalIn eruron_L(p7);
YusukeWakuta 0:b1290ca6c4a2 15 DigitalIn drug_R(p8);
YusukeWakuta 0:b1290ca6c4a2 16 DigitalIn drug_L(p8);
YusukeWakuta 0:b1290ca6c4a2 17 DigitalOut myled1(LED1);
YusukeWakuta 0:b1290ca6c4a2 18 DigitalOut myled2(LED2);
YusukeWakuta 0:b1290ca6c4a2 19
YusukeWakuta 0:b1290ca6c4a2 20 signed char yokutanDatas_R[YOKUTAN_DATAS_NUM];
YusukeWakuta 0:b1290ca6c4a2 21 signed char yokutanDatas_L[YOKUTAN_DATAS_NUM];
YusukeWakuta 0:b1290ca6c4a2 22 char inputDatas_R[IMPUT_DATAS_NUM];
YusukeWakuta 0:b1290ca6c4a2 23 char inputDatas_L[IMPUT_DATAS_NUM];
YusukeWakuta 0:b1290ca6c4a2 24
YusukeWakuta 0:b1290ca6c4a2 25 CANMessage recmsg_R(SEND_DATAS_CAN_ID, inputDatas_R, IMPUT_DATAS_NUM);
YusukeWakuta 0:b1290ca6c4a2 26 CANMessage recmsg_L(SEND_DATAS_CAN_ID, inputDatas_R, IMPUT_DATAS_NUM);
YusukeWakuta 0:b1290ca6c4a2 27
YusukeWakuta 0:b1290ca6c4a2 28 void InputAndSentControlValues_R(){
YusukeWakuta 0:b1290ca6c4a2 29 inputDatas_R[0] = eruron_R;
YusukeWakuta 0:b1290ca6c4a2 30 inputDatas_R[1] = drug_R;
YusukeWakuta 0:b1290ca6c4a2 31 for(int i = 0; i < IMPUT_DATAS_NUM; i++){
YusukeWakuta 0:b1290ca6c4a2 32 if(can_R.write(recmsg_R)){
YusukeWakuta 0:b1290ca6c4a2 33 pc.printf("Right successed!\n\r");
YusukeWakuta 0:b1290ca6c4a2 34 }
YusukeWakuta 0:b1290ca6c4a2 35 }
YusukeWakuta 0:b1290ca6c4a2 36 }
YusukeWakuta 0:b1290ca6c4a2 37
YusukeWakuta 0:b1290ca6c4a2 38 void ledcheck_R() {
YusukeWakuta 0:b1290ca6c4a2 39 myled1 = 1;
YusukeWakuta 0:b1290ca6c4a2 40 wait(0.2);
YusukeWakuta 0:b1290ca6c4a2 41 myled1 = 0;
YusukeWakuta 0:b1290ca6c4a2 42 wait(0.2);
YusukeWakuta 0:b1290ca6c4a2 43 }
YusukeWakuta 0:b1290ca6c4a2 44
YusukeWakuta 0:b1290ca6c4a2 45 void ledcheck_L() {
YusukeWakuta 0:b1290ca6c4a2 46 myled2 = 1;
YusukeWakuta 0:b1290ca6c4a2 47 wait(0.2);
YusukeWakuta 0:b1290ca6c4a2 48 myled2 = 0;
YusukeWakuta 0:b1290ca6c4a2 49 wait(0.2);
YusukeWakuta 0:b1290ca6c4a2 50 }
YusukeWakuta 0:b1290ca6c4a2 51
YusukeWakuta 0:b1290ca6c4a2 52 void InputAndSentControlValues_L(){
YusukeWakuta 0:b1290ca6c4a2 53 inputDatas_L[0] = eruron_L;
YusukeWakuta 0:b1290ca6c4a2 54 inputDatas_L[1] = drug_L;
YusukeWakuta 0:b1290ca6c4a2 55 for(int i = 0; i < IMPUT_DATAS_NUM; i++){
YusukeWakuta 0:b1290ca6c4a2 56 if(can_L.write(recmsg_L)){
YusukeWakuta 0:b1290ca6c4a2 57 pc.printf("Left successed!\n\r");
YusukeWakuta 0:b1290ca6c4a2 58 }
YusukeWakuta 0:b1290ca6c4a2 59 }
YusukeWakuta 0:b1290ca6c4a2 60 }
YusukeWakuta 0:b1290ca6c4a2 61
YusukeWakuta 0:b1290ca6c4a2 62 void SendDarasToKeiki(){
YusukeWakuta 0:b1290ca6c4a2 63 for(int i = 0; i < YOKUTAN_DATAS_NUM; i++){
YusukeWakuta 0:b1290ca6c4a2 64 toKeikiSerial.putc(yokutanDatas_R[i]);
YusukeWakuta 0:b1290ca6c4a2 65 toKeikiSerial.putc(yokutanDatas_L[i]);
YusukeWakuta 0:b1290ca6c4a2 66 }
YusukeWakuta 0:b1290ca6c4a2 67 }
YusukeWakuta 0:b1290ca6c4a2 68
YusukeWakuta 0:b1290ca6c4a2 69 void toString_R(){
YusukeWakuta 0:b1290ca6c4a2 70 for(int i = 0; i < YOKUTAN_DATAS_NUM; i++){
YusukeWakuta 0:b1290ca6c4a2 71 pc.printf("R : %i:",yokutanDatas_R[i]);
YusukeWakuta 0:b1290ca6c4a2 72 }
YusukeWakuta 0:b1290ca6c4a2 73 pc.printf("\t");
YusukeWakuta 0:b1290ca6c4a2 74 }
YusukeWakuta 0:b1290ca6c4a2 75
YusukeWakuta 0:b1290ca6c4a2 76 void toString_L(){
YusukeWakuta 0:b1290ca6c4a2 77 for(int i = 0; i < YOKUTAN_DATAS_NUM; i++){
YusukeWakuta 0:b1290ca6c4a2 78 pc.printf("L : %i:",yokutanDatas_L[i]);
YusukeWakuta 0:b1290ca6c4a2 79 }
YusukeWakuta 0:b1290ca6c4a2 80 pc.printf("\n\r");
YusukeWakuta 0:b1290ca6c4a2 81 }
YusukeWakuta 0:b1290ca6c4a2 82
YusukeWakuta 0:b1290ca6c4a2 83 void init(){
YusukeWakuta 0:b1290ca6c4a2 84 }
YusukeWakuta 0:b1290ca6c4a2 85
YusukeWakuta 0:b1290ca6c4a2 86
YusukeWakuta 0:b1290ca6c4a2 87 void receiveDatas(){
YusukeWakuta 0:b1290ca6c4a2 88 if(can_R.read(recmsg_R)){
YusukeWakuta 0:b1290ca6c4a2 89 ledcheck_R();
YusukeWakuta 0:b1290ca6c4a2 90 for(int i = 0; i < recmsg_R.len; i++){
YusukeWakuta 0:b1290ca6c4a2 91 yokutanDatas_R[i] = recmsg_R.data[i];
YusukeWakuta 0:b1290ca6c4a2 92 }
YusukeWakuta 0:b1290ca6c4a2 93 }
YusukeWakuta 0:b1290ca6c4a2 94 if(can_L.read(recmsg_L)){
YusukeWakuta 0:b1290ca6c4a2 95 ledcheck_L();
YusukeWakuta 0:b1290ca6c4a2 96 for(int i = 0; i < recmsg_L.len; i++){
YusukeWakuta 0:b1290ca6c4a2 97 yokutanDatas_L[i] = recmsg_L.data[i];
YusukeWakuta 0:b1290ca6c4a2 98 }
YusukeWakuta 0:b1290ca6c4a2 99 }
YusukeWakuta 0:b1290ca6c4a2 100 }
YusukeWakuta 0:b1290ca6c4a2 101
YusukeWakuta 0:b1290ca6c4a2 102
YusukeWakuta 0:b1290ca6c4a2 103 int main(){
YusukeWakuta 0:b1290ca6c4a2 104 init();
YusukeWakuta 0:b1290ca6c4a2 105 while(1){
YusukeWakuta 0:b1290ca6c4a2 106 InputAndSentControlValues_R();
YusukeWakuta 0:b1290ca6c4a2 107 InputAndSentControlValues_L();
YusukeWakuta 0:b1290ca6c4a2 108 wait_us(10);
YusukeWakuta 0:b1290ca6c4a2 109 receiveDatas();
YusukeWakuta 0:b1290ca6c4a2 110 toString_R();
YusukeWakuta 0:b1290ca6c4a2 111 toString_L();
YusukeWakuta 0:b1290ca6c4a2 112 wait(WAIT_LOOP_TIME);
YusukeWakuta 0:b1290ca6c4a2 113 }
YusukeWakuta 0:b1290ca6c4a2 114 }