20 nh.
serviceClient<rsm_msgs::SetNavigationGoal>(
"setNavigationGoal");
26 _name =
"E: Calculate Goal";
38 rsm_msgs::GetRobotPose srv;
40 geometry_msgs::Pose current_pose = srv.response.pose;
41 double min_distance = std::numeric_limits<double>::infinity();
45 (current_pose.position.x - pt.position.x), 2)
46 + pow((current_pose.position.y - pt.position.y), 2);
47 if (distance < min_distance) {
48 min_distance = distance;
49 _goal.position.x = pt.position.x;
50 _goal.position.y = pt.position.y;
54 if (min_distance == std::numeric_limits<double>::infinity()) {
56 "Exploration stopped because there are no more reachable goals");
59 double yaw = atan2(
_goal.position.y - current_pose.position.y,
60 _goal.position.x - current_pose.position.x);
70 ROS_ERROR(
"Failed to call Get Robot Pose service");
77 rsm_msgs::SetNavigationGoal srv;
78 srv.request.goal =
_goal;
82 ROS_ERROR(
"Failed to call Set Navigation Goal service");
87 std::string &message) {
89 message =
"Exploration running";
93 std::string &message) {
95 message =
"Exploration stopped";
100 std::string &message) {
102 message =
"Exploration running";
106 std::string &message) {
108 message =
"Exploration running";
115 boost::make_shared<EmergencyStopState>());
120 boost::make_shared<TeleoperationState>());
132 const geometry_msgs::PoseArray::ConstPtr& frontiers) {
138 const geometry_msgs::PoseArray::ConstPtr& failed_goals) {
144 double tolerance = 0.05;
146 double x_dif = abs(point.x - iterator.position.x);
147 double y_dif = abs(point.y - iterator.position.y);
148 if (x_dif <= tolerance && y_dif <= tolerance) {
156 ROS_ERROR(
"Exploration stopped because no goal was selected in time");
163 boost::make_shared<IdleState>());
void onExplorationStart(bool &success, std::string &message)
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
boost::shared_ptr< rsm::BaseState > getPluginState(int plugin_type, std::string routine="")
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ros::Subscriber _failed_goals_sub
void onInterrupt(int interrupt)
Called when an operation mode interrupt was received.
bool call(MReq &req, MRes &res)
TFSIMD_FORCE_INLINE tfScalar distance(const Vector3 &v) const
void transitionToVolatileState(boost::shared_ptr< rsm::BaseState > next_state)
#define TELEOPERATION_INTERRUPT
void onExplorationStop(bool &success, std::string &message)
Called when exploration was stopped manually.
void abortCalculateGoal()
geometry_msgs::PoseArray _failed_goals
bool differentFromFailedGoals(geometry_msgs::Point point)
Checks if a point is different from a previously failed goals including a small tolerance.
void onExit()
Called once when left.
void onEntry()
Called once when activated.
ros::ServiceClient _get_robot_pose_service
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
StateInterface * _stateinterface
bool _failed_goals_received
ros::Subscriber _frontiers_sub
#define EMERGENCY_STOP_INTERRUPT
CalculateGoalState()
Constructor.
geometry_msgs::Pose _goal
void onSetup()
Called once when registered at StateInterface.
ros::ServiceClient _set_navigation_goal_service
void timerCallback(const ros::TimerEvent &event)
Callback for when no goal was chosen in time and calculation likely failed.
static geometry_msgs::Quaternion createQuaternionMsgFromYaw(double yaw)
geometry_msgs::PoseArray _frontier_points
void onActive()
Process method (step-wise, never block this method)
void onWaypointFollowingStart(bool &success, std::string &message)
void onWaypointFollowingStop(bool &success, std::string &message)
~CalculateGoalState()
Destructor.
State for choosing a goal from all provided frontiers and calling Navigation when successful...
#define SIMPLE_GOAL_INTERRUPT
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
void frontiersCallback(const geometry_msgs::PoseArray::ConstPtr &frontiers)
Called when new frontiers are received.
void failedGoalsCallback(const geometry_msgs::PoseArray::ConstPtr &failed_goals)
Called when new failed goals are received.