tag:www.mathworks.com,2005:/matlabcentral/fileexchange/feedMATLAB Central File Exchangeicon.pnglogo.pngMATLAB Central - File Exchange - type:model category:"3-D Visualization"User-contributed code library2015-01-31T00:35:14-05:00101100tag:www.mathworks.com,2005:FileInfo/214392008-09-15T14:28:53Z2014-08-22T14:23:24ZSimulation of a one-legged hopping robotSimulation of a one-legged hopping robot<p>This model simulates a robot jumping on one leg. </p>
<p>I saw this robot at the MIT Museum last winter and after discussing with few colleagues at The MathWorks™ we decided that it would be cool to have a Simulink® model of this robot.</p>
<p>This submission contains 2 models. They both use Simulink® and SimMechanics™ and the second model uses Simulink® 3D Animation™. This second version of the model allows you to click in the virtual reality scene to bring the robot where you want. This functionality is inspired by the inverted pendulum demo provided with the Simulink 3D animation.</p>
<p>Have fun, and let me know if you have any idea to make it better, or if you decide to add more legs ;-)</p>Guy Rouleauhttp://www.mathworks.com/matlabcentral/profile/authors/1248313-guy-rouleauMATLAB 7.8 (R2009a)SimMechanicsSimulinkMore interesting with Simulink 3D Animation.falsetag:www.mathworks.com,2005:FileInfo/328352011-09-08T18:10:44Z2011-09-14T18:54:11ZRobot Soccer 2.0: Modeling Team Strategies with Stateflow and Network Effects with SimEventsAdditional discrete modeling enhancements to the demo<p>This demo is an extension of the following demo:</p>
<p><a href="http://www.mathworks.com/matlabcentral/fileexchange/28196-robot-soccer-an-exercise-in-learning-the-key-features-of-simulink">http://www.mathworks.com/matlabcentral/fileexchange/28196-robot-soccer-an-exercise-in-learning-the-key-features-of-simulink</a></p>
<p>The key Simulink concepts on how to build this demo discussed in the "Introduction to Simulink" webinar:</p>
<p><a href="http://www.mathworks.com/company/events/webinars/wbnr37271.html">http://www.mathworks.com/company/events/webinars/wbnr37271.html</a></p>
<p>Please note that the webinar does not cover the Stateflow and SimEvents portions.</p>
<p>Key points to consider in this demo:</p>
<p>1. Team 1 has a strategy that is implemented as different modes in a state chart where the collective behavior of the two robots switches between aggressive and passive plays. The criteria that determines the switching is based on opponent positions and residual energy. Team 2 uses a rather simple strategy with one robot always attacking and the other simply defending by blocking shots. </p>
<p>2. For each team, both robots upload their energy values on a shared channel and download actuator command signals on another shared channel from a centralized station.</p>
<p>3. Observe that the outcomes and game play are different each time you run the simulation. How can you explain this paradox given that all the initial positions and strategy of the robots are the same? What is causing the non-deterministic system level behavior in the system?</p>
<p>4. Under the non-deterministic circumstances outlined above, is it possible to design (assuming existence) an algorithm that guarantees a 90% confidence that team 1 will always win? If such an algorithm does not exist, can you prove why?</p>
<p>Please make sure you use R2011b as SimEvents underwent a major update that requires new blocks (gateway block) for this demo to work.</p>Simulink Dudehttp://www.mathworks.com/matlabcentral/profile/authors/1297391-simulink-dudeMATLAB 7.12 (R2011a)SimEventsSimulinkStateflowSimulink 3D Animationfalsetag:www.mathworks.com,2005:FileInfo/324032011-08-01T16:17:56Z2011-09-08T13:30:44ZModeling, Simulation and 3D Animation of a Simple Assembly LineA simple template that combines SimEvents, Stateflow, Simulink and Simulink 3D Animation.<p>The goal of this demo is to establish a general template for simulating and animating simple assembly lines. In this example, we have two conveyor belts that have motions perpendicular to each other. Furthermore, a package needs to be mounted onto the conveyors and transferred across them as well by three gantries.</p>
<p>Key points to keep in mind:
<br />1. The SimEvents model is used to model the environmental input to the conveyor belt system. A gated release of the packages is obtained through control from the assemly line that signals if the conveyor_x is indeed free. Furthermore, each entity is assigned a unique identification number (UID) to keep track of its flow through the statechart. </p>
<p>2. The Stateflow chart is used as a diagram to sequence the states. All concurrent motions of the various elements in the system are modeled as parallel states.</p>
<p>3. The transfers are also modeled as parallel states with timed delays to create a simple loading motion. Observe how the uid values are reset only after the sequence is done to keep the various states of the system in synchronous.</p>
<p>4. The Integration subsystem is a placeholder for modeling additional dynamics that can be incorporated by the modeler.</p>
<p>5. The Animation Logic MATLAB function has been designed to simply the animation. At any point in time, there are only two blocks possible on the assembly line. By switching on/off the transparencies of the blocks, a uniform motion of the blocks can be obtained. This is much simpler than having to create a new block dynamically using the PROTO function.</p>
<p>Questions to ponder about:
<br />1. The maximum queue capacity is 25. At what value of the velocities(forward & backward) for both the conveyors will the queue length never exceed 10?
<br />2. How does the result in (1) change if you use a uniform distribution for the time-based entity generation? </p>Simulink Dudehttp://www.mathworks.com/matlabcentral/profile/authors/1297391-simulink-dudeMATLAB 7.12 (R2011a)SimEventsSimulinkStateflowSimulink 3D Animationfalsetag:www.mathworks.com,2005:FileInfo/312492011-04-29T15:44:26Z2011-05-06T09:09:33ZSimEvents Entity Animation in 3DBasic infrastructure S-Function for hooking up a SimEvents model to Simulink 3D Animation<p>The demo uses one possible implementation of hooking up a SimEvents model with 3D animation using Simulink 3D Animation.</p>
<p>A simple model of an entity generation is created in SimEvents. This entity generation is sampled in time to establish synchronism between the 3D objects created dynamically inside the Simulink 3D Animation environment and the SimEvents model.</p>
<p>The attribute functions are used to randomly select the color of the balls thereby modeling two dimensional randomized events in the system (entity generation and their color in time)</p>
<p>The 3D spheres that are created on the "fly" uses the PROTO definitions of similar objects contained in the "vrmarkers.wrl" file that ships with Simulink 3D Animation.
<br />These objects can be replaced with more complex objects such as luggage, machine parts etc. Also, the velocity of the balls is the same for all to maintain homogeneity. This is a parameter that can be modified in the S-Function. </p>
<p></p>Simulink Dudehttp://www.mathworks.com/matlabcentral/profile/authors/1297391-simulink-dudeMATLAB 7.11 (R2010b)SimEventsSimulinkSimulink 3D Animationfalsetag:www.mathworks.com,2005:FileInfo/311422011-04-21T18:45:05Z2011-04-21T18:45:05ZInternational Flight Route Planning Simulator using Aerospace BlocksetExample that shows how you can visualize airline routes on the globe.<p>In this demo, with an ordered list of cities with latitudes and longitudes as input, the simulator computes the shortest path between the two consecutive cities and then animates the aircraft motion on 3D earth while tracing the trajectory. Observe that this is an example where the analysis of the data is done in MATLAB and the data is "played back" in Simulink.</p>
<p>Also, attached to the plane is a North-East-Down (NED) frame, that gives a better understanding of aircraft coordinate systems.</p>
<p>Key design considerations:</p>
<p>1. The image of the earth that was used to texture the spherical earth was from NASA's 2002 Blue Marble images:</p>
<p><a href="http://visibleearth.nasa.gov/view_rec.php?id=2433">http://visibleearth.nasa.gov/view_rec.php?id=2433</a></p>
<p>Please note that calibrating the latitudes and longitudes on this spehrical earth requires that you use a mercator projection with aspect ratio 2:1. </p>
<p>2. The great circles joining any two cities were computed using the Mapping Toolbox's track2 function:</p>
<p><a href="http://www.mathworks.com/help/toolbox/map/ref/track2.html">http://www.mathworks.com/help/toolbox/map/ref/track2.html</a></p>
<p>The number of sampling points chosen were scaled accordingly to allow for uniformity in airplane motion. </p>
<p>3. The set of latitudes and longitudes were input to a LLA to ECEF block to compute the translational coordinates of the aircraft with the NED frame attached:</p>
<p><a href="http://www.mathworks.com/help/toolbox/aeroblks/llatoecefposition.html">http://www.mathworks.com/help/toolbox/aeroblks/llatoecefposition.html</a></p>
<p>4. To compute the orientation of the NED frame, the Direction Cosine Matrix to Quaternion block was used before mapping it to VRML rotational coordinates:</p>
<p><a href="http://www.mathworks.com/help/toolbox/aeroblks/directioncosinematrixtoquaternions.html">http://www.mathworks.com/help/toolbox/aeroblks/directioncosinematrixtoquaternions.html</a></p>
<p>The use of quaternions avoids the issues such as those encountered in this demo:</p>
<p><a href="http://www.mathworks.com/matlabcentral/fileexchange/26123">http://www.mathworks.com/matlabcentral/fileexchange/26123</a></p>
<p>5. The VR Tracer block from Simulink 3D Animation traces the trajectory in the 3D world. It is put inside an enabled subsystem to downsample the number of trajectory points and thus save memroy for visualization(each point plotted is a 3D object)</p>
<p>Thought provoking questions:
<br />1. Observe how thethe orientation of the aircraft is computed in the NED frame. How does this accuracy depend on the largest allowable number of sampling points i.e. t_scaled?</p>
<p>2. How accurate is the aircraft orientation for routes that pass over the poles? </p>
<p></p>Simulink Dudehttp://www.mathworks.com/matlabcentral/profile/authors/1297391-simulink-dudeMATLAB 7.12 (R2011a)Aerospace BlocksetMapping ToolboxSimulinkSimulink 3D Animation2612327986falsetag:www.mathworks.com,2005:FileInfo/281962010-07-13T11:04:27Z2010-10-21T12:25:48ZRobot Soccer: An Exercise in Learning the Key Features of Simulink Demo files to accompany the Introduction to Simulink webinar<p>This demo helps you apply the key features of Simulink that are discussed in the "Introduction to Simulink" webinar: </p>
<p><a href="http://www.mathworks.com/company/events/webinars/wbnr37271.html">http://www.mathworks.com/company/events/webinars/wbnr37271.html</a></p>
<p>The demo was specifically built using the features and concepts that are shown in the webinar; modeling a simple continuous system, adding nonlinearities, including documentation, using subsystems, masking, model reference, buses etc. </p>
<p>If you are new to Simulink, it is recommended that you watch the webinar before you try out the exercises and look to implement new strategies for the game. </p>
<p>Additional notes accompanying the demo. These notes have been intentionally kept fuzzy and listed in random order as it is expected that you will explore the model to understand all the components and their interaction with each other. </p>
<p>1. The demo simulates a 2 vs. 2 robot soccer match. The robots are assumed to be heavier than the football. Thus, any collision between the ball and the robots is perfectly elastic. The robot’s motion is not impacted by the collision. </p>
<p>2. Collision among robots is not implemented as they are considered as point masses. </p>
<p>3. Collision modeling in all cases is assumed to be as a spring contact model. When the object colliding with a boundary comes close to that boundary, a force proportional to the negative of the "penetration distance" is computed. </p>
<p>4. The strategy subsystems are implemented as referenced models. This was done intentionally so that competing teams could protect their strategies and run the simulation against each other. You can use the model reference protected mode to generate a mdlp file instead of mdl file (introduced in R2009b): </p>
<p>>> Simulink.ModelReference.protect('Team_1_Strategy') </p>
<p>and </p>
<p>>> Simulink.ModelReference.protect('Team_2_Strategy') </p>
<p>5. Robot dynamics are simple dynamics of a point mass. However, the mass is inversely proportional to the battery power or "stamina" of the robot. Some damping is also put into the system to avoid too much overshoot. Also, each time the robot actuates itself or brakes, it incurs a small power loss thereby lowering its endurance in the game. </p>
<p>6. Positional coordinates in the system are 2D i.e. (x,y). The signal dimensions have been set explicitly. Click on any of the output ports->signal attributes of the masked subsystems to see the dimensions. </p>
<p>7. Ball dynamics has a simple implementation- same "spring-based" contact dynamics. From the ball's point of view, there are five contact forces to be accounted for: contacts with the 4 robots and those of the boundaries. </p>
<p>8. Observe that the solver has been changed to ode15s which is a stiff solver. The reason for this is that there is stiffness present in the system because of the contact/collision modeling with high spring constants. This can give rise to modes with relatively different dynamics. With a ode45 solver, the faster modes will force the adaptive solver to take smaller steps slowing the simulation down. ode15s ignores some of these fast dynamics. </p>
<p>9. All the icon drawing commands on the robot dynamics subsystems were implemented using the MATLAB patch commands. These were taken from the flags demo by Mike Woodward: </p>
<p><a href="http://www.mathworks.com/matlabcentral/fileexchange/8856-flags">http://www.mathworks.com/matlabcentral/fileexchange/8856-flags</a> </p>
<p>Use other flags to customize this. </p>
<p>10. 2D animation was done using Simulink 3D Animation. The field was textured with a grass image and a viewpoint was so selected so that it looked as 2D. The "GOAL" text was kept behind the field. The moment, a goal is scored, this text is translated to the front giving a TV effect. Texturing was also used to paint the bodies of the robots with the flags. You will have to change the images in order to change these. </p>
<p>11. Play around with the strategy subsystems to see if you can come up with efficient strategies to score goals early. Note that each of the teams has full knowledge of the others' positions and those of the ball. They also have knowledge of the remaining power in their team's batteries. There is no velocity information available. </p>
<p>12. You need Simulink 3D Animation installed to view animation.</p>
<p>Exercises for you to try out:
<br />1. How can you use Stateflow to implement a finite state machine that uses a mix of attack and defensive strategies based on ball location? </p>
<p>2. What block in Simulink should you use to input a new signal into these strategy subsystems so that time elapsed since the start of the game can be measured and hence be used as part of the strategy? </p>
<p>3. Identify the contents inside the MAT file used in the demo. What is the "type" of the contents of the data inside the file? Identify the function that loads this MAT file. Why did we need these data objects in our model? </p>
<p>4. Explore the possibility of using control strategies, like PID, to improve robot tracking</p>
<p></p>Simulink Dudehttp://www.mathworks.com/matlabcentral/profile/authors/1297391-simulink-dudeMATLAB 7.10 (R2010a)Simulink 3D Animation8856falsetag:www.mathworks.com,2005:FileInfo/284512010-08-11T14:39:42Z2010-10-08T15:10:22ZSolution of Differential Equations with MATLAB & Simulink: Lorenz Attractor Case StudySimulink design pattern for solving differential equations, visualize results in MATLAB graphics<p>One of the readers who attended the introductory Simulink webinar:</p>
<p><a href="http://www.mathworks.com/company/events/webinars/wbnr37271.html">http://www.mathworks.com/company/events/webinars/wbnr37271.html</a></p>
<p>asked me how to implement differential equations in Simulink and visualize the results in a MATLAB plot. This demo attempts to answer those kinds of questions.</p>
<p>Notes on this submission:</p>
<p>1. The approach is to represent the equations using Simulink blocks and then use MATLAB graphics to plot the results. The advantage of using the graphical approach is with the ability to customize the solver configurations and step through the solution in time. </p>
<p>2. The design pattern shows a two stage model in which the integrator plays the role of integrating the ODE. The terms are collected and fed into this integrator. </p>
<p>3. As mentioned in the webinar, we use vector processing capabilities of the integrator to process the three terms simultaneously.</p>
<p>4. The concept of feedback is important as the solver solves for the next step in the simulation based on its current states. </p>
<p>5. We use MATLAB S-Functions to incorporate visualization code for the MATLAB GUI. Also, observe that we move the camera around so that you get a good visual of how the 3D curve looks like. There is also a model that uses a Level-1 S-function for those who may be interested in it for legacy reasons.</p>
<p>6. Look into the MATLAB S-Function code as to how a red marker that acts like a tracer is created.</p>
<p>7. The S-Function block was modeled as a discrete block with a sampling time so that a high fidelity plot could be obtained(at the cost of performance). There is a performance trade-off that you should look out for when visualizing results.</p>
<p>8. Look into the code for the various S-Functions and read the comments to understand how the code is structured.</p>
<p>9. Notes on the Lorenz Attractor: </p>
<p>The study of strange attractors began with the publication by E. N. Lorenz- "Deterministic non-periodic flow"(Journal of Atmospheric Science, 20:130-141, 1963). In the process of investigating meteorological models, Edward Lorenz found that very small truncation or rounding errors in his algorithms produced large changes in the resulting predictions. This led to the study of "strange" or chaotic attractors. </p>
<p>One crude way to visualize attractors is a set such that if during the evolution of the dynamics of the system, one of the states hits a point in that set, it will continue to remain in that set. From a simulation point of view, it is interesting to see the existence of such sets for certain nonlinear dynamical systems. If this attractor is chaotic meaning it has sensitive dependence on initial conditions, then it is called a strange attractor. </p>
<p>It was particularly an interesting result which he observed that for parameter values sigma=10, beta=8/3, and rho=28, the solutions start revolving about two repelling equilibirum points at (sqrt(72), sqrt(72.27).</p>
<p>The number of times the solution revolves around one equilibirum point before switching to the other has no discernible pattern. More information on this can be obtained in a standard introductory nonlinear systems text.</p>
<p>10. Questions to ponder about:</p>
<p>a. How would you project this 3D trajectory onto a arbitrary plane surface and visualize it during the simulation? Would the trajectory intersect itself?</p>
<p>b. How would you visualize the Poincare map?</p>
<p>c. How would you compute the number of turns the red marker makes around the equilibrium point before switching to the other? Could this number be used to generate random numbers?
<br /> </p>
<p></p>Simulink Dudehttp://www.mathworks.com/matlabcentral/profile/authors/1297391-simulink-dudeMATLAB 7.10 (R2010a)Simulinkfalsetag:www.mathworks.com,2005:FileInfo/260982009-12-14T14:37:15Z2009-12-14T14:37:15ZBouncing Ball with Damping and Temperature VisualizationExtension of the bouncing ball demo for the getting started series demos.<p>In this demo, we show how you can model the damping and energy loss of a bouncing ball by modifying the contact equations. We compute the cumulative energy loss to the floor as a function of time and use resetting of the integrator to compute the bursts of energy transferred to the floor after each bounce. We then use a simplified heat equation with special conditions to model the temperature rise of the floor. We also show how you can create your own color dynamics of the visualization by changing from a cold color(blue) to a warm color(red).</p>
<p>Note that Simulink 3D Animation was formerly called as Virtual Reality Toolbox.</p>
<p>The Getting Started videos of which this demo is an extension are available here:</p>
<p><a href="http://www.mathworks.com/products/3d-animation/demos.html">http://www.mathworks.com/products/3d-animation/demos.html</a>
</p>Simulink Dudehttp://www.mathworks.com/matlabcentral/profile/authors/1297391-simulink-dudeMATLAB 7.9 (R2009b)SimulinkSimulink 3D Animationfalsetag:www.mathworks.com,2005:FileInfo/128372006-10-31T11:13:35Z2006-11-27T15:52:09ZOptimization of a Double Wishbone Suspension SystemDemo files from the Webinar "Introduction to Optimization with MATLAB(R) Products" Oct. 26, 2006<p>This demo shows how to use MATLAB, Optimization Toolbox, and Genetic Algorithm and Direct Search Toolbox to optimize the design of a double wishbone suspension system. </p>
<p>Note: You will need to have the following products installed in order to run this demo: MATLAB, Simulink, Optimization Toolbox, Genetic Algorithm and Direct Search Toolbox, and SimMechanics. Optional: Virtual Reality Toolbox.</p>Stuart Kozolahttp://www.mathworks.com/matlabcentral/profile/authors/726228-stuart-kozolaMATLAB 7.3 (R2006b)Global Optimization ToolboxOptimization ToolboxSimMechanicsSimulinkSimulink 3D Animationfalsetag:www.mathworks.com,2005:FileInfo/49152004-05-12T18:59:25Z2005-05-02T09:50:07Z3DScopeMultitrack 3D Simulink Scope.<p>This block is an enhanced version of the standard XYGraph simulink block.</p>
<p>The standard XYGraph allows to plot the motion of ONE point in the XY plane. This block allows to plot the motion of SEVERAL points in the XYZ space. In other words each point draws a line as it moves, so you end up having several lines in the plot instead of just one. Of course setting the camera position parameter to [0 0 1] reduces the plot to a classic 2D one.</p>
<p>This block is very useful when you have to compare the motion of a point versus a reference trajectory.</p>
<p>The file M2DScope.mdl contains the block.
<br />The file sfunxyz.m is the actual s-function that implements the scope.</p>
<p>Giampy</p>Giampiero Campahttp://www.mathworks.com/matlabcentral/profile/authors/1692307-giampiero-campaMATLAB 5.3 (R11)Simulinktrue