Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Filo - Calculating weight on cable point
#7
(19-03-2020, 04:42 PM)MarcPilgaard Wrote: - All weights are negative

Negate the impulse magnitude. My original code simply divided by a negative scalar value, but once you deal with vectors signs become important. Keep in mind that the jacobian points from the first link to the second link in the cable. So while the impulse magnitude applied to the first link has the same sign as the jacobian (towards the second link), the impulse magnitude applied to the second link goes in the opposite direction (towards the first link).

Also you're projecting the gravity vector, then calculating its length. This is both unnecessary and can be slightly off: when you perform a dot product with a unit length vector (such as the jacobian), the result is the projection length, and it has the correct sign depending on the relative directions both vectors are pointing.

The dot product is all you really need, because the jacobian has unit length:

Code:
//Last joint where the weight is attached
CableJoint joint = cable.Joints[0];

// Calculate force by diving Impulse with Time
float force = -joint.ImpulseMagnitude / Time.fixedDeltaTime;

//Calculate the weight by dividing the force by the "amount" of gravity along the constraint gradient:
float weight = force / Vector3.Dot(Physics.gravity, joint.Jacobian);

(19-03-2020, 04:42 PM)MarcPilgaard Wrote: - When I move my crane around, slowly, the weight fluctuates alot, much more than I would have expected, sometimes the calculated weights briefly becomes 0.0. But the element we are moving is being moved very slowly, so I doubt it is because the cables starts to slack.

Can't reproduce, the mass reported is pretty stable and accurate for me. Edit: try calculating the mass in LateUpdate() instead of FixedUpdate(). FixedUpdate is called a variable amount of times each frame, might not even be called at all. Joints will always report the last impulse data they applied, so reading it in LateUpdate() is safe.

This method calculates the mass "seen" by the cable. If the cable has to pull the load to move it against gravity, the mass reported by this method will be higher than the actual mass of the load. Also, if the cable has some slack, it will report 0 mass. Also, mass can be slightly off due to non-perfect convergence. If the timestep is large or the amount of iterations not high enough, the reported mass will be higher because the cables are slightly overstretched.
Reply


Messages In This Thread
RE: Filo - Calculating weight on cable point - by josemendez - 20-03-2020, 12:05 PM