32 #include <boost/bind.hpp>
37 #include <trajectory_msgs/JointTrajectory.h>
38 #include <pr2_controllers_msgs/JointTrajectoryAction.h>
39 #include <pr2_controllers_msgs/JointTrajectoryControllerState.h>
62 if (!pn.
getParam(
"joints", joint_names))
72 for (
int i = 0; i < joint_names.
size(); ++i)
75 if (name_value.
getType() != XmlRpcValue::TypeString)
77 ROS_FATAL(
"Array of joint names should contain all strings. (namespace: %s)",
90 std::string ns = std::string(
"constraints/") +
joint_names_[i];
92 pn.
param(ns +
"/goal", g, -1.0);
93 pn.
param(ns +
"/trajectory", t, -1.0);
111 if (started_waiting_for_controller !=
ros::Time(0) &&
114 ROS_WARN(
"Waited for the controller for 30 seconds, but it never showed up.");
115 started_waiting_for_controller =
ros::Time(0);
132 static bool setsEqual(
const std::vector<std::string> &a,
const std::vector<std::string> &b)
134 if (a.size() != b.size())
137 for (
size_t i = 0; i < a.size(); ++i)
139 if (count(b.begin(), b.end(), a[i]) != 1)
142 for (
size_t i = 0; i < b.size(); ++i)
144 if (count(a.begin(), a.end(), b[i]) != 1)
158 bool should_abort =
false;
162 ROS_WARN(
"Aborting goal because we have never heard a controller state message.");
167 ROS_WARN(
"Aborting goal because we haven't heard from the controller in %.3lf seconds",
174 trajectory_msgs::JointTrajectory empty;
190 ROS_ERROR(
"Joints on incoming goal don't match our joints");
199 trajectory_msgs::JointTrajectory empty;
222 trajectory_msgs::JointTrajectory empty;
265 ROS_ERROR(
"Joint names from the controller don't match our joint names.");
277 for (
size_t i = 0; i < msg->joint_names.size(); ++i)
279 double abs_error = fabs(msg->error.positions[i]);
281 if (constraint >= 0 && abs_error > constraint)
284 trajectory_msgs::JointTrajectory empty;
290 ROS_WARN(
"Aborting because we would up outside the trajectory constraints");
298 bool inside_goal_constraints =
true;
299 for (
size_t i = 0; i < msg->joint_names.size() && inside_goal_constraints; ++i)
301 double abs_error = fabs(msg->error.positions[i]);
303 if (goal_constraint >= 0 && abs_error > goal_constraint)
304 inside_goal_constraints =
false;
307 if (fabs(msg->desired.velocities[i]) < 1e-6)
310 inside_goal_constraints =
false;
314 if (inside_goal_constraints)
325 ROS_WARN(
"Aborting because we wound up outside the goal constraints");
335 int main(
int argc,
char** argv)
337 ros::init(argc, argv,
"joint_trajectory_action_node");