16 April 2021 at 0 h 05 min #19187BrunoB81HKParticipant
I’m currently working on a plugin to link a custom haptic device to a Sofa simulation. My goal is to move and rotate a mechanical object base on the position of my haptic device. So far, I implemented the translation and the force computation, but I can’t find how to apply a rotation that make sense. In my .scn file, the mechanical object is defined as such :
<Node name="Instr"> <EulerImplicitSolver rayleighStiffness='0.1' rayleighMass='0.1'/> <CGLinearSolver threshold='1e-11' tolerance='1e-11' iterations='25'/> <MechanicalObject name='InstrDOFs' template='Rigid3d'/> <UniformMass name='InstrMass' totalMass='0.05'/> <LCPForceFeedback template="Rigid3d" name="ForceFeedback" listening="1" activate="1" forceCoef="1."/> <Node name='InstrCol'> <MechanicalObject name='InstrColModel' src='@../../InstrColMesh'/> <SphereCollisionModel contactStiffness='1' listRadius='0.0025'/> <RigidMapping input='@../InstrDOFs' output='@InstrColModel'/> </Node> <Node name='InstrVis'> <OglModel name='InstrVisModel' src='@../../InstrVisMesh'/> <RigidMapping input='@../InstrDOFs' output='@InstrVisModel'/> </Node> </Node>
In my plugin, I start by retrieving the pointer
m_instrumentto the mechanical object. From there, I compute the needed translation and apply it with
m_instrument->applyTranslation(trans, trans, trans). This part is working very well.
The next step is to apply the required rotation. My mechanical object is basically a long cylinder. I want the axis of the cylinder to pass through a fixed point in the simulation. This point stay static through the entire simulation. I can easily compute the required axis/angle pair to achieve my rotation. I then use
m_instrument->applyRotation(q)to apply my rotation (q being a quaternion).
The problem is that the rotation is applied, but doesn’t match the one that I want. I don’t know if it as to do with reference frame, but I compute my quaternion in the general reference frame. I feel like the rotations might be applied in the mechanical object reference frame. I’m kinda lost on this one.
Thanks a lot for your help!
Bruno23 April 2021 at 11 h 15 min #19281HugoKeymaster
- SOFA Consortium
I would first use for transformation a TransformEngine : this engine allows to apply a transformation (translation/rotation) and output the associated positions based on input positions. You can have a look at the example : TransformEngine. The TransformMatrixEngine might also be of interest.
I would recommend to decouple each transformation (translation // rotation).
I hope this helps.
Hugo26 April 2021 at 5 h 17 min #19309
- You must be logged in to reply to this topic.