AdditionsServiceProvider.cpp
Go to the documentation of this file.
2 
3 namespace rsm {
4 
6  as(NULL) {
7  ros::NodeHandle private_nh("~");
8  private_nh.param<std::string>("autonomy_cmd_vel_topic",
9  _autonomy_cmd_vel_topic, "/autonomy/cmd_vel");
10 
11  ros::NodeHandle nh("rsm");
12 
13  std::string navigation_plugin;
14  private_nh.param<std::string>("navigation_plugin", navigation_plugin, "");
15  if (navigation_plugin.compare("rsm::NavigationState") == 0) {
16  _set_navigation_to_reverse_service = nh.advertiseService(
17  "setNavigationToReverse",
19  std::ostringstream autonomy_cmd_vel_reverse_topic;
20  autonomy_cmd_vel_reverse_topic << _autonomy_cmd_vel_topic << "_reverse";
22  autonomy_cmd_vel_reverse_topic.str(), 10,
24  _reverse_mode_cmd_vel_publisher = _nh.advertise<geometry_msgs::Twist>(
26  }
27 
28  std::string calculate_goal_plugin;
29  private_nh.param<std::string>("calculate_goal_plugin",
30  calculate_goal_plugin, "");
31  if (calculate_goal_plugin.compare("rsm::CalculateGoalState") == 0) {
33  private_nh.param<double>("exploration_goal_tolerance",
35  as = new MoveBaseActionServer(_nh, "frontier_move_base",
37  this, _1), false);
38  as->start();
39  frontiers_marker_array_subscriber = _nh.subscribe("explore/frontiers",
41  _exploration_goals_publisher = nh.advertise<geometry_msgs::PoseArray>(
42  "explorationGoals", 1);
43  _exploration_mode_subscriber = nh.subscribe("explorationMode", 1,
45  _failed_goals_publisher = nh.advertise<geometry_msgs::PoseArray>(
46  "failedGoals", 1);
47  _exploration_goal_subscriber = nh.subscribe("explorationGoalStatus", 1,
49  _get_navigation_goal_service = nh.serviceClient<
50  rsm_msgs::GetNavigationGoal>("getNavigationGoal");
51  } else {
53  }
54 
55  std::string mapping_plugin;
56  private_nh.param<std::string>("mapping_plugin", mapping_plugin, "");
57  if (mapping_plugin.compare("rsm::KinectMappingState") == 0) {
58  _reset_kinect_position_serivce = nh.advertiseService(
59  "resetKinectPosition",
61  _kinect_joint_controller = _nh.advertise<std_msgs::Float64>(
62  "kinect_controller/command", 1, true);
63  }
64 
66  _goal_obsolete = false;
67 }
68 
70 
71 }
72 
77  }
78  if (_exploration_mode) {
80  }
81 }
82 
84  std_srvs::SetBool::Request &req, std_srvs::SetBool::Response &res) {
85  res.success = 1;
86  res.message = "Mode set";
87  return true;
88 }
89 
91  const geometry_msgs::Twist::ConstPtr& cmd_vel) {
92  geometry_msgs::Twist cmd_vel_reversed;
93  cmd_vel_reversed.linear.x = cmd_vel->linear.x * -1;
94  cmd_vel_reversed.linear.y = cmd_vel->linear.y * -1;
95  cmd_vel_reversed.linear.z = cmd_vel->linear.z * -1;
96  cmd_vel_reversed.angular.x = cmd_vel->angular.x;
97  cmd_vel_reversed.angular.y = cmd_vel->angular.y;
98  cmd_vel_reversed.angular.z = cmd_vel->angular.z;
99  _reverse_mode_cmd_vel_publisher.publish(cmd_vel_reversed);
100 }
101 
103  const move_base_msgs::MoveBaseGoalConstPtr& frontier_goal) {
104  as->setSucceeded(move_base_msgs::MoveBaseResult(), "Goal reached.");
105 }
106 
108  _exploration_goals.header.frame_id = "map";
109  _exploration_goals.header.stamp = ros::Time::now();
111 }
112 
114  _failed_goals.header.frame_id = "map";
115  _failed_goals.header.stamp = ros::Time::now();
117 }
118 
120  std_msgs::Bool msg;
121  msg.data = _goal_obsolete;
123 }
124 
126  const rsm_msgs::GoalStatus::ConstPtr& goal_status) {
127  if (goal_status->goal_status == rsm_msgs::GoalStatus::REACHED) {
128  _failed_goals.poses.clear();
129  } else if (goal_status->goal_status == rsm_msgs::GoalStatus::FAILED) {
130  _failed_goals.poses.push_back(goal_status->goal);
131  }
132 }
133 
135  const visualization_msgs::MarkerArray::ConstPtr& frontiers) {
136  _exploration_goals.poses.clear();
137  for (auto it : frontiers->markers) {
138  if (it.type == visualization_msgs::Marker::POINTS) {
139  int frontier_size = it.points.size();
140  if (frontier_size > 0) {
141  geometry_msgs::Pose point;
142  point.position.x = it.points[frontier_size / 2].x;
143  point.position.y = it.points[frontier_size / 2].y;
144  point.position.z = it.points[frontier_size / 2].z;
145  point.orientation.w = 1.0;
146  _exploration_goals.poses.push_back(point);
147  }
148  }
149  }
151  _goal_obsolete = true;
152  } else {
153  _goal_obsolete = false;
154  }
155 }
156 
158  const std_msgs::Bool::ConstPtr& exploration_mode) {
159  _exploration_mode = exploration_mode->data;
160  if (_exploration_mode) {
161  ros::NodeHandle nh("rsm");
162  _goal_obsolete_publisher = nh.advertise<std_msgs::Bool>("goalObsolete",
163  1);
164  } else {
166  }
167 }
168 
170  ROS_INFO_STREAM("Goal tolerance: " << _exploration_goal_tolerance);
171  rsm_msgs::GetNavigationGoal srv;
173  geometry_msgs::Pose navigation_goal = srv.response.goal;
174  for (auto iterator : _exploration_goals.poses) {
175  double x_dif = abs(
176  navigation_goal.position.x - iterator.position.x);
177  double y_dif = abs(
178  navigation_goal.position.y - iterator.position.y);
179  double z_dif = abs(
180  navigation_goal.position.z - iterator.position.z);
181  if (x_dif <= _exploration_goal_tolerance
182  && y_dif <= _exploration_goal_tolerance
183  && z_dif <= _exploration_goal_tolerance) {
184  return true;
185  }
186  }
187  } else {
188  ROS_ERROR("Failed to call Get Navigation Goal service");
189  }
190  return false;
191 }
192 
194  std_srvs::Trigger::Request &req, std_srvs::Trigger::Response &res) {
195  std_msgs::Float64 kinect_command;
196  kinect_command.data = 0.0; //center position of kinect camera
197  _kinect_joint_controller.publish(kinect_command);
198  return true;
199 }
200 }
void explorationModeCallback(const std_msgs::Bool::ConstPtr &exploration_mode)
ros::ServiceServer _reset_kinect_position_serivce
geometry_msgs::PoseArray _exploration_goals
void publish(const boost::shared_ptr< M > &message) const
void explorationGoalCallback(const rsm_msgs::GoalStatus::ConstPtr &goal_status)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void frontierCallback(const visualization_msgs::MarkerArray::ConstPtr &frontiers)
bool call(MReq &req, MRes &res)
void reverseModeCmdVelCallback(const geometry_msgs::Twist::ConstPtr &cmd_vel)
ros::ServiceClient _get_navigation_goal_service
ros::ServiceServer _set_navigation_to_reverse_service
void setSucceeded(const Result &result=Result(), const std::string &text=std::string(""))
bool param(const std::string &param_name, T &param_val, const T &default_val) const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
actionlib::SimpleActionServer< move_base_msgs::MoveBaseAction > MoveBaseActionServer
void navigationGoalCallback(const move_base_msgs::MoveBaseGoalConstPtr &frontier_goal)
#define ROS_INFO_STREAM(args)
static Time now()
geometry_msgs::PoseArray _failed_goals
bool setNavigationToReverse(std_srvs::SetBool::Request &req, std_srvs::SetBool::Response &res)
#define ROS_ERROR(...)
bool resetKinectPosition(std_srvs::Trigger::Request &req, std_srvs::Trigger::Response &res)


rsm_additions
Author(s): Marco Steinbrink
autogenerated on Tue Mar 16 2021 02:44:35