to hack the effect of a PID, I just added a fake scale that amplify the error.
there is a very good intuitive explanation of the PID controller in wikipedia
https://en.wikipedia.org/wiki/PID_controller
for us as I said before, the correction should be
- Code: Select all
accel = - ke * error - Ki * errorSum - kv * veloc;
errorSum = errorSum + error;
the hack is just scaling the error, in essence making a stronger Ks, while will be wrong, but for testing is ok.
if you now just go to line 248 in file ../newton-4.00\sdk\dNewton\dIkSolver\ndIk6DofEffector.cpp
and you play FAKE_PID_factor, you will see how the yellow dot catches better with the target.
and that is when we look for, by is had to be adaptive which is what the PID will do for us.
float FAKE_PID_factor = 10.0f;
our Implementation of the PID will be like this
- Code: Select all
accel = - ke * (positError + errorSum) - kv * veloc;
errorSum = errorSum + Ki * positError;
this way the ki pid will be a normalized scale of the error. if we make it zero, it will be them is will be and normal PD as it is now. no all joint need PID.
and finally if you go to the controller, and uncomement the line that set the target matrix to be the desire one. lie this.
- Code: Select all
ndVector localGravity(matrix1.UnrotateVector(m_gravityDir));
//ndMatrix targetMatrix(m_effector->GetOffsetMatrix());
ndMatrix targetMatrix(dGetIdentityMatrix() * matrix1.Inverse());
targetMatrix.m_posit = localGravity.Scale(1.0f) | ndVector::m_wOne;
it just moves to the point that keep the balance, applyng that toque to the box, and them just stops there.
the top box keeps rotating because is reach and indifferent equilibrium, it is exactly the behavior we look for, basically the rotation of the box does no add or remove momentum to the system for that the pivot has to be offset from the center so that any rotation make the com goes up of down.
so far I like these results.