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

feat!: split trajectory classes and implement Cartesian/JointState specializations #218

Merged
Merged
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
61455af
feat: move up to C++20
bpapaspyros Jan 13, 2025
1c0c110
refactor: format Trajectory.hpp
bpapaspyros Jan 13, 2025
b957af4
refactor: simplify Trajectory to a flatter base class
bpapaspyros Jan 13, 2025
cee8f97
feat: add Cartesian/JointTrajectory to StateType
bpapaspyros Jan 14, 2025
c76f70d
feat: implement CartesianTrajectory
bpapaspyros Jan 15, 2025
12782ac
feat: implement JointTrajectory class
bpapaspyros Jan 15, 2025
a6761ef
fix: override cleanup functions and allow derived classes to clean
bpapaspyros Jan 15, 2025
094c7e3
feat: add set_point(s) functionality
bpapaspyros Jan 15, 2025
9c11b71
test: expand test case coverage
bpapaspyros Jan 15, 2025
eeae5ab
refactor: rename directory from trajectories->trajectory
bpapaspyros Jan 15, 2025
d2dcae7
docs: update CHANGELOG.md
bpapaspyros Jan 15, 2025
6326d0d
fix: make get_point(s) public in TrajectoryBase
bpapaspyros Jan 15, 2025
c41fd67
docs: update CHANGELOG.md
bpapaspyros Jan 15, 2025
216f1b9
fix: python update bindings
bpapaspyros Jan 15, 2025
0dbf0f1
Revert "feat: move up to C++20"
bpapaspyros Jan 16, 2025
e4f3fb0
refactor: tidy up headers (public/protected/private)
bpapaspyros Jan 16, 2025
f1844f6
refactor: redifine number sequence of StateType enum
bpapaspyros Jan 16, 2025
94ef3f3
fix: make TrajectoryBase contructors protected
bpapaspyros Jan 16, 2025
5c45bec
docs: docstrings
bpapaspyros Jan 16, 2025
0b06d51
fix: change set_point signature to move index at the end
bpapaspyros Jan 16, 2025
0748fb2
fix: minor fix in TrajectoryBase [] overload
bpapaspyros Jan 16, 2025
2b40eb9
feat: add more Trajectory constructors
bpapaspyros Jan 16, 2025
198569d
fix: set_point(s) functions throw instead of returning bool
bpapaspyros Jan 16, 2025
c5c7139
test: adapt tests
bpapaspyros Jan 16, 2025
cf30137
refactor: redesign the flat trajectory classes and pack data better
bpapaspyros Jan 19, 2025
cf54ae0
refactor: make base class get_point(s) classes protected
bpapaspyros Jan 19, 2025
3478b0b
fix: expose get_points functions in test interface
bpapaspyros Jan 19, 2025
ced7d7c
fix: rearrange includes
bpapaspyros Jan 28, 2025
741c017
docs: update docstrings
bpapaspyros Jan 28, 2025
47e6311
fix: tidy up clear, reset, and delete functions
bpapaspyros Jan 28, 2025
ee987c7
feat: implement add_points function in TrajectoryBase
bpapaspyros Jan 28, 2025
f0e75bc
feat: implement add_points functions for derived classes
bpapaspyros Jan 28, 2025
1e8e12c
test: fix tests on reset
bpapaspyros Jan 28, 2025
8bc0280
refactor: variable renaming
bpapaspyros Jan 28, 2025
f95ad5e
fix: improve get_times_from_start
bpapaspyros Jan 28, 2025
3d7e7f2
fix: tidy up TrajectoryBase [] overload and exceptions
bpapaspyros Jan 28, 2025
abc89bf
fix: use add_point in CartesianTrajectory constructor
bpapaspyros Jan 28, 2025
fe5c9a2
fix: condition and state update after delete_point
bpapaspyros Jan 28, 2025
c4e59c8
Merge branch 'main' into feat/restructure-trajectory-classes
bpapaspyros Jan 28, 2025
a903f18
feat: delete_point by providing and index
bpapaspyros Jan 28, 2025
f0ffbcc
fix: use vectors instead of queues in getters
bpapaspyros Jan 29, 2025
8610d36
fix: rearrange constructor arguments
bpapaspyros Jan 29, 2025
63cb968
refactor: change reference frame/joint names/robot name setting logic
bpapaspyros Jan 29, 2025
1f8b30e
fix: correct flag value when deleting results in empty queue
bpapaspyros Jan 29, 2025
4534679
fix: further restructure constructors
bpapaspyros Jan 30, 2025
e85cee4
Merge branch 'feat/trajectory-msgs-dev' into feat/restructure-traject…
bpapaspyros Jan 30, 2025
739ba8a
test: clean up and improve test structure and test coverage
bpapaspyros Jan 30, 2025
914a826
refactor: improve condition checks in vector operations
bpapaspyros Jan 30, 2025
0ff1210
refactor: re-arrange includes
bpapaspyros Jan 30, 2025
93419ca
fix: better checks for empty vector arguments
bpapaspyros Jan 30, 2025
2ed6228
refactor: improve/optimize code structure and readability
bpapaspyros Jan 31, 2025
55afa45
fix: more constructor touch ups and docstring updates
bpapaspyros Jan 31, 2025
822401b
feat: add getters for individual duration & time from start
bpapaspyros Jan 31, 2025
bd0c01c
feat: add function that returns the total trajectory duration
bpapaspyros Jan 31, 2025
1e418b7
fix: empty state bug fixes and improve trajectory point constructors
Feb 4, 2025
17293a2
fix: correctly call base constructor on empty CartesianTrajectory
Feb 4, 2025
dd625a6
docs: update docstrings (WIP)
bpapaspyros Feb 4, 2025
82939aa
docs: update docstrings
bpapaspyros Feb 4, 2025
cdefa4b
feat: modernize syntax where possible for verbosity and readabilty
bpapaspyros Feb 4, 2025
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
Prev Previous commit
Next Next commit
feat: add set_point(s) functionality
  • Loading branch information
