Browse Source

添加7f9,机构学习最大电流限制

limengqi 5 months ago
parent
commit
59ad23cb68

+ 1 - 0
src/canbus/CMakeLists.txt

@@ -85,6 +85,7 @@ add_message_files(FILES
    RbtSlfChckCtrlReq.srv
    IOMode.srv
    SftTxtReq.srv
+   ActuatorLearnCurrentLimit.srv
  )
 
 ## Generate actions in the 'action' folder

+ 35 - 2
src/canbus/canbus.cpp

@@ -179,6 +179,9 @@ int Canbus::Start() {
 
   ros::ServiceServer SftTxtService = node_handle_->advertiseService(robot::common::SftTxtService,
                                                                     &Canbus::SftTxtReq,this);
+
+  ros::ServiceServer ActuatorLrnCrntLmtService = node_handle_->advertiseService(robot::common::ActuatorLrnCrntLmtService,
+                                                                    &Canbus::ActuatorLrnCrrntLimitReq,this);
   //data receive
   while(ros::ok())
   {
@@ -200,7 +203,7 @@ void Canbus::OnTimer(const ros::TimerEvent &) {
       heatbeat = 0;
   }
   icuMonitor.uiICUAlive = heatbeat++;
-
+//TODO dakai
   try
   {
       canObdData_pub.publish(obd);
@@ -234,6 +237,7 @@ void Canbus::OnTimer(const ros::TimerEvent &) {
   {
        LOG(ERROR)<<Name()<< " OnTimer error. "<< ex.what();
   }
+  //TODO
 }
 
 void Canbus::Stop() {
@@ -276,6 +280,7 @@ void Canbus::InitServiceAndMsg()
 //read from CAN forever - until manual break
 int Canbus::read_loop()
 {
+  //TODO dakai
     TPCANRdMsg msg;
     __u32 status;
 
@@ -295,7 +300,7 @@ int Canbus::read_loop()
             return errno;
         }
     }
-
+//TODO
     return ROBOT_SUCCESS;
 }
 
@@ -1989,7 +1994,35 @@ bool Canbus::IOMode(canbus::IOMode::Request &req,
 }
 
 
+bool Canbus::ActuatorLrnCrrntLimitReq(canbus::ActuatorLearnCurrentLimit::Request &req,
+                                  canbus::ActuatorLearnCurrentLimit::Response &res)
+{
+  LOG(INFO)<< "controlservice start ActuatorLearnCurrentLimit";
+
+  TPCANMsg canLrnLimit;
+  try{
+      T_MOT_MAXCUR request;
+      request.uiAccMotMaxCur = req.uiAccMotMaxCur;
+      request.uiBrkMotMaxCur = req.uiBrkMotMaxCur;
+      request.uiStrMotMaxCur = req.uiStrMotMaxCur;
+
+      MessageCoder::CanMsgPackage((void*)&request, robot::common::ActuatorLearnCurrentLimit, &canLrnLimit);
 
+      if (write_data(&canLrnLimit) != ROBOT_SUCCESS)
+      {
+          res.uiReturn = 0; // =0
+          return true;
+      }
+      res.uiReturn = 1;
+  }
+  catch (ros::Exception ex)
+  {
+      res.uiReturn = 0;
+      LOG(ERROR)<< "controlservice ActuatorLearnCurrentLimit failed "<< ex.what();
+      return true;
+  }
+  return true;
+}
 
 
 }  // namespace canbus

+ 4 - 0
src/canbus/canbus.h

@@ -58,6 +58,7 @@
 #include <canbus/IOMode.h>
 #include "std_msgs/String.h"
 #include <canbus/SftTxtReq.h>
+#include <canbus/ActuatorLearnCurrentLimit.h>
 
 using namespace std;
 
@@ -265,6 +266,9 @@ class Canbus : public robot::common::RobotApp{
   bool SftTxtReq(canbus::SftTxtReq::Request &req,
                  canbus::SftTxtReq::Response &res);
 
+  bool ActuatorLrnCrrntLimitReq(canbus::ActuatorLearnCurrentLimit::Request &req,
+                                    canbus::ActuatorLearnCurrentLimit::Response &res);
+
 private:
 
   int64_t last_timestamp_ = 0;

+ 31 - 2
src/canbus/candatatype.h

@@ -298,8 +298,8 @@ typedef struct
   unsigned int :3;
   unsigned int uiPsngLrnReq:3;		//位置学习请求确认
   unsigned int :5;
-  unsigned int uiSysLrnReq:3;			//系统学习请求
-  unsigned int :5;
+  unsigned int uiSysLrnReq:4;			//系统学习请求
+  unsigned int :4;
 }T_CONTROL_CMD_7F7;
 
 typedef struct
@@ -370,6 +370,35 @@ typedef struct
 }T_ICU_MONITOR;
 
 #define	ICU_CLS_REQ_CLOSE	1		//正常关闭请求
