klampt.model.trajectory module

Classes for loading, saving, evaluating, and operating on trajectories.

Classes:

GeodesicHermiteTrajectory(geodesic[, times, …])

A trajectory that performs Hermite interpolation on a GeodesicSpace using the DeCastlejau algorithm.

GeodesicTrajectory(geodesic[, times, milestones])

A trajectory that performs interpolation on a GeodesicSpace.

HermiteTrajectory([times, milestones, …])

A trajectory that performs cubic interpolation between prescribed segment endpoints and velocities.

RobotTrajectory(robot[, times, milestones])

A trajectory that performs interpolation according to the robot’s interpolation scheme.

SE3HermiteTrajectory([times, milestones, …])

A trajectory that performs Bezier interpolation in SE3.

SE3Trajectory([times, milestones])

A trajectory that performs interpolation in SE3.

SO3HermiteTrajectory([times, milestones, …])

A trajectory that performs Hermite interpolation in SO3.

SO3Trajectory([times, milestones])

A trajectory that performs interpolation in SO3.

Trajectory([times, milestones])

A basic piecewise-linear trajectory class, which can be overloaded to provide different functionality.

Functions:

execute_path(path, controller[, speed, …])

Sends an untimed trajectory to a controller.

execute_trajectory(trajectory, controller[, …])

Sends a timed trajectory to a controller.

path_to_trajectory(path[, velocities, …])

Converts an untimed path to a timed trajectory.

class klampt.model.trajectory.GeodesicHermiteTrajectory(geodesic, times=None, milestones=None, outgoingLieDerivatives=None)[source]

Bases: klampt.model.trajectory.Trajectory

A trajectory that performs Hermite interpolation on a GeodesicSpace using the DeCastlejau algorithm.

The milestones are a concatenation of the segment start point and the outgoing Lie derivatives w.r.t. t. The incoming Lie derivative at the segment end point is assumed to be the negative of the outgoing Lie derivative.

Parameters
  • geodesic (GeodesicSpace) – the underlying space

  • times (list of floats, optional) – the knot points defining each segment

  • milestones (list of lists, optional) – the points at the ends of each segment

  • outgoingLieDerivatives (list of lists, optional) – the Lie derivatives (velocities) at the ends of each segment.

Possible constructor options are:

  • GeodesicHermiteTrajectory(geodesic): empty trajectory

  • GeodesicHermiteTrajectory(geodesic,times,milestones): milestones contains 2N-D lists consisting of the concatenation of a point and its outgoing Lie derivative.

  • GeodesicHermiteTrajectory(geodesic,times,milestones,lieDerivatives): milestones and lieDerivatives contain N-D lists defining the points and outgoing Lie derivatives.

Note: the curve is assumed to be smooth. To make a non-smooth curve, duplicate the knot point and milestone, but set a different Lie derivative at the copy.

Parameters
  • times (list of floats, optional) – if provided, initializes the self.times attribute. If milestones is provided, a uniform timing is set. Otherwise self.times is empty.

  • milestones (list of Configs, optional) – if provided, initializes the self.milestones attribute. Otherwise milestones is empty.

Does not perform error checking. The caller must be sure that the lists have the same size, the times are non-decreasing, and the configs are equally-sized (you can call checkValid() for this).

Methods:

checkValid()

Checks whether this is a valid trajectory, raises a ValueError if not.

constructor()

Returns a “standard” constructor for the split / concat routines.

deriv(t[, endBehavior])

Returns the velocity at time t

difference_state(a, b, u, dt)

Subclasses can override this to implement non-Cartesian spaces.

discretize(dt)

Creates a discretized piecewise-geodesic (GeodesicTrajectory) approximation of this curve in config space, with resolution dt.

eval(t[, endBehavior])

Evaluates the configuration at time t

eval_state(t[, endBehavior])

Returns the (configuration,velocity) state at time t.

extractDofs(dofs)

Invalid for GeodesicHermiteTrajectory.

interpolate_state(a, b, u, dt)

Can override this to implement non-cartesian spaces.

length()

Returns an upper bound on length given by the Bezier property.

makeBezier(times, controlPoints)

Sets up this spline to perform Bezier interpolation of the given control points, with segment 0 a Bezier curve on cps[0:3], segment 1 a Bezier curve on cps[3:6], etc.

makeSpline(waypointTrajectory[, loop])

Creates a spline from a set of waypoints, with smooth interpolation between waypoints.

stackDofs(trajs[, strict])

Stacks the degrees of freedom of multiple trajectories together.

waypoint(state)

Returns the primary configuration corresponding to the given state.

checkValid()[source]

Checks whether this is a valid trajectory, raises a ValueError if not.

constructor()[source]

Returns a “standard” constructor for the split / concat routines. The result should be a function that takes two arguments: a list of times and a list of milestones.

deriv(t, endBehavior='halt')[source]

Returns the velocity at time t

difference_state(a, b, u, dt)[source]

Subclasses can override this to implement non-Cartesian spaces. Returns the time derivative along the geodesic from b to a. dt is the duration of the segment form a to b

discretize(dt)[source]

Creates a discretized piecewise-geodesic (GeodesicTrajectory) approximation of this curve in config space, with resolution dt.

eval(t, endBehavior='halt')[source]

Evaluates the configuration at time t

eval_state(t, endBehavior='halt')[source]

Returns the (configuration,velocity) state at time t.

extractDofs(dofs)[source]

Invalid for GeodesicHermiteTrajectory.

interpolate_state(a, b, u, dt)[source]

Can override this to implement non-cartesian spaces. Interpolates along the geodesic from a to b. dt is the duration of the segment from a to b

length()[source]

