basic_robotics.kinematics.arm_model module

Model a Serial Arm.

Primarily uses functions from Modern Robotics (Lynch).

class basic_robotics.kinematics.arm_model.Arm(base_pos_global: tm, screw_list: ndarray[float], end_effector_home: tm, joint_poses_home: list[tm], joint_axes: ndarray[float] = None)[source]

Bases: Robot

Models a Serial Arm.

__init__(base_pos_global: tm, screw_list: ndarray[float], end_effector_home: tm, joint_poses_home: list[tm], joint_axes: ndarray[float] = None) → Arm[source]

Create a new Arm Instance.

Parameters:
  • base_pos_global (tm) – Base link position of the arm.

  • screw_list (np.ndarray[float]) – Screw list in the global space

  • end_effector_home (tm) – End effector pose in global space

  • joint_poses_home (list[tm]) – Joint poses in global space

  • joint_axes (np.ndarray[float], optional) – Joint Axes list. Defaults to None.

Returns:

Arm – New Serial arm.

initialize(base_pos_global: tm, screw_list: ndarray[float], end_effector_home: tm, joint_poses_home: list[tm]) → None[source]

Initialize internal elements of the serial arm.

Used when creating a new arm, and when moving it from one location to another.

Parameters:
  • base_pos_global (tm) – Base location of the arm.

  • screw_list (np.ndarray[float]) – Screw list in the global space.

  • end_effector_home (tm) – End effector home in global space.

  • joint_poses_home (list[tm]) – Joint poses in the global space.

thetaProtector(theta: ndarray[float]) → ndarray[float][source]

Ensure thetas are within joint mins and maxes.

Parameters:

theta (np.ndarray[float]) – Input thetas.

Returns:

np.ndarray[float] – Output protected thetas.

FK(theta: ndarray[float], protect: bool = False) → tm[source]

Perform Forward Kinematics, yielding an end effector transform from joint configuration.

Updates internal arm state. :param theta: joint configuration :type theta: np.ndarray[float] :param protect: disable error checking.. Defaults to False. :type protect: bool, optional

Returns:

tm – end effector configuration.

Get a given link origin pose in global space for a given theta configuration.

Parameters:
  • theta (np.ndarray[float]) – joint configuration

  • i (int) – link index

  • protect (bool, optional) – Disable error checking. Defaults to False.

Returns:

tm – Link transform.

FKJoint(theta: ndarray[float], i: int, protect: bool = False) → tm[source]

Get a given joint origin pose in global space for a given theta configuration.

Parameters:
  • theta (np.ndarray[float]) – joint configuration

  • i (int) – joint index

  • protect (bool, optional) – Disable error checking. Defaults to False.

Returns:

tm – joint transform.

IK(goal_position: tm, theta_init: ndarray[float] = None, check: bool = True, level: int = 6, max_iters: int = 30, protect: bool = False)[source]

Calculate joint configuration of an arm to reach a desired end effector configuration.

There may be more than one appropriate configuration depending on the arm. Updates internal arm state. :param goal_position: Goal Position to reach. :type goal_position: tm :param theta_init: Initial Guess Thetas. Defaults to None/use current thetas. :type theta_init: np.ndarray[float], optional :param check: If failure, try again with a different guess. Defaults to True. :type check: bool, optional :param level: Maximum number of guesses. Defaults to 6. :type level: int, optional :param max_iters: Maximum number of iterations per attempt. Defaults to 30. :type max_iters: int, optional :param protect: (bool, optional): Disable error checking. Defaults to False.

Returns:

theta_list (np.ndarray[float]) – solution thetas success (bool): success of the operation.

constrainedIK(goal_position: tm, theta_init: ndarray[float] = None, check: bool = True, level: int = 6, max_iters: int = 30)[source]

Calculate joint positions of a serial arm, provided rotational constraints on the Joints.

All parameters are optional except the desired end effector position Joint constraints are set through the joint_maxs and joint_mins properties, and should be arrays the same size as the number of DOFS

Parameters:
  • goal_position (tm) – Goal Position to reach.

  • theta_init (np.ndarray[float], optional) – Initial Guess Thetas. Defaults to None/use current thetas.

  • check (bool, optional) – If failure, try again with a different guess. Defaults to True.

  • level (int, optional) – Maximum number of guesses. Defaults to 6.

  • max_iters (int, optional) – Maximum number of iterations per attempt. Defaults to 30.

