clock_relay.cpp
Go to the documentation of this file.
1 
26 
28 
29 #include <string>
30 
31 namespace clock_relay
32 {
33 
34 const boost::unordered_map<std::string, ClockRelay::Type> ClockRelay::type_name_map_ =
35  boost::assign::map_list_of("source", ClockRelay::SOURCE)("sink", ClockRelay::SINK);
36 
37 ClockRelay::ClockRelay(std::string from, std::string to, std::string clock_relay_type_string, double frequency)
38 {
39  ClockRelay::Type clock_relay_type;
40  try
41  {
42  clock_relay_type = type_name_map_.at(clock_relay_type_string);
43  }
44  catch (const std::out_of_range &ex)
45  {
46  ROS_FATAL_STREAM("Invalid clock relay type " << clock_relay_type_string << " specified");
47  throw ex;
48  }
49 
51  params.topic = "clock";
52  params.type = "rosgraph_msgs/Clock";
53  params.origin = boost::make_shared<ros::NodeHandle>(from);
54  params.target = boost::make_shared<ros::NodeHandle>(to);
55  params.queue_size = 1;
56  params.throttle_frequency = frequency;
57 
58  switch (clock_relay_type)
59  {
60  case ClockRelay::SOURCE:
61  {
62  // Synchronize offset to current walltime
64 
65  // Publish offset on 'clock_offset' topic
66  offset_publisher_ = params.origin->advertise<multimaster_msgs::ClockOffset>("/clock_offset", 1, true);
67  offset_.offset.fromNSec(now.toNSec());
69 
70  offset_server_ = params.origin->advertiseService("/get_clock_offset", &ClockRelay::getClockOffsetCb, this);
71 
72  // offset outgoing clock
75  break;
76  }
77  case ClockRelay::SINK:
78  {
79  // No processing needed
80  break;
81  }
82  default:
83  {
84  ROS_FATAL_STREAM("Unsupported clock relay type " << clock_relay_type_string << " specified");
85  break;
86  }
87  }
88 
90 }
91 
92 bool ClockRelay::getClockOffsetCb(multimaster_msgs::GetClockOffset::Request &req,
93  multimaster_msgs::GetClockOffset::Response &res)
94 {
95  res.clock_offset = offset_;
96  return true;
97 }
98 
99 } // namespace clock_relay
void publish(const boost::shared_ptr< M > &message) const
boost::shared_ptr< ros::NodeHandle > target
TimeProcessor::ConstPtr time_processor
ClockRelay(std::string from, std::string to, std::string clock_relay_type_string, double frequency)
Definition: clock_relay.cpp:37
static const boost::unordered_map< std::string, Type > type_name_map_
Definition: clock_relay.h:59
message_relay::TopicRelay::Ptr clock_relay_
Definition: clock_relay.h:56
#define ROS_FATAL_STREAM(args)
bool getClockOffsetCb(multimaster_msgs::GetClockOffset::Request &req, multimaster_msgs::GetClockOffset::Response &res)
Definition: clock_relay.cpp:92
static ConstPtr create(std::string offset_operation_string, ros::Duration offset=ros::Duration(0.0))
ros::ServiceServer offset_server_
Definition: clock_relay.h:54
TopicRelay::Ptr createTopicRelay(const TopicRelayParams &params)
static WallTime now()
multimaster_msgs::ClockOffset offset_
Definition: clock_relay.h:53
ros::Publisher offset_publisher_
Definition: clock_relay.h:57
boost::shared_ptr< ros::NodeHandle > origin


clock_relay
Author(s):
autogenerated on Wed Jul 17 2019 03:27:57