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

Classes

struct  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  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  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  IKResult
 The result of numerical_ik. More...

Typedefs

using PlanarJoints = std::array<real_t, 2>
 The angles of the two joints of a PlanarArm [rad].
using SpatialJoints = std::array<real_t, 3>
 The angles of the three joints of a SpatialArm [rad].
using 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 dh_frame (const DHRow &row)
 \(R_z(\theta)\, T_z(d)\, T_x(a)\, R_x(\alpha)\)
chrono::ChFrame 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 > 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 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 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 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 > 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 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<> > 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 spatial_fk (const SpatialArm &arm, const SpatialJoints &q)
 The pose of the end-effector in the world, \(X_{WE}\).
std::vector< SpatialJoints > spatial_ik (const SpatialArm &arm, const ChVector3d &p_W)
std::optional< SpatialJoints > spatial_ik_elbow_up (const SpatialArm &arm, const ChVector3d &p_W)
RealMat3d 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 numerical_ik (const SpatialArm &arm, const ChVector3d &target, SpatialJoints q0, real_t damping, int max_iterations, real_t tolerance, real_t max_step, const IKObserver &observer)
std::vector< SpatialJoints > 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 > 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.
IKResult 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.
chrono::ChMatrix33d rot_x (real_t angle)
 The rotation by angle [rad] about the x axis. It leaves the x axis unchanged:
chrono::ChMatrix33d rot_z (real_t angle)
 The rotation by angle [rad] about the z axis.
real_t wrap_angle (real_t angle)
 The angle [rad] wrapped to \((-\pi, \pi]\), so that angles that differ by whole turns compare equal.

Function Documentation

◆ numerical_ik()

IKResult bitsim::kinematics::numerical_ik ( const SpatialArm & arm,
const ChVector3d & target,
SpatialJoints q0,
real_t damping,
int max_iterations,
real_t tolerance,
real_t max_step,
const IKObserver & observer )

◆ rot_x()

chrono::ChMatrix33d bitsim::geometry::rot_x ( real_t angle)

The rotation by angle [rad] about the x axis. It leaves the x axis unchanged:

\[R_x(\theta) = \begin{bmatrix} 1 & 0 & 0 \\ 0 & \cos\theta & -\sin\theta \\ 0 & \sin\theta & \cos\theta \end{bmatrix} \]

◆ rot_z()

chrono::ChMatrix33d bitsim::geometry::rot_z ( real_t angle)

The rotation by angle [rad] about the z axis.

\[R_z(\theta) = \begin{bmatrix} \cos\theta & -\sin\theta & 0 \\ \sin\theta & \cos\theta & 0 \\ 0 & 0 & 1 \end{bmatrix} \]

◆ spatial_ik()

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

◆ spatial_ik_elbow_up()

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

◆ wrap_angle()

The angle [rad] wrapped to \((-\pi, \pi]\), so that angles that differ by whole turns compare equal.