DCMotor: Interactive Control

Introduction

This notebook shows how to create a custom real time simulation interface in Mathematica.

Explore the available scenarios by evaluating each cell in order. Evaluation is done by selecting a cell and pressing Shift+Enter.

In order to get the full experience of this example, you need the following:

Wolfram System Modeler; a free trial download is available at www.wolfram.com/system-modeler

The model that came in the same bundle as this notebook

For more information about Wolfram System Modeler, visit www.wolfram.com/system-modeler.

Initialize

Make the Wolfram System Modeler Link available and load the example model from the file.
Load the package:

Needs["WSMLink`"]

Define the model name:

mmodel="EducationExamples.ElectricalEngineering.DCMotor.Components.InteractiveMotor";

Setup

The user input will be added together with a base level and then sent as an input signal to the DC Motor. Below is a diagram view of the model.

SystemModel[mmodel,{"Diagram",ImageSize->Large,Frame->False}]

Setup the real time connection:

conn=WSMRealTimeSimulate[mmodel,{0,100},Method->{"RealTime"->True}]

Connect the Mathematica variable input to the variable userInput in the model:

WSMLink`Simulate`SetInputs[conn,"userInput"->(input&)]

User interface and Simulation

Define a user interface to control the simulation:

{graycolor,framecolor,plotframecolor,framefillingcolor}={RGBColor[0.9490196078431372`,0.9490196078431372`,0.9490196078431372`],
RGBColor[{0.8431372549019608`,0.8431372549019608`,0.8431372549019608`}],
RGBColor[{0.8392156862745098`,0.8392156862745098`,0.8392156862745098`}],
RGBColor[{0.9607843137254902`,0.9607843137254902`,0.9607843137254902`}]};
Framed[
Framed[
Grid[
{{Row[{Column[{Row[{Dynamic[Refresh[AngularGauge[input,{-1,1},ImageSize->140,PerformanceGoal->"Speed",GaugeLabels->{Placed["Input Signal",{.5,.7}],Automatic},GaugeStyle->1,ScaleRanges->{{.5,.6},{.6,.7},{.7,.8},{.8,1}}],UpdateInterval->0.5]],Spacer[15],
Dynamic[Refresh[AngularGauge[conn[{"motor.w"}],{-1,1},ImageSize->140,PerformanceGoal->"Speed",GaugeLabels->{Placed["Speed",{.5,.7}],Automatic},ScaleRanges->{{.5,.6},{.6,.7},{.7,.8},{.8,1}}],UpdateInterval->0.2]]}],
Row[{Slider[Dynamic[input],{-1,1},ImageSize->300]},Alignment->Center]}]}]},
{Row[{Column[{Framed[Style[Pane[
WSMRealTimePlot[conn,{"userInput","motor.w"},10,Paneled->False,ImageSize->{300,300},AspectRatio->1,PlotRange->{-1.5,1.5},PlotStyle->{Blue,Red},ImagePadding->15,Background->graycolor,PlotLegends->Placed[SwatchLegend[{Blue,Red},{"Input Signal","Speed"},LabelStyle->Directive[FontFamily->"Helvetica"],LegendMarkers->"Bubble"],Below]]],
Background->graycolor],FrameMargins->0,FrameStyle->Directive[plotframecolor]]}]}]}},
FrameStyle->Directive[framecolor],Background->White],
FrameMargins->{{17,17},{8,8}},Background->White,FrameStyle->Directive[framecolor]
],
FrameMargins->8,Background->framefillingcolor,FrameStyle->framecolor
]

Start the simulation by pressing the play button in the simulation control or by evaluating the next cell:

conn["Start"]

The simulation will run for 100 seconds. Drag the slider to change the input voltage and see how the speed is effected.

Terms and Conditions of Use

This domain example is an informational resource made freely available by Wolfram Research.

Use of This Example

• You may not use this example for any purpose that is unlawful or dangerous.
• You assume total responsibility and risk for your use of this example.
• You may not present this example with any alteration to its trade dress, trademarks, or design.

License

All content in this bundle is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. By accessing the content or using it in any way, you accept and agree to be bound by the terms of this license. If you do not agree to these Terms of Use, you may not use this content. Wolfram Research reserves the right to change, modify, add to, or remove portions of these Terms of Use at any time without notice. Please refer back to www.wolfram.com for the latest Terms of Use.

A summary of the licensing terms can be found at:
http://creativecommons.org/licenses/by-nc-sa/3.0

The full legal code can be found at: 
http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode