basic_robotics.kinematics.sp_model module

Holding file for Stewart Platform specific functions, notably the SP class.

class basic_robotics.kinematics.sp_model.SP(bottom_joints: ndarray[float], top_joints: ndarray[float], bT: tm, tT: tm, leg_ext_min: float, leg_ext_max: float, bottom_plate_thickness: float, top_plate_thickness: float, name: str)[source]

Bases: Robot

Models a stewart platform.

__init__(bottom_joints: ndarray[float], top_joints: ndarray[float], bT: tm, tT: tm, leg_ext_min: float, leg_ext_max: float, bottom_plate_thickness: float, top_plate_thickness: float, name: str) → SP[source]

Initialize a new Stewart Platform Object.

Parameters:
  • bottom_joints (ndarray) – Bottom joint positions of the stewart platform

  • top_joints (ndarray) – Top joint positions of the stewart platform

  • bT (tm) – bottom plate position

  • tT (tm) – top plate position

  • leg_ext_min (float) – minimum leg ext limit

  • leg_ext_max (float) – maximum leg ext limit

  • bottom_plate_thickness (float) – bottom plate thickness

  • top_plate_thickness (float) – top plate thickness

  • name (string) – name of the sp

Returns:

SP – sp model object

setDrawingParameters(top_plate_radius: float = None, bottom_plate_radius: float = None, act_shaft_radius: float = None, act_motor_radius: float = None) → None[source]

Set drawing parameters for stewart platform.

Primarily used by 3JS visualizer. Values set here (such as plate radius) have no effect on kinematics. :param top_plate_radius: Top plate radius (m). Defaults to None. :type top_plate_radius: float, optional :param bottom_plate_radius: Bottom plate radius (m). Defaults to None. :type bottom_plate_radius: float, optional :param act_shaft_radius: Actuator shaft radius (m). Defaults to None. :type act_shaft_radius: float, optional :param act_motor_radius: Actuator motor radius (m). Defaults to None. :type act_motor_radius: float, optional

setMasses(plate_mass_general: float, act_shaft_mass: float, act_motor_mass: float, grav: ndarray[float] = array([0., 0., -9.81]), top_plate_mass: float = 0.0) → None[source]

Set SP Masses and gravity vector.

share plates, these weights are halved with respect to end plates :param plate_mass_general: mass of bottom plate (both if top is not specified) (kg) :type plate_mass_general: float :param act_shaft_mass: mass of actuator shaft (kg) :type act_shaft_mass: float :param act_motor_mass: mass of actuator motor (kg) :type act_motor_mass: float :param grav: [Optional, default 9.81] acceleration due to gravity :type grav: np.ndarray[float] :param top_plate_mass: [Optional, default 0] top plate mass (kg) :type top_plate_mass: float

setCOG(motor_grav_center: float, shaft_grav_center: float) → None[source]

Set the centers of gravity for actuator components.

Parameters:
  • motor_grav_center (float) – distance from top of actuator to actuator shaft COG

  • shaft_grav_center (float) – distance from bottom of actuator to actuator motor COG

setMaxAngleDev(max_angle_dev: float = 1.0, degrees: bool = True) → None[source]

Set the maximum angle joints can deflect before failure.

Parameters:
  • max_angle_dev (float, Optional) – maximum deflection angle. Default 1.0 radians.

  • degrees (bool, Optional) – use degrees instead. Defaults to true.

setMaxPlateRotation(max_plate_rotation: float = 1.25, degrees: bool = False) → True[source]

Set the maximum angle the plate can rotate before failure.

Parameters:
  • max_plate_rotation (Float) – Maximum angle before plate rotation failure. Default 1.25 radians.

  • degrees (bool, Optional) – use degrees instead. Defaults to true.

setNames(sp_name: str = None, leg_names: list = None) → None[source]

Set names for SP elements.

