Passing Messages
In the SWARM RDS Platform, there are mechanisms to pass information between different modules in the system. This enables you to, for example, send messages to other agents, or to the SWARM RDS system itself. This is done through the Publish and Subscribe mechanism, which is a common way to pass information in distributed systems.
These mechanisms are fully automated, meaning you don't have to have any extra code to publish or subscribe to different data sources. You simply update your module configuration in the RDS Client, describing what data you want to subscribe or publish to.
There are limitations to what type of data you can publish, however. Currently, the only data types are the SWARM Data types as defined in the SWARM RDS Platform. These data types ensure that information is in the correct format when you receive it for your algorithm.
Subscribing to Data
To start, you need to know what data sources are available to you. The following are the default data sources you can utilize in the SWARM RDS Platform:
- AgentState - The current state of the Agent.
- MovementCommand - A position, velocity, or acceleration command (or some combo of all three).
- Image - A 3-channel (or 1-channel) image from a camera. Subscription occurs by using the Camera's unique name.
- SWARMPointCloud - A list of points received from a LiDAR sensor, with associated Metadata.
- OccupancyMap - A 3-D numpy matrix describing the sensed environment.
- Message - A JSON-based message that can contain arbirtary Python-specific data.
To subscribe to the data source listed above, you need to do the following:
Step 1: RDS ClientIn the RDS Client, on the Software Modules page for your agent, you will see a dropdown called "Subscribe". Choose the data source and click "Add". This will add the data source to the module.
Cameras, LiDARs and Sensors
For sensors that have a unique name (ex. Camera1), you will need to specify the name of the sensor in the subscription. when you click on the dropdown, you should see the sensor name for all cameras or LiDARs that you can subscribe to. This is NOT what you will use to get the data in your algorithm, however!
Now that you have told the system what to subscribe to, you need to ensure that you can get that data in your algorithm. The SWARM RDS Client will automatically create a message queue for your Module and subscribe to that data. All you need to do is in the arguements of the run function of your algorithm, add the proper name of the Data type you are subcribing to. For example, if you are subscribing to the AgentState, you would add the following to your run function:
Be aware that it is possible for the AgentState variable to be None if the agent is not yet initialized. You should check for this in your code.
Please remember that for sensors, you need to specify the data type: Image for Camera or SWARMPointCloud for LiDAR. The name of the sensor is not used in your code. If you subscribe to multiple images or point clouds, you would use the following: Image1, Image2, etc. but ONLY if you subscribe to two or more cameras, LiDARs, etc.
Publishing Data
Publishing data is just as simple as subscribing to data. The following are the default data sources you can publish to in the SWARM RDS Platform:
- MovementCommand - A position, velocity, or acceleration command (or some combo of all three).
- Message - A JSON-based message that can contain arbirtary Python-specific data.
To publish to the data source listed above, you need to do the following:
Step 1: Your CodeFor your algorithm, return the data you want to publish in the run function. For example, if you want to publish a MovementCommand, you would return the MovementCommand data type with the fields filled out. It is always possible to publish None if you don't have any data to publish.
Step 2: RDS ClientUsing the RDS Client, on the Software Modules page for your agent, you will see a dropdown called "Publish". Choose the data source and click "Add". You will see the data types available to publish.
Returning Arguemnents Order
The order you return the data in is critical! Ensure that you return the list properly and that the order in which you add the data in the "Publish" section of your model matches the order you return the data in your algorithm.