00001 /********************************************************************* 00002 * Software License Agreement (CC BY-NC-SA 4.0 License) 00003 * 00004 * Copyright (c) 2014, PAL Robotics, S.L. 00005 * All rights reserved. 00006 * 00007 * This work is licensed under the Creative Commons 00008 * Attribution-NonCommercial-ShareAlike 4.0 International License. 00009 * 00010 * To view a copy of this license, visit 00011 * http://creativecommons.org/licenses/by-nc-sa/4.0/ 00012 * or send a letter to 00013 * Creative Commons, 444 Castro Street, Suite 900, 00014 * Mountain View, California, 94041, USA. 00015 *********************************************************************/ 00016 00017 /* 00018 * @author Enrique Fernandez 00019 * @author Siegfried Gevatter 00020 */ 00021 00022 #ifndef TWIST_MUX_H 00023 #define TWIST_MUX_H 00024 00025 #include <ros/ros.h> 00026 #include <std_msgs/Bool.h> 00027 #include <geometry_msgs/Twist.h> 00028 00029 #include <list> 00030 00031 namespace twist_mux 00032 { 00033 00034 // Forwarding declarations: 00035 class TwistMuxDiagnostics; 00036 struct TwistMuxDiagnosticsStatus; 00037 class VelocityTopicHandle; 00038 class LockTopicHandle; 00039 00044 class TwistMux 00045 { 00046 public: 00047 00048 // @todo use this type alias when the compiler supports this C++11 feat. 00049 //template<typename T> 00050 //using handle_container = std::list<T>; 00051 // @todo alternatively we do the following: 00052 typedef std::list<VelocityTopicHandle> velocity_topic_container; 00053 typedef std::list<LockTopicHandle> lock_topic_container; 00054 00055 TwistMux(int window_size = 10); 00056 ~TwistMux(); 00057 00058 bool hasPriority(const VelocityTopicHandle& twist); 00059 00060 void publishTwist(const geometry_msgs::TwistConstPtr& msg); 00061 00062 void updateDiagnostics(const ros::TimerEvent& event); 00063 00064 protected: 00065 00066 typedef TwistMuxDiagnostics diagnostics_type; 00067 typedef TwistMuxDiagnosticsStatus status_type; 00068 00069 ros::Timer diagnostics_timer_; 00070 00071 static constexpr double DIAGNOSTICS_PERIOD = 1.0; 00072 00079 // @todo use handle_container (see above) 00080 //handle_container<VelocityTopicHandle> velocity_hs_; 00081 //handle_container<LockTopicHandle> lock_hs_; 00082 boost::shared_ptr<velocity_topic_container> velocity_hs_; 00083 boost::shared_ptr<lock_topic_container> lock_hs_; 00084 00085 ros::Publisher cmd_pub_; 00086 00087 geometry_msgs::Twist last_cmd_; 00088 00089 template<typename T> 00090 void getTopicHandles(ros::NodeHandle& nh, ros::NodeHandle& nh_priv, const std::string& param_name, std::list<T>& topic_hs); 00091 00092 int getLockPriority(); 00093 00094 boost::shared_ptr<diagnostics_type> diagnostics_; 00095 boost::shared_ptr<status_type> status_; 00096 }; 00097 00098 } // namespace twist_mux 00099 00100 #endif // TWIST_MUX_H