8 #ifndef _GAMS_UTILITY_ROS_ROS_PARSER_
9 #define _GAMS_UTILITY_ROS_ROS_PARSER_
13 #include "madara/knowledge/KnowledgeBase.h"
14 #include "madara/knowledge/containers/NativeDoubleVector.h"
15 #include "madara/knowledge/containers/NativeIntegerVector.h"
16 #include "madara/knowledge/containers/Double.h"
17 #include "madara/knowledge/Any.h"
18 #include "madara/knowledge/CapnObject.h"
19 #include "madara/knowledge/containers/String.h"
20 #include "madara/knowledge/containers/Integer.h"
21 #include "madara/knowledge/containers/StringVector.h"
22 #include "madara/knowledge/containers/CircularBuffer.h"
23 #include "madara/utility/SimTime.h"
24 #include "madara/utility/Utility.h"
31 #pragma GCC diagnostic push
32 #pragma GCC diagnostic ignored "-Wpedantic"
33 #pragma GCC diagnostic ignored "-Wreorder"
34 #pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
39 #include "ros/serialization.h"
40 #include "rosbag/bag.h"
41 #include "rosbag/view.h"
42 #include "rosbag/message_instance.h"
43 #include <ros_type_introspection/ros_introspection.hpp>
44 #include <topic_tools/shape_shifter.h>
46 #include <pcl_conversions/pcl_conversions.h>
47 #include <pcl/point_types.h>
48 #include <pcl/PCLPointCloud2.h>
49 #include <pcl_ros/transforms.h>
51 #include <tf/transform_datatypes.h>
53 #include <geometry_msgs/Quaternion.h>
54 #include <geometry_msgs/Twist.h>
55 #include <geometry_msgs/Pose.h>
56 #include <nav_msgs/Odometry.h>
57 #include <sensor_msgs/Imu.h>
58 #include <sensor_msgs/LaserScan.h>
59 #include <sensor_msgs/CompressedImage.h>
60 #include <sensor_msgs/PointCloud2.h>
61 #include <sensor_msgs/Range.h>
62 #include <sensor_msgs/FluidPressure.h>
63 #include <geometry_msgs/TransformStamped.h>
64 #include <tf2_msgs/TFMessage.h>
65 #include <std_msgs/String.h>
66 #include <std_msgs/Int32.h>
69 #pragma GCC diagnostic pop
76 #include <sys/types.h>
79 #include "capnp/serialize.h"
80 #include "capnp/schema-loader.h"
81 #include "capnp/schema-parser.h"
84 namespace global_ros = ros;
85 namespace logger = madara::logger;
86 namespace knowledge = madara::knowledge;
87 namespace containers = knowledge::containers;
95 static std::string cleanCapnpSchemaName(
const std::string& full_name)
97 std::regex re(
"[^\\/:]+");
98 std::sregex_token_iterator begin(full_name.begin(),
99 full_name.end(), re), end;
100 std::vector<std::string> tokens;
101 std::copy(begin, end, std::back_inserter(tokens));
102 return tokens.back();
108 const std::string IGNORE_MARKER =
"_IGNORE_";
109 const std::string NSEC_MARKER =
"_TO_NSEC_";
111 RosParser(knowledge::KnowledgeBase * kb, std::string world_frame,
112 std::string base_frame,
113 std::map<std::string, std::string> capnp_types,
114 std::map<std::string,
115 std::pair<std::string, std::string>> plugin_types,
116 std::map<std::string, int> circular_containers=std::map<std::string,
118 knowledge::EvalSettings eval_settings=knowledge::EvalSettings(),
119 std::string frame_prefix=
123 void parse_message(
const rosbag::MessageInstance m,
124 std::string container_name);
125 void parse_message(
const topic_tools::ShapeShifter::ConstPtr& m,
126 std::string container_name);
129 void registerMessageDefinition(std::string topic_name,
130 RosIntrospection::ROSType type, std::string definition);
131 void registerRenamingRules(RosIntrospection::ROSType type,
132 std::vector<RosIntrospection::SubstitutionRule> rules);
133 void parse_unknown(
const rosbag::MessageInstance m,
134 std::string container_name);
141 void register_rename_rules(
142 std::map<std::string, std::map<std::string,
143 std::string>> name_substitution_map);
150 void parse_any(
const rosbag::MessageInstance & m,
151 std::string container_name);
160 void parse_any(std::string topic,
const topic_tools::ShapeShifter & m,
161 std::string container_name);
170 void parse_any( std::string datatype, std::string topic_name,
171 std::vector<uint8_t> & parser_buffer,
172 std::string container_name);
179 void parse_external(
const rosbag::MessageInstance & m,
180 std::string container_name);
188 void load_capn_schema(std::string path);
193 void parse_pointcloud2_pclschema(sensor_msgs::PointCloud2 * pointcloud,
194 std::string container_name);
198 void parse_odometry(nav_msgs::Odometry * odom,
199 std::string container_name);
200 void parse_imu(sensor_msgs::Imu * imu,
201 std::string container_name);
202 void parse_laserscan(sensor_msgs::LaserScan * laser,
203 std::string container_name);
205 containers::NativeDoubleVector *orientation);
206 void parse_point(geometry_msgs::Point *point_msg,
207 containers::NativeDoubleVector *point);
208 void parse_twist(geometry_msgs::Twist *twist,
209 std::string container_name);
211 containers::NativeDoubleVector *target);
213 std::string container_name);
214 void parse_compressed_image(sensor_msgs::CompressedImage * img,
215 std::string container_name);
216 void parse_pointcloud2(sensor_msgs::PointCloud2 * pointcloud,
217 std::string container_name);
218 void parse_range(sensor_msgs::Range * range,
219 std::string container_name);
220 void parse_tf_message(tf2_msgs::TFMessage * tf);
221 void parse_fluidpressure(sensor_msgs::FluidPressure * press,
222 std::string container_name);
226 void parse_float64_array(boost::array<double, N> *array,
227 containers::NativeDoubleVector *target);
228 void parse_float64_array(std::vector<float> *array,
229 containers::NativeDoubleVector *target);
233 void parse_int_array(boost::array<int, N> *array,
234 containers::NativeIntegerVector *target);
236 void parse_int_array(std::vector<T> *array,
237 containers::NativeIntegerVector *target);
242 void print_schemas();
246 RosIntrospection::Parser parser_;
250 std::map<std::string, RosIntrospection::FlatMessage> flat_containers_;
251 std::map<std::string, RosIntrospection::RenamedValues> renamed_vectors_;
252 std::vector<uint8_t> parser_buffer_;
253 std::map<std::string, unsigned int> ros_array_sizes_;
256 std::string world_frame_;
257 std::string base_frame_;
260 std::map<std::string, std::string> capnp_types_;
261 std::map<std::string, capnp::Schema> schemas_;
262 capnp::SchemaLoader capnp_loader_;
267 knowledge::KnowledgeBase * knowledge_;
268 knowledge::EvalSettings eval_settings_;
269 std::string frame_prefix_;
272 std::map<std::string, madara::knowledge::containers::CircularBuffer>
274 std::map<std::string, int> circular_container_stats_;
277 std::map<std::string, std::map<std::string, std::string>>
278 name_substitution_map_;
281 std::map<std::string, std::pair<std::string, std::string>> plugin_map_;
284 typedef void(*plugin_t)(
const rosbag::MessageInstance*,
285 madara::knowledge::KnowledgeBase*,
287 std::map<std::string, void*> plugin_cache_;
297 capnp::DynamicStruct::Builder get_dyn_capnp_struct(
298 capnp::DynamicStruct::Builder builder, std::string name);
304 void set_dyn_capnp_enum_value(capnp::DynamicStruct::Builder dynvalue,
305 std::string var_name, T val);
311 void set_dyn_capnp_value(capnp::DynamicStruct::Builder builder,
312 std::string name, T val,
unsigned int array_size);
318 unsigned int get_array_size(std::string var_name,
319 RosIntrospection::RenamedValues* array);
325 std::string substitute_name(std::string type, std::string name);
331 void set_sim_time(global_ros::Time rostime);
334 std::string ros_to_gams_name(std::string ros_topic_name);
static const std::string & default_prefix()
Return the default prefix for load/save operations.
gams::pose::Quaternion Quaternion
Used internally to implement angle operations.
gams::pose::Pose Pose
Represents a combination of Location and Orientation within a single reference frame.
Contains all GAMS-related tools, classes and code.
Copyright(c) 2015 Carnegie Mellon University.
Copyright (c) 2015 Carnegie Mellon University.
Copyright (c) 2015 Carnegie Mellon University.