Will use generics if not specified. :param sp_name: SP name. Defaults to None. :type sp_name: str, optional :param leg_names: Names for each leg/actuator. Defaults to None. :type leg_names: list[str], optional

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

Set actuator (leg) motion limits for the platform.

Mirrors Arm.setJointProperties. Leg extension limits (leg_ext_min/leg_ext_max) are set at construction time and are not touched here. :param max_vels: Leg maximum extension velocities. Defaults to None. :type max_vels: np.ndarray[float], optional :param max_effort: Leg maximum forces (N). Defaults to None. :type max_effort: np.ndarray[float], optional :param max_accels: Leg maximum accelerations, used by

timeParametrizePath(). Defaults to None.

Parameters:

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

setTopPlateInertia(top_plate_inertia: ndarray[float]) → None[source]

Set the rotational inertia tensor of the top (moving) plate, about its own origin/COM, expressed in the top plate’s local (body) frame.

Used by massMatrix/inverseDynamics/forwardDynamics. Defaults to the zero matrix (a point-mass platform with no rotational inertia), matching the point-mass treatment already implicit in carryMassCalc’s gravity wrenches. :param top_plate_inertia: 3x3 rotational inertia tensor (kg*m^2). :type top_plate_inertia: np.ndarray[float]

getBottomJoints() → ndarray[float][source]

Get the bottom joint positions in space.

Does not return orientation, only position.

Returns:

ndarray(Float) – bottom joint positions

getTopJoints() → ndarray[float][source]

Get the top joint positions in space.

Does not return orientation, only position. :returns: ndarray(Float) – top joint positions in space

getCurrentLocalTransform() → tm[source]

Get the current local transform from the bottom plate to the top plate.

Returns:

tm – Top plate relative to bottom plate

getLens() → ndarray[float][source]

Get Actuator lengths in meters (joint to joint).

Returns:

ndarray(Float) – Actuator lengths in meters.

getTopT() → float[source]

Return the global frame transform of the top plate.

Synonymous with getEEPos(), and will be removed eventuallly.

Returns:

tm – top plate transform in space frame

getBottomT() → float[source]

Return the global frame transform of the bottom plate.

Synonymous with getBasePos() and will be removed eventually.

Returns:

tm – bottom plate transform in space frame

getActuatorLoc(num: int, type: str = 'm') → tm[source]

Return the position (no orientation) of a specified actuator in the global (space) frame.

Takes in an actuator number and a type. m for actuator midpoint b for actuator motor position t for actuator top position

Parameters:
  • num (Int) – number of actuator to return

  • type (Str) – property of actuator to return

Returns:

tm – location of desired component of an actuator in the global frame.

getJointAnglesFromNorm() → ndarray[float][source]

Return the angular deviation of each angle socket from its nominal position in radians.

Returns:

ndarray(Float) – Angular deviation from home of each joint socket

getJointAnglesFromVertical()[source]

Calculate joint angles from vertical at each joint.

Returns:

ndarray(Float) – top joints from vertical (downward) ndarray(Float): bottom joints from vertical (upward)

randomPos(max_attempts=100, min_deviation=0.3141592653589793)[source]

Generate a random configuration.

Parameters:
  • max_attempts (int, optional) – Maximum attempts before giving up. Defaults to 100.

  • min_deviation (float, optional) – Minimum acceptable angular deviation (avoids ‘home-like’ poses). Defaults to np.pi/10.

Returns:

tm – new top pose in global space

spinCustom(rot: float, degrees: bool = False) → None[source]

Rotate platform by radian amount while maintaining orientation in global space.

This function is useful for setting an initial coordinate alignment with the platform relative to global space that is not generated by default upon loading the platform. This function is NOT absolute, instead relative, so to undo a rotation, one would Need to apply the inverse rotation (e.g. -pi/4 to counteract a pi/4 rotation.) :param rot: rotation in radians (clockwise) :type rot: Float :param degrees: use degrees instead of radians :type degrees: bool

