2/24 操舵まいn
Dependencies: mbed
Fork of Control_Main_Full by
main.cpp
- Committer:
- YusukeWakuta
- Date:
- 2016-02-13
- Revision:
- 0:b1290ca6c4a2
- Child:
- 1:65a3a2a4f535
File content as of revision 0:b1290ca6c4a2:
//中央can program #include "mbed.h" #define WAIT_LOOP_TIME 0.1 #define YOKUTAN_DATAS_NUM 5 #define IMPUT_DATAS_NUM 2 #define SEND_DATAS_CAN_ID 100 CAN can_R(p9,p10); CAN can_L(p30,p29); Serial toKeikiSerial(p28,p27); Serial pc(USBTX,USBRX); DigitalIn eruron_R(p7); DigitalIn eruron_L(p7); DigitalIn drug_R(p8); DigitalIn drug_L(p8); DigitalOut myled1(LED1); DigitalOut myled2(LED2); signed char yokutanDatas_R[YOKUTAN_DATAS_NUM]; signed char yokutanDatas_L[YOKUTAN_DATAS_NUM]; char inputDatas_R[IMPUT_DATAS_NUM]; char inputDatas_L[IMPUT_DATAS_NUM]; CANMessage recmsg_R(SEND_DATAS_CAN_ID, inputDatas_R, IMPUT_DATAS_NUM); CANMessage recmsg_L(SEND_DATAS_CAN_ID, inputDatas_R, IMPUT_DATAS_NUM); void InputAndSentControlValues_R(){ inputDatas_R[0] = eruron_R; inputDatas_R[1] = drug_R; for(int i = 0; i < IMPUT_DATAS_NUM; i++){ if(can_R.write(recmsg_R)){ pc.printf("Right successed!\n\r"); } } } void ledcheck_R() { myled1 = 1; wait(0.2); myled1 = 0; wait(0.2); } void ledcheck_L() { myled2 = 1; wait(0.2); myled2 = 0; wait(0.2); } void InputAndSentControlValues_L(){ inputDatas_L[0] = eruron_L; inputDatas_L[1] = drug_L; for(int i = 0; i < IMPUT_DATAS_NUM; i++){ if(can_L.write(recmsg_L)){ pc.printf("Left successed!\n\r"); } } } void SendDarasToKeiki(){ for(int i = 0; i < YOKUTAN_DATAS_NUM; i++){ toKeikiSerial.putc(yokutanDatas_R[i]); toKeikiSerial.putc(yokutanDatas_L[i]); } } void toString_R(){ for(int i = 0; i < YOKUTAN_DATAS_NUM; i++){ pc.printf("R : %i:",yokutanDatas_R[i]); } pc.printf("\t"); } void toString_L(){ for(int i = 0; i < YOKUTAN_DATAS_NUM; i++){ pc.printf("L : %i:",yokutanDatas_L[i]); } pc.printf("\n\r"); } void init(){ } void receiveDatas(){ if(can_R.read(recmsg_R)){ ledcheck_R(); for(int i = 0; i < recmsg_R.len; i++){ yokutanDatas_R[i] = recmsg_R.data[i]; } } if(can_L.read(recmsg_L)){ ledcheck_L(); for(int i = 0; i < recmsg_L.len; i++){ yokutanDatas_L[i] = recmsg_L.data[i]; } } } int main(){ init(); while(1){ InputAndSentControlValues_R(); InputAndSentControlValues_L(); wait_us(10); receiveDatas(); toString_R(); toString_L(); wait(WAIT_LOOP_TIME); } }