Sungwoo Kim
/
HydraulicControlBoard_PostLIGHT_210420
LIGHT2
Diff: CAN/function_CAN.cpp
- Revision:
- 14:8e7590227d22
- Parent:
- 12:6f2531038ea4
- Child:
- 15:bd0d12728506
diff -r 747daba9cf59 -r 8e7590227d22 CAN/function_CAN.cpp --- a/CAN/function_CAN.cpp Tue Aug 27 06:50:54 2019 +0000 +++ b/CAN/function_CAN.cpp Thu Aug 29 07:38:00 2019 +0000 @@ -10,6 +10,7 @@ int CID_RX_REF_PRES_DIFF = 400; int CID_RX_REF_VOUT = 500; int CID_RX_REF_VALVE_POSITION = 600; +int CID_RX_REF_CURRENT = 700; int CID_TX_INFO = 1100; int CID_TX_POSITION = 1200; @@ -33,6 +34,7 @@ CID_RX_REF_PRES_DIFF = (int) (BNO + INIT_CID_RX_REF_PRES_DIFF); CID_RX_REF_VOUT = (int) (BNO + INIT_CID_RX_REF_VOUT); CID_RX_REF_VALVE_POSITION = (int) (BNO + INIT_CID_RX_REF_VALVE_POSITION); + CID_RX_REF_CURRENT = (int) (BNO + INIT_CID_RX_REF_CURRENT); CID_TX_INFO = (int) (BNO + INIT_CID_TX_INFO); CID_TX_POSITION = (int) (BNO + INIT_CID_TX_POSITION); @@ -114,6 +116,7 @@ case CRX_SET_DATA_REQUEST: { int request_type = msg.data[2]; flag_data_request[request_type] = msg.data[1]; + //pc.printf("can middle %d\n", request_type); // if (flag_data_request[1] == HIGH) SPI_VREF_DAC_WRITE(PRES_A_VREF, PRES_B_VREF, TORQUE_VREF, 0); // set DAC if (flag_data_request[1] == HIGH) dac_1 = PRES_A_VREF/3.3; @@ -595,12 +598,15 @@ void CAN_RX_HANDLER() { + //pc.printf("can received"); can.read(msg); unsigned int address = msg.id; - + //pc.printf("add %d\n",address); + //pc.printf("cmd %d\n", CID_RX_CMD); if(address==CID_RX_CMD){ unsigned int CMD = msg.data[0]; ReadCMD(CMD); + pc.printf("cmd %d\n ",CMD); } else if(address==CID_RX_REF_POSITION) { int32_t temp_pos = (int32_t) (msg.data[0] | msg.data[1] << 8 | msg.data[2] << 16 | msg.data[3] << 24); int32_t temp_vel = (int32_t) (msg.data[4] | msg.data[5] << 8 | msg.data[6] << 16 | msg.data[7] << 24); @@ -616,6 +622,9 @@ int16_t temp_PWM = (int16_t) (msg.data[0] | msg.data[1] << 8); Vout.ref = (double)temp_PWM; } else if(address==CID_RX_REF_VALVE_POSITION) { + int16_t temp_valve_pos = (int16_t) (msg.data[0] | msg.data[1] << 8); + valve_pos.ref = (double)temp_valve_pos; + } else if(address==CID_RX_REF_CURRENT) { int16_t temp_cur = (int16_t) (msg.data[0] | msg.data[1] << 8); cur.ref = (double)temp_cur; }