IK(top_plate_pos: tm = None, bottom_plate_pos: tm = None, protect: bool = False)[source]

Calculate inverse kinematics for given goals.

Parameters:
  • top_plate_pos (tm) – top plate position

  • bottom_plate_pos (tm) – bottom plate position

  • protect (bool) – If true, bypass any safeties

Returns:

ndarray(float) – leg lengths bool: validity of pose

FK(L, plate_pos=None, reverse=False, protect=False, fk_mode=None)[source]

Calculate Forward Kinematics for desired leg lengths (joint to joint).

Parameters:
  • L (ndarray(Float)) – Goal leg lengths

  • plate_pos (tm) – Fixed plate location

  • reverse (Bool) – Boolean to reverse action. If true, treat the top plate as stationary.

  • protect (Bool) – Boolean to bypass error detection and correction. Bypass if True

Returns:

tm – top plate configuration Bool: validity

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

Create a trajectory moving the top plate in a straight line towards the target.

Parameters:
  • target (tm) – Target top plate configuration

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

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

  • delt (float, optional) – Distance of top plate between each pose in meters. Defaults to .01.

Returns:

leg_lengths_list (list[np.ndarray[float]]) – List of leg length configurations.

reverse() → None[source]

Flip the stewart platform, swapping which plate is the fixed base and which is the moving top plate.

Works from any current configuration, not just the platform’s nominal home pose. The platform’s present physical shape is frozen in place: the new base is mounted exactly where the top plate currently sits, and the new top plate’s pose is set to wherever the base has always been mounted (the base does not move as legs are actuated, so this holds no matter what configuration reverse() is called from).

Because the “motor” (fixed-side) and “shaft” (moving-side) portions of each actuator swap which physical side they’re on, actuator masses and centers of gravity are swapped along with the joint geometry. Drawing parameters and plate masses are swapped correspondingly.

Calling reverse() again immediately afterwards exactly restores the joint geometry, plate masses/thickness, actuator COG, and drawing parameters that were in effect before the first call.

Because this is implemented by rerunning the constructor, any other customization (debug, validation_settings, fk_mode, joint_deflection_max, plate_rotation_limit, top plate inertia, cameras, force_limit) is reset to its default and should be reapplied afterwards if still needed.

validate(donothing: bool = False, validation_limit: int = 4) → bool[source]

Validate the current configuration of the stewart platform.

Perform corrective action if necessary.

Parameters:
  • donothing (Bool) – If set to true, even if an invalid configuration is detected, will not attempt to correct it

  • validation_limit (Int) – number at which to stop validating. For internal use.

Returns:

Bool – Validity of configuration

validateLegs(valid: bool = True, donothing: bool = False) → bool[source]

Validate leg lengths against leg bounds and perform corrective action if necessary.

Parameters:
  • valid (Bool) – whether to start the validator with an assumption of prior validity

  • donothing (Bool) – If set to true, even if an invalid configuration is detected, will not attempt to correct it

Returns:

Bool – Validity of configuration

validateContinuousTranslation(valid: bool = True, donothing: bool = False) → bool[source]

Validate that the top plate has positive Z in bottom plate’s local frame.

There is no situation where the top plate should be ‘underneath’ the bottom. Performs corrective action if necessary.

Parameters:
  • valid (Bool) – whether to start the validator with an assumption of prior validity

  • donothing (Bool) – If set to true, even if an invalid configuration is detected, will not attempt to correct it

Returns:

Bool – Validity of configuration

validateInteriorAngles(valid: bool = True, donothing: bool = False) → bool[source]

Validate that the interior angles of the legs from normal are within limits.

Perform corrective action if necessary.

Parameters:
  • valid (Bool) – whether to start the validator with an assumption of prior validity

  • donothing (Bool) – If set to true, even if an invalid configuration is detected, will not attempt to correct it

