Editor: Asynchronous Software Loop
Description
By default, all components are ticked with the same frequency. There is no current way to put certain components on a different thread and tick at a different interval than the simulation. Although this makes for a simple system, it means developing custom ADCS loops for attitude control to be trickier. Realistic spacecraft have flight software that runs at a different interval than the sensor reading and a default simulation in Nominal Editor will not allow for alternative ticking times.
This tutorial will show how to enable and disable software components based on a separate Unreal interval. This example will use the Demo_HeadingEstimation
level as a base for adding the custom login in Blueprints and will attempt to put the flight software on an update loop that has a larger interval than the sensor loop attached to the simulation. The full level can be found in Demos/Events/Demo_ADCSSoftwareLoop
.
To make it easier to see what has changed, the Demo_HeadingEstimation
level has been copied and any changes that were made to get the flight software to work properly have been coloured in orange. This document will break down each of the steps for the changes in this scenario.
Custom Event Binding
The Unreal tick is called every Unreal frame and is used to update the objects within the level and call the simulation to tick. However, this is decoupled from the actual simulation tick and can result in the Unreal frame being called less frequently than the simulation (if the simulation is ticked >1 time per frame). It is possible to bind an event to the OnSimulationTick
delegate which allows for a blueprint event to be called every time the simulation ticks. It is here we will perform the custom event loop.
This is done on the Event Begin Play
event and the Bind Event to Simulation Tick Delegate
is found on the Simulation System
.
The step to creating an event is a bit more advanced. This code was done with the following steps:
- Get the simulation subsystem from the Level Blueprint
- Call the method
Bind Event to Simulation Tick Delegate
- Drag the red cube out and find
Create Event
- Under the drop-down, select
Create a Matching Event
Creating an Array
For this system, a list of all flight software on the computer must be stored in an array to make it easier to loop over all of the software nodes. This is done just by constructing a new array of type Software Component
and adding all of the flight software that was added in the Configure Software
function. In this example, there are 5 flight software modules on the spacecraft, but this may depend on the simulation demonstration.
Updating the Software
For a custom flight software loop, the idea is to disable the flight software from running its OnUpdate
function in the simulation until the appropriate frequency time is reached. To help demonstrate this, this example assumes that the flight software should update its output messages every 10 seconds. This is an extreme example. The software itself can be disabled by getting the Mono Object
from the software object and setting the Is Enabled
flag to false.
The code above is called every time the simulation is ticked (not to be confused with the Unreal level tick). This function will loop through all of the flight software components and disable or enable the Update call (by setting the IsEnabled
flag) based on whether the update time has been met. The Software Update Delta
is the time in seconds that represents the time-step between update calls on the computer.
Result
The result of this level is flight software that runs at a different interval than the sensor data. This system is a workaround and should be treated as a demonstration rather than a fully functioning feature.
Warning
This functionality will only work when the software is running on a smaller frequency loop. For larger frequencies of ticking, alternative and more creative solutions may be required.