34 #include <boost/bind.hpp> 37 #include <pr2_controllers_msgs/JointControllerState.h> 38 #include <pr2_controllers_msgs/Pr2GripperCommand.h> 39 #include <pr2_controllers_msgs/Pr2GripperCommandAction.h> 62 node_.
advertise<pr2_controllers_msgs::Pr2GripperCommand>(
"command", 1);
100 if (has_active_goal_)
102 bool should_abort =
false;
106 ROS_WARN(
"Aborting goal because we have never heard a controller state message.");
111 ROS_WARN(
"Aborting goal because we haven't heard from the controller in %.3lf seconds",
119 has_active_goal_ =
false;
127 if (has_active_goal_)
131 has_active_goal_ =
false;
136 has_active_goal_ =
true;
138 min_error_seen_ = 1e10;
147 if (active_goal_ == gh)
152 pr2_controllers_msgs::Pr2GripperCommand stop;
154 stop.max_effort = 0.0;
155 pub_controller_command_.
publish(stop);
160 has_active_goal_ =
false;
169 last_controller_state_ = msg;
172 if (!has_active_goal_)
176 if (fabs(msg->set_point - active_goal_.
getGoal()->command.position) > goal_threshold_)
184 ROS_ERROR(
"Cancelling goal: Controller is trying to achieve a different setpoint.");
186 has_active_goal_ =
false;
191 pr2_controllers_msgs::Pr2GripperCommandFeedback feedback;
192 feedback.position = msg->process_value;
193 feedback.effort = msg->command;
194 feedback.reached_goal =
false;
195 feedback.stalled =
false;
197 pr2_controllers_msgs::Pr2GripperCommandResult result;
198 result.position = msg->process_value;
199 result.effort = msg->command;
200 result.reached_goal =
false;
201 result.stalled =
false;
203 if (fabs(msg->process_value - active_goal_.
getGoal()->command.position) < goal_threshold_)
205 feedback.reached_goal =
true;
207 result.reached_goal =
true;
209 has_active_goal_ =
false;
214 if (fabs(msg->process_value_dot) > stall_velocity_threshold_)
218 else if ((
ros::Time::now() - last_movement_time_).toSec() > stall_timeout_ &&
219 active_goal_.
getGoal()->command.max_effort != 0.0)
221 feedback.stalled =
true;
223 result.stalled =
true;
225 has_active_goal_ =
false;
233 int main(
int argc,
char** argv)
235 ros::init(argc, argv,
"gripper_action_node");
void publishFeedback(const Feedback &feedback)
boost::shared_ptr< const Goal > getGoal() const
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void cancelCB(GoalHandle gh)
Pr2GripperAction(ros::NodeHandle &n)
ros::Time last_movement_time_
void setCanceled(const Result &result=Result(), const std::string &text=std::string(""))
void setAccepted(const std::string &text=std::string(""))
void goalCB(GoalHandle gh)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
void publish(const boost::shared_ptr< M > &message) const
void setSucceeded(const Result &result=Result(), const std::string &text=std::string(""))
ros::Subscriber sub_controller_state_
GAS::GoalHandle GoalHandle
int main(int argc, char **argv)
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)
ros::Timer watchdog_timer_
ros::Publisher pub_controller_command_