Returns:

theta_list (np.ndarray[float]) – solution thetas success (bool): success of the operation.

IKFree(goal_position: tm, theta_init: ndarray[float], inds)[source]

Perform IK but only allow ‘free_inds’ to be varied.

Method not covered in Lynch. SetElements inserts the variable vector x into the positions indicated by freeinds in theta_init. The remaining elements are unchanged. This function is sensitive to initial conditions. :param goal_position: Desired end effector position to calculate for :param theta_init: Intial theta guess for desired end effector position. :param inds: Free indexes to move

Returns:

theta – list of theta lists success: boolean for success

randomPos() → tm[source]

Generate a random position.

Returns:

tm – Randomly assigned configuration of the end effector.

reverse() → None[source]

Flip the serial arm end-for-end, swapping the base and end effector.

Works from any current joint configuration, not just the arm’s home (all-zero) pose. The arm’s present physical shape is frozen in place as the new home configuration of the reversed chain: the new base is mounted exactly where the end effector currently sits, and the new end effector’s home is set to wherever the base has always been mounted (the base does not move as joints are driven, so this holds no matter what configuration reverse() is called from).

As a direct result:
  • Immediately after reverse(), self._theta is all zeros and getEEPos() exactly equals the base pose the arm had right before this call - for any starting configuration.

  • Calling reverse() again immediately afterwards exactly restores the base pose, end effector home, and screw list that were in effect before the first call.

Only kinematic properties (screw axes, joint homes, theta) are updated. Joint limits/velocity/effort caps are reordered to match the new joint indices but are not otherwise adjusted - they remain relative to each physical joint’s own original home, not to the snapshot taken here. Visual/collision and dynamics properties set via setVisColProperties/setMassProperties/setDynamicsProperties describe the old link order and should be reapplied afterwards if still needed.

lineTrajectory(target: tm, initial: tm = None, execute: bool = True, delt: float = 0.01)[source]

Create a trajectory moving the end effector in a straight line torwards the target.

Parameters:
  • target (tm) – Target configuration

  • initial (tm, optional) – Initial Pose. Defaults to None/Current Pose.

  • execute (bool, optional) – Execute motion, or remain at current config. Defaults to True.

  • delt (float, optional) – Distance of end effector betweene ach pose in meters. Defaults to .01.

Returns:

theta_list (list[np.ndarray[float]]) – List of theta configurations.

PDControlToGoalEE(goal_position: tm, theta: ndarray[float] = None, prev_theta: ndarray[float] = None, p_gain: float = 100.0, d_gain: float = 100.0, max_theta_dot: float = 0.1) → ndarray[float][source]

Use PD Control to move to the goal position.

Parameters:
  • goal_position (tm) – Goal Position

  • theta (np.ndarray[float], optional) – Initial Theta. Defaults to None/Current Position.

  • prev_theta (np.ndarray[float], optional) – previous theta. Defaults to None/Dead stop.

  • p_gain (float, optional) – Proportional Gain. Defaults to 100.0.

  • d_gain (float, optional) – Derivative Gain. Defaults to 100.0.

  • max_theta_dot (float, optional) – Max joint velocity. Defaults to 0.1.

Returns:

np.ndarray[float] – Scaled joint velocities.

setNames(arm_name: str = None, link_names=None, joint_names=None) → None[source]

Set names for Arm elements.

Will use generics if not specified. :param arm_name: Arm name. Defaults to None. :type arm_name: str, optional :param link_names: Names for each link. Defaults to None. :type link_names: list[str], optional :param joint_names: Names for each joint. Defaults to None. :type joint_names: list[str], optional

setJointProperties(joint_mins: ndarray[float] = None, joint_maxs: ndarray[float] = None, max_vels: ndarray[float] = None, max_effort: ndarray[float] = None, max_accels: ndarray[float] = None, max_jerks: ndarray[float] = None) → None[source]

Set joint properties for the arm.

