GAMS  1.2.2
RosParser.h
Go to the documentation of this file.
1 
8 #ifndef _GAMS_UTILITY_ROS_ROS_PARSER_
9 #define _GAMS_UTILITY_ROS_ROS_PARSER_
10 
11 #include "madara/knowledge/KnowledgeBase.h"
12 #include "madara/knowledge/containers/NativeDoubleVector.h"
13 #include "madara/knowledge/containers/NativeIntegerVector.h"
14 #include "madara/knowledge/containers/Double.h"
15 #include "madara/knowledge/containers/String.h"
16 #include "madara/knowledge/containers/Integer.h"
17 #include "madara/knowledge/containers/StringVector.h"
19 #include "gams/pose/Pose.h"
20 #include "gams/pose/Quaternion.h"
21 
22 #ifdef __GNUC__
23 #pragma GCC diagnostic push
24 #pragma GCC diagnostic ignored "-Wpedantic"
25 #pragma GCC diagnostic ignored "-Wreorder"
26 #endif
27 
28 #include "ros/ros.h"
29 #include "ros/serialization.h"
30 #include "rosbag/bag.h"
31 #include "rosbag/view.h"
32 #include "rosbag/message_instance.h"
33 #include <ros_type_introspection/ros_introspection.hpp>
34 #include <topic_tools/shape_shifter.h>
35 
36 #include <tf/transform_datatypes.h>
37 
38 #include <geometry_msgs/Quaternion.h>
39 #include <geometry_msgs/Twist.h>
40 #include <geometry_msgs/Pose.h>
41 #include <nav_msgs/Odometry.h>
42 #include <sensor_msgs/Imu.h>
43 #include <sensor_msgs/LaserScan.h>
44 #include <sensor_msgs/CompressedImage.h>
45 #include <sensor_msgs/PointCloud2.h>
46 #include <sensor_msgs/Range.h>
47 #include <sensor_msgs/FluidPressure.h>
48 #include <geometry_msgs/TransformStamped.h>
49 #include <tf2_msgs/TFMessage.h>
50 #include <std_msgs/String.h>
51 #include <std_msgs/Int32.h>
52 
53 #ifdef __GNUC__
54 #pragma GCC diagnostic pop
55 #endif
56 
57 namespace logger = madara::logger;
58 namespace knowledge = madara::knowledge;
59 namespace containers = knowledge::containers;
60 
61 namespace gams
62 {
63  namespace utility
64  {
65  namespace ros
66  {
67  class RosParser
68  {
69  public:
70  RosParser (knowledge::KnowledgeBase * kb, std::string world_frame,
71  std::string base_frame,
72  std::string frame_prefix=gams::pose::ReferenceFrame::default_prefix());
73  void parse_message (const rosbag::MessageInstance m,
74  std::string container_name);
75  void parse_message (const topic_tools::ShapeShifter::ConstPtr& m,
76  std::string container_name);
77 
78  // Parsing for unknown types
79  void registerMessageDefinition(std::string topic_name,
80  RosIntrospection::ROSType type, std::string definition);
81  void parse_unknown (const rosbag::MessageInstance m,
82  std::string container_name);
83 
84  //known types
85  void parse_odometry (nav_msgs::Odometry * odom,
86  std::string container_name);
87  void parse_imu (sensor_msgs::Imu * imu,
88  std::string container_name);
89  void parse_laserscan (sensor_msgs::LaserScan * laser,
90  std::string container_name);
92  containers::NativeDoubleVector *orientation);
93  void parse_point (geometry_msgs::Point *point_msg,
94  containers::NativeDoubleVector *point);
95  void parse_twist (geometry_msgs::Twist *twist,
96  std::string container_name);
98  containers::NativeDoubleVector *target);
99  void parse_pose (geometry_msgs::Pose *pose,
100  std::string container_name);
101  void parse_compressed_image (sensor_msgs::CompressedImage * img,
102  std::string container_name);
103  void parse_pointcloud2 (sensor_msgs::PointCloud2 * pointcloud,
104  std::string container_name);
105  void parse_range (sensor_msgs::Range * range,
106  std::string container_name);
107  void parse_tf_message (tf2_msgs::TFMessage * tf);
108  void parse_fluidpressure (sensor_msgs::FluidPressure * press,
109  std::string container_name);
110 
111 
112  template <size_t N>
113  void parse_float64_array (boost::array<double, N> *array,
114  containers::NativeDoubleVector *target);
115  void parse_float64_array (std::vector<float> *array,
116  containers::NativeDoubleVector *target);
117 
118 
119  template <size_t N>
120  void parse_int_array (boost::array<int, N> *array,
121  containers::NativeIntegerVector *target);
122  template <class T>
123  void parse_int_array (std::vector<T> *array,
124  containers::NativeIntegerVector *target);
125 
126  protected:
127  // ros introspection parser for unknown types
128  RosIntrospection::Parser parser_;
129 
130  //to reduce the amount of memory allocations these maps are reused for
131  //all unknown topic types which are not parsed directly
132  std::map<std::string, RosIntrospection::FlatMessage> flat_containers_;
133  std::map<std::string, RosIntrospection::RenamedValues> renamed_vectors_;
134  std::vector<uint8_t> parser_buffer_;
135 
136  // Transform tree frame names
137  std::string world_frame_;
138  std::string base_frame_;
139 
140  // The knowledgebase
141  knowledge::KnowledgeBase * knowledge_;
142  knowledge::EvalSettings eval_settings_;
143  std::string frame_prefix_;
144 
145  };
146  std::string ros_to_gams_name (std::string ros_topic_name);
147  }
148  }
149 }
150 
151 
152 #endif // _GAMS_ROS_TOPIC_PARSER_
void parse_int_array(boost::array< int, N > *array, containers::NativeIntegerVector *target)
RosParser(knowledge::KnowledgeBase *kb, std::string world_frame, std::string base_frame, std::string frame_prefix=gams::pose::ReferenceFrame::default_prefix())
void parse_twist(geometry_msgs::Twist *twist, std::string container_name)
void parse_unknown(const rosbag::MessageInstance m, std::string container_name)
void parse_pose(geometry_msgs::Pose *pose, std::string container_name)
void registerMessageDefinition(std::string topic_name, RosIntrospection::ROSType type, std::string definition)
void parse_laserscan(sensor_msgs::LaserScan *laser, std::string container_name)
std::map< std::string, RosIntrospection::RenamedValues > renamed_vectors_
Definition: RosParser.h:133
void parse_pointcloud2(sensor_msgs::PointCloud2 *pointcloud, std::string container_name)
std::string ros_to_gams_name(std::string ros_topic_name)
std::vector< uint8_t > parser_buffer_
Definition: RosParser.h:134
void parse_vector3(geometry_msgs::Vector3 *vec, containers::NativeDoubleVector *target)
Eigen::Vector3d Vector3
Definition: geodetic_conv.h:86
void parse_imu(sensor_msgs::Imu *imu, std::string container_name)
void parse_message(const rosbag::MessageInstance m, std::string container_name)
std::map< std::string, RosIntrospection::FlatMessage > flat_containers_
Definition: RosParser.h:132
void parse_point(geometry_msgs::Point *point_msg, containers::NativeDoubleVector *point)
static const std::string & default_prefix()
Return the default prefix for load/save operations.
void parse_tf_message(tf2_msgs::TFMessage *tf)
void parse_quaternion(geometry_msgs::Quaternion *quat, containers::NativeDoubleVector *orientation)
knowledge::EvalSettings eval_settings_
Definition: RosParser.h:142
Contains all GAMS-related tools, classes and code.
void parse_float64_array(boost::array< double, N > *array, containers::NativeDoubleVector *target)
knowledge::KnowledgeBase * knowledge_
Definition: RosParser.h:141
void parse_fluidpressure(sensor_msgs::FluidPressure *press, std::string container_name)
gams::pose::Pose Pose
Represents a combination of Location and Orientation within a single reference frame.
Definition: Pose.h:79
gams::pose::Quaternion Quaternion
Used internally to implement angle operations.
Definition: Quaternion.h:72
RosIntrospection::Parser parser_
Definition: RosParser.h:128
void parse_odometry(nav_msgs::Odometry *odom, std::string container_name)
void parse_range(sensor_msgs::Range *range, std::string container_name)
void parse_compressed_image(sensor_msgs::CompressedImage *img, std::string container_name)