# Control instructions in MATLAB and Simulink (2023)

• Circuit Sim activity

## Contents

• physical environment
• Create a world structure and basic configuration
• Assemble the equipment
• Pass the ball
• Controller implementation

## physical environment

In this section, we also show how to use physical system modeling to build a non-linear ball and beam model, which is implemented by a mathematical model in. We will also implement the developed control algorithmside to check the movement of the ball.

The physical configuration of the system is shown in the diagram below. As the servo gear rotates through the hornthe handle changes the lighting angle by. When the angle changes from horizontal, gravity causes the ball to roll along the stick.

In this problem, we make sure that the ball rolls without slipping and that the friction between the beam and the ball is negligible.

The constants and variables for this example are defined as follows:

`(m) mass of glucose 0.11 kg`
`(R) projectile radius 0.015 m`
`(d) displacement of the lever arm 0.03 m`
`(g) gravitational acceleration 9.8 m/s^2`
`(L) ballet length 1.0m`
`(J) moment of inertia of the ball 9.99e-6 kg.m^2`
`(r) ball location coordinate`
`(alpha) beam angle coordinate`
`(theta) servo acceleration angle`

The design criteria for this problem are:

• Setup time less than 3 seconds
• Exceed less than 5%

## Create a world structure and basic configuration

Open a new Simscape Multibody model by typingnewin the MATLAB command window. A new model as shown below will open 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. In addition, you must define the appropriate model parameters in the MATLAB workspace. This can be achieved by running the fileproperties_of_ball_beams.mwhich can be downloaded by right-clicking and selectingSave link as....

To configure basic settings in the model, do the following:

• Dvaput click block Setup mechanism and placeSeriousnessto "[0 -9.81 0]", it means gravitational acceleration fromacting along the global -Y direction
• Open the Solver Configuration block and check itUse a local solverthe checkbox is unchecked
• TipCTRL-Eto open the Configuration Parameters dialog box
• Check it in the solver panelTipis set to "Variable-Step" and that's itSolveris set to "ode23t"
• Expand the sectionSolution detailsby clicking the triangle
• setAbsolute tolerancedo „1-4”

## Assemble the equipment

The gear needs a pin in the center and a second pin at a radial distance d from the center to which the lever is attached.

• Connect the B port of the Rigid Transform to the W port of the World Frame.
• Double-click the Rigid Transform block
• In the group, set Rotationmethodto "Standard axis",Osdoor "+Z" iKuttwo "90s"
• Rename the rigid transformation block to "Transform Gear Axis"

1. 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.
2. When you enter a block, you are prompted to enter a parameter.
3. To rotate a block or flip blocks, right click on the block and select the z option you wantTwist and turnMenu.
4. To display the parameter under the block name, seeSet annotation block propertiesin the Simulink documentation.

*dsoute Joint, rename it "Revolute Gear"
*tranbollenFcn
*earn
*StepImport

Determine the acceleration degree of freedom.

• Connect port B of the sprocket to port F of the transformation gear shaft
• Double click "Revolute Gear"
• In a groupPrimary rotating element Z (Rz)insideState goals, select the check box forSpecify the target position
• setPriorityna "Visoko" iValuetwo "0 you"
• In a groupactivation, setKoppelto "Autocalculated"
• In a groupactivation, setMovementto "Import Insured"
• In a groupFeeling, select the check box forPosition

Create a subsystem to define gears and pins:

• Make a copy of the Transform Gear Axis, rename the new block to "Transform Lever"
• Connect port B of the transformation lever to port F of the spin gear
• Double-click the transform handle
• In a groupRotation, setmethodto nothing"
• In a groupTranslation, setOsdo „-Y”,Changeto "d" in "m" meter units, then clickAgree
• Press the transform handle to select it
• TipCTRL-Gcreate a subsystem and name the subsystem "Gear"

Now we will add the pins:

