bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
bitsim::kinematics

Forward and inverse kinematics of serial arms. Needs bitsim built with Chrono. More...

Classes

struct  bitsim::kinematics::DHRow
 One row of a Denavit-Hartenberg table: the pose of a joint frame in the one before it is \(R_z(\theta)\, T_z(d)\, T_x(a)\, R_x(\alpha)\). More...
struct  bitsim::kinematics::PlanarArm
 A planar arm with two links that moves in the xy plane, like a SCARA arm seen from above. Joint 1 is at the origin of the world, and both joints turn about z. More...
struct  bitsim::kinematics::SpatialArm
 An arm with three revolute joints. Joint 1 turns the arm about the vertical axis at height h0; joints 2 and 3, the shoulder and the elbow, turn about horizontal axes, so the upper arm and the forearm move in a vertical plane. More...
struct  bitsim::kinematics::IKResult
 The result of numerical_ik. More...

Typedefs

using bitsim::kinematics::PlanarJoints = std::array<real_t, 2>
 The angles of the two joints of a PlanarArm [rad].
using bitsim::kinematics::SpatialJoints = std::array<real_t, 3>
 The angles of the three joints of a SpatialArm [rad].
using bitsim::kinematics::IKObserver = std::function<void(int, const SpatialJoints &, real_t)>
 Called by numerical_ik at every iteration with the iteration, the joint angles and the error [m], for example to print the progress.

Functions

chrono::ChFrame bitsim::kinematics::dh_frame (const DHRow &row)
 \(R_z(\theta)\, T_z(d)\, T_x(a)\, R_x(\alpha)\)
chrono::ChFrame bitsim::kinematics::dh_fk (const std::vector< DHRow > &table)
 The product of the frames of all the rows: the pose of the last frame in the first.
std::vector< DHRow > bitsim::kinematics::spatial_dh_table (const SpatialArm &arm, const SpatialJoints &q)
 The Denavit-Hartenberg table of a SpatialArm at joint angles q. dh_fk of it is spatial_fk.
chrono::ChFrame bitsim::kinematics::joint_rotation (real_t q)
 The frame of a revolute joint turned by q [rad] about its z axis: a rotation, with no offset.
ChVector3d bitsim::kinematics::planar_fk (const PlanarArm &arm, const PlanarJoints &q)
 Where the tip is, written out with trigonometry: \(x = l_1 \cos q_1 + l_2 \cos(q_1 + q_2)\), \(y = l_1 \sin q_1 + l_2 \sin(q_1 + q_2)\).
ChFrame bitsim::kinematics::planar_fk_frames (const PlanarArm &arm, const PlanarJoints &q)
 The pose of the tip as a chain of frames, \(X_{WE} = X_{W1} X_{12} X_{2E}\): each joint adds a rotation about z, each link an offset along x.
std::vector< PlanarJoints > bitsim::kinematics::planar_ik (const PlanarArm &arm, real_t x, real_t y)
 The joint angles that put the tip at (x, y), from the law of cosines.
RealMat2d bitsim::kinematics::planar_jacobian (const PlanarArm &arm, const PlanarJoints &q)
 The Jacobian \(\partial(x, y) / \partial(q_1, q_2)\). It is singular when \(\sin q_2 = 0\): the arm fully stretched or folded.
std::vector< ChFrame<> > bitsim::kinematics::spatial_fk_all (const SpatialArm &arm, const SpatialJoints &q)
 The pose in the world of every joint frame, followed by the end-effector: \(X_{W1}, X_{W2}, X_{W3}, X_{WE}\).
ChFrame bitsim::kinematics::spatial_fk (const SpatialArm &arm, const SpatialJoints &q)
 The pose of the end-effector in the world, \(X_{WE}\).
std::vector< SpatialJoints > bitsim::kinematics::spatial_ik (const SpatialArm &arm, const chrono::ChVector3d &p_W)
 All the joint angles that put the end-effector at p_W.
std::optional< SpatialJoints > bitsim::kinematics::spatial_ik_elbow_up (const SpatialArm &arm, const chrono::ChVector3d &p_W)
 The solution facing the target with the elbow up, or nothing when p_W is out of reach.
RealMat3d bitsim::kinematics::numerical_jacobian (const SpatialArm &arm, const SpatialJoints &q)
 The Jacobian \(\partial(x, y, z) / \partial(q_1, q_2, q_3)\) of the end-effector's position by central differences. It needs only the forward kinematics.
IKResult bitsim::kinematics::numerical_ik (const SpatialArm &arm, const chrono::ChVector3d &target, SpatialJoints q0, real_t damping, int max_iterations=100, real_t tolerance=1.0e-6, real_t max_step=0.5, const IKObserver &observer={})
 Inverse kinematics by iteration from q0: \(q \leftarrow q + \Delta q\) until the end-effector is within tolerance of the target.

Detailed Description

Forward and inverse kinematics of serial arms. Needs bitsim built with Chrono.

Poses follow the convention of the frames examples: \(X_{AB}\) is the pose of frame B expressed in frame A, so that \(X_{WR} X_{RS} = X_{WS}\). Every joint is revolute and turns about its own z axis, as Chrono's rotational motors do.

Typedef Documentation

◆ IKObserver

