Sebastian Castro, MathWorks
Ed Marquez Brunal, MathWorks
Join Sebastian Castro and Ed Marquez Brunal as they discuss approaches for modeling and simulation of mechanical contact using Simulink® and Simscape™. Contact modeling can approximate physical phenomena such as rolling, bouncing, gripping, and walking. This can help you build detailed simulations for design and analysis of mechanical systems.
In this video, Sebastian and Ed present the general workflow for modeling mechanical contact in Simulink block diagrams. They explore simple examples with different levels of detail for 1D and 3D contact modeling with Simscape and Simscape Multibody™, along with some useful block libraries you can find online.
After introducing the different contact modeling approaches, Sebastian and Ed demonstrate some models created for robotics and automotive applications. You can find the example models used in this video on MATLAB Central File Exchange.
For more information, you can access the following resources:
Hello, everyone. Welcome to the MATLAB and Simulink Robotics Arena. I'm Sebastian.
And I am Ed.
And this video is an Introduction to Contact Modeling. This is the first part of two videos that we'll be recording.
For this part, we'll talk about a motivation for contact modeling. So what is it? Why do we care about it? Then we'll go through some theoretical basics of contact modeling, and finally move onto some simple examples of how we would do this with Simulink. In the second part of the video, we'll look at some other tools, as well as revisit some of the examples that we'll show you in this video.
So one of the reasons that we're doing this video together is that we're actually working on two similar projects which kind of ties in to the motivation. So why do we care about contact modeling?
So one of the reasons is automotive applications. Sometimes we want to study the interaction between the wheels and also the road.
Another application is with robotics; for example, robot manipulation, where you're trying to pick up objects and place them elsewhere.
Sometimes we also want to analyze mechanisms. We want to study or model the contact that happens in different robots or machines.
Going back to the robot point, locomotion is another key thing that we can model; for example, if you have a walking robot or something that needs to contact with the ground in order to move.
So you see we've got some automotive and robotics applications here, primarily. And that has to do with the stuff that we've been working on, right?
So we'll show you two examples really quickly of some of the things we've been working on. So Ed, I'm going to pull up your vehicle model and run it. And why don't you tell us a little bit about it?
Sounds good. So what I'm really modeling here is the contact between the four wheels and also the road. And you see that I'm also using Simscape tools to model the geometry of the vehicle. But again, we want to focus on the contact part here.
So one of the cool things about this model is that if you actually zoom into it, it's got a full suspension model. So it's not just the wheels in contact with the ground and they're staying fixed. You actually have all the links and springs and dampers taken care of here.
Right. Right. And you can also model the steering in the front wheels and also the torque input to the rear wheels. So that's pretty interesting to see as well.
Yeah. So there it is, steering as they back up through the simulation. So again, this is one application of contact simulation.
Another one that we'd like to show you really quickly is one for a robot arm. So this is a robotics pick-and-place application where we have this arm that is grabbing a box that's on a conveyor belt. And there's sort of two ways that contact is modeled here, right? The first one being the actual box sliding on the conveyor belts--so there's some friction happening there--as well as, of course, the robot simply being able to pick up that box out of the ground.
And as we go through the videos, we'll revisit these models at the end and show you exactly how we did it. Before that, though, we're going to go through some introductory material that builds up to basically these models.
Let's talk some basics about contact modeling. Suppose that you have something that looks like what's on your screen. So you had two objects that are colliding with each other. What are the physics that are happening behind there? So first of all, whenever the two objects collide, there's generally going to be a contact point, or it could be a chaotic surface. This depends really on whether the bodies are deforming or what is happening when you actually hit.
But let's suppose there's a point. Because two objects can't overlap with each other, there's going to be a force that pushes away from that collision. So we have a normal force; that is, normal to the contact surface. In addition to that is the friction force. And that has to do with if two objects are in contact, they're going to be sliding against each other. So this friction force is going to be along the surface or tangential to the contact surface, and it generally will oppose the motion of the object.
When we talk about simulation now, the forces that are applied at a certain point. But if we're tracking, for example, the motion about the center of mass of the object, what we can do is move these forces to the center of mass, and that's going to create some kind of torque at the center of mass. What that really means from a simulation standpoint is that when you have objects that come in contact, they're not only to be pushed apart from each other, but there might be some spinning or turning of the object as well.
So actually here on the screen, I see that you have the ball, but also you have a plane. So what about the reaction forces in this case?
Right. So this is kind of half of the model. If the plane were rigid, then that's all you really care about. But if that plate was free to move, as you just said, Ed, there's going to be equal and opposite reaction forces. And what that means, depending on where that plane is clamped or if it is clamped at all, then you will also have some kind of force and torque that causes the second object to move in some way as well.
This all depends on how you're going to do your modeling. If you're colliding against a rigid surface versus two freely moving bodies, you've got to account for that.
So let's dig into some more details about these normal and friction forces. What are some ways that normal forces or normal contact is modeled out there?
The first one that I want to talk about is impulse-based contact. And this really has to do with kind of an individual collision event that happens. For example, if you have an object striking another object, then there's going to be an instantaneous change of momentum. And what that means is that before the collision, the objects will have some speed. And after the collision, depending on the rules, they're going to have some other speed at the end of it.
So in the case of a bouncing ball, like you see in the diagram, that might just be you come in with a downward velocity and you leave the collision with an upward velocity. And what dictates what the beginning and end velocities relationship is is things like elastic versus inelastic collisions or how the energy is preserved.
Other ways of modeling contact is by actually just doing force-based calculation. And there's a couple of ways of doing this. One of them is one that uses Lagrange multipliers. I won't get too much into the detail of this but this is a way to take your existing equations, and in addition, impose constraints that basically prevent things from overlapping. The contact constraints are actually met exactly, because you're putting them into your equations. But because you have to have more equations to solve the system, it can sometimes be expensive to compute. So for large systems, this approach tends to get pretty slow.
Another simpler way, but it has its own nuances, is the penalty force. And we'll talk more about this as we go through the videos. This is one in which you actually let the two bodies overlap by a little amount.
So take, for example, if you have some materials that are squishy or they can deform. If you have a little bit of overlap, then that's going to cause a force that pushes things away from each other. So generally, this is a good approximation. You won't have exact contact, because the two objects will be on top of each other somewhat, but it's relatively simpler to implement. Generally, you do this with a force law, like spring and damping, which, again, can be easy to implement, but you need to choose good parameters that make sense for the real world.
Makes sense. And what about if you don't have to worry about a collision or maybe the forces that are happening between the bodies?
Yes, it's a good point. If you absolutely need all the contact dynamics, then definitely invest in some of these techniques. But if you need to model a very simple contact relationship, then you might not even need to worry about forces. You can just implement a motion constraint.
Just basically build in your equations the fact that these two objects must have some relationship to each other. And that means a lot less equations in your system.
I see. And now you've proposed these three different approaches. But when is it best to use one over the other?
Yeah, so there's a lot of factors that come into play here. But I think the diagram that I'll pull up here kind of summarizes it, that if you have bodies that are always in contact--so you don't really need to worry about things going in and out of contact and what the dynamics are--then you're better off near the bottom of this diagram, which is just implement a motion constraint. And if you need more, then start moving up the chain.
For example, the impulse-based is good for infrequent collisions, because you don't want something chattering where every other time set in simulation is just there's a collision, then there's no collision, then there's another one again. So definitely think about this as you're figuring out the contact modeling approach.
So let's talk about friction forces now. Friction forces are going to be engaged when bodies are in contact. And as we talked about, that's going to be in the direction of the actual contact surface. The way that friction force generally works is that it would depend on the normal force, which that has to do with the weight of the object--so the heavier the object, the more friction force you have--but it might also depend on the velocity along the contact surface. Friction has a static and a kinetic component.
So let's take this first graph, which on the horizontal, it's the force that you apply to an object, and on the vertical, it's the actual friction force you experience. So you start with the static region, which is while you're not moving--so when you start from rest--you actually have to keep pushing on the object until it overcomes a certain force or breakaway threshold. So at that point in the static region, the friction force completely negates the applied force. And then once you get past that certain point, then your friction force is smaller than the applied force, which means that your object is moving with some loss of energy due to friction.
Another way to look at it is with speed. So if I'm plotting here the friction force versus the speed, you see that that vertical portion in the graph means, again, that in order to cross from zero velocity to not zero, then you actually need to overcome that initial step and force.
I see. Yeah.
And then as you're moving, that force will have a different relationship with the velocity.
Makes sense. And for that diagram on the right, can you define the shape of those curves maybe by tuning some of those parameters that we see?
Absolutely. So there's multiple ways of doing it. This is a curve. So you could actually try to fit analytical equations to the curve, or you can actually use a completely data-driven approach and say have a lookup table that describes that relationship between friction and velocity, which kind of segues to our next point.
How would you model these things in Simulink? Just to recap, contact is made of normal force and friction force. So for impulse-based contact, usually when we do equations, we have these integrator blocks to go from acceleration to speed.
Now, if we need to do this kind of collision type of contact, then the integrator block actually has an option to reset the state of that integrator. So what you would do is detect the collision, and then fire off some kind of a reset trigger that re-initializes speed to ending value.
And then on the force-based contact that were just creating the friction forces, like we were just talking about, we can use Simulink blocks, such as lookup tables or other types of mathematical relationships, to build our force laws.
Let's take a look at some of the examples to see how this was done in Simulink.
Okay. So the first example that I wanted to show was one that actually is included with Simulink, and this is one of a bouncing ball. So I'm just going to run this section.
When this diagram pulls up, you'll see that it's a fairly simple block diagram. I'm going to simulate it. And here you see in the scope, you have the position at the top and the velocity at the bottom. So the scope, again, just shows that you have an object that is going upwards. And then every now and then, it bounces and loses some speed every time it bounces until it gets to rest.
So what determines the characteristics of that bounce?
Yeah. So what you see here is that, basically, this integrator block is set up such that it resets every time the position value reaches 0; so in other words, when you hit the ground. And then what this does is it grabs the velocity signal and it multiplies it by this coefficient of restitution. In this case, it's 0.8. So what that means is when you hit this collision, if you're going down at a certain speed, then you're going to bounce back up at the opposite speed, but only 80% of that. So that's the way that you lose energy in the system.
I see. What if we try a different value and simulate the system?
Right. So let's go to 0.5, meaning that you actually lose more energy every time you bounce. And again, you should see that now it's a lot quicker for it to reach that steady state.
You could kind of extend this impulse-based approach. For example, we have a model here that shows collision between two objects. And the way that this works is we have basically the equations, force equals mass times acceleration for two bodies. And then what we're doing on the right of this model is figuring out basically whenever the two bodies come into contact with each other, we implement some kind of equation to figure out what the new speeds are. And you see that the equations are actually shown here in the model. So it says that the new speeds are a function of the masses and the velocities prior to the collision.
So we can run this, eventually go to the position scope. So if I run this with its default parameters, you'll see, again, that the two objects end up--they begin moving towards each other. And then when they collide, they bounce away from each other.
And I could always change these parameters. So right now, you see that its coefficient of restitution is set to 0.5. If I go in one direction, for example, 0, it means that now the two objects completely stick together--
--as they move. So we can now very quickly change these parameters and see the difference in the nature of the collision.
So that's it for the impulse. Let's now talk about force-based. So this is a different type of model. It's one where you have a mass on a spring that's sliding along a friction surface, and then you also have some contact, so that, again, just like in the previous model, when you hit a position of 0, then you're going to bounce against the wall.
So go ahead and run this. And again, you'll see very similar shapes than you did before, where you have an object bouncing and then coming to rest. Because is a force-based approach that is actually modeled using a penalty force, you'll see that for this model you don't actually get exact contact. If I zoom in here to the spikes, when you collide with the object, you see that there's actually a dip of about 2 and 1/2 centimeters on the first bounce. And you basically need to be tuning your contact parameters to make sure whether that's okay or it's too much overlap.
So again, the way that this works, this is the way that you model any second order system. And then here I've got blocks that I built modeling the friction force and the normal force.
For the friction force, this is just a lookup table block. And I can actually just plot basically the friction relationship. You see that this contains, again, the static component, where you have to overcome some force to start moving. And then you have those spikes there that denote just the dynamics of how you move from the static to the kinetic region.
So I see, in this case, that you use the lookup table, right? So with that you can characterize your contact to fit whatever needs you have, correct? Is that right?
Right, because if my curve were to look completely different from this, then you're just loading some vector of data.
For the normal force, it's done a little different. We're doing this with just mathematical operations.
This is a penalty force. It's based off of a spring-and-damper type model. So what we have is a switch block that basically looks for whether or not we're in contact. If there is no contact, then we just apply 0 force. But if there is contact, then we have this spring-and-damper law. So it's really some force is proportional to the displacement and the speed.
And then, again, two of these parameters--for example, if I were to, I don't know, let's say increase the damping value to something bigger, then I try to rerun the simulation, you'll see a different bouncing relationship.
Hm. Makes sense.
So again, these are some basic examples of how you would do contact modeling with Simulink. We'll talk a lot more about that in the next video. So stay tuned.
Again, as always, feel free to contact us via email or Facebook. And check out the other resources below. Thank you for watching.
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .Select web site
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.