瀏覽代碼

1、修改超差逻辑判定bug
2、在localization节点添加读取txt文件,通过txt文件中的数据替代模拟量发布数据

limengqi 5 月之前
父節點
當前提交
7d243d8c3a
共有 3 個文件被更改,包括 48 次插入6 次删除
  1. 1 2
      src/canbus/canbus.cpp
  2. 39 3
      src/localization/localization.cpp
  3. 8 1
      src/localization/localization.h

+ 1 - 2
src/canbus/canbus.cpp

@@ -2604,8 +2604,7 @@ void Canbus::RackTestReplyOnTimer(const ros::TimerEvent &event)
       over_min = 0;
     }
 
-    if(rack_set_speed - rack_actual_speed > over_max
-       || rack_set_speed - rack_actual_speed < over_min)
+    if(rack_actual_speed > over_max || rack_actual_speed < over_min)
     {
       if(!over_speed_flag)
       {

+ 39 - 3
src/localization/localization.cpp

@@ -13,7 +13,8 @@
 #include <cmath>
 #include <arpa/inet.h>
 #include <sys/socket.h>
-
+#include <fstream>
+using namespace std;
 
 namespace  robot{
 namespace localizationspace {
@@ -76,6 +77,9 @@ int Localization::Start() {
   LOG(INFO)<<Name()<<" start start...";
   geometry_pub = node_handle_->advertise<localization::localMsg>(robot::common::Geometry, 1);
   //TODO  zhushidiao
+//  string str = "/home/madesheng/taskuidata.txt";
+//  read_txt(str);
+//  speed_count = 0;
 //      rack_test_timer_ = CreateTimer(ros::Duration(duration_rack), &Localization::RackTestOnTimer, this,false,false);
 //      rack_test_timer_.start();
   //TODO dakai
@@ -181,11 +185,43 @@ void Localization::RackTestOnTimer(const ros::TimerEvent &event)
   localization.Latitude = 0;
   localization.Height =0;
   localization.AngleDeviated = 0;
-  localization.Speed = 0;
+  if(speed_count <= speed_number -1)
+  {
+    localization.Speed = speeds[speed_count];
+  }
+  else
+  {
+    localization.Speed = 0;
+  }
   geometry_pub.publish(localization);
+  speed_count ++;
 
 }
-
+int Localization::read_txt(string &path)
+{
+  //ifstream myfile("/home/madesheng/data.txt");
+  ifstream myfile(path);
+  if (!myfile.is_open())
+  {
+      LOG(ERROR)<<Name()<< "open src File  Error opening file" << endl;
+      return ROBOT_FAILTURE;
+  }
+  for (int i = 0; i < 18000; i++)
+  {
+      if(myfile.eof())
+      {
+          speed_number = i;
+          break;
+      }
+      myfile >> speeds[i];
+      //myfile >> temp;
+      //cout <<"char:"<< temp<< endl;
+     //cout <<"angle:"<< angles[i] <<endl;
+  }
+  cout << "speed NUMBER:" <<speed_number<<endl;
+   myfile.close();
+   return ROBOT_SUCCESS;
+}
 bool Localization::IsOpen()
 {
   //检测串口是否已经打开,并给出提示信息

+ 8 - 1
src/localization/localization.h

@@ -23,6 +23,8 @@
 #include <math.h>
 #include "localizationdata.h"
 
+using namespace std;
+
 /**
  * @namespace robot::localization
  * @brief robot::localization
@@ -104,6 +106,11 @@ class Localization : public robot::common::RobotApp{
    * @return ture or false
    */
   int PublishData(NMEA0183 &nmea);
+
+  int read_txt(string &path);  //读取TXT文件
+  double speeds[17810] = {0};  //TXT文件中的角度值
+  int speed_number = 0; //TXT文件中的角度值的数量
+  int speed_count = 0;
 private:
   int64_t last_timestamp_ = 0;
 
@@ -133,7 +140,7 @@ private:
   unsigned char modbus_recv[11];
   //----------
 
-  const double duration_rack = 0.005;//10ms//台架测试任务执行时间
+  const double duration_rack = 0.1;//5ms//台架测试任务执行时间
      ros::Timer rack_test_timer_;    //台架测试任务定时器
       void RackTestOnTimer(const ros::TimerEvent &event);  //台架测试任务定时器回调函数
 };