Skip to content

Commit

Permalink
Reorganize visualization service and update documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
clagms committed Nov 22, 2023
1 parent b9ad2e9 commit 9c7bd74
Show file tree
Hide file tree
Showing 29 changed files with 68 additions and 65 deletions.
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ The DT follows a service based architecture, with different services communicati
Each service is started with a python script, and most services refer to [software/startup.conf](software/startup.conf) for their configuration.

The code that starts the services is in [software/startup](software/startup).
It is possible to start all services from the same script [software/startup/start_all_services.py](software/startup/start_all_services.py) or each service individually.
It is possible to start all services (except the 3D visualization service) from the same script [software/startup/start_all_services.py](software/startup/start_all_services.py) or each service individually.

The services (and their starting scripts) currently implemented are:
- [incubator_realtime_mockup](software/startup/start_incubator_realtime_mockup.py) -- implements a real time plant simulation mockup so that the whole digital twin system can be run locally on any computer without the need to connect to an external physical twin. When using a real physical twin this service is not started.
Expand All @@ -200,6 +200,7 @@ The services (and their starting scripts) currently implemented are:
- [controller_physical](software/startup/start_controller_physical.py) -- this service implements the controller.
- [supervisor](software/startup/start_supervisor.py) -- This service can periodically retune the controller.
- [self_adaptation_manager](software/startup/start_self_adaptation_manager.py) -- the service implements the self-adaptation which checks whether the physical characteristics of the plant have changed and can trigger a recalibration as well as controller tuning when that happens.
- [3d_visualization](software/digital_twin/visualization/project.godot) -- This service is a [Godot](https://godotengine.org/) project that shows a 3D rendering of the incubator.

## System Architecture

Expand Down Expand Up @@ -309,18 +310,22 @@ Make sure you can successfully [start the DT framework](#after-first-time-setup-
The script [run_integration_tests.ps1](./software/run_integration_tests.ps1) contains the instructions.

# Start visualization
1. Open Godot

2. Click Import (or press Ctrl+I)
We assume the reader is broadly familiar with [Godot](https://godotengine.org/) engine.

3. Insert the project path to the visualization folder (C:[YOUR PATH]\visualization), and click "Import and Edit"

4. Build and run the project by clicking on the "play" button in the top-right corner (or press F5).

If the application crashes when opening the project, it is due to the GPU not supporting the Vulkan rendering API. Instead open a terminal and run the following command:
1. Download and install Godot v4.1.1.stable.mono.official [bd6af8e0e]
2. Open [project.godot](software/digital_twin/visualization/project.godot) with Godot engine.
3. The UI should look like:
![](figures/godot_gui.png)
4. Make sure the RabbitMQ server is runnning.
5. Build and run the project by clicking on the "play" button in the top-right corner (or press F5). If the application crashes when opening the project, it could be due to:
1. Connection from Godot to Rabbitmq server failed (check the Errors tab in Godot UI).
2. You GPU does not support the Vulkan rendering API. Open a terminal and run the following command:
```
C:\path\to\your\godot4.exe --rendering-driver opengl3.
```
6. The result should look like this:
![](figures/example_incubator_visualization.png)

# Diagnosing Startup Errors

Expand Down Expand Up @@ -482,7 +487,7 @@ General guidelines:
The [software](software) directory contains all things code related.
- [cli](./software/cli) -- Contains code to communicate with the running DT components.
- [digital_twin](./software/digital_twin) -- Code that forms the digital twin.
- [digital_twin](./software/digital_twin) -- Code that forms the digital twin services.
- [incubator](./software/incubator) -- Code that implements the physical twin, models, and datasets
- [integration_tests](./software/integration_tests) -- Code to run integration tests.
- [mock_plant](./software/mock_plant) -- Code setting up the local virtual incubator plant.
Expand Down
Binary file added figures/example_incubator_visualization.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figures/godot_gui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
54 changes: 54 additions & 0 deletions software/digital_twin/visualization/scripts/RBConnection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Godot;
using System;
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
using System.Text;
using System.Collections.Generic;

public partial class RBConnection : Node3D {
private ConnectionFactory factory = new ConnectionFactory() {
Uri = new Uri("amqp://incubator:incubator@localhost:5672")
};
private IConnection connection;
private IModel channel;

private string localQueue;
private string exchangeName = "Incubator_AMQP";
private string ROUTING_KEY_KF_PLANT_STATE = "incubator.record.kalmanfilter.plant.state";
private string ROUTING_KEY_STATE = "incubator.record.driver.state";
private List<string> messages = new();

[Signal]
public delegate void MessageEventHandler(string message);

public override void _Ready() {
connection = factory.CreateConnection();
channel = connection.CreateModel();
GD.Print("Connection created");

localQueue = channel.QueueDeclare(autoDelete: true, exclusive: true);
channel.QueueBind(queue: localQueue, exchange: exchangeName, routingKey: ROUTING_KEY_KF_PLANT_STATE);
channel.QueueBind(queue: localQueue, exchange: exchangeName, routingKey: ROUTING_KEY_STATE);
ReceiveMessage();
}

public override void _Process(double delta) {
for (int i = 0; i < messages.Count; i++) {
EmitSignal(SignalName.Message, messages[i]);
}
messages.Clear();
}

private void ReceiveMessage() {
GD.Print("Waiting for messages");
var consumer = new EventingBasicConsumer(channel);

consumer.Received += (model, ea) => {
var body = ea.Body.ToArray();
var message = Encoding.ASCII.GetString(body);
messages.Add(message);
};

channel.BasicConsume(queue: localQueue, autoAck: true, consumer: consumer);
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 0 additions & 2 deletions visualization/.gitattributes

This file was deleted.

54 changes: 0 additions & 54 deletions visualization/scripts/RBConnection.cs

This file was deleted.

0 comments on commit 9c7bd74

Please sign in to comment.