21BPS1034 Lab-9
21BPS1034 Lab-9
CHENNAI CAMPUS
Lab 9
AIM:
SOFTWARE REQUIRED:
Ptolemy II (supports various domain-specific languages and provides a user-
friendly environment for editing system parameters and observing their
effects on time-plots.)
PROCEDURE:
1. The Ptolemy software interface and its components should be familiarized with.
2. The Electric Power Generator System to be analyzed along with its associated
time- plots should be identified.
3. A parameter within the system for modification should be selected.
4. The chosen parameter's value or configuration should be edited,
ensuring documentation of the original and altered settings.
5. The simulation or analysis should be run with the modified parameter.
6. The resulting time-plot should be observed and compared with the original
one, noting any significant changes in characteristics such as amplitude,
frequency,
or shape.
7. Steps 3-6 should be repeated for other parameters within the system to
understand their individual effects on the time-plots.
8. The observed changes should be analyzed to draw conclusions about the
system's behavior under different parameter configurations.
9. Documentation should include the original and modified parameter values, the
observed time-plot changes, and any insights gained about the system's
performance.
10. The results should be shared with relevant stakeholders, and the gathered
information should be used to optimize the system's performance or improve
the Ptolemy software's functionality.
CIRCUIT DIAGRAM:
import java.util.HashMap;
import java.util.Iterator;
import
java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import ptolemy.actor.IOPort;
import
ptolemy.actor.TypedAtomicActor;
import ptolemy.actor.TypedIOPort;
import ptolemy.data.DoubleToken;
import ptolemy.data.IntToken;
import ptolemy.data.Token;
import
ptolemy.data.expr.ASTPtRootNode;
import ptolemy.data.expr.ModelScope;
import ptolemy.data.expr.Parameter;
import ptolemy.data.expr.ParseTreeEvaluator;
import
ptolemy.data.expr.ParseTreeFreeVariableCollector;
import ptolemy.data.expr.ParseTreeTypeInference;
import ptolemy.data.expr.PtParser;
import ptolemy.data.expr.Variable;
import
ptolemy.data.type.BaseType;
import
ptolemy.data.type.MonotonicFunction;
import ptolemy.data.type.Type;
import ptolemy.data.type.TypeConstant;
import ptolemy.graph.InequalityTerm;
import
ptolemy.kernel.CompositeEntity;
import ptolemy.kernel.util.Attribute;
import ptolemy.kernel.util.IllegalActionException;
import ptolemy.kernel.util.NameDuplicationException;
import ptolemy.kernel.util.Settable;
import
ptolemy.kernel.util.StringAttribute;
import ptolemy.kernel.util.Workspace;
_setOutputTypeConstraint();
}
public TypedIOPort output;
public StringAttribute
expression; @Override
public void attributeChanged(Attribute
attribute) throws IllegalActionException {
if (attribute == expression) {
_parseTree = null;
}
}
@Override
public Object clone(Workspace workspace) throws CloneNotSupportedException
{ Expression newObject = (Expression) super.clone(workspace);
newObject._iterationCount = 1;
newObject._parseTree = null;
newObject._parseTreeEvaluator = null;
newObject._scope = null;
newObject._setOutputTypeConstraint()
; newObject._tokenMap = null;
return newObject;
}
@Override
public void fire() throws IllegalActionException
{ super.fire();
Iterator inputPorts = inputPortList().iterator();
while (inputPorts.hasNext()) {
IOPort port = (IOPort) inputPorts.next();
try {,
if (_parseTree == null) {
PtParser parser = new PtParser();
_parseTree = parser
.generateParseTree(expression.getExpression());
}
if (_parseTreeEvaluator == null) {
_parseTreeEvaluator = new ParseTreeEvaluator();
}
if (_scope == null) {
_scope = new VariableScope();
}
if (_result == null) {
throw new
IllegalActionException(this,
"Expression yields a null result: "
+ expression.getExpression());
}
output.send(0, _result);
}
@Override
public void initialize() throws IllegalActionException
{ super.initialize();
if (getPort("time") != null) {
throw new IllegalActionException(this,
"This actor has a port named \"time\", "
+ "which will not be read, instead the "
+ "reserved system variable \"time\" will be read. "
+ "Delete the \"time\" port to avoid this message.");
}
if (getPort("iteration") != null) {
throw new IllegalActionException(this,
"This actor has a port named \"iteration\", "
+ "which will not be read, instead the "
+ "reserved system variable \"iteration\" will be read. "
+ "Delete the \"iteration\" port to avoid this message.");
}
_iterationCount = 1;
}
@Override
public boolean postfire() throws IllegalActionException {
_iterationCount++;
return
super.postfire();
}
@Override
public boolean prefire() throws IllegalActionException
{ Iterator inputPorts = inputPortList().iterator();
while (inputPorts.hasNext()) {
IOPort port = (IOPort)
inputPorts.next(); if
(port.isOutsideConnected()) {
if (!port.hasToken(0))
{ return false;
}
}
}
return super.prefire();
}
@Override
public void preinitialize() throws IllegalActionException
{ super.preinitialize();
_tokenMap = new HashMap<String, Token>();
}
protected Token _result;
_setOutputTypeConstraint() {
output.setTypeAtLeast(new OutputTypeFunction());
}
Token token =
_tokenMap.get(name); if (token !=
null) {
return token;
}
return null;
}
@Override
public Type getType(String name) throws IllegalActionException
{ if (name.equals("time")) {
return BaseType.DOUBLE;
} else if (name.equals("iteration"))
{ return BaseType.INT;
}
TypedIOPort port = (TypedIOPort) getPort(name);
if (port != null) {
return port.getType();
}
return null;
}
@Override
public ptolemy.graph.InequalityTerm getTypeTerm(String
name) throws IllegalActionException {
if (name.equals("time")) {
return new TypeConstant(BaseType.DOUBLE);
} else if (name.equals("iteration")) {
return new TypeConstant(BaseType.INT);
}
return null;
}
@Override
public Set identifierSet() {
return getAllScopedVariableNames(null, Expression.this);
}
}
private class OutputTypeFunction extends MonotonicFunction
{ @Override
public Object getValue() throws IllegalActionException
{ try {
InequalityTerm[] terms = getVariables();
if (_scope == null) {
_scope = new VariableScope();
}
Type type = _typeInference.inferTypes(_parseTree,
_scope); return type;
} catch (Exception ex) {
throw new IllegalActionException(Expression.this, ex,
"An error occurred during expression type inference of \""
+ expression.getExpression() + "\".");
}
}
@Override
public InequalityTerm[] getVariables()
{ try {
if (_parseTree == null) {
PtParser parser = new PtParser();
_parseTree = parser
.generateParseTree(expression.getExpression());
}
if (_scope == null) {
_scope = new VariableScope();
}
disconnectGraphOnAbsentValue; public
Parameter useLocalTime;
@Override
public Object clone(Workspace workspace) throws CloneNotSupportedException
{ TimedPlotter newObject = (TimedPlotter) super.clone(workspace);
newObject._connected = new ArrayList<Boolean>();
return newObject;
}
@Override
public boolean prefire() throws IllegalActionException
{ super.prefire();
int width = input.getWidth();
if (width != _connected.size()) {
_connected.clear();
for (int i = 0; i < width; i++) {
_connected.add(true);
}
}
return true;
}
@Override
public void initialize() throws IllegalActionException
{ super.initialize();
int width = input.getWidth();
_connected.clear();
for (int i = 0; i < width; i++) {
_connected.add(true);
}
((PlotInterface) plot).markDisconnections(true);
}
@Override
public boolean postfire() throws IllegalActionException
{ double currentTimeValue;
int width = input.getWidth();
return super.postfire();
}
RESULT:
In Ptolemy, when analyzing a Electric Power Generator System, the results may vary
depending on the edited parameters. Key observations include changes in output
power, efficiency, and stability of the system. By adjusting parameters such as input
power, load demand, or control mechanisms, one can observe how these factors
influence the overall performance of the power generator. The results can provide
valuable insights for improving system efficiency, maintaining optimal performance,
and ensuring the stability of the power generation process.
ROBOT MPC SYSTEM
AIM:
To analyze and evaluate the impact of Robot MPC System by modifying system
parameters on time-plots within the Ptolemy software environment. This involves
systematically observing and documenting the changes in the time-plots'
characteristics as a result of editing various parameters. The goal is to gain
insights into the system's behavior under different configurations, which can be
useful for optimizing performance and enhancing overall understanding of the
software's functionality.
SOFTWARE REQUIRED:
Ptolemy II (supports various domain-specific languages and provides a user-
friendly environment for editing system parameters and observing their
effects on time-plots.)
PROCEDURE:
1. The Ptolemy software interface and its components should be familiarized with.
2. The Robot MPC system to be analyzed along with its associated time-plots should
be identified.
3. A parameter within the system for modification should be selected.
4. The chosen parameter's value or configuration should be edited,
ensuring documentation of the original and altered settings.
5. The simulation or analysis should be run with the modified parameter.
6. The resulting time-plot should be observed and compared with the original
one, noting any significant changes in characteristics such as amplitude,
frequency,
or shape.
7. Steps 3-6 should be repeated for other parameters within the system to
understand their individual effects on the time-plots.
8. The observed changes should be analyzed to draw conclusions about the
system's behavior under different parameter configurations.
9. Documentation should include the original and modified parameter values, the
observed time-plot changes, and any insights gained about the system's
performance.
10. The results should be shared with relevant stakeholders, and the gathered
information should be used to optimize the system's performance or improve
the Ptolemy software's functionality.
CIRCUIT DIAGRAM:
import
ptolemy.actor.TypedAtomicActor;
import ptolemy.actor.TypedIOPort;
import ptolemy.data.ArrayToken;
import
ptolemy.data.DoubleMatrixToken;
import ptolemy.data.DoubleToken;
import ptolemy.data.IntToken;
import ptolemy.data.RecordToken;
import ptolemy.data.StringToken;
import ptolemy.data.expr.Parameter;
import ptolemy.data.type.ArrayType;
import ptolemy.data.type.BaseType;
import
ptolemy.data.type.RecordType;
import ptolemy.data.type.Type;
import
ptolemy.kernel.CompositeEntity;
import ptolemy.kernel.util.Attribute;
import ptolemy.kernel.util.IllegalActionException;
import ptolemy.kernel.util.NameDuplicationException;
import ptolemy.math.DoubleMatrixMath;
_timeHorizon = 1;
timeHorizon = new Parameter(this, "prediction
horizon"); timeHorizon.setExpression("1");
timeHorizon.setTypeEquals(BaseType.INT);
}
public Parameter timeHorizon;
public TypedIOPort controlInput;
public TypedIOPort currentState;
public TypedIOPort predictedStates;
public TypedIOPort
jacobianOfStates; @Override
public void fire() throws IllegalActionException {
super.fire();
if (controlInput.hasToken(0)) {
ArrayToken arrayOfControl = ((ArrayToken) controlInput.get(0));
ArrayToken uArray = (ArrayToken) arrayOfControl.getElement(0);
_uValue = new double[arrayOfControl.length()]
[uArray.length()]; for (int i = 0; i < _uValue.length; i++) {
for (int it_u = 0; it_u < _uValue[0].length; it_u++) {
uArray = (ArrayToken) arrayOfControl.getElement(i);
_uValue[i][it_u] = ((DoubleToken) uArray.getElement(it_u))
.doubleValue();
}
}
}
if (currentState.hasToken(0)) {
_currentState = new double[_labels.length];
RecordToken incoming = (RecordToken)
currentState.get(0); for (int it = 0; it < _labels.length; it++) {
_currentState[it] = ((DoubleToken) incoming.get(_labels[it]))
.doubleValue();
}
}
calcPredict();
predictedStates.send(0, new
ArrayToken(_predictedStates)); DoubleMatrixToken[]
jacobianResult = new
DoubleMatrixToken[_jacobianOfStates.length];
for (int i = 0; i < jacobianResult.length; i++)
{
jacobianResult[i] = new DoubleMatrixToken(_jacobianOfStates[i]);
}
jacobianOfStates.send(0, new ArrayToken(jacobianResult));
}
@Override
public void attributeChanged(Attribute
attribute) throws IllegalActionException {
if (attribute == timeHorizon) {
_timeHorizon = ((IntToken) timeHorizon.getToken()).intValue();
}
}
private int
_timeHorizon; private
String[] _labels; private
Type[] _types;
private double[]
_currentState; private
double[][] _uValue;
private RecordToken[]
_predictedStates; private double[][][]
_jacobianOfStates;
import ptolemy.data.IntToken;
import
ptolemy.data.expr.Parameter;
import ptolemy.data.type.BaseType;
import
ptolemy.kernel.CompositeEntity;
import ptolemy.kernel.util.Attribute;
import ptolemy.kernel.util.IllegalActionException;
import ptolemy.kernel.util.NameDuplicationException;
import ptolemy.plot.Plot;
public class XYScope extends XYPlotter {
public XYScope(CompositeEntity container, String name)
throws IllegalActionException, NameDuplicationException
{ super(container, name);
persistence = new Parameter(this, "persistence", new
IntToken(100)); persistence.setTypeEquals(BaseType.INT);
}
public Parameter
persistence; @Override
public void attributeChanged(Attribute
attribute) throws IllegalActionException {
if (attribute == persistence && plot != null) {
int persValue = ((IntToken)
persistence.getToken()).intValue(); ((Plot)
plot).setPointsPersistence(persValue);
} else {
super.attributeChanged(attribute);
}
}
@Override
public void initialize() throws IllegalActionException
{ super.initialize();
import ptolemy.actor.Director;
import
ptolemy.actor.SuperdenseTimeDirector;
import ptolemy.data.Token;
import ptolemy.kernel.CompositeEntity;
import ptolemy.kernel.util.IllegalActionException;
import ptolemy.kernel.util.NameDuplicationException;
import ptolemy.kernel.util.Workspace;
output.setTypeSameAs(input);
}
@Override
public Object clone(Workspace workspace) throws CloneNotSupportedException
{ MicrostepDelay newObject = (MicrostepDelay) super.clone(workspace);
newObject.output.setTypeSameAs(newObject.input);
return newObject;
}
@Override
public void declareDelayDependency() throws IllegalActionException {
_declareDelayDependency(input, output, 0.0);
}
@Override
public void fire() throws IllegalActionException
{ super.fire();
if (_pendingOutput != null) {
output.send(0,
_pendingOutput); if
(_debugging) {
_debug("Sending output. Value = " + _pendingOutput);
}
} else {
output.send(0,
null); if
(_debugging) {
_debug("Nothing to send. Asserting absent output at time "
+ getDirector().getModelTime());
}
}
}
@Override
public void initialize() throws IllegalActionException
{ super.initialize();
_pendingOutput = null;
if (!(getDirector() instanceof SuperdenseTimeDirector))
{ throw new IllegalActionException(this,
"MicrostepDelay can only be used with a director that implements "
+ "SuperdenseTimeDirector, such as ContinuousDirector or
DEDirector.");
}
}
@Override
public boolean isStrict()
{ return false;
}
@Override
public boolean postfire() throws IllegalActionException
{ Director director = getDirector();
if (input.hasToken(0)) {
_pendingOutput = input.get(0);
director.fireAt(this,
director.getModelTime()); if (_debugging) {
_debug("Read input with value = " + _pendingOutput);
}
} else {
_pendingOutput = null;
}
return super.postfire();
}
RESULT:
The results of Robot Model Predictive Control (MPC) within the Ptolemy software
demonstrate a significant improvement in the robotic system's ability to navigate
complex environments safely. By implementing the MPC algorithm, the robots exhibit
increased adaptability and responsiveness to unexpected obstacles, effectively
avoiding collisions and maintaining smooth trajectories. This integration of MPC in
Ptolemy showcases a promising approach for enhancing the autonomy and efficiency
of robotic systems in various applications, such as manufacturing, logistics, and
exploration.
CLIP PLAYER - CAPECODE SYSTEM
AIM:
SOFTWARE REQUIRED:
Ptolemy II (supports various domain-specific languages and provides a user-
friendly environment for editing system parameters and observing their
effects on time-plots.)
PROCEDURE:
1. The Ptolemy software interface and its components should be familiarized with.
2. The Clip Player - CapeCode system to be analyzed along with its
associated time-plots should be identified.
3. A parameter within the system for modification should be selected.
4. The chosen parameter's value or configuration should be edited,
ensuring documentation of the original and altered settings.
5. The simulation or analysis should be run with the modified parameter.
6. The resulting time-plot should be observed and compared with the original
one, noting any significant changes in characteristics such as amplitude,
frequency,
or shape.
7. Steps 3-6 should be repeated for other parameters within the system to
understand their individual effects on the time-plots.
8. The observed changes should be analyzed to draw conclusions about the
system's behavior under different parameter configurations.
9. Documentation should include the original and modified parameter values, the
observed time-plot changes, and any insights gained about the system's
performance.
10. The results should be shared with relevant stakeholders, and the gathered
information should be used to optimize the system's performance or improve
the Ptolemy software's functionality.
CIRCUIT DIAGRAM:
OUTPUT SCREENSHOT:
SOURCE CODE:
"use strict";
var cameras =
require("@accessors-modules/cameras"); var camera;
var handle = null;
exports.setup = function () {
this.input('trigger');
this.output('image');
this.parameter('triggered', {
'type':
'boolean',
'value': false
});
this.parameter('maxFrameRate',
{ 'type': 'number',
'value': 25
});
this.parameter('camera',
{ 'type': 'string',
'value': 'default camera'
});
this.parameter('viewSize',
{ 'type': 'JSON'
});
try {
this.parameter('camera', {
'options':
cameras.cameras()
});
camera = new
cameras.Camera(this.getParameter('camera'));
this.parameter('viewSize', {
'value':
camera.getViewSize(),
'options': camera.viewSizes()
});
} catch (err)
{ error(err)
;
}
};
exports.initialize = function () {
camera.setViewSize(this.getParameter('viewSize'));
camera.open();
var self = this;
if (this.getParameter('triggered')) {
camera.on('snapshot', function (image)
{ self.send('image', image);
});
"use strict";
var aprilTags =
require('aprilTags'); exports.setup
= function () {
this.input('input');
this.output('output');
this.output('tags');
this.input('options', {
'type': 'JSON',
'value': ''
});
};
var handle;
exports.initialize = function ()
{ var self = this;
handle = this.addInputHandler('input', function ()
{ var options = self.get('options');
var image = self.get('input');
var result = aprilTags.filter(image,
options); self.send('output', result);
var tags =
aprilTags.tags(); if (tags) {
self.send('tags', tags);
}
});
};
exports.wrapup = function ()
{ if (handle) {
this.removeInputHandler(handle);
}
};
exports.setup = function()
{ this.input('tags');
this.input('frames');
this.output('newTag');
}
exports.initialize = function() {
var self = this; // For use inside handler
functions. var tagsSeen = [];
this.addInputHandler('frames', function() {
// Although this is triggered by frames, we are interested in
tags. var tags = this.get('tags');
if (!tags || tags.length === 0)
{ tagsSeen = [];
return;
}
var currentTags = [];
for (var i = 0; i < tags.length; i++) {
currentTags[tags[i].id] =
true; if (!tagsSeen[tags[i].id])
{
// Have not seen this tag
before. self.send('newTag',
tags[i].id);
}
}
tagsSeen = currentTags;
});
}
var handle;
exports.initialize = function ()
{ var self = this;
handle = self.addInputHandler('input', function ()
{ var options = self.get('options');
var image = self.get('input');
var result = aprilTags.filter(image,
options); self.send('output', result);
var tags =
aprilTags.tags(); if (tags) {
self.send('tags', tags);
}
});
};
exports.wrapup = function ()
{ if (handle) {
this.removeInputHandler(handle);
}
};
exports.initialize = function () {
camera.setViewSize(this.getParameter('viewSize'));
camera.open();
var self = this;
if (this.getParameter('triggered')) {
// Request a snapshot. Note the video stream might not be playing.
// An event will be generated when a snapshot is
available. camera.on('snapshot', function (image) {
self.send('image', image);
});
RESULT:
AIM:
To analyze and evaluate the impact of Fuel Tank System by modifying system
parameters on time-plots within the Ptolemy software environment. This involves
systematically observing and documenting the changes in the time-plots'
characteristics as a result of editing various parameters. The goal is to gain
insights into the system's behavior under different configurations, which can be
useful for optimizing performance and enhancing overall understanding of the
software's functionality.
SOFTWARE REQUIRED:
Ptolemy II (supports various domain-specific languages and provides a user-
friendly environment for editing system parameters and observing their
effects on time-plots.)
PROCEDURE:
1. The Ptolemy software interface and its components should be familiarized with.
2. The Fuel Tank system to be analyzed along with its associated time-plots should
be identified.
3. A parameter within the system for modification should be selected.
4. The chosen parameter's value or configuration should be edited,
ensuring documentation of the original and altered settings.
5. The simulation or analysis should be run with the modified parameter.
6. The resulting time-plot should be observed and compared with the original
one, noting any significant changes in characteristics such as amplitude,
frequency,
or shape.
7. Steps 3-6 should be repeated for other parameters within the system to
understand their individual effects on the time-plots.
8. The observed changes should be analyzed to draw conclusions about the
system's behavior under different parameter configurations.
9. Documentation should include the original and modified parameter values, the
observed time-plot changes, and any insights gained about the system's
performance.
10. The results should be shared with relevant stakeholders, and the gathered
information should be used to optimize the system's performance or improve
the Ptolemy software's functionality.
CIRCUIT DIAGRAM:
direction.addChoice("both");
direction.addChoice("falling")
;
direction.addChoice("rising");
output.setTypeAtLeast(value);
_errorTolerance = 1e-4;
errorTolerance = new Parameter(this,
"errorTolerance", new
DoubleToken(_errorTolerance));
errorTolerance.setTypeEquals(BaseType.DOUBLE);
}
public StringParameter
direction; public Parameter
errorTolerance; public Parameter
level;
public Parameter value;
public TypedIOPort output;
public TypedIOPort
trigger; @Override
public void attributeChanged(Attribute
attribute) throws IllegalActionException {
if (attribute == errorTolerance) {
double tolerance = ((DoubleToken) errorTolerance.getToken())
.doubleValue();
_errorTolerance = tolerance;
} else if (attribute == direction) {
String crossingDirections = direction.stringValue();
if (crossingDirections.equalsIgnoreCase("falling")) {
_detectFallingCrossing = true;
_detectRisingCrossing = false;
} else if (crossingDirections.equalsIgnoreCase("rising")) {
_detectFallingCrossing = false;
_detectRisingCrossing = true;
} else if (crossingDirections.equalsIgnoreCase("both")) {
_detectFallingCrossing = true;
_detectRisingCrossing = true;
} else {
throw new IllegalActionException(
"Unknown direction: " + crossingDirections);
}
} else if (attribute == level) {
_level = ((DoubleToken) level.getToken()).doubleValue();
} else {
super.attributeChanged(attribute);
}
}
@Override
public Object clone(Workspace workspace) throws CloneNotSupportedException
{ LevelCrossingDetector newObject = (LevelCrossingDetector) super.clone(
workspace);
newObject.output.setTypeAtLeast(newObject.value);
return newObject;
}
@Override
public void declareDelayDependency() throws IllegalActionException {
_declareDelayDependency(trigger, output, 0.0);
}
@Override
public void fire() throws IllegalActionException {
ContinuousDirector dir = (ContinuousDirector)
getDirector(); double currentStepSize =
dir.getCurrentStepSize();
int microstep = dir.getIndex();
_postponedOutputProduced = false;
if (_debugging) {
_debug("Called fire() at time " + dir.getModelTime()
+ " with microstep " + microstep + " and step size "
+ currentStepSize);
}
if (_lastTrigger == Double.NEGATIVE_INFINITY)
{ return;
}
_lastTrigger = _thisTrigger;
_eventMissed =
false; if (_postponed
> 0) { if
(_debugging) {
_debug("Requesting refiring at the current time.");
}
getDirector().fireAtCurrentTime(this);
}
if (_postponedOutputProduced) {
_postponedOutputProduced = false;
ContinuousDirector dir = (ContinuousDirector)
getDirector(); int microstep = dir.getIndex();
if (microstep >= _postponed) {
_postponed = 0;
}
}
return super.postfire();
}
@Override
public void preinitialize() throws IllegalActionException
{ if (!(getDirector() instanceof ContinuousDirector)) {
throw new IllegalActionException("LevelCrossingDetector can only"
+ " be used inside Continuous domain.");
}
super.preinitialize();
}
@Override
public double refinedStepSize() {
ContinuousDirector dir = (ContinuousDirector)
getDirector(); double refinedStep = dir.getCurrentStepSize();
if (_eventMissed) {
refinedStep = (Math.abs(_lastTrigger - _level)
+ _errorTolerance / 2) * dir.getCurrentStepSize()
/ Math.abs(_thisTrigger - _lastTrigger);
if (_debugging) {
_debug(getFullName() + "-- Event Missed: refine step to "
+ refinedStep);
}
_eventMissed = false;
}
return refinedStep;
}
/** Return the maximum Double value. This actor does not suggest
* or constrain the step size for the next iteration.
* @return java.Double.MAX_VALUE.
*/
@Overrid
e
public double suggestedStepSize() {
return java.lang.Double.MAX_VALUE;
}
protected double _level;
private boolean _detectRisingCrossing;
private boolean
_detectFallingCrossing; private double
_errorTolerance;
private boolean _eventMissed =
false; private double _lastTrigger;
private int _postponed;
private boolean
_postponedOutputProduced; private double
_thisTrigger;
}
disconnectGraphOnAbsentValue; public
Parameter useLocalTime;
@Override
public Object clone(Workspace workspace) throws CloneNotSupportedException
{ TimedPlotter newObject = (TimedPlotter) super.clone(workspace);
newObject._connected = new ArrayList<Boolean>();
return newObject;
}
@Override
public boolean prefire() throws IllegalActionException
{ super.prefire();
@Override
public void initialize() throws IllegalActionException
{ super.initialize();
int width = input.getWidth();
_connected.clear();
for (int i = 0; i < width; i++) {
_connected.add(true);
}
((PlotInterface) plot).markDisconnections(true);
}
@Override
public boolean postfire() throws IllegalActionException
{ double currentTimeValue;
int width = input.getWidth();
return super.postfire();
}
RESULT:
In Ptolemy, when analyzing the results of a fuel system model, the parameters can be
edited to observe their effects on the time-plots. By modifying factors such as fuel
pressure, flow rate, or temperature, one can visualize how these changes influence
the system's behavior over time. The purpose of this analysis is to identify optimal
configurations for efficient fuel management, ensuring smooth performance and
minimizing potential issues.
AIR MANAGEMENT SYSTEM
AIM:
SOFTWARE REQUIRED:
Ptolemy II (supports various domain-specific languages and provides a user-
friendly environment for editing system parameters and observing their
effects on time-plots.)
PROCEDURE:
1. The Ptolemy software interface and its components should be familiarized with.
2. The system to be analyzed along with its associated time-plots should
be identified.
3. A parameter within the system for modification should be selected.
4. The chosen parameter's value or configuration should be edited,
ensuring documentation of the original and altered settings.
5. The simulation or analysis should be run with the modified parameter.
6. The resulting time-plot should be observed and compared with the original
one, noting any significant changes in characteristics such as amplitude,
frequency,
or shape.
7. Steps 3-6 should be repeated for other parameters within the system to
understand their individual effects on the time-plots.
8. The observed changes should be analyzed to draw conclusions about the
system's behavior under different parameter configurations.
9. Documentation should include the original and modified parameter values, the
observed time-plot changes, and any insights gained about the system's
performance.
10. The results should be shared with relevant stakeholders, and the gathered
information should be used to optimize the system's performance or improve
the Ptolemy software's functionality.
CIRCUIT DIAGRAM:
STRUCTURE OF ACTORS USED:
OUTPUT SCREENSHOT:
SOURCE CODE:
package ptolemy.actor.lib;
import java.util.HashMap;
import java.util.Iterator;
import
java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import ptolemy.actor.IOPort; import
ptolemy.actor.TypedAtomicActor; import ptolemy.actor.TypedIOPort;
import ptolemy.data.DoubleToken; import ptolemy.data.IntToken;
import ptolemy.data.Token;
import ptolemy.data.expr.ASTPtRootNode; import
ptolemy.data.expr.ModelScope; import ptolemy.data.expr.ParseTreeEvaluator;
import ptolemy.data.expr.ParseTreeFreeVariableCollector;
import ptolemy.data.expr.ParseTreeTypeInference; import
ptolemy.data.expr. PtParser;
import ptolemy.data.expr.Variable; import ptolemy.data.type.BaseType;
import ptolemy.data.type.MonotonicFunction; import ptolemy.data.type.Type;
import ptolemy.data.type.TypeConstant; import
ptolemy.graph.InequalityTerm; import ptolemy.kernel.CompositeEntity;
import ptolemy.kernel.util.Attribute; import
ptolemy.kernel.util.IllegalActionException;
import ptolemy.kernel.util.NameDuplicationException;
import ptolemy.kernel.util.Settable;
import
ptolemy.kernel.util.StringAttribute;
import ptolemy.kernel.util.Workspace;
public class Expression extends TypedAtomicActor {
public Expression(CompositeEntity container, String
name)
throws NameDuplicationException, IllegalActionException
{ super(container, name);
_setOutputTypeConstraint();
}
@Override
public Object clone(Workspace workspace) throws CloneNotSupportedException
{ Expression newObject = (Expression) super.clone(workspace );
newObject.expression.copy(this.expression);
return newObject;
}
output.setTypeEquals(outputType);
}
if (expressionString.startsWith("_hide") || expressionString.isEmpty()) {
_parseTree =
null; return;
}
_collectFreeVariables(_freeVariables, expressionString);
Type inferredType = _inferType(expressionString);
if (inferredType instanceof TypeConstant) {
_parseTree = new ASTPtRootNode(expressionString);
_parseTree.setType(_getConstantType(inferredType));
} else {
PtParser parser = new
PtParser(expressionString);
parser.setTypeInference(inferredType);
_parseTree = parser.parse();
}
}
@Override
public void init() throws Exception
{ super.init();
_parseExpression();
}
@Override
public synchronized void fire() throws RuntimeException
{ if (_parseTree == null) {
output.send(0, new
DoubleToken(0)); return;
}
RESULT:
In Ptolemy, the results of the Air Management System can be observed by analyzing
the time-plots after editing specific parameters. By modifying these parameters, the
system's performance, efficiency, and responsiveness may change. Key observations
to note include variations in response time, resource allocation, and overall system
stability. The results can provide valuable insights for fine-tuning the Air Management
System, ultimately leading to improved performance and better management of
resources within the software.
COLLISION AVOIDANCE SYSTEM
AIM:
SOFTWARE REQUIRED:
Ptolemy II (supports various domain-specific languages and provides a user-
friendly environment for editing system parameters and observing their
effects on time-plots.)
PROCEDURE:
1. The Ptolemy software interface and its components should be familiarized with.
2. The Collision Avoidance system to be analyzed along with its associated time-
plots should be
identified.
3. A parameter within the system for modification should be selected.
4. The chosen parameter's value or configuration should be edited,
ensuring documentation of the original and altered settings.
5. The simulation or analysis should be run with the modified parameter.
6. The resulting time-plot should be observed and compared with the original
one, noting any significant changes in characteristics such as amplitude,
frequency,
or shape.
7. Steps 3-6 should be repeated for other parameters within the system to
understand their individual effects on the time-plots.
8. The observed changes should be analyzed to draw conclusions about the
system's behavior under different parameter configurations.
9. Documentation should include the original and modified parameter values, the
observed time-plot changes, and any insights gained about the system's
performance.
10. The results should be shared with relevant stakeholders, and the gathered
information should be used to optimize the system's performance or improve
the Ptolemy software's functionality.
CIRCUIT DIAGRAM:
import ptolemy.actor.Director;
import
ptolemy.actor.SuperdenseTimeDirector;
import ptolemy.data.Token;
import ptolemy.kernel.CompositeEntity;
import ptolemy.kernel.util.IllegalActionException;
import ptolemy.kernel.util.NameDuplicationException;
import ptolemy.kernel.util.Workspace;
output.setTypeSameAs(input);
}
@Override
public Object clone(Workspace workspace) throws CloneNotSupportedException
{ MicrostepDelay newObject = (MicrostepDelay) super.clone(workspace);
newObject.output.setTypeSameAs(newObject.input);
return newObject;
}
@Override
public void declareDelayDependency() throws IllegalActionException {
_declareDelayDependency(input, output, 0.0);
}
@Override
public void fire() throws IllegalActionException
{ super.fire();
if (_pendingOutput != null) {
output.send(0,
_pendingOutput); if
(_debugging) {
_debug("Sending output. Value = " + _pendingOutput);
}
} else {
output.send(0,
null); if
(_debugging) {
_debug("Nothing to send. Asserting absent output at time "
+ getDirector().getModelTime());
}
}
}
@Override
public void initialize() throws IllegalActionException
{ super.initialize();
_pendingOutput = null;
import
ptolemy.actor.TypedAtomicActor;
import ptolemy.actor.TypedIOPort;
import ptolemy.data.ArrayToken;
import
ptolemy.data.DoubleMatrixToken;
import ptolemy.data.DoubleToken;
import ptolemy.data.IntToken;
import ptolemy.data.RecordToken;
import ptolemy.data.StringToken;
import ptolemy.data.expr.Parameter;
import
ptolemy.data.type.ArrayType;
import ptolemy.data.type.BaseType;
import
ptolemy.data.type.RecordType;
import ptolemy.data.type.Type;
import
ptolemy.kernel.CompositeEntity;
import ptolemy.kernel.util.Attribute;
import ptolemy.kernel.util.IllegalActionException;
import ptolemy.kernel.util.NameDuplicationException;
import ptolemy.math.DoubleMatrixMath;
_timeHorizon = 1;
timeHorizon = new Parameter(this, "prediction
horizon"); timeHorizon.setExpression("1");
timeHorizon.setTypeEquals(BaseType.INT);
}
public Parameter timeHorizon;
public TypedIOPort controlInput;
public TypedIOPort currentState;
public TypedIOPort predictedStates;
public TypedIOPort
jacobianOfStates; @Override
public void fire() throws IllegalActionException {
super.fire();
if (controlInput.hasToken(0)) {
ArrayToken arrayOfControl = ((ArrayToken) controlInput.get(0));
ArrayToken uArray = (ArrayToken) arrayOfControl.getElement(0);
_uValue = new double[arrayOfControl.length()]
[uArray.length()]; for (int i = 0; i < _uValue.length; i++) {
for (int it_u = 0; it_u < _uValue[0].length; it_u++) {
uArray = (ArrayToken) arrayOfControl.getElement(i);
_uValue[i][it_u] = ((DoubleToken) uArray.getElement(it_u))
.doubleValue();
}
}
}
if (currentState.hasToken(0)) {
_currentState = new double[_labels.length];
RecordToken incoming = (RecordToken)
currentState.get(0); for (int it = 0; it < _labels.length; it++) {
_currentState[it] = ((DoubleToken) incoming.get(_labels[it]))
.doubleValue();
}
}
calcPredict();
predictedStates.send(0, new
ArrayToken(_predictedStates)); DoubleMatrixToken[]
jacobianResult = new
DoubleMatrixToken[_jacobianOfStates.length];
for (int i = 0; i < jacobianResult.length; i++)
{
jacobianResult[i] = new DoubleMatrixToken(_jacobianOfStates[i]);
}
jacobianOfStates.send(0, new ArrayToken(jacobianResult));
}
@Override
public void attributeChanged(Attribute
attribute) throws IllegalActionException {
if (attribute == timeHorizon) {
_timeHorizon = ((IntToken) timeHorizon.getToken()).intValue();
}
}
private int
_timeHorizon; private
String[] _labels; private
Type[] _types;
private double[]
_currentState; private
double[][] _uValue;
private RecordToken[]
_predictedStates; private double[][][]
_jacobianOfStates;
package ptolemy.actor.lib;
import ptolemy.actor.Director;
import
ptolemy.actor.SuperdenseTimeDirector;
import ptolemy.data.Token;
import ptolemy.kernel.CompositeEntity;
import ptolemy.kernel.util.IllegalActionException;
import ptolemy.kernel.util.NameDuplicationException;
import ptolemy.kernel.util.Workspace;
output.setTypeSameAs(input);
}
@Override
public Object clone(Workspace workspace) throws CloneNotSupportedException
{ MicrostepDelay newObject = (MicrostepDelay) super.clone(workspace);
newObject.output.setTypeSameAs(newObject.input);
return newObject;
}
@Override
public void declareDelayDependency() throws IllegalActionException {
_declareDelayDependency(input, output, 0.0);
}
@Override
public void fire() throws IllegalActionException
{ super.fire();
if (_pendingOutput != null) {
output.send(0,
_pendingOutput); if
(_debugging) {
_debug("Sending output. Value = " + _pendingOutput);
}
} else {
output.send(0,
null); if
(_debugging) {
_debug("Nothing to send. Asserting absent output at time "
+ getDirector().getModelTime());
}
}
}
@Override
public void initialize() throws IllegalActionException
{ super.initialize();
_pendingOutput = null;
@Override
public boolean isStrict()
{ return false;
}
@Override
public boolean postfire() throws IllegalActionException
{ Director director = getDirector();
if (input.hasToken(0)) {
_pendingOutput = input.get(0);
director.fireAt(this,
director.getModelTime()); if (_debugging) {
_debug("Read input with value = " + _pendingOutput);
}
} else {
_pendingOutput = null;
}
return super.postfire();
}
RESULT: