ami-iit / yarp-openmct

Repo for YARP and OpenMCT integration.
BSD 3-Clause "New" or "Revised" License
6 stars 1 forks source link

9: The Camera view in the visualizer has a very poor performance compared to the real cameras output #71

Open nunoguedelha opened 2 years ago

nunoguedelha commented 2 years ago

Camera view In the visualizer has a very poor performance: pixelation, degraded resolution, color shift (e.g blue->red), delayed input (1min).

nunoguedelha commented 2 years ago

In addition, in some tests the image is occasionally flickering. Refer to https://github.com/ami-iit/component_ANA-Avatar-XPRIZE/issues/403.

nunoguedelha commented 2 years ago

At some point we suspected that the line scattering observed in the fake-framegrabber rendering was due to the simultaneous display of multiple frames, and thus related to the Historical requests (refer to this documentation section). This seems now to be a wrong lead, as we can see in the screenshot below that even a single frame includes multiple lines instead of a singe one for the fake framegrabber.

image
nunoguedelha commented 2 years ago

CC @traversaro @RiccardoGrieco

nunoguedelha commented 2 years ago

Logging the received image data on a yarp port

We publish the image data received through the plugin RealtimeTelemetryPlugin on a Yarp port /yarpjs/cameraEcho:o of type bottle.

For this we added the support of socket.io and yarp.js features in the visualizer plugin installation page:

https://github.com/ami-iit/yarp-openmct/blob/3d6105dc8efc7de4eefeef9ed27feba60bc21eba/openmctStaticServer/index.html#L12-L13

https://github.com/ami-iit/yarp-openmct/blob/3d6105dc8efc7de4eefeef9ed27feba60bc21eba/openmctStaticServer/index.html#L28-L33

https://github.com/ami-iit/yarp-openmct/blob/3d6105dc8efc7de4eefeef9ed27feba60bc21eba/openmctStaticServer/index.html#L143

https://github.com/ami-iit/yarp-openmct/blob/3d6105dc8efc7de4eefeef9ed27feba60bc21eba/openmctStaticServer/realtime-telemetry-plugin.js#L5-L16

We then use the stream video plugin example of yarp.js repository to display the streamed images. We can see in the stream the same scattered lines instead of a single one, as we see in the Open-MCT based visualizer.

We can conclude that the line scattered lines issue occurs in the data transmission between the telemetry server and the Open-MCT based visualizer client.

Sending a fixed frame

If we break the telemetry server we get a constant sample and thus a fixed frame on the visualizer, similar to the output illustrated on https://github.com/ami-iit/yarp-openmct/issues/71#issuecomment-1063569388, i.e with scattered lines.

image

This confirms the observation from the previous experiment. We then implement some changes in order to have the server send the raw image data buffer, and the client to apply the conversion to the URI format and base 64 (yarp.getImageSrc(...)): https://github.com/ami-iit/yarp-openmct/blob/34cae51cd90077c7d7d63f01f937562d5839ae15/openmctStaticServer/realtime-telemetry-plugin.js#L10-L21

This way it's easier to compare the data sent and received.

I'm suspecting an issue with the way the data transmission is scheduled, which could cause a race condition leading to concurrent data access in the case of big chunks of data, typically image data.

nunoguedelha commented 2 years ago

This way it's easier to compare the data sent and received.

image

We can see that the outputs are well aligned. We then break the telemetry server and the client visualizer in order to get in the debugger the sent and received buffers.

The buffers are identical.

The problem is not in the transmission of the data between the server and client, but rather in the implementation of the yarp image type port reading.


From the yarp.js repository examples, we know that the implementation of image type port reading through websockets works pretty well. For that reason we'll try reading the port directly via yarp socket in the visualizer client (no history shall be supported).


nunoguedelha commented 2 years ago

For that reason we'll try reading the port directly via yarp socket in the visualizer client (no history shall be supported).

This works pretty well, it solves the scattered lines issue. We can now choose a better protocol for the connection, other than tcp.

A debug version of the fix is implemented in https://github.com/ami-iit/yarp-openmct/tree/e5e0f28fbe8708954ac8240bfc43819b2955ff02.

nunoguedelha commented 2 years ago

This change broke the shutdown sequence. Fixing...

nunoguedelha commented 2 years ago

The proper closure of the iCubTelemVizServer server was blocked by the openmctStaticServer server hanging at closure itself.

Received SIGINT ...
{
  status: 'WRPLY',
  message: 'Process (PID 36504) OpenMCT Server stopping (signal SIGINT) ...'
}
iCub Telemetry Server closing: no further connection requests accepted.
Control Console Server closing: no further connection requests accepted.
[OPEN-MCT STATIC SERVER] stdout: Received SIGINT ...
Open-MCT Visualizer Server closing: no further incoming requests accepted. Refreshing the visualizer web page will fail.
Open-MCT Visualizer Server closed: all sockets closed.

The closure process resumes normally after we kill the nodejs process running the openmctStaticServer server.

iCub Telemetry Server closing: no further "subscribe"/"unsubscribe" requests accepted.
[INFO] |yarp.os.impl.PortCoreInputUnit| Removing input from /icubSim/inertial to /yarpjs/inertial:i
[INFO] |yarp.os.impl.PortCoreInputUnit| Removing input from /icubSim/left_leg/stateExt:o to /yarpjs/left_leg/stateExt:o
[INFO] |yarp.os.impl.PortCoreInputUnit| Removing input from /icubSim/camLeftEye to /yarpjs/camLeftEye:i
[INFO] |yarp.os.impl.PortCoreInputUnit| Removing input from /walking-coordinator/logger/data:o to /yarpjs/walking-coordinator-logger/data:i
iCub Telemetry Server closing: disconnected network ports.
Data transmission ended.
Closing all Telemetry Server and Control Console sockets!
[
  'iCub Telemetry Server closed: all sockets closed.',
  'Control Console Server closed: all sockets closed.'
]
Waiting for the debugger to disconnect...

Process finished with exit code 0
nunoguedelha commented 2 years ago

The proper closure of the iCubTelemVizServer server was blocked by the openmctStaticServer server hanging at closure itself.

Further analysis and fix documented in #102 .

Converting current issue into an epic.