Practice#

In this section, you will be tasked with solving a control problem from start to finish.

Feel free to proceed as you wish. You could use a mathematical model or learn a model from data and then attempt to control it.

We will be using the Pendulum environment from gymnasium.

The system consists of a pendulum attached at one end to a fixed point, and the other end being free. The pendulum starts in a random position and we can apply torque to rotate the free end.

As seen below, the pendulum is represented in red and the joint is represented in black.

env = create_pendulum_environment()
result = simulate_environment(env)
show_video(result.frames, fps=env.metadata["render_fps"])
error: XDG_RUNTIME_DIR not set in the environment.

The environments allows the use of the following control (action):

Index

Action

Unit

Min

Max

0

apply torque to the actuated joint

torque (N m)

-2

2

and the following measurements (observation):

Index

Observation

Min

Max

0

\(\cos(\theta)\)

\(-1\)

\(1\)

1

\(\sin(\theta)\)

\(-1\)

\(1\)

2

\(\dot{\theta}\)

\(-8\)

\(8\)

First Goal#

The first goal is to apply torques on the actuated joint to swing the pendulum into an upright position and keep it there.

Second Goal#

The second goal is to apply torques on the actuated joint to swing the pendulum as fast as possible.

Exercise 1#

Exercise 8 (Pendulum Model)

Use one of the previously seen methods to learn a model of the system from data.

Hint

If you would like to use a mathematical model of the system either for the control or just as help when learning a model, then please refer to the following page for the equations.

Exercise 2#

Exercise 9 (Pendulum Control)

Use the learned model and synthesize a controller to achieve the goals described above.