33 #include <geometry_msgs/Transform.h> 34 #include <moveit_msgs/DisplayTrajectory.h> 40 if (scene->debug_)
HIGHLIGHT_NAMED(
"VisualizationMoveIt",
"Initialising visualizer");
49 trajectory_pub_ = Server::Advertise<moveit_msgs::DisplayTrajectory>(
scene_->GetName() + (
scene_->GetName().empty() ?
"" :
"/") +
"Trajectory", 1,
true);
61 if (trajectory.cols() !=
scene_->GetKinematicTree().GetNumControlledJoints())
62 ThrowPretty(
"Number of DoFs in trajectory does not match number of controlled joints of robot. Got " << trajectory.cols() <<
" but expected " <<
scene_->GetKinematicTree().GetNumControlledJoints());
64 moveit_msgs::DisplayTrajectory traj_msg;
65 traj_msg.model_id =
scene_->GetKinematicTree().GetRobotModel()->getName();
67 const int num_trajectory_points = trajectory.rows();
69 traj_msg.trajectory.resize(1);
70 traj_msg.trajectory[0].joint_trajectory.header.frame_id =
scene_->GetRootFrameName();
71 traj_msg.trajectory[0].joint_trajectory.header.stamp =
ros::Time::now();
75 switch (
scene_->GetKinematicTree().GetControlledBaseType())
95 traj_msg.trajectory[0].multi_dof_joint_trajectory.header.frame_id =
scene_->GetRootFrameName();
96 traj_msg.trajectory[0].multi_dof_joint_trajectory.joint_names.push_back(
scene_->GetKinematicTree().GetRootJointName());
97 traj_msg.trajectory[0].multi_dof_joint_trajectory.points.resize(num_trajectory_points);
99 geometry_msgs::Transform base_transform;
100 Eigen::Quaterniond quat;
101 for (
int i = 0; i < num_trajectory_points; ++i)
103 base_transform.translation.x = trajectory(i, 0);
104 base_transform.translation.y = trajectory(i, 1);
108 base_transform.translation.z = trajectory(i, 2);
109 quat = Eigen::AngleAxisd(trajectory(i, 3), Eigen::Vector3d::UnitX()) * Eigen::AngleAxisd(trajectory(i, 4), Eigen::Vector3d::UnitY()) * Eigen::AngleAxisd(trajectory(i, 5), Eigen::Vector3d::UnitZ());
113 base_transform.translation.z = 0.0;
114 quat = Eigen::AngleAxisd(0.0, Eigen::Vector3d::UnitX()) * Eigen::AngleAxisd(0.0, Eigen::Vector3d::UnitY()) * Eigen::AngleAxisd(trajectory(i, 2), Eigen::Vector3d::UnitZ());
117 base_transform.rotation.x = quat.x();
118 base_transform.rotation.y = quat.y();
119 base_transform.rotation.z = quat.z();
120 base_transform.rotation.w = quat.w();
122 traj_msg.trajectory[0].multi_dof_joint_trajectory.points[i].transforms.push_back(base_transform);
128 traj_msg.trajectory_start.joint_state.header.frame_id =
scene_->GetRootFrameName();
131 auto model_state_map =
scene_->GetKinematicTree().GetModelStateMap();
132 for (
const auto& pair : model_state_map)
135 if (pair.first.find(
scene_->GetRootFrameName()) == std::string::npos)
137 traj_msg.trajectory_start.joint_state.name.push_back(pair.first);
138 traj_msg.trajectory_start.joint_state.position.push_back(pair.second);
143 const int num_actuated_joints_without_base = trajectory.cols() - base_offset;
144 traj_msg.trajectory[0].joint_trajectory.points.resize(num_trajectory_points);
145 traj_msg.trajectory[0].joint_trajectory.joint_names.resize(num_actuated_joints_without_base);
146 for (
int i = 0; i < num_actuated_joints_without_base; ++i)
147 traj_msg.trajectory[0].joint_trajectory.joint_names[i] =
scene_->GetKinematicTree().GetControlledJointNames()[base_offset + i];
150 for (
int i = 0; i < num_trajectory_points; ++i)
152 traj_msg.trajectory[0].joint_trajectory.points[i].positions.resize(num_actuated_joints_without_base);
153 for (
int n = 0;
n < num_actuated_joints_without_base; ++
n)
155 traj_msg.trajectory[0].joint_trajectory.points[i].positions[
n] = trajectory(i,
n + base_offset);
void publish(const boost::shared_ptr< M > &message) const
ros::Publisher trajectory_pub_
std::shared_ptr< Scene > ScenePtr
void DisplayTrajectory(Eigen::MatrixXdRefConst trajectory)
const Eigen::Ref< const Eigen::MatrixXd > & MatrixXdRefConst
VisualizationMoveIt(ScenePtr scene)
#define HIGHLIGHT_NAMED(name, x)
virtual ~VisualizationMoveIt()