Parameters:
  • joint_mins (np.ndarray[float], optional) – Joint minimum rotations. Defaults to None.

  • joint_maxs (np.ndarray[float], optional) – Joint maximum rotations. Defaults to None.

  • max_vels (np.ndarray[float], optional) – Joint maximum velocities. Defaults to None.

  • max_effort (np.ndarray[float], optional) – Joint maximum efforts/torques. Defaults to None.

  • max_accels (np.ndarray[float], optional) – Joint maximum accelerations, used by timeParametrizePath(). Defaults to None.

  • max_jerks (np.ndarray[float], optional) – Joint maximum jerks, used by timeParametrizePath() for jerk-limited (S-curve) retiming. Defaults to None.

setVisColProperties(vis_props: list = None, col_props: list = None, link_dimensions: ndarray[float] = None) → None[source]

Set visual and collision properties for the arm.

All arguments are optional. :param vis_props: Visual Properties. Defaults to None. :type vis_props: list, optional :param col_props: Collision Properties. Defaults to None. :type col_props: list, optional :param link_dimensions: Link Box Dimensions. Defaults to None. :type link_dimensions: np.ndarray[float], optional

setOrigins(prev_joints_to_next_joints=None, joint_homes_global=None, link_homes_global=None, eef_to_last_joint: tm = None, base_to_fixed_joint: tm = None) → None[source]

Set origins of joints and links for the arm.

Parameters:
  • prev_joints_to_next_joints (list[tm], optional) – Local transforms from one joint to the next. Defaults to None.

  • joint_homes_global (list[tm], optional) – Joint positions in global space. Defaults to None.

  • link_homes_global (list[tm], optional) – Link centers in global space. Defaults to None.

  • eef_to_last_joint (tm, optional) – End effector transform to the last joint. Defaults to None.

  • base_to_fixed_joint (tm, optional) – offset from arm base to actual base. Defaults to None.

setMassProperties(link_masses: ndarray[float] = None, mass_grav_centers=None, box_spatial_links: ndarray[float] = None) → None[source]

Set mass properties for the arm.

Parameters:
  • link_masses (np.ndarray[float], optional) – Link masses in Kg. Defaults to None.

  • mass_grav_centers (list[tm], optional) – Link centers of mass in local frame. Defaults to None.

  • box_spatial_links (np.ndarray[float], optional) – Box spatial inertia. Defaults to None.

testArmValues() → None[source]

Print a detailed description of the arm.

getJointTransforms(return_base: bool = True)[source]

Return joint information for each link in the arm, including the base.

If the end effector is not coincident with the last joint of the arm, returns end effector also, even though it is not a true joint Base return behavior can be disabled by setting ‘return_base’ to false

Parameters:

return_base (bool, optional) – Return the base or not. Defaults to True.

Returns:

list[tm] – list of each joint location.

setArbitraryHome(new_home_global: tm, theta: ndarray[float] = None) → None[source]

Set a new end effector position relative to last joint.

Parameters:
  • new_home_global (tm) – New relative home position

  • theta (np.ndarray[float], optional) – configuration for joints. Defaults to None.

restoreOriginalEE() → None[source]

Restore the original End effector configuration of the arm.

getScrewList() → ndarray[float][source]

Get the space frame screw list for the arm.

Returns:

np.ndarray[float] – space frame screw list.

getLinkDimensions() → ndarray[float][source]

Get box link dimensions for the arm.

Returns:

np.ndarray[float] – Box link dimensions.

staticForcesWithCrossMoments(end_effector_wrench: Wrench = <basic_robotics.general.faser_wrench.Wrench object>, theta: ndarray[float] = None) → ndarray[float][source]

Calculate joint wrenches given an end effector wrench.

Parameters:
  • end_effector_wrench (Wrench, optional) – End effector wrench. Defaults to None.

  • theta (np.ndarray[float], optional) – Joint configuration. Defaults to None.

Returns:

list[wrench] wrenches at each joint

staticForcesWithLinkMasses(end_effector_wrench: Wrench = <basic_robotics.general.faser_wrench.Wrench object>, theta: ndarray[float] = None) → ndarray[float][source]

Calculate joint torques given end effector wrench, and all joint masses.

Parameters:
  • end_effector_wrench (Wrench, optional) – End effector wrench. Defaults to None.

  • theta (np.ndarray[float], optional) – Joint configuration. Defaults to None.

Returns:

np.ndarray[float] – Joint torques of the arm.