Returns an upper bound on length given by the Bezier property. Faster than calculating the true length. To retrieve an approximation of true length, use self.discretize(dt).length().

makeBezier(times, controlPoints)[source]

Sets up this spline to perform Bezier interpolation of the given control points, with segment 0 a Bezier curve on cps[0:3], segment 1 a Bezier curve on cps[3:6], etc.

makeSpline(waypointTrajectory, loop=False)[source]

Creates a spline from a set of waypoints, with smooth interpolation between waypoints.

stackDofs(trajs, strict=True)[source]

Stacks the degrees of freedom of multiple trajectories together. The result is contained in self.

All evaluations are assumed to take place with the ‘halt’ endBehavior.

Parameters
  • trajs (list or tuple of Trajectory) – the trajectories to stack

  • strict (bool, optional) – if True, will warn if the classes of the trajectories do not match self.

Returns

None

waypoint(state)[source]

Returns the primary configuration corresponding to the given state.

This is usually the same as state but for some trajectories, specifically Hermite curves, the state and configuration are not identically the same.

class klampt.model.trajectory.GeodesicTrajectory(geodesic, times=None, milestones=None)[source]

Bases: klampt.model.trajectory.Trajectory

A trajectory that performs interpolation on a GeodesicSpace. See klampt.math.geodesic for more information.

Parameters
  • times (list of floats, optional) – if provided, initializes the self.times attribute. If milestones is provided, a uniform timing is set. Otherwise self.times is empty.

  • milestones (list of Configs, optional) – if provided, initializes the self.milestones attribute. Otherwise milestones is empty.

Does not perform error checking. The caller must be sure that the lists have the same size, the times are non-decreasing, and the configs are equally-sized (you can call checkValid() for this).

Methods:

checkValid()

Checks whether this is a valid trajectory, raises a ValueError if not.

constructor()

Returns a “standard” constructor for the split / concat routines.

difference_state(a, b, u, dt)

Subclasses can override this to implement non-Cartesian spaces.

extractDofs(dofs)

Invalid for GeodesicTrajectory.

interpolate_state(a, b, u, dt)

Can override this to implement non-cartesian spaces.

length([metric])

Returns the arc-length of the trajectory, according to the given metric.

stackDofs(trajs)

Stacks the degrees of freedom of multiple trajectories together.

checkValid()[source]

Checks whether this is a valid trajectory, raises a ValueError if not.

constructor()[source]

Returns a “standard” constructor for the split / concat routines. The result should be a function that takes two arguments: a list of times and a list of milestones.

difference_state(a, b, u, dt)[source]

Subclasses can override this to implement non-Cartesian spaces. Returns the time derivative along the geodesic from b to a. dt is the duration of the segment form a to b

extractDofs(dofs)[source]

Invalid for GeodesicTrajectory.

interpolate_state(a, b, u, dt)[source]

Can override this to implement non-cartesian spaces. Interpolates along the geodesic from a to b. dt is the duration of the segment from a to b

length(metric=None)[source]

Returns the arc-length of the trajectory, according to the given metric.

If metric = None, uses the “natural” metric for this trajectory, which is usually Euclidean. Otherwise it is a function f(a,b) from configurations to nonnegative numbers.

stackDofs(trajs)[source]

Stacks the degrees of freedom of multiple trajectories together. The result is contained in self.

All evaluations are assumed to take place with the ‘halt’ endBehavior.

Parameters
  • trajs (list or tuple of Trajectory) – the trajectories to stack

  • strict (bool, optional) – if True, will warn if the classes of the trajectories do not match self.

Returns

None

class klampt.model.trajectory.HermiteTrajectory(times=None, milestones=None, dmilestones=None)[source]

Bases: klampt.model.trajectory.Trajectory

A trajectory that performs cubic interpolation between prescribed segment endpoints and velocities.

The milestones (states) are given in phase space (x,dx).

eval(t) returns the primary configuration x, and deriv(t) returns the velocity dx. To get acceleration, use accel(t). To get the state space (x,dx), use eval_state(t).

Parameters
  • times (list of float, optional) – the knot points

  • milestones (list of lists, optional) – the milestones met at the knot points.

  • dmilestones (list of lists, optional) – the velocities (derivatives w.r.t time) at each knot point.

Possible constructor options are:

  • HermiteTrajectory(): empty trajectory

  • HermiteTrajectory(times,milestones): milestones contains 2N-D lists consisting of the concatenation of a point and its outgoing velocity.

  • HermiteTrajectory(times,milestones,dmilestones): milestones and dmilestones each contain N-D lists defining the points and outgoing velocities.

Note: the curve is assumed to be smooth. To make a non-smooth curve, duplicate the knot point and milestone, but set a different velocity at the copy.

Parameters
  • times (list of floats, optional) – if provided, initializes the self.times attribute. If milestones is provided, a uniform timing is set. Otherwise self.times is empty.

  • milestones (list of Configs, optional) – if provided, initializes the self.milestones attribute. Otherwise milestones is empty.

Does not perform error checking. The caller must be sure that the lists have the same size, the times are non-decreasing, and the configs are equally-sized (you can call checkValid() for this).

Methods:

checkValid()

Checks whether this is a valid trajectory, raises a ValueError if not.

constructor()

Returns a “standard” constructor for the split / concat routines.

deriv(t[, endBehavior])

Returns just the velocity component of the result

difference_state(a, b, u, dt)

Subclasses can override this to implement non-Cartesian spaces.

discretize(dt)

Creates a discretized piecewise linear Trajectory in config space that approximates this curve with resolution dt.

eval(t[, endBehavior])

Returns just the configuration component of the result

eval_accel(t[, endBehavior])

Returns just the acceleration component of the derivative

eval_state(t[, endBehavior])

Returns the (configuration,velocity) state at time t.

