basic_robotics.kinematics.robot_model module
Holding file for Robot class, which is the superclass of sp_model and arm_model.
- class basic_robotics.kinematics.robot_model.Robot(name: str = 'Robot')[source]
Bases:
objectModels a Robot.
Provides interfaces for a standard set of functions, and makes best guesses at some implementations. Most functions will work if either jacobian or inverseJacobian are defined in child class.
- __init__(name: str = 'Robot') Robot[source]
Generate new Robot instance.
- Parameters:
name (str, optional) – Name of the robot instance. Defaults to “Robot”.
- Returns:
Robot – Robot instance.
- getActuatorForces() ndarray[float][source]
Return a copy of the last calculated actuator forces/torques depending on the robot type.
If the type of the robot is parallel/joints are linear, then it will be forces N. If the type of the robot is serial/joints are rotary, then it will be torque N*m.
- Returns:
last_tau (np.ndarray[float]) – last calculated joint/actuator forces.
- getEEPos() tm[source]
Return a copy of the current global end effector position.
- Returns:
tm – global frame end effector position
- getBasePos() tm[source]
Return a copy of the current global base position.
- Returns:
tm – global base position
- getGrav() ndarray[float][source]
Get a copy of the current applied gravity vector.
- Returns:
np.ndarray[Float] – gravity vector
- setGrav(new_grav: ndarray[float] = array([0., 0., -9.81])) None[source]
Set gravity vector.
Defaults to earth gravity (-9.81 ms^2 in negative Z) :param grav: Acceleration due to gravity :type grav: float
- Returns:
None – None
- FK(*args, **kwargs)[source]
Calculate Forward Kinematics of a robot.
This function must be implemented in child class.
- IK(*args, **kwargs)[source]
Calculate Inverse Kinematics of a robot.
This function must be implemented in child class.
- randomPos()[source]
Generate a random configuration through Forward Kinematics.
This function must be implemented in child class.
- velocityAtEndEffector(joint_vels: ndarray[float], *args, **kwargs) ndarray[float][source]
Calculate end effector velocity twist given a set of joint velocities.
Source for Open Chains: Modern Robotics 5.1.6 Source for Parallel Robots: NASA Memorandum 107585 p18 (36) :param joint_vels: joint velocities :type joint_vels: np.ndarray[float]
- Returns:
np.ndarray[float] – end effector velocity twist.
- velocityAtJoints(end_effector_twist, *args, **kwargs) ndarray[float][source]
Calculate joint velocities from end effector velocity twist.
Source for Open Chains: Modern Robotics 5.1.6 Source for Parallel Robots: NASA Memorandum 107585 p18 (37) :param end_effector_twist: end effector velocity twist :type end_effector_twist: np.ndarray[float]
- Returns:
np.ndarray[float] – joint velocities
- staticForces(eef_wrench: Wrench, *args, **kwargs) ndarray[float][source]
Calculate actuator forces for a static application of a wrench in global space.
- Parameters:
eef_wrench (Wrench) – Wrench in global frame to apply at end effector
- Returns:
np.ndarray(Float) – Forces on each actuator of the robot
- staticForcesInv(forces: ndarray[float], *args, **kwargs) Wrench[source]
Calculate the wrench acting on the end effector of the robot in the space frame given joint/actuator forces.
- Parameters:
forces (np.ndarray(Float)) – joint forces/torques in Newtons.
- Returns:
Wrench – Space Frame Acting Wrench
- staticForcesBody(eef_wrench: Wrench, *args, **kwargs) ndarray[float][source]
Calculate actuator forces for a static application of a wrench in body frame.
- Parameters:
eef_wrench (Wrench) – Wrench in body frame to apply at end effector
- Returns:
np.ndarray(Float) – Forces on each actuator of the robot
- staticForcesInvBody(forces: ndarray[float], *args, **kwargs) Wrench[source]
Calculate the wrench acting on the end effector of the robot in the body/EE frame given joint/actuator forces.
- Parameters:
forces (np.ndarray(Float)) – joint forces/torques in Newtons.
- Returns:
Wrench – Body Frame Acting Wrench
- jacobian(*args, **kwargs) ndarray[float][source]
Calculate Space Jacobian for given configuration.
- Returns:
jacobian
- inverseJacobian(*args, **kwargs) ndarray[float][source]
Calculate Inverse Space Jacobian for given configuration.
- Returns:
jacobian
- jacobianBody(*args, **kwargs) ndarray[float][source]
Calculate Body (EE Frame) Jacobian for given configuration.
- Returns:
body jacobian
- inverseJacobianBody(*args, **kwargs) ndarray[float][source]
Inverse Body (EE Frame) Jacobian for given configuration.
- Returns:
jacobian
- addCamera(cam, end_effector_to_cam: tm) None[source]
Add a camera to the robot, mounted at a fixed offset from the end effector.
- Parameters:
cam – camera object
end_effector_to_cam (tm) – end effector to camera transform
- visualServoToTarget(target: tm, pixel_tol: int = 2, desired_dist: float = 1.0, pose_delta: float = 0.1, pose_tol: float = 0.2, max_iter: int = 1000, cam_ind: int = 0)[source]
Perform visual servoing to a target using a virtual camera mounted on the robot.
- Parameters:
target (tm) – Object of interest to move towards.
pixel_tol (int, optional) – Pixel Tolerance. Defaults to 2.
desired_dist (float, optional) – Desired distance to object in meters. Defaults to 1.0.
pose_delta (float, optional) – Distance in meters to move the end effector per step. Defaults to 0.1.
pose_tol (float, optional) – Pose tolerance in meters. Defaults to 0.2.
max_iter (int, optional) – Maximum iterations before giving up. Defaults to 1000.
cam_ind (int, optional) – Virtual camera to use. Defaults to 0.
- Returns:
state – final actuator state (joint angles, leg lengths, etc) state_list (list): actuator state at each step along the servo trajectory.
- timeParametrizePath(path, max_vels: np.ndarray[float] = None, max_accels: np.ndarray[float] = None, max_jerks: np.ndarray[float] = None) JointTrajectory[source]
Convert a sequence of actuator-space waypoints into a velocity/acceleration-limited (and, if max_jerks is given, jerk-limited) time-parametrized JointTrajectory.
By default this uses the robot’s own max_vels/max_accels/max_jerks (see setJointProperties); pass any of the three explicitly to override them for this call without changing the robot’s configured limits.
- Parameters:
path (list[np.ndarray[float]]) – at least two actuator-space waypoints
max_vels (np.ndarray[float], optional) – overrides the robot’s configured limit
max_accels (np.ndarray[float], optional) – overrides the robot’s configured limit
max_jerks (np.ndarray[float], optional) – overrides the robot’s configured limit. A fully-infinite value (the default when unset) disables jerk limiting rather than raising an error.
- Returns:
JointTrajectory – retimed trajectory; see JointTrajectory.sample()