20 state_buf_ = boost::circular_buffer<rostate_machine::State>(2);
80 std::vector<std::string> active_tags;
86 for(
auto state_itr = tag_itr->states.begin(); state_itr != tag_itr->states.end(); state_itr++)
90 active_tags.push_back(tag_itr->tag);
99 for(
auto state_itr = tag_itr->states.begin(); state_itr != tag_itr->states.end(); state_itr++)
103 active_tags.push_back(tag_itr->tag);
112 for(
auto state_itr = tag_itr->states.begin(); state_itr != tag_itr->states.end(); state_itr++)
116 active_tags.push_back(tag_itr->tag);
120 active_tags.push_back(tag_itr->tag);
126 for(
auto tag_itr = active_tags.begin(); tag_itr != active_tags.end(); tag_itr++)
128 std::vector<std::function<boost::optional<rostate_machine::Event>(void)> > execute_funcs =
tagged_functions_[*tag_itr];
129 for(
auto func_itr = execute_funcs.begin(); func_itr != execute_funcs.end(); func_itr++)
131 std::function<boost::optional<rostate_machine::Event>(void)> func = *func_itr;
132 boost::optional<rostate_machine::Event> ret = func();
145 using namespace boost::property_tree;
147 std::stringstream ss;
149 xml_parser::read_xml(ss, pt);
150 for (
const ptree::value_type& state_itr : pt.get_child(
"state_machine"))
152 if(state_itr.first ==
"callback")
154 std::string tag = state_itr.second.get<std::string>(
"<xmlattr>.tag");
155 std::string when = state_itr.second.get<std::string>(
"<xmlattr>.when");
156 std::vector<std::string> states =
split(state_itr.second.get<std::string>(
"<xmlattr>.states"),
',');
157 bool is_matched =
false;
164 if(when ==
"on_entry")
170 if(when ==
"on_exit")
176 if(is_matched ==
false)
181 if(state_itr.first ==
"transition")
183 std::string trigger_event_name = state_itr.second.get<std::string>(
"<xmlattr>.name");
195 if(*itr == event.trigger_event_name)
211 std::vector<std::string> tags;
218 std::vector<std::string> elems;
219 std::stringstream ss(s);
221 while (getline(ss, item, delim))
225 elems.push_back(item);
void publishEvent(rostate_machine::Event event)
ros::Subscriber current_state_sub_
void registerCallback(std::function< boost::optional< rostate_machine::Event >(void)> func, std::string tag)
void publish(const boost::shared_ptr< M > &message) const
Event Client for Rostate Machine.
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void stateCallback(const rostate_machine::State::ConstPtr msg)
boost::optional< rostate_machine::State > getPreviousState()
ros::Publisher trigger_event_pub_
std::vector< std::string > available_events_
boost::optional< rostate_machine::State > getCurrentState()
const std::string client_namespace
EventClient(ros::NodeHandle nh, ros::NodeHandle pnh, std::string client_namespace)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
ros::Duration getCurrentStateDuration()
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
#define ROS_WARN_STREAM(args)
std::vector< TagInfo > tag_info_
std::vector< std::string > onTransition()
boost::circular_buffer< rostate_machine::State > state_buf_
std::vector< std::string > split(const std::string &s, char delim)
bool eventKeyFound(rostate_machine::Event event)
std::map< std::string, std::vector< std::function< boost::optional< rostate_machine::Event >void)> > > tagged_functions_
ros::Time state_changed_timestamp_