• Double-click the instance to open it
• Rename port 1 to "P" and port 2 to "L"
• Cylindrical insertReliableblock (hard block before R2019b)
• Rename the block to "Pin Gear"
• Then click on "Pin Gear"
• Stele in editions vóór R2019b wFormto the "cylinder"
• In a groupGeometry, setRadiusdoor "0.01m" iLengthto "0.02 m", then clickAgree
• Connect the R port of the Pin Gear to the B port of the transformation lever
• Copy and paste the Pin Gear and name the new block "Pin Lever"
• Double click "Pin Lever"
• In a groupGeometry, setLengthto "0.04 m" and clickAgree
• Connect the R port on the pin handle to the F port on the transform handle

Now let's define the hardware:

• Copy and paste Pin Gear and name the new block "Gear"
• Double-click "Hardware"
• In a groupGeometry, setRadiusdoe "d+0.025 m" iLengthdoe "0.003 m"
• In a groupGraphicpod belowVisual properties, setColori.e. "[0 0.6 0.8]"
• ClickAgree
• Connect the Gear's R port to the Transform Handle's B port

Here is the Gear subsystem:

We will shift the gear by introducing movements. The traffic input must be filtered to avoid an algebraic loop. We also need to ensure the continuity of the motion control signal and its first two derivatives, which is why we will use a critically damped filter in the Simulink-PS converter block.

• Connect the Simulink-PS converter to the Revolute Gear's q input
• Double click Simulink-PS converter and configureInput signal unitwork"
• LapInput handlingbookmark, setFiltering and derivativesto "Input filtering, calculated derivatives"
• LapInput handlingbookmark, setOrder of input filtersto "Second Order Filtering"
• LapInput handlingbookmark, setInput filtering time constantat "0.01 seconds"
• Connect the Transfer Fcn output to the Simulink-PS converter
• Double click Transfer Fcn and setDenominator coefficientsthat is "[0.01 1]"
• Connect the Step to the Transfer Fcn input and call this signal "Gear Angle"
• Double click has step block and settingFinal valuei.e. "0.3"

We will measure the angle of the gear and use this angle to estimate the angle of the radius at which the ball is located.

• Connect the PS-Simulink converter to the Revolute Gear q output
• Drop the gain block onto the flat part of the signal that connects the PS-Simulink converter to the oscilloscope
• Dvaput click on block Get 1st placeearndoor "d/l"
• Double click on the input signal for Range and name it "Approximate" as this is an estimated value for the beam angle

The general model looks like this:

Start simulation (CTRL-Tor press the green arrow start button) gives the following diagram.

For the given dimensions of the pinion and the beam, the connection between the pinion and the beam must be 0.35 m long. In this section, we will add a coupling to the model. Add the following to the model:

• Add Revolute Joint, rename it to "Revolute Gear Lever"
• Connect the transmission rocker port B to the transmission subsystem L port
• Add a rigid transform block, rename it "Transform Center"
• Connect the B port of the transformation center to the F port of the shifter axle
• Click once on the Transformation Center to select it
• PressCTRL-Gcreate a subsystem and name it "Liver"

We will define a lever with one solid and two connection points. First, we define connection points.

• Double-click to open the leverage subsystem
• Rename port 1 "B" and port 2 "F"
• Double-click Transformation Center
• In a groupTranslation, setOsafter "+X" and placeChangei.e. "0.35/2"
• Copy and paste the Transform Center and name the new block "Transform Beam"
• Place the transformation bar on the line between the center of the transformation and the F joint

Now we define leverage

• Place Solid Stone (Solid Block on pre-R2019b versions)
• Double-click the Brick Solid block
• In a groupGeometry, setDimensionsw „[0,35 0,03 0,01] m”
• In a groupLaziness, setThicknessdoe "7200 kg/m^3"
• In a groupGraphicpod belowVisual properties, setColorthat "[1 0 0]"

The lever subsystem should look like this:

The entire model should look like this:

The simulation of the model shows the results when rotating the handle:

Now we will define the connection between the beam and the lever.

