34 inline void eigenToPointsMsgs(
const Eigen::MatrixXd& in,std::vector<geometry_msgs::Point>& out)
37 if(out.size()!= in.cols())
39 out.resize(in.cols());
43 for(
auto t = 0u; t < in.cols(); t++)
51 inline void createToolPathMarker(
const Eigen::MatrixXd& tool_line,
int id, std::string frame_id,
52 const std_msgs::ColorRGBA& rgb,
double line_width,
53 std::string ns,visualization_msgs::Marker& m)
57 m.header.frame_id = frame_id;
58 m.type = m.LINE_STRIP;
62 m.scale.x = line_width;
64 if(tool_line.cols() == 0)
70 eigenToPointsMsgs(tool_line,m.points);
73 inline void createSphereMarker(
const Eigen::Vector3d& tool_point,
int id, std::string frame_id,
74 const std_msgs::ColorRGBA& rgb,
double radius,
75 std::string ns,visualization_msgs::Marker& m)
79 m.header.frame_id = frame_id;
84 m.scale.x = m.scale.y = m.scale.z= 2*radius;
91 namespace noisy_filters
94 MultiTrajectoryVisualization::MultiTrajectoryVisualization():
95 name_(
"MultiTrajectoryVisualization"),
103 MultiTrajectoryVisualization::~MultiTrajectoryVisualization()
109 bool MultiTrajectoryVisualization::initialize(moveit::core::RobotModelConstPtr robot_model_ptr,
112 robot_model_ = robot_model_ptr;
113 group_name_ = group_name;
115 if(!configure(config))
121 viz_pub_ = nh_.advertise<visualization_msgs::MarkerArray>(marker_topic_,1);
131 std_msgs::ColorRGBA rgb;
132 rgb.r = (
static_cast<int>(p[0]))/255.0;
133 rgb.g =
static_cast<int>(p[1])/255.0;
134 rgb.b =
static_cast<int>(p[2])/255.0;
140 auto members = {
"line_width",
"marker_array_topic",
"rgb",
"marker_namespace"};
141 for(
auto& m : members)
145 ROS_ERROR(
"%s failed to find one or more required parameters",
getName().c_str());
154 line_width_ =
static_cast<double>(c[
"line_width"]);
155 rgb_ = toColorRgb(c[
"rgb"]);
156 marker_topic_ =
static_cast<std::string
>(c[
"marker_array_topic"]);
157 marker_namespace_ =
static_cast<std::string
>(c[
"marker_namespace"]);
168 bool MultiTrajectoryVisualization::setMotionPlanRequest(
const planning_scene::PlanningSceneConstPtr&
planning_scene,
169 const moveit_msgs::MotionPlanRequest &req,
171 moveit_msgs::MoveItErrorCodes& error_code)
175 error_code.val = error_code.SUCCESS;
179 tool_traj_line_ = Eigen::MatrixXd::Zero(3,config.
num_timesteps);
180 Eigen::Vector3d tool_point;
184 tool_traj_markers_.markers.resize(traj_total_);
185 tool_points_markers_.markers.resize(traj_total_);
188 createToolPathMarker(tool_traj_line_,
189 r+1,robot_model_->getRootLinkName(),
191 marker_namespace_,tool_traj_markers_.markers[
r]);
192 createSphereMarker(tool_point,
193 r+1,robot_model_->getRootLinkName(),
195 marker_namespace_ +
"/goal",tool_points_markers_.markers[
r]);
203 ROS_ERROR(
"%s Failed to get current robot state from request",
getName().c_str());
208 visualization_msgs::MarkerArray m;
214 bool MultiTrajectoryVisualization::filter(std::size_t start_timestep,
215 std::size_t num_timesteps,
216 int iteration_number,
218 Eigen::MatrixXd& parameters,
228 if(rollout_number >= traj_total_)
238 for(
auto t = 0u; t < parameters.cols();t++)
240 state_->setJointGroupPositions(joint_group,parameters.col(t));
241 Eigen::Affine3d tool_pos = state_->getFrameTransform(tool_link);
242 tool_traj_line_(0,t) = tool_pos.translation()(0);
243 tool_traj_line_(1,t) = tool_pos.translation()(1);
244 tool_traj_line_(2,t) = tool_pos.translation()(2);
248 eigenToPointsMsgs(tool_traj_line_,tool_traj_markers_.markers[rollout_number].points);
249 Eigen::Vector3d goal_tool_point = tool_traj_line_.rightCols(1);
250 tf::pointEigenToMsg(goal_tool_point, tool_points_markers_.markers[rollout_number].pose.position);
253 if(rollout_number == traj_total_ - 1)
255 viz_pub_.publish(tool_traj_markers_);
256 viz_pub_.publish(tool_points_markers_);
const std::string & getMessage() const
Interface class for filtering noisy trajectories.
const std::vector< std::string > & getLinkModelNames() const
Publishes rviz markers to visualize the noisy trajectories.
std::string getName(void *handle)
PLUGINLIB_EXPORT_CLASS(test_moveit_controller_manager::TestMoveItControllerManager, moveit_controller_manager::MoveItControllerManager)
bool robotStateMsgToRobotState(const Transforms &tf, const moveit_msgs::RobotState &robot_state, RobotState &state, bool copy_attached_bodies=true)
void pointEigenToMsg(const Eigen::Vector3d &e, geometry_msgs::Point &m)
bool hasMember(const std::string &name) const
static void poseTFToMsg(const Pose &bt, geometry_msgs::Pose &msg)
This defines a multi trajectory visualizer for publishing the noisy trajectories. ...