111

Dependencies:   yezhong_main_controller_copy mbed1-dev

Files at this revision

API Documentation at this revision

Comitter:
ganlikun
Date:
Thu Jul 07 11:38:10 2022 +0000
Parent:
4:3f7a59212142
Commit message:
112

Changed in this revision

CAN/CAN.cpp Show annotated file Show diff for this revision Revisions of this file
LEG_MESSAGE/leg_message.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-dev.lib Show annotated file Show diff for this revision Revisions of this file
--- a/CAN/CAN.cpp	Mon Jun 13 12:25:22 2022 +0000
+++ b/CAN/CAN.cpp	Thu Jul 07 11:38:10 2022 +0000
@@ -8,7 +8,7 @@
 CAN df_can(PB_12, PB_13);                                                       // CAN Rx pin name, CAN Tx pin name
 // 定义CAN消息
 CANMessage pf_rxMsg, df_rxMsg;                                                  // 主控收到的CAN消息
-CANMessage PF_can, DF_can;                                                      // 主控发送的CAN消息
+CANMessage PF_can,   DF_can;                                                      // 主控发送的CAN消息
 
 //=================================函数=======================================//
 
@@ -31,19 +31,19 @@
 /// 7: [torque[7-0]]
 void pack_cmd(CANMessage * msg, joint_control joint){
      
-     /// limit data to be within bounds ///
+     /// limit data to be within bounds 将数据限制在一定范围内///
      float p_des = fminf(fmaxf(P_MIN, joint.p_des), P_MAX);                    
      float v_des = fminf(fmaxf(V_MIN, joint.v_des), V_MAX);
      float kp = fminf(fmaxf(KP_MIN, joint.kp), KP_MAX);
      float kd = fminf(fmaxf(KD_MIN, joint.kd), KD_MAX);
      float t_ff = fminf(fmaxf(T_MIN, joint.t_ff), T_MAX);
-     /// convert floats to unsigned ints ///
+     /// convert floats to unsigned ints 将浮点数转换为无符号整数///
      uint16_t p_int = float_to_uint(p_des, P_MIN, P_MAX, 16);            
      uint16_t v_int = float_to_uint(v_des, V_MIN, V_MAX, 12);
      uint16_t kp_int = float_to_uint(kp, KP_MIN, KP_MAX, 12);
      uint16_t kd_int = float_to_uint(kd, KD_MIN, KD_MAX, 12);
      uint16_t t_int = float_to_uint(t_ff, T_MIN, T_MAX, 12);
-     /// pack ints into the can buffer ///
+     /// pack ints into the can buffer 将整型数据打包到can缓冲区中///
      msg->data[0] = p_int>>8;                                       
      msg->data[1] = p_int&0xFF;
      msg->data[2] = v_int>>4;
@@ -84,7 +84,7 @@
 /// 3: [velocity[3-0], current[11-8]]
 /// 4: [current[7-0]]
 void unpack_reply(CANMessage msg, ankle_state * ankle){
-    /// unpack ints from can buffer ///
+    /// unpack ints from can buffer 从can缓冲区解包整数///
     uint16_t id = msg.data[0];
     uint16_t p_int = (msg.data[1]<<8)|msg.data[2];
     uint16_t v_int = (msg.data[3]<<4)|(msg.data[4]>>4);
@@ -100,7 +100,7 @@
         ankle->pf.v = v;
         ankle->pf.t = t;
         }
-    else if(id==0x03){
+    else if(id==0x02){
         ankle->df.p = p;
         ankle->df.v = v;
         ankle->df.t = t;
--- a/LEG_MESSAGE/leg_message.h	Mon Jun 13 12:25:22 2022 +0000
+++ b/LEG_MESSAGE/leg_message.h	Thu Jul 07 11:38:10 2022 +0000
@@ -22,39 +22,8 @@
     };
 
 
-//struct cal_data_t
-//{
-//    float q_pf;
-//    float q_df;
-//
-//    float qd_pf;
-//    float qd_df;
-//
-//    int32_t flag_pf;
-//    int32_t flag_df;
-//    //int32_t checksum;
-//};
-//
-//struct cal_command_t
-//{
-//    float q_des_pf;
-//    float q_des_df;
-//
-//    float qd_des_pf;
-//    float qd_des_df;
-//
-//    float kp_pf;
-//    float kp_df;
-//
-//    float kd_pf;
-//    float kd_df;
-//
-//    float tau_pf_ff;
-//    float tau_df_ff;
-//
-//    int32_t flag;                                                               // 进入电机模式标志位
-//    //int32_t checksum;
-//};
+
+
 
 
 #endif
\ No newline at end of file
--- a/main.cpp	Mon Jun 13 12:25:22 2022 +0000
+++ b/main.cpp	Thu Jul 07 11:38:10 2022 +0000
@@ -15,7 +15,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 
-int main()
+int main() 
 {
      //Timer t;
      //float a=PI/8;
@@ -35,20 +35,21 @@
     pf_can.filter(CAN_ID<<21, 0xFFE00004, CANStandard, 0);
     pf_rxMsg.len = 6;
     PF_can.len   = 8;
-    PF_can.id    = 0x02;
+    PF_can.id    = 0x03;
     
     df_can.frequency(800000);
     df_can.filter(CAN_ID<<21, 0xFFE00004, CANStandard, 0);
     df_rxMsg.len = 6;
-    DF_can.len   = 8;
+    DF_can.len   = 8;    
     DF_can.id    = 0x02;
     
 /////////////////////////////////////position///////////////////////////////////////////
     wait(6);
       Zero(&PF_can);
+      EnterMotorMode(&PF_can);
+       
       Zero(&DF_can);//0位置
-    EnterMotorMode(&PF_can);
-    EnterMotorMode(&DF_can);//电机模式
+      EnterMotorMode(&DF_can);//电机模式
     
 /*
     a_control.pf.p_des=PI/8;
@@ -80,9 +81,9 @@
         float pfkv = a_state.pf.v;
         float pfkt = a_state.pf.t;
 
-        //float dfp = a_state.df.p;
-       // float dfv = a_state.df.v;
-       // float dft = a_state.df.t;
+        float dfp = a_state.df.p;
+        float dfv = a_state.df.v;
+        float dft = a_state.df.t;
 
        // pc.printf("%.3f--%.3f--%.3f==================%.3f--%.3f--%.3f\n",pfkp,pfkv,pfkt,dfp,dfv,dft);
        // pc.printf("%.4f,%.3f,%.3f,%.4f,%.3f,%.4f\n",pfkp,pfkv,pfkt,a_control.pf.p_des,j,P);
@@ -159,6 +160,7 @@
         a_control.df.kp=0;
         a_control.df.kd=5;
         a_control.df.t_ff=0;
+        
         PackAll();
         WriteAll();       
 
--- a/mbed-dev.lib	Mon Jun 13 12:25:22 2022 +0000
+++ b/mbed-dev.lib	Thu Jul 07 11:38:10 2022 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/ganlikun/code/mbed-dev/#13413ea9a877
+https://os.mbed.com/users/ganlikun/code/mbed1-dev/#13413ea9a877