basic_robotics.modern_robotics_numba.modern_high_performance module
Numba-accelerated port of the Modern Robotics code library.
This module reimplements the core rigid-body motion, kinematics, dynamics,
and trajectory-generation functions from the “Modern Robotics: Mechanics,
Planning, and Control” textbook code library, with several functions
compiled using numba.jit for performance.
- basic_robotics.modern_robotics_numba.modern_high_performance.NearZero(z)[source]
Determines whether a scalar is small enough to be treated as zero.
- Parameters:
z – A scalar input to check.
- Returns:
True if z is close to zero, false otherwise.
Example:
z = -1e-7 # Output: # True
- basic_robotics.modern_robotics_numba.modern_high_performance.Normalize(V)[source]
Normalizes a vector.
- Parameters:
V – A vector.
- Returns:
A unit vector pointing in the same direction as V.
Example:
V = np.array([1, 2, 3]) # Output: # np.array([0.26726124, 0.53452248, 0.80178373])
- basic_robotics.modern_robotics_numba.modern_high_performance.AngleMod(rad)[source]
Wraps each element of an angle array into the range (-2*pi, 2*pi).
- Parameters:
rad – An array of angles in radians, modified in place.
- Returns:
The input array with each element reduced modulo 2*pi.
- basic_robotics.modern_robotics_numba.modern_high_performance.Norm(v)[source]
Computes the Euclidean norm of a 3-vector.
- Parameters:
v – A 3-element vector.
- Returns:
The Euclidean (L2) norm of v.
- basic_robotics.modern_robotics_numba.modern_high_performance.Norm6(v)[source]
Computes the Euclidean norm of a 6-vector.
Faster than
np.linalg.normfor the small, fixed-size float vectors used throughout this module, but is not safe for very large values.- Parameters:
v – A 6-element float vector.
- Returns:
The Euclidean (L2) norm of v.
- basic_robotics.modern_robotics_numba.modern_high_performance.RotInv(R)[source]
Inverts a rotation matrix.
- Parameters:
R – A rotation matrix.
- Returns:
The inverse of R.
Example:
R = np.array([[0, 0, 1], [1, 0, 0], [0, 1, 0]]) # Output: # np.array([[0, 1, 0], # [0, 0, 1], # [1, 0, 0]])
- basic_robotics.modern_robotics_numba.modern_high_performance.VecToso3(omg)[source]
Converts a 3-vector to an so(3) representation.
- Parameters:
omg – A 3-vector.
- Returns:
The skew symmetric representation of omg.
Example:
omg = np.array([1, 2, 3]) # Output: # np.array([[ 0, -3, 2], # [ 3, 0, -1], # [-2, 1, 0]])
- basic_robotics.modern_robotics_numba.modern_high_performance.so3ToVec(so3mat)[source]
Converts an so(3) representation to a 3-vector.
- Parameters:
so3mat – A 3x3 skew-symmetric matrix.
- Returns:
The 3-vector corresponding to so3mat.
Example:
so3mat = np.array([[ 0, -3, 2], [ 3, 0, -1], [-2, 1, 0]]) # Output: # np.array([1, 2, 3])
- basic_robotics.modern_robotics_numba.modern_high_performance.AxisAng3(expc3)[source]
Converts a 3-vector of exponential coordinates for rotation into axis-angle form.
- Parameters:
expc3 – A 3-vector of exponential coordinates for rotation.
- Returns:
omghat – A unit rotation axis. theta: The corresponding rotation angle.
Example:
expc3 = np.array([1, 2, 3]) # Output: # (np.array([0.26726124, 0.53452248, 0.80178373]), 3.7416573867739413)
- basic_robotics.modern_robotics_numba.modern_high_performance.MatrixExp3(so3mat)[source]
Computes the matrix exponential of a matrix in so(3).
- Parameters:
so3mat – A 3x3 skew-symmetric matrix.
- Returns:
The matrix exponential of so3mat.
Example:
so3mat = np.array([[ 0, -3, 2], [ 3, 0, -1], [-2, 1, 0]]) # Output: # np.array([[-0.69492056, 0.71352099, 0.08929286], # [-0.19200697, -0.30378504, 0.93319235], # [ 0.69297817, 0.6313497 , 0.34810748]])
- basic_robotics.modern_robotics_numba.modern_high_performance.SafeTrace(R)[source]
Computes the trace of a square matrix.
- Parameters:
R – A square matrix.
- Returns:
The sum of the diagonal elements of R, or -1 if R is not square.
- basic_robotics.modern_robotics_numba.modern_high_performance.SafeClip(x, mn, mx)[source]
Clips a scalar value to the range [mn, mx].
- Parameters:
x – The value to clip.
mn – The minimum allowed value.
mx – The maximum allowed value.
- Returns:
x clamped to the range [mn, mx].
- basic_robotics.modern_robotics_numba.modern_high_performance.MatrixLog3(R)[source]
Computes the matrix logarithm of a rotation matrix.
- Parameters:
R – A 3x3 rotation matrix.
- Returns:
The matrix logarithm of R.
Example:
R = np.array([[0, 0, 1], [1, 0, 0], [0, 1, 0]]) # Output: # np.array([[ 0, -1.20919958, 1.20919958], # [ 1.20919958, 0, -1.20919958], # [-1.20919958, 1.20919958, 0]])
- basic_robotics.modern_robotics_numba.modern_high_performance.RpToTrans(R, p)[source]
Converts a rotation matrix and a position vector into a homogeneous transformation matrix.
- Parameters:
R – A 3x3 rotation matrix.
p – A 3-vector.
- Returns:
A homogeneous transformation matrix corresponding to the inputs.
Example:
R = np.array([[1, 0, 0], [0, 0, -1], [0, 1, 0]]) p = np.array([1, 2, 5]) # Output: # np.array([[1, 0, 0, 1], # [0, 0, -1, 2], # [0, 1, 0, 5], # [0, 0, 0, 1]])
- basic_robotics.modern_robotics_numba.modern_high_performance.TransToRp(T)[source]
Converts a homogeneous transformation matrix into a rotation matrix and position vector.
- Parameters:
T – A homogeneous transformation matrix.
- Returns:
R – The corresponding rotation matrix. p: The corresponding position vector.
Example:
T = np.array([[1, 0, 0, 0], [0, 0, -1, 0], [0, 1, 0, 3], [0, 0, 0, 1]]) # Output: # (np.array([[1, 0, 0], # [0, 0, -1], # [0, 1, 0]]), # np.array([0, 0, 3]))
- basic_robotics.modern_robotics_numba.modern_high_performance.TransInv(T)[source]
Inverts a homogeneous transformation matrix.
Uses the structure of transformation matrices to avoid taking a matrix inverse, for efficiency.
- Parameters:
T – A homogeneous transformation matrix.
- Returns:
The inverse of T.
Example:
T = np.array([[1, 0, 0, 0], [0, 0, -1, 0], [0, 1, 0, 3], [0, 0, 0, 1]]) # Output: # np.array([[1, 0, 0, 0], # [0, 0, 1, -3], # [0, -1, 0, 0], # [0, 0, 0, 1]])
- basic_robotics.modern_robotics_numba.modern_high_performance.VecTose3(V)[source]
Converts a spatial velocity vector into a 4x4 matrix in se3.
- Parameters:
V – A 6-vector representing a spatial velocity.
- Returns:
The 4x4 se3 representation of V.
Example:
V = np.array([1, 2, 3, 4, 5, 6]) # Output: # np.array([[ 0, -3, 2, 4], # [ 3, 0, -1, 5], # [-2, 1, 0, 6], # [ 0, 0, 0, 0]])
- basic_robotics.modern_robotics_numba.modern_high_performance.se3ToVec(se3mat)[source]
Converts an se3 matrix into a spatial velocity vector.
- Parameters:
se3mat – A 4x4 matrix in se3.
- Returns:
The spatial velocity 6-vector corresponding to se3mat.
Example:
se3mat = np.array([[ 0, -3, 2, 4], [ 3, 0, -1, 5], [-2, 1, 0, 6], [ 0, 0, 0, 0]]) # Output: # np.array([1, 2, 3, 4, 5, 6])
- basic_robotics.modern_robotics_numba.modern_high_performance.Adjoint(T)[source]
Computes the adjoint representation of a homogeneous transformation matrix.
- Parameters:
T – A homogeneous transformation matrix.
- Returns:
The 6x6 adjoint representation [AdT] of T.
Example:
T = np.array([[1, 0, 0, 0], [0, 0, -1, 0], [0, 1, 0, 3], [0, 0, 0, 1]]) # Output: # np.array([[1, 0, 0, 0, 0, 0], # [0, 0, -1, 0, 0, 0], # [0, 1, 0, 0, 0, 0], # [0, 0, 3, 1, 0, 0], # [3, 0, 0, 0, 0, -1], # [0, 0, 0, 0, 1, 0]])
- basic_robotics.modern_robotics_numba.modern_high_performance.ScrewToAxis(q, s, h)[source]
Takes a parametric description of a screw axis and converts it to a normalized screw axis.
- Parameters:
q – A point lying on the screw axis.
s – A unit vector in the direction of the screw axis.
h – The pitch of the screw axis.
- Returns:
A normalized screw axis described by the inputs.
Example:
q = np.array([3, 0, 0]) s = np.array([0, 0, 1]) h = 2 # Output: # np.array([0, 0, 1, 0, -3, 2])
- basic_robotics.modern_robotics_numba.modern_high_performance.AxisAng6(expc6)[source]
Converts a 6-vector of exponential coordinates into screw axis-angle form.
- Parameters:
expc6 – A 6-vector of exponential coordinates for rigid-body motion S*theta.
- Returns:
S – The corresponding normalized screw axis. theta: The distance traveled along/about S.
Example:
expc6 = np.array([1, 0, 0, 1, 2, 3]) # Output: # (np.array([1.0, 0.0, 0.0, 1.0, 2.0, 3.0]), 1.0)
- basic_robotics.modern_robotics_numba.modern_high_performance.MatrixExp6(se3mat)[source]
Computes the matrix exponential of an se3 representation of exponential coordinates.
- Parameters:
se3mat – A matrix in se3.
- Returns:
The matrix exponential of se3mat.
Example:
se3mat = np.array([[0, 0, 0, 0], [0, 0, -1.57079632, 2.35619449], [0, 1.57079632, 0, 2.35619449], [0, 0, 0, 0]]) # Output: # np.array([[1.0, 0.0, 0.0, 0.0], # [0.0, 0.0, -1.0, 0.0], # [0.0, 1.0, 0.0, 3.0], # [ 0, 0, 0, 1]])
- basic_robotics.modern_robotics_numba.modern_high_performance.MatMul(A, B)[source]
Multiplies two matrices.
- Parameters:
A – The left-hand matrix.
B – The right-hand matrix.
- Returns:
The matrix product A @ B.
- basic_robotics.modern_robotics_numba.modern_high_performance.LocalToGlobal(reference, rel)[source]
Transforms a local 6-vector pose (position and Rodrigues rotation vector) into the global frame.
- Parameters:
reference – A 6-vector [position; Rodrigues vector] describing the reference frame’s pose in the global frame.
rel – A 6-vector [position; Rodrigues vector] describing a pose relative to the reference frame.
- Returns:
A 6x1 vector [position; Rodrigues vector] describing rel expressed in the global frame.
- basic_robotics.modern_robotics_numba.modern_high_performance.GlobalToLocal(reference, rel)[source]
Transforms a global 6-vector pose (position and Rodrigues rotation vector) into the local frame defined by reference.
- Parameters:
reference – A 6-vector [position; Rodrigues vector] describing the reference frame’s pose in the global frame.
rel – A 6-vector [position; Rodrigues vector] describing a pose in the global frame.
- Returns:
A 6x1 vector [position; Rodrigues vector] describing rel expressed relative to the reference frame.
- basic_robotics.modern_robotics_numba.modern_high_performance.MatrixLog6(T)[source]
Computes the matrix logarithm of a homogeneous transformation matrix.
- Parameters:
T – A matrix in SE3.
- Returns:
The matrix logarithm of T.
Example:
T = np.array([[1, 0, 0, 0], [0, 0, -1, 0], [0, 1, 0, 3], [0, 0, 0, 1]]) # Output: # np.array([[0, 0, 0, 0] # [0, 0, -1.57079633, 2.35619449] # [0, 1.57079633, 0, 2.35619449] # [0, 0, 0, 0]])
- basic_robotics.modern_robotics_numba.modern_high_performance.SafeDot(A, B)[source]
Computes the matrix product of two arrays.
- Parameters:
A – The left-hand array.
B – The right-hand array.
- Returns:
The matrix product A @ B.
- basic_robotics.modern_robotics_numba.modern_high_performance.ProjectToSO3(mat)[source]
Returns a projection of mat into SO(3).
Projects a matrix mat to the closest matrix in SO(3) using singular-value decomposition (see http://hades.mech.northwestern.edu/index.php/Modern_Robotics_Linear_Algebra_Review). This function is only appropriate for matrices close to SO(3).
- Parameters:
mat – A matrix near SO(3) to project to SO(3).
- Returns:
The closest matrix to mat that is in SO(3).
Example:
mat = np.array([[ 0.675, 0.150, 0.720], [ 0.370, 0.771, -0.511], [-0.630, 0.619, 0.472]]) # Output: # np.array([[ 0.67901136, 0.14894516, 0.71885945], # [ 0.37320708, 0.77319584, -0.51272279], # [-0.63218672, 0.61642804, 0.46942137]])
- basic_robotics.modern_robotics_numba.modern_high_performance.ProjectToSE3(mat)[source]
Returns a projection of mat into SE(3).
Projects a matrix mat to the closest matrix in SE(3) using singular-value decomposition (see http://hades.mech.northwestern.edu/index.php/Modern_Robotics_Linear_Algebra_Review). This function is only appropriate for matrices close to SE(3).
- Parameters:
mat – A 4x4 matrix to project to SE(3).
- Returns:
The closest matrix to mat that is in SE(3).
Example:
mat = np.array([[ 0.675, 0.150, 0.720, 1.2], [ 0.370, 0.771, -0.511, 5.4], [-0.630, 0.619, 0.472, 3.6], [ 0.003, 0.002, 0.010, 0.9]]) # Output: # np.array([[ 0.67901136, 0.14894516, 0.71885945, 1.2 ], # [ 0.37320708, 0.77319584, -0.51272279, 5.4 ], # [-0.63218672, 0.61642804, 0.46942137, 3.6 ], # [ 0. , 0. , 0. , 1. ]])
- basic_robotics.modern_robotics_numba.modern_high_performance.DistanceToSO3(mat)[source]
Returns the Frobenius norm describing the distance of mat from the SO(3) manifold.
Computes the distance d from mat to the SO(3) manifold as follows: if det(mat) <= 0, d is a large number; if det(mat) > 0, d = norm(mat^T . mat - I).
- Parameters:
mat – A 3x3 matrix.
- Returns:
A quantity describing the distance of mat from the SO(3) manifold.
Example:
mat = np.array([[ 1.0, 0.0, 0.0 ], [ 0.0, 0.1, -0.95], [ 0.0, 1.0, 0.1 ]]) # Output: # 0.08835
- basic_robotics.modern_robotics_numba.modern_high_performance.DistanceToSE3(mat)[source]
Returns the Frobenius norm describing the distance of mat from the SE(3) manifold.
Computes the distance from mat to the SE(3) manifold as follows: let matR be the top-left 3x3 submatrix of mat; if det(matR) <= 0, return a large number; otherwise replace the top-left 3x3 submatrix of mat with matR^T . matR, set the first three entries of the fourth column of mat to zero, and return norm(mat - I).
- Parameters:
mat – A 4x4 matrix.
- Returns:
A quantity describing the distance of mat from the SE(3) manifold.
Example:
mat = np.array([[ 1.0, 0.0, 0.0, 1.2 ], [ 0.0, 0.1, -0.95, 1.5 ], [ 0.0, 1.0, 0.1, -0.9 ], [ 0.0, 0.0, 0.1, 0.98 ]]) # Output: # 0.134931
- basic_robotics.modern_robotics_numba.modern_high_performance.TestIfSO3(mat)[source]
Returns true if mat is close to or on the manifold SO(3).
Computes the distance d from mat to the SO(3) manifold (see DistanceToSO3) and returns whether d is close to zero.
- Parameters:
mat – A 3x3 matrix.
- Returns:
True if mat is very close to or in SO(3), false otherwise.
Example:
mat = np.array([[1.0, 0.0, 0.0 ], [0.0, 0.1, -0.95], [0.0, 1.0, 0.1 ]]) # Output: # False
- basic_robotics.modern_robotics_numba.modern_high_performance.TestIfSE3(mat)[source]
Returns true if mat is close to or on the manifold SE(3).
Computes the distance d from mat to the SE(3) manifold (see DistanceToSE3) and returns whether d is close to zero.
- Parameters:
mat – A 4x4 matrix.
- Returns:
True if mat is very close to or in SE(3), false otherwise.
Example:
mat = np.array([[1.0, 0.0, 0.0, 1.2], [0.0, 0.1, -0.95, 1.5], [0.0, 1.0, 0.1, -0.9], [0.0, 0.0, 0.1, 0.98]]) # Output: # False
- basic_robotics.modern_robotics_numba.modern_high_performance.FKinBody(M, Blist, thetalist)[source]
Computes forward kinematics in the body frame for an open chain robot.
- Parameters:
M – The home configuration (position and orientation) of the end-effector.
Blist – The joint screw axes in the end-effector frame when the manipulator is at the home position, in the format of a matrix with axes as the columns.
thetalist – A list of joint coordinates.
- Returns:
A homogeneous transformation matrix representing the end-effector frame when the joints are at the specified coordinates (i.t.o. body frame).
Example:
M = np.array([[-1, 0, 0, 0], [ 0, 1, 0, 6], [ 0, 0, -1, 2], [ 0, 0, 0, 1]]) Blist = np.array([[0, 0, -1, 2, 0, 0], [0, 0, 0, 0, 1, 0], [0, 0, 1, 0, 0, 0.1]]).T thetalist = np.array([np.pi / 2.0, 3, np.pi]) # Output: # np.array([[0, 1, 0, -5], # [1, 0, 0, 4], # [0, 0, -1, 1.68584073], # [0, 0, 0, 1]])
- basic_robotics.modern_robotics_numba.modern_high_performance.FKinSpace(M, Slist, thetalist)[source]
Computes forward kinematics in the space frame for an open chain robot.
- Parameters:
M – The home configuration (position and orientation) of the end-effector.
Slist – The joint screw axes in the space frame when the manipulator is at the home position, in the format of a matrix with axes as the columns.
thetalist – A list of joint coordinates.
- Returns:
A homogeneous transformation matrix representing the end-effector frame when the joints are at the specified coordinates (i.t.o. space frame).
Example:
M = np.array([[-1, 0, 0, 0], [ 0, 1, 0, 6], [ 0, 0, -1, 2], [ 0, 0, 0, 1]]) Slist = np.array([[0, 0, 1, 4, 0, 0], [0, 0, 0, 0, 1, 0], [0, 0, -1, -6, 0, -0.1]]).T thetalist = np.array([np.pi / 2.0, 3, np.pi]) # Output: # np.array([[0, 1, 0, -5], # [1, 0, 0, 4], # [0, 0, -1, 1.68584073], # [0, 0, 0, 1]])
- basic_robotics.modern_robotics_numba.modern_high_performance.SafeCopy(arr)[source]
Makes an element-wise copy of a 2D array.
- Parameters:
arr – A 2D array to copy.
- Returns:
A new array with the same shape and values as arr.
- basic_robotics.modern_robotics_numba.modern_high_performance.JacobianBody(Blist, thetalist)[source]
Computes the body Jacobian for an open chain robot.
- Parameters:
Blist – The joint screw axes in the end-effector frame when the manipulator is at the home position, in the format of a matrix with axes as the columns.
thetalist – A list of joint coordinates.
- Returns:
The body Jacobian corresponding to the inputs (6xn real numbers).
Example:
Blist = np.array([[0, 0, 1, 0, 0.2, 0.2], [1, 0, 0, 2, 0, 3], [0, 1, 0, 0, 2, 1], [1, 0, 0, 0.2, 0.3, 0.4]]).T thetalist = np.array([0.2, 1.1, 0.1, 1.2]) # Output: # np.array([[-0.04528405, 0.99500417, 0, 1] # [ 0.74359313, 0.09304865, 0.36235775, 0] # [-0.66709716, 0.03617541, -0.93203909, 0] # [ 2.32586047, 1.66809, 0.56410831, 0.2] # [-1.44321167, 2.94561275, 1.43306521, 0.3] # [-2.06639565, 1.82881722, -1.58868628, 0.4]])
- basic_robotics.modern_robotics_numba.modern_high_performance.JacobianSpace(Slist, thetalist)[source]
Computes the space Jacobian for an open chain robot.
- Parameters:
Slist – The joint screw axes in the space frame when the manipulator is at the home position, in the format of a matrix with axes as the columns.
thetalist – A list of joint coordinates.
- Returns:
The space Jacobian corresponding to the inputs (6xn real numbers).
Example:
Slist = np.array([[0, 0, 1, 0, 0.2, 0.2], [1, 0, 0, 2, 0, 3], [0, 1, 0, 0, 2, 1], [1, 0, 0, 0.2, 0.3, 0.4]]).T thetalist = np.array([0.2, 1.1, 0.1, 1.2]) # Output: # np.array([[ 0, 0.98006658, -0.09011564, 0.95749426] # [ 0, 0.19866933, 0.4445544, 0.28487557] # [ 1, 0, 0.89120736, -0.04528405] # [ 0, 1.95218638, -2.21635216, -0.51161537] # [0.2, 0.43654132, -2.43712573, 2.77535713] # [0.2, 2.96026613, 3.23573065, 2.22512443]])
- basic_robotics.modern_robotics_numba.modern_high_performance.IKinBody(Blist, M, T, thetalist0, eomg, ev)[source]
Computes inverse kinematics in the body frame for an open chain robot.
Uses an iterative Newton-Raphson root-finding method. The maximum number of iterations before the algorithm is terminated has been hardcoded in as a variable called maxiterations. It is set to 20 at the start of the function, but can be changed if needed.
- Parameters:
Blist – The joint screw axes in the end-effector frame when the manipulator is at the home position, in the format of a matrix with axes as the columns.
M – The home configuration of the end-effector.
T – The desired end-effector configuration Tsd.
thetalist0 – An initial guess of joint angles that are close to satisfying Tsd.
eomg – A small positive tolerance on the end-effector orientation error. The returned joint angles must give an end-effector orientation error less than eomg.
ev – A small positive tolerance on the end-effector linear position error. The returned joint angles must give an end-effector position error less than ev.
- Returns:
thetalist –
- Joint angles that achieve T within the specified
tolerances.
- success: A logical value where TRUE means that the function found
a solution and FALSE means that it ran through the set number of maximum iterations without finding a solution within the tolerances eomg and ev.
Example:
Blist = np.array([[0, 0, -1, 2, 0, 0], [0, 0, 0, 0, 1, 0], [0, 0, 1, 0, 0, 0.1]]).T M = np.array([[-1, 0, 0, 0], [ 0, 1, 0, 6], [ 0, 0, -1, 2], [ 0, 0, 0, 1]]) T = np.array([[0, 1, 0, -5], [1, 0, 0, 4], [0, 0, -1, 1.6858], [0, 0, 0, 1]]) thetalist0 = np.array([1.5, 2.5, 3]) eomg = 0.01 ev = 0.001 # Output: # (np.array([1.57073819, 2.999667, 3.14153913]), True)
- basic_robotics.modern_robotics_numba.modern_high_performance.IKinSpace(Slist, M, T, thetalist0, eomg, ev, max_iters=20)[source]
Computes inverse kinematics in the space frame for an open chain robot.
Uses an iterative Newton-Raphson root-finding method. The maximum number of iterations before the algorithm is terminated has been hardcoded in as a variable called maxiterations. It is set to 20 at the start of the function, but can be changed if needed.
- Parameters:
Slist – The joint screw axes in the space frame when the manipulator is at the home position, in the format of a matrix with axes as the columns.
M – The home configuration of the end-effector.
T – The desired end-effector configuration Tsd.
thetalist0 – An initial guess of joint angles that are close to satisfying Tsd.
eomg – A small positive tolerance on the end-effector orientation error. The returned joint angles must give an end-effector orientation error less than eomg.
ev – A small positive tolerance on the end-effector linear position error. The returned joint angles must give an end-effector position error less than ev.
- Returns:
thetalist –
- Joint angles that achieve T within the specified
tolerances.
- success: A logical value where TRUE means that the function found
a solution and FALSE means that it ran through the set number of maximum iterations without finding a solution within the tolerances eomg and ev.
Example:
Slist = np.array([[0, 0, 1, 4, 0, 0], [0, 0, 0, 0, 1, 0], [0, 0, -1, -6, 0, -0.1]]).T M = np.array([[-1, 0, 0, 0], [ 0, 1, 0, 6], [ 0, 0, -1, 2], [ 0, 0, 0, 1]]) T = np.array([[0, 1, 0, -5], [1, 0, 0, 4], [0, 0, -1, 1.6858], [0, 0, 0, 1]]) thetalist0 = np.array([1.5, 2.5, 3]) eomg = 0.01 ev = 0.001 # Output: # (np.array([ 1.57073783, 2.99966384, 3.1415342 ]), True)
- basic_robotics.modern_robotics_numba.modern_high_performance.ad(V)[source]
Calculates the 6x6 matrix [adV] of the given 6-vector.
Used to calculate the Lie bracket [V1, V2] = [adV1]V2.
- Parameters:
V – A 6-vector spatial velocity.
- Returns:
The corresponding 6x6 matrix [adV].
Example:
V = np.array([1, 2, 3, 4, 5, 6]) # Output: # np.array([[ 0, -3, 2, 0, 0, 0], # [ 3, 0, -1, 0, 0, 0], # [-2, 1, 0, 0, 0, 0], # [ 0, -6, 5, 0, -3, 2], # [ 6, 0, -4, 3, 0, -1], # [-5, 4, 0, -2, 1, 0]])
- basic_robotics.modern_robotics_numba.modern_high_performance.InverseDynamics(thetalist, dthetalist, ddthetalist, g, Ftip, Mlist, Glist, Slist)[source]
Computes inverse dynamics in the space frame for an open chain robot.
Uses forward-backward Newton-Euler iterations to solve the equation:
taulist = Mlist(thetalist)*ddthetalist + c(thetalist, dthetalist) + g(thetalist) + Jtr(thetalist)*Ftip- Parameters:
thetalist – n-vector of joint variables.
dthetalist – n-vector of joint rates.
ddthetalist – n-vector of joint accelerations.
g – Gravity vector g.
Ftip – Spatial force applied by the end-effector expressed in frame {n+1}.
Mlist – List of link frames {i} relative to {i-1} at the home position.
Glist – Spatial inertia matrices Gi of the links.
Slist – Screw axes Si of the joints in a space frame, in the format of a matrix with axes as the columns.
- Returns:
The n-vector of required joint forces/torques.
Example (3 Link Robot):
thetalist = np.array([0.1, 0.1, 0.1]) dthetalist = np.array([0.1, 0.2, 0.3]) ddthetalist = np.array([2, 1.5, 1]) g = np.array([0, 0, -9.8]) Ftip = np.array([1, 1, 1, 1, 1, 1]) M01 = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0.089159], [0, 0, 0, 1]]) M12 = np.array([[ 0, 0, 1, 0.28], [ 0, 1, 0, 0.13585], [-1, 0, 0, 0], [ 0, 0, 0, 1]]) M23 = np.array([[1, 0, 0, 0], [0, 1, 0, -0.1197], [0, 0, 1, 0.395], [0, 0, 0, 1]]) M34 = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0.14225], [0, 0, 0, 1]]) G1 = np.diag([0.010267, 0.010267, 0.00666, 3.7, 3.7, 3.7]) G2 = np.diag([0.22689, 0.22689, 0.0151074, 8.393, 8.393, 8.393]) G3 = np.diag([0.0494433, 0.0494433, 0.004095, 2.275, 2.275, 2.275]) Glist = np.array([G1, G2, G3]) Mlist = np.array([M01, M12, M23, M34]) Slist = np.array([[1, 0, 1, 0, 1, 0], [0, 1, 0, -0.089, 0, 0], [0, 1, 0, -0.089, 0, 0.425]]).T # Output: # np.array([74.69616155, -33.06766016, -3.23057314])
- basic_robotics.modern_robotics_numba.modern_high_performance.MassMatrix(thetalist, Mlist, Glist, Slist)[source]
Computes the mass matrix of an open chain robot at a given configuration.
This function calls InverseDynamics n times, each time passing a ddthetalist vector with a single element equal to one and all other inputs set to zero. Each call of InverseDynamics generates a single column, and these columns are assembled to create the inertia matrix.
- Parameters:
thetalist – A list of joint variables.
Mlist – List of link frames i relative to i-1 at the home position.
Glist – Spatial inertia matrices Gi of the links.
Slist – Screw axes Si of the joints in a space frame, in the format of a matrix with axes as the columns.
- Returns:
The numerical inertia matrix M(thetalist) of an n-joint serial chain at the given configuration thetalist.
Example (3 Link Robot):
thetalist = np.array([0.1, 0.1, 0.1]) M01 = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0.089159], [0, 0, 0, 1]]) M12 = np.array([[ 0, 0, 1, 0.28], [ 0, 1, 0, 0.13585], [-1, 0, 0, 0], [ 0, 0, 0, 1]]) M23 = np.array([[1, 0, 0, 0], [0, 1, 0, -0.1197], [0, 0, 1, 0.395], [0, 0, 0, 1]]) M34 = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0.14225], [0, 0, 0, 1]]) G1 = np.diag([0.010267, 0.010267, 0.00666, 3.7, 3.7, 3.7]) G2 = np.diag([0.22689, 0.22689, 0.0151074, 8.393, 8.393, 8.393]) G3 = np.diag([0.0494433, 0.0494433, 0.004095, 2.275, 2.275, 2.275]) Glist = np.array([G1, G2, G3]) Mlist = np.array([M01, M12, M23, M34]) Slist = np.array([[1, 0, 1, 0, 1, 0], [0, 1, 0, -0.089, 0, 0], [0, 1, 0, -0.089, 0, 0.425]]).T # Output: # np.array([[ 2.25433380e+01, -3.07146754e-01, -7.18426391e-03] # [-3.07146754e-01, 1.96850717e+00, 4.32157368e-01] # [-7.18426391e-03, 4.32157368e-01, 1.91630858e-01]])
- basic_robotics.modern_robotics_numba.modern_high_performance.VelQuadraticForces(thetalist, dthetalist, Mlist, Glist, Slist)[source]
Computes the Coriolis and centripetal terms in the inverse dynamics of an open chain robot.
This function calls InverseDynamics with g = 0, Ftip = 0, and ddthetalist = 0.
- Parameters:
thetalist – A list of joint variables.
dthetalist – A list of joint rates.
Mlist – List of link frames i relative to i-1 at the home position.
Glist – Spatial inertia matrices Gi of the links.
Slist – Screw axes Si of the joints in a space frame, in the format of a matrix with axes as the columns.
- Returns:
The vector c(thetalist, dthetalist) of Coriolis and centripetal terms for a given thetalist and dthetalist.
Example (3 Link Robot):
thetalist = np.array([0.1, 0.1, 0.1]) dthetalist = np.array([0.1, 0.2, 0.3]) M01 = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0.089159], [0, 0, 0, 1]]) M12 = np.array([[ 0, 0, 1, 0.28], [ 0, 1, 0, 0.13585], [-1, 0, 0, 0], [ 0, 0, 0, 1]]) M23 = np.array([[1, 0, 0, 0], [0, 1, 0, -0.1197], [0, 0, 1, 0.395], [0, 0, 0, 1]]) M34 = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0.14225], [0, 0, 0, 1]]) G1 = np.diag([0.010267, 0.010267, 0.00666, 3.7, 3.7, 3.7]) G2 = np.diag([0.22689, 0.22689, 0.0151074, 8.393, 8.393, 8.393]) G3 = np.diag([0.0494433, 0.0494433, 0.004095, 2.275, 2.275, 2.275]) Glist = np.array([G1, G2, G3]) Mlist = np.array([M01, M12, M23, M34]) Slist = np.array([[1, 0, 1, 0, 1, 0], [0, 1, 0, -0.089, 0, 0], [0, 1, 0, -0.089, 0, 0.425]]).T # Output: # np.array([0.26453118, -0.05505157, -0.00689132])
- basic_robotics.modern_robotics_numba.modern_high_performance.GravityForces(thetalist, g, Mlist, Glist, Slist)[source]
Computes the joint forces/torques an open chain robot requires to overcome gravity at its configuration.
This function calls InverseDynamics with Ftip = 0, dthetalist = 0, and ddthetalist = 0.
- Parameters:
thetalist – A list of joint variables.
g – 3-vector for gravitational acceleration.
Mlist – List of link frames i relative to i-1 at the home position.
Glist – Spatial inertia matrices Gi of the links.
Slist – Screw axes Si of the joints in a space frame, in the format of a matrix with axes as the columns.
- Returns:
grav –
- The joint forces/torques required to overcome gravity at
thetalist.
Example (3 Link Robot):
thetalist = np.array([0.1, 0.1, 0.1]) g = np.array([0, 0, -9.8]) M01 = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0.089159], [0, 0, 0, 1]]) M12 = np.array([[ 0, 0, 1, 0.28], [ 0, 1, 0, 0.13585], [-1, 0, 0, 0], [ 0, 0, 0, 1]]) M23 = np.array([[1, 0, 0, 0], [0, 1, 0, -0.1197], [0, 0, 1, 0.395], [0, 0, 0, 1]]) M34 = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0.14225], [0, 0, 0, 1]]) G1 = np.diag([0.010267, 0.010267, 0.00666, 3.7, 3.7, 3.7]) G2 = np.diag([0.22689, 0.22689, 0.0151074, 8.393, 8.393, 8.393]) G3 = np.diag([0.0494433, 0.0494433, 0.004095, 2.275, 2.275, 2.275]) Glist = np.array([G1, G2, G3]) Mlist = np.array([M01, M12, M23, M34]) Slist = np.array([[1, 0, 1, 0, 1, 0], [0, 1, 0, -0.089, 0, 0], [0, 1, 0, -0.089, 0, 0.425]]).T # Output: # np.array([28.40331262, -37.64094817, -5.4415892])
- basic_robotics.modern_robotics_numba.modern_high_performance.EndEffectorForces(thetalist, Ftip, Mlist, Glist, Slist)[source]
Computes the joint forces/torques an open chain robot requires only to create the end-effector force Ftip.
This function calls InverseDynamics with g = 0, dthetalist = 0, and ddthetalist = 0.
- Parameters:
thetalist – A list of joint variables.
Ftip – Spatial force applied by the end-effector expressed in frame {n+1}.
Mlist – List of link frames i relative to i-1 at the home position.
Glist – Spatial inertia matrices Gi of the links.
Slist – Screw axes Si of the joints in a space frame, in the format of a matrix with axes as the columns.
- Returns:
The joint forces and torques required only to create the end-effector force Ftip.
Example (3 Link Robot):
thetalist = np.array([0.1, 0.1, 0.1]) Ftip = np.array([1, 1, 1, 1, 1, 1]) M01 = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0.089159], [0, 0, 0, 1]]) M12 = np.array([[ 0, 0, 1, 0.28], [ 0, 1, 0, 0.13585], [-1, 0, 0, 0], [ 0, 0, 0, 1]]) M23 = np.array([[1, 0, 0, 0], [0, 1, 0, -0.1197], [0, 0, 1, 0.395], [0, 0, 0, 1]]) M34 = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0.14225], [0, 0, 0, 1]]) G1 = np.diag([0.010267, 0.010267, 0.00666, 3.7, 3.7, 3.7]) G2 = np.diag([0.22689, 0.22689, 0.0151074, 8.393, 8.393, 8.393]) G3 = np.diag([0.0494433, 0.0494433, 0.004095, 2.275, 2.275, 2.275]) Glist = np.array([G1, G2, G3]) Mlist = np.array([M01, M12, M23, M34]) Slist = np.array([[1, 0, 1, 0, 1, 0], [0, 1, 0, -0.089, 0, 0], [0, 1, 0, -0.089, 0, 0.425]]).T # Output: # np.array([1.40954608, 1.85771497, 1.392409])
- basic_robotics.modern_robotics_numba.modern_high_performance.ForwardDynamics(thetalist, dthetalist, taulist, g, Ftip, Mlist, Glist, Slist)[source]
Computes forward dynamics in the space frame for an open chain robot.
This function computes ddthetalist by solving:
Mlist(thetalist) * ddthetalist = taulist - c(thetalist, dthetalist) - g(thetalist) - Jtr(thetalist) * Ftip- Parameters:
thetalist – A list of joint variables.
dthetalist – A list of joint rates.
taulist – An n-vector of joint forces/torques.
g – Gravity vector g.
Ftip – Spatial force applied by the end-effector expressed in frame {n+1}.
Mlist – List of link frames i relative to i-1 at the home position.
Glist – Spatial inertia matrices Gi of the links.
Slist – Screw axes Si of the joints in a space frame, in the format of a matrix with axes as the columns.
- Returns:
The resulting joint accelerations.
Example (3 Link Robot):
thetalist = np.array([0.1, 0.1, 0.1]) dthetalist = np.array([0.1, 0.2, 0.3]) taulist = np.array([0.5, 0.6, 0.7]) g = np.array([0, 0, -9.8]) Ftip = np.array([1, 1, 1, 1, 1, 1]) M01 = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0.089159], [0, 0, 0, 1]]) M12 = np.array([[ 0, 0, 1, 0.28], [ 0, 1, 0, 0.13585], [-1, 0, 0, 0], [ 0, 0, 0, 1]]) M23 = np.array([[1, 0, 0, 0], [0, 1, 0, -0.1197], [0, 0, 1, 0.395], [0, 0, 0, 1]]) M34 = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0.14225], [0, 0, 0, 1]]) G1 = np.diag([0.010267, 0.010267, 0.00666, 3.7, 3.7, 3.7]) G2 = np.diag([0.22689, 0.22689, 0.0151074, 8.393, 8.393, 8.393]) G3 = np.diag([0.0494433, 0.0494433, 0.004095, 2.275, 2.275, 2.275]) Glist = np.array([G1, G2, G3]) Mlist = np.array([M01, M12, M23, M34]) Slist = np.array([[1, 0, 1, 0, 1, 0], [0, 1, 0, -0.089, 0, 0], [0, 1, 0, -0.089, 0, 0.425]]).T # Output: # np.array([-0.97392907, 25.58466784, -32.91499212])
- basic_robotics.modern_robotics_numba.modern_high_performance.EulerStep(thetalist, dthetalist, ddthetalist, dt)[source]
Computes the joint angles and velocities at the next timestep using first order Euler integration.
- Parameters:
thetalist – n-vector of joint variables.
dthetalist – n-vector of joint rates.
ddthetalist – n-vector of joint accelerations.
dt – The timestep delta t.
- Returns:
thetalistNext –
- Vector of joint variables after dt from first order
Euler integration.
- dthetalistNext: Vector of joint rates after dt from first order
Euler integration.
Example (3 Link Robot):
thetalist = np.array([0.1, 0.1, 0.1]) dthetalist = np.array([0.1, 0.2, 0.3]) ddthetalist = np.array([2, 1.5, 1]) dt = 0.1 # Output: # thetalistNext: array([ 0.11, 0.12, 0.13]) # dthetalistNext: array([ 0.3 , 0.35, 0.4 ])
- basic_robotics.modern_robotics_numba.modern_high_performance.InverseDynamicsTrajectory(thetamat, dthetamat, ddthetamat, g, Ftipmat, Mlist, Glist, Slist)[source]
Calculates the joint forces/torques required to move the serial chain along the given trajectory using inverse dynamics.
- Parameters:
thetamat – An N x n matrix of robot joint variables.
dthetamat – An N x n matrix of robot joint velocities.
ddthetamat – An N x n matrix of robot joint accelerations.
g – Gravity vector g.
Ftipmat – An N x 6 matrix of spatial forces applied by the end-effector (If there are no tip forces the user should input a zero and a zero matrix will be used).
Mlist – List of link frames i relative to i-1 at the home position.
Glist – Spatial inertia matrices Gi of the links.
Slist – Screw axes Si of the joints in a space frame, in the format of a matrix with axes as the columns.
- Returns:
The N x n matrix of joint forces/torques for the specified trajectory, where each of the N rows is the vector of joint forces/torques at each time step.
Example (3 Link Robot):
from __future__ import print_function import numpy as np import modern_robotics as mr # Create a trajectory to follow using functions from Chapter 9 thetastart = np.array([0, 0, 0]) thetaend = np.array([np.pi / 2, np.pi / 2, np.pi / 2]) tm= 3 N= 1000 method = 5 traj = mr.JointTrajectory(thetastart, thetaend, Tf, N, method) thetamat = np.array(traj).copy() dthetamat = np.zeros((1000, 3 )) ddthetamat = np.zeros((1000, 3)) dt = tm/ (N - 1.0) for i in range(np.array(traj).shape[0] - 1): dthetamat[i + 1, :] = (thetamat[i + 1, :] - thetamat[i, :]) / dt ddthetamat[i + 1, :] = (dthetamat[i + 1, :] - dthetamat[i, :]) / dt # Initialize robot description (Example with 3 links) g = np.array([0, 0, -9.8]) Ftipmat = np.ones((N, 6)) M01 = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0.089159], [0, 0, 0, 1]]) M12 = np.array([[ 0, 0, 1, 0.28], [ 0, 1, 0, 0.13585], [-1, 0, 0, 0], [ 0, 0, 0, 1]]) M23 = np.array([[1, 0, 0, 0], [0, 1, 0, -0.1197], [0, 0, 1, 0.395], [0, 0, 0, 1]]) M34 = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0.14225], [0, 0, 0, 1]]) G1 = np.diag([0.010267, 0.010267, 0.00666, 3.7, 3.7, 3.7]) G2 = np.diag([0.22689, 0.22689, 0.0151074, 8.393, 8.393, 8.393]) G3 = np.diag([0.0494433, 0.0494433, 0.004095, 2.275, 2.275, 2.275]) Glist = np.array([G1, G2, G3]) Mlist = np.array([M01, M12, M23, M34]) Slist = np.array([[1, 0, 1, 0, 1, 0], [0, 1, 0, -0.089, 0, 0], [0, 1, 0, -0.089, 0, 0.425]]).T taumat = mr.InverseDynamicsTrajectory(thetamat, dthetamat, ddthetamat, g, Ftipmat, Mlist, Glist, Slist) # Output using matplotlib to plot the joint forces/torques Tau1 = taumat[:, 0] Tau2 = taumat[:, 1] Tau3 = taumat[:, 2] timestamp = np.linspace(0, Tf, N) try: import matplotlib.pyplot as plt except: print('The result will not be plotted due to a lack of package matplotlib') else: plt.plot(timestamp, Tau1, label = "Tau1") plt.plot(timestamp, Tau2, label = "Tau2") plt.plot(timestamp, Tau3, label = "Tau3") plt.ylim (-40, 120) plt.legend(loc = 'lower right') plt.xlabel("Time") plt.ylabel("Torque") plt.title("Plot of Torque Trajectories") plt.show()
- basic_robotics.modern_robotics_numba.modern_high_performance.ForwardDynamicsTrajectory(thetalist, dthetalist, taumat, g, Ftipmat, Mlist, Glist, Slist, dt, intRes)[source]
Simulates the motion of a serial chain given an open-loop history of joint forces/torques.
This function calls a numerical integration procedure that uses ForwardDynamics.
- Parameters:
thetalist – n-vector of initial joint variables.
dthetalist – n-vector of initial joint rates.
taumat – An N x n matrix of joint forces/torques, where each row is the joint effort at any time step.
g – Gravity vector g.
Ftipmat – An N x 6 matrix of spatial forces applied by the end-effector (If there are no tip forces the user should input a zero and a zero matrix will be used).
Mlist – List of link frames {i} relative to {i-1} at the home position.
Glist – Spatial inertia matrices Gi of the links.
Slist – Screw axes Si of the joints in a space frame, in the format of a matrix with axes as the columns.
dt – The timestep between consecutive joint forces/torques.
intRes – Integration resolution is the number of times integration (Euler) takes places between each time step. Must be an integer value greater than or equal to 1.
- Returns:
thetamat –
- The N x n matrix of robot joint angles resulting from
the specified joint forces/torques.
dthetamat: The N x n matrix of robot joint velocities.
Example (3 Link Robot):
from __future__ import print_function import numpy as np import modern_robotics as mr thetalist = np.array([0.1, 0.1, 0.1]) dthetalist = np.array([0.1, 0.2, 0.3]) taumat = np.array([[3.63, -6.58, -5.57], [3.74, -5.55, -5.5], [4.31, -0.68, -5.19], [5.18, 5.63, -4.31], [5.85, 8.17, -2.59], [5.78, 2.79, -1.7], [4.99, -5.3, -1.19], [4.08, -9.41, 0.07], [3.56, -10.1, 0.97], [3.49, -9.41, 1.23]]) # Initialize robot description (Example with 3 links) g = np.array([0, 0, -9.8]) Ftipmat = np.ones((np.array(taumat).shape[0], 6)) M01 = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0.089159], [0, 0, 0, 1]]) M12 = np.array([[ 0, 0, 1, 0.28], [ 0, 1, 0, 0.13585], [-1, 0, 0, 0], [ 0, 0, 0, 1]]) M23 = np.array([[1, 0, 0, 0], [0, 1, 0, -0.1197], [0, 0, 1, 0.395], [0, 0, 0, 1]]) M34 = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0.14225], [0, 0, 0, 1]]) G1 = np.diag([0.010267, 0.010267, 0.00666, 3.7, 3.7, 3.7]) G2 = np.diag([0.22689, 0.22689, 0.0151074, 8.393, 8.393, 8.393]) G3 = np.diag([0.0494433, 0.0494433, 0.004095, 2.275, 2.275, 2.275]) Glist = np.array([G1, G2, G3]) Mlist = np.array([M01, M12, M23, M34]) Slist = np.array([[1, 0, 1, 0, 1, 0], [0, 1, 0, -0.089, 0, 0], [0, 1, 0, -0.089, 0, 0.425]]).T dt = 0.1 intRes = 8 thetamat, dthetamat = mr.ForwardDynamicsTrajectory(thetalist, dthetalist, taumat, g, Ftipmat, Mlist, Glist, Slist, dt, intRes) # Output using matplotlib to plot the joint angle/velocities theta1 = thetamat[:, 0] theta2 = thetamat[:, 1] theta3 = thetamat[:, 2] dtheta1 = dthetamat[:, 0] dtheta2 = dthetamat[:, 1] dtheta3 = dthetamat[:, 2] N = np.array(taumat).shape[0] tm= np.array(taumat).shape[0] * dt timestamp = np.linspace(0, Tf, N) try: import matplotlib.pyplot as plt except: print('The result will not be plotted due to a lack of package matplotlib') else: plt.plot(timestamp, theta1, label = "Theta1") plt.plot(timestamp, theta2, label = "Theta2") plt.plot(timestamp, theta3, label = "Theta3") plt.plot(timestamp, dtheta1, label = "DTheta1") plt.plot(timestamp, dtheta2, label = "DTheta2") plt.plot(timestamp, dtheta3, label = "DTheta3") plt.ylim (-12, 10) plt.legend(loc = 'lower right') plt.xlabel("Time") plt.ylabel("Joint Angles/Velocities") plt.title("Plot of Joint Angles and Joint Velocities") plt.show()
- basic_robotics.modern_robotics_numba.modern_high_performance.CubicTimeScaling(Tf, t)[source]
Computes s(t) for a cubic time scaling.
- Parameters:
Tf – Total time of the motion in seconds from rest to rest.
t – The current time t satisfying 0 < t < Tf.
- Returns:
The path parameter s(t) corresponding to a third-order polynomial motion that begins and ends at zero velocity.
Example:
tm = 2 t = 0.6 # Output: # 0.216
- basic_robotics.modern_robotics_numba.modern_high_performance.QuinticTimeScaling(Tf, t)[source]
Computes s(t) for a quintic time scaling.
- Parameters:
Tf – Total time of the motion in seconds from rest to rest.
t – The current time t satisfying 0 < t < Tf.
- Returns:
The path parameter s(t) corresponding to a fifth-order polynomial motion that begins and ends at zero velocity and zero acceleration.
Example:
tm = 2 t = 0.6 # Output: # 0.16308
- basic_robotics.modern_robotics_numba.modern_high_performance.JointTrajectory(thetastart, thetaend, Tf, N, method)[source]
Computes a straight-line trajectory in joint space.
- Parameters:
thetastart – The initial joint variables.
thetaend – The final joint variables.
Tf – Total time of the motion in seconds from rest to rest.
N – The number of points N > 1 (Start and stop) in the discrete representation of the trajectory.
method – The time-scaling method, where 3 indicates cubic (third-order polynomial) time scaling and 5 indicates quintic (fifth-order polynomial) time scaling.
- Returns:
A trajectory as an N x n matrix, where each row is an n-vector of joint variables at an instant in time. The first row is thetastart and the Nth row is thetaend. The elapsed time between each row is Tf / (N - 1).
Example:
thetastart = np.array([1, 0, 0, 1, 1, 0.2, 0, 1]) thetaend = np.array([1.2, 0.5, 0.6, 1.1, 2, 2, 0.9, 1]) tm = 4 N = 6 method = 3 # Output: # np.array([[ 1, 0, 0, 1, 1, 0.2, 0, 1] # [1.0208, 0.052, 0.0624, 1.0104, 1.104, 0.3872, 0.0936, 1] # [1.0704, 0.176, 0.2112, 1.0352, 1.352, 0.8336, 0.3168, 1] # [1.1296, 0.324, 0.3888, 1.0648, 1.648, 1.3664, 0.5832, 1] # [1.1792, 0.448, 0.5376, 1.0896, 1.896, 1.8128, 0.8064, 1] # [ 1.2, 0.5, 0.6, 1.1, 2, 2, 0.9, 1]])
- basic_robotics.modern_robotics_numba.modern_high_performance.ScrewTrajectory(Xstart, Xend, Tf, N, method)[source]
Computes a trajectory as a list of N SE(3) matrices corresponding to the screw motion about a space screw axis.
- Parameters:
Xstart – The initial end-effector configuration.
Xend – The final end-effector configuration.
Tf – Total time of the motion in seconds from rest to rest.
N – The number of points N > 1 (Start and stop) in the discrete representation of the trajectory.
method – The time-scaling method, where 3 indicates cubic (third-order polynomial) time scaling and 5 indicates quintic (fifth-order polynomial) time scaling.
- Returns:
The discretized trajectory as a list of N matrices in SE(3) separated in time by Tf/(N-1). The first in the list is Xstart and the Nth is Xend.
Example:
Xstart = np.array([[1, 0, 0, 1], [0, 1, 0, 0], [0, 0, 1, 1], [0, 0, 0, 1]]) Xend = np.array([[0, 0, 1, 0.1], [1, 0, 0, 0], [0, 1, 0, 4.1], [0, 0, 0, 1]]) tm = 5 N = 4 method = 3 # Output: # [np.array([[1, 0, 0, 1] # [0, 1, 0, 0] # [0, 0, 1, 1] # [0, 0, 0, 1]]), # np.array([[0.904, -0.25, 0.346, 0.441] # [0.346, 0.904, -0.25, 0.529] # [-0.25, 0.346, 0.904, 1.601] # [ 0, 0, 0, 1]]), # np.array([[0.346, -0.25, 0.904, -0.117] # [0.904, 0.346, -0.25, 0.473] # [-0.25, 0.904, 0.346, 3.274] # [ 0, 0, 0, 1]]), # np.array([[0, 0, 1, 0.1] # [1, 0, 0, 0] # [0, 1, 0, 4.1] # [0, 0, 0, 1]])]
- basic_robotics.modern_robotics_numba.modern_high_performance.CartesianTrajectory(Xstart, Xend, Tf, N, method)[source]
Computes a trajectory as a list of N SE(3) matrices corresponding to the origin of the end-effector frame following a straight line.
This function is similar to ScrewTrajectory, except the origin of the end-effector frame follows a straight line, decoupled from the rotational motion.
- Parameters:
Xstart – The initial end-effector configuration.
Xend – The final end-effector configuration.
Tf – Total time of the motion in seconds from rest to rest.
N – The number of points N > 1 (Start and stop) in the discrete representation of the trajectory.
method – The time-scaling method, where 3 indicates cubic (third-order polynomial) time scaling and 5 indicates quintic (fifth-order polynomial) time scaling.
- Returns:
The discretized trajectory as a list of N matrices in SE(3) separated in time by Tf/(N-1). The first in the list is Xstart and the Nth is Xend.
Example:
Xstart = np.array([[1, 0, 0, 1], [0, 1, 0, 0], [0, 0, 1, 1], [0, 0, 0, 1]]) Xend = np.array([[0, 0, 1, 0.1], [1, 0, 0, 0], [0, 1, 0, 4.1], [0, 0, 0, 1]]) tm = 5 N = 4 method = 5 # Output: # [np.array([[1, 0, 0, 1] # [0, 1, 0, 0] # [0, 0, 1, 1] # [0, 0, 0, 1]]), # np.array([[ 0.937, -0.214, 0.277, 0.811] # [ 0.277, 0.937, -0.214, 0] # [-0.214, 0.277, 0.937, 1.651] # [ 0, 0, 0, 1]]), # np.array([[ 0.277, -0.214, 0.937, 0.289] # [ 0.937, 0.277, -0.214, 0] # [-0.214, 0.937, 0.277, 3.449] # [ 0, 0, 0, 1]]), # np.array([[0, 0, 1, 0.1] # [1, 0, 0, 0] # [0, 1, 0, 4.1] # [0, 0, 0, 1]])]
- basic_robotics.modern_robotics_numba.modern_high_performance.ComputedTorque(thetalist, dthetalist, eint, g, Mlist, Glist, Slist, thetalistd, dthetalistd, ddthetalistd, Kp, Ki, Kd)[source]
Computes the joint control torques at a particular time instant.
- Parameters:
thetalist – n-vector of joint variables.
dthetalist – n-vector of joint rates.
eint – n-vector of the time-integral of joint errors.
g – Gravity vector g.
Mlist – List of link frames {i} relative to {i-1} at the home position.
Glist – Spatial inertia matrices Gi of the links.
Slist – Screw axes Si of the joints in a space frame, in the format of a matrix with axes as the columns.
thetalistd – n-vector of reference joint variables.
dthetalistd – n-vector of reference joint velocities.
ddthetalistd – n-vector of reference joint accelerations.
Kp – The feedback proportional gain (identical for each joint).
Ki – The feedback integral gain (identical for each joint).
Kd – The feedback derivative gain (identical for each joint).
- Returns:
The vector of joint forces/torques computed by the feedback linearizing controller at the current instant.
Example:
thetalist = np.array([0.1, 0.1, 0.1]) dthetalist = np.array([0.1, 0.2, 0.3]) eint = np.array([0.2, 0.2, 0.2]) g = np.array([0, 0, -9.8]) M01 = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0.089159], [0, 0, 0, 1]]) M12 = np.array([[ 0, 0, 1, 0.28], [ 0, 1, 0, 0.13585], [-1, 0, 0, 0], [ 0, 0, 0, 1]]) M23 = np.array([[1, 0, 0, 0], [0, 1, 0, -0.1197], [0, 0, 1, 0.395], [0, 0, 0, 1]]) M34 = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0.14225], [0, 0, 0, 1]]) G1 = np.diag([0.010267, 0.010267, 0.00666, 3.7, 3.7, 3.7]) G2 = np.diag([0.22689, 0.22689, 0.0151074, 8.393, 8.393, 8.393]) G3 = np.diag([0.0494433, 0.0494433, 0.004095, 2.275, 2.275, 2.275]) Glist = np.array([G1, G2, G3]) Mlist = np.array([M01, M12, M23, M34]) Slist = np.array([[1, 0, 1, 0, 1, 0], [0, 1, 0, -0.089, 0, 0], [0, 1, 0, -0.089, 0, 0.425]]).T thetalistd = np.array([1.0, 1.0, 1.0]) dthetalistd = np.array([2, 1.2, 2]) ddthetalistd = np.array([0.1, 0.1, 0.1]) Kp = 1.3 Ki = 1.2 Kd = 1.1 # Output: # np.array([133.00525246, -29.94223324, -3.03276856])
- basic_robotics.modern_robotics_numba.modern_high_performance.SimulateControl(thetalist, dthetalist, g, Ftipmat, Mlist, Glist, Slist, thetamatd, dthetamatd, ddthetamatd, gtilde, Mtildelist, Gtildelist, Kp, Ki, Kd, dt, intRes)[source]
Simulates the computed torque controller over a given desired trajectory.
The end of this function plots all the actual and desired joint angles using matplotlib and random libraries.
- Parameters:
thetalist – n-vector of initial joint variables.
dthetalist – n-vector of initial joint velocities.
g – Actual gravity vector g.
Ftipmat – An N x 6 matrix of spatial forces applied by the end-effector (If there are no tip forces the user should input a zero and a zero matrix will be used).
Mlist – Actual list of link frames i relative to i-1 at the home position.
Glist – Actual spatial inertia matrices Gi of the links.
Slist – Screw axes Si of the joints in a space frame, in the format of a matrix with axes as the columns.
thetamatd – An Nxn matrix of desired joint variables from the reference trajectory.
dthetamatd – An Nxn matrix of desired joint velocities.
ddthetamatd – An Nxn matrix of desired joint accelerations.
gtilde – The gravity vector based on the model of the actual robot (actual values given above).
Mtildelist – The link frame locations based on the model of the actual robot (actual values given above).
Gtildelist – The link spatial inertias based on the model of the actual robot (actual values given above).
Kp – The feedback proportional gain (identical for each joint).
Ki – The feedback integral gain (identical for each joint).
Kd – The feedback derivative gain (identical for each joint).
dt – The timestep between points on the reference trajectory.
intRes – Integration resolution is the number of times integration (Euler) takes places between each time step. Must be an integer value greater than or equal to 1.
- Returns:
taumat –
- An Nxn matrix of the controller’s commanded joint
forces/torques, where each row of n forces/torques corresponds to a single time instant.
thetamat: An Nxn matrix of actual joint angles.
Example:
from __future__ import print_function import numpy as np from modern_robotics import JointTrajectory thetalist = np.array([0.1, 0.1, 0.1]) dthetalist = np.array([0.1, 0.2, 0.3]) # Initialize robot description (Example with 3 links) g = np.array([0, 0, -9.8]) M01 = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0.089159], [0, 0, 0, 1]]) M12 = np.array([[ 0, 0, 1, 0.28], [ 0, 1, 0, 0.13585], [-1, 0, 0, 0], [ 0, 0, 0, 1]]) M23 = np.array([[1, 0, 0, 0], [0, 1, 0, -0.1197], [0, 0, 1, 0.395], [0, 0, 0, 1]]) M34 = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0.14225], [0, 0, 0, 1]]) G1 = np.diag([0.010267, 0.010267, 0.00666, 3.7, 3.7, 3.7]) G2 = np.diag([0.22689, 0.22689, 0.0151074, 8.393, 8.393, 8.393]) G3 = np.diag([0.0494433, 0.0494433, 0.004095, 2.275, 2.275, 2.275]) Glist = np.array([G1, G2, G3]) Mlist = np.array([M01, M12, M23, M34]) Slist = np.array([[1, 0, 1, 0, 1, 0], [0, 1, 0, -0.089, 0, 0], [0, 1, 0, -0.089, 0, 0.425]]).T dt = 0.01 # Create a trajectory to follow thetaend = np.array([np.pi / 2, np.pi, 1.5 * np.pi]) tm = 1 N = int(1.0 * tm/ dt) method = 5 traj = mr.JointTrajectory(thetalist, thetaend, Tf, N, method) thetamatd = np.array(traj).copy() dthetamatd = np.zeros((N, 3)) ddthetamatd = np.zeros((N, 3)) dt = tm/ (N - 1.0) for i in range(np.array(traj).shape[0] - 1): dthetamatd[i + 1, :] = (thetamatd[i + 1, :] - thetamatd[i, :]) / dt ddthetamatd[i + 1, :] = (dthetamatd[i + 1, :] - dthetamatd[i, :]) / dt # Possibly wrong robot description (Example with 3 links) gtilde = np.array([0.8, 0.2, -8.8]) Mhat01 = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0.1], [0, 0, 0, 1]]) Mhat12 = np.array([[ 0, 0, 1, 0.3], [ 0, 1, 0, 0.2], [-1, 0, 0, 0], [ 0, 0, 0, 1]]) Mhat23 = np.array([[1, 0, 0, 0], [0, 1, 0, -0.2], [0, 0, 1, 0.4], [0, 0, 0, 1]]) Mhat34 = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0.2], [0, 0, 0, 1]]) Ghat1 = np.diag([0.1, 0.1, 0.1, 4, 4, 4]) Ghat2 = np.diag([0.3, 0.3, 0.1, 9, 9, 9]) Ghat3 = np.diag([0.1, 0.1, 0.1, 3, 3, 3]) Gtildelist = np.array([Ghat1, Ghat2, Ghat3]) Mtildelist = np.array([Mhat01, Mhat12, Mhat23, Mhat34]) Ftipmat = np.ones((np.array(traj).shape[0], 6)) Kp = 20 Ki = 10 Kd = 18 intRes = 8 taumat, thetamat = mr.SimulateControl(thetalist, dthetalist, g, Ftipmat, Mlist, Glist, Slist, thetamatd, dthetamatd, ddthetamatd, gtilde, Mtildelist, Gtildelist, Kp, Ki, Kd, dt, intRes)