Returns:

Bool – Validity of configuration

validatePlateRotation(valid: bool = True, donothing: bool = False) → bool[source]

Validate that plate rotation is not exceeding bounds.

Perform corrective action if necessary.

Parameters:
  • valid (Bool) – whether to start the validator with an assumption of prior validity

  • donothing (Bool) – If set to true, even if an invalid configuration is detected, will not attempt to correct it

Returns:

Bool – Validity of configuration

inverseJacobian(top_plate_pos: tm = None, bottom_plate_pos: tm = None, protect: bool = True) → ndarray[float][source]

Calculate Inverse Jacobian for stewart platform. Optionally use top and bottom transforms.

Parameters:
  • bottom_plate_pos (tm) – bottom plate transformation in space frame

  • top_plate_pos (tm) – top plate transformation in space frame

  • protect (Bool) – Boolean to bypass error detection and correction. Bypass if True

Returns:

ndarray(Float) – Inverse Jacobian for current configuration

numericalJacobian(top_plate_pos: tm = None, bottom_plate_pos: tm = None, delta: float = 0.0005) → ndarray[float][source]

Calculate numerical inverse Jacobian for given configuration, as a sanity check against inverseJacobian().

Perturbs the top plate pose by a small space-frame twist along each of the 6 screw axis directions and observes the resulting change in leg lengths. (TAA components can’t be perturbed directly for this purpose, since - unlike a serial arm’s joint angles - they aren’t independent generalized coordinates: away from the identity pose, a small TAA change is not the same thing as a small twist.) :param top_plate_pos: top plate transformation in space frame.

Defaults to None/current pose.

Parameters:
  • bottom_plate_pos (tm, optional) – bottom plate transformation in space frame. Defaults to None/current pose.

  • delta (float, optional) – finite-difference twist step size. Defaults to 0.0005.

Returns:

ndarray(Float) – Numerical Inverse Jacobian for current configuration

getManipulability()[source]

Calculate Manipulability at the current configuration.

Returns:

Manipulability parameters

carryMassCalc(twrench: Wrench, protect: bool = False)[source]

Calculate the forces on each actuator given actuator masses, plate masses, and a wrench on the end effector in the global frame.

Use this over the body frame equivalent in most cases, :param twrench: input wrench for configuration :type twrench: ndarray(Float) :param protect: Boolean to bypass error detection and correction. Bypass if True :type protect: Bool

Returns:

ndarray(Float) – forces in Newtons for each leg

carryMassCalcBody(twrench: Wrench, protect: bool = False)[source]

Calculate the forces on each actuator given actuator masses, plate masses, and a wrench in the end effector frame.

Parameters:
  • twrench (ndarray(Float)) – input wrench for configuration

  • protect (Bool) – Boolean to bypass error detection and correction. Bypass if True

Returns:

ndarray(Float) – forces in Newtons for each leg

componentForces(forces: ndarray[float] = None)[source]

Calculate force components for given leg forces.

Parameters:

forces (ndarray(Float)) – force exerted through each leg in Newtons.

Returns:

ndarray(Float) – vertical components of forces ndarray(Float): horizontal components of forces

sumActuatorWrenches(forces: ndarray[float] = None) → Wrench[source]

Sum all actuator wrenches to produce bottom wrench.

Parameters:

forces (ndarray(Float)) – leg forces in Newtons

Returns:

ndarray(Float) – bottom plate wrench

inverseDynamics(angular_vel: ~numpy.ndarray[float], angular_accel: ~numpy.ndarray[float], linear_accel: ~numpy.ndarray[float], grav: ~numpy.ndarray[float] = None, top_plate_wrench: ~basic_robotics.general.faser_wrench.Wrench = <basic_robotics.general.faser_wrench.Wrench object>) → ndarray[float][source]

Calculate actuator forces required to produce a given top plate motion.

