
Using Gazebo and Ros2 to Simulate And Control an Inverted Pendulum
Brief Overview
As an introduction to using Gazebo for simulating physics and controllers, I implemented a PI controller for inverted pendulum. I designed the Gazebo model using .sdf format which consisted of base frame, a slider with prismatic joint, and the pendulum with revolute joint constrained to the slider. To get the orientation of the pendulum, I used an IMU. On the Ros2 side, I created a node that imported the IMU data from Gazebo and actuated the prismatic joint velocity using a PI controller. The briding between Ros2 and Gazebo is done using a .yaml file. A launch file is also created to launch the controller, bridge, and gazebo model. The rqt_graph of the Ros2 is provided below.
Controller Implementation:
1. PI (Proportional- Integral)
K_p = 0.27, K_I = 0.26
2. LQR (Linear Quadratic Regulator)
K = [0, 1.5, 0, 0.4] for state vector = [cart_position, roll angle, cart_velocity, roll_velocity]
Supporting Files
The corresponding code can be found here