ContactMesh not working with input stl file from solidworks.

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Ratna Sambhav
Posts: 42
Joined: Sat Jan 12, 2019 10:16 am

ContactMesh not working with input stl file from solidworks.

Post by Ratna Sambhav » Tue Jan 21, 2020 2:41 am

Hello,
I need a little bit of help in understanding why the ContactMesh used by me is not working properly. I made a sphere in solidworks, saved it in stl format, Part4.stl. Then, I made the body of a ball and body of a flat surface, using API command of OpenSim. I activated contact on the surface using ContactHalfSpace command. For the body of the ball, I activated contact by using ContactMesh('Part4.stl') command. I kept the ball above the surface and simulated. Problem is ball is passing through the surface. I tried using ContactSphere and it worked. But my main concern is to import SolidWorks model and activate contact on this, which I don't see working here.
(It is just an example, I am trying to run before I implement it in my project where I have to import an upper limb exoskeleton design made in solidworks and calculate contact force between the musculoskeletal model and the device, which will be used as user's intention in control loop implemention)

Here is my code:
surface = Body('surface',1,Vec3(0),Inertia(1));
surf_geo = Brick(Vec3(5,0.1,5));
surf_geo.setColor(Vec3(0));
surface.attachGeometry(surf_geo);
model.addBody(surface);
joint = WeldJoint('joint',model.getGround(),Vec3(0,0.9,0),Vec3(0,0,0),surface,Vec3(0),Vec3(0));
model.addJoint(joint);

ball = Body('ball',1,Vec3(0),Inertia(1));
sphere = Mesh('Part3.stl')
sphere.setColor(Vec3(1));
ball.attachGeometry(sphere);
model.addBody(ball);
joint = FreeJoint('joint',model.getGround(), Vec3(0,5,0), Vec3(0, 0, 0), ball,Vec3(0), Vec3(0, 0, 0));
model.addJoint(joint);

floor = ContactHalfSpace(Vec3(0), Vec3(0, 0, -pi/2), surface,'floor');
contact = ContactMesh('Part3.stl',Vec3(0,0,0),Vec3(0,0,0),ball,'contact');
% contact = ContactSphere(1, Vec3(0, 0, 0), ball, 'contact');

stiffness = 1.e8; dissipation = 0.5; friction = [0.1, 0.1, 0.1];
contactForce = HuntCrossleyForce();
contactForce.setStiffness(stiffness);
contactForce.setDissipation(dissipation);
contactForce.setStaticFriction(friction(1));
contactForce.setDynamicFriction(friction(2));
contactForce.setViscousFriction(friction(3));
contactForce.addGeometry('floor');
contactForce.addGeometry('contact');

% Add the contact-related components to the model.
model.addContactGeometry(floor);
model.addContactGeometry(contact);
model.addForce(contactForce);
Attachments
Capture.JPG
Capture.JPG (50.56 KiB) Viewed 508 times

Tags:

User avatar
Ayman Habib
Posts: 2248
Joined: Fri Apr 01, 2005 12:24 pm

Re: ContactMesh not working with input stl file from solidworks.

Post by Ayman Habib » Tue Jan 21, 2020 10:19 am

Hi Ratna,

The difference between a ContactMesh and a ContactSphere is that the ContactSphere has sidedness and triangulation built in while a mesh can have a variety of issues as it supports a more general shapes, examples:
- Normals pointing in the wrong direction or not aligned
- Mesh not closed for whatever reason, or have degenerate triangles.
You can use some third party tools (e.g. MeshLab) to figure out the issues with the Mesh/STL file. Also make sure the sidedness of the halfspace is correct (I assume it is the same as the one you used with ContactSphere).

Hope this helps,
-Ayman

User avatar
Ratna Sambhav
Posts: 42
Joined: Sat Jan 12, 2019 10:16 am

Re: ContactMesh not working with input stl file from solidworks.

Post by Ratna Sambhav » Fri Jan 24, 2020 5:19 am

Thankyou for your kind attention Ayman Habib.
From now on, I'll be using MeshLab for model import, for avoiding any issue related to mesh. My current problem was solved by using ElasticFoundationForce instead of HuntCrossleyForce.
Thanks

POST REPLY