• Copy and paste Revolute Gear Lever, rename the new block to "Revolute Lever Beam"
• Add a rigid transform, rename the new block to "Lever transform"
• Connect port B of the transformation arm to port F of the rocker beam
• Click the transform handle once to select it
• PressCTRL-Gcreate a subsystem and name it "Beam"

Within this subsystem, we will define a member. First, we define the beam end connection points.

• Double-click on the "Beam" subsystem.
• Rename the port connected to the transform handle to 'L', it should be the port connected to port B of the transform handle
• Rename the second port to "P"
• Double-click the transform handle
• In a groupTranslation, setmethodto "standard axis"
• In a groupTranslation, setOsdoor "+Ý" iChange"L/2" door
• Copy and paste Transform Left, name the new block "Transform Beam Center"

Then we define the beam.

• Add a Brick Solid block to this subsystem (pre-R2019b solid block), name this new block "Beam"
• Double-click Beam
• Stele in editions vóór R2019b wFormbrick"
• In a groupGeometry, setDimensionsw „[0,025 L+0,04 0,03] m”
• In a groupLaziness, setThicknessdoe "7200 kg/m^3"
• In a groupGraphicpod belowVisual properties, setColorthat "[1 0 0]"

We will define pins that visually represent the connection between the beam and the lever and a fixed point in space.

• Add a cylindrical solid block (pre-R2019b solid block) to the Beam subsystem. Name the new block "Pin Beam Pivot".
• Double-click the pivot point of the beam pin
• Stele in editions vóór R2019b wFormon "cylindrical"
• In a groupGeometry, setRadiusmake "0.01m"
• In a groupGeometry, setLengthto "0.04 m" and clickAgree
• Connect the pivot R port of the beam to the center port B of the transform beam
• Copy and paste pin beam pin, name the new block "Pin Lever Beam"
• Connect the R port of the wedge holder to the B port of the transformation holder

Now we define the frame of reference for the ball.

• In the Beam subsystem, add a rigid Transform block and name the new block "Transform Beam End Ball"
• In a groupRotation, setmethodto "Aligned axes"
• In a groupRotation, pod, podPart 1, setfollowerafter "+Z" and placeBasicallyby "+J"
• In a groupRotation, pod, podPart 2, setfollowerafter "+Y" and placeBasicallydoor "+X"
• In a groupTranslation, setmethodto "standard axis"
• In a groupTranslation, setOsdoor "+X" iChangepl „0,025/2m”
• Connect the transformer rod ball terminal B to the transformer arm terminal B
• Copy and paste port P and name the new port B.
• Connect port B to port F of the ball end of the transformer rod

The Beam subsystem must have:

Now it is necessary to define a connection between the beam and a fixed point in space.

• Add a rigid transformation block, name the new block "Transform Beam Axis"
• Connect port B of the transformation beam pivot to the world frame
• Copy and paste Revolute Gear and name the new block "Revolute Beam"
• Double-click the pivot beam
• In a groupFeeling, uncheck the boxPosition
• Connect the B port of the pivot beam to the F port of the transformation pivot beam
• Connect the F port of the swing beam to the P port of the boom subsystem
• Copy and paste the PS-Simulink block connected to the Revolute Gear
• Connect the Revolute Beam's q-port to the new PS-Simulink block
• Connect the output of the PS-Simulink block to Scope and name the new signal "Measured"

The whole model should then look like this:

The model simulation then creates the following view as the handle rotates.

## Pass the ball

Now we will add a ball to our model. The ball must be held to keep it moving along the fingerboard, and a separate bracket is used to keep the ball rolling without sliding down the fingerboard. Various blocks are used to define axes and constraints.

• Add pinion and pinion stop block
• Connect port F to port B of the Beam subsystem
• Click once on the acceleration and acceleration limit block to select it
• PressCTRL-Gto create a subsystem
• Rename the subsystem to "Ball Beam Constraints"

Within this subsystem, we will define the boundaries for the ball. First, we define the anti-slip tilt limit.

• Double-click the Ball Beam Constraints subsystem to open it
• Rename the port connected to port F of the gear and pinion stopper to "Beam"
• Rename the second connector to "sphere"
• Double-click Rack and pinion mate and set the parameterAcceleration radius„R”

