1
Dependencies: mcp2515 mbed-dev-f303
Diff: CAN/CAN.cpp
- Revision:
- 2:cd74a8cb03b0
- Parent:
- 0:d80c66cb1b3a
- Child:
- 3:940a9e40d327
--- a/CAN/CAN.cpp Tue Nov 17 11:32:58 2020 +0000 +++ b/CAN/CAN.cpp Thu Nov 19 07:59:28 2020 +0000 @@ -4,11 +4,11 @@ //定义设备 -CAN knee_can(PB_8, PB_9); // CAN Rx pin name, CAN Tx pin name -CAN ankle_can(PB_12, PB_13); // CAN Rx pin name, CAN Tx pin name +CAN pf_can(PB_8, PB_9); // CAN Rx pin name, CAN Tx pin name +CAN df_can(PB_12, PB_13); // CAN Rx pin name, CAN Tx pin name // 定义CAN消息 -CANMessage knee_rxMsg, ankle_rxMsg; // 主控收到的CAN消息 -CANMessage knee_txMsg, ankle_txMsg; // 主控发送的CAN消息 +CANMessage pf_rxMsg, df_rxMsg; // 主控收到的CAN消息 +CANMessage PF_can, DF_can; // 主控发送的CAN消息 //=================================函数=======================================// @@ -57,16 +57,16 @@ // 多个控制器联合打包准备发送 void PackAll(){ - pack_cmd(&knee_txMsg, a_control.knee); - pack_cmd(&ankle_txMsg, a_control.ankle); + pack_cmd(&PF_can, a_control.pf); + pack_cmd(&DF_can, a_control.df); } // 写联合打包的数据 void WriteAll(){ - knee_can.write(knee_txMsg); + pf_can.write(PF_can); wait(.00002); - ankle_can.write(ankle_txMsg); + df_can.write(DF_can); wait(.00002); } @@ -83,7 +83,7 @@ /// 2: [velocity[11-4]] /// 3: [velocity[3-0], current[11-8]] /// 4: [current[7-0]] -void unpack_reply(CANMessage msg, leg_state * state){ +void unpack_reply(CANMessage msg, ankle_state * ankle){ /// unpack ints from can buffer /// uint16_t id = msg.data[0]; uint16_t p_int = (msg.data[1]<<8)|msg.data[2]; @@ -93,16 +93,17 @@ float p = uint_to_float(p_int, P_MIN, P_MAX, 16); float v = uint_to_float(v_int, V_MIN, V_MAX, 12); float t = uint_to_float(i_int, -T_MAX, T_MAX, 12); + if(id==0x01){ - state->knee_state.p = p; - state->knee_state.v = v; - state->knee_state.t = t; + ankle->pf.p = p; + ankle->pf.v = v; + ankle->pf.t = t; } else if(id==0x01){ - state->ankle_state.p = p; - state->ankle_state.v = v; - state->ankle_state.t = t; + ankle->df.p = p; + ankle->df.v = v; + ankle->df.t = t; } }