Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Initial value of simulink signal object in Unit Delay block
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
karthikeyan

Posts: 15
Registered: 1/12/09
Initial value of simulink signal object in Unit Delay block
Posted: Mar 6, 2012 5:44 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Legacy code
-------------------
sim_y = K1 * sim_x + K2 * sim_y;

if (sim_y <= SIM_XMAX) {sim_y = sim_x;}
else { sim_y = sim_y * K2;}


Limitations :
1. Don't use stateflow
2. Don't use DataStore blocks
3. Don't use Global Memory From/To blocks


Question 1: Is it possible to map the value of initial condition value with sim_y signal object initial value(i.e sim_y.InitialValue) during simulation?

Question 2: Is possible to generate the code as mentioned like legacy code?

I have added the signal object and model as text.

Thanks
Karthikeyan

Here the signal objects
F32=Simulink.AliasType;
F32.BaseType='single';

F64=Simulink.AliasType;
F64.BaseType='double';

SIM_XMAX = mpt.Parameter;
SIM_XMAX.Value = 5;
SIM_XMAX.DataType ='F32';

K1 = mpt.Parameter;
K1.Value = 0.2000;
K1.DataType ='F32';
K1.RTWInfo.CustomStorageClass = 'Define';

K2 = mpt.Parameter;
K2.Value = 0.7000;
K2.DataType ='F32';
K2.RTWInfo.CustomStorageClass = 'Define';

K2 = mpt.Parameter;
K2.Value = 0.5000;
K2.DataType ='F32';
K2.RTWInfo.CustomStorageClass = 'Define';

sim_x = mpt.Signal;
sim_x.DataType ='F32';
sim_x.InitialValue = '5';
sim_x.RTWInfo.CustomStorageClass = 'ImportFromFile';
sim_x.RTWInfo.CustomAttributes.HeaderFile = 'myimports.h';

sim_y = mpt.Signal;
sim_y.DataType ='F32';
sim_y.InitialValue = '10';

sim_out = mpt.Signal;
sim_out.DataType ='F32';

