rosping.cpp
Go to the documentation of this file.
1 // doc/html/boost_asio/example/icmp/
2 
3 #include "ping.cpp"
4 #include <ros/ros.h>
5 #include <std_msgs/Float64.h>
6 
7 int main(int argc, char* argv[])
8 {
9  try
10  {
11  ros::init(argc, argv, "ping");
12  if (argc != 2)
13  {
14  std::cerr << "Usage: " << argv[0] << " <host>" << std::endl;
15 #if !defined(BOOST_WINDOWS)
16  std::cerr << "(You may need to set permission to run this program as root.)\n$ chown root.root rosping; ls -al rosping; chmod 4755 rosping\n" << std::endl;
17 #endif
18  return 1;
19  }
20 
21  boost::asio::io_service io_service;
22  pinger p(io_service, argv[1]);
23 
24 
25 
27  ros::NodeHandle pnh("~");
28  double rate;
29  if (!pnh.getParam("rate", rate)) {
30  rate = 10.0; // 0.1Hz
31  }
32  ros::Publisher pub = n.advertise<std_msgs::Float64>("ping/delay", 10);
33 
34  std_msgs::Float64 msg;
35 
36  ros::Time last_time = ros::Time::now();
37 
38  while (ros::ok()) {
39  ros::Time now = ros::Time::now();
40  io_service.run_one();
41  if ( now - last_time > ros::Duration(rate) ) {
42 
43  msg.data = p.delay;
44  pub.publish(msg);
45  ros::spinOnce();
46 
47  last_time = now;
48  }
49  }
50 
51  }
52  catch (std::exception& e)
53  {
54  std::cerr << "Exception: " << e.what() << std::endl;
55  }
56 }
Definition: ping.cpp:24
void publish(const boost::shared_ptr< M > &message) const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
double delay
Definition: ping.cpp:38
ROSCPP_DECL bool ok()
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
bool getParam(const std::string &key, std::string &s) const
static Time now()
ROSCPP_DECL void spinOnce()
int main(int argc, char *argv[])
Definition: rosping.cpp:7


rosping
Author(s): Kei Okada
autogenerated on Tue May 11 2021 02:55:50