-
-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #129 from hungpham2511/feat-parametrizer
[cpp]Implement trajectory parametrizer
- Loading branch information
Showing
19 changed files
with
652 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,4 +107,8 @@ venv.bak/ | |
.mypy_cache/ | ||
|
||
# emacs temp file | ||
*~ | ||
*~ | ||
cpp/.clangd | ||
build* | ||
cpp/doc/CMakeFiles/* | ||
cpp/doc/doc/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <toppra/parametrizer.hpp> | ||
#include <toppra/toppra.hpp> | ||
|
||
namespace toppra { | ||
|
||
Parametrizer::Parametrizer(GeometricPathPtr path, const Vector& gridpoints, | ||
const Vector& vsquared) | ||
: m_path(path), m_gridpoints(gridpoints) { | ||
assert(gridpoints.size() == vsquared.size()); | ||
m_vs.resize(vsquared.size()); | ||
for (std::size_t i = 0; i < gridpoints.size(); i++) { | ||
assert(vsquared[i] >= 0); | ||
m_vs[i] = std::sqrt(vsquared[i]); | ||
if (i == gridpoints.size() - 1) continue; | ||
assert(gridpoints[i + 1] > gridpoints[i]); | ||
} | ||
|
||
assert(std::abs(path->pathInterval()[0] - gridpoints[0]) < TOPPRA_NEARLY_ZERO); | ||
assert(std::abs(path->pathInterval()[1] - gridpoints[gridpoints.size() - 1]) < | ||
TOPPRA_NEARLY_ZERO); | ||
} | ||
|
||
Vector Parametrizer::eval_single(value_type val, int order) const { | ||
Vector v{1}; | ||
v << val; | ||
auto results = eval_impl(v, order); | ||
return results[0]; | ||
} | ||
|
||
Vectors Parametrizer::eval(const Vector& positions, int order) const { | ||
return eval_impl(positions, order); | ||
} | ||
|
||
Bound Parametrizer::pathInterval() const { return pathInterval_impl(); } | ||
|
||
bool Parametrizer::validate() const { return validate_impl(); } | ||
} // namespace toppra |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#ifndef TOPPRA_PARAMETRIZER_HPP | ||
#define TOPPRA_PARAMETRIZER_HPP | ||
|
||
#include <toppra/geometric_path.hpp> | ||
#include <toppra/toppra.hpp> | ||
|
||
namespace toppra { | ||
|
||
/** | ||
* \brief Abstract output trajectory parametrizers. | ||
* | ||
* A parametrizer has the same interface as a geometric path. It | ||
* receives as input the original geometric path and two arrays of | ||
* gridpoints and parametrization (i.e. squared path velocities). A | ||
* parametrizer should validate the input data. If not validated, | ||
* evaluation results are not defined. | ||
* | ||
* Requirements: https://github.com/hungpham2511/toppra/issues/102 | ||
* | ||
* Sub-classes should override the virtual private methods *_impl. | ||
*/ | ||
class Parametrizer : public GeometricPath { | ||
public: | ||
/** Construct the parametrizer. | ||
* | ||
* \param path Input geometric path. | ||
* \param gridpoints Shape (N+1,). Gridpoints of the parametrization, should be | ||
* compatible with the path domain. \param vsquared Shape (N+1,). Path velocity | ||
* squared, should have same shape as gridpoints as vsquared[i] corresponds to the | ||
* velocity at gridpoints[i]. | ||
*/ | ||
Parametrizer(GeometricPathPtr path, const Vector &gridpoints, const Vector &vsquared); | ||
|
||
/** \brief Evaluate the path at given position. | ||
*/ | ||
Vector eval_single(value_type, int order = 0) const override; | ||
|
||
/** \brief Evaluate the path at given positions (vector). | ||
*/ | ||
Vectors eval(const Vector &, int order = 0) const override; | ||
|
||
/** \brief Return the starting and ending path positions. | ||
*/ | ||
Bound pathInterval() const override; | ||
|
||
/** \brief Validate input data. | ||
* | ||
* Return false if something is wrong with the output | ||
* trajectory. Only use the trajectory if validation successes. | ||
*/ | ||
bool validate() const; | ||
|
||
virtual ~Parametrizer() {} | ||
|
||
protected: | ||
// Input geometric path | ||
GeometricPathPtr m_path; | ||
// Input gridpoints | ||
Vector m_gridpoints; | ||
// Input path velocities (not squared) | ||
Vector m_vs; | ||
|
||
private: | ||
/// To be overwriten by derived classes | ||
virtual Vectors eval_impl(const Vector &, int order = 0) const = 0; | ||
virtual bool validate_impl() const = 0; | ||
virtual Bound pathInterval_impl() const = 0; | ||
}; | ||
}; // namespace toppra | ||
|
||
#endif |
Oops, something went wrong.