26 state_is_valid_(false)
40 for (
int i = 0; i < chains.
size(); ++i)
42 std::string name, topic, group;
43 name =
static_cast<std::string
>(chains[i][
"name"]);
44 group =
static_cast<std::string
>(chains[i][
"planning_group"]);
46 if (chains[i].hasMember(
"topic"))
48 topic =
static_cast<std::string
>(chains[i][
"topic"]);
52 for (
int j = 0; j < chains[i][
"joints"].
size(); ++j)
54 controller->joint_names.push_back(static_cast<std::string>(chains[i][
"joints"][j]));
57 ROS_INFO(
"Waiting for %s...", topic.c_str());
58 if (!controller->client.waitForServer(
ros::Duration(wait_time)))
60 ROS_WARN(
"Failed to connect to %s", topic.c_str());
68 ROS_WARN(
"Failed to connect to move_group");
87 if (msg->name.size() != msg->position.size())
89 ROS_ERROR(
"JointState Error: name array is not same size as position array.");
93 if (msg->position.size() != msg->velocity.size())
95 ROS_ERROR(
"JointState Error: position array is not same size as velocity array.");
101 for (
size_t msg_j = 0; msg_j < msg->name.size(); msg_j++)
104 for (state_j = 0; state_j <
state_.name.size(); state_j++)
106 if (
state_.name[state_j] == msg->name[msg_j])
108 state_.position[state_j] = msg->position[msg_j];
109 state_.velocity[state_j] = msg->velocity[msg_j];
113 if (state_j ==
state_.name.size())
116 state_.name.push_back(msg->name[msg_j]);
117 state_.position.push_back(msg->position[msg_j]);
118 state_.velocity.push_back(msg->velocity[msg_j]);
131 trajectory_msgs::JointTrajectoryPoint
134 trajectory_msgs::JointTrajectoryPoint p;
135 for (
size_t i = 0; i < joints.size(); ++i)
137 for (
size_t j = 0; j < state.name.size(); ++j)
139 if (joints[i] == state.name[j])
141 p.positions.push_back(state.position[j]);
145 p.velocities.push_back(0.0);
146 p.accelerations.push_back(0.0);
147 if (p.velocities.size() != p.positions.size())
163 control_msgs::FollowJointTrajectoryGoal goal;
164 goal.trajectory.joint_names =
controllers_[i]->joint_names;
170 moveit_msgs::MoveGroupGoal moveit_goal;
171 moveit_goal.request.group_name =
controllers_[i]->chain_planning_group;
172 moveit_goal.request.num_planning_attempts = 1;
173 moveit_goal.request.allowed_planning_time = 5.0;
175 moveit_msgs::Constraints c1;
176 c1.joint_constraints.resize(
controllers_[i]->joint_names.size());
177 for (
size_t c = 0; c <
controllers_[i]->joint_names.size(); c++)
179 c1.joint_constraints[c].joint_name =
controllers_[i]->joint_names[c];
180 c1.joint_constraints[c].position = p.positions[c];
181 c1.joint_constraints[c].tolerance_above = 0.01;
182 c1.joint_constraints[c].tolerance_below = 0.01;
183 c1.joint_constraints[c].weight = 1.0;
185 moveit_goal.request.goal_constraints.push_back(c1);
191 moveit_goal.request.start_state.is_diff =
true;
192 moveit_goal.planning_options.planning_scene_diff.is_diff =
true;
193 moveit_goal.planning_options.planning_scene_diff.robot_state.is_diff =
true;
196 moveit_goal.planning_options.plan_only =
true;
201 if (result->error_code.val != moveit_msgs::MoveItErrorCodes::SUCCESS)
207 goal.trajectory = result->planned_trajectory.joint_trajectory;
208 max_duration = std::max(max_duration, goal.trajectory.points[goal.trajectory.points.size()-1].time_from_start.toSec());
214 goal.trajectory.points.push_back(p);
235 sensor_msgs::JointState state;
252 for (
size_t j = 0; j < state.name.size(); ++j)
255 if (fabs(state.velocity[j]) < 0.001)
260 for (
size_t k = 0; k <
controllers_[i]->joint_names.size(); ++k)
293 std::vector<std::string> chains;
302 const std::string& chain_name)
309 std::vector<std::string> empty;
314 const std::string& chain_name)
321 std::vector<std::string> empty;
322 return std::string(
"");
std::string getPlanningGroupName(const std::string &chain_name)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
actionlib::SimpleActionClient< moveit_msgs::MoveGroupAction > MoveGroupClient
Type const & getType() const
void stateCallback(const sensor_msgs::JointStateConstPtr &msg)
std::vector< std::string > getChainJointNames(const std::string &chain_name)
Get the joint names associated with a chain. Mainly for testing.
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
sensor_msgs::JointState state_
bool waitToSettle()
Wait for joints to settle.
boost::mutex state_mutex_
trajectory_msgs::JointTrajectoryPoint makePoint(const sensor_msgs::JointState &state, const std::vector< std::string > &joints)
Calibration code lives under this namespace.
bool moveToState(const sensor_msgs::JointState &state)
Send commands to all managed joints. The ChainManager automatically figures out which controller to s...
bool getParam(const std::string &key, std::string &s) const
bool getState(sensor_msgs::JointState *state)
Get the current JointState message.
MoveGroupClientPtr move_group_
bool hasParam(const std::string &key) const
#define ROS_ERROR_STREAM(args)
std::vector< boost::shared_ptr< ChainController > > controllers_
ros::Subscriber subscriber_
ROSCPP_DECL void spinOnce()
std::vector< std::string > getChains()
Get the names of chains. Mainly for testing.
ChainManager(ros::NodeHandle &nh, double wait_time=15.0)
Constructor, sets up chains from ros parameters.