inverseDynamicsEMR(theta: ~numpy.ndarray[float], theta_dot: ~numpy.ndarray[float], theta_dot_dot: ~numpy.ndarray[float], grav: ~numpy.ndarray[float] = None, end_effector_wrench: ~basic_robotics.general.faser_wrench.Wrench = <basic_robotics.general.faser_wrench.Wrench object>) → ndarray[float][source]

Inverse Dynamics using Modern Robotics Formulation.

Parameters:
  • theta (np.ndarray[float]) – Joint thetas.

  • theta_dot (np.ndarray[float]) – Joint velocities.

  • theta_dot_dot (np.ndarray[float]) – Joint accelerations

  • grav (np.ndarray[float], optional) – Gravity vector. Defaults to None.

  • end_effector_wrench (Wrench, optional) – End effector wrench. Defaults to None.

Returns:

np.ndarray[float] – Joint torque list (tau)

inverseDynamics(theta: ~numpy.ndarray[float], theta_dot: ~numpy.ndarray[float], theta_dot_dot: ~numpy.ndarray[float], grav: ~numpy.ndarray[float] = None, end_effector_wrench: ~basic_robotics.general.faser_wrench.Wrench = <basic_robotics.general.faser_wrench.Wrench object>)[source]

Inverse Dynamics using Modern Robotics Formulation.

Parameters:
  • theta (np.ndarray[float]) – Joint thetas.

  • theta_dot (np.ndarray[float]) – Joint velocities.

  • theta_dot_dot (np.ndarray[float]) – Joint accelerations

  • grav (np.ndarray[float], optional) – Gravity vector. Defaults to None.

  • end_effector_wrench (Wrench, optional) – End effector wrench. Defaults to None.

Returns:

np.ndarray[float] – Joint torque list (tau)

inverseDynamicsC(theta: ~numpy.ndarray[float], theta_dot: ~numpy.ndarray[float], theta_dot_dot: ~numpy.ndarray[float], grav: ~numpy.ndarray[float] = None, end_effector_wrench: ~basic_robotics.general.faser_wrench.Wrench = <basic_robotics.general.faser_wrench.Wrench object>)[source]

Calculate inverse dynamics according to the algorithm in Lynch 8.4.

Parameters:
  • theta (np.ndarray[float]) – Joint thetas.

  • theta_dot (np.ndarray[float]) – Joint velocities.

  • theta_dot_dot (np.ndarray[float]) – Joint accelerations

  • grav (np.ndarray[float], optional) – Gravity vector. Defaults to None.

  • end_effector_wrench (Wrench, optional) – End effector wrench. Defaults to empty wrench.

Returns:

tau (np.ndarray[float]) – joint torques

forwardDynamicsE(theta: ~numpy.ndarray[float], theta_dot: ~numpy.ndarray[float], tau: ~numpy.ndarray[float], grav: ~numpy.ndarray[float] = None, end_effector_wrench: ~basic_robotics.general.faser_wrench.Wrench = <basic_robotics.general.faser_wrench.Wrench object>)[source]

Calculate forward dynamics sans Modern Robotics.

Parameters:
  • theta (np.ndarray[float]) – Joint configuration

  • theta_dot (np.ndarray[float]) – Joint velocities

  • tau (np.ndarray[float]) – Joint torques

  • grav (np.ndarray[float], optional) – gravity vector. Defaults to None.

  • end_effector_wrench (Wrench, optional) – end effector wrench. Defaults to None.

Returns:

theta_dot_dot (np.ndarray[Float]) – Joint accelerations

forwardDynamics(theta: ~numpy.ndarray[float], theta_dot: ~numpy.ndarray[float], tau: ~numpy.ndarray[float], grav: ~numpy.ndarray[float] = None, end_effector_wrench: ~basic_robotics.general.faser_wrench.Wrench = <basic_robotics.general.faser_wrench.Wrench object>) → ndarray[float][source]

Calculate forward dynamics sans Modern Robotics.

Parameters:
  • theta (np.ndarray[float]) – Joint configuration

  • theta_dot (np.ndarray[float]) – Joint velocities

  • tau (np.ndarray[float]) – Joint torques

  • grav (np.ndarray[float], optional) – gravity vector. Defaults to None.

  • end_effector_wrench (Wrench, optional) – end effector wrench. Defaults to None.