bpapaspyros committed Jan 15, 2025
commit 094c7e3d873600f894bf363d67423701352cc6e0
Original file line number Diff line number Diff line change
@@ -48,6 +48,28 @@ class CartesianTrajectory : public TrajectoryBase<Eigen::VectorXd> {
*/
CartesianState get_point(unsigned int index) const;

/**
* @brief Set the trajectory point at given index
* @param index the index
* @param point the new point
* @param new_time the new time
* @return Success of the operation
*/
template<typename DurationT>
bool
set_point(unsigned int index, const CartesianState& point, const std::chrono::duration<int64_t, DurationT>& new_time);

/**
* @brief Set the trajectory point at given index
* @param points vector of new points
* @param new_time vector of new times
* @return Success of the operation
*/
template<typename DurationT>
bool set_points(
const std::vector<CartesianState>& points,
const std::vector<std::chrono::duration<int64_t, DurationT>>& new_times);

/**
* @brief Operator overload for returning a single trajectory point and
* corresponding time
@@ -73,6 +95,9 @@ class CartesianTrajectory : public TrajectoryBase<Eigen::VectorXd> {
template<typename DurationT>
inline bool CartesianTrajectory::add_point(
const CartesianState& new_point, const std::chrono::duration<int64_t, DurationT>& new_time) {
if (new_point.is_empty()) {
return false;
}
if (this->get_size() > 0) {
if (new_point.get_reference_frame() != reference_frame_) {
return false;
@@ -87,6 +112,9 @@ inline bool CartesianTrajectory::add_point(
template<typename DurationT>
inline bool CartesianTrajectory::insert_point(
const CartesianState& new_point, const std::chrono::duration<int64_t, DurationT>& new_time, int pos) {
if (new_point.is_empty()) {
return false;
}
if (this->get_size() > 0) {
if (new_point.get_reference_frame() != reference_frame_) {
return false;
@@ -98,4 +126,40 @@ inline bool CartesianTrajectory::insert_point(
return true;
}

template<typename DurationT>
inline bool CartesianTrajectory::set_point(
unsigned int index, const CartesianState& point, const std::chrono::duration<int64_t, DurationT>& new_time) {
if (point.is_empty()) {
return false;
}
if (point.get_reference_frame() != reference_frame_) {
return false;
}
return this->TrajectoryBase<Eigen::VectorXd>::set_point(index, point.data(), new_time);
}

template<typename DurationT>
inline bool CartesianTrajectory::set_points(
const std::vector<CartesianState>& points,
const std::vector<std::chrono::duration<int64_t, DurationT>>& new_times) {
if (points.empty()) {
return false;
}
std::string candidate_reference_frame = points[0].get_reference_frame();

std::vector<Eigen::VectorXd> data;
for (const auto& point : points) {
if (point.is_empty() || (point.get_reference_frame() != candidate_reference_frame)) {
return false;
}
data.push_back(point.data());
}
if (this->TrajectoryBase<Eigen::VectorXd>::set_points(data, new_times)) {
reference_frame_ = candidate_reference_frame;
return true;
} else {
return false;
}
}

}// namespace state_representation
Original file line number Diff line number Diff line change
@@ -52,6 +52,27 @@ class JointTrajectory : public TrajectoryBase<Eigen::VectorXd> {
*/
const JointState get_point(unsigned int index) const;

/**
* @brief Set the trajectory point at given index
* @param index the index
* @param point the new point
* @param new_time the new time
* @return Success of the operation
*/
template<typename DurationT>
bool
set_point(unsigned int index, const JointState& point, const std::chrono::duration<int64_t, DurationT>& new_time);

/**
* @brief Set the trajectory point at given index
* @param points vector of new points
* @param new_time vector of new times
* @return Success of the operation
*/
template<typename DurationT>
bool set_points(
const std::vector<JointState>& points, const std::vector<std::chrono::duration<int64_t, DurationT>>& new_times);

/**
* @brief Operator overload for returning a single trajectory point and
* corresponding time
@@ -77,6 +98,9 @@ class JointTrajectory : public TrajectoryBase<Eigen::VectorXd> {
template<typename DurationT>
inline bool
JointTrajectory::add_point(const JointState& new_point, const std::chrono::duration<int64_t, DurationT>& new_time) {
if (new_point.is_empty()) {
return false;
}
if (this->get_size() == 0) {
this->joint_names_ = new_point.get_names();
this->robot_name_ = new_point.get_name();
@@ -90,6 +114,9 @@ JointTrajectory::add_point(const JointState& new_point, const std::chrono::durat
template<typename DurationT>
inline bool JointTrajectory::insert_point(
const JointState& new_point, const std::chrono::duration<int64_t, DurationT>& new_time, int pos) {
if (new_point.is_empty()) {
return false;
}
if (this->get_size() == 0) {
this->joint_names_ = new_point.get_names();
this->robot_name_ = new_point.get_name();
@@ -99,4 +126,39 @@ inline bool JointTrajectory::insert_point(
this->TrajectoryBase<Eigen::VectorXd>::insert_point(new_point.data(), new_time, pos);
return true;
}

template<typename DurationT>
inline bool JointTrajectory::set_point(
unsigned int index, const JointState& point, const std::chrono::duration<int64_t, DurationT>& new_time) {
if (point.is_empty() || (point.get_names() != this->joint_names_) || (point.get_name() != this->robot_name_)) {
return false;
}
return this->TrajectoryBase<Eigen::VectorXd>::set_point(index, point.data(), new_time);
}

template<typename DurationT>
inline bool JointTrajectory::set_points(
const std::vector<JointState>& points, const std::vector<std::chrono::duration<int64_t, DurationT>>& new_times) {
if (points.empty() || points[0].is_empty()) {
return false;
}
auto candidate_robot_name = points[0].get_name();
auto candidate_joint_names = points[0].get_names();

std::vector<Eigen::VectorXd> data;
for (const auto& point : points) {
if (point.is_empty() || (point.get_names() != candidate_joint_names)
|| (point.get_name() != candidate_robot_name)) {
return false;
}
data.push_back(point.data());
}
if (this->TrajectoryBase<Eigen::VectorXd>::set_points(data, new_times)) {
this->joint_names_ = candidate_joint_names;
this->robot_name_ = candidate_robot_name;
return true;
} else {
return false;
}
}
}// namespace state_representation
Original file line number Diff line number Diff line change
@@ -81,6 +81,27 @@ class TrajectoryBase : public State {
*/
TrajectoryT& get_point(unsigned int index);

/**
* @brief Set the trajectory point at given index
* @param index the index
* @param point the new point
* @param new_time the new time
* @return Success of the operation
*/
template<typename DurationT>
bool
set_point(unsigned int index, const TrajectoryT& point, const std::chrono::duration<int64_t, DurationT>& new_time);

/**
* @brief Set the trajectory point at given index
* @param points vector of new points
* @param new_time vector of new times
* @return Success of the operation
*/
template<typename DurationT>
bool set_points(
const std::vector<TrajectoryT>& points, const std::vector<std::chrono::duration<int64_t, DurationT>>& new_times);

/**
* @brief Operator overload for returning a single trajectory point and
* corresponding time
@@ -95,27 +116,27 @@ class TrajectoryBase : public State {
};

template<typename TrajectoryT>
TrajectoryBase<TrajectoryT>::TrajectoryBase() : State() {
inline TrajectoryBase<TrajectoryT>::TrajectoryBase() : State() {
this->set_type(StateType::NONE);
this->reset();
}

template<typename TrajectoryT>
TrajectoryBase<TrajectoryT>::TrajectoryBase(const std::string& name) : State(name) {
inline TrajectoryBase<TrajectoryT>::TrajectoryBase(const std::string& name) : State(name) {
this->set_type(StateType::NONE);
this->reset();
}

template<typename TrajectoryT>
void TrajectoryBase<TrajectoryT>::reset() {
inline void TrajectoryBase<TrajectoryT>::reset() {
this->State::reset();
this->points_.clear();
this->times_.clear();
}

template<typename TrajectoryT>
template<typename DurationT>
void TrajectoryBase<TrajectoryT>::add_point(
inline void TrajectoryBase<TrajectoryT>::add_point(
const TrajectoryT& new_point, const std::chrono::duration<int64_t, DurationT>& new_time) {
this->set_empty(false);
this->points_.push_back(new_point);
@@ -130,7 +151,7 @@ void TrajectoryBase<TrajectoryT>::add_point(

template<typename TrajectoryT>
template<typename DurationT>
void TrajectoryBase<TrajectoryT>::insert_point(
inline void TrajectoryBase<TrajectoryT>::insert_point(
const TrajectoryT& new_point, const std::chrono::duration<int64_t, DurationT>& new_time, int pos) {
this->set_empty(false);

@@ -150,7 +171,7 @@ void TrajectoryBase<TrajectoryT>::insert_point(
}

template<typename TrajectoryT>
void TrajectoryBase<TrajectoryT>::delete_point() {
inline void TrajectoryBase<TrajectoryT>::delete_point() {
this->set_empty(false);
if (!this->points_.empty()) {
this->points_.pop_back();
@@ -161,7 +182,7 @@ void TrajectoryBase<TrajectoryT>::delete_point() {
}

template<typename TrajectoryT>
void TrajectoryBase<TrajectoryT>::clear() {
inline void TrajectoryBase<TrajectoryT>::clear() {
this->points_.clear();
this->times_.clear();
}
@@ -172,32 +193,66 @@ inline const std::deque<TrajectoryT>& TrajectoryBase<TrajectoryT>::get_points()
}

template<typename TrajectoryT>
const TrajectoryT& TrajectoryBase<TrajectoryT>::get_point(unsigned int index) const {
inline const TrajectoryT& TrajectoryBase<TrajectoryT>::get_point(unsigned int index) const {
return this->points_[index];
}

template<typename TrajectoryT>
TrajectoryT& TrajectoryBase<TrajectoryT>::get_point(unsigned int index) {
inline TrajectoryT& TrajectoryBase<TrajectoryT>::get_point(unsigned int index) {
return this->points_[index];
}

template<typename TrajectoryT>
template<typename DurationT>
inline bool TrajectoryBase<TrajectoryT>::set_point(
unsigned int index, const TrajectoryT& point, const std::chrono::duration<int64_t, DurationT>& new_time) {
if (index < this->points_.size()) {
this->points_[index] = point;
if (index == 0) {
this->times_[index] = new_time;
} else {
this->times_[index] = this->times_[index - 1] + new_time;
}
for (unsigned int i = index + 1; i < this->points_.size(); ++i) {
this->times_[i] += this->times_[index - 1];
}
return true;
}
return false;
}

template<typename TrajectoryT>
template<typename DurationT>
inline bool TrajectoryBase<TrajectoryT>::set_points(
const std::vector<TrajectoryT>& points, const std::vector<std::chrono::duration<int64_t, DurationT>>& new_times) {
if (points.size() != new_times.size()) {
return false;
}
this->clear();
for (unsigned int i = 0; i < points.size(); ++i) {
this->add_point(points[i], new_times[i]);
}
return true;
}

template<typename TrajectoryT>
inline const std::deque<std::chrono::nanoseconds>& TrajectoryBase<TrajectoryT>::get_times() const {
return this->times_;
}

template<typename TrajectoryT>
int TrajectoryBase<TrajectoryT>::get_size() const {
inline int TrajectoryBase<TrajectoryT>::get_size() const {
return this->points_.size();
}

template<typename TrajectoryT>
const std::pair<TrajectoryT, std::chrono::nanoseconds> TrajectoryBase<TrajectoryT>::operator[](unsigned int idx) const {
inline const std::pair<TrajectoryT, std::chrono::nanoseconds>
TrajectoryBase<TrajectoryT>::operator[](unsigned int idx) const {
return std::make_pair(this->points_[idx], this->times_[idx]);
}

template<typename TrajectoryT>
std::pair<TrajectoryT, std::chrono::nanoseconds> TrajectoryBase<TrajectoryT>::operator[](unsigned int idx) {
inline std::pair<TrajectoryT, std::chrono::nanoseconds> TrajectoryBase<TrajectoryT>::operator[](unsigned int idx) {
this->set_empty(false);
return std::make_pair(this->points_[idx], this->times_[idx]);
}