extractDofs(dofs)

Returns a trajectory just over the given DOFs.

interpolate_state(a, b, u, dt)

Can override this to implement non-cartesian spaces.

length()

Returns an upper bound on length given by the Bezier property.

makeBezier(times, controlPoints)

Sets up this spline to perform Bezier interpolation of the given control points, with segment 0 a Bezier curve on cps[0:3], segment 1 a Bezier curve on cps[3:6], etc.

makeMinTimeSpline(milestones[, velocities, …])

Creates a spline that interpolates between the given milestones with bounded velocities, accelerations, and positions.

makeSpline(waypointTrajectory[, …])

Computes natural velocities for a standard configuration- space Trajectory to make it smoother.

stackDofs(trajs[, strict])

Stacks the degrees of freedom of multiple trajectories together.

waypoint(state)

Returns the primary configuration corresponding to the given state.

checkValid()[source]

Checks whether this is a valid trajectory, raises a ValueError if not.

constructor()[source]

Returns a “standard” constructor for the split / concat routines. The result should be a function that takes two arguments: a list of times and a list of milestones.

deriv(t, endBehavior='halt')[source]

Returns just the velocity component of the result

difference_state(a, b, u, dt)[source]

Subclasses can override this to implement non-Cartesian spaces. Returns the time derivative along the geodesic from b to a. dt is the duration of the segment form a to b

discretize(dt)[source]

Creates a discretized piecewise linear Trajectory in config space that approximates this curve with resolution dt.

eval(t, endBehavior='halt')[source]

Returns just the configuration component of the result

eval_accel(t, endBehavior='halt')[source]

Returns just the acceleration component of the derivative

eval_state(t, endBehavior='halt')[source]

Returns the (configuration,velocity) state at time t.

extractDofs(dofs)[source]

Returns a trajectory just over the given DOFs.

Parameters
  • dofs (list of int) – the (primary) indices to extract. Each entry

  • be < len (must) –

Returns

a copy of this trajectory but only over the given DOFs.

Return type

HermiteTrajectory

interpolate_state(a, b, u, dt)[source]

Can override this to implement non-cartesian spaces. Interpolates along the geodesic from a to b. dt is the duration of the segment from a to b

length()[source]

Returns an upper bound on length given by the Bezier property. Faster than calculating the true length. To retrieve an approximation of true length, use self.discretize(dt).length().

makeBezier(times, controlPoints)[source]

Sets up this spline to perform Bezier interpolation of the given control points, with segment 0 a Bezier curve on cps[0:3], segment 1 a Bezier curve on cps[3:6], etc.

makeMinTimeSpline(milestones, velocities=None, xmin=None, xmax=None, vmax=None, amax=None)[source]

Creates a spline that interpolates between the given milestones with bounded velocities, accelerations, and positions.

If velocities==None, this requires the spline to move in a straight configuration-space path between the given milestones. This option is helpful for postprocessing the results for kinematic motion planning, for example.

makeSpline(waypointTrajectory, preventOvershoot=True, loop=False)[source]

Computes natural velocities for a standard configuration- space Trajectory to make it smoother.

stackDofs(trajs, strict=True)[source]

Stacks the degrees of freedom of multiple trajectories together. The result is contained in self.

All evaluations are assumed to take place with the ‘halt’ endBehavior.

Parameters
  • trajs (list or tuple of HermiteTrajectory) – the trajectories to stack

  • strict (bool, optional) – ignored. Will always warn for invalid classes.

Returns

None

waypoint(state)[source]

Returns the primary configuration corresponding to the given state.

This is usually the same as state but for some trajectories, specifically Hermite curves, the state and configuration are not identically the same.

class klampt.model.trajectory.RobotTrajectory(robot, times=None, milestones=None)[source]

Bases: klampt.model.trajectory.Trajectory

A trajectory that performs interpolation according to the robot’s interpolation scheme.

Parameters
  • robot (RobotModel or SubRobotModel) – the robot whose configuration should follow this trajectory.

  • times (list of floats, optional) – if provided, initializes the self.times attribute. If milestones is provided, a uniform timing is set. Otherwise self.times is empty.

  • milestones (list of Configs, optional) – if provided, initializes the self.milestones attribute. Otherwise milestones is empty.

Methods:

checkValid()

Checks whether this is a valid trajectory, raises a ValueError if not.

constructor()

Returns a “standard” constructor for the split / concat routines.

difference_state(a, b, u, dt)

Subclasses can override this to implement non-Cartesian spaces.

extractDofs(dofs)

Returns a RobotTrajectory just over the given DOFs.

getLinkTrajectory(link[, discretization])

Returns the SE3Trajectory corresponding to the link’s pose along the robot’s trajectory.

interpolate_state(a, b, u, dt)

Can override this to implement non-cartesian spaces.

length([metric])

Returns the arc-length of the trajectory, according to the given metric.

stackDofs(trajs)

Stacks the degrees of freedom of multiple trajectories together.

checkValid()[source]

Checks whether this is a valid trajectory, raises a ValueError if not.

constructor()[source]

Returns a “standard” constructor for the split / concat routines. The result should be a function that takes two arguments: a list of times and a list of milestones.

difference_state(a, b, u, dt)[source]

Subclasses can override this to implement non-Cartesian spaces. Returns the time derivative along the geodesic from b to a. dt is the duration of the segment form a to b

extractDofs(dofs)[source]

Returns a RobotTrajectory just over the given DOFs.

Parameters

dofs (list of int or str) – the indices to extract

Returns

a copy of this trajectory but over a SubRobotModel.

Return type

RobotTrajectory

getLinkTrajectory(link, discretization=None)[source]

