It seems to lack any sort of gravity compensation – the outputs from the PD+feedforward and state-space are similar, but the state-space output is missing the positive voltage offset. If I turn off simulateGravity on the sim side, it works great.
Two questions:
Is this supposed to be the case? That the State-Space Elevator example only works for counterbalanced or horizontal elevators? Or did I break something when I tried to integrate these?
How would one add a gravity-compensation term to a state-space model? Or would it only be added outside of the core model, as it is in the ElevatorSim itself?
LQR is often aggressive enough to reject gravity anyway, but you can tack on gravity compensation to the feedforward (i.e., add a constant to the motor output).
Adding gravity to the model would make it an affine model of the form dx/dt = Ax + Bu + c, and LinearSystem expects linear systems of the form dx/dt = Ax + Bu.
I played with the error tolerances and control effort tolerance some to see how well it could reject gravity, and it’s not too bad, but it oscillates far more than the PD+feedforward version did in response to noise, and the average steady-state error is larger (0.02m vs. ~0.002m). Of course, all of this is with a simulated elevator; I’m not sure if/when it’ll be possible to test with the actual one from this past season – it may be better-behaved than the simulation implies.
If I’m reading this correctly, that would make it incompatible with the remaining code and libraries? Is there a way to alter the model, yet maintain compatibility?
Would it be possible to maintain the same form by adding an acceleration component to the state vector?