5#include "state_representation/State.hpp"
11 std::deque<StateT> points_;
12 std::deque<std::chrono::nanoseconds> times_;
13 std::string reference_frame_;
14 std::vector<std::string> joint_names_;
61 template<
typename DurationT>
62 void add_point(
const StateT& new_point,
const std::chrono::duration<int64_t, DurationT>& new_time);
67 template<
typename DurationT>
68 void insert_point(
const StateT& new_point,
const std::chrono::duration<int64_t, DurationT>& new_time,
int pos);
89 const StateT&
get_point(
unsigned int index)
const;
100 const std::deque<std::chrono::nanoseconds>&
get_times()
const;
110 const std::pair<StateT, std::chrono::nanoseconds>
operator[](
unsigned int idx)
const;
115 std::pair<StateT, std::chrono::nanoseconds>
operator[](
unsigned int idx);
119template<
class StateT>
125template<
class StateT>
128 reference_frame_(
"") {
132template<
class StateT>
134 return this->reference_frame_;
137template<
class StateT>
139 this->reference_frame_ = reference_frame;
142template<
class StateT>
144 return this->joint_names_;
147template<
class StateT>
149 this->joint_names_.resize(nb_joints);
150 for (
unsigned int i = 0; i < nb_joints; i++) {
151 this->joint_names_[i] =
"joint_" + std::to_string(i + 1);
155template<
class StateT>
157 this->joint_names_ = joint_names;
160template<
class StateT>
163 this->points_.clear();
164 this->times_.clear();
167template<
class StateT>
168template<
typename DurationT>
171 this->points_.push_back(new_point);
173 if (!this->times_.empty()) {
174 auto const previous_time = this->times_.back();
175 this->times_.push_back(previous_time + new_time);
177 this->times_.push_back(new_time);
181template<
class StateT>
182template<
typename DurationT>
184 const std::chrono::duration<int64_t, DurationT>& new_time,
188 auto it_points = this->points_.begin();
189 auto it_times = this->times_.begin();
190 std::advance(it_points, pos);
191 std::advance(it_times, pos);
193 this->points_.insert(it_points, new_point);
195 auto previous_time = this->times_[pos - 1];
196 this->times_.insert(it_times, previous_time + new_time);
198 for (
unsigned int i = pos + 1; i <= this->points_.size(); i++) {
199 this->times_[i] += new_time;
203template<
class StateT>
206 if (!this->points_.empty()) {
207 this->points_.pop_back();
209 if (!this->times_.empty()) {
210 this->times_.pop_back();
214template<
class StateT>
216 this->points_.clear();
217 this->times_.clear();
220template<
class StateT>
222 return this->points_;
225template<
class StateT>
227 return this->points_[index];
230template<
class StateT>
232 return this->points_[index];
235template<
class StateT>
240template<
class StateT>
242 return this->points_.size();
245template<
class StateT>
247 return std::make_pair(this->points_[idx], this->times_[idx]);
250template<
class StateT>
253 return std::make_pair(this->points_[idx], this->times_[idx]);
Abstract class to represent a state.
virtual void initialize()
Initialize the State to a zero value.
virtual void set_reference_frame(const std::string &reference_frame)
Setter of the reference frame.
void initialize()
Initialize trajectory.
const std::vector< std::string > & get_joint_names() const
Getter of the names attribute.
void set_joint_names(unsigned int nb_joints)
Setter of the names attribute from the number of joints.
const StateT & get_point(unsigned int index) const
Get the trajectory point at given index.
void delete_point()
Delete last point and corresponding time from trajectory.
const std::deque< std::chrono::nanoseconds > & get_times() const
Get attribute list of trajectory times.
const std::pair< StateT, std::chrono::nanoseconds > operator[](unsigned int idx) const
Operator overload for returning a single trajectory point and corresponding time.
void insert_point(const StateT &new_point, const std::chrono::duration< int64_t, DurationT > &new_time, int pos)
Insert new point and corresponding time to trajectory between two already existing points.
int get_size() const
Get attribute number of point in trajectory.
const std::deque< StateT > & get_points() const
Get attribute list of trajectory points.
Trajectory()
Empty constructor.
void add_point(const StateT &new_point, const std::chrono::duration< int64_t, DurationT > &new_time)
Add new point and corresponding time to trajectory.
const std::string get_reference_frame() const
Getter of the reference frame as const reference.
void clear()
Clear trajectory.
Core state variables and objects.
StateType
The class types inheriting from State.