Course Project: Modelling of Cyber-Physical Systems
Method: PD stabilization with relay-based switching to an energy swing-up controller
This repository contains mathematical models, simulations, and control systems for selected mechanical systems from the pendulum family, with particular focus on the Furuta Pendulum (Rotational Inverted Pendulum).
The project was developed as part of the Modelling of Cyber-Physical Systems course, using MATLAB & Simulink.
Inverted pendulum systems are a classic problem in control theory and robotics - they are nonlinear, open-loop unstable systems, and therefore require an active control system to keep the pendulum in the upright position.
Before implementation, the system was analyzed on paper: identifying the double rotational movement (arm → pendulum), the control input (torque), the target states for stabilization (θ = π, ω = 0; θ = 0, ω = 0), workspace constraints, and open questions such as joint friction and moments of inertia of both components.
Modelling_of_CPS/
├── controlled_inverted_pendulum_on_a_cart/ # Pendulum on a cart with a control system
├── pendulum_on_a_cart/ # Pendulum on a cart (open-loop model)
├── simple_pendulum/ # Simple pendulum (base model)
├── img/ # Plots, diagrams, and images for documentation
├── furuta.slx # Main Simulink model of the Furuta Pendulum
├── main.m # Script initializing parameters and simulation
└── README.md # Project documentation
A basic single-degree-of-freedom model used to verify the correctness of physical parameters and the fundamentals of the dynamics.
A model of the traditional inverted pendulum mounted on a cart moving along a rail. It includes both the open-loop version and the closed-loop version with a feedback controller.
A rotational inverted pendulum consisting of an arm rotating in the horizontal plane and a freely swinging pendulum arm attached to it, rotating in the vertical plane.
The top-level diagram connects the controller (Regulator_upright) with the physical pendulum model (Multibody) in a closed feedback loop. Based on the angles and velocities of the arm and the pendulum, the controller computes the control signal (drive torque), which is fed into the physical model.
The controller consists of two PD loops – one for the arm (kp_arm, kd_arm) and one for the pendulum (kp_pend, kd_pend). A Relay block switches the control strategy depending on the size of the deviation:
- Stabilization (upright control) – when the pendulum's deviation from the vertical is within about ±30°, the PD controller is active and keeps the pendulum in the upright position.
- Swing-up control – when the deviation exceeds about 30° (0.52 rad), the
Swing-up Controlblock is activated, injecting the energy needed to bring the pendulum close to the upright position.
⚠️ Known limitation: the model works correctly only for initial deflections of up to ~32° from the upright position. For larger deflections the swing-up mechanism fails to stabilize the system and the pendulum starts spinning uncontrollably.⚠️
The physical part was modelled in Simscape Multibody. The system consists of an arm (Rod) with a counterweight (Counter mass) driven by a revolute joint, and a freely suspended pendulum (Pendulum) connected via a second revolute joint. Angles and angular velocities are read from the joints and fed to the controller, while the control signal is applied as a torque on the arm joint.
Preview of the system in Mechanics Explorer – the grey pendulum stabilized in the upright position, the green arm with a red counterweight rotating in the horizontal plane.
The plots below show the system response for an initial pendulum deflection of about 30° from the upright position. The pendulum angle converges to π rad (upright position) within few seconds, while the arm angle, both angular velocities, and the control signal all settle to zero – the pendulum is stabilized and the arm returns to its reference position.





