鱼C论坛

 找回密码
 立即注册
查看: 1719|回复: 4

[已解决]C++问题求助!!

[复制链接]
发表于 2022-12-30 20:21:50 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
有没有大佬告诉我一下这个代码写的是啥意思 求助!!顺便大致标注一下~谢谢!

  1. #include"utility.h"


  2. class ConversionPosion
  3. {
  4. public:
  5.    
  6.     ConversionPosion()
  7.     {   
  8.         SubOdometry = nh.subscribe<nav_msgs::Odometry>("/integrated_to_init",5,&ConversionPosion::OdometryHandle,this);
  9.         pubOdometry = nh.advertise<geometry_msgs::Pose2D>("/my_position",5);
  10.     }

  11.     void OdometryHandle(const nav_msgs::Odometry::ConstPtr &msg)
  12.     {
  13.         currentHeader = msg->header;
  14.         
  15.         double roll,pitch,yaw;

  16.         geometry_msgs::Quaternion geoQut = msg->pose.pose.orientation;
  17.         tf::Matrix3x3(tf::Quaternion(geoQut.z, -geoQut.x, -geoQut.y, geoQut.w)).getRPY(roll,pitch,yaw);

  18.         My_Position.theta = (yaw/PI)*180;
  19.         My_Position.x = msg->pose.pose.position.x;
  20.         My_Position.y = msg->pose.pose.position.y;

  21.         pubOdometry.publish(My_Position);

  22.     }

  23.     // void OdometryHandle(const nav_msgs::Odometry::ConstPtr &msg)
  24.     // {
  25.     //     geometry_msgs::PoseStamped thispose;
  26.     //     thispose.header.frame_id = msg->header.frame_id;
  27.     //     thispose.header.stamp = ros::Time::now();
  28.     //     thispose.pose.position.x = msg->pose.pose.position.x;
  29.     //     thispose.pose.position.y = msg->pose.pose.position.y;
  30.     //     thispose.pose.position.z = msg->pose.pose.position.z;
  31.     //     thispose.pose.orientation = msg->pose.pose.orientation;

  32.     //     path.poses.push_back(thispose);
  33.     //     path.header.frame_id = msg->header.frame_id;
  34.     //     path.header.stamp = ros::Time::now();

  35.     //     pubOdometry.publish(path);

  36.     // }
  37.    
  38.    

  39. private:
  40.     ros::NodeHandle nh;
  41.     ros::Subscriber SubOdometry;
  42.     ros::Publisher pubOdometry;
  43.    
  44.     std_msgs::Header currentHeader;

  45.     geometry_msgs::Pose2D My_Position;
  46.     nav_msgs::Path path;
  47. };


  48. int main(int argc, char *argv[])
  49. {
  50.     ros::init(argc, argv, "lego_loam");
  51.    
  52.     ConversionPosion Cp;

  53.     ROS_INFO("\033[1;32m---->\033[0m  ConversionPosion Started.");

  54.     ros::spin();
  55.    
  56.     return 0;
  57. }