Then we add a constraint that the ball moves along the beam.

• Add a prism connection to the model
• Double-click the prismatic joint
• In a groupPrismatic Z (Pz) prism, pod, podState goals, select the check box forSpecify the target position
• setPrioritywhen set to "High".Valueit is "0"
• In a groupInternal mechanics, setDamping factorw „0,001 N/(m/s)”
• In a groupFeeling, select the check box forPosition

Connect the prism joint to the reference frame and feel the position of the ball.

• Connect port B to port F of rack and pinion stopper
• Connect the PS-Simulink conversion block to the p-port of the prismatic link
• Double click on the PS-Simulink converter block and place itOutput signal unitwith me"
• Add an output signal port and name this new port "x"
• Connect the PS-Simulink converter block to the output

We need to add some degree of freedom to rotate the ball as it rolls. First we need to define the axis of rotation.

• Add a rigid transform block and name this block "Transform Pinion"
• Dvaput persblok Transform Pinion
• In a groupRotation, setmethodto "standard axis"
• In a groupRotation, setOsdo „+Y” iKutin "90 degrees"
• In a groupTranslation, setmethodto "standard axis"
• In a groupRotation, setOsby "+J",Changedoe "R metara"
• Connect port B of the transformer to port F of the prismatic connector

Now we can add degrees of freedom.

• Connect the swivel port F to the limit port B of the rack and pinion
• Connect port B of the swivel joint to port F of the transformer gearbox

The Ball Beam Constraints subsystem should look like this:

Finally, we can pass the ball.

• Go to the top level of the model
• Add spherical solid block (full block before R2019b)
• Name this block "Ball"
• Double-click on the "Ball" block.
• Stele in editions vóór R2019b wFormin "atmosphere"
• In a groupGeometrysetRadiusdoe "R metara"
• In a groupLazinesssetTipto "custom"
• In a groupLazinesssetMoments of slowdowna "[JJJ] kg*m^2"

• Connect the ball port R to the ball port of the ball beam restraint subsystem
• Add a scope block and connect the x port of the spherical beam constraint to the new scope, name this signal "x ball"

The resulting complete model should look something like this:

If you simulate this system, you should see the following range response. As well as the animation below.

## Controller implementation

We successfully modeled the physical system. We make it a subsystem and add a controller.

• Click once on the chart (but not on the block) and pressCTRL-Ato select all blocks
• StickChangeand click the Step and Range blocks to deselect those blocks
• PressCTRL-Gto create a subsystem
• Rename the subsystem to "Ball on Beam"

Now we close the loop with the controller.

• Remove the connection between the Step block and the Ball on Beam subsystem
• Add a gain block and set the parameterearnby "pi/180"
• Connect the gain output to the input of the Ball on Beam subsystem
• Add a Transfer Fcn block and name the block "Lead Compensator"
• Set the parametersMeter coefficientsthat is "[1 0.01]"
• Set the parametersDenominator coefficientsthat "[1 5]"
• Connect the output of the drain compensator to the amplification block
• Copy and paste the Boost block and editearnnew block at "37.1"
• Connect the output of the subtract block to the trigger compensator
• Connect the Step block to the + port of the Subtract block and rename the Step block to "Target Ball Position"
• Connect the Ball on Beam "x Ball" output to the subtraction block port
• Align the position of the target ball with the crosshair

Since this is now a rigid system, we need to change the solver settings.

• TipCTRL-Eopenconfiguration parametersdialog.
• LapSolverwindow, setSolverna "ode23t"
• Changestop timedoe "1000"

The resulting closed loop system should look like this:

Running the simulation then gives the following output as observed on the oscilloscope.

Released with MATLAB® 9.7

## References

Top Articles
Latest Posts
Article information

Author: Kerri Lueilwitz

Last Updated: 09/30/2023

Views: 5999

Rating: 4.7 / 5 (67 voted)

Author information

Name: Kerri Lueilwitz

Birthday: 1992-10-31