Uses the current top/bottom plate pose - call IK/FK first to set the configuration to evaluate. See the “Dynamics” section docstring above for the modeling assumptions. :param angular_vel: top plate angular velocity, space frame (rad/s) :type angular_vel: ndarray(Float) :param angular_accel: top plate angular acceleration, space frame (rad/s^2) :type angular_accel: ndarray(Float) :param linear_accel: linear acceleration of the top plate origin,

space frame (m/s^2)

Parameters:
  • grav (ndarray(Float), optional) – gravity vector. Defaults to self.grav.

  • top_plate_wrench (Wrench, optional) – additional externally applied wrench at the top plate (e.g. a payload load). Defaults to zero.

Returns:

ndarray(Float) – actuator forces (N) required at each leg

coriolisGravity(angular_vel: ndarray[float] = None, grav: ndarray[float] = None, top_plate_wrench: Wrench = <basic_robotics.general.faser_wrench.Wrench object>) → ndarray[float][source]

Calculate the velocity-dependent (centripetal) and gravity/load contribution to actuator forces, i.e. inverseDynamics() with zero platform acceleration.

Uses the current top/bottom plate pose - call IK/FK first to set the configuration to evaluate. :param angular_vel: top plate angular velocity, space

frame (rad/s). Defaults to zero.

Parameters:
  • grav (ndarray(Float), optional) – gravity vector. Defaults to self.grav.

  • top_plate_wrench (Wrench, optional) – additional externally applied wrench at the top plate. Defaults to zero.

Returns:

ndarray(Float) – actuator forces (N)

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

Generate the platform’s actuator-space mass matrix M, such that

tau = M @ [angular_accel; linear_accel] + coriolisGravity(angular_vel)

at the current top/bottom plate pose. :param angular_vel: top plate angular velocity, space

frame (rad/s). Defaults to zero.

Returns:

ndarray(Float) – 6x6 mass matrix

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

Calculate the top plate’s resulting acceleration given actuator forces.

Uses the current top/bottom plate pose - call IK/FK first to set the configuration to evaluate. :param tau: actuator forces (N) :type tau: ndarray(Float) :param angular_vel: top plate angular velocity, space

frame (rad/s). Defaults to zero.

Parameters:
  • grav (ndarray(Float), optional) – gravity vector. Defaults to self.grav.

  • top_plate_wrench (Wrench, optional) – additional externally applied wrench at the top plate. Defaults to zero.

Returns:

ndarray(Float) – [angular_accel (3,); linear_accel (3,)] of the top plate

integrateForwardDynamics(angular_vel0: ~numpy.ndarray[float], tau: ~numpy.ndarray[float], dt: float = 1.0, n_steps: int = 100, grav: ~numpy.ndarray[float] = None, top_plate_wrench: ~basic_robotics.general.faser_wrench.Wrench = <basic_robotics.general.faser_wrench.Wrench object>)[source]

Integrate the top plate’s rigid-body motion forward under a constant actuator force vector, starting from the current top/bottom plate pose.

Uses a simple fixed-step integrator with an exact (matrix-exponential) rotation update per step, since naive component-wise integration of a rotation is not physically meaningful. :param angular_vel0: initial top plate angular velocity, space

frame (rad/s)

Parameters:
  • tau (ndarray(Float)) – (constant) actuator forces (N) applied throughout

  • dt (float, optional) – total duration to integrate over. Defaults to 1.0.

  • n_steps (int, optional) – number of fixed integration steps. Defaults to 100.

  • grav (ndarray(Float), optional) – gravity vector. Defaults to self.grav.

  • top_plate_wrench (Wrench, optional) – additional externally applied wrench at the top plate, held constant throughout. Defaults to zero.

Returns:

t (ndarray(Float)) – time samples, shape (n_steps+1,) poses (list[tm]): top plate pose at each time sample angular_vels (ndarray(Float)): top plate angular velocity at each time

