Function

Derivative

Notes

WorldPosition

1,2

WorldDirection

1,2

WorldOrientation

1,2

WorldTransform

1,2

WorldVelocity

1

WorldAngularVelocity

1

#LocalPosition

1

#LocalDirection

1

#LocalOrientation

1

Y

Y

Y

l2d[robot](q) -> R^numDrivers()

Y

ConfigInterpolate

N

qinterp[robot](a,b,u) -> R^n

Note that each call to WorldX or LocalX will recompute the forward kinematics of the robot, which can be rather expensive if many of these will be called.

Also, see the KinematicsBuilder class which creates the computational graph for a robot’s forward kinematics, which allows you to reuse subexpressions for multiple forward kinematics calls.

Classes:

 WorldPosition(link, localPos) Autodiff wrapper of the link.getWorldPosition() function as a function of robot configuration q. WorldDirection(link, localDir) Autodiff wrapper of the link.getWorldDirection() function as a function of robot configuration q. Autodiff wrapper of the link.getTransform()[0] function as a function of robot configuration q. WorldTransform(link[, localPos]) Autodiff wrapper of the link.getTransform() function as a function of robot configuration q. WorldVelocity(link, localPos) Autodiff wrapper of the link.getPointVelocity() function as a function of robot configuration q and velocity dq. Autodiff wrapper of the link.getAngularVelocity() function, as a function of robotconfiguration q and velocity dq. DriversToLinks(robot) Autodiff function to convert driver values to link values. Autodiff function to convert driver velocities to link velocities. LinksToDrivers(robot) Autodiff function to convert link values to driver values. Autodiff function to convert link velocities to driver velocities. ConfigInterpolate(robot) Autodiff wrapper of the RobotModel.interpolate function KinematicsBuilder(robot[, configuration, …]) A class that computes the entire computation graph of forward kinematics and caches it so that multiple queries are auto-diffable and share the same intermediate computations.
class klampt.math.autodiff.kinematics_ad.WorldPosition(link, localPos)[source]

Autodiff wrapper of the link.getWorldPosition() function as a function of robot configuration q.

Methods:

 Returns the number of arguments. n_in(arg) Returns the number of entries in argument #arg. Returns the number of entries in the output of the function. Evaluates the application of the function to the given (instantiated) arguments. derivative(arg, q) Returns the Jacobian of the function w.r.t. gen_derivative(arg, q) Generalized derivative that allows higher-order derivatives to be taken.
n_args()[source]

Returns the number of arguments.

n_in(arg)[source]

Returns the number of entries in argument #arg. If 1, this can either be a 1-D vector or a scalar. If -1, the function can accept a variable sized argument.

n_out()[source]

Returns the number of entries in the output of the function. If -1, this can output a variable sized argument.

eval(q)[source]

Evaluates the application of the function to the given (instantiated) arguments.

Parameters

args (list) – a list of arguments, which are either ndarrays or scalars.

derivative(arg, q)[source]

Returns the Jacobian of the function w.r.t. argument #arg.

Parameters
• arg (int) – A value from 0,…,self.n_args()-1 indicating that we wish to take $$df/dx_{arg}$$.

• args (list of ndarrays) – arguments for the function.

Returns

A numpy array of shape (self.n_out(),self.n_in(arg)). Keep in mind that even if the argument or result is a scalar, this needs to be a 2D array.

If the derivative is not implemented, raise a NotImplementedError.

If the derivative is zero, can just return 0 (the integer) regardless of the size of the result.

Return type

ndarray

gen_derivative(arg, q)[source]

Generalized derivative that allows higher-order derivatives to be taken.

Parameters
• arg (list) – Indicates the order of derivatives to be taken. For example, to take the 2nd derivative w.r.t. x0,x1, arg = [0,1] should be specified.

• args (list of ndarrays) – arguments for the function.

Returns

