#include <trgen.h>
Public Member Functions | |
Trajectory (TrajectoryConstraints tc, bool _backward=false) | |
Trajectory constructor. | |
~Trajectory () | |
void | addPoint (double x, double y) |
Adds a new point to the trajectory. | |
void | addTurn (double angle) |
double | calcLength () |
Returns the length of the whole trajectory. | |
bool | prepare (Pos _initPos) |
Prepares the trajectory. | |
bool | getRefPos (double time, Pos &rp) |
Returns reference position of the trajectory at a given time. | |
Public Attributes | |
double | finalHeading |
Desired heading of the robot at the end of the trajectory. | |
bool | backward |
Private Member Functions | |
void | deleteSegments () |
bool | splitSegment (iterator &seg, double distance) |
Split a sergment and add the newly created segment to the trajectory. | |
bool | points2segments () |
Connects points by line segments. | |
void | corners2arcs () |
Converts corners in trajectory to arcs. | |
void | addTurns () |
void | calcSpeeds () |
Assigns speeds and accelerations to segments; tries to maximize speed where possible. | |
void | getSegRefPos (TrajectorySegment *seg, double time, Pos &rp) |
Returns reference position of the given segment in the trajectory and takes backward into the account. | |
Private Attributes | |
Pos | initPos |
iterator | currentSeg |
TrajectoryPoints | wayPoints |
Points, this trajectory is composed from. | |
Point * | initialPoint |
Point * | finalPoint |
TrajectoryConstraints | constr |
bool | prepared |
When a new trajectory is created (by Trajectory() constructor), addPoint() should be used to add points, the trajectory should go through. After all points are added, a call to prepare() uses these points to construct optimized trajectory and find the speeds along the trajectory. After the trajectory is prepared, you can call getRefPos(), to get the reference position at a specific time.
Definition at line 221 of file trgen.h.
Trajectory::Trajectory | ( | TrajectoryConstraints | tc, | |
bool | _backward = false | |||
) | [inline] |
Trajectory constructor.
tc | Trajectory constraints | |
_backward | Whether the trajectory should be followed in backward direction. |
bool Trajectory::splitSegment | ( | iterator & | seg, | |
double | distance | |||
) | [private] |
Split a sergment and add the newly created segment to the trajectory.
seg | Segment to split. | |
distance | Where to split. |
Definition at line 345 of file trgen.cc.
References dbgPrintf, TrajectorySegment::splitAt(), and wayPoints.
Referenced by calcSpeeds().
void Trajectory::corners2arcs | ( | ) | [private] |
void Trajectory::calcSpeeds | ( | ) | [private] |
Assigns speeds and accelerations to segments; tries to maximize speed where possible.
If necessary it also splits long segments to multiple parts with maximum acceleration/deceleration and maximal speed. The optimization is done in three passes. In the first pass, maximal speed of segments are set up (see TrajectoryConstraints::maxv, TrajectoryConstraints::maxomega, TrajectoryConstraints::maxcenacc). Then follows a forward pass, where acceleration is added to join segments with increasing maximal speeds. Finally, backward pass does almost the same by adding deceleration segments.
Finding the split point of the segment where deceleration immediately follows acceleration is based on the following calculations:
For uniformly accelerated motion, we can calculate time as function of speed:
Using this, we can express distance as a function of speed:
Then, distance traveled during acceleration () and deceleration (
) must be equal to the length of the segment
. Considering a segment with initial speed
, final speed
, and maximal speed (in the split point)
, we can derive:
Then, the length of the segment before split is:
Definition at line 563 of file trgen.cc.
References constr, dbgPrintf, initPos, splitSegment(), and Pos::v.
Referenced by prepare().
void Trajectory::getSegRefPos | ( | TrajectorySegment * | seg, | |
double | time, | |||
Pos & | rp | |||
) | [private] |
Returns reference position of the given segment in the trajectory and takes backward
into the account.
[in] | seg | Segment to get the position from. |
[in] | time | Time from the beginning of the trajectory. |
[out] | rp | Returned reference position. |
Definition at line 858 of file trgen.cc.
References backward, TrajectorySegment::getRefPos(), Pos::phi, and Pos::v.
Referenced by getRefPos().
void Trajectory::addPoint | ( | double | x, | |
double | y | |||
) | [inline] |
Adds a new point to the trajectory.
x | ||
y |
Definition at line 270 of file trgen.h.
References finalPoint, and wayPoints.
Referenced by new_goal(), and robot_trajectory_add_point().
double Trajectory::calcLength | ( | ) |
bool Trajectory::prepare | ( | Pos | _initPos | ) |
Prepares the trajectory.
It converts points added by addPoint() to line segments (Line). Then it replaces by sharp corners by arcs (see corners2arcs()), then it adds turns at the begin and end and finally it calculates speeds in the different parts of the trajectory by adding acceleration and decceleration segments (see calcSpeeds()).
_initPos | The point where the trajectory should start. Typically the current robot position. |
Definition at line 771 of file trgen.cc.
References addTurns(), calcSpeeds(), constr, corners2arcs(), currentSeg, dbgPrintf, initPos, TrajectoryConstraints::maxacc, TrajectoryConstraints::maxangacc, TrajectoryConstraints::maxcenacc, TrajectoryConstraints::maxe, TrajectoryConstraints::maxomega, TrajectoryConstraints::maxv, points2segments(), prepared, and wayPoints.
Referenced by new_goal(), and new_trajectory().
bool Trajectory::getRefPos | ( | double | time, | |
Pos & | rp | |||
) |
Returns reference position of the trajectory at a given time.
[in] | time | Time from the beginning of the trajectory. |
[out] | rp | Returned reference position. |
Definition at line 817 of file trgen.cc.
References currentSeg, getSegRefPos(), TrajectorySegment::getT1(), TrajectorySegment::getT2(), and prepared.
Referenced by trajectory_follower().
TrajectoryPoints Trajectory::wayPoints [private] |
Points, this trajectory is composed from.
Definition at line 224 of file trgen.h.
Referenced by addPoint(), corners2arcs(), points2segments(), prepare(), and splitSegment().
double Trajectory::finalHeading |
Desired heading of the robot at the end of the trajectory.
If equal to NAN
, ignored.
Definition at line 247 of file trgen.h.
Referenced by addTurns(), new_goal(), and robot_trajectory_add_final_point().