WPILib State Space Elevator Question

I started playing around with the WPILib Elevator Simulation. I evolved the original example some, then brought in the state-space elevator code to see how it would work.

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:

  1. 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?

  2. 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.

Thanks, good to know.

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?

Add a feedforward term to compensate for it and ignore it in the system dynamics otherwise (use an ordinary linear feedback controller).

In other words, pretend gravity doesn’t exist except for the constant voltage you add to your motor output at the end.

2 Likes