34 typedef std::vector<geometry_msgs::Point> ToolLine;
37 static const int MARKER_ID = 1;
39 inline void eigenToPointsMsgs(
const Eigen::MatrixXd& in,std::vector<geometry_msgs::Point>& out)
42 if(out.size()!= in.cols())
44 out.resize(in.cols());
48 for(
auto t = 0u; t < in.cols(); t++)
65 Eigen::MatrixXd tool_traj = Eigen::MatrixXd::Zero(3,parameters.cols());
68 for(
auto t = 0u; t < parameters.cols();t++)
72 tool_traj(0,t) = tool_pos.translation()(0);
73 tool_traj(1,t) = tool_pos.translation()(1);
74 tool_traj(2,t) = tool_pos.translation()(2);
77 return std::move(tool_traj);
80 inline void createToolPathMarker(
const Eigen::MatrixXd& tool_line,
int id, std::string frame_id,
81 const std_msgs::ColorRGBA& rgb,
double line_width,
82 std::string ns,visualization_msgs::Marker& m)
86 m.header.frame_id = frame_id;
87 m.type = m.LINE_STRIP;
91 m.scale.x = line_width;
93 if(tool_line.cols() == 0)
99 eigenToPointsMsgs(tool_line,m.points);
104 namespace update_filters
107 TrajectoryVisualization::TrajectoryVisualization():
108 name_(
"TrajectoryVisualization"),
111 publish_intermediate_(
false)
117 TrajectoryVisualization::~TrajectoryVisualization()
122 bool TrajectoryVisualization::initialize(moveit::core::RobotModelConstPtr robot_model_ptr,
125 robot_model_ = robot_model_ptr;
126 group_name_ = group_name;
128 if(!configure(config))
134 viz_pub_ = nh_.advertise<visualization_msgs::Marker>(marker_topic_,1);
144 std_msgs::ColorRGBA rgb;
145 rgb.r = (
static_cast<int>(p[0]))/255.0;
146 rgb.g =
static_cast<int>(p[1])/255.0;
147 rgb.b =
static_cast<int>(p[2])/255.0;
153 auto members = {
"line_width",
"rgb",
"error_rgb",
"publish_intermediate",
"marker_topic",
"marker_namespace"};
154 for(
auto& m : members)
158 ROS_ERROR(
"%s failed to find one or more required parameters",
getName().c_str());
166 line_width_ =
static_cast<double>(c[
"line_width"]);
167 rgb_ = toColorRgb(c[
"rgb"]);
168 error_rgb_ = toColorRgb(c[
"error_rgb"]);
169 publish_intermediate_ =
static_cast<bool>(c[
"publish_intermediate"]);
170 marker_topic_ =
static_cast<std::string
>(c[
"marker_topic"]);
171 marker_namespace_ =
static_cast<std::string
>(c[
"marker_namespace"]);
182 bool TrajectoryVisualization::setMotionPlanRequest(
const planning_scene::PlanningSceneConstPtr&
planning_scene,
183 const moveit_msgs::MotionPlanRequest &req,
185 moveit_msgs::MoveItErrorCodes& error_code)
189 error_code.val = error_code.SUCCESS;
193 tool_traj_line_ = Eigen::MatrixXd::Zero(3,config.
num_timesteps);
196 createToolPathMarker(tool_traj_line_,
197 MARKER_ID,robot_model_->getRootLinkName(),
199 marker_namespace_,tool_traj_marker_);
205 ROS_ERROR(
"%s Failed to get current robot state from request",
getName().c_str());
210 visualization_msgs::Marker m;
211 createToolPathMarker(Eigen::MatrixXd(),MARKER_ID,robot_model_->getRootLinkName(),rgb_,line_width_,marker_namespace_,m);
218 bool TrajectoryVisualization::filter(std::size_t start_timestep,
219 std::size_t num_timesteps,
220 int iteration_number,
221 const Eigen::MatrixXd& parameters,
222 Eigen::MatrixXd& updates,
232 if(publish_intermediate_)
234 Eigen::MatrixXd updated_parameters = parameters + updates;
236 eigenToPointsMsgs(tool_traj_line_,tool_traj_marker_.points);
237 viz_pub_.publish(tool_traj_marker_);
243 void TrajectoryVisualization::done(
bool success,
int total_iterations,
double final_cost,
const Eigen::MatrixXd& parameters)
247 eigenToPointsMsgs(tool_traj_line_,tool_traj_marker_.points);
251 tool_traj_marker_.color = error_rgb_;
254 viz_pub_.publish(tool_traj_marker_);
const std::string & getMessage() const
Publishes rviz markers to visualize the optimized trajectory.
const JointModelGroup * getJointModelGroup(const std::string &group) const
const std::vector< std::string > & getLinkModelNames() const
const Eigen::Affine3d & getFrameTransform(const std::string &id)
std::string getName(void *handle)
Interface class which applies filtering methods to the update parameters before it is added onto the ...
PLUGINLIB_EXPORT_CLASS(test_moveit_controller_manager::TestMoveItControllerManager, moveit_controller_manager::MoveItControllerManager)
This defines a trajectory visualizer for publishing the smooth trajectory.
bool robotStateMsgToRobotState(const Transforms &tf, const moveit_msgs::RobotState &robot_state, RobotState &state, bool copy_attached_bodies=true)
bool hasMember(const std::string &name) const
static void poseTFToMsg(const Pose &bt, geometry_msgs::Pose &msg)
void setJointGroupPositions(const std::string &joint_group_name, const double *gstate)
static Eigen::MatrixXd jointsToToolPath(RobotState &state, const std::string &group_name, const Eigen::MatrixXd ¶meters)
Creates a tool path xyz trajectory from the joint parameters.