+/****************机构学习最大电流限制**********************/
+typedef struct
+{
+  unsigned int :32;
+  unsigned int :8;
+  unsigned int uiStrMotMaxCur:8;
+  unsigned int uiBrkMotMaxCur:8;
+  unsigned int uiAccMotMaxCur:8;
+
+}T_CONTROL_CMD_7F9;
+
+typedef struct
+{
+  unsigned int uiStrMotMaxCur;
+  unsigned int uiBrkMotMaxCur;
+  unsigned int uiAccMotMaxCur;
+
+}T_MOT_MAXCUR;
+
+#define SYS_LRN_REQ_UNDEFINE    0	//无效请求
+#define	SYS_LRN_REQ_ACC			1	//油门学习
+#define	SYS_LRN_REQ_BRK			2	//制动踏板学习
+#define	SYS_LRN_REQ_CLCH		3	//离合踏板学习
+#define	SYS_LRN_REQ_STR			4	//转向学习
+#define	SYS_LRN_REQ_AUTO_SFT	5	//自动档学习
+#define	SYS_LRN_REQ_HAND_SFT	6	//手动档学习
+#define	SYS_LRN_REQ_AU_ACC			7	//油门自动学习(脱机模式下有效)
+#define	SYS_LRN_REQ_AU_BRK			8	//制动自动学习(脱机模式下有效)
+#define	SYS_LRN_REQ_AU_STR			9	//转向自动学习(脱机模式下有效)
 
 /*************制动踏板执行机构控制命令*************/
 typedef struct

+ 22 - 0
src/canbus/messagecoder.cpp

@@ -872,6 +872,25 @@ void MessageCoder::CanMsgPackageID_7F8(T_ICU_MONITOR * tIcuMonitor, TPCANMsg *tC
     tCanMsg->MSGTYPE = MSGTYPE_STANDARD;
 }
 
+//机构学习最大电流限制--数据组包
+void MessageCoder::CanMsgPackageID_7F9(T_MOT_MAXCUR *tMotMaxcur, TPCANMsg *tCanMsg)
+{
+    T_CONTROL_CMD_7F9 tCtrCmd7F9 = { 0 };
+    unsigned char ucCanMsgSrc[8] = { 0 };
+
+    tCtrCmd7F9.uiAccMotMaxCur = tMotMaxcur->uiAccMotMaxCur;
+    tCtrCmd7F9.uiBrkMotMaxCur = tMotMaxcur->uiBrkMotMaxCur;
+    tCtrCmd7F9.uiStrMotMaxCur = tMotMaxcur->uiStrMotMaxCur;
+
+    memcpy(ucCanMsgSrc, &tCtrCmd7F9, CAN_MSG_LEN);
+    CharReverse(ucCanMsgSrc,8);
+    memcpy(tCanMsg->DATA, ucCanMsgSrc, CAN_MSG_LEN);
+    tCanMsg->ID = robot::common::ActuatorLearnCurrentLimit;
+    tCanMsg->LEN = 8;
+    tCanMsg->MSGTYPE = MSGTYPE_STANDARD;
+}
+
+
 //执行机构加速度控制请求--数据组包
 void MessageCoder::CanMsgPackageID_5F5(T_STR_ACC_CTR_REQ * tActAccCtrReq, TPCANMsg *tCanMsg)
 {
@@ -1439,6 +1458,9 @@ void MessageCoder::CanMsgPackage(void * p, int id, TPCANMsg *tCanMsg)
     case robot::common::ICUMonitor://上位机监控
         CanMsgPackageID_7F8((T_ICU_MONITOR *)p, tCanMsg);
         break;
+    case robot::common::ActuatorLearnCurrentLimit:  //机构学习最大电流限制
+        CanMsgPackageID_7F9((T_MOT_MAXCUR *)p,tCanMsg);
+        break;
     case robot::common::ActuatorAccelerateCtrReq://转向机构加速度控制请求
         CanMsgPackageID_5F5((T_STR_ACC_CTR_REQ *)p,tCanMsg);
         break;

+ 3 - 0
src/canbus/messagecoder.h

@@ -135,6 +135,9 @@ private:
     //上位机监控--数据组包
     static void CanMsgPackageID_7F8(T_ICU_MONITOR *tIcuMonitor, TPCANMsg *tCanMsg);
 
+    //机构学习最大电流限制--数据组包
+    static void CanMsgPackageID_7F9(T_MOT_MAXCUR *tMotMaxcur, TPCANMsg *tCanMsg);
+
     //执行机构加速度控制请求--数据组包
     static void CanMsgPackageID_5F5(T_STR_ACC_CTR_REQ *tActAccCtrReq, TPCANMsg *tCanMsg);
 

+ 4 - 3
src/canbus/srv/ActuatorLearnCurrentLimit.srv

@@ -1,4 +1,5 @@
-int64 a
-int64 b
+uint32 uiAccMotMaxCur		#油门电机最大电流
+uint32 uiBrkMotMaxCur		#制动电机最大电流
+uint32 uiStrMotMaxCur		#转向电机最大电流
 ---
-int64 sum
+uint32 uiReturn

+ 2 - 0
src/common/canmsgobdmsgid.h

@@ -35,6 +35,8 @@ const int RobotDriverCtr = 0x5FD;
 const int RobotManager = 0x7F6;
 //上位机监控
 const int ICUMonitor = 0x7F8;
+//机构学习最大电流限制
+const int ActuatorLearnCurrentLimit = 0x7F9;
 //转向机构加速度控制请求
 const int ActuatorAccelerateCtrReq = 0x5F5;
 //执行机构限值设置

+ 2 - 0
src/common/message.h

@@ -135,6 +135,8 @@ const std::string RobotWorkMdService = "robotworkmdservice";
 const std::string EstpCtrlService = "estpctrlservice";
 
 const std::string SftTxtService = "sfttxtservice";
+
+const std::string ActuatorLrnCrntLmtService = "actuatorlrncrntlmtservice";
 // -----------------services ----------------------------