35 #include <pr2_controllers_msgs/JointControllerState.h> 36 #include <pr2_controllers_msgs/Pr2GripperCommand.h> 37 #include <pr2_controllers_msgs/Pr2GripperCommandAction.h> 38 #include <std_srvs/Empty.h> 62 node_.
advertise<pr2_controllers_msgs::Pr2GripperCommand>(
"command", 1);
101 bool should_abort =
false;
105 ROS_WARN(
"Aborting goal because we have never heard a controller state message.");
110 ROS_WARN(
"Aborting goal because we haven't heard from the controller in %.3lf seconds",
118 has_active_goal_ =
false;
126 if (has_active_goal_)
130 has_active_goal_ =
false;
135 has_active_goal_ =
true;
137 min_error_seen_ = 1e10;
146 if (active_goal_ == gh)
159 std_srvs::Empty::Request req;
160 std_srvs::Empty::Response
resp;
169 has_active_goal_ =
false;
178 last_controller_state_ = msg;
181 if (!has_active_goal_)
185 if(!node_.
getParam(
"position_servo_position_tolerance", goal_threshold_))
186 ROS_ERROR(
"No position_servo_position_tolerance given in namespace: '%s')", node_.
getNamespace().c_str());
190 if (fabs(msg->set_point - active_goal_.
getGoal()->command.position) > stall_velocity_threshold_)
198 ROS_ERROR(
"Cancelling goal: Controller is trying to achieve a different setpoint.");
200 has_active_goal_ =
false;
205 pr2_controllers_msgs::Pr2GripperCommandFeedback feedback;
206 feedback.position = msg->process_value;
207 feedback.effort = msg->command;
208 feedback.reached_goal =
false;
209 feedback.stalled =
false;
211 pr2_controllers_msgs::Pr2GripperCommandResult result;
212 result.position = msg->process_value;
213 result.effort = msg->command;
214 result.reached_goal =
false;
215 result.stalled =
false;
218 if (fabs(msg->process_value - active_goal_.
getGoal()->command.position) < goal_threshold_)
220 feedback.reached_goal =
true;
222 result.reached_goal =
true;
224 has_active_goal_ =
false;
229 if (fabs(msg->process_value_dot) > stall_velocity_threshold_)
233 else if ((
ros::Time::now() - last_movement_time_).toSec() > stall_timeout_ &&
234 active_goal_.
getGoal()->command.max_effort != 0.0)
236 feedback.stalled =
true;
238 result.stalled =
true;
240 has_active_goal_ =
false;
248 int main(
int argc,
char** argv)
250 ros::init(argc, argv,
"gripper_action_node");
void publishFeedback(const Feedback &feedback)
void publish(const boost::shared_ptr< M > &message) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
bool call(const std::string &service_name, MReq &req, MRes &res)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void cancelCB(GoalHandle gh)
boost::shared_ptr< const Goal > getGoal() const
Pr2GripperAction(ros::NodeHandle &n)
ros::Time last_movement_time_
void setCanceled(const Result &result=Result(), const std::string &text=std::string(""))
ROSCPP_DECL void spin(Spinner &spinner)
void setAccepted(const std::string &text=std::string(""))
void goalCB(GoalHandle gh)
void setSucceeded(const Result &result=Result(), const std::string &text=std::string(""))
ros::Subscriber sub_controller_state_
GAS::GoalHandle GoalHandle
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
const std::string & getNamespace() const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
actionlib::ActionServer< pr2_controllers_msgs::Pr2GripperCommandAction > GAS
void controllerStateCB(const pr2_controllers_msgs::JointControllerStateConstPtr &msg)
pr2_controllers_msgs::JointControllerStateConstPtr last_controller_state_
void setAborted(const Result &result=Result(), const std::string &text=std::string(""))
double stall_velocity_threshold_
void watchdog(const ros::TimerEvent &e)
bool getParam(const std::string &key, std::string &s) const
ros::Timer watchdog_timer_
ros::Publisher pub_controller_command_
ROSCPP_DECL bool exists(const std::string &service_name, bool print_failure_reason)
int main(int argc, char **argv)