Quick Start Part 3¶
Temperature Display Requirements:
- The Temperature Display shall have two temperature sensors, one outside sensor and one inside sensor, which read temperatures in Celsius as 32-bit floating point values.
- The display shall sample the sensor data and update every 100 milliseconds.
- The temperature °F shall be calculated from the temperature °C with the following equation: °F = °C × 9/5 + 32
- For each sensor the display shall indicate Sensor Broken if the temperature is greater than 150°F or less than -150°F.
All the software logic for a single sensor is now modeled, but requirement #1 specifies that there is both an indoor and an outdoor sensor. Ideally, the logic we modeled can be reused between the two sensors. CertSAFE makes this sort of reuse within a project very easy.
Just like in part 2, you can achieve this by using either a diagram or a stitch. In this case, both work well. However, when dealing with many variables or many instances, stitches may be easier to work with than diagrams. We’ll focus on doing this with diagrams first, then show how this can be done with stitches.
Reuse in diagrams¶
As a diagram, you could model the first requirement like this:
To model the above, start by creating a new diagram. Then go to the Projects view and drag the Process Sensor Data stitch from part 2 into the new diagram as a component. Repeat this one more time (or copy the component using right-click-and-drag) to get a second Process Sensor Data component. Then, connect the components up to different diagram inputs and outputs. You should give the indoor and outdoor copies distinct I/O names since the sensors are independent and can record different values.
Reuse in stitches¶
Let’s try building the same structure in a stitch. Create a new stitch and drag the Process Sensor Data stitch from the Projects view to the left-hand pane of the new stitch editor. Repeat this again to create two child units of type Process Sensor Data, as in the image below:
The stitch editor groups multiple child units of the same type together in the left-hand table. Notice that CertSAFE automatically appended a string of hexadecimal characters after the name. To differentiate the two definitions from each other, CertSAFE needs an unique identifier, called a child name. Every child unit in a diagram or stitch definition has a child name. If you have not assigned a child name to a child unit, CertSAFE will give that unit a default child name and append a hexadecimal number to the end of that child name that is unique within the parent diagram or stitch. CertSAFE will also append the unique hexadecimal number to the end of any child unit that shares a child name with anything else in the parent diagram or stitch. Setting an explicit child name yourself on a component isn’t necessary, but doing so can help clarify the structure of a model to other readers and make navigating the model easier.
In a diagram, you can change a component’s child name by selecting the component and editing the “Child name” property in the Properties view. In a stitch, you can change a child unit’s name by double-clicking on the name in the left-hand pane of the stitch editor. (Remember, child units are represented in the left-hand pane as rows with a blue background.) For this example, you can rename the child Process Sensor Data units to “Process Indoor Data” and “Process Outdoor Data” to help keep them straight.
Recall that there are two types of rows in the right-hand table: the top-level names with a light blue background, and the second-level entries with a white background. The top-level entries are variable names in the stitch itself. These are analogous to exported and non-exported names in diagrams, which is why these are the rows we have to mark as exported names of the stitch. The second-level entries are names of child I/Os, represented as (child name) ● (I/O name).
As we saw in part 2, the stitch editor automatically connects together child I/Os that have the same name by mapping them to a stitch-level variable with that name. In this case, CertSAFE has mapped both of the two °C inputs of the Process Sensor Data instances to “°C” and both of the two Sensor Broken outputs to “Sensor Broken”, which is not what we want. To create the desired connections in your stitch, you will need to use custom name mapping, specifying the new variable names and remapping the Process Sensor Data I/Os explicitly.
In our diagram above, we made up names like “°C Indoor” so that we had distinct identifiers for the inputs and outputs of the two sensors. You will want to do the same thing in your stitch. You can add a new variable name to your stitch by clicking the Add Var button at the bottom-right of the stitch editor and typing in a name. If you don’t see the Add Var button, try adjusting the width of the stitch editor window by making it wider.
Do this for each of the four I/Os, and mark them as Exported Names through the Properties view. Remember that you can copy symbols like “°C” from the requirements text or from other places in your project if you don’t want to look up how to type them. Also remember that you can select multiple variables at once to change all of them to Exported Names.
At this point, you have all the variables ready, but nothing is actually connected correctly. Your stitch should look like this:
Stitch variables shown in black are explicitly declared in the file on disk, while variables shown in gray only exist because some child I/O is mapped to them. Child I/Os shown in black are explicitly mapped to a custom name, while child I/Os shown in gray are automatically mapped to their default name. This helps you keep track of which parts of the stitch will need to be updated if other files in the project change.
To remap a child I/O to be connected to a different stitch variable, select the child I/O in the right-hand table and drag it over the stitch variable you want to map it to. For example, you will want to drag Process Indoor Data ● Sensor Broken onto Sensor Broken Indoor. Remember, stitch variables have a blue background, and child I/Os have a white background. The final stitch should look like this:
Save the stitch under the name “Process All Sensors”.
In instance mode, rather than displaying the name of a variable in a definition of a diagram, CertSAFE will show a canonical name based on what the variable is connected to. For example, the indoor instance of the Temperature Conversion diagram is displayed like this:
Instead of “°C”, CertSAFE now shows the input as “°C Indoor”, which is the name from the stitch you created earlier in this tutorial. This helps you keep track of where values are coming from and going to. The name shown for °F does not change because we have not given a more specific name for the variable at a higher level in the instance hierarchy.
Also, the °C variable is displayed as blue because it is an input to the current root. °F is still shown as black because it is not an input or output of the current root, but merely an intermediate value used in a later computational step.
Now that you know how to view different diagram instances, try making a simulation with different inputs for the indoor and outdoor instances, like the one shown below:
You can see that the model is generally working correctly, but what if we want more information on how the values are being calculated? CertSAFE can help by displaying intermediate computation steps in the form of probes.
When you have a diagram open in instance mode and you are looking at a simulation, you can see probes in the diagram that show you the values at each intermediate point.
The values shown in the probes are based on the current location of the time cursor in the last simulation editor you clicked on. You can move the time cursor back and forth to see the values at different points in time. (You have to move the diagram and simulation editors side-by-side to see this, or lock the time cursor and switch between the two tabs.) Different instances of a diagram will show different probe values too, of course, since they represent independent subsystems with their own inputs and outputs. In this case, you should be able to switch between the indoor and outdoor instances of your diagrams using the breadcrumbs bar or Instance view and see different values at each step of the computation.
If the probes are getting in the way of seeing logic in your diagrams, they can be disabled. At the bottom of the screen is the Fast Options Bar. This bar contains numerous settings that can quickly change the display of your project in CertSAFE. The third button from the left controls whether probes are displayed or not. It also has a drop-down menu which lets you select how the values in the probes are displayed, and a text box that lets you change the displayed precision when showing floating-point values in decimal. For more information about this feature, and other options in the Fast Options Bar, see the Fast Options Bar documentation.
None of the buttons in the Fast Options Bar affect the functionality of your model - they only change how you interact with the CertSAFE software. You can mouse over any of the controls in the Fast Options Bar to get a pop-up tooltip with a short description of what that control does.
This quick start guide gave a brief look at some of the most commonly-used features of CertSAFE. For more information on specific features, you can browse through the other articles listed in the sidebar. You can also take a look at the Glossary for a summary of the terminology used in the CertSAFE user interface with links to more information.