Master JSON Files - SpartanHyperloop3/main GitHub Wiki
State Data
The state data JSON file relates combinations of state variables to next state transitions. The initial keys are the current state with exception of the "all" key, which takes precedence over current state logic, and exists to simplify the JSON file by allowing logic that would otherwise have to repeatedly listed under each key to be written only once.
Ex 1. "all" state logic with one state transition by one state variable.
{
"all" : [
[ 13,
[
{
"battery_A_current" : 1
}
]
]
]
}
Here, "all"
signifies that these state variables and their corresponding transitions should be checked for all current states.
The first list after all holds lists of state transitions and their corresponding logic.
The second list has to values, first the number of the state to transition to if the logic is found true ([ 13,
in the example above is the state to transition to if battery_A_current is found to be true)
The third list contains dictionaries of state variables and the conditions for them to be considered true (either 1 or 0). In the example above only one state variable is listed in the dictionary, but it is also possible to add more state variables.
Adding more state variables to the dictionary signifies an AND condition, where each of the variables must be found to be true together for the state transition to take place.
Ex 2. state transition with an AND condition for two state variables
{
"all" : [
[ 13,
[
{
"battery_A_current" : 1,
"battery_A_temp" : 1
}
]
]
]
}
An OR condition can be created by adding another dictionary to the list.
Ex 3. state transition with an OR condition for two state variables
{
"all" : [
[ 13,
[
{
"battery_A_current" : 1,
},
{
"battery_A_temp" : 1
}
]
]
]
}
Any amount of objects can be added for both AND and OR cases.
Ex 4. Adding additional state transitions
{
"all" : [
[ 13,
[
{
"battery_A_current" : 1,
},
{
"battery_A_temp" : 1
}
]
],
[ 54,
[
{
"manual_mode_activated" : 1
}
]
]
]
}
Additional possible state transitions are added within the first list.
Ex 5. Current state transitions
"3" : [
[ 16,
[
{
"manual_enter_state_16_ready_2" : 1
}
]
]
],
Current state transitions have the same form as noted above, but are evaluated after the "all" possibilities. The key, "3"
in the example, is the current state of the state machine, and [ 16,
is the next possible state when manual_enter_state_16_read_2
is found true. Only possibilities that correspond to the current state are evaluated.
Input Logic
The input logic JSON file associates incoming sensor data to a logical evaluation. The logical evaluation sets a Boolean value to a corresponding state variable, which is used in the state data JSON file. This allows sensor data to individually, or be combined, to characterize the current state of a system, which is denoted by the state variable.
Ex 1. A state variable is assigned an incoming Boolean value
{
"Emergency_Override": [
0,
{
"raw_data_names": {
"Emergency_Override": {
"digital": 1,
"params": null,
"raw_data_units": "bool",
"typeOfLogic": "boolean"
}
},
}
]
The initial keys in the JSON file signify state variables. The value for the state variable contains a list with the first element being the state that variable is initialized to. The second element contains a dictionary with information on the sensor input and type of logical evaluation.
The dictionary should contains two keys: "raw_data_names"
and "typeOfLogic"
. The type of logic that can be associated to a state variable is as follows:
typeOfLogic | Explanation |
---|---|
time_diff | Performs a timing check by evaluating the amount of time passed in the current state |
boolean | Performs no operation and takes the incoming Boolean value as-is |
range | evaluates if the incoming value is out side of a specified range |
raw_data_names contains a dictionary of sensor names held in the global data storage. All sensor names listed here will be parsed and automatically added to the global data storage. Each sensor name contains a dictionary of metadata that is used to identify the type of data that is being received. The following table relates valid keys within the sensor name dictionary to their corresponding function:
Key | Function |
---|---|
digital | 1 for digital source 0 for analog, optional metadata |
params | Used by the logical evaluation functions such as range |
raw_data_units | Identifies the units of the data |
The "params"
key should contain a list of values depending on the type of logic denoted, or null
for incoming values that are already Boolean values.
params | typeOfLogic |
---|---|
range | a [] contain the lower and upper bounds; eg. [0.0,1.0] |
boolean | null |
time_diff | a [] should contain the name of the variable in which the start time is store. All start times are store in memory in the form state_[state number]_start_time , and a max time in seconds. Eg. ["state_1_start_time", 120] sets a maximum time of two minutes for state 1 |
Ex 2. A state variable with a incoming data evaluated by range logic
"battery_A_current": [
0,
{
"raw_data_names": {
"PI_1_U1_CH1": {
"digital": 0,
"params": [
0.0,
1.0
],
"raw_data_units": "volts",
"typeOfLogic": "range"
}
},
}
]
}
Ex 3. Multiple sensor values combined into one state variable
"battery_A_current": [
0,
{
"raw_data_names": {
"PI_1_U1_CH1": {
"digital": 0,
"params": [
0.0,
1.0
],
"raw_data_units": "volts",
"typeOfLogic": "range"
},
"PI_1_U1_CH2": {
"digital": 0,
"params": [
0.0,
1.0
],
"raw_data_units": "volts",
"typeOfLogic": "range"
}
},
}
]
}
When multiple sensors are evaluated for one state variable OR logic is used, meaning only one needs to be evaluated true for the state variable to be true.