26 state_is_valid_(false)
41 for (
int i = 0; i < chains.
size(); ++i)
43 std::string
name, topic, group;
44 name =
static_cast<std::string
>(chains[i][
"name"]);
45 group =
static_cast<std::string
>(chains[i][
"planning_group"]);
47 if (chains[i].hasMember(
"topic"))
49 topic =
static_cast<std::string
>(chains[i][
"topic"]);
53 for (
int j = 0; j < chains[i][
"joints"].
size(); ++j)
55 controller->joint_names.push_back(
static_cast<std::string
>(chains[i][
"joints"][j]));
58 ROS_INFO(
"Waiting for %s...", topic.c_str());
59 if (!controller->client.waitForServer(
ros::Duration(wait_time)))
61 ROS_WARN(
"Failed to connect to %s", topic.c_str());
69 ROS_WARN(
"Failed to connect to move_group");
88 if (msg->name.size() != msg->position.size())
90 ROS_ERROR(
"JointState Error: name array is not same size as position array.");
94 if (msg->position.size() != msg->velocity.size())
96 ROS_ERROR(
"JointState Error: position array is not same size as velocity array.");
102 for (
size_t msg_j = 0; msg_j < msg->name.size(); msg_j++)
105 for (state_j = 0; state_j <
state_.name.size(); state_j++)
107 if (
state_.name[state_j] == msg->name[msg_j])
109 state_.position[state_j] = msg->position[msg_j];
110 state_.velocity[state_j] = msg->velocity[msg_j];
114 if (state_j ==
state_.name.size())
117 state_.name.push_back(msg->name[msg_j]);
118 state_.position.push_back(msg->position[msg_j]);
119 state_.velocity.push_back(msg->velocity[msg_j]);
132 trajectory_msgs::JointTrajectoryPoint
135 trajectory_msgs::JointTrajectoryPoint p;
136 for (
size_t i = 0; i < joints.size(); ++i)
138 for (
size_t j = 0; j < state.name.size(); ++j)
140 if (joints[i] == state.name[j])
142 p.positions.push_back(state.position[j]);
146 p.velocities.push_back(0.0);
147 p.accelerations.push_back(0.0);
148 if (p.velocities.size() != p.positions.size())
164 control_msgs::FollowJointTrajectoryGoal goal;
165 goal.trajectory.joint_names =
controllers_[i]->joint_names;
171 moveit_msgs::MoveGroupGoal moveit_goal;
172 moveit_goal.request.group_name =
controllers_[i]->chain_planning_group;
173 moveit_goal.request.num_planning_attempts = 1;
174 moveit_goal.request.allowed_planning_time = 5.0;
176 moveit_msgs::Constraints c1;
177 c1.joint_constraints.resize(
controllers_[i]->joint_names.size());
178 for (
size_t c = 0; c <
controllers_[i]->joint_names.size(); c++)
180 c1.joint_constraints[c].joint_name =
controllers_[i]->joint_names[c];
181 c1.joint_constraints[c].position = p.positions[c];
182 c1.joint_constraints[c].tolerance_above = 0.01;
183 c1.joint_constraints[c].tolerance_below = 0.01;
184 c1.joint_constraints[c].weight = 1.0;
186 moveit_goal.request.goal_constraints.push_back(c1);
192 moveit_goal.request.start_state.is_diff =
true;
193 moveit_goal.planning_options.planning_scene_diff.is_diff =
true;
194 moveit_goal.planning_options.planning_scene_diff.robot_state.is_diff =
true;
197 moveit_goal.planning_options.plan_only =
true;
202 if (result->error_code.val != moveit_msgs::MoveItErrorCodes::SUCCESS)
208 goal.trajectory = result->planned_trajectory.joint_trajectory;
209 max_duration = std::max(max_duration, goal.trajectory.points[goal.trajectory.points.size()-1].time_from_start.toSec());
215 goal.trajectory.points.push_back(p);
236 sensor_msgs::JointState state;
259 for (
size_t j = 0; j < state.name.size(); ++j)
262 if (fabs(state.velocity[j]) < 0.001)
267 for (
size_t k = 0; k <
controllers_[i]->joint_names.size(); ++k)
300 std::vector<std::string> chains;
309 const std::string& chain_name)
316 std::vector<std::string> empty;
321 const std::string& chain_name)
328 std::vector<std::string> empty;
329 return std::string(
"");