Returns the SE3Trajectory corresponding to the link’s pose along the robot’s trajectory. If discretization = None, only the milestones are extracted. Otherwise, the piecewise linear approximation at dt = discretization is used.

interpolate_state(a, b, u, dt)[source]

Can override this to implement non-cartesian spaces. Interpolates along the geodesic from a to b. dt is the duration of the segment from a to b

length(metric=None)[source]

Returns the arc-length of the trajectory, according to the given metric.

If metric = None, uses the “natural” metric for this trajectory, which is usually Euclidean. Otherwise it is a function f(a,b) from configurations to nonnegative numbers.

stackDofs(trajs)[source]

Stacks the degrees of freedom of multiple trajectories together. The result is contained in self.

All evaluations are assumed to take place with the ‘halt’ endBehavior.

Parameters
  • trajs (list or tuple of Trajectory) – the trajectories to stack

  • strict (bool, optional) – if True, will warn if the classes of the trajectories do not match self.

Returns

None

class klampt.model.trajectory.SE3HermiteTrajectory(times=None, milestones=None, outgoingLieDerivatives=None)[source]

Bases: klampt.model.trajectory.GeodesicHermiteTrajectory

A trajectory that performs Bezier interpolation in SE3. Each milestone is 24-D, consisting of a 12-D flattened klampt.math.se3 element and its subsequent Lie derivative.

Parameters
  • times (list of floats, optional) – if provided, initializes the self.times attribute. If milestones is provided, a uniform timing is set. Otherwise self.times is empty.

  • milestones (list of Configs, optional) – if provided, initializes the self.milestones attribute. Otherwise milestones is empty.

Does not perform error checking. The caller must be sure that the lists have the same size, the times are non-decreasing, and the configs are equally-sized (you can call checkValid() for this).

Methods:

constructor()

Returns a “standard” constructor for the split / concat routines.

deriv(t[, endBehavior])

Returns the derivative as the derivatives of an SE3 element

deriv_screw(t[, endBehavior])

Returns the derivative at t, in screw vector form, that is, a 6D vector (angular velocity, velocity).

discretize(dt)

Creates a discretized piecewise-geodesic (GeodesicTrajectory) approximation of this curve in config space, with resolution dt.

eval(t[, endBehavior])

Returns an SE3 element

from_se3(T)

Converts a klampt.se3 element to a state parameter vector

postTransform(T)

Postmultiplies every transform in here by the se3 element R.

preTransform(T)

Premultiplies every transform in here by the se3 element T.

to_se3(state)

Converts a state parameter vector to a klampt.se3 element

waypoint(state)

Returns the primary configuration corresponding to the given state.

constructor()[source]

Returns a “standard” constructor for the split / concat routines. The result should be a function that takes two arguments: a list of times and a list of milestones.

deriv(t, endBehavior='halt')[source]

Returns the derivative as the derivatives of an SE3 element

deriv_screw(t, endBehavior='halt')[source]

Returns the derivative at t, in screw vector form, that is, a 6D vector (angular velocity, velocity).

discretize(dt)[source]

Creates a discretized piecewise-geodesic (GeodesicTrajectory) approximation of this curve in config space, with resolution dt.

eval(t, endBehavior='halt')[source]

Returns an SE3 element

from_se3(T)[source]

Converts a klampt.se3 element to a state parameter vector

postTransform(T)[source]

Postmultiplies every transform in here by the se3 element R. In other words, if R rotates a local frame F to frame F’, this method converts this SO3Trajectory from describing how F’ rotates to how F rotates.

preTransform(T)[source]

Premultiplies every transform in here by the se3 element T. In other words, if T transforms a local frame F to frame F’, this method converts this SE3HermiteTrajectory from coordinates in F to coordinates in F’

to_se3(state)[source]

Converts a state parameter vector to a klampt.se3 element

waypoint(state)[source]

Returns the primary configuration corresponding to the given state.

This is usually the same as state but for some trajectories, specifically Hermite curves, the state and configuration are not identically the same.

class klampt.model.trajectory.SE3Trajectory(times=None, milestones=None)[source]

Bases: klampt.model.trajectory.GeodesicTrajectory

A trajectory that performs interpolation in SE3. Each milestone (state) is a 12-D flattened klampt.math.se3 element (i.e., the concatenation of R + t for an (R,t) pair).

Constructor can take either a list of SE3 elements or 12-element vectors.

Methods:

checkValid()

Checks whether this is a valid trajectory, raises a ValueError if not.

constructor()

Returns a “standard” constructor for the split / concat routines.

deriv(t[, endBehavior])

Returns the derivative as the derivatives of an SE3 element

deriv_screw(t[, endBehavior])

Returns the derivative at t, in screw form, that is, a 6D (angular velocity,velocity) vector.

eval(t[, endBehavior])

Returns an SE3 element

extractDofs(dofs)

Invalid for GeodesicTrajectory.

from_se3(T)

Converts a klampt.se3 element to a state parameter vector

getPositionTrajectory([localPt])

Returns a Trajectory describing the movement of the given local point localPt (or the origin, if none is provided).

getRotationTrajectory()

Returns an SO3Trajectory describing the rotation trajectory.

postTransform(T)

Postmultiplies every transform in self by the se3 element T.

preTransform(T)

Premultiplies every transform in self by the se3 element T.

to_se3(state)

Converts a state parameter vector to a klampt.se3 element

waypoint(state)

Returns the primary configuration corresponding to the given state.

checkValid()[source]

Checks whether this is a valid trajectory, raises a ValueError if not.

constructor()[source]

Returns a “standard” constructor for the split / concat routines. The result should be a function that takes two arguments: a list of times and a list of milestones.

deriv(t, endBehavior='halt')[source]

Returns the derivative as the derivatives of an SE3 element

