Lab 12b: LQG on the Inverted Pendulum on a Cart

Objective

The purpose of this lab is to stabilize an inverted pendulum on a cart from lab 11b using Kalman filter on the simulator.

Checking out the Kalman Filter

  1. Kalman filter A and B matrix were changed from the previous lab because we are working in discrete time compared to continuous time.
  2. Running the simulator as it is threw some errors. I had to change all the np.cos(theta) and np.sin(theta) to np.cos(theta[0]) and np.sin(theta[0]) to fix the error. This is the video of the inverted pendulum after the code correction.
  3. When you print the obsv(A,C) command, you get a matrix that looks like this.

    Each column represents the state we are trying to observe. The first column of zeros indicate that the z state is not observable since the first column is not linearly independent. However, as seen in the video, the inverted pendulum is capable of stabilizing itself. This is because in the C matrix (seen below), only measures the fourth state, which is the angular velocity (theta dot). Seen on the observability matrix, the fourth column is linearly independent and observable.

    The performance graphs also show that each state was stable.

Adding Imperfections and Adjusting Kalman Filter

  1. I uncommented the line with process noise in pendulumNonlinearDynamics.py.

    It added some noise to the states, but Kalman filter was able to still stabilize the inverted pendulum.

    I added more noise to the y_kf to get a noiser output. It seems that the Kalman filter still does a good job of stabilizing despite the added noises.

  2. I changed the inital state to see how well the Kalman filter converges to the correct state. I changed from the given values:

    to these values:

    It might be hard to measure the initial position and initial angle properly, but it is reasonable to assume that the inverted pendulum started from rest, which is why the initial velocities remained unchanged. When I ran the simulation, the Kalman filter did a good job stabilizing the inverted pendulum, which can be seen from the performance graph.
  3. I added realistic saturation and deadband to u taken from lab 11.

    The Kalman filter had no problem stabilizing even with control limits, which can be seen in the performance graph below.
  4. I had already added in the measurement and process noise from previous steps.
  5. I made adjustments to the A and B matrix until the system failed. I was able to do so when A multiplied by 0.3 and B multiplied by 0.9. It seemed that the B matrix does not affect the system's stability as much as making adjustments to A, which makes sense since A matrix is representative of the system.

    The performance of this adjustment can be seen below. The inverted pendulum attempted for the first few seconds, but was unable to recover afterwards.
  6. I changed the update rate of the controller and estimator to see how much of delay would lead the inverted pendulum to become unstable.
    First, I tested with time update of 0.05 seconds. The pendulum seems jittery, but is still stable. This can be seen in the performance graphs.

    I tested update time of 0.1 seconds and it took a few seconds to reach unstable state. Compared to delay of 0.05 seconds, it can be clearly seen in the graph that it was not a stable system.
  7. If I learned anything in this class, it is that simulations are extremely different from real life. I think these simulations show a good potential for making a real life inverted pendulum on the robot. However, there are many other factors, such as friction, motors, battery, battery life, etc to consider.