ami-iit / yarp-openmct

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

Displayed joint positions are mixed and mirrored between left and right limbs #130

Closed nunoguedelha closed 2 years ago

nunoguedelha commented 2 years ago

Issue 3: The displayed joint positions are always the same between left and right parts, e.g. left and right legs or left and right arms, and values are oscillating between the two expected values

While reading the port data from both legs on the terminal with yarp read, we get the hip_pitch values for both legs...

  • left hip_pitch ~ -3 deg
  • right hip_pitch ~ 14 deg

...we can see in the example screenshots below (obtained with Gazebo simulation) the visualiser plot values being always the same between the two legs, and oscillating between the two expected values.

image

image

image

We can conclude that the visualiser is displaying the same values for both telemetry entries and somehow mixing both ports.

Analysing...

Originally posted by @nunoguedelha in https://github.com/ami-iit/yarp-openmct/issues/123#issuecomment-1229587565

nunoguedelha commented 2 years ago

After further analysis, we see that:

It could be a problem with the definition of the function pointer icubtelemetry.forwardYarpDataToNotifier...

Originally posted by @nunoguedelha in https://github.com/ami-iit/yarp-openmct/issues/123#issuecomment-1229600017

nunoguedelha commented 2 years ago

After checking again, actually the parser ICubTelemetry.prototype.parseFromId is called with the proper samples, different between the two ids sens.leftLegJointState and sens.rightLegJointState.

The problem was with the initialisation of the variable ICubTelemetry.state storing the parsed samples.

https://github.com/ami-iit/yarp-openmct/blob/ff74f1e351fe1ddb7c1139002a57acc9dbcc5eb9/iCubTelemVizServer/icubtelemetry.js#L22 https://github.com/ami-iit/yarp-openmct/blob/ff74f1e351fe1ddb7c1139002a57acc9dbcc5eb9/iCubTelemVizServer/icubtelemetry.js#L29-L35 https://github.com/ami-iit/yarp-openmct/blob/ff74f1e351fe1ddb7c1139002a57acc9dbcc5eb9/iCubTelemVizServer/icubtelemetry.js#L70

When initialising the sens.rightLegJointState nested structure, we had used the = operator to copy sens.leftLegJointState, which just sets a pointer to the later. For that reason we were always filling the same data for both legs.

image

This is easily fixed by using a deep copy through JSON.parse(JSON.stringify(...)).

image

Originally posted by @nunoguedelha in https://github.com/ami-iit/yarp-openmct/issues/123#issuecomment-1229658228

nunoguedelha commented 2 years ago

CC @S-Dafarra