deriv_screw(t, endBehavior='halt')[source]

Returns the derivative at t, in screw form, that is, a 6D (angular velocity,velocity) vector.

eval(t, endBehavior='halt')[source]

Returns an SE3 element

extractDofs(dofs)[source]

Invalid for GeodesicTrajectory.

from_se3(T)[source]

Converts a klampt.se3 element to a state parameter vector

getPositionTrajectory(localPt=None)[source]

Returns a Trajectory describing the movement of the given local point localPt (or the origin, if none is provided).

getRotationTrajectory()[source]

Returns an SO3Trajectory describing the rotation trajectory.

postTransform(T)[source]

Postmultiplies every transform in self by the se3 element T. In other words, if T transforms a local frame F to frame F’, this method converts this SE3Trajectory from describing how F’ moves to how F moves.

preTransform(T)[source]

Premultiplies every transform in self by the se3 element T. In other words, if T transforms a local frame F to frame F’, this method converts this SE3Trajectory from coordinates in F to coordinates in F’

to_se3(state)[source]

Converts a state parameter vector to a klampt.se3 element

waypoint(state)[source]

Returns the primary configuration corresponding to the given state.

This is usually the same as state but for some trajectories, specifically Hermite curves, the state and configuration are not identically the same.

class klampt.model.trajectory.SO3HermiteTrajectory(times=None, milestones=None, outgoingLieDerivatives=None)[source]

Bases: klampt.model.trajectory.GeodesicHermiteTrajectory

A trajectory that performs Hermite interpolation in SO3. Each milestone is 18-D, consisting of a 9-D klampt.math.so3 element and its subsequent Lie derivative.

Parameters
  • times (list of floats, optional) – knot points.

  • milestones (list of Configs, optional) – list of waypoint orientations.

  • outgoingLieDerivatives (list of 9-D lists) – list of Lie derivatives, i.e. cross product matrix (cross_product()) for each angular velocity.

  • times – if provided, initializes the self.times attribute. If milestones is provided, a uniform timing is set. Otherwise self.times is empty.

  • milestones – if provided, initializes the self.milestones attribute. Otherwise milestones is empty.

Does not perform error checking. The caller must be sure that the lists have the same size, the times are non-decreasing, and the configs are equally-sized (you can call checkValid() for this).

Methods:

constructor()

Returns a “standard” constructor for the split / concat routines.

deriv_angvel(t[, endBehavior])

Returns the derivative at t, in angular velocity form

discretize(dt)

Creates a discretized piecewise-geodesic (GeodesicTrajectory) approximation of this curve in config space, with resolution dt.

postTransform(R)

Postmultiplies every rotation in here by the se3 element R.

preTransform(R)

Premultiplies every rotation in here by the so3 element R.

constructor()[source]

Returns a “standard” constructor for the split / concat routines. The result should be a function that takes two arguments: a list of times and a list of milestones.

deriv_angvel(t, endBehavior='halt')[source]

Returns the derivative at t, in angular velocity form

discretize(dt)[source]

Creates a discretized piecewise-geodesic (GeodesicTrajectory) approximation of this curve in config space, with resolution dt.

postTransform(R)[source]

Postmultiplies every rotation in here by the se3 element R. In other words, if R rotates a local frame F to frame F’, this method converts this SO3HermiteTrajectory from describing how F’ rotates to how F rotates.

preTransform(R)[source]

Premultiplies every rotation in here by the so3 element R. In other words, if R rotates a local frame F to frame F’, this method converts this SO3HermiteTrajectory from coordinates in F to coordinates in F’

class klampt.model.trajectory.SO3Trajectory(times=None, milestones=None)[source]

Bases: klampt.model.trajectory.GeodesicTrajectory

A trajectory that performs interpolation in SO3. Each milestone is a 9-D klampt.math.so3 element.

Parameters
  • times (list of floats, optional) – if provided, initializes the self.times attribute. If milestones is provided, a uniform timing is set. Otherwise self.times is empty.

  • milestones (list of Configs, optional) – if provided, initializes the self.milestones attribute. Otherwise milestones is empty.

Does not perform error checking. The caller must be sure that the lists have the same size, the times are non-decreasing, and the configs are equally-sized (you can call checkValid() for this).

Methods:

checkValid()

Checks whether this is a valid trajectory, raises a ValueError if not.

constructor()

Returns a “standard” constructor for the split / concat routines.

deriv_angvel(t[, endBehavior])

Returns the derivative at t, in angular velocity form

getPointTrajectory(localPt)

Returns a Trajectory describing the movement of the point localPt attached to this rotating frame.

postTransform(R)

Postmultiplies every rotation in here by the se3 element R.

preTransform(R)

Premultiplies every rotation in here by the so3 element R.

checkValid()[source]

Checks whether this is a valid trajectory, raises a ValueError if not.

constructor()[source]

Returns a “standard” constructor for the split / concat routines. The result should be a function that takes two arguments: a list of times and a list of milestones.

deriv_angvel(t, endBehavior='halt')[source]

Returns the derivative at t, in angular velocity form

getPointTrajectory(localPt)[source]

Returns a Trajectory describing the movement of the point localPt attached to this rotating frame.

postTransform(R)[source]

Postmultiplies every rotation in here by the se3 element R. In other words, if R rotates a local frame F to frame F’, this method converts this SO3Trajectory from describing how F’ rotates to how F rotates.

preTransform(R)[source]

Premultiplies every rotation in here by the so3 element R. In other words, if R rotates a local frame F to frame F’, this method converts this SO3Trajectory from coordinates in F to coordinates in F’

class klampt.model.trajectory.Trajectory(times=None, milestones=None)[source]

Bases: object

