Skip to content

Commit

Permalink
- Implement plotting a trajectory with commands
Browse files Browse the repository at this point in the history
- Implement trajectory namespace option
  • Loading branch information
rjoomen committed Oct 12, 2023
1 parent cfbc929 commit cc947bf
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
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

0 comments on commit cc947bf

Please sign in to comment.