Related links to manuals
- Osnove Simulinka
- Modeling in Simulink
- Circuit Sim activity
Related external links
Contents
- physical environment
- Create a world structure and basic configuration
- Assemble the base plane and carriage
- The pendulum subsystem and the connection of the trolley to the pendulum
- Selection of output for controller and angle conversion
- Create a riser and cart subsystem
- Closed circuit installation
- Controller implementation
physical environment
In this section, we will show you how to build an inverted pendulum model using Simscape Multibody's physical modeling blocks. The blocks in the Simscape library represent real physical components; therefore, complex many-body dynamical models can be built without having to build mathematical equations based on physical principles, as is done by applying Newton's laws to generate the model implemented inInverted pendulum: modeling in Simulink.
The system parameters are defined as follows:
(M) vehicle weight 0.5 kg
(m) time 0.2 kg
(b) coefficient of friction for the trolley 0.1 N/m/sec
(l) length to the center of gravity of the pendulum 0.3 m
(I) moment of inertia of a pendulum of mass 0.006 kg.m^2
Create a world structure and basic configuration
Open a new Simscape Multibody model by typingnewin the MATLAB command window. A new model will open as shown below, with some frequently used blocks already in the model. PS-Simulink and Simulink-PS blocks define the boundary between Simulink I/O models where blocks are evaluated sequentially and Simscape models where equations are evaluated simultaneously.
To configure basic settings in the model, do the following:
- Dvaput click block Setup mechanism and placeSeriousnessto "[0 0 -9.81]", which represents the gravitational acceleration from
acting along the global -Z direction
- Open the Solver Configuration block and check itUse a local solverthe checkbox is unchecked.
- TipCTRL-Eopenconfiguration parametersdialog
- LapSolverpanel, make sureTipis set to "Variable-Step" and that's itSolverset to "auto", also setstop timedoe "10"
Assemble the base plane and carriage
We will model the cart as a point mass moving along an axis. We use the World Frame to define the axis along which the carriage will move.
- Connect the B port of the Rigid Transform to the W port of the World Frame
- Double-click the Rigid Transform block
- In a groupRotation, setmethodto "Standard axis",Osdo „+Y” iKuttwo "90s"
- Rename the rigid transformation block to "Transform Vehicle Axis"
Tips for adding blocks:
- Use quick insert to add blocks. Click on the diagram and enter the name of the block (use the letters uboldbelow). A list of blocks will appear and you can select the desired block from the list.
- When you enter a block, you are prompted to enter a parameter. Enter the variable names as shown below.
- To rotate a block or flip blocks, right-click on a block and select zTwist and turnMenu.
- To display the parameter under the block name, seeSet annotation block propertiesin the Simulink documentation.
Add the following blocks:
*Laptasty reference
*schoolpe
*Pulsee Generator
For Pulse Generator to double click on a block and placePeriodi.e. "10",Amplitudei.e. "1000",pulse widthdoor "0.01", i.ephase delayi.e. "1".
A prism joint allows only one translational degree of freedom. The prism joint will move under force.
- Double-click the prismatic joint to open the dialog box
- In a groupInternal mechanics, setDamping factorat "0.1 N/(m/s)"
- Among the groupactivation, PlaceThento "Import Insured"
- In a groupFeeling, To choosePositionISpeed
- Rename the prismatic joint to "Prismatic Wheel"
The prism connection should then be connected to the rest of the model.
- Connect the B terminal of the prismatic car to the F terminal of the conversion axle block
- Connect the F port of the prismatic carriage to the R port of the full block
- Rename the pulse generator block to "Interference" and connect the "Interference" output to the Simulink-PS converter block already in the diagram
- Connect the output of the Simulink-PS conversion block to the power input of the prismatic carriage
- Double click on this signal and name it "Strength"
- Then click on the Simulink-PS Converter block and setInput signal unitafter "N" for newtne
- Make a copy of the PS-Simulink block
- Double-click the PS-Simulink block and place itOutput signal unitto 'm' and connect this block to the p port of the prism cart block
- Click on the drug PS-Simulink block, placeOutput signal unitto "m/s" and connect it to the v port of the prism carriage block
- Connect both PS-Simulink blocks to the oscilloscope
- Name the p-port signal "x Cart"
- Name the v-port signal "v Cart"
Since we model the slide car as a point mass, only the mass affects the simulation results.
- Double-click the solid
- Set the parametersDimensionsto "[0.2,0.04,0.6]" so that the longest dimension points in the direction of motion.
- In a groupLaziness, setTipna „Puntmassa” iTimei.e. "0.5 kg"
- In a groupGraphic, pod, podVisual propertiessetColorwhich is "[0.8 0.45 0]"
- Rename the block to "Shopping Cart"
The model should now look like this.
Run a simulation (typCTRL-Tor press the green arrow run button), the resulting graph shows both the distance traveled by the cart and its speed.
The pendulum subsystem and the connection of the trolley to the pendulum
Add the following blocks to the model:
- Rigid transformation block
- Full Stone Block (Full Block before R2019b)
- A revolutionary combination
To define the axis of rotation of the pendulum:
- Connect the B port of the new rigid transformation block to the F port of the prismatic carriage
- Connect port F of the new Rigid Transform block to port B of the new Revolute Joint block
- Double-click the new Rigid Transform block
- In a groupRotation, setmethodto "Standard axis",Osdoor "+X" iKuttwo "90s"
- Rename the "Convert Pendulum Axis" block to Revolution
To define the degree of freedom of rotation of a pendulum:
- Rename Revolute Joint to "Revolute Pendulum"
- Connect the pendulum's F port to the Brick Solid's R port (pre-R2019b solid block)
To model the pendulum:
- Double-click the Brick Solid block
- In a groupGeometry, setDimensionsw „[0,6 0,03 0,05] m”
- In a groupLaziness, setTipna „Puntmassa” iTimei.e. "0.2 kg"
- In a groupGraphic, pod, podVisual propertiessetColorwhich is "[0.25 0.4 0.7]"
- PressAgreeand rename the block to "Pendulum"
To model the wheelchair attachment point:
- Double-click the pendulum block
- In a groupFrames, click the + sign next to itNew framework, opens the interface for defining frames
- Click on the smaller side of the brick facing you (in the positive x direction) to select it
- at sectionOrigin of the frame, select the radio buttonBased on a geometric element
- ClickReddenbutton at the bottom of the dialog box
- Rename "Frame1" to "B"
- Uncheck the box forShow port R
- ClickAgree
- Connect the B port of the pendulum to the F port of "pendulum transform"
The resulting model should look like this:
Run a simulation (typCTRL-Tor press the green arrow run button), the following diagram is generated showing that adding a pendulum changes the behavior of the cart, both in terms of distance traveled and speed.
Selection of output for controller and angle conversion
Now we need to measure the angle and angular velocity of the pendulum:
- Double click "Revolute Pendulum"
- In a groupPrimary rotating element Z (Rz)pod belowFeeling, select the checkboxes forPositionISpeed
- Make two copies of the PS-Simulink conversion block
- Double-click the PS-Simulink block and place itOutput signal unitswork"
- Connect this PS-Simulink block to the q port of the pendulum
- Double click another PS-Simulink block and place itOutput signal unitsfor work"
- Connect this PS-Simulink block to the port on the Revolute Pendulum
We need to constrain the measured angle to be between -pi and pi radians.
- Add an instance block to your model
- Rename the subsystem block to "Wrap Angle"
- Double-click to open the wrap angle subsystem
In this subsystem, we add pi radians to the result, find the remainder of dividing the signal by 2*pi, and then subtract pi radians.
- Rename the input block to "q"
- Remove the signal connection between input and output
- Add a deviation block to the model
- Set the parametersPrejudiceby "bees"
- Sposit-block q is a deviation block
- Add a math function block to the model
- Then click on the math function block and place itFunctionin a row"
- Connect the deviation output to the first input of the math function block
- Add a solid block to the model
- Set the parametersincessantby "2*pi"
- Connect the Constant block to the second input of the math function
- Make a copy of the Bias block
- Set the parametersPrejudicein a new block on "-pi"
- Connect the output of the math function to the input of the new deviation block
- Connect the output of the new Bias block to the output
- Rename output "qwrap"
- Go up one level in the diagram and rename the subsystem to "Wrap Angle"
Here you can see the resulting corner wrap subsystem
We'll deploy new signals to Scope
- Connect the PS-Simulink output for q pendulum measurement to the Wrap Angle input
- Add a new range
- Connect the output of the qwrap Wrap Angle to a new oscilloscope and rename this signal to "q pendulum"
- Connect the PS-Simulink w pendulum output to the new oscilloscope and rename this signal to "w pendulum"
The resulting model should look like this:
Run a simulation (typCTRL-Tor press the green arrow start button), the following diagram is generated. The movement of the carriage is the same as before, but now we can see the movement of the pendulum. The corresponding animation below is also generated.
Create a riser and cart subsystem
We have now managed to create all the elements of the inverted pendulum system. We turn it into a subsystem.
- Click once on the chart (but not on the block) and pressCTRL-Ato select all blocks
- StickChangeand click on the interfering block and each crosshair to deselect those blocks
- PressCTRL-Gto create a subsystem
- Rename subsystem "Inverted pendulum on cart"
Your model should now look like this:
Closed circuit installation
Now we will add open and closed loop test blocks.
Add the following blocks:
- Start
- regulator PID
- incessant
- Manual switch
- Quantity
Noise is also added to the control signal.
- Remove the signal linking the Interference with the car's subsystem
- Connect the output of the sum block to the force input of the trolley subsystem
- Connect the Disruption to the lower port + Sum block
We want to manually select open or closed loop behavior.
- Connect the hand switch output to the + input of the sum block
- Connect the Constant block to the lower input of the hand switch, then set the parameterincessantto "0" and rename the block to "No Strength"
- Connect the output of the PID controller to the upper input of the hand switch
- Connect the output of the subtract block to the input of the PID controller
We'll close the loop to control the angle of the pendulum.
- Connect the q output of the carriage subsystem pendulum to the - port of the subtraction block
- Make a copy of the Constant block and connect it to the +connector of the Subtract block and rename the block to "Desired Pendulum Angle"
Your model should now look like this. The simulation output remains unchanged from previous open-loop results.
Controller implementation
We will now implement the PID control gains developed inInverted pendulum: design of the PID controllerside.
- Double-click on the PID controller block
- Set the parametersProportional (P)doe "100"
- Set the parametersintegral(s)this is "1"
- Set the parametersderivative (D)doe "20"
Double-click the manual switch until the PID controller input is selected.
Running the simulation yields the following two graphs showing the controlled response of the system. After the first impact, the controller was able to quickly reduce the angle of the pendulum to zero, and the speed of the pendulum is also zero. The cart moves slowly and at a constant speed in the negative X direction to balance the pendulum.
You can download the final Simscape model created here by right-clickingHerethen selectSave link as....
Released with MATLAB® 9.7