Sfoglia il codice sorgente

模拟量转换速度最大值设置为参数

limengqi 7 mesi fa
parent
commit
682d9991e9

+ 1 - 1
src/canbus/canbus.cpp

@@ -336,7 +336,7 @@ int Canbus::read_loop()
     if (canbus_mode == "tcp") {
       int recv_len = read(canbus_socket, s_g_pBufGet, sizeof(s_g_pBufGet));
       if (recv_len != sizeof(s_g_pBufGet)) {
-        LOG(ERROR) << Name() <<" canbus socket read error: " << recv_len;
+         LOG(ERROR) << Name() <<" canbus socket read error: " << recv_len;
       }
       else {
         msg.Msg.ID = static_cast<int>(s_g_pBufGet[3]) * 256 + static_cast<int>(s_g_pBufGet[4]);

+ 1 - 0
src/canbus/canbus.h

@@ -452,6 +452,7 @@ private:
   int canbus_socket;
 
   unsigned char s_g_pBufGet[13] , s_g_pBufSet[13];
+        unsigned char s_g_pBuf1[13] , s_g_pBuf2[13];
 
 };
 

+ 3 - 2
src/launch/robot.launch

@@ -10,9 +10,9 @@ ns = "NAME_SPACE" 这个属性可以让你在自定义的命名空间里运行
 <include file="$(find rosbridge_server)/launch/rosbridge_websocket.launch" >
     <arg name="port" value="9090"/>
  </include>
-<node pkg="decision" name="decision" type="decision" output="screen" required="true"/>-->
+<!--<node pkg="decision" name="decision" type="decision" output="screen" required="true"/>-->
 <node pkg="perception" name="perception" type="perception" output="screen" respawn="true"/>
-<!--<node pkg="localization" name="localization" type="localization" output="screen" respawn="true"/>-->
+<node pkg="localization" name="localization" type="localization" output="screen" respawn="true"/>
 <node pkg="canbus" name="canbus" type="canbus" output="screen" respawn="true"/>
 <param name = "rcu_canbus_mode" value = "tcp" /><!--can总线模式: usb(默认)/tcp-->
 <param name = "rcu_canbus_ip" value = "192.168.200.10" /><!--tcp转can模块IP地址-->
@@ -20,4 +20,5 @@ ns = "NAME_SPACE" 这个属性可以让你在自定义的命名空间里运行
 <param name = "car_input_mode" value = "modbus" /><!--速度接入方式: rtk(gpfpd)/modbus(模拟量0~10V)-->
 <param name = "car_input_ip" value = "192.168.200.80" /><!--速度接入IP地址-->
 <param name = "car_input_port" value = "502"/><!--速度接入端口-->
+<param name = "car_input_volspeed_max" value = "180.0"/><!--速度电压最大值-->
 </launch>

+ 5 - 1
src/localization/localization.cpp

@@ -74,6 +74,9 @@ int Localization::Start() {
   LOG(INFO)<<Name()<<" start start...";
   geometry_pub = node_handle_->advertise<localization::localMsg>(robot::common::Geometry, 1);
   if (car_input_mode == "modbus") {
+    if (!ros::param::get("car_input_volspeed_max", car_input_volspeed_max))
+        car_input_volspeed_max = 0;
+
     ros::Rate loop_rate(rate);
     while(ros::ok())
     {
@@ -94,7 +97,8 @@ int Localization::Start() {
               localization.Height = 0;
               localization.AngleDeviated = 0;
               int voltage = (unsigned int)modbus_recv[sizeof(modbus_recv)-2] * 256 + (unsigned int)modbus_recv[sizeof(modbus_recv)-1];
-              localization.Speed = voltage / 65535.0 * 180.0;
+              int max = car_input_volspeed_max;
+              localization.Speed = voltage / 65535.0 * max;
               geometry_pub.publish(localization);
               LOG(INFO) << Name() << " publish speed:" << std::setprecision(4) << localization.Speed;
           }

+ 2 - 0
src/localization/localization.h

@@ -124,6 +124,8 @@ private:
   //20240111 by zhaowei add tcp2can
   std::string car_input_mode; //速度接入方式: rtk(gpfpd)/modbus(模拟量0~10V)
 
+  int car_input_volspeed_max;
+
   int modbus_socket;
 
   const unsigned char modbus_req[12] = {0x00, 0x01, 0x00, 0x00, 0x00, 0x06, 0x01, 0x04, 0x01, 0x01, 0x00, 0x01};