An inverted pendulum control system and experimental method based on network communication
Through the inverted pendulum control system based on network communication, the UDP communication protocol is used to realize two-way data interaction among the experimental interaction system, the programming system and the inverted pendulum system, which solves the problems of high programming complexity and high hardware cost of the existing system and realizes convenient teaching experiments and virtual simulation effects.
Patent Information
- Application Number
- CN202511038782.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-28
- Publication Date
- 2025-09-19
- Estimated Expiration
- 2045-07-28
AI Technical Summary
The existing inverted pendulum control system has high programming complexity, high hardware cost, unreasonable resource utilization and limited use, which makes it difficult to meet the needs of efficient teaching and convenient experiments.
An inverted pendulum control system based on network communication is adopted. Through UDP communication between the experimental interaction system, the programming system and the inverted pendulum system, the servo drive control box is directly controlled and the control instructions written by the user are received. Matlab and Python programming are supported to achieve real-time control and virtual simulation.
It reduces the user's programming ability requirements, improves the convenience of teaching experiments, supports Matlab and Python tools to verify algorithms, and has virtual simulation and digital twin functions.
Smart Images

Figure CN120540180B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a control theory experimental platform, in particular to an inverted pendulum control system and an experimental method based on network communication. Background Art
[0002] As a classic experimental platform in the field of control theory, the inverted pendulum system is widely used in teaching and research. Traditional inverted pendulum systems are mainly divided into two categories, each with its own limitations.
[0003] The first category involves embedded systems based on microprocessors (such as single-chip microcomputers, DSPs, and ARM processors), low-cost sensors, and actuators. These systems require users to write slave hardware drivers and control algorithms in C language within an IDE compiler. Simultaneously, they develop a master program based on slave communication protocols to observe experimental data. This approach places stringent demands on user programming skills and creates high programming complexity, significantly hindering user efficiency and learning.
[0004] The second category is a real-time inverted pendulum hardware-in-the-loop simulation experiment platform designed by a well-known educational instrument company based on Matlab's RTW toolset. These platforms are typically constructed using standardized industrial components such as PCI motion control boards, servo drives and motors, and incremental encoders. While Matlab's RTW toolset simplifies the process from system design to hardware implementation, allowing users to focus on control algorithm development, PCI motion control boards have numerous drawbacks. On the one hand, their powerful functionality comes at a high price, leading to significant hardware resource redundancy and increased development costs when used in inverted pendulum systems. On the other hand, their reliance on the PCI interface in desktop PCs or industrial computers limits the device's flexibility and inconvenient connectivity, making them unsuitable for the control needs of mobile devices such as laptops.
[0005] In summary, the existing inverted pendulum control system has problems such as high programming difficulty, high hardware cost, unreasonable resource utilization and limited use. It is difficult to meet the needs of efficient teaching and convenient experiments. There is an urgent need for a simpler, more economical and flexible inverted pendulum control system to overcome these shortcomings. Summary of the Invention
[0006] In view of the shortcomings of the existing technology, the present invention provides an inverted pendulum control system and experimental method based on network communication. Based on the interactive program installed in the experimental interactive system, the present invention directly controls the servo drive control box and reads signals. It also directly communicates with Matlab and Python programs, receiving control instructions written by the user directly in Matlab or Python. Based on these control instructions, the inverted pendulum system is controlled in real time, reducing the programming requirements for the user and improving the convenience of teaching experiments.
[0007] The technical means adopted in the present invention are as follows.
[0008] An inverted pendulum control system based on network communication comprises: a programming system for compiling control instructions for controlling the movement of the inverted pendulum system and an experimental control algorithm, the programming system being one of Matlab, Simulink or Python; an experimental interaction system, the experimental interaction system being equipped with a first interactive program and a second interactive program, the first interactive program being based on a UDP communication protocol to implement bidirectional data interaction between the experimental interaction system and the programming system, the second interactive program being based on a UDP communication protocol to implement bidirectional data interaction between the experimental interaction system and the inverted pendulum system; and an inverted pendulum system, the inverted pendulum system being configured to move according to the control instructions and output real-time status data of the inverted pendulum to the experimental interaction system.
[0009] Furthermore, the inverted pendulum system includes a real inverted pendulum or a virtual inverted pendulum.
[0010] Furthermore, the physical inverted pendulum includes a servo drive control box and a trolley that reciprocates on a guide rail, and the trolley is provided with a pendulum. The servo drive control box is connected to the experimental interaction system for communication and reception of control instructions on the one hand, and is connected to the sensor for collecting real-time status data of the inverted pendulum and sending it to the experimental interaction system on the other hand; the sensor includes an angle encoder for reading the inclination angle of the pendulum and a motor encoder for reading the position and speed of the trolley.
[0011] Furthermore, the virtual inverted pendulum is established by simulating a real inverted pendulum using a Unity3D animation module.
[0012] Furthermore, the control algorithm used in the experiment is one of a nonlinear control algorithm, a variable structure control algorithm, a predictive control algorithm, a robust control algorithm and a fuzzy control algorithm.
[0013] The present invention also discloses a physical inverted pendulum experimental method based on network communication, which is implemented based on the above-mentioned system and includes the following steps: S101, compiling control instructions and experimental control algorithms for controlling the actions of the inverted pendulum system through a programming system, and the programming system is one of Matlab, Simulink or Python; S102, the experimental interactive system receives the control instructions through a first interactive program, converts the control instructions into motor torque control instructions for the trolley, and sends the motor torque control instructions to the physical inverted pendulum system through a second interactive program; S103, the physical inverted pendulum system drives the trolley to move according to the motor torque control instructions, and at the same time collects real-time status data of the inverted pendulum through sensors, and sends the real-time status data of the inverted pendulum to the experimental interactive system through the second interactive program; S104, the experimental interactive system inputs the real-time status data of the inverted pendulum into the experimental control algorithm compiled by the programming system through the first interactive program, and outputs further control instructions based on the experimental control algorithm, and returns to S101.
[0014] Furthermore, the method also includes the following steps: S105, generating a follow-up display interface of the virtual inverted pendulum through the Unity3D animation module to realize the digital twin of the real inverted pendulum.
[0015] The present invention also discloses a virtual inverted pendulum experimental method based on network communication, which is implemented based on the above-mentioned system and includes the following steps: S201, compiling control instructions and experimental control algorithms for controlling the actions of the inverted pendulum system through a programming system, and the programming system is one of Matlab, Simulink or Python; S202, the experimental interactive system receives the control instructions through a first interactive program, converts the control instructions into motor torque control instructions for a virtual car, and sends the motor torque control instructions to the virtual inverted pendulum system through a second interactive program; S203, the virtual inverted pendulum system drives the virtual car to move according to the motor torque control instructions, and at the same time collects real-time status data of the virtual inverted pendulum through a virtual sensor, and sends the real-time status data of the virtual inverted pendulum to the experimental interactive system through the second interactive program; S204, the experimental interactive system inputs the real-time status data of the virtual inverted pendulum into the experimental control algorithm compiled by the programming system through the first interactive program, and outputs further control instructions based on the experimental control algorithm, and returns to S201.
[0016] Compared with the prior art, the present invention has the following advantages.
[0017] This paper discloses a network-based inverted pendulum control system and experimental method. This method simplifies the control structure, allowing the experimental interaction system to directly control the inverted pendulum system's servo drive control box, thereby controlling the motor torque and achieving real-time control of the trolley. The system also supports real-time control interfaces for Matlab and Python, making it easy for students to quickly get started. Students can freely use Matlab and Python tools to verify algorithms, and the system supports virtual simulation and digital twin capabilities. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0019] Figure 1 This is a working principle diagram of an inverted pendulum control system based on network communication in an embodiment of the present invention.
[0020] Figure 2 This is a working principle diagram of an inverted pendulum based on a PID algorithm in an embodiment of the present invention.
[0021] Figure 3 Schematic diagram of the actual inverted pendulum structure in an embodiment of the present invention.
[0022] Figure 4 Schematic diagram of the parameter setting interface for inverted pendulum control in an embodiment of the present invention.
[0023] Figure 5 This is the inverted pendulum model used in the embodiment of the present invention.
[0024] In the figure: 1. Servo motor; 2. First fixed seat; 3. Guide rod; 4. Carriage; 5. Angle encoder; 6. Mechanical collision block; 7. Base; 8. Rocker arm; 9. Counterweight; 10. Second fixed seat; 11. Belt; 12. Connecting rod; 13. Track; 14. Set screw; 15. Limit device. DETAILED DESCRIPTION
[0025] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of the present invention.
[0026] It should be noted that the terms "first", "second", etc. in the description and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0027] Example 1
[0028] The present invention provides an inverted pendulum control system based on network communication, which mainly includes a programming system, an experimental interaction system, and an inverted pendulum system. The programming system compiles control instructions for controlling the movement of the inverted pendulum system and an experimental control algorithm. The experimental interaction system is equipped with a first interactive program and a second interactive program. The first interactive program implements bidirectional data exchange between the experimental interaction system and the programming system based on the UDP (User Datagram Protocol) communication protocol, and the second interactive program implements bidirectional data exchange between the experimental interaction system and the inverted pendulum system based on the UDP communication protocol. The inverted pendulum system is configured to operate according to the control instructions and output real-time status data of the inverted pendulum to the experimental interaction system. The inverted pendulum system can use a physical inverted pendulum or a virtual inverted pendulum.
[0029] Further, if Figure 1 As shown, the programming system in the embodiments of this application is Matlab, Simulink, or Python running on a computer. Matlab or Python software can be used to compile real-world control algorithms such as root loci, PID, and fuzzy control, as well as perform experiments such as LQR. In preferred embodiments of the present invention, the computer can also be equipped with Unity3D software, which enables digital twinning and virtual simulation.
[0030] Furthermore, the experimental interaction system in the embodiment of the present application is an experimental control C# software program running on a computer, which collects the real-time status of the inverted pendulum system in real time through the UDP communication protocol, and obtains the real-time status data of the inverted pendulum system through calculation and processing, including the trolley position, trolley speed, pendulum position, pendulum angle and trolley acceleration, and realizes the display of the curve graph of data changing with time in the UI interface through the software code function, and completes the function of saving the collected inverted pendulum real-time status data as csv data.
[0031] Furthermore, as a preferred embodiment of the present invention, a physical inverted pendulum includes a servo drive control box and a trolley that reciprocates on a guide rail. The trolley is provided with a pendulum arm. The servo drive control box communicates with the experimental interaction system to receive trolley control commands and connects to sensors to collect real-time status data of the inverted pendulum and transmit it to the experimental interaction system. The sensors include an angle encoder for reading the pendulum arm's tilt angle and a motor encoder for reading the trolley's position and speed.
[0032] Specifically, if Figure 3 As shown, the real inverted pendulum includes a guide rod 3, a slider unit, a servo motor 1, a base 7, a transmission unit and a servo drive control box. The transmission unit includes a first fixed base 2, a first pulley, a second fixed base 10, a second pulley, and a belt 11. The first and second fixed bases 2 and 10 are hollow and shaped like a Chinese character "J." The slider unit includes a rocker arm 8, a connecting rod 12, a trolley 4, and an angle encoder 5. The servo motor 1 is fixed to the base 7, with the output end of the servo motor 1 connected to either the first pulley or the second pulley. The first pulley is located inside the first fixed base 2, and the second pulley is fixedly mounted inside the second fixed base 10. The first and second pulleys are connected by a belt 11. The ends of the guide rod 3 are fixed to the first and second fixed bases 2 and 10, respectively. The trolley 4 is movably mounted on the guide rod 3. The angle encoder 5 is mounted on the trolley 4. One end of the connecting rod 12 is connected to the angle encoder 5, and the other end of the connecting rod 12 is fixedly connected to one end of the rocker arm 8. The angle encoder 5 is connected to the servo drive control box, which is in turn connected to the servo motor 1. A counterweight 9 is provided at the other end of the rocker arm 8. A limit device 15 is provided on the base 7. Mechanical collision blocks 6 are provided at both ends of the guide rod 3. Set screws 14 are provided on the sides of the first fixing seat 2. Set screws 14 are provided on the sides of the second fixing seat 10. A hollow track 13 is connected to the servo motor 1, and the track 13 is connected to the servo motor 1 and the angle encoder 5, respectively.
[0033] While the physical inverted pendulum is operating, the programming system reads real-time status data from the experimental interactive system via UDP. By modeling the inverted pendulum system, the control algorithm is developed in Matlab, Simulink, or Python. Taking the linear quadratic regulator (LQR) as an example, the feedback matrix K is calculated by adjusting the QR, and the control algorithm is developed in Matlab or Python. The real-time status data of the inverted pendulum system includes the position and speed of the trolley, the pendulum arm angle, the pendulum arm angular velocity, the actual acceleration of the trolley, and the limit status. The trolley acceleration is the controlled variable of the experimental control algorithm. Sensor parameters of the inverted pendulum system include the motor encoder value, the angle encoder value, and the limit signal.
[0034] The experimental interactive system reads the acceleration of the car calculated by Matlab or Python through the UDP communication protocol, converts it into the motor torque control quantity through software calculation, and communicates it to the servo drive control box in real time, and then the motor torque completes the physical inverted pendulum control.
[0035] Furthermore, as another preferred embodiment of the present invention, the inverted pendulum system is a virtual inverted pendulum. At this time, the experimental interactive system sends the real-time status data of the inverted pendulum to the virtual inverted pendulum established by simulating the real inverted pendulum by the Unity3D animation module. When the virtual inverted pendulum receives and parses the data, it converts the corresponding data into the trolley position and the pendulum rod angle, and assigns the data to the trolley movement and pendulum rod rotation script functions, thereby realizing the movement of the virtual inverted pendulum trolley and the rod, and then realizing the synchronous control of the virtual inverted pendulum and the real inverted pendulum, digital twin.
[0036] Specifically, the experimental interactive system calculates the dynamic model of the physical inverted pendulum and establishes mathematical nonlinear system functions, such as Figure 4 As shown in the figure, a virtual dynamic environment for an inverted pendulum is created. By setting the trolley mass, pendulum mass, pendulum length, slide length, trolley friction coefficient, pendulum rotation friction coefficient, simulation execution cycle, simulation environment gain coefficient, and the dynamic environment of the system, the user writes the experimental control algorithm in Matlab or Python to interact with the experimental interactive system data, and sends the system data and the real-time status data of the inverted pendulum to the virtual inverted pendulum. The virtual inverted pendulum performs data analysis to obtain the virtual trolley position and pendulum angle, and assigns the data to the trolley movement and pendulum rotation script functions, finally realizing the movement of the virtual inverted pendulum trolley and pendulum, and realizing virtual simulation.
[0037] Preferably, the experimental interaction system is equipped with a UI system. Different functions are executed by mode selection in the UI system. Different functions such as physical control and virtual simulation are realized by experimental control algorithms compiled by Matlab or Python. A parameter modification menu is added to the UI system, including the functions of modifying basic parameters and more parameters, saving, recording parameter templates, importing parameter templates, and restoring default parameters.
[0038] Further preferably, a log area can be added to the experimental interactive system to display the result information of the system execution, a real-time data display area can display the real-time data of the system, and an image curve area can display a curve chart of the system data changing over time.
[0039] Example 2
[0040] This embodiment discloses a physical inverted pendulum experiment method based on network communication, which is implemented based on the above system and includes the following steps.
[0041] S101 , compiling control instructions for controlling the motion of the inverted pendulum system and an experimental control algorithm through a programming system, wherein the programming system is one of Matlab, Simulink or Python.
[0042] S102. The experimental interactive system receives the control instruction through the first interactive program, converts the control instruction into a motor torque control instruction for the vehicle, and sends the motor torque control instruction to the physical inverted pendulum system through the second interactive program.
[0043] S103. The physical inverted pendulum system drives the trolley to move according to the motor torque control instruction, and at the same time collects the real-time state data of the inverted pendulum through the sensor, and sends the real-time state data of the inverted pendulum to the experimental interactive system through the second interactive program.
[0044] S104. The experimental interactive system inputs the real-time state data of the inverted pendulum into the experimental control algorithm compiled by the programming system through the first interactive program, and outputs further control instructions based on the experimental control algorithm, and returns to S101.
[0045] Furthermore, the method may also include the following steps: S105, generating a follow-up display interface of the virtual inverted pendulum through the Unity3D animation module to realize the digital twin of the real inverted pendulum.
[0046] Specifically, when conducting a physical inverted pendulum control experiment, the user writes an experimental control algorithm in Matlab, Simulink or Python, turns on the physical inverted pendulum, and the sensor signals collected by the inverted pendulum (including motor encoder values, angle encoder values and limit signals) are collected by the AC servo motor driver installed in the servo drive control box and transmitted to the experimental interactive system through UDP communication. The C# program algorithm of the experimental interactive system processes the collected original sensor signals into system state quantities (including the position of the car, the speed of the car, the pendulum angle, the pendulum angular velocity, the actual acceleration of the car and the limit status). The data is then transmitted to Matlab, Simulink or Python in real time via UDP communication. After processing by the experimental control algorithm written by the user, the obtained car acceleration is transferred to the experimental interactive system via UDP communication. The algorithm of the experimental interactive system then converts the car acceleration into a servo motor torque control instruction and transmits it to the servo driver, driving the servo motor to control the movement of the car. This cycle completes the control of the inverted pendulum system to ensure that the inverted pendulum does not fall. Figure 2The figure shows a schematic diagram of the working principle of an inverted pendulum experiment using the PID algorithm using the method of this application. Furthermore, based on the user-controlled physical inverted pendulum experiment, the experimental interactive system transmits the inverted pendulum system state data to the Unity virtual module to complete the follow-up display. At this time, the motion state of the inverted pendulum in the animation is completely consistent with the physical effect, thus realizing digital twinning.
[0047] Example 3
[0048] This embodiment discloses a virtual inverted pendulum experimental method based on network communication, which is implemented based on the above system and includes the following steps.
[0049] S201 , compiling control instructions for controlling the motion of the inverted pendulum system and an experimental control algorithm through a programming system, wherein the programming system is one of Matlab, Simulink or Python.
[0050] S202. The experimental interactive system receives the control instruction through the first interactive program, converts the control instruction into a motor torque control instruction for the virtual car, and sends the motor torque control instruction to the virtual inverted pendulum system through the second interactive program.
[0051] S203. The virtual inverted pendulum system drives the virtual car to move according to the motor torque control instruction, and at the same time collects the real-time state data of the virtual inverted pendulum through the virtual sensor, and sends the real-time state data of the virtual inverted pendulum to the experimental interactive system through the second interactive program.
[0052] S204 . The experimental interactive system inputs the real-time state data of the virtual inverted pendulum into the experimental control algorithm compiled by the programming system through the first interactive program, and outputs further control instructions based on the experimental control algorithm, and returns to S201 .
[0053] Specifically, when conducting a virtual inverted pendulum control experiment, the user writes the experimental control algorithm in Matlab, Simulink or Python, opens the Unity virtual animation, and the experimental interaction system provides a virtual inverted pendulum environment to simulate a real-world simulation environment. The acceleration of the car output by the user-written experimental algorithm is transmitted to the experimental interaction system via UDP. The Unity virtual animation replaces the real-world object to produce the action, and returns the real-time status data of the virtual inverted pendulum at this time to the experimental control algorithm of the programming system, and sends the real-time status data of the virtual inverted pendulum to Unity's 3D animation for real-time animation display, completing the virtual simulation experiment instead of the real object.
[0054] Example 4
[0055] This embodiment provides a method for performing a physical inverted pendulum experiment based on the system in Example 1. The specific process mainly includes the following steps.
[0056] 1. Build a physical inverted pendulum system. The electrical components used in this embodiment include a 200W AC servo motor, an angle encoder, and a limit switch.
[0057] 2. Connect the AC servo motor, angle encoder, and switch signal cables and control cables to the AC servo driver in the servo drive control box to complete the AC servo connection. Read the servo motor encoder values, the swing arm angle encoder values, and the switch limit sensor signals. The AC servo driver uses torque control mode. Controlling the torque output by the AC servo driver changes the motor current, thereby changing the motor's torque.
[0058] 3. Create UDP communication between the AC servo drive register and the experimental interactive system. It is necessary to read the motor encoder, angle encoder, and limit signals and values from the AC server.
[0059] 4. After the first power-on, it is necessary to give the servo motor a constant torque and control speed, so that the servo motor drives the belt to control the movement of the trolley to the sensor position on the right. The sensor status is read through the AC servo driver to control the trolley to stop moving, and the motor pulse value of the sensor zero point is recorded. The difference between the servo motor pulse value and the pulse value at zero point collected at any time corresponds to the position of the trolley on the guide rail. The position, speed and acceleration of the trolley are obtained through collection and processing, and filtered data processing is introduced when calculating the speed and acceleration.
[0060] 5. When powered on for the first time, take the pendulum pointing vertically downward as the zero point and record the angle pulse value at this time. After that, the difference at any position will correspond to the angle of the pendulum in one circle after processing, and the pendulum angle and pendulum angular velocity will be obtained using the same method as above.
[0061] 6. The C# program of the experimental interactive system must complete the control algorithm of the car's acceleration to the motor torque, that is, to ensure that the car's acceleration is the set value by controlling the motor torque value of the AC servo.
[0062] 7. Write a PID-based control algorithm in the programming system to control the motor torque value, and add other special algorithms to limit torque mutations and handle nonlinearity.
[0063] 8. Write a safety protection program in the programming system. If the pendulum angle exceeds the control angle, the motor control will be stopped. If the car speed and acceleration exceed the set maximum, they will be limited and output according to the maximum value. If the car acceleration is abnormal or the control sudden change is unreasonable, the motor control will be stopped to protect the motor. If the car displacement reaches the limit, the motor will be stopped immediately to ensure the safety of the experiment.
[0064] 9. The experimental interactive system packages the inverted pendulum system's real-time status data (trolley position, trolley speed, trolley acceleration, pendulum arm angle, and pendulum arm angular velocity) processed in the previous step into a single packet. Using UDP communication, the system binds the local IP address to the corresponding Matlab port number and sends the data to Matlab via UDP. There is no set communication interval.
[0065] 10. Use the UDP receiving module in Matlab / Simulink to receive data sent from the experimental interaction system, expand it into the corresponding data format, and then scale it up and down to convert it into the international units used for modeling.
[0066] 11. The time step processed by Matlab / Simulink real-time simulation software is inconsistent with the display time. It is necessary to add a timing module to make the running time of Matlab consistent with the real time and set the control time of Simulink to inf infinite.
[0067] 12. Use the UDP send module in Matlab / Simulink to bind the port number of the experimental interaction system, transmit the final controlled car acceleration to the experimental interaction system via UDP, and control the sampling period of Simulink to 3ms to complete the 3ms period inverted pendulum control system.
[0068] 13. Complete the modeling of the inverted pendulum system using the following steps. Design an experimental control algorithm to calculate the vehicle's acceleration from the system's state variables in Matlab / Simulink and transmit it to the experimental interaction system. The specific parameter settings for the inverted pendulum model are shown below.
[0069] M-trolley mass, unit: kg.
[0070] m- mass of the pendulum, in kg.
[0071] F-The external force the car receives from the motor, in N.
[0072] f- friction resistance received by the car.
[0073] b-The coefficient of friction resistance received by the car.
[0074] - The angle between the pendulum arm and the vertical upward direction, measured in rad. In the real world, the vertical upward direction is considered zero, and the direction toward the motor is considered positive.
[0075] x - Carriage position, in meters. In the real world, the effective stroke center is the 0 point, and the side closest to the motor is the positive direction.
[0076] J- moment of inertia of the pendulum.
[0077] l-The distance from the center of mass of the pendulum to the center of rotation, in meters.
[0078] Before the experiment, we first need to model the system of the car. There are generally two methods: Lagrange equation and Newton-Euler equation. If the Lagrange method is used for modeling, the Lagrange equation is:
[0079] (1)
[0080] Where L is the Lagrangian operator, q is the generalized coordinate of the system, T is the kinetic energy of the system, and V is the potential energy of the system.
[0081] (2)
[0082] Where i=1,2,3,……,n, is the external force of the system on the i-th generalized coordinate. In the first-order inverted pendulum system, there are two generalized coordinates, x and .
[0083] Assume the following variables:
[0084] xpend——the horizontal coordinate of the pendulum center of mass.
[0085] ypend——the vertical coordinate of the pendulum center of mass.
[0086] (3)
[0087] The total kinetic energy of the system is obtained according to the following calculation.
[0088] (4)
[0089] in is the kinetic energy of the car, is the kinetic energy of the pendulum.
[0090] Therefore the kinetic energy of the cart is given as follows.
[0091] (5)
[0092] The kinetic energy of the pendulum can be further calculated as follows.
[0093] (6)
[0094] (7)
[0095] The total kinetic energy and total potential energy of the system are shown below.
[0096] (8)
[0097] (9)
[0098] Considering the friction factor, we have:
[0099] (10)
[0100] Solve the following equation of state.
[0101] (11)
[0102] Need to solve , so let:
[0103] (12)
[0104] Performing Taylor series expansion near the equilibrium position and linearizing it yields:
[0105] (13)
[0106] in:
[0107] (14a)
[0108] (14b)
[0109] (14c)
[0110] (14d)
[0111] (14e)
[0112] Solving the above formula we get:
[0113]
[0114] The resulting equation is:
[0115] (15)
[0116] Further arrangement can be obtained as follows:
[0117] (16)
[0118] (17)
[0119] Among them, the calculated The value is 31.96, The value of is 3.26.
[0120] Design the LQR controller:
[0121] The system state equation is:
[0122] (18)
[0123] Quadratic performance index function:
[0124] (19)
[0125] Among them: the weighted matrices Q and R are used to balance the weights of the state variables and input variables, Q is a semi-positive matrix, and R is a positive definite matrix. X is the n-dimensional state variable, U is the r-dimensional input variable, Y is the m-dimensional output vector, and A, B, C, and D are n*n, n*r, m*n, and m*r dimensional constant matrices respectively. If the system deviates from the zero state due to external interference, what kind of control U* should be applied to make the system return to near the zero state and at the same time satisfy J to reach the minimum, then U* at this time is called optimal control. According to the optimal control theory, the optimal control law that minimizes the above equation is:
[0126] (20)
[0127] Where P is the solution of the Riccati equation and K is the linear optimal feedback gain matrix. Solve the Riccati algebraic equation:
[0128] (twenty one)
[0129] The P value and the optimal feedback gain matrix K value can be obtained.
[0130] (twenty two)
[0131] The state equation of the first-order inverted pendulum system is as follows:
[0132] (twenty three)
[0133] (twenty four)
[0134] in, is the position of the trolley, is the car speed, is the swing rod angle, is the angular velocity of the pendulum. The LQR solution can be obtained using MATLAB. The specific procedure is shown below.
[0135] clear;
[0136] A = [0 1 0 0;0 0 0 0;0 0 0 1;0 0 31.96 0];
[0137] B = [0 1 0 3.26]';
[0138] C = [1 0 0 0;0 0 1 0];
[0139] D = [0 0]';
[0140] Q11=500;Q33=500;
[0141] Q=[Q11 0 0 0;0 0 0 0;0 0 Q33 0;0 0 0 0];
[0142] R=1;
[0143] K = lqr(A,B,Q,R)
[0144] Ac=[(AB*K)];Bc=[B];Cc=[C];Dc=[D];
[0145] T=0:0.005:5;
[0146] U=0.2*ones(size(T));
[0147] Obtain
[0148]
[0149] 14. Write the LQR control algorithm module in Simulink to obtain the car acceleration, and transmit the car acceleration to the experimental interaction system through the UDP sending module.
[0150] 15. According to steps 6, 7, and 8, the experimental interactive system converts the acceleration value of the car obtained from Simulink into the torque value of the actual control server through algorithm calculation, and sends it to the server through UDP to complete the inverted pendulum control.
[0151] 16. Use the Python user program to call the UDP communication package in Python, and also receive the state quantities uploaded from the experimental interaction system (car position, car speed, car actual acceleration, pendulum angle, pendulum angular velocity).
[0152] 17. Write an inverted pendulum control algorithm in Python and transmit the acceleration of the control car back to the experimental interaction system via UDP.
[0153] 18. According to steps 6, 7, and 8, the experimental interactive system converts the acceleration value of the car obtained from Python into the torque value of the actual control server through algorithm calculation, and sends it to the server via UDP to complete the inverted pendulum control.
[0154] 19. Use the Unity animation engine to model a 3D animation that is the same as a physical inverted pendulum object, and set up two degrees of freedom for animation movement. One is that the car can move horizontally to any position on the track, and the other is that the pendulum can rotate around the axis to any position in a circle.
[0155] 20. The inverted pendulum modeled in Unity can refresh the animation at a frame rate of 30 frames. Each frame reads the position of the car and the angle of the pendulum arm and displays the 3D animation.
[0156] 21. Using UDP communication, the real-time status data of the inverted pendulum (car position, car speed, car acceleration, pendulum angle, pendulum angular velocity) read by the experimental interactive system is transmitted to the Unity animation. Unity refreshes the received data and refreshes the animation, thereby realizing the digital twin of physical control and virtual 3D animation.
[0157] 22. Based on the nonlinear model of the inverted pendulum in step 13, create a dynamic environment consistent with the physical inverted pendulum through mathematical formulas in the experimental interactive system based on the mathematical model of the physical inverted pendulum.
[0158] 23. The created dynamic environment program retains the UDP communication interface with the host computer Matlab, Python and Unity animation. In the above process, the experimental control algorithm written in Matlab and Python can directly exchange with the dynamic environment through UDP communication, and feed back real-time status data to Unity animation to realize a visual virtual simulation experiment.
[0159] 24. The experimental interactive system uses the data that the user needs to modify as the modification menu content, and the front-end creates a UI interface for the user to modify.
[0160] 25. The experimental interactive system calls the plane curve drawing library to visualize the real-time state data of the inverted pendulum (trolley position, trolley speed, pendulum angle, pendulum angular velocity) in the form of a real-time curve on the UI interface.
[0161] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the above embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. An inverted pendulum control system based on network communication, characterized in that: include: A programming system, wherein the programming system is used to compile control instructions for controlling the inverted pendulum system and experimental control algorithms, and the programming system is one of Matlab, Simulink or Python; An experimental interaction system, wherein the experimental interaction system is equipped with a first interactive program and a second interactive program, wherein the first interactive program implements bidirectional data interaction between the experimental interaction system and a programming system based on the UDP communication protocol, and the second interactive program implements bidirectional data interaction between the experimental interaction system and an inverted pendulum system based on the UDP communication protocol; the experimental interaction system is equipped with a UI system, wherein different functional functions are executed by mode selection in the UI system, and an experimental control algorithm compiled by Matlab, Simulink or Python realizes the control of a physical inverted pendulum and a virtual inverted pendulum; An inverted pendulum system, the inverted pendulum system being configured to operate according to control instructions and output real-time state data of the inverted pendulum to the experimental interaction system; the inverted pendulum system comprising a physical inverted pendulum and a virtual inverted pendulum; The physical inverted pendulum includes a guide rod, a slider unit, a servo motor, a base, a transmission unit and a servo drive control box, the transmission unit includes a first fixed seat, a first pulley, a second fixed seat, a second pulley and a belt, the first fixed seat and the second fixed seat are in a "J" shape and are hollow inside; the slider unit includes a swing rod, a connecting rod, a trolley, and an angle encoder; the servo motor is fixed on the base, the output end of the servo motor is connected to the first pulley or the second pulley, the first pulley is arranged inside the first fixed seat, the second pulley is fixedly installed inside the second fixed seat, the first pulley and the second pulley are connected by a belt, the two ends of the guide rod are respectively fixed to the first fixed seat and the second fixed seat, the trolley is movably sleeved on the guide rod, the angle encoder is arranged on the trolley, one end of the connecting rod is connected to the angle encoder, and the other end of the connecting rod is fixedly connected to one end of the swing rod The angle encoder is connected to the servo drive control box, and the servo drive control box is connected to the servo motor; when the physical inverted pendulum is working, the programming system reads the real-time status data of the physical inverted pendulum sent from the experimental interaction system through UDP, and writes the experimental control algorithm of the inverted pendulum in Matlab, Simulink or Python. The real-time status data of the physical inverted pendulum include the position of the trolley, the speed of the trolley, the angle of the pendulum, the angular velocity of the pendulum, the actual acceleration of the trolley and the limit status. Among them, the acceleration of the trolley is the control quantity of the experimental control algorithm. The experimental interaction system reads the acceleration of the trolley calculated by Matlab or Python through the UDP communication protocol, and converts it into the motor torque control quantity through software calculation and communicates it to the servo drive control box in real time, so that the motor torque completes the control of the physical inverted pendulum; The virtual inverted pendulum is established by simulating a real inverted pendulum by the Unity3D animation module; when the virtual inverted pendulum is working, the programming system reads the real-time status data of the virtual inverted pendulum sent from the experimental interaction system through UDP, and writes the experimental control algorithm of the inverted pendulum in Matlab, Simulink or Python. The real-time status data of the virtual inverted pendulum system includes the position of the trolley, the trolley speed, the pendulum angle, the pendulum angular velocity, the actual acceleration of the trolley and the limit status, among which the trolley acceleration is the control quantity of the experimental control algorithm. The experimental interaction system reads the trolley acceleration calculated by Matlab or Python through the UDP communication protocol to complete the virtual inverted pendulum control.
2. The inverted pendulum control system based on network communication according to claim 1, characterized in that: The control algorithm used in the experiment is one of a nonlinear control algorithm, a variable structure control algorithm, a predictive control algorithm, a robust control algorithm and a fuzzy control algorithm.
3. A physical inverted pendulum experiment method based on network communication, implemented based on the system of claim 1, characterized in that: The following steps are involved: S101, compiling control instructions for controlling the movement of the inverted pendulum system and an experimental control algorithm through a programming system, wherein the programming system is one of Matlab, Simulink, or Python; S102, the experimental interactive system receives the control instruction through the first interactive program, converts the control instruction into a motor torque control instruction for the vehicle, and sends the motor torque control instruction to the physical inverted pendulum system through the second interactive program; S103, the physical inverted pendulum system drives the trolley to move according to the motor torque control command, and simultaneously collects real-time state data of the inverted pendulum through the sensor, and sends the real-time state data of the inverted pendulum to the experimental interactive system through the second interactive program; S104. The experimental interactive system inputs the real-time state data of the inverted pendulum into the experimental control algorithm compiled by the programming system through the first interactive program, and outputs further control instructions based on the experimental control algorithm, and returns to S101.
4. A physical inverted pendulum experimental method based on network communication according to claim 3, characterized in that: The method further comprises the following steps: S105. Generate a follow-up display interface of the virtual inverted pendulum through the Unity3D animation module to realize the digital twin of the real inverted pendulum.
5. A virtual inverted pendulum experimental method based on network communication, implemented based on the system of claim 1, characterized in that: The following steps are involved: S201, compiling control instructions for controlling the inverted pendulum system and an experimental control algorithm through a programming system, wherein the programming system is one of Matlab, Simulink, or Python; S202, the experimental interactive system receives the control instruction through the first interactive program, converts the control instruction into a motor torque control instruction for the virtual car, and sends the motor torque control instruction to the virtual inverted pendulum system through the second interactive program; S203, the virtual inverted pendulum system drives the virtual car to move according to the motor torque control instruction, and at the same time collects real-time state data of the virtual inverted pendulum through the virtual sensor, and sends the real-time state data of the virtual inverted pendulum to the experimental interaction system through the second interactive program; S204 . The experimental interactive system inputs the real-time state data of the virtual inverted pendulum into the experimental control algorithm compiled by the programming system through the first interactive program, and outputs further control instructions based on the experimental control algorithm, and returns to S201 .
Citation Information
Patent Citations
Semi-virtual inverted pendulum system utilizing single chip microcomputer and network 3D technology
CN108648596A
Inverted pendulum experiment platform based on industrial robot
CN221687117U