A basic piecewise-linear trajectory class, which can be overloaded to provide different functionality. A plain Trajectory interpolates in Cartesian space.

(To interpolate for a robot, use RobotTrajectory. To perform Hermite interpolation, use HermiteTrajectory)

times

a list of times at which the milestones are met.

Type

list of floats

milestones

a list of milestones that are interpolated.

Type

list of Configs

Parameters
  • times (list of floats, optional) – if provided, initializes the self.times attribute. If milestones is provided, a uniform timing is set. Otherwise self.times is empty.

  • milestones (list of Configs, optional) – if provided, initializes the self.milestones attribute. Otherwise milestones is empty.

Does not perform error checking. The caller must be sure that the lists have the same size, the times are non-decreasing, and the configs are equally-sized (you can call checkValid() for this).

Methods:

after(time)

Returns the part of the trajectory after the given time

before(time)

Returns the part of the trajectory before the given time

checkValid()

Checks whether this is a valid trajectory, raises a ValueError if not.

concat(suffix[, relative, jumpPolicy])

Returns a new trajectory with another trajectory concatenated onto self.

constructor()

Returns a “standard” constructor for the split / concat routines.

deriv(t[, endBehavior])

Evaluates the trajectory velocity using piecewise linear interpolation.

deriv_state(t[, endBehavior])

Internal deriv, used on the underlying state representation

difference_state(a, b, u, dt)

Subclasses can override this to implement non-Cartesian spaces.

discretize(dt)

Returns a trajectory, uniformly discretized at resolution dt, and with state-space the same as its configuration space.

discretize_state(dt)

Returns a copy of this but with uniformly defined milestones at resolution dt.

duration()

Returns the duration of the trajectory.

endTime()

Returns the final time.

eval(t[, endBehavior])

Evaluates the trajectory using piecewise linear interpolation.

eval_state(t[, endBehavior])

Internal eval, used on the underlying state representation

extractDofs(dofs)

Returns a trajectory just over the given DOFs.

getSegment(t[, endBehavior])

Returns the index and interpolation parameter for the segment at time t.

insert(time)

Inserts a milestone and keyframe at the given time.

interpolate_state(a, b, u, dt)

Can override this to implement non-cartesian spaces.

length([metric])

Returns the arc-length of the trajectory, according to the given metric.

load(fn)

Reads from a whitespace-separated file in the format.

remesh(newtimes[, tol])

Returns a path that has milestones at the times given in newtimes, as well as the current milestone times.

save(fn)

Writes to a whitespace-separated file

splice(suffix[, time, relative, jumpPolicy])

Returns a path such that the suffix is spliced in at some time

split(time)

Returns a pair of trajectories obtained from splitting this one at the given time

stackDofs(trajs[, strict])

Stacks the degrees of freedom of multiple trajectories together.

startTime()

Returns the initial time.

waypoint(state)

Returns the primary configuration corresponding to the given state.

after(time)[source]

Returns the part of the trajectory after the given time

before(time)[source]

Returns the part of the trajectory before the given time

checkValid()[source]

Checks whether this is a valid trajectory, raises a ValueError if not.

concat(suffix, relative=False, jumpPolicy='strict')[source]

Returns a new trajectory with another trajectory concatenated onto self.

Parameters
  • suffix (Trajectory) – the suffix trajectory

  • relative (bool) – If True, then the suffix’s time domain is shifted so that self.times[-1] is added on before concatenation.

  • jumpPolicy (str) –

    If the suffix starts exactly at the existing trajectory’s end time, then jumpPolicy is checked. Can be:

    • ’strict’: the suffix’s first milestone has to be equal to the existing trajectory’s last milestone. Otherwise an exception is raised.

    • ’blend’: the existing trajectory’s last milestone is discarded.

    • ’jump’: a discontinuity is added to the trajectory.

constructor()[source]

Returns a “standard” constructor for the split / concat routines. The result should be a function that takes two arguments: a list of times and a list of milestones.

deriv(t, endBehavior='halt')[source]

Evaluates the trajectory velocity using piecewise linear interpolation.

Parameters
  • t (float) – The time at which to evaluate the segment

  • endBehavior (str) – If ‘loop’ then the trajectory loops forever.

Returns

the velocity (derivative) at time t

Return type

(list of float)

deriv_state(t, endBehavior='halt')[source]

Internal deriv, used on the underlying state representation

difference_state(a, b, u, dt)[source]

Subclasses can override this to implement non-Cartesian spaces. Returns the time derivative along the geodesic from b to a. dt is the duration of the segment form a to b

discretize(dt)[source]

Returns a trajectory, uniformly discretized at resolution dt, and with state-space the same as its configuration space. Similar to discretize, but if the state space is of higher dimension (e.g., Hermite trajectories) this projects to a piecewise linear trajectory.

discretize_state(dt)[source]

Returns a copy of this but with uniformly defined milestones at resolution dt. Start and goal are maintained exactly

duration()[source]

Returns the duration of the trajectory.

endTime()[source]

Returns the final time.

eval(t, endBehavior='halt')[source]

Evaluates the trajectory using piecewise linear interpolation.

Parameters
  • t (float) – The time at which to evaluate the segment

  • endBehavior (str) – If ‘loop’ then the trajectory loops forever.

Returns

the configuration at time t

Return type

(list of float)

eval_state(t, endBehavior='halt')[source]

Internal eval, used on the underlying state representation

extractDofs(dofs)[source]

Returns a trajectory just over the given DOFs.

Parameters

dofs (list of int) – the indices to extract.

Returns

a copy of this trajectory but only over the given DOFs.

Return type

Trajectory

getSegment(t, endBehavior='halt')[source]

Returns the index and interpolation parameter for the segment at time t.

