ContactMesh not working with input stl file from solidworks.
Posted: 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);
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);