First of all, it seems that the API is only open for 6DOF constraints, which makes using motors difficult from the very beginning. Indeed, I would have expected to be able to simply do a setTargetVelocity() , setTargetPosition() or setForce() on simpler constraints such as a HingeJoint or a PrismaticJoint.
Is there a way to call native Havok functions to try this?
Is there an online API for Havok?
I’ve done a few tries starting with the main Havok example and the constraints example, but I can’t get the second solid to move using the motor related functions.
Here is my result on a 6DOF joint which looks like a distance constraint:
I wonder if anyone has a starting point that would allow me to start with this topic?
We’ve got a bug in HavokPlugin.setAxisMotorType() - we’re passing the motor type straight into the WASM; it needs to be converted to the “native” type, like we do for the axis ID.
I was able to workaround it in the playground by passing in the native type directly. Here’s a playground that I based on the above which shows how. I also modified the joint and shapes to make it a bit easier to see the effect of the motor. I’d definitely like to add some more interfaces to the simple joint types. As it is, they use the 6DOF interface under the hood, but in a limited way, to make them easier to setup.
Thank you very much for taking my issue into consideration.
I can now progress a lot with your workaround.
I worked several years in robotic simulations and I recommend you to open APIs to control prismatic and hinge constraints, in force, velocity and position modes. This covers 95% of the robotic cases. PID control would also be sugar.
If at some point I have a good sample to share, I will post it there.
I progress a lot with linear and angular constraints in my project, and it’s working like a charm (even if 6DOF anchors and axes are a nightmare to setup).
Linear and rotational control in velocity and position seems to work well too.
I have now another issue: is there a way to retrieve the actual angle or position of a constraint? I need this feeedback to implement PID control.
Physics6DoFConstraint.getAxisMotorTarget() allow to get the last command, but not the actual position or angle feedback.
@eoin I probably have to call some Havok API directly?
Yes, this is what I’m doing now, so I’m not blocked with this.
But I expect that the physics engine has this data internally. So recomputing it is not efficient, and not so obvious. For example, a motor controlled in position can do several turns and can have values above 2*Pi. There are also issues with signs, etc. This is not simply a crossproduct.
Every physics engine I worked with have an access to this value, for example AMMO:
We don’t actually store those values in the engine (except in some special cases), so calculating it is definitely the way to go. I agree we should put in methods in the joints to calculate these so you don’t have to write that code.
As an aside, Ammo seems to sometimes calculate it, and sometimes use a stored value:
I don’t know anything about the Ammo implementation, but my gut feeling is that using a stored value is likely to give slightly incorrect results. I guess that slider’s stored value is set inside the solver; in a PGS solver, other constraints are able to modify the bodies after that value would have been computed, so it can be slightly wrong. It also probably doesn’t account for modifications to the body transforms after the solving has completed. Could be wrong on either of these, obviously, but just looked like something I’d be concerned about.
Thank you very much for your answer.
I have to digest it, and I will come back later with this.
The bug you solved with the perpAxis may explain lot of my issues. Currently, I think there are bugs with 6DOFConstraints, when there are more than 4 DOF that are locked. I bet that it’s precisely linked with perpAxis…