Running time is O(log n) time where n is the number of segments.

Parameters
  • t (float) – The time at which to evaluate the segment

  • endBehavior (str) – If ‘loop’ then the trajectory loops forever.

Returns

(index,param) giving the segment index and interpolation parameter. index < 0 indicates that the time is before the first milestone and/or there is only 1 milestone.

Return type

(tuple)

insert(time)[source]

Inserts a milestone and keyframe at the given time. Returns the index of the new milestone, or if a milestone already exists, then it returns that milestone index.

If the path is empty, the milestone is set to an empty list [].

interpolate_state(a, b, u, dt)[source]

Can override this to implement non-cartesian spaces. Interpolates along the geodesic from a to b. dt is the duration of the segment from a to b

length(metric=None)[source]

Returns the arc-length of the trajectory, according to the given metric.

If metric = None, uses the “natural” metric for this trajectory, which is usually Euclidean. Otherwise it is a function f(a,b) from configurations to nonnegative numbers.

load(fn)[source]

Reads from a whitespace-separated file in the format:

t1 [q1]
t2 [q2]
...

where each [qi] is a Klamp’t formatted length-n configuration, written in the form n qi1 ... qin.

remesh(newtimes, tol=1e-06)[source]

Returns a path that has milestones at the times given in newtimes, as well as the current milestone times. Return value is (path,newtimeidx) where path is the remeshed path, and newtimeidx is a list of time indices for which path.times[newtimeidx[i]] = newtimes[i].

newtimes is an iterable over floats. It does not need to be sorted.

tol is a parameter specifying how closely the returned path must interpolate the original path. Old milestones will be dropped if they are not needed to follow the path within this tolerance.

The end behavior is assumed to be ‘halt’.

save(fn)[source]

Writes to a whitespace-separated file

splice(suffix, time=None, relative=False, jumpPolicy='strict')[source]

Returns a path such that the suffix is spliced in at some time

Parameters
  • suffix (Trajectory) – the trajectory to splice in

  • time (float, optional) – determines when the splice occurs. The suffix is spliced in at the suffix’s start time if time=None, or the given time if specified.

  • jumpPolicy (str) – if ‘strict’, then it is required that suffix(t0)=path(t0) where t0 is the absolute start time of the suffix.

split(time)[source]

Returns a pair of trajectories obtained from splitting this one at the given time

stackDofs(trajs, strict=True)[source]

Stacks the degrees of freedom of multiple trajectories together. The result is contained in self.

All evaluations are assumed to take place with the ‘halt’ endBehavior.

Parameters
  • trajs (list or tuple of Trajectory) – the trajectories to stack

  • strict (bool, optional) – if True, will warn if the classes of the trajectories do not match self.

Returns

None

startTime()[source]

Returns the initial time.

waypoint(state)[source]

Returns the primary configuration corresponding to the given state.

This is usually the same as state but for some trajectories, specifically Hermite curves, the state and configuration are not identically the same.

klampt.model.trajectory.execute_path(path, controller, speed=1.0, smoothing=None, activeDofs=None)[source]

Sends an untimed trajectory to a controller.

If smoothing = None, the path will be executed as a sequence of go-to commands, starting and stopping at each milestone. Otherwise, it will be smoothed somehow and sent to the controller as faithfully as possible.

Parameters
  • path (list of Configs) – a list of milestones

  • controller (SimRobotController) – the controller to execute the path

  • speed (float, optional) – if given, changes the execution speed of the path. Not valid with smoothing=None or ‘ramp’.

  • smoothing (str, optional) –

    any smoothing applied to the path. Valid values are:

    • None: starts / stops at each milestone, moves in linear joint-space paths. Trapezoidal velocity profile used.

    • ’linear’: interpolates milestones linearly with fixed duration. Constant velocity profile used.

    • ’cubic’: interpolates milestones with cubic spline with fixed duration. Parabolic velocity profile used. Starts/stops at each milestone.

    • ’spline’: interpolates milestones smoothly with some differenced velocity.

    • ’ramp’: starts / stops at each milestone, moves in minimum-time / minimum- acceleration paths. Trapezoidal velocity profile used.

  • activeDofs (list, optional) – if not None, a list of dofs that are moved by the trajectory. Each entry may be an integer or a string.

klampt.model.trajectory.execute_trajectory(trajectory, controller, speed=1.0, smoothing=None, activeDofs=None)[source]

Sends a timed trajectory to a controller.

Parameters
  • trajectory (Trajectory) – a Trajectory, RobotTrajectory, or HermiteTrajectory instance

  • controller (SimRobotController) – the controller to execute the trajectory

  • speed (float, optional) – modulates the speed of the path.

  • smoothing (str, optional) –

    any smoothing applied to the path. Only valid for piecewise linear trajectories. Valid values are

    • None: no smoothing, just do a piecewise linear trajectory

    • ’spline’: interpolate tangents to the curve

    • ’pause’: smoothly speed up and slow down

  • activeDofs (list, optional) – if not None, a list of dofs that are moved by the trajectory. Each entry may be an integer or a string.

klampt.model.trajectory.path_to_trajectory(path, velocities='auto', timing='limited', smoothing='spline', stoptol=None, vmax='auto', amax='auto', speed=1.0, dt=0.01, startvel=0.0, endvel=0.0, verbose=0)[source]

Converts an untimed path to a timed trajectory.

The resulting trajectory passes through each of the milestones without stopping, except for “stop” milestones. Stop milestones by default are only the first and last milestone, but if stoptol is given, then the trajectory will be stopped if the curvature of the path exceeds this value.

The first step is to assign each segment a ‘distance’ d[i] suggesting how much time it would take to traverse that much spatial distance. This distance assignment method is controlled by the timing parameter.

