Simulating Rotational Inverted Pendulum
Introduction
The purpose of this example is to demonstrate how a CDP Simulator project can make testing your automation system hardware independent in CDP Studio, the independent automation software for open PC-based real-time distributed control systems.
Consider a rod mounted on a horizontally rotating arm, such that the rod rotates freely in the normal plane of the arm. The arm motion is controlled by an external torque, in order to keep the rod in an upright position.
Rotary Inverted Pendulum (image courtesy, Quanser Inc. / © CC BY-SA 3.0)
Project Overview
This example includes:
- A library project containing two components:
- A regular CDP component called ArmController. It reads arm and rod angles as input and calculates the correct torque for the arm to keep the rod in the upright position.
- A simulator component called RotaryInvertedPendulumSimulator that makes this project independent from hardware. The rod and arm angles are simulated by RotaryInvertedPendulumSimulator using the torque of the arm as input.
- A system project containing three applications that may be deployed to either the same machine or different controllers. By default, they are configured to run on your local PC.
- Controller - contains the ArmController component created in the library project.
- Simulator - contains the RotaryInvertedPendulumSimulator component created in the library project and the SimulatorManager component which allows configuring some simulation properties.
- Graph - Includes a small plot to visualize the arm and rod angles. With default settings, both angles should become 0 rad once the rod is balanced.
The project implements the Example 2: Rotary Inverted Pendulum described in CDP Simulator manual with a small modification. Instead of directly Routing values between ArmController and RotaryInvertedPendulumSimulator, this example splits them into different applications and uses UDP I/O for communication. Presuming the real hardware can be controlled with UDP packets, this would enable hassle-free changing between the simulator and actual hardware as one can simply disconnect the hardware and instead run the simulator application. To get a better idea of how to configure UDPIOServer components, see the UDP Setup Guide.
How to Run the Example
To run the example from CDP Studio, open Welcome mode and find it under Examples. Next, in Configure mode right-click on the library project and select Build, then right-click on the system project and select Run & Connect. See the Running the Example Project tutorial for more information.
After running the project, a window opens which will plot the rod and arm angles. It will look something like this:
- The swing-up phase. At start-up () the rod is simply hanging, meaning its angle is π rad. Next, the arm will start swinging the rod () to get it to the upright position which is at the angle 0 rad. In this case, the swing-up was too aggressive and the rod did a full loop () meaning the new "down" position is -π rad. The swing-up continued until the rod was successfully balanced.
- The balancing phase (). Here the controller is balancing the rod in the upright position while moving the arm to desired position, which is set by Controller.ArmController.phi_desired parameter in Configure mode. In this example, the desired arm position is 0 rad.
The example has also a DHChain component based visualizer included. When you locate and click on the Graph -> Visualizer node in the Project tree then you can see the pendulum visualized like this:
For further information of how the controller and simulator components were implemented, see the Example 2: Rotary Inverted Pendulum within CDP Simulator manual.
Get started with CDP Studio today
Let us help you take your great ideas and turn them into the products your customer will love.