Mapping values to text or images
3 minute read
Many parameters hold a number that stands for something: a state, a mode, an error code. A map file turns that number into a name the operator understands, or into a picture. You write the map once, as a JSON file in your GRID package, and select it in each widget that should use it.
How a map works
A widget with a map looks up the parameter’s value in the file and shows the name it finds. A Dropdown works the other way round as well: it lists every name in the map, and when you pick one it writes that name’s number to the parameter.
Maps work in these places:
| Where | What it maps |
|---|---|
| Output widget, map property | The value to a name |
| Dropdown widget, map property | The names to choose from, and the number each one writes |
| Image widget, map property | The value to an image file |
| Error codes in the Errors settings | Error numbers to error names |
| state codes in the States settings | State numbers to state names |
Create a map file
- In your GRID package on motorcortex.io, create a file with the extension
.json. The stock packages keep their maps in aconfig/folder. - Open the file and write one entry per value. The key is the number, as a string in quotes; each key appears only once. The value is the name to show.
- Save the file.
- In Grid, select the widget, click select next to its map property and pick the file.
This map from a stock robot interface names the homing methods of an axis. The numbers are those of the homing block in the control library:
{
"0": "By-Pass",
"1": "Direct Reference",
"2": "Move till Trigger",
"3": "Move till no Trigger",
"4": "Move till no Trigger, Reverse Move till Trigger",
"5": "Move till Trigger, Reverse Move till no Trigger",
"6": "Manual Jog till Trigger"
}
For an Image widget, each value is the path of an image in the package:
{
"0": "img/image01.png",
"1": "img/image02.png",
"2": "img/image03.png"
}
Leave out the comma after the last entry: JSON does not allow it.
Use one map for many widgets
A map file is not tied to one widget. The stock robot interface shows the error code of each of its six drives with one map, config/somanet_drive_errors.json: six Output widgets use the same map, each with its own prefix, such as root/Ethercat/Robot/Axis1/, in front of the same path SDOs/Error Code.