mvsim_node_core.h
Go to the documentation of this file.
00001 
00004 #ifndef SR_MVSIM_NODE_CORE_H
00005 #define SR_MVSIM_NODE_CORE_H
00006 
00007 // ROS includes.
00008 #include <ros/ros.h>
00009 #include <ros/time.h>
00010 #include <rosgraph_msgs/Clock.h>
00011 
00012 // Dynamic reconfigure includes.
00013 #include <dynamic_reconfigure/server.h>
00014 
00015 #include <tf/transform_broadcaster.h>
00016 #include <tf2_ros/static_transform_broadcaster.h>
00017 #include <visualization_msgs/MarkerArray.h>
00018 #include <thread>
00019 
00020 // Auto-generated from cfg/ directory.
00021 #include <mvsim/mvsimNodeConfig.h>
00022 
00023 #include <mvsim/mvsim.h>  // the mvsim library
00024 #include <mrpt/utils/CTicTac.h>
00025 
00026 #if MRPT_VERSION >= 0x130
00027 #include <mrpt/obs/CObservation.h>
00028 using mrpt::obs::CObservation;
00029 #else
00030 #include <mrpt/slam/CObservation.h>
00031 using mrpt::slam::CObservation;
00032 #endif
00033 
00036 class MVSimNode
00037 {
00038    public:
00040         MVSimNode(ros::NodeHandle& n);
00042         ~MVSimNode();
00043 
00044         void loadWorldModel(const std::string& world_xml_file);
00045 
00046         void spin();  
00047 
00049         void configCallback(mvsim::mvsimNodeConfig& config, uint32_t level);
00050 
00052         class MyWorld : public mvsim::World
00053         {
00054                 MVSimNode& m_parent;
00055 
00056            public:
00057                 MyWorld(MVSimNode& node) : m_parent(node) {}
00058                 virtual void onNewObservation(
00059                         const mvsim::VehicleBase& veh, const CObservation* obs);
00060 
00061         };  // End of MyWorld
00062 
00063         MyWorld mvsim_world_;  
00064 
00065 
00066         double realtime_factor_;  
00067         int gui_refresh_period_ms_;  
00068         bool m_show_gui;  
00069         bool m_do_fake_localization;  
00070 
00071 
00072 
00073         double m_transform_tolerance;  
00074 
00075 
00076    protected:
00077         ros::NodeHandle& m_n;
00078         ros::NodeHandle m_localn;
00079 
00080         // === ROS Publishers ====
00081         ros::Publisher m_pub_map_ros,
00082                 m_pub_map_metadata;  
00083         ros::Publisher m_pub_clock;
00084         tf::TransformBroadcaster m_tf_br;  
00085         tf2_ros::StaticTransformBroadcaster
00086                 m_static_tf_br;  
00087 
00088         struct TPubSubPerVehicle
00089         {
00090                 ros::Subscriber
00091                         sub_cmd_vel;  
00092                 ros::Publisher pub_odom;  
00093                 ros::Publisher
00094                         pub_ground_truth;  
00095                 ros::Publisher pub_amcl_pose,
00096                         pub_particlecloud;  
00097                 std::map<std::string, ros::Publisher>
00098                         pub_sensors;  
00099                 ros::Publisher pub_chassis_markers;  
00100                 ros::Publisher pub_chassis_shape;  
00101                 visualization_msgs::MarkerArray chassis_shape_msg;
00102         };
00103 
00104         std::vector<TPubSubPerVehicle>
00105                 m_pubsub_vehicles;  
00106 
00107 
00108 
00111         void initPubSubs(TPubSubPerVehicle& out_pubsubs, mvsim::VehicleBase* veh);
00112 
00113         // === End ROS Publishers ====
00114 
00115         // === ROS Hooks ====
00116         void onROSMsgCmdVel(
00117                 const geometry_msgs::Twist::ConstPtr& cmd, mvsim::VehicleBase* veh);
00118         // === End ROS Hooks====
00119 
00120         rosgraph_msgs::Clock m_clockMsg;
00121         ros::Time m_sim_time;  
00122         ros::Time
00123                 m_base_last_cmd;  
00124         ros::Duration m_base_watchdog_timeout;
00125         const tf::Transform
00126                 m_tfIdentity;  
00127 
00128         struct TThreadParams
00129         {
00130                 MVSimNode* obj;
00131                 volatile bool closing;
00132                 TThreadParams() : obj(NULL), closing(false) {}
00133         };
00134         TThreadParams thread_params_;
00135         mrpt::utils::CTicTac realtime_tictac_;
00136 
00137         double t_old_;  // = realtime_tictac_.Tac();
00138         bool world_init_ok_;  
00139 
00140 
00141         double m_period_ms_publish_tf;  
00142 
00143         mrpt::utils::CTicTac m_tim_publish_tf;
00144 
00145         double m_period_ms_teleop_refresh;  
00146 
00147 
00148         mrpt::utils::CTicTac m_tim_teleop_refresh;
00149 
00150         size_t m_teleop_idx_veh;  
00151 
00152         mvsim::World::TGUIKeyEvent m_gui_key_events;
00153         std::string m_msg2gui;
00154 
00155         std::thread thGUI_;
00156         static void thread_update_GUI(TThreadParams& thread_params);
00157 
00160         void notifyROSWorldIsUpdated();
00161 
00163         void spinNotifyROS();
00164 
00167         std::string vehVarName(
00168                 const std::string& sVarName, const mvsim::VehicleBase* veh) const;
00169 
00170         void sendStaticTF(
00171                 const std::string& frame_id, const std::string& child_frame_id,
00172                 const tf::Transform& tx, const ros::Time& stamp);
00173 
00174         struct MVSimVisitor_notifyROSWorldIsUpdated
00175                 : public mvsim::World::VehicleVisitorBase,
00176                   public mvsim::World::WorldElementVisitorBase
00177         {
00178                 void visit(mvsim::VehicleBase* obj);
00179                 void visit(mvsim::WorldElementBase* obj);
00180 
00181                 MVSimVisitor_notifyROSWorldIsUpdated(MVSimNode& parent)
00182                         : m_parent(parent)
00183                 {
00184                 }
00185                 MVSimNode& m_parent;
00186         };
00187 
00188 };  // end class
00189 
00190 #endif  // SR_MVSIM_NODE_CORE_H


mvsim
Author(s):
autogenerated on Thu Jun 6 2019 22:08:35