sample, shape (n_steps+1, 3)

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

Move the base of the stewart platform to a new location.

Parameters:
  • new_pos (tm) – New base transform to move to

  • protect (Bool) – Boolean to bypass error detection and correction. Bypass if True

  • stationary (bool, optional) – If True, keep the top plate fixed in global space while only the bottom (base) plate moves to new_pos - mirrors Arm.move(stationary=True). Defaults to False (top plate moves rigidly with the base, preserving their relative pose).

draw(ax) → None[source]

Draw this SP in the Matplotlib environemnt.

Parameters:

ax – axis object

basic_robotics.kinematics.sp_model.loadSP(fname: str, file_directory: str = '../robot_definitions/', baseloc: tm = None, altRot: float = 1) → SP[source]

Load A Stewart Platform Object from a json file.

Parameters:
  • fname (String) – file name of the sp config

  • file_directory (String) – optional directory, defaults to robot_defintions

  • baseloc (tm) – Base location.

  • altRot (Float) – alternate relative plate rotation.

Returns:

SP – SP object

basic_robotics.kinematics.sp_model.newSP(bottom_radius, top_radius, bJointSpace, tJointSpace, bottom_plate_thickness, top_plate_thickness, actuator_shaft_mass, actuator_motor_mass, plate_top_mass, plate_bot_mass, motor_grav_center, shaft_grav_center, actuator_min, actuator_max, base_location, name, rot=1)[source]

Build a new SP, called usually by a constructor.

Parameters:
  • bottom_radius (Float) – Bottom plate Radius (m)

  • top_radius (Float) – Top plate Radius (m)

  • bJointSpace (ndarray(Float)) – bottom joints space locations

  • tJointSpace (ndarray(Float)) – top joints space locations

  • bottom_plate_thickness (Float) – bottom plate thickness (m)

  • top_plate_thickness (Float) – top plate thickness (m)

  • actuator_shaft_mass (Float) – Actuator shaft (moving portion) mass Kg

  • actuator_motor_mass (Float) – Actuator motor (stationary portion) mass Kg

  • plate_top_mass (Float) – top plate mass (Kg)

  • plate_bot_mass (Float) – bottom plate mass (Kg)

  • motor_grav_center (Float) – Actuator motor inline COG distance from joint

  • shaft_grav_center (Float) – Actuator shaft inline CG distance from top joint

  • actuator_min (Float) – Actuator length when fully retracted

  • actuator_max (Float) – Actuator length when fully extended

  • base_location (tm) – Base transform

  • name (String) – Name of the SP

  • rot (Float) – Rotation parameter

Returns:

SP – SP object

basic_robotics.kinematics.sp_model.makeSP(bRad, tRad, spacing, baseT, platOffset, rot=1, plate_thickness_avg=0, altRot=0)[source]

Load a SP without need of a file.

Deprecated in favor of loading SPs from a JSON file. :param bRad: bottom plate radius :type bRad: Float :param tRad: top plate radius :type tRad: Float :param spacing: joint spacing (deg) :type spacing: Float :param baseT: base transform :type baseT: tm :param platOffset: platform offset height :type platOffset: Float :param rot: creates an invert platform if flipped :type rot: Float :param plate_thickness_avg: plate thickness :type plate_thickness_avg: Float :param altRot: rotational offset :type altRot: Float

Returns:

SP – Stewart platform object

basic_robotics.kinematics.sp_model.midHeightEstimate(leg_ext_min, leg_ext_max, bj, tj, bth, tth)[source]

Calculate an estimate of the resting height of a stewart plaform.

Parameters:
  • leg_ext_min (float) – minimum leg extension

  • leg_ext_max (float) – maximum leg extension

  • bj (array(float)) – bottom joints

  • tj (array(float)) – top joints

  • bth (tm) – bottom plate thickness

  • tth (tm) – top plate thickness

Returns:

Float – Description of returned object.