move_to_target_pose_planning.cpp
Go to the documentation of this file.
1 //
2 // Created by yijiangh on 9/4/17.
3 //
4 
6 #include <ros/console.h>
7 
8 // service
9 #include <choreo_msgs/MoveToTargetPose.h>
10 
11 // msg
12 #include <trajectory_msgs/JointTrajectory.h>
13 
14 #include "path_transitions.h"
15 #include "common_utils.h"
16 
17 // for immediate execution
19 #include <control_msgs/FollowJointTrajectoryAction.h>
20 
22 {
23 
24 const static std::string JOINT_TOPIC_NAME =
25  "joint_states"; // ROS topic to subscribe to for current robot state info
26 
28  choreo_msgs::MoveToTargetPose::Request& req,
29  choreo_msgs::MoveToTargetPose::Response& res)
30 {
31  if(req.type == req.JOINT_POSE)
32  {
33  std::vector<double> current_joints = getCurrentJointState(JOINT_TOPIC_NAME);
34  const std::vector<std::string>& joint_names =
35  moveit_model_->getJointModelGroup(hotend_group_name_)->getActiveJointModelNames();
36 
37  if(current_joints == req.pose)
38  {
39  // skip planning if required pose = current pose
40  return true;
41  }
42 
43  std::vector<double> target_pose(req.pose.end() - joint_names.size(), req.pose.end());
44 
45  trajectory_msgs::JointTrajectory ros_traj = getMoveitPlan(hotend_group_name_,
46  current_joints,
47  target_pose,
49 
50  ros::Duration base_time = ros_traj.points[0].time_from_start;
51 
52  double sim_time_scale = 0.6;
53  for (int i = 0; i < ros_traj.points.size(); i++)
54  {
55  ros_traj.points[i].time_from_start -= base_time;
56 
57  //sim speed tuning
58  ros_traj.points[i].time_from_start *= sim_time_scale;
59  }
60 
61  fillTrajectoryHeaders(joint_names, ros_traj, world_frame_);
62 
63  // step 5: immediate execution (a quick solution for debugging)
64  ros::NodeHandle nh;
66  if (!client.waitForServer(ros::Duration(1.0)))
67  {
68  ROS_WARN("[Reset Exe] Exec timed out");
69  }
70  else
71  {
72  ROS_INFO("[Reset Exe] Found action server");
73  }
74 
75  control_msgs::FollowJointTrajectoryGoal goal;
76  goal.trajectory = ros_traj;
77 
78  client.sendGoalAndWait(goal);
79  return true;
80  }
81 }
82 }
static const std::string JOINT_TOPIC_NAME
bool waitForServer(const ros::Duration &timeout=ros::Duration(0, 0)) const
#define ROS_WARN(...)
std::vector< double > getCurrentJointState(const std::string &topic)
void fillTrajectoryHeaders(const std::vector< std::string > &joints, trajectory_msgs::JointTrajectory &traj, const std::string world_frame)
#define ROS_INFO(...)
SimpleClientGoalState sendGoalAndWait(const Goal &goal, const ros::Duration &execute_timeout=ros::Duration(0, 0), const ros::Duration &preempt_timeout=ros::Duration(0, 0))
trajectory_msgs::JointTrajectory getMoveitPlan(const std::string &group_name, const std::vector< double > &joints_start, const std::vector< double > &joints_stop, moveit::core::RobotModelConstPtr model)
bool handleMoveToTargetPosePlanAndExecution(choreo_msgs::MoveToTargetPose::Request &req, choreo_msgs::MoveToTargetPose::Response &res)


choreo_process_planning
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:02