To support some degree of physical interaction between a rigid-body system and its environment, Spatial_v2 provides a Simulink block to calculate the forces acting on an identified set of points due to contact with a compliant ground plane.  This block is based around the function gcontact.  Three other functions support the use of this block: gcPosVel, which calculates the positions and velocities of the identified set of points; Fpt, which converts linear forces acting at specified points into equivalent spatial or planar forces; and gcFD, which converts the resulting matrix of spatial or planar forces into the format required in the f_ext argument of the forward-dynamics functions.  The complete ground-contact model can be found in Simulink tutorial example 7, from where it can be copied and adapted.

The model works in both 2-D and 3-D Euclidean spaces, its behaviour being essentially the same in both cases.  In 2-D space, the ground plane is defined to be the x axis; the y axis points up; and each point is identified by its x and y coordinates.  In 3-D space, the ground plane is defined to be the x-y plane; the z axis points up; and each point is identified by its x, y and z coordinates.  You use the 2-D ground-contact model with any system model based on planar arithmetic; and you use the 3-D ground-contact model with any system model based on spatial arithmetic.

### How the Model Works

1. Every point has a given position and velocity, and the purpose of the ground model is to calculate the forces acting on the points.
2. Each point is considered in isolation.  The force acting on any one point depends only on the motion of that one point.
3. The ground is modelled as a massless, nonlinear spring-damper system, with compliance in both the normal and tangent directions.  The normal compliance gives rise to a normal force, whereas the tangential compliance gives rise to a tangential force that is subject to an upper limit determined by the friction cone.
4. Any point that is above the ground plane is not in contact with it, and experiences no forces.
5. Any point that is below the ground plane may or may not be in contact with it, depending on its velocity.  If such a point is travelling upwards faster than the natural recovery rate of the ground then it experiences no ground-reaction force and is deemed not to be in contact with the ground.
6. For this reason, each point is classified as being either in contact or not in contact according to the forces acting on it: a point is in contact if it experiences a nonzero force, otherwise it is not in contact.
7. Each in-contact point can be further classified according to whether it is sticking (due to friction) or not sticking (i.e., slipping).  Thus, every point is always in exactly one of the following three states at any given instant: sticking, slipping, or not in contact.
8. The sticking status of an in-contact point is determined as follows.  First, the normal component of ground reaction force is calculated; then the tangent component is calculated on the assumption that the point is sticking.  The result is then tested against the friction cone.  If the calculated tangent force falls outside the friction cone then it is truncated to the surface of the friction cone and the point is classified as slipping.  Otherwise, the point is sticking.
9. Simulink's zero-crossing detection facility is used to detect the precise moment when any point changes its state.
The compliant ground model resembles the one described in Section 11.8 of RBDA, except that the model used here is nonlinear.  More particularly, the compliant ground model is closely based on the model described in Azad & Featherstone (2010), except that the model used here is for points rather than spheres.

### How to Use it

Step 1:  Identify the set of contact points.  You must first identify the set of points in your model that will experience forces if they come into contact with the ground.  We shall call them ground-contact points.  The number and distribution of ground-contact points will depend on circumstances.  For example, if you want to study bipedal walking in a humanoid with rectangular feet, then eight points will probably be enough: one at each corner of each foot.  On the other hand, if you want to investigate the unrestricted rolling behaviour of a polyhedral approximation to a disc (as in Simulink tutorial example 7), then every vertex of the polyhedron must be included in the set.  Each ground-contact point is characterized by two quantities: the body number of the body to which it belongs, and its coordinates in the local coordinate system of that body (x and y coordinates if the system model uses planar arithmetic, otherwise x, y and z coordinates).

Step 2:  Add them to your model.  Add a new field, called gc, to your system model data structure.  This field is a data structure containing fields called body and point, such that body(i) is the body number of the body to which ground-contact point number i belongs, and point(:,i) contains the coordinates of point i.  Points can be listed in any order.