using bitsim::kinematics::IKObserver = std::function<void(int, const SpatialJoints &, real_t)>

Called by numerical_ik at every iteration with the iteration, the joint angles and the error [m], for example to print the progress.

◆ PlanarJoints

using bitsim::kinematics::PlanarJoints = std::array<real_t, 2>

The angles of the two joints of a PlanarArm [rad].

◆ SpatialJoints

using bitsim::kinematics::SpatialJoints = std::array<real_t, 3>

The angles of the three joints of a SpatialArm [rad].

Function Documentation

◆ dh_fk()

ChFrame bitsim::kinematics::dh_fk ( const std::vector< DHRow > & table)

The product of the frames of all the rows: the pose of the last frame in the first.

◆ dh_frame()

ChFrame bitsim::kinematics::dh_frame ( const DHRow & row)

\(R_z(\theta)\, T_z(d)\, T_x(a)\, R_x(\alpha)\)

◆ joint_rotation()

ChFrame bitsim::kinematics::joint_rotation ( real_t q)

The frame of a revolute joint turned by q [rad] about its z axis: a rotation, with no offset.

◆ numerical_ik()

IKResult bitsim::kinematics::numerical_ik ( const SpatialArm & arm,
const chrono::ChVector3d & target,
SpatialJoints q0,
real_t damping,
int max_iterations = 100,
real_t tolerance = 1.0e-6,
real_t max_step = 0.5,
const IKObserver & observer = {} )

Inverse kinematics by iteration from q0: \(q \leftarrow q + \Delta q\) until the end-effector is within tolerance of the target.

With damping \(\lambda = 0\) the step is Newton's, \(\Delta q = J^{-1} e\); otherwise it is damped least squares, \(\Delta q = J^T (J J^T + \lambda^2 I)^{-1} e\), which stays finite near a singular J. No joint turns by more than max_step [rad] in one step. The iteration stops too when the arm stops moving, which is the best it can do for a target out of reach

◆ numerical_jacobian()

RealMat3d bitsim::kinematics::numerical_jacobian ( const SpatialArm & arm,
const SpatialJoints & q )

The Jacobian \(\partial(x, y, z) / \partial(q_1, q_2, q_3)\) of the end-effector's position by central differences. It needs only the forward kinematics.

◆ planar_fk()

chrono::ChVector3d bitsim::kinematics::planar_fk ( const PlanarArm & arm,
const PlanarJoints & q )

Where the tip is, written out with trigonometry: \(x = l_1 \cos q_1 + l_2 \cos(q_1 + q_2)\), \(y = l_1 \sin q_1 + l_2 \sin(q_1 + q_2)\).

◆ planar_fk_frames()

chrono::ChFrame bitsim::kinematics::planar_fk_frames ( const PlanarArm & arm,
const PlanarJoints & q )

The pose of the tip as a chain of frames, \(X_{WE} = X_{W1} X_{12} X_{2E}\): each joint adds a rotation about z, each link an offset along x.

◆ planar_ik()

std::vector< PlanarJoints > bitsim::kinematics::planar_ik ( const PlanarArm & arm,
real_t x,
real_t y )

The joint angles that put the tip at (x, y), from the law of cosines.

Returns
no solution when (x, y) is out of reach, otherwise the two solutions with the elbow on either side, elbow angle positive first. When the arm is fully stretched or folded the two are the same and only one is returned. The angles are in \((-\pi, \pi]\)

◆ planar_jacobian()

RealMat2d bitsim::kinematics::planar_jacobian ( const PlanarArm & arm,
const PlanarJoints & q )

The Jacobian \(\partial(x, y) / \partial(q_1, q_2)\). It is singular when \(\sin q_2 = 0\): the arm fully stretched or folded.

◆ spatial_dh_table()

std::vector< DHRow > bitsim::kinematics::spatial_dh_table ( const SpatialArm & arm,
const SpatialJoints & q )

The Denavit-Hartenberg table of a SpatialArm at joint angles q. dh_fk of it is spatial_fk.

◆ spatial_fk()

chrono::ChFrame bitsim::kinematics::spatial_fk ( const SpatialArm & arm,
const SpatialJoints & q )

The pose of the end-effector in the world, \(X_{WE}\).

◆ spatial_fk_all()

std::vector< chrono::ChFrame<> > bitsim::kinematics::spatial_fk_all ( const SpatialArm & arm,
const SpatialJoints & q )

The pose in the world of every joint frame, followed by the end-effector: \(X_{W1}, X_{W2}, X_{W3}, X_{WE}\).

◆ spatial_ik()

std::vector< SpatialJoints > bitsim::kinematics::spatial_ik ( const SpatialArm & arm,
const chrono::ChVector3d & p_W )

All the joint angles that put the end-effector at p_W.

Joint 1 points the vertical plane of the arm at the target, and in that plane the shoulder and the elbow are a PlanarArm. The arm can also turn its back to the target and reach over its head, so there are up to four solutions; none when p_W is out of reach

◆ spatial_ik_elbow_up()

std::optional< SpatialJoints > bitsim::kinematics::spatial_ik_elbow_up ( const SpatialArm & arm,
const chrono::ChVector3d & p_W )

The solution facing the target with the elbow up, or nothing when p_W is out of reach.