The second step is to smooth the spline, if smoothing=’spline’ is given (default).

The third step creates the trajectory, assigning the times and velocity profile as specified by the velocities parameter. velocities dictates how the overall velocity profile behaves from beginning to end, and basically, each profile gradually speeds up and slows down. The path length L = \(\sum_{i=1}^n d[i]\) determines the duration T of the trajectory, as follows:

  • For constant velocity profiles, T=L.

  • For trapezoidal, triangular, parabolic, and cosine, T = sqrt(L).

  • For minimum-jerk, T = L^(1/3).

The fourth step is to time scale the result to respect limits velocity / acceleration limits, if timing==’limited’ or speed==’limited’.

The fifth step is to time scale the result by speed.

Note

There are only some meaningful combinations of arguments:

  • velocities=’auto’; timing=’limited’: a generates a timed spline using a heuristic and then revises it to respect velocity and acceleration limits.

    The limited timing heuristic works best when the milestones are widely spaced.

    Be sure to specify vmax and amax if you don’t have a RobotTrajectory.

  • velocities=’auto’, trapezoidal’, ‘triangular’, ‘parabolic’, ‘cosine’, or ‘minimum-jerk’; timing=’L2’, ‘Linf’, ‘robot’, ‘sqrt-L2’, ‘sqrt-Linf’, or ‘sqrt-robot’: an entirely heuristic approach.

    The sqrt values lead to somewhat better tangents for smoothed splines with nonuniform distances between milestones.

    In these cases, vmax and amax are ignored.

  • If path uses non-Euclidean interpolation, then smoothing=None should be provided. Smoothing is not yet supported for non-Euclidean spaces (e.g., robots with special joints, SO3, SE3).

Parameters
  • path – a list of milestones, a trajectory, or a RobotTrajectory. In the latter cases, if durations = ‘path’ then the durations are extracted from the trajectory’s timing.

  • velocities (str, optional) –

    the manner in which velocities are assigned along the path. Can be:

    • ’auto’ (default): if timing is ‘limited’, this is equivalent to ‘constant’. Otherwise, this is equivalent to ‘trapezoidal’.

    • ’trapezoidal’: a trapezoidal velocity profile with max acceleration and velocity. If timing is ‘limited’, the velocity max is determined by vmax. Otherwise, the ramp up proceeds for 1/4 of the time, stays constant 1/2 of the time, and then ramps down for 1/4 of the time.

    • ’constant’: the path is executed at fixed constant velocity

    • ’triangular’: velocities are ramped up for 1/2 of the duration and then ramped back down.

    • ’parabolic’: a parabolic curve (output is a Hermite spline)

    • ’cosine’: velocities follow (1-cosine)/2

    • ’minimum-jerk’: minimum jerk velocities

    • ’optimal’: uses time scaling optimization. NOT IMPLEMENTED YET

  • timing (optional) –

    affects how path timing between milestones is normalized. Valid options are:

    • ’limited’ (default): uses the vmax, amax variables along with the velocity profile to dynamically determine the duration assigned to each segment.

    • ’uniform’: base timing between milestones is uniform (1/(|path|*speed))

    • ’path’: only valid if path is a Trajectory object. Uses the timing in path.times as the base timing.

    • ’L2’: base timing is set proportional to L2 distance between milestones

    • ’Linf’: base timing is set proportional to L-infinity distance between milestones

    • ’robot’: base timing is set proportional to robot’s distance function between milestones

    • ’sqrt-L2’, ‘sqrt-Linf’, or ‘sqrt-robot’: base timing is set proportional to the square root of the L2, Linf, or robot distance between milestones

    • a list or tuple: the base timing is given in this list

    • callable function f(a,b): sets the normalization to the function f(a,b).

  • smoothing (str, optional) – if ‘spline’, the geometric path is first smoothed before assigning times. Otherwise, the geometric path is interpreted as a piecewise linear path.

  • stoptol (float, optional) – determines how start/stop segments are determined. If None, the trajectory only pauses at the start and end of the path. If 0, it pauses at every milestone. Otherwise, it pauses if the curvature at the milestone exceeds stoptol.

  • vmax (optional) –

    only meaningful if timing==’limited’. Can be:

    • ’auto’ (default): either 1 or the robot’s joint velocity limits if a RobotTrajectory is provided

    • a positive number: the L2 norm of the derivative of the result trajectory is limited to this value

    • a list of positive floats: the element-wise derivative of the result trajectory is limited to this value

  • amax (optional) –

    only meaningful if timing==’limited’. Can be:

    • ’auto’ (default): either 4 or the robot’s joint acceleration limits if a RobotTrajectory is provided

    • a positive number: the L2 norm of the acceleration of the result trajectory is limited to this value

    • a list of positive floats: the element-wise acceleration of the result trajectory is limited to this value.

  • speed (float or str, optional) – if a float, this is a speed multiplier applied to the resulting trajectory. This can also be ‘limited’, which applies the velocity and acceleration limits.

  • dt (float, optional) – the resolution of the resulting trajectory. Default 0.01.

  • startvel (float, optional) –

    the starting velocity of the path, given as a multiplier of path[1]-path[0]. Must be nonnegative.

    Note: might not be respected for some velocity profiles.

    Warning

    NOT IMPLEMENTED YET

  • endvel (float, optional) –

    the ending velocity of the path, given as a multiplier of path[-1]-path[-2]. Must be nonnegative.

    Note: might not be respected for some velocity profiles.

    Warning

    NOT IMPLEMENTED YET

  • verbose (int, optional) – if > 0, some debug printouts will be given.

Returns

a finely-discretized, timed trajectory that is C1 continuous

and respects the limits defined in the arguments.

Return type

(Trajectory)