A tensor of shape (n_out,n_in(arg[0]),..., n_in(arg[-1]).

If the generalized derivative is not implemented, raise a NotImplementedError.

If the generalized derivative is zero, can just return 0 (the integer) regardless of the size of the result.

Return type

ndarray

class klampt.math.autodiff.kinematics_ad.WorldDirection(link, localDir)[source]

Autodiff wrapper of the link.getWorldDirection() function as a function of robot configuration q.

Methods:

 Returns the number of arguments. n_in(arg) Returns the number of entries in argument #arg. Returns the number of entries in the output of the function. Evaluates the application of the function to the given (instantiated) arguments. derivative(arg, q) Returns the Jacobian of the function w.r.t. gen_derivative(arg, q) Generalized derivative that allows higher-order derivatives to be taken.
n_args()[source]

Returns the number of arguments.

n_in(arg)[source]

Returns the number of entries in argument #arg. If 1, this can either be a 1-D vector or a scalar. If -1, the function can accept a variable sized argument.

n_out()[source]

Returns the number of entries in the output of the function. If -1, this can output a variable sized argument.

eval(q)[source]

Evaluates the application of the function to the given (instantiated) arguments.

Parameters

args (list) – a list of arguments, which are either ndarrays or scalars.

derivative(arg, q)[source]

Returns the Jacobian of the function w.r.t. argument #arg.

Parameters
• arg (int) – A value from 0,…,self.n_args()-1 indicating that we wish to take $$df/dx_{arg}$$.

• args (list of ndarrays) – arguments for the function.

Returns

A numpy array of shape (self.n_out(),self.n_in(arg)). Keep in mind that even if the argument or result is a scalar, this needs to be a 2D array.

If the derivative is not implemented, raise a NotImplementedError.

If the derivative is zero, can just return 0 (the integer) regardless of the size of the result.

Return type

ndarray

gen_derivative(arg, q)[source]

Generalized derivative that allows higher-order derivatives to be taken.

Parameters
• arg (list) – Indicates the order of derivatives to be taken. For example, to take the 2nd derivative w.r.t. x0,x1, arg = [0,1] should be specified.

• args (list of ndarrays) – arguments for the function.

Returns

A tensor of shape (n_out,n_in(arg[0]),..., n_in(arg[-1]).

If the generalized derivative is not implemented, raise a NotImplementedError.

If the generalized derivative is zero, can just return 0 (the integer) regardless of the size of the result.

Return type

ndarray

class klampt.math.autodiff.kinematics_ad.WorldOrientation(link)[source]

Autodiff wrapper of the link.getTransform()[0] function as a function of robot configuration q.

Methods:

 Returns the number of arguments. n_in(arg) Returns the number of entries in argument #arg. Returns the number of entries in the output of the function. Evaluates the application of the function to the given (instantiated) arguments. derivative(arg, q) Returns the Jacobian of the function w.r.t. gen_derivative(arg, q) Generalized derivative that allows higher-order derivatives to be taken.
n_args()[source]

Returns the number of arguments.

n_in(arg)[source]

Returns the number of entries in argument #arg. If 1, this can either be a 1-D vector or a scalar. If -1, the function can accept a variable sized argument.

n_out()[source]

Returns the number of entries in the output of the function. If -1, this can output a variable sized argument.

eval(q)[source]

Evaluates the application of the function to the given (instantiated) arguments.

Parameters

args (list) – a list of arguments, which are either ndarrays or scalars.

derivative(arg, q)[source]

Returns the Jacobian of the function w.r.t. argument #arg.

Parameters
• arg (int) – A value from 0,…,self.n_args()-1 indicating that we wish to take $$df/dx_{arg}$$.

• args (list of ndarrays) – arguments for the function.

Returns

A numpy array of shape (self.n_out(),self.n_in(arg)). Keep in mind that even if the argument or result is a scalar, this needs to be a 2D array.

If the derivative is not implemented, raise a NotImplementedError.

If the derivative is zero, can just return 0 (the integer) regardless of the size of the result.

Return type

ndarray

gen_derivative(arg, q)[source]

Generalized derivative that allows higher-order derivatives to be taken.

Parameters
• arg (list) – Indicates the order of derivatives to be taken. For example, to take the 2nd derivative w.r.t. x0,x1, arg = [0,1] should be specified.

• args (list of ndarrays) – arguments for the function.

Returns

A tensor of shape (n_out,n_in(arg[0]),..., n_in(arg[-1]).

If the generalized derivative is not implemented, raise a NotImplementedError.

If the generalized derivative is zero, can just return 0 (the integer) regardless of the size of the result.

Return type

ndarray

class klampt.math.autodiff.kinematics_ad.WorldTransform(link, localPos=None)[source]

Autodiff wrapper of the link.getTransform() function as a function of robot configuration q.

Methods:

 Returns the number of arguments. n_in(arg) Returns the number of entries in argument #arg. Returns the number of entries in the output of the function. Evaluates the application of the function to the given (instantiated) arguments. derivative(arg, q) Returns the Jacobian of the function w.r.t. gen_derivative(arg, q) Generalized derivative that allows higher-order derivatives to be taken.
n_args()[source]

Returns the number of arguments.

n_in(arg)[source]

Returns the number of entries in argument #arg. If 1, this can either be a 1-D vector or a scalar. If -1, the function can accept a variable sized argument.

n_out()[source]

Returns the number of entries in the output of the function. If -1, this can output a variable sized argument.

eval(q)[source]

Evaluates the application of the function to the given (instantiated) arguments.

Parameters

args (list) – a list of arguments, which are either ndarrays or scalars.

derivative(arg, q)[source]

Returns the Jacobian of the function w.r.t. argument #arg.

Parameters
• arg (int) – A value from 0,…,self.n_args()-1 indicating that we wish to take $$df/dx_{arg}$$.

• args (list of ndarrays) – arguments for the function.

Returns

A numpy array of shape (self.n_out(),self.n_in(arg)). Keep in mind that even if the argument or result is a scalar, this needs to be a 2D array.

If the derivative is not implemented, raise a NotImplementedError.

If the derivative is zero, can just return 0 (the integer) regardless of the size of the result.

Return type

ndarray

gen_derivative(arg, q)[source]

Generalized derivative that allows higher-order derivatives to be taken.

Parameters
• arg (list) – Indicates the order of derivatives to be taken. For example, to take the 2nd derivative w.r.t. x0,x1, arg = [0,1] should be specified.

• args (list of ndarrays) – arguments for the function.

Returns

A tensor of shape (n_out,n_in(arg[0]),..., n_in(arg[-1]).

If the generalized derivative is not implemented, raise a NotImplementedError.

If the generalized derivative is zero, can just return 0 (the integer) regardless of the size of the result.

Return type

ndarray

class klampt.math.autodiff.kinematics_ad.WorldVelocity(link, localPos)[source]

Autodiff wrapper of the link.getPointVelocity() function as a function of robot configuration q and velocity dq.

Methods:

 Returns the number of arguments. n_in(arg) Returns the number of entries in argument #arg. Returns the number of entries in the output of the function. eval(q, dq) Evaluates the application of the function to the given (instantiated) arguments. derivative(arg, q, dq) Returns the Jacobian of the function w.r.t.
n_args()[source]

Returns the number of arguments.

n_in(arg)[source]

Returns the number of entries in argument #arg. If 1, this can either be a 1-D vector or a scalar. If -1, the function can accept a variable sized argument.

n_out()[source]

Returns the number of entries in the output of the function. If -1, this can output a variable sized argument.

eval(q, dq)[source]

Evaluates the application of the function to the given (instantiated) arguments.

Parameters

args (list) – a list of arguments, which are either ndarrays or scalars.

derivative(arg, q, dq)[source]

Returns the Jacobian of the function w.r.t. argument #arg.

Parameters
• arg (int) – A value from 0,…,self.n_args()-1 indicating that we wish to take $$df/dx_{arg}$$.

• args (list of ndarrays) – arguments for the function.

Returns

A numpy array of shape (self.n_out(),self.n_in(arg)). Keep in mind that even if the argument or result is a scalar, this needs to be a 2D array.

If the derivative is not implemented, raise a NotImplementedError.

If the derivative is zero, can just return 0 (the integer) regardless of the size of the result.

Return type

ndarray

class klampt.math.autodiff.kinematics_ad.WorldAngularVelocity(link)[source]

Autodiff wrapper of the link.getAngularVelocity() function, as a function of robotconfiguration q and velocity dq.

Methods:

 Returns the number of arguments. n_in(arg) Returns the number of entries in argument #arg. Returns the number of entries in the output of the function. eval(q, dq) Evaluates the application of the function to the given (instantiated) arguments. derivative(arg, q, dq) Returns the Jacobian of the function w.r.t.
n_args()[source]

Returns the number of arguments.

n_in(arg)[source]

Returns the number of entries in argument #arg. If 1, this can either be a 1-D vector or a scalar. If -1, the function can accept a variable sized argument.

n_out()[source]

Returns the number of entries in the output of the function. If -1, this can output a variable sized argument.

eval(q, dq)[source]

Evaluates the application of the function to the given (instantiated) arguments.

Parameters

args (list) – a list of arguments, which are either ndarrays or scalars.

derivative(arg, q, dq)[source]

Returns the Jacobian of the function w.r.t. argument #arg.

Parameters
• arg (int) – A value from 0,…,self.n_args()-1 indicating that we wish to take $$df/dx_{arg}$$.

• args (list of ndarrays) – arguments for the function.

Returns

A numpy array of shape (self.n_out(),self.n_in(arg)). Keep in mind that even if the argument or result is a scalar, this needs to be a 2D array.

If the derivative is not implemented, raise a NotImplementedError.

If the derivative is zero, can just return 0 (the integer) regardless of the size of the result.

Return type

ndarray

Autodiff function to convert driver values to link values.

Methods:

 Returns the number of arguments. n_in(arg) Returns the number of entries in argument #arg. Returns the number of entries in the output of the function. eval(qdriver) Evaluates the application of the function to the given (instantiated) arguments. jvp(arg, dqdriver, qdriver) Performs a Jacobian-vector product for argument #arg.
n_args()[source]

Returns the number of arguments.

n_in(arg)[source]

Returns the number of entries in argument #arg. If 1, this can either be a 1-D vector or a scalar. If -1, the function can accept a variable sized argument.

n_out()[source]

Returns the number of entries in the output of the function. If -1, this can output a variable sized argument.

eval(qdriver)[source]

Evaluates the application of the function to the given (instantiated) arguments.

Parameters

args (list) – a list of arguments, which are either ndarrays or scalars.

jvp(arg, dqdriver, qdriver)[source]

Performs a Jacobian-vector product for argument #arg.

Parameters
• arg (int) – A value from 0,…,self.n_args()-1 indicating that we wish to calculate df/dx_arg * darg.

• darg (ndarray) – the derivative of x_arg w.r.t some other parameter. Must have darg.shape = (self.n_in(arg),).

• args (list of ndarrays) – arguments for the function.

Returns

A numpy array of length self.n_out()

If the derivative is not implemented, raise a NotImplementedError.

Return type

ndarray

Autodiff function to convert driver velocities to link velocities.

Methods:

 Returns the number of arguments. n_in(arg) Returns the number of entries in argument #arg. Returns the number of entries in the output of the function. eval(vdriver) Evaluates the application of the function to the given (instantiated) arguments. jvp(arg, dvdriver, vdriver) Performs a Jacobian-vector product for argument #arg.
n_args()[source]

Returns the number of arguments.

n_in(arg)[source]

Returns the number of entries in argument #arg. If 1, this can either be a 1-D vector or a scalar. If -1, the function can accept a variable sized argument.

n_out()[source]

Returns the number of entries in the output of the function. If -1, this can output a variable sized argument.

eval(vdriver)[source]

Evaluates the application of the function to the given (instantiated) arguments.

Parameters

args (list) – a list of arguments, which are either ndarrays or scalars.

jvp(arg, dvdriver, vdriver)[source]

Performs a Jacobian-vector product for argument #arg.

Parameters
• arg (int) – A value from 0,…,self.n_args()-1 indicating that we wish to calculate df/dx_arg * darg.

• darg (ndarray) – the derivative of x_arg w.r.t some other parameter. Must have darg.shape = (self.n_in(arg),).

• args (list of ndarrays) – arguments for the function.

Returns

A numpy array of length self.n_out()

If the derivative is not implemented, raise a NotImplementedError.

Return type

ndarray

class klampt.math.autodiff.kinematics_ad.LinksToDrivers(robot)[source]

Autodiff function to convert link values to driver values.

Methods:

 Returns the number of arguments. n_in(arg) Returns the number of entries in argument #arg. Returns the number of entries in the output of the function. Evaluates the application of the function to the given (instantiated) arguments. jvp(arg, dq, q) Performs a Jacobian-vector product for argument #arg.
n_args()[source]

Returns the number of arguments.

n_in(arg)[source]

Returns the number of entries in argument #arg. If 1, this can either be a 1-D vector or a scalar. If -1, the function can accept a variable sized argument.

n_out()[source]

Returns the number of entries in the output of the function. If -1, this can output a variable sized argument.

eval(q)[source]

Evaluates the application of the function to the given (instantiated) arguments.

Parameters

args (list) – a list of arguments, which are either ndarrays or scalars.

jvp(arg, dq, q)[source]

Performs a Jacobian-vector product for argument #arg.

Parameters
• arg (int) – A value from 0,…,self.n_args()-1 indicating that we wish to calculate df/dx_arg * darg.

• darg (ndarray) – the derivative of x_arg w.r.t some other parameter. Must have darg.shape = (self.n_in(arg),).

• args (list of ndarrays) – arguments for the function.

Returns

A numpy array of length self.n_out()

If the derivative is not implemented, raise a NotImplementedError.

Return type

ndarray

class klampt.math.autodiff.kinematics_ad.LinkDerivsToDrivers(robot)[source]

Autodiff function to convert link velocities to driver velocities.

Methods:

 Returns the number of arguments. n_in(arg) Returns the number of entries in argument #arg. Returns the number of entries in the output of the function. Evaluates the application of the function to the given (instantiated) arguments. jvp(arg, dv, v) Performs a Jacobian-vector product for argument #arg.
n_args()[source]

Returns the number of arguments.

n_in(arg)[source]

Returns the number of entries in argument #arg. If 1, this can either be a 1-D vector or a scalar. If -1, the function can accept a variable sized argument.

n_out()[source]

Returns the number of entries in the output of the function. If -1, this can output a variable sized argument.

eval(v)[source]

Evaluates the application of the function to the given (instantiated) arguments.

Parameters

args (list) – a list of arguments, which are either ndarrays or scalars.

jvp(arg, dv, v)[source]

Performs a Jacobian-vector product for argument #arg.

Parameters
• arg (int) – A value from 0,…,self.n_args()-1 indicating that we wish to calculate df/dx_arg * darg.

• darg (ndarray) – the derivative of x_arg w.r.t some other parameter. Must have darg.shape = (self.n_in(arg),).

• args (list of ndarrays) – arguments for the function.

Returns

A numpy array of length self.n_out()

If the derivative is not implemented, raise a NotImplementedError.

Return type

ndarray

class klampt.math.autodiff.kinematics_ad.ConfigInterpolate(robot)[source]

Autodiff wrapper of the RobotModel.interpolate function

Methods:

 Returns the number of arguments. n_in(arg) Returns the number of entries in argument #arg. Returns the number of entries in the output of the function. eval(a, b, u) Evaluates the application of the function to the given (instantiated) arguments.
n_args()[source]

Returns the number of arguments.

n_in(arg)[source]

Returns the number of entries in argument #arg. If 1, this can either be a 1-D vector or a scalar. If -1, the function can accept a variable sized argument.

n_out()[source]

Returns the number of entries in the output of the function. If -1, this can output a variable sized argument.

eval(a, b, u)[source]

Evaluates the application of the function to the given (instantiated) arguments.

Parameters

args (list) – a list of arguments, which are either ndarrays or scalars.

class klampt.math.autodiff.kinematics_ad.KinematicsBuilder(robot, configuration='fixed', velocity=None, relative_transforms='fixed', axes='fixed')[source]

Bases: object

A class that computes the entire computation graph of forward kinematics and caches it so that multiple queries are auto-diffable and share the same intermediate computations.

Parameters
• robot (RobotModel) – the robot

• configuration (array, AD expression, or list of expressions, optional) – the robot’s configuration, either as a fixed configuration or a variable. By default, this is fixed at the robot’s configuration.

• velocity (array, AD expression, or list of expressions, optional) – if given, the X_velocity methods are available. This gives the robot’s velocity, either as a fixed vector or a variable. By default, no velocity expression tree is created.

• relative_transform (array or list of AD so3 expressions, optional) – if given, the relative transforms of the robot’s links. By default these are taken from the robot model.

• axes (array or list of AD R^3 expressions, optional) – if given, the axes relative transforms of the robot’s links. By default these are taken from the robot model.

Example:

kb = KinematicsBuilder(robot,'q','dq')


Methods:

 Returns an autodiff expression for the transform of the given link. world_position(link[, localPos]) Returns an autodiff expression for the world position of the point localPos on the given link. world_direction(link, localDir) Returns an autodiff expression for the world direction of the direction localDir on the given link. Returns an autodiff expression for the orientation of the given link. world_velocity(link[, localPos]) Returns an autodiff expression for the world velocity of the point localPos on the given link. Returns an autodiff expression for the world angular velocity of the given link. local_position(link, localPos) local_direction(link, localDir)
world_transform(link)[source]

Returns an autodiff expression for the transform of the given link.

Expression evaluates to a 12-D se3_ad array.

world_position(link, localPos=None)[source]

Returns an autodiff expression for the world position of the point localPos on the given link. If localPos isn’t given, the link origin’s position is returned.

world_direction(link, localDir)[source]

Returns an autodiff expression for the world direction of the direction localDir on the given link.

world_orientation(link)[source]

Returns an autodiff expression for the orientation of the given link.

Expression evaluates to a 9-D so3_ad array.

world_velocity(link, localPos=None)[source]

Returns an autodiff expression for the world velocity of the point localPos on the given link. If localPos isn’t given, the link origin’s velocity is returned.

world_angular_velocity(link)[source]

Returns an autodiff expression for the world angular velocity of the given link.

Expression evaluates to a 9-D so3_ad array.

local_position(link, localPos)[source]
local_direction(link, localDir)[source]
inv_orientation(link)[source]