Returns:

theta_dot_dot (np.ndarray[Float]) – Joint accelerations

integrateForwardDynamics(theta0: ~numpy.ndarray[float], thetadot0: ~numpy.ndarray[float], tau: ~numpy.ndarray[float], dt: float = 1.0, grav: ~numpy.ndarray[float] = None, end_effector_wrench: ~basic_robotics.general.faser_wrench.Wrench = <basic_robotics.general.faser_wrench.Wrench object>, t_series: ~numpy.ndarray[float] = None)[source]

Integrate forward kinematics.

Parameters:
  • theta0 (np.ndarray[float]) – Joint configuration init

  • thetadot0 (np.ndarray[float]) – Joint velocity init

  • tau (np.ndarray[float]) – Joint torques init.

  • dt (float, optional) – delta time. Defaults to 1.0.

  • grav (np.ndarray[float], optional) – gravity vector. Defaults to None.

  • end_effector_wrench (Wrench, optional) – end effector wrench. Defaults to Wrench().

  • t_series (np.ndarray[float], optional) – use specified time series. Defaults to None.

Returns:

np.ndarray[float] – joint accelerations

massMatrix(theta: ndarray[float] = None) → ndarray[float][source]

Generate arm mass matrix list.

Parameters:

theta (np.ndarray[float], optional) – joint configuration. Defaults to None.

Returns:

np.ndarray[float] – mass matrix for arm

coriolisGravity(theta: ndarray[float], theta_dot: ndarray[float], grav: ndarray[float]) → ndarray[float][source]

Calculate coriolis Gravity.

Parameters:
  • theta (np.ndarray[float]) – Joint configuration

  • theta_dot (np.ndarray[float]) – Joint acceleration

  • grav (np.ndarray[float]) – Gravity array

Returns:

np.ndarray[float] – Mass matrix for the arm.

jacobian(theta: ndarray[float] = None) → ndarray[float][source]

Calculate Space Jacobian for given configuration.

Parameters:

theta – joint configuration

Returns:

jacobian

jacobianBody(theta: ndarray[float] = None) → ndarray[float][source]

Calculate Body Jacobian for given configuration.

Parameters:

theta – joint configuration

Returns:

jacobian

Calculate Space Jacobian for given configuration link.

Parameters:
  • i – joint index

  • theta – joint configuration

Returns:

jacobian

jacobianEETrans(theta: ndarray[float] = None) → ndarray[float][source]

Calculate Jacobian of the end effector (body), but the frame is rotated to be aligned with the space (global) frame.

Parameters:

theta – joint configuration

Returns:

jacobian

numericalJacobian(theta: ndarray[float] = None) → ndarray[float][source]

Calculate numerical Jacobian for given configuration.

Parameters:

theta – joint configuration

Returns:

jacobian

getManipulability(theta: ndarray[float] = None)[source]

Calculate Manipulability at a given configuration.

Parameters:

theta – configuration

Returns:

Manipulability parameters

move(new_base_pos_global: tm, stationary: bool = False) → None[source]

Move the arm to another location.

Parameters:
  • T – new base location

  • stationary – boolean for keeping the end effector in origianal location while moving the base separately

draw(ax)[source]

Draw the arm using the vis_matplotlib library.

Parameters:

ax – matplotlib axes to plot to.

class basic_robotics.kinematics.arm_model.URDFLoader[source]

Bases: object

Load a URDF into an Arm object.

__init__()[source]

Init a URDFLoader.

basic_robotics.kinematics.arm_model.load_urdf_spec_file(urdf_fname, package_fname)[source]

Return a file path from a urdf specified file.

Parameters:
  • urdf_fname – urdf file name

  • package_fname – package_fname

Returns:

string of the absolute path

basic_robotics.kinematics.arm_model.find_package_dir(urdf_fname, package_rel_dir)[source]

Attempt to find a directory specified by a ros package macro without ROS.

Parameters:
  • urdf_fname – urdf file name/path - must be absolute

  • package_rel_dir – relative package directory

Returns:

string of the absolute file path

basic_robotics.kinematics.arm_model.loadArmFromURDF(file_name)[source]

Load an arm from a URDF File.

Parameters:

file_name – file name of urdf object

Returns:

Arm object