7 void state_callback (
const smach_msgs::SmachContainerStatus::ConstPtr& msg)
9 ROS_DEBUG(
"Received state machine path %s", msg->path.c_str());
16 state = msg->active_states[0];
27 string uuid = msg.swarmio.node;
32 member_state.
uuid = uuid;
47 int main (
int argc,
char **argv)
50 init(argc, argv,
"state_exchanger");
55 nh.param(this_node::getName() +
"/loop_rate", loop_rate, 1.5);
57 nh.param(this_node::getName() +
"/queue_size", queue_size, 10);
59 nh.param(this_node::getName() +
"/timeout", timeout, 20.0);
67 Subscriber state_subscriber = nh.subscribe(
"smach_server/smach/container_status", queue_size,
state_callback);
68 Subscriber incoming_state_subscriber = nh.subscribe(
"bridge/events/state", queue_size,
swarm_state_callback);
69 Publisher outgoing_state_publisher = nh.advertise<cpswarm_msgs::StateEvent>(
"state", queue_size);
70 Publisher incoming_state_publisher = nh.advertise<cpswarm_msgs::ArrayOfStates>(
"swarm_state", queue_size);
77 ROS_DEBUG_ONCE(
"Waiting for valid state...");
83 cpswarm_msgs::ArrayOfStates swarm_state_msg;
88 swarm_state_msg.states.clear();
93 if ((Time::now() - member->second.stamp) > Duration(timeout)) {
99 cpswarm_msgs::StateEvent state_event;
100 state_event.header.stamp = Time::now();
101 state_event.swarmio.node = member->first;
102 swarm_state_msg.states.push_back(state_event);
109 incoming_state_publisher.publish(swarm_state_msg);
112 cpswarm_msgs::StateEvent state_event;
113 state_event.header.stamp = Time::now();
114 state_event.swarmio.name =
"state";
115 state_event.state =
state;
116 outgoing_state_publisher.publish(state_event);
void swarm_state_callback(cpswarm_msgs::StateEvent msg)
Callback function for state updates from other swarm members.
string sm_path
The path of the smach state machine whose state shall be exchanged.
bool state_valid
Whether a valid state has been received.
string state
Current state of the CPS.
int main(int argc, char **argv)
A ROS node that exchanges the behavioral state between CPSs in a swarm.
A STATE type containing UUID and state of the corresponding CPS together with last updated time stamp...
map< string, state_t > swarm_state
The state of all known swarm members.
void state_callback(const smach_msgs::SmachContainerStatus::ConstPtr &msg)
Callback function for state updates.