Saturday, January 5, 2013

Simmechanics: Simulating floor interaction/collision

I'll demonstrate how to simulate a floor in Simmechanics, this floor will prevent free falling (6 DOF) objects from falling below a threshold level ("the floor level"), i.e. I will simulate a collision/interaction between the free falling object and the floor.

I'll assume you have a basic understanding of how Simmechanics works. If you don't, you might want to check this post.

The problem

If you have used Simmechanics before, then you know it's an excellent toolbox for simulation of multibody dynamics. You can easily work with robotic arms, which are always fixed to the ground. But what happens when you want to work with legged robots, that can't be fixed to the ground. Well, then you run in a problem, if you don't fix any part of the robot to the ground, then the robot will fall and fall by action of the gravity. Removing the gravity is not an option, because you want to design the controllers of your robot with gravity compensation, even worse your robot will float if you simulate a zero gravity environment.

Let's develop a minimal model to illustrate the problem: a 6 DOF ball.

Illustrating the problem

We'll start by drawing the floor. Implement the following block diagram in Simulink.

Block diagram to visualize the floor.

Modify the Floor block parameters to match the following image, and also on the Visualization tab change the Body geometry option to "Equivalent ellipsoid from mass properties".

Parameters to draw a 1 meter radius floor.

Next, start a simulation. Activate the the Isometric View and the "Enable Automatic Expanding Fit".

Animation showing the floor as a 1 m radius disk.

Now, we add the free falling ball. Add more blocks to the model to match the following diagram.

Added a free falling ball to the model.

Next, modify the parameters of the Above Ground block and the Ball block, to match the following images. On the Visualization tab of the ball block also select "Equivalent ellipsoid from mass properties" on the Body geometry option.

Above Ground parameters
Ball parameters

Now simulate the system and observe the problem.

Ball falling through the floor.

The Idea

Known the problem, we must now create a solution. Let's begin by analyzing how the floor behaves. Ideally the floor is a rigid body that exerts enough force over adjacent bodies to prevent them from falling through. Now, perfect rigid bodies doesn't exist in the real world, all bodies deform when stressed or compressed. This means our floor model must be elastic, this can be modeled as a spring.

Our floor model can't be modeled only as a spring, otherwise will end with a trampoline. When we fall to the ground, we don't jump back to the sky, instead our potential energy dissipates as heat or as permanent deformation. This means our floor model must also have a dissipation element.

A mass-spring-damper system.

That description resembles a lot to a mass-spring-damper system. As you might know those system tend to vibrate, unless they are overdamped. This means our floor model must behave as an overdamped mass-spring-damper system. The final condition is that the free falling object must be the mass of the system, this means that our floor model doesn't really has a mass parameter. Other way to think of it is that the mass is detachable, and this mass is only affected by the spring and the damper when is at or below the floor level.

Implementing the floor interaction

First, let's enable some sensor/actuator ports on the free falling ball. These two ports must be located at the same point, at the bottom of the ball.

Adding sensor/actuator ports to the free falling ball.

The floor control diagram can be implemented as follows:

Floor Control Diagram.

The body sensor is configured to output the position in meters, while the body actuator is configured to exert force in newtons over the ball. Using a demuxer, we extract the Y component of the position, then we compare it to the floor level. If the Y position of the bottom of the ball is below the floor level, then we activate the spring-damper system represented by the gains 'k' and 'c', otherwise the floor exerts no force over the ball. The force developed by the spring damper system is exerted over the ball but only in the Y direction, thanks to a muxer and the body actuator.

The final step is selecting 'k' and 'c'. You need to considerate the following things:

  • The damping ratio "c / 2 / sqrt(m * k)" should be greater than 1, to guarantee overdamping.
  • The free falling body will sink a distance "m * g / k" into the ground, so you might want to increase 'k', right?
  • But Increasing 'k', also increases the computation load of the simulation.

How do I select the parameters 'k' and 'c'? I first select 'k' balancing how much sinking and computation load can I tolerate. Then I compute 'c' using the biggest mass and choosing a damping ratio of 1.

The Results

I'll leave you with the simulation output.

Floor control enabled.

Ball interacting with the floor. (Y position)

As a closing remark, I must say that I have used this method in the simulation of a humanoid robot with positive results.


  1. Jorge,

    How did you go about modelling the floor? What values did you input for the blocks in your SimMechanics block diagram?

    1. Hey there,

      For the spring constant 'k', I used the floor material (say concrete) young's modulus times the "contact area", and for the friction coefficient 'c' I selected a value that results in critically damped oscillation.

      Hope that helps

  2. Hey,
    I just stumbled over your site and find your Simulations very interesting!
    I am currently trying to get into Simmechanics but have a few starting problems.
    Can you please send me the mdl file of this simulation?
    that would really be of great help for me!

    Kind regards, Thomas

  3. Hey Jorge,

    thanks so much for your nice explanation. I am writing my diploma thesis about pretty much the same thing as you did with your humanoid robot simulation and this tutorial just blew away one of the many problems i am encountering. ;)

    In addition i think i found a little mistake in the explanation above:

    The equation for calculating the damping ratio you mentioned above "c / 2 / sqrt(m * k)"
    should look like this "c / (2*sqrt(m * k))"


  4. great work. can u share the value of k and c in your system ?
    thank you so much

  5. Programming is combination of intelligent and creative work. Programmers can do anything with code. The entire Programming tutorials that you mention here on this blog are awesome. Beginners Heap also provides latest tutorials of Programming from beginning to advance level.
    Be with us to learn programming in new and creative way.

  6. I build up this model in simmechanics model. But unfortunately with the "derivative" block (the forceconsisted from spring and damping was almost proportional and ball fell down) it didn't work properly so i exchange it to the "Switched
    derivative for
    linearization" block and it started to work. Any idea why?

  7. Hola Jorge, Estoy Siguiendo tu Blog, y Este trabajo de simular un piso en SimMechanics es muy bueno, favor me pordías ayudar de como Simular piernas de Robot Bípedo para la Camita, Agradeceria Mucho tu ayuda.

    Josmell Alva.

  8. Superb. I really enjoyed very much with this article here. Really it is an amazing article I had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this excellent article.thank you for sharing such a great blog with us. expecting for your.
    Digital Marketing Company in India
    seo Company in India

  9. This blog having the details of Processes running. The way of running is explained clearly. The content quality is really great. The full document is entirely amazing. Thank you very much for this blog.
    SEO Company in India
    Digital Marketing Company in India