Here the test model(NOTE : COPY THE BELOW TEXT AND SAVE AS UnitDelayCodeGen.mdl

Model {
Name "UnitDelayCodeGen"
Version 7.0
MdlSubVersion 0
GraphicalInterface {
NumRootInports 1
Inport {
SignalName "sim_x"
Name "sim_x"
}
NumRootOutports 1
Outport {
BusObject ""
BusOutputAsStruct "off"
SignalName "sim_y"
Name "sim_y"
}
ParameterArgumentNames ""
ComputedModelVersion "1.132"
NumModelReferences 0
NumTestPointedSignals 0
}
SavedCharacterEncoding "windows-1252"
PostLoadFcn "load_dd"
SaveDefaultBlockParams on
SampleTimeColors off
LibraryLinkDisplay "none"
WideLines off
ShowLineDimensions off
ShowPortDataTypes on
ShowLoopsOnError on
IgnoreBidirectionalLines off
ShowStorageClass off
ShowTestPointIcons on
ShowViewerIcons on
SortedOrder off
ExecutionContextIcon off
ShowLinearizationAnnotations on
ScopeRefreshTime 0.035000
OverrideScopeRefreshTime on
DisableAllScopes off
DataTypeOverride "UseLocalSettings"
MinMaxOverflowLogging "UseLocalSettings"
MinMaxOverflowArchiveMode "Overwrite"
BlockNameDataTip off
BlockParametersDataTip off
BlockDescriptionStringDataTip off
ToolBar on
StatusBar on
BrowserShowLibraryLinks off
BrowserLookUnderMasks off
Created "Fri Dec 12 11:18:04 2008"
Creator "balu_karthikeyan"
UpdateHistory "UpdateHistoryNever"
ModifiedByFormat "%<Auto>"
LastModifiedBy "balu"
ModifiedDateFormat "%<Auto>"
LastModifiedDate "Tue Mar 06 15:14:51 2012"
RTWModifiedTimeStamp 252947686
ModelVersionFormat "1.%<AutoIncrement:132>"
ConfigurationManager "None"
SimulationMode "normal"
RTW.FcnDefault {
$PropName "RTWFcnClass"
$ObjectID 1
Name "Auto"
FunctionName "AutoCodeDemo_step"
}
LinearizationMsg "none"
Profile off
ParamWorkspaceSource "MATLABWorkspace"
AccelSystemTargetFile "accel.tlc"
AccelTemplateMakefile "accel_default_tmf"
AccelMakeCommand "make_rtw"
TryForcingSFcnDF off
RecordCoverage off
CovPath "/"
CovSaveName "covdata"
CovMetricSettings "dw"
CovNameIncrementing off
CovHtmlReporting on
covSaveCumulativeToWorkspaceVar on
CovSaveSingleToWorkspaceVar on
CovCumulativeVarName "covCumulativeData"
CovCumulativeReport off
CovReportOnPause on
ExtModeBatchMode off
ExtModeEnableFloating on
ExtModeTrigType "manual"
ExtModeTrigMode "normal"
ExtModeTrigPort "1"
ExtModeTrigElement "any"
ExtModeTrigDuration 1000
ExtModeTrigDurationFloating "auto"
ExtModeTrigHoldOff 0
ExtModeTrigDelay 0
ExtModeTrigDirection "rising"
ExtModeTrigLevel 0
ExtModeArchiveMode "off"
ExtModeAutoIncOneShot off
ExtModeIncDirWhenArm off
ExtModeAddSuffixToVar off
ExtModeWriteAllDataToWs off
ExtModeArmWhenConnect on
ExtModeSkipDownloadWhenConnect off
ExtModeLogAll on
ExtModeAutoUpdateStatusClock on
BufferReuse on
ShowModelReferenceBlockVersion off
ShowModelReferenceBlockIO off
Array {
Type "Handle"
Dimension 1
Simulink.ConfigSet {
$ObjectID 2
Version "1.3.0"
Array {
Type "Handle"
Dimension 7
Simulink.SolverCC {
$ObjectID 3
Version "1.3.0"
StartTime "0.0"
StopTime "1"
AbsTol "auto"
FixedStep "1"
InitialStep "auto"
MaxNumMinSteps "-1"
MaxOrder 5
ConsecutiveZCsStepRelTol "10*128*eps"
MaxConsecutiveZCs "1000"
ExtrapolationOrder 4
NumberNewtonIterations 1
MaxStep "auto"
MinStep "auto"
MaxConsecutiveMinStep "1"
RelTol "1e-3"
SolverMode "Auto"
Solver "FixedStepDiscrete"
SolverName "FixedStepDiscrete"
ZeroCrossControl "UseLocalSettings"
AlgebraicLoopSolver "TrustRegion"
SolverResetMethod "Fast"
PositivePriorityOrder off
AutoInsertRateTranBlk off
SampleTimeConstraint "Unconstrained"
RateTranMode "Deterministic"
}
Simulink.DataIOCC {
$ObjectID 4
Version "1.3.0"
Decimation "1"
ExternalInput "[t, u]"
FinalStateName "xFinal"
InitialState "xInitial"
LimitDataPoints on
MaxDataPoints "1000"
LoadExternalInput off
LoadInitialState off
SaveFinalState off
SaveFormat "Array"
SaveOutput on
SaveState off
SignalLogging on
InspectSignalLogs off
SaveTime on
StateSaveName "xout"
TimeSaveName "tout"
OutputSaveName "yout"
SignalLoggingName "logsout"
OutputOption "RefineOutputTimes"
OutputTimes "[]"
Refine "1"
}
Simulink.OptimizationCC {
$ObjectID 5
Version "1.3.0"
BlockReduction on
BooleanDataType on
ConditionallyExecuteInputs on
InlineParams on
InlineInvariantSignals off
OptimizeBlockIOStorage on
BufferReuse on
EnforceIntegerDowncast on
ExpressionFolding on
ExpressionDepthLimit 2147483647
FoldNonRolledExpr on
LocalBlockOutputs on
RollThreshold 5
SystemCodeInlineAuto off
StateBitsets off
DataBitsets off
UseTempVars off
ZeroExternalMemoryAtStartup on
ZeroInternalMemoryAtStartup on
InitFltsAndDblsToZero on
NoFixptDivByZeroProtection off
EfficientFloat2IntCast off
OptimizeModelRefInitCode on
LifeSpan "1"
BufferReusableBoundary on
SimCompilerOptimization "Off"
AccelVerboseBuild off
}
Simulink.DebuggingCC {
$ObjectID 6
Version "1.3.0"
RTPrefix "error"
ConsistencyChecking "none"
ArrayBoundsChecking "none"
SignalInfNanChecking "none"
SignalRangeChecking "none"
ReadBeforeWriteMsg "UseLocalSettings"
WriteAfterWriteMsg "UseLocalSettings"
WriteAfterReadMsg "UseLocalSettings"
AlgebraicLoopMsg "warning"
ArtificialAlgebraicLoopMsg "warning"
SaveWithDisabledLinksMsg "warning"
SaveWithParameterizedLinksMsg "warning"
CheckSSInitialOutputMsg on
CheckExecutionContextPreStartOutputMsg off
CheckExecutionContextRuntimeOutputMsg off
SignalResolutionControl "UseLocalSettings"
BlockPriorityViolationMsg "warning"
MinStepSizeMsg "warning"
TimeAdjustmentMsg "none"
MaxConsecutiveZCsMsg "error"
SolverPrmCheckMsg "warning"
InheritedTsInSrcMsg "warning"
DiscreteInheritContinuousMsg "warning"
MultiTaskDSMMsg "error"
MultiTaskCondExecSysMsg "error"
MultiTaskRateTransMsg "error"
SingleTaskRateTransMsg "none"
TasksWithSamePriorityMsg "warning"
SigSpecEnsureSampleTimeMsg "warning"
CheckMatrixSingularityMsg "none"
IntegerOverflowMsg "warning"
Int32ToFloatConvMsg "warning"
ParameterDowncastMsg "error"
ParameterOverflowMsg "error"
ParameterUnderflowMsg "none"
ParameterPrecisionLossMsg "warning"
ParameterTunabilityLossMsg "warning"
UnderSpecifiedDataTypeMsg "none"
UnnecessaryDatatypeConvMsg "none"
VectorMatrixConversionMsg "none"
InvalidFcnCallConnMsg "error"
FcnCallInpInsideContextMsg "Use local settings"
SignalLabelMismatchMsg "none"
UnconnectedInputMsg "warning"
UnconnectedOutputMsg "warning"
UnconnectedLineMsg "warning"
SFcnCompatibilityMsg "none"
UniqueDataStoreMsg "none"
BusObjectLabelMismatch "warning"
RootOutportRequireBusObject "warning"
AssertControl "UseLocalSettings"
EnableOverflowDetection off
ModelReferenceIOMsg "none"
ModelReferenceVersionMismatchMessage "none"
ModelReferenceIOMismatchMessage "none"
ModelReferenceCSMismatchMessage "none"
ModelReferenceSimTargetVerbose off
UnknownTsInhSupMsg "warning"
ModelReferenceDataLoggingMessage "warning"
ModelReferenceSymbolNameMessage "warning"
ModelReferenceExtraNoncontSigs "error"
StateNameClashWarn "warning"
StrictBusMsg "Warning"
LoggingUnavailableSignals "error"
}
Simulink.HardwareCC {
$ObjectID 7
Version "1.3.0"
ProdBitPerChar 8
ProdBitPerShort 16
ProdBitPerInt 32
ProdBitPerLong 32
ProdIntDivRoundTo "Undefined"
ProdEndianess "Unspecified"
ProdWordSize 32
ProdShiftRightIntArith on
ProdHWDeviceType "32-bit Generic"
TargetBitPerChar 8
TargetBitPerShort 16
TargetBitPerInt 32
TargetBitPerLong 32
TargetShiftRightIntArith on
TargetIntDivRoundTo "Undefined"
TargetEndianess "Unspecified"
TargetWordSize 32
TargetTypeEmulationWarnSuppressLevel 0
TargetPreprocMaxBitsSint 32
TargetPreprocMaxBitsUint 32
TargetHWDeviceType "Specified"
TargetUnknown off
ProdEqTarget on
}
Simulink.ModelReferenceCC {
$ObjectID 8
Version "1.3.0"
UpdateModelReferenceTargets "IfOutOfDateOrStructuralChange"
CheckModelReferenceTargetMessage "error"
ModelReferenceNumInstancesAllowed "Multi"
ModelReferencePassRootInputsByReference on
ModelReferenceMinAlgLoopOccurrences off
}
Simulink.RTWCC {
$BackupClass "Simulink.RTWCC"
$ObjectID 9
Version "1.3.0"
SystemTargetFile "ert.tlc"
GenCodeOnly on
MakeCommand "make_rtw"
GenerateMakefile off
TemplateMakefile "ert_default_tmf"
Description "Real-Time Workshop Embedded Coder (no auto configuration)"
GenerateReport on
SaveLog off
RTWVerbose on
RetainRTWFile off
ProfileTLC off
TLCDebug off
TLCCoverage off
TLCAssert off
ProcessScriptMode "Default"
ConfigurationMode "Optimized"
ProcessScript "ert_make_rtw_hook"
ConfigAtBuild off
IncludeHyperlinkInReport on
LaunchReport on
TargetLang "C"
IncludeBusHierarchyInRTWFileBlockHierarchyMap off
IncludeERTFirstTime off
GenerateTraceInfo on
RTWCompilerOptimization "Off"
Array {
Type "Handle"
Dimension 2
Simulink.CodeAppCC {
$ObjectID 10
Version "1.3.0"
ForceParamTrailComments off
GenerateComments on
IgnoreCustomStorageClasses off
IncHierarchyInIds off
MaxIdLength 31
PreserveName off
PreserveNameWithParent off
ShowEliminatedStatement off
IncAutoGenComments off
SimulinkDataObjDesc on
SFDataObjDesc on
IncDataTypeInIds off
MangleLength 1
CustomSymbolStrGlobalVar "$R$N$M"
CustomSymbolStrType "$N$R$M"
CustomSymbolStrField "$N$M"
CustomSymbolStrFcn "$N$M$F"
CustomSymbolStrBlkIO "rtb_$N$M"
CustomSymbolStrTmpVar "$N$M"
CustomSymbolStrMacro "$R$N$M"
DefineNamingRule "None"
ParamNamingRule "UpperCase"
SignalNamingRule "None"
InsertBlockDesc on
SimulinkBlockComments on
EnableCustomComments off
InlinedPrmAccess "Literals"
ReqsInCode off
}
Simulink.ERTTargetCC {
$BackupClass "Simulink.TargetCC"
$ObjectID 11
Version "1.3.0"
TargetFcnLib "ansi_tfl_table_tmw.mat"
TargetLibSuffix ""
TargetPreCompLibLocation ""
GenFloatMathFcnCalls "ANSI_C"
UtilityFuncGeneration "Auto"
GenerateFullHeader on
GenerateSampleERTMain on
GenerateTestInterfaces off
IsPILTarget off
ModelReferenceCompliant on
CompOptLevelCompliant on
IncludeMdlTerminateFcn on
CombineOutputUpdateFcns on
SuppressErrorStatus off
IncludeFileDelimiter "Auto"
ERTCustomFileBanners on
SupportAbsoluteTime on
LogVarNameModifier "rt_"
MatFileLogging off
MultiInstanceERTCode off
SupportNonFinite on
SupportComplex on
PurelyIntegerCode off
SupportContinuousTime off
SupportNonInlinedSFcns off
EnableShiftOperators on
ParenthesesLevel "Nominal"
PortableWordSizes off
ModelStepFunctionPrototypeControlCompliant on
GenerateErtSFunction off
GenerateASAP2 off
ExtMode off
ExtModeTransport 0
ExtModeStaticAlloc off
ExtModeStaticAllocSize 1000000
ExtModeTesting off
ExtModeMexFile "ext_comm"
ExtModeIntrfLevel "Level1"
InlinedParameterPlacement "NonHierarchical"
TargetOS "BareBoardExample"
MultiInstanceErrorCode "Error"
RateGroupingCode on
RootIOFormat "Individual arguments"
RTWCAPISignals off
RTWCAPIParams off
RTWCAPIStates off
ERTSrcFileBannerTemplate "ert_code_template.cgt"
ERTHdrFileBannerTemplate "ert_code_template.cgt"
ERTDataSrcFileTemplate "ert_code_template.cgt"
ERTDataHdrFileTemplate "ert_code_template.cgt"
ERTCustomFileTemplate "example_file_process.tlc"
ModuleNamingRule "Unspecified"
SignalDisplayLevel 10
ParamTuneLevel 10
GlobalDataDefinition "Auto"
DataDefinitionFile "global.c"
GlobalDataReference "Auto"
DataReferenceFile "global.h"
GRTInterface off
PreserveExpressionOrder off
PreserveIfCondition off
EnableUserReplacementTypes on
Array {
Type "Struct"
Dimension 1
MATStruct {
double "F64"
single "F32"
int32 ""
int16 ""
int8 ""
uint32 ""
uint16 ""
uint8 ""
boolean ""
int ""
uint ""
char ""
}
PropName "ReplacementTypes"
}
MemSecPackage "mpt"
MemSecDataConstants "Default"
MemSecDataIO "Default"
MemSecDataInternal "Default"
MemSecDataParameters "Default"
MemSecFuncInitTerm "Default"
MemSecFuncExecute "Default"
}
PropName "Components"
}
}
PropName "Components"
}
Name "Configuration"
ExtraOptions "-aGenerateTraceInfo=1 "
CurrentDlgPage "Optimization"
}
PropName "ConfigurationSets"
}
Simulink.ConfigSet {
$PropName "ActiveConfigurationSet"
$ObjectID 2
}
BlockDefaults {
Orientation "right"
ForegroundColor "black"
BackgroundColor "white"
DropShadow off
NamePlacement "normal"
FontName "Arial"
FontSize 10
FontWeight "normal"
FontAngle "normal"
ShowName on
}
BlockParameterDefaults {
Block {
BlockType Gain
Gain "1"
Multiplication "Element-wise(K.*u)"
ParamMin "[]"
ParamMax "[]"
ParameterDataTypeMode "Same as input"
ParameterDataType "fixdt(1,16,0)"
ParameterScalingMode "Best Precision: Matrix-wise"
ParameterScaling "[]"
OutMin "[]"
OutMax "[]"
OutDataTypeMode "Same as input"
OutDataType "fixdt(1,16,0)"
OutScaling "[]"
LockScale off
RndMeth "Floor"
SaturateOnIntegerOverflow on
SampleTime "-1"
}
Block {
BlockType Inport
Port "1"
UseBusObject off
BusObject "BusObject"
BusOutputAsStruct off
PortDimensions "-1"
SampleTime "-1"
OutMin "[]"
OutMax "[]"
DataType "auto"
OutDataType "fixdt(1,16,0)"
OutScaling "[]"
SignalType "auto"
SamplingMode "auto"
LatchByDelayingOutsideSignal off
LatchByCopyingInsideSignal off
Interpolate on
}
Block {
BlockType SignalViewerScope
Floating off
ModelBased off
TickLabels "OneTimeTick"
ZoomMode "on"
Grid "on"
TimeRange "auto"
YMin "-5"
YMax "5"
SaveToWorkspace off
SaveName "ScopeData"
LimitDataPoints on
MaxDataPoints "5000"
Decimation "1"
SampleInput off
SampleTime "0"
Disabled off
ScrollMode on
}
Block {
BlockType Outport
Port "1"
UseBusObject off
BusObject "BusObject"
BusOutputAsStruct off
PortDimensions "-1"
SampleTime "-1"
OutMin "[]"
OutMax "[]"
DataType "auto"
OutDataType "fixdt(1,16,0)"
OutScaling "[]"
SignalType "auto"
SamplingMode "auto"
OutputWhenDisabled "held"
InitialOutput "[]"
}
Block {
BlockType SubSystem
ShowPortLabels "FromPortIcon"
Permissions "ReadWrite"
PermitHierarchicalResolution "All"
TreatAsAtomicUnit off
SystemSampleTime "-1"
RTWFcnNameOpts "Auto"
RTWFileNameOpts "Auto"
RTWMemSecFuncInitTerm "Inherit from model"
RTWMemSecFuncExecute "Inherit from model"
RTWMemSecDataConstants "Inherit from model"
RTWMemSecDataInternal "Inherit from model"
RTWMemSecDataParameters "Inherit from model"
SimViewingDevice off
DataTypeOverride "UseLocalSettings"
MinMaxOverflowLogging "UseLocalSettings"
}
Block {
BlockType Sum
IconShape "rectangular"
Inputs "++"
CollapseMode "All dimensions"
CollapseDim "1"
InputSameDT on
OutMin "[]"
OutMax "[]"
OutDataTypeMode "Same as first input"
OutDataType "fixdt(1,16,0)"
OutScaling "[]"
LockScale off
RndMeth "Floor"
SaturateOnIntegerOverflow on
SampleTime "-1"
}
Block {
BlockType Switch
Criteria "u2 >= Threshold"
Threshold "0"
InputSameDT on
OutMin "[]"
OutMax "[]"
OutDataTypeMode "Inherit via internal rule"
OutDataType "fixdt(1,16,0)"
OutScaling "[]"
LockScale off
RndMeth "Floor"
SaturateOnIntegerOverflow on
ZeroCross on
SampleTime "-1"
}
Block {
BlockType UnitDelay
X0 "0"
SampleTime "1"
StateMustResolveToSignalObject off
RTWStateStorageClass "Auto"
}
Block {
BlockType Constant
Value "1"
VectorParams1D on
SamplingMode "Sample based"
OutMin "[]"
OutMax "[]"
OutDataTypeMode "Inherit from 'Constant value'"
OutDataType "fixdt(1,16,0)"
ConRadixGroup "Use specified scaling"
OutScaling "[]"
SampleTime "inf"
FramePeriod "inf"
}
Block {
BlockType RelationalOperator
Operator ">="
InputSameDT on
LogicOutDataTypeMode "Logical (see Configuration Parameters: Optimization)"
LogicDataType "uint(8)"
ZeroCross on
SampleTime "-1"
}
}
AnnotationDefaults {
HorizontalAlignment "center"
VerticalAlignment "middle"
ForegroundColor "black"
BackgroundColor "white"
DropShadow off
FontName "Arial"
FontSize 10
FontWeight "normal"
FontAngle "normal"
UseDisplayTextAsClickCallback off
}
LineDefaults {
FontName "Arial"
FontSize 9
FontWeight "normal"
FontAngle "normal"
}
System {
Name "UnitDelayCodeGen"
Location [2, 74, 1364, 707]
Open on
ModelBrowserVisibility off
ModelBrowserWidth 212
ScreenColor "white"
PaperOrientation "landscape"
PaperPositionMode "auto"
PaperType "usletter"
PaperUnits "inches"
TiledPaperMargins [0.500000, 0.500000, 0.500000, 0.500000]
TiledPageScale 1
ShowPageBoundaries off
ZoomFactor "99"
ReportName "simulink-default.rpt"
Block {
BlockType Inport
Name "sim_x"
Position [285, 48, 315, 62]
IconDisplay "Port number"
Port {
PortNumber 1
Name "sim_x"
MustResolveToSignalObject on
RTWStorageClass "Auto"
DataLoggingNameMode "SignalName"
}
}
Block {
BlockType Sum
Name "Add"
Ports [2, 1]
Position [575, 90, 615, 120]
ShowName off
IconShape "round"
Inputs "|++"
CollapseMode "All dimensions"
InputSameDT off
OutDataTypeMode "Inherit via internal rule"
OutDataType "sfix(16)"
OutScaling "2^-10"
SaturateOnIntegerOverflow off
Port {
PortNumber 1
Name "sim_y"
RTWStorageClass "Auto"
DataLoggingNameMode "SignalName"
}
}
Block {
BlockType Reference
Name "Compare\nTo Constant"
Ports [1, 1]
Position [690, 92, 770, 118]
ShowName off
SourceBlock "simulink/Logic and Bit\nOperations/Compare\nTo Constant"
SourceType "Compare To Constant"
ShowPortLabels "FromPortIcon"
SystemSampleTime "-1"
FunctionWithSeparateData off
RTWMemSecFuncInitTerm "Inherit from model"
RTWMemSecFuncExecute "Inherit from model"
RTWMemSecDataConstants "Inherit from model"
RTWMemSecDataInternal "Inherit from model"
RTWMemSecDataParameters "Inherit from model"
relop "<="
const "SIM_XMAX"
LogicOutDataTypeMode "boolean"
ZeroCross off
}
Block {
BlockType Gain
Name "Gain_1"
Description "This is first threshold"
Position [505, 90, 535, 120]
Gain "K1"
ParameterDataTypeMode "Inherit via internal rule"
ParameterDataType "sfix(16)"
ParameterScaling "2^0"
OutDataTypeMode "Inherit via internal rule"
OutDataType "sfix(16)"
OutScaling "2^0"
SaturateOnIntegerOverflow off
}
Block {
BlockType Gain
Name "Gain_2"
Position [505, 155, 535, 185]
Gain "K2"
ParameterDataTypeMode "Inherit via internal rule"
ParameterDataType "sfix(16)"
ParameterScaling "2^0"
OutDataTypeMode "Inherit via internal rule"
OutDataType "sfix(16)"
OutScaling "2^0"
SaturateOnIntegerOverflow off
}
Block {
BlockType Gain
Name "Gain_3"
Position [725, 140, 755, 170]
Gain "K2"
ParameterDataTypeMode "Inherit via internal rule"
ParameterDataType "sfix(16)"
ParameterScaling "2^0"
OutDataTypeMode "Inherit via internal rule"
OutDataType "sfix(16)"
OutScaling "2^0"
SaturateOnIntegerOverflow off
}
Block {
BlockType Switch
Name "Switch"
Position [835, 90, 865, 120]
Threshold "0.5"
InputSameDT off
OutDataType "sfix(16)"
OutScaling "2^0"
SaturateOnIntegerOverflow off
Port {
PortNumber 1
Name "sim_y"
MustResolveToSignalObject on
RTWStorageClass "Auto"
DataLoggingNameMode "SignalName"
}
}
Block {
BlockType UnitDelay
Name "Unit Delay"
Position [400, 153, 435, 187]
Port {
PortNumber 1
PropagatedSignals "sim_y"
ShowPropagatedSignals "on"
RTWStorageClass "Auto"
DataLoggingNameMode "SignalName"
}
}
Block {
BlockType Outport
Name "sim_y"
Position [925, 98, 955, 112]
IconDisplay "Port number"
}
Block {
BlockType SignalViewerScope
Name "Scope"
Ports []
Position [20, 15, 60, 55]
IOType "viewer"
List {
ListType IOSignalStrings
set0ParseKeys "9"
set0Sigs "Switch:o1"
}
Location [162, 372, 486, 611]
Open off
NumInputPorts "1"
List {
ListType AxesTitles
axes1 "%<SignalLabel>"
}
ShowDataMarkers off
ShowLegends off
DataFormat "Array"
MaxDataPoints "7500"
RefreshTime 0.035000
}
Block {
BlockType SignalViewerScope
Name "Scope1"
Ports []
Position [20, 15, 60, 55]
IOType "viewer"
List {
ListType IOSignalStrings
set0ParseKeys "6"
set0Sigs "Add:o1"
}
Location [188, 365, 512, 604]
Open off
NumInputPorts "1"
List {
ListType AxesTitles
axes1 "%<SignalLabel>"
}
ShowDataMarkers off
ShowLegends off
SaveName "ScopeData1"
DataFormat "Array"
MaxDataPoints "7500"
RefreshTime 0.035000
}
Block {
BlockType SignalViewerScope
Name "Scope2"
Ports []
Position [20, 15, 60, 55]
IOType "viewer"
List {
ListType IOSignalStrings
set0ParseKeys "13"
set0Sigs "Unit Delay:o1"
}
Location [188, 365, 512, 604]
Open off
NumInputPorts "1"
List {
ListType AxesTitles
axes1 "%<SignalLabel>"
}
ShowDataMarkers off
ShowLegends off
SaveName "ScopeData2"
DataFormat "Array"
MaxDataPoints "7500"
RefreshTime 0.035000
}
Line {
Name "sim_x"
Labels [0, 0]
SrcBlock "sim_x"
SrcPort 1
Points [45, 0]
Branch {
Points [0, 50]
DstBlock "Gain_1"
DstPort 1
}
Branch {
Points [445, 0; 0, 40]
DstBlock "Switch"
DstPort 1
}
}
Line {
SrcBlock "Gain_1"
SrcPort 1
DstBlock "Add"
DstPort 1
}
Line {
Labels [0, 0]
SrcBlock "Unit Delay"
SrcPort 1
DstBlock "Gain_2"
DstPort 1
}
Line {
SrcBlock "Gain_2"
SrcPort 1
Points [55, 0]
DstBlock "Add"
DstPort 2
}
Line {
Name "sim_y"
Labels [0, 0]
SrcBlock "Add"
SrcPort 1
Points [50, 0]
Branch {
DstBlock "Compare\nTo Constant"
DstPort 1
}
Branch {
Points [0, 50]
Branch {
DstBlock "Gain_3"
DstPort 1
}
Branch {
Points [0, 100; -305, 0; 0, -85]
DstBlock "Unit Delay"
DstPort 1
}
}
}
Line {
Name "sim_y"
Labels [0, 0]
SrcBlock "Switch"
SrcPort 1
DstBlock "sim_y"
DstPort 1
}
Line {
SrcBlock "Compare\nTo Constant"
SrcPort 1
DstBlock "Switch"
DstPort 2
}
Line {
SrcBlock "Gain_3"
SrcPort 1
Points [50, 0; 0, -40]
DstBlock "Switch"
DstPort 3
}
Annotation {
Name "Legacy code\n-------------------\nsim_y = K1 * sim_x + K2 * sim_y;\n\nif (sim_y <= SIM_XMAX) {sim_y = sim_x;}\nelse { sim_y = sim_y * K2;}"
Position [184, 170]
ForegroundColor "orange"
DropShadow on
FontSize 16
}
Annotation {
Name "Implementation:\n-----------------------\n1. sim_x is global input signal from other feature\n2. sim_y is global signal to share other feature\n3. SIM_XMAX is calibrations\n K1 and K2 are defines\n\nSIM_XMAX = 10\nK1 = 0.2\nK2 = 0.5"
Position [34, 389]
HorizontalAlignment "left"
ForegroundColor "cyan"
DropShadow on
FontSize 16
}
Annotation {
Name "Calculation\nsim_y = K1 * sim_x + K2 * sim_y;\n\n = 0.2 * 5 + 0.5 * 10 => 6"
Position [949, 445]
DropShadow on
FontSize 16
}
Annotation {
Name "Question 1: Is it possible to map the value of initial condition value with sim_y signal object initial value(i.e sim_y.InitialValue)\n during simulation?\n\nQuestion 2: Is possible to generate the code as mentioned as like legacy code?"
Position [424, 343]
HorizontalAlignment "left"
ForegroundColor "red"
DropShadow on
FontSize 16
}
Annotation {
Name "Limitations :\n1. Don't use stateflow\n2. Don't use DataStore blocks\n3. Don't use Global Memory From/To blocks"
Position [718, 239]
HorizontalAlignment "left"
ForegroundColor "green"
DropShadow on
FontSize 12
}
}
}
# Finite State Machines
#
# Stateflow Version 6.7 (R2007b) dated Aug 7 2007, 16:48:14
#
#


Stateflow {
machine {
id 1
name "UnitDelayCodeGen"
created "12-Dec-2008 12:02:44"
isLibrary 0
firstTarget 2
sfVersion 67014000.000001
}
target {
id 2
name "sfun"
description "Default Simulink S-Function Target."
codeFlags " debug=1 overflow=1 echo=1"
machine 1
linkNode [1 0 3]
}
target {
id 3
name "rtw"
codeFlags " comments=1 statebitsets=1 databitsets=1 emitlogicalops=1 elseifdetection=1 constantfolding=1 redundantloadelimination=0 preservenames=0 preservenameswithparent=0 exportcharts=0"
machine 1
linkNode [1 2 0]
}
}



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.