Skip to content

Commit

Permalink
cli and viz: interpolate trajectory
Browse files Browse the repository at this point in the history
  • Loading branch information
jlblancoc committed Sep 30, 2024
1 parent 6d7d174 commit 5c1a065
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
17 changes: 16 additions & 1 deletion apps/path-planner-cli/path-planner-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ TCLAP::ValueArg<float> argObstaclesGridResolution(
"pixel in meters.",
false, 0.05, "0.05", cmd);

TCLAP::ValueArg<float> arg_interpolation_period(
"", "interpolarion-period",
"Interpolation (and animation) time step between keyframes [s].", false,
0.25, "0.25", cmd);

TCLAP::ValueArg<std::string> arg_ptgs_file(
"c", "ptg-config", "Input .ini file with PTG definitions.", true, "",
"ptgs.ini", cmd);
Expand Down Expand Up @@ -384,7 +389,17 @@ static void do_plan_path()
{
const auto t0 = mrpt::Clock::nowDouble();

traj = mpp::plan_to_trajectory(pathEdges, pi.ptgs);
const double interpPeriod = arg_interpolation_period.getValue();

traj = mpp::plan_to_trajectory(pathEdges, pi.ptgs, interpPeriod);

// Note: trajectory is in local frame of reference
// of plan.originalInput.stateStart.pose
// so, correct that relative pose so we keep everything in global
// frame:
const auto& startPose = plan.originalInput.stateStart.pose;
for (auto& kv : *traj)
kv.second.state.pose = startPose + kv.second.state.pose;

const auto dt = mrpt::Clock::nowDouble() - t0;

Expand Down
6 changes: 4 additions & 2 deletions mrpt_path_planning/include/mpp/algos/refine_trajectory.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ namespace mpp
void refine_trajectory(
const MotionPrimitivesTreeSE2::path_t& inPath,
MotionPrimitivesTreeSE2::edge_sequence_t& edgesToRefine,
const TrajectoriesAndRobotShape& ptgInfo);
const TrajectoriesAndRobotShape& ptgInfo,
const double ptg_tolerance_dist = 0.10);

/// \overload taking `std::vector` of nodes and edges, instead of `std::list`
void refine_trajectory(
const std::vector<MotionPrimitivesTreeSE2::node_t>& inPath,
std::vector<MotionPrimitivesTreeSE2::edge_t>& edgesToRefine,
const TrajectoriesAndRobotShape& ptgInfo);
const TrajectoriesAndRobotShape& ptgInfo,
const double ptg_tolerance_dist = 0.10);

} // namespace mpp
8 changes: 4 additions & 4 deletions mrpt_path_planning/src/algos/refine_trajectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
void mpp::refine_trajectory(
const mpp::MotionPrimitivesTreeSE2::path_t& inPath,
MotionPrimitivesTreeSE2::edge_sequence_t& edgesToRefine,
const TrajectoriesAndRobotShape& ptgInfo)
const TrajectoriesAndRobotShape& ptgInfo, const double ptg_tolerance_dist)
{
const size_t nEdges = edgesToRefine.size();
ASSERT_EQUAL_(inPath.size(), nEdges + 1);
Expand Down Expand Up @@ -53,7 +53,7 @@ void mpp::refine_trajectory(
normalized_distance_t newNormDist = 0;

const bool ok = ptg->inverseMap_WS2TP(
deltaNodes.x, deltaNodes.y, newK, newNormDist);
deltaNodes.x, deltaNodes.y, newK, newNormDist, ptg_tolerance_dist);
if (!ok)
{
std::stringstream ss;
Expand Down Expand Up @@ -92,7 +92,7 @@ void mpp::refine_trajectory(
void mpp::refine_trajectory(
const std::vector<mpp::MotionPrimitivesTreeSE2::node_t>& inPath,
std::vector<mpp::MotionPrimitivesTreeSE2::edge_t>& edgesToRefine,
const TrajectoriesAndRobotShape& ptgInfo)
const TrajectoriesAndRobotShape& ptgInfo, const double ptg_tolerance_dist)
{
mpp::MotionPrimitivesTreeSE2::path_t newPath;
MotionPrimitivesTreeSE2::edge_sequence_t newEdges;
Expand All @@ -102,5 +102,5 @@ void mpp::refine_trajectory(

// this will store the output directly in "edgesToRefine" since we use
// pointers above:
refine_trajectory(newPath, newEdges, ptgInfo);
refine_trajectory(newPath, newEdges, ptgInfo, ptg_tolerance_dist);
}
4 changes: 1 addition & 3 deletions mrpt_path_planning/src/algos/viz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* ------------------------------------------------------------------------- */

#include <mpp/algos/render_tree.h>
#include <mpp/algos/trajectories.h>
#include <mpp/algos/viz.h>
#include <mrpt/gui/CDisplayWindow3D.h>
#include <mrpt/opengl/CCylinder.h>
Expand Down Expand Up @@ -106,9 +107,6 @@ void mpp::viz_nav_plan_animation(

glVehFrame->insert(glVeh);

// The path is referenced to the path planning "start pose", account for it:
glVehFrame->setPose(plan.originalInput.stateStart.pose);

// Build opengl scene:
{
mrpt::gui::CDisplayWindow3DLocker dwl(*win, scene);
Expand Down

0 comments on commit 5c1a065

Please sign in to comment.