复制代码
最佳答案
2022-12-31 15:48:37
大概就是定义了一个用来订阅机器人nav_msgs::Odometry消息,然后经OdometryHandle函数转换为geometry_msgs::Pose2D消息并发布出去的类;在主函数里初始化了ros并定义一个那个类的对象,然后打印了一下信息,最后进入spin,此时机器人会不断订阅nav_msgs::Odometry消息,发布geometry_msgs::Pose2D消息。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2022-12-30 20:22:29 | 显示全部楼层
这是头文件

  1. #ifndef _UTILITY_LIDAR_ODOMETRY_H_
  2. #define _UTILITY_LIDAR_ODOMETRY_H_


  3. #include <ros/ros.h>

  4. #include <sensor_msgs/Imu.h>
  5. #include <sensor_msgs/PointCloud2.h>
  6. #include <nav_msgs/Odometry.h>
  7. #include<nav_msgs/Path.h>
  8. #include<geometry_msgs/PoseStamped.h>
  9. #include<geometry_msgs/Pose2D.h>
  10. #include <geometry_msgs/Quaternion.h>
  11. #include "cloud_msgs/cloud_info.h"

  12. #include <opencv/cv.h>

  13. #include <pcl/point_cloud.h>
  14. #include <pcl/point_types.h>
  15. #include <pcl_ros/point_cloud.h>
  16. #include <pcl_conversions/pcl_conversions.h>
  17. #include <pcl/range_image/range_image.h>
  18. #include <pcl/filters/filter.h>
  19. #include <pcl/filters/voxel_grid.h>
  20. #include <pcl/kdtree/kdtree_flann.h>
  21. #include <pcl/common/common.h>
  22. #include <pcl/registration/icp.h>

  23. #include <tf/transform_broadcaster.h>
  24. #include <tf/transform_datatypes.h>

  25. #include <vector>
  26. #include <cmath>
  27. #include <algorithm>
  28. #include <queue>
  29. #include <deque>
  30. #include <iostream>
  31. #include <fstream>
  32. #include <ctime>
  33. #include <cfloat>
  34. #include <iterator>
  35. #include <sstream>
  36. #include <string>
  37. #include <limits>
  38. #include <iomanip>
  39. #include <array>
  40. #include <thread>
  41. #include <mutex>

  42. #define PI 3.14159265

  43. using namespace std;

  44. typedef pcl::PointXYZI  PointType;

  45. extern const string pointCloudTopic = "/lidar_points";
  46. extern const string imuTopic = "";

  47. // Save pcd
  48. extern const string fileDirectory = "/home/lizhiyuan/";

  49. // Using velodyne cloud "ring" channel for image projection (other lidar may have different name for this channel, change "PointXYZIR" below)
  50. extern const bool useCloudRing = false; // if true, ang_res_y and ang_bottom are not used

  51. // VLP-16
  52. //extern const int N_SCAN = 16;
  53. //extern const int Horizon_SCAN = 1800;
  54. //extern const float ang_res_x = 0.2;
  55. //extern const float ang_res_y = 2.0;
  56. //extern const float ang_bottom = 15.0+0.1;
  57. //extern const int groundScanInd = 7;

  58. // HDL-32E
  59. // extern const int N_SCAN = 32;
  60. // extern const int Horizon_SCAN = 1800;
  61. // extern const float ang_res_x = 360.0/float(Horizon_SCAN);
  62. // extern const float ang_res_y = 41.33/float(N_SCAN-1);
  63. // extern const float ang_bottom = 30.67;
  64. // extern const int groundScanInd = 20;

  65. //C-Fans-32
  66. // extern const int N_SCAN = 32;
  67. // extern const int Horizon_SCAN =600;
  68. // extern const float ang_res_x = 0.2;
  69. // extern const float ang_res_y =0.6;
  70. // extern const float ang_bottom = 10.2;
  71. // extern const int groundScanInd = 10;

  72. //R-Fans-32
  73. // extern const int N_SCAN = 32;
  74. // extern const int Horizon_SCAN =2000;
  75. // extern const float ang_res_x = 0.18;
  76. // extern const float ang_res_y =1;
  77. // extern const float ang_bottom = 20;
  78. // extern const int groundScanInd = 10;
  79. //R-fans-32M
  80. extern const int N_SCAN = 32;
  81. extern const int Horizon_SCAN =2000;
  82. extern const float ang_res_x = 0.18;
  83. //extern const float ang_res_y =0.87;
  84. extern const float ang_bottom = 16.9;
  85. extern const int groundScanInd = 10;
  86. //HDL-64
  87. // extern const int N_SCAN = 64;
  88. // extern const int Horizon_SCAN =4000;
  89. // extern const float ang_res_x = 0.09;
  90. // extern const float ang_res_y =0.4;
  91. // extern const float ang_bottom = 24.8;
  92. // extern const int groundScanInd = 20;



  93. // VLS-128
  94. // extern const int N_SCAN = 128;
  95. // extern const int Horizon_SCAN = 1800;
  96. // extern const float ang_res_x = 0.2;
  97. // extern const float ang_res_y = 0.3;
  98. // extern const float ang_bottom = 25.0;
  99. // extern const int groundScanInd = 10;

  100. // Ouster users may need to uncomment line 159 in imageProjection.cpp
  101. // Usage of Ouster imu data is not fully supported yet (LeGO-LOAM needs 9-DOF IMU), please just publish point cloud data
  102. // Ouster OS1-16
  103. // extern const int N_SCAN = 16;
  104. // extern const int Horizon_SCAN = 1024;
  105. // extern const float ang_res_x = 360.0/float(Horizon_SCAN);
  106. // extern const float ang_res_y = 33.2/float(N_SCAN-1);
  107. // extern const float ang_bottom = 16.6+0.1;
  108. // extern const int groundScanInd = 7;

  109. // Ouster OS1-64
  110. // extern const int N_SCAN = 64;
  111. // extern const int Horizon_SCAN = 1024;
  112. // extern const float ang_res_x = 360.0/float(Horizon_SCAN);
  113. // extern const float ang_res_y = 33.2/float(N_SCAN-1);
  114. // extern const float ang_bottom = 16.6+0.1;
  115. // extern const int groundScanInd = 15;

  116. extern const bool loopClosureEnableFlag = false;
  117. extern const double mappingProcessInterval = 0.3;

  118. extern const float scanPeriod = 0.1;
  119. extern const int systemDelay = 0;
  120. extern const int imuQueLength = 200;

  121. extern const float sensorMinimumRange = 1.0;
  122. extern const float sensorMountAngle = 0.0;
  123. extern const float segmentTheta = 60.0/180.0*M_PI; // decrese this value may improve accuracy
  124. extern const int segmentValidPointNum = 5;
  125. extern const int segmentValidLineNum = 3;
  126. extern const float segmentAlphaX = ang_res_x / 180.0 * M_PI;
  127. extern const float segmentAlphaY = 1/ 180.0 * M_PI;


  128. extern const int edgeFeatureNum = 2;
  129. extern const int surfFeatureNum = 4;
  130. extern const int sectionsTotal = 6;
  131. extern const float edgeThreshold = 0.1;
  132. extern const float surfThreshold = 0.1;
  133. extern const float nearestFeatureSearchSqDist = 25;


  134. // Mapping Params
  135. extern const float surroundingKeyframeSearchRadius = 50.0; // key frame that is within n meters from current pose will be considerd for scan-to-map optimization (when loop closure disabled)
  136. extern const int   surroundingKeyframeSearchNum = 50; // submap size (when loop closure enabled)
  137. // history key frames (history submap for loop closure)
  138. extern const float historyKeyframeSearchRadius = 7.0; // key frame that is within n meters from current pose will be considerd for loop closure
  139. extern const int   historyKeyframeSearchNum = 25; // 2n+1 number of hostory key frames will be fused into a submap for loop closure
  140. extern const float historyKeyframeFitnessScore = 0.3; // the smaller the better alignment

  141. extern const float globalMapVisualizationSearchRadius = 500.0; // key frames with in n meters will be visualized


  142. struct smoothness_t{
  143.     float value;
  144.     size_t ind;
  145. };

  146. struct by_value{
  147.     bool operator()(smoothness_t const &left, smoothness_t const &right) {
  148.         return left.value < right.value;
  149.     }
  150. };

  151. /*
  152.     * A point cloud type that has "ring" channel
  153.     */
  154. struct PointXYZIR
  155. {
  156.     PCL_ADD_POINT4D
  157.     PCL_ADD_INTENSITY;
  158.     uint16_t ring;
  159.     EIGEN_MAKE_ALIGNED_OPERATOR_NEW
  160. } EIGEN_ALIGN16;

  161. POINT_CLOUD_REGISTER_POINT_STRUCT (PointXYZIR,  
  162.                                    (float, x, x) (float, y, y)
  163.                                    (float, z, z) (float, intensity, intensity)
  164.                                    (uint16_t, ring, ring)
  165. )

  166. /*
  167.     * A point cloud type that has 6D pose info ([x,y,z,roll,pitch,yaw] intensity is time stamp)
  168.     */
  169. struct PointXYZIRPYT
  170. {
  171.     PCL_ADD_POINT4D
  172.     PCL_ADD_INTENSITY;
  173.     float roll;
  174.     float pitch;
  175.     float yaw;
  176.     double time;
  177.     EIGEN_MAKE_ALIGNED_OPERATOR_NEW
  178. } EIGEN_ALIGN16;

  179. POINT_CLOUD_REGISTER_POINT_STRUCT (PointXYZIRPYT,
  180.                                    (float, x, x) (float, y, y)
  181.                                    (float, z, z) (float, intensity, intensity)
  182.                                    (float, roll, roll) (float, pitch, pitch) (float, yaw, yaw)
  183.                                    (double, time, time)
  184. )

  185. typedef PointXYZIRPYT  PointTypePose;

  186. #endif
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-12-30 23:34:30 | 显示全部楼层
学一下ROS就知道了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-12-31 14:47:32 | 显示全部楼层
lvk 发表于 2022-12-30 23:34
学一下ROS就知道了

那这段大致是啥意思大佬!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-12-31 15:48:37 | 显示全部楼层    本楼为最佳答案   
大概就是定义了一个用来订阅机器人nav_msgs::Odometry消息,然后经OdometryHandle函数转换为geometry_msgs::Pose2D消息并发布出去的类;在主函数里初始化了ros并定义一个那个类的对象,然后打印了一下信息,最后进入spin,此时机器人会不断订阅nav_msgs::Odometry消息,发布geometry_msgs::Pose2D消息。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-1 02:54

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表