Each body contains inertial properties, which are collectively set referred to as a Mass object.
- mass (float)
- center of mass (
Vector3) given in local coordinates - inertia matrix (
Matrix3) HL given in local coordinates
Robot (.rob) and Rigid Object (.obj) files can automatically infer inertial properties from link masses using the automass line.
- RobotLink.getMass(): returns the link's
Massstructure - RobotLink.setMass(mass): sets the link's
Massstructure - RigidObjectModel.getMass(): returns the object's
Massstructure - RigidObjectModel.setMass(mass): sets the object's
Massstructure
Mass structure
mass.get/setMass(m): get/sets total mass to a floatmass.get/setCom(com): get/sets center of mass to a float 3-tuple in link-local coordinatesmass.getInertia(inertia): gets inertia as a 9-vector, indicating rows of the inertia matrix in link-local coordinatesmass.setInertia(inertia): sets inertia, either a float, float 3-tuple, or float 9-tuple. If float, sets inertia matrix to HL=I3x3*inertia. If 3-tuple, sets matrix to HL=diag(inertia)
The fundamental Langrangian mechanics equation is
B(q)q''+C(q,q')+G(q)=τ+Σi Ji(q)T fiWhere:
- q is configuration,
- q' is velocity,
- q'' is acceleration,
- B(q) is the positive semidefinite mass matrix,
- C(q,q') is the Coriolis force,
- G(q) is the generalized gravity,
- τ is the link torque,
- fi are external forces, and
- Ji(q) are the Jacobians of the points at which the points are applied.
A robot's motion under given torques and external forces can be computed by determining the acceleration q'' by multiplying both sides by B-1 and integrating the equation forward in time.
Klamp't has several methods for calculating and manipulating dynamics terms. The first set of methods is found in the Robot class, which use the "classic" Euler-Lagrange method that expands the terms mathematically in terms of Jacobians and Jacobian derivatives, and runs in O(n3).
CalcAcceleration: used to convert the RHS to accelerations (forward dynamics).CalcTorquesis used to convert from accelerations to the RHS (inverse dynamics).KineticEnergy:KineticEnergyInv:GravityTorques:CoriolisForce: Note that these are actually defined inRobotKinematics3DandRobotDynamics3D.
The second set of methods uses the Newton-Euler rigid body equations and the Featherstone algorithm (KrisLibrary/robotics/NewtonEuler.h). These equations are O(n) for sparsely branched chains and are typically faster than the classic methods for modestly sized robots (e.g., n>6). Although NewtonEuler is designed particularly for the CalcAccel and CalcTorques methods for forward and inverse dynamics, it is also possible to use it to calculate the C+G term in O(n) time, and it can calculate the B or B-1 matrices in O(n2) time.
The RobotModel class can compute each of these items using the Newton-Euler method:
robot.getCom(): returns robot’s center of mass as a 3-tuple of floatsrobot.getMassMatrix(): returns nxn array (n nested length-n lists) describing the mass matrix B at the robot’s currentConfigrobot.getMassMatrixInv(): returns nxn array (n nested length-n lists) describing the inverse mass matrix B-1 at the robot’s currentConfigrobot.getCoriolisForceMatrix(): returns nxn array (n nested length-n lists) describing the Coriolis force matrix such that at the robot’s currentConfig/Velocityrobot.getCoriolisForces(): returns the length-n list giving the Coriolis torques at the robot’s currentConfig/Velocityrobot.getGravityForces(gravity): returns the length-n list giving the generalized gravity G at the robot’s currentConfig, given the 3-tuple gravity vector (usually (0,0,-9.8))robot.torquesFromAccel(ddq): solves for the inverse dynamics, returning the length-n list of joint torques that would produce the acceleration ddq at the currentConfig/Velocityrobot.accelFromTorques(torques): solves for the forward dynamics, returning the length-n list of joint accelerations produced by the torques torques at the currentConfig/Velocity
Klamp't supports several operations for working with contacts. Currently these support legged locomotion more conveniently than object manipulation, because the manipulated object must be defined as part of the robot, and robot-object contact is considered self-contact.
These routines can be found in KrisLibrary/robotics, in particular Contact.h, Stability.h, and TorqueSolver.h.
- A
ContactPointis either a frictionless or frictional point contact. Consist of a position, normal, and coefficient of friction. - A
ContactFormationdefines a set of contacts on multiple links of a robot. Consists of a list of links and a list of lists of contacts. For all indicesi,contacts[i]is the set of contacts that affectlinks[i]. Optionally, self-contacts may be defined by providing the list of target linkstargets[i], with -1 denoting the world coordinate frame. Contact quantities may be given target space or in link-local coordinates is application-defined. - The
TestCOMEquilibriumfunctions test whether the center of mass of a rigid body can be stably supported against gravity by valid contact forces at the given contact list. - The
EquilibriumTesterclass provides richer functionality thanTestCOMEquilibrium, such as force limiting and adding robustness factors. It may also save some memory allocations when testing multiple centers of mass with the same contact list. - The
SupportPolygonclass explicitly computes a support polygon for a given contact list, and provides even faster testing than EquilibriumTester for testing large numbers of centers of mass (typically around 10-20). - The
TorqueSolverclass solves for equilibrium of an articulated robot under gravity and torque constraints. It can handle both statically balanced and dynamically moving robots.
These routines can be found in klampt.model.contact which are thin wrappers around the underlying C++ functions.
-
A
ContactPointis either a frictionless or frictional point contact. Consist of a position, normal, and coefficient of friction. Unlike in C++, theContactPointdata structure also has the option of referring to which objects are in contact. -
forceClosuretests whether a given set of contacts is in force closure. -
comEquilibriumtests whether the center of mass of a rigid body can be stably supported against gravity by valid contact forces at the given contact list. -
supportPolygoncomputes a support polygon for a given contact list. Testing the resulting boundaries of the support polygon is much faster than calling comEqulibrium multiple times. -
equilibriumTorques solves for equilibrium of an articulated robot under gravity and torque constraints. It can handle both statically balanced and dynamically moving robots.
The contact state of a single link, or a related set of links, is modeled with three higher-level concepts.
Hold: a set of contacts of a link against the environment and are used for locomotion planning.Stance: a set ofHolds.Grasp: like a Hold, but can also contain constraints on the values of related link DOFs (e.g., the fingers). Generally used for manipulation planning but could also be part of locomotion as well (grasping a rail for stability, for example).
A Hold is defined as a set of contacts (the contacts member) and the associated IK constraint (the ikConstraint member) that keeps a link on the robot placed at those contacts. These contacts are considered fixed in the world frame. Holds may be saved and loaded from disk. The C++ API defines them in Klampt/Contact/Hold.h, which also defines convenience setup routines in the Setup* methods. The Python API defines them in klampt.model.contact.
A Stance (Klampt/Contact/Stance.h) defines all contact constraints of a robot. It is defined simply as a map from links to Holds in C++, and is simply a list of Holds in Python.
A Grasp (Klampt/Contact/Grasp.h) is more sophisticated than a Hold and are most appropriate for modeling hands that make contact with fingers. A Grasp defines an IK constraint of some link (e.g., a palm) relative to some movable object or the environment, as well as the values of related link DOFs (e.g., the fingers) and possibly the contact state. Note: support for planning with Grasps is limited in the current version.