rcll_beacon_sender_node.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * rcll_fawkes_sim_node.cpp - RCLL simulation access through Fawkes
3  *
4  * Created: Sun May 29 15:36:18 2016
5  * Copyright 2016 Tim Niemueller [www.niemueller.de]
6  ****************************************************************************/
7 
8 /* This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Library General Public License for more details.
17  *
18  * Read the full text in the LICENSE.GPL file in the doc directory.
19  */
20 
21 #include <ros/ros.h>
22 
23 #include <rcll_ros_msgs/SendBeaconSignal.h>
24 
25 #include <geometry_msgs/PoseWithCovarianceStamped.h>
26 
27 geometry_msgs::PoseWithCovarianceStamped last_pose_;
29 
30 unsigned int seq_num_;
31 
32 void cb_pose(const geometry_msgs::PoseWithCovarianceStamped::ConstPtr& msg)
33 {
34  last_pose_ = *msg;
35 }
36 
37 void
39 {
40  if (ros::service::waitForService("rcll/send_beacon", ros::Duration(5.0))) {
41  ROS_INFO("Got service, creating service client");
42  scl_send_beacon_ =
43  n.serviceClient<rcll_ros_msgs::SendBeaconSignal>("rcll/send_beacon", /* persistent */ true);
44  }
45 }
46 
48 {
49  if (! scl_send_beacon_.isValid()) {
51  }
52  if (! scl_send_beacon_.isValid()) {
53  ROS_WARN_THROTTLE(30, "Beacon service client disconnected, retrying later");
54  return;
55  }
56 
57  rcll_ros_msgs::SendBeaconSignal sbs;
58  sbs.request.header.seq = ++seq_num_;
60  sbs.request.header.stamp.sec = now.sec;
61  sbs.request.header.stamp.nsec = now.nsec;
62  sbs.request.pose.pose = last_pose_.pose.pose;
63  sbs.request.pose.header = last_pose_.header;
64  if (scl_send_beacon_.call(sbs)) {
65  if (! sbs.response.ok) {
66  ROS_WARN_THROTTLE(30, "Failed to send beacon: %s", sbs.response.error_msg.c_str());
67  }
68  } else {
69  ROS_ERROR("Failed to call beacon service");
70  }
71 }
72 
73 
74 
75 int
76 main(int argc, char **argv)
77 {
78  ros::init(argc, argv, "rcll_beacon_sender");
79 
81 
82  seq_num_ = 0;
83 
85 
86  ros::Subscriber sub_pose =
87  n.subscribe<geometry_msgs::PoseWithCovarianceStamped>("rcll_sim/amcl_pose", 10, cb_pose);
88 
89  ros::WallTimer timer =
90  n.createWallTimer(ros::WallDuration(1.0), boost::bind(cb_timer, _1, boost::ref(n)));
91 
92  ros::spin();
93 
94  return 0;
95 }
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
#define ROS_WARN_THROTTLE(rate,...)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ros::ServiceClient scl_send_beacon_
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool call(MReq &req, MRes &res)
unsigned int seq_num_
void cb_pose(const geometry_msgs::PoseWithCovarianceStamped::ConstPtr &msg)
ROSCPP_DECL void spin(Spinner &spinner)
#define ROS_INFO(...)
void cb_timer(const ros::WallTimerEvent &event, ros::NodeHandle &n)
WallTimer createWallTimer(WallDuration period, void(T::*callback)(const WallTimerEvent &), T *obj, bool oneshot=false, bool autostart=true) const
bool isValid() const
void init_service_client(ros::NodeHandle &n)
static WallTime now()
geometry_msgs::PoseWithCovarianceStamped last_pose_
int main(int argc, char **argv)
#define ROS_ERROR(...)
ROSCPP_DECL bool waitForService(const std::string &service_name, int32_t timeout)


rcll_fawkes_sim
Author(s): Tim Niemueller
autogenerated on Mon Jun 10 2019 14:31:10