Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trajectory plotting additions #76

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tesseract_msgs/msg/Trajectory.msg
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ string description
# (Optional) Override the existing Tesseract Environment
Environment environment

# (Optional) Additional Commands to be applied to environment prior to trajectory visualization
# (Optional) Additional Commands to be applied to environment prior to trajectory visualization (ignored if environment is provided)
tesseract_msgs/EnvironmentCommand[] commands

# (Required) Initial Environment Joint State
Expand Down
6 changes: 5 additions & 1 deletion tesseract_rosutils/include/tesseract_rosutils/plotting.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,13 @@ class ROSPlotting : public tesseract_visualization::Visualization
const tesseract_planning::InstructionPoly& instruction,
std::string ns = "");

void plotTrajectory(const tesseract_environment::Commands& cmds,
const tesseract_planning::InstructionPoly& instruction,
std::string = "");

void plotToolpath(const tesseract_environment::Environment& env,
const tesseract_planning::InstructionPoly& instruction,
std::string ns);
std::string ns = "");

void plotMarker(const tesseract_visualization::Marker& marker, std::string ns = "") override;

Expand Down
43 changes: 41 additions & 2 deletions tesseract_rosutils/src/plotting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,10 @@ void ROSPlotting::plotTrajectory(const tesseract_msgs::msg::Trajectory& traj, st

void ROSPlotting::plotTrajectory(const tesseract_common::JointTrajectory& traj,
const tesseract_scene_graph::StateSolver& /*state_solver*/,
std::string /*ns*/)
std::string ns)
{
tesseract_msgs::msg::Trajectory msg;
msg.ns = ns;

if (!traj.empty())
{
Expand All @@ -138,9 +139,10 @@ void ROSPlotting::plotTrajectory(const tesseract_common::JointTrajectory& traj,

void ROSPlotting::plotTrajectory(const tesseract_environment::Environment& env,
const tesseract_planning::InstructionPoly& instruction,
std::string /*ns*/)
std::string ns)
{
tesseract_msgs::msg::Trajectory msg;
msg.ns = ns;

// Set tesseract state information
toMsg(msg.environment, env);
Expand Down Expand Up @@ -168,6 +170,43 @@ void ROSPlotting::plotTrajectory(const tesseract_environment::Environment& env,
plotTrajectory(msg);
}

void ROSPlotting::plotTrajectory(const tesseract_environment::Commands& cmds,
const tesseract_planning::InstructionPoly& instruction,
std::string ns)
{
tesseract_msgs::msg::Trajectory msg;
msg.ns = ns;

// Set the commands message
std::vector<tesseract_msgs::msg::EnvironmentCommand> env_cmds;
tesseract_rosutils::toMsg(env_cmds, cmds, 0);
msg.commands = env_cmds;

// Convert to joint trajectory
assert(instruction.isCompositeInstruction());
const auto& ci = instruction.as<tesseract_planning::CompositeInstruction>();
tesseract_common::JointTrajectory traj = tesseract_planning::toJointTrajectory(ci);

if (!traj.empty())
{
// Set the initial state
for (std::size_t i = 0; i < traj[0].joint_names.size(); ++i)
{
tesseract_msgs::msg::StringDoublePair pair;
pair.first = traj[0].joint_names[i];
pair.second = traj[0].position[static_cast<Eigen::Index>(i)];
msg.initial_state.push_back(pair);
}
}

// Set the joint trajectory message
tesseract_msgs::msg::JointTrajectory traj_msg;
toMsg(traj_msg, traj);
msg.joint_trajectories.push_back(traj_msg);

plotTrajectory(msg);
}

void ROSPlotting::plotMarker(const tesseract_visualization::Marker& marker, std::string ns)
{
switch (marker.getType())
Expand Down
Loading