Quote:
Originally Posted by Spoam
However, for a velocity it converges to about 65% of the velocity I want (e.g. a desired state of [x_hat(k), 1] asymptotically approaches [x_hat(k), .65] instead) (and what it converges to depends on the poles, which seems bizarre to me; my intuition tells me <1 eigenvalues should stabilize to 0 not something arbitrary like .35). Anyone know why?
|
The reason for this is that, in order to sustain a constant velocity, the motor will require a non-zero voltage, but when you reach your goal velocity, R - x_hat = 0 and so the output voltage is zero and so the motor will not actually achieve that velocity. In order to handle this, you need to add a feed-forward value to U which is proportional to the goal velocity.
Another trick that 971 has used in the past is, instead of always updating the position goal to be the same as the current position, instead, on each timestep, update the position goal by the velocity goal * dt and make sure that the position goal never runs off too far from the current position.
Quote:
Code:
%put A and B in discrete time space
A_d = expm(A*dt);
B_d = pinv(A)*(A_d - eye(size(A_d)))*B;
|
Since you're using matlab, you may as well use the provided c2d function; python has no such function, hence why 971 implemented it themselves.
Quote:
|
Also, I imagine to use it as a real controller I would just replace "C*x" with an encoder/sensor value and feed u to the motor controller, correct?
|
That is correct.
Quote:
If the code is completely wrong somewhere please tell me
|
Nothing strikes me as wrong; I haven't tried running your code myself though.
Good luck getting this working; I had a lot of fun learning this stuff in High School.