Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Vector Collection Server for publishing information for real-time users in the YARPRobotLoggerDevice #796

Closed
wants to merge 73 commits into from

Conversation

nicktrem
Copy link
Contributor

Edited the functionality of the real-time logger to use a vector collection client/server

Copy link
Member

@S-Dafarra S-Dafarra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done!

Comment on lines 67 to 72
.def("getMetadata",
[](VectorsCollectionClient& impl) -> std::map<std::string, std::vector<std::string>>
{
BipedalLocomotion::YarpUtilities::VectorsCollectionMetadata metadata;
impl.getMetadata(metadata);
return metadata.vectors;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things:

  1. in Python we tend to use snake case for methods and variables for example get_metadata
  2. Can you directly return a metadata and not the vector? In this case you need to write the bindings for metadata

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added more pyBind methods for the metadata in e5d0cdb. Renamed functions to snake case in 568addd

@@ -0,0 +1,57 @@
#ifndef BIPEDAL_LOCOMOTION_fRAMEWORK_YARP_ROBOT_LOGGER_DEVICE_VTN_H
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a big fan of these kinds of define. Can you add these names directly in the main class as attributes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 568addd

}

void YarpRobotLoggerDevice::storeAndSendLoggingData(const std::string& name,
const Eigen::VectorXd& data,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use eigen ref here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of Eigen::Ref to the data parameter causes the data to not be saved correctly, see the image below regarding the mesh:
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually a problem. we should understand why

Copy link
Member

@GiulioRomualdi GiulioRomualdi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @nicktrem, sorry for the delayed response. I've been occupied with various lab activities and personal deadlines, which delayed the review process. Upon revisiting the PR, there are some points that need to be addressed before merging it. Once this is resolved, I'll move on to ami-iit/robot-log-visualizer#77

[](const VectorsCollectionMetadata& impl, yarp::os::ConnectionWriter& connection) -> bool {
return impl.write(connection);
})
.def("toString", &VectorsCollectionMetadata::toString)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.def("toString", &VectorsCollectionMetadata::toString)
.def("to_string", &VectorsCollectionMetadata::toString)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 107860c

Comment on lines +91 to +106
.def("readWireReader",
[](VectorsCollectionMetadata& impl, yarp::os::idl::WireReader& reader) -> bool {
return impl.read(reader);
})
.def("readConnectionReader",
[](VectorsCollectionMetadata& impl, yarp::os::ConnectionReader& connection) -> bool {
return impl.read(connection);
})
.def("writeWireWriter",
[](const VectorsCollectionMetadata& impl, const yarp::os::idl::WireWriter& writer) -> bool {
return impl.write(writer);
})
.def("writeConnectionWriter",
[](const VectorsCollectionMetadata& impl, yarp::os::ConnectionWriter& connection) -> bool {
return impl.write(connection);
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not clear to me, in theory, there are no bindings of yarp::os::ConnectionWriter and yarp::os::idl::WireReader so you cannot call this method from python. How did you test them? moreover you can check this for function overloading in pybind11 https://pybind11.readthedocs.io/en/stable/classes.html#overloaded-methods

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to discuss face-to-face

Comment on lines +102 to +107
// if (m_pimpl->isMetadataFinalized)
// {
// log()->error("[VectorsCollectionServer::populateMetadata] The metadata has been already "
// "populated.");
// return false;
// }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be re-added before merging this PR 🤔. Why was it removed in the first place?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be better to discuss face-to-face. This has to do with the issue regarding adding new data to the vectors Collection on the fly


// check if the key has been already used
// // check if the key has been already used
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// // check if the key has been already used
// check if the key has been already used

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in cf0370b

Comment on lines +161 to +165
// if (!m_pimpl->isMetadataFinalized)
// {
// log()->error("{} The metadata has not been finalized.", logPrefix);
// return false;
// }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as before

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to discuss face-to-face

}
else if (externalSignalCollection == nullptr && signal.connected)
{
signal.numMissedPackets++;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This statement is inaccurate. The logger does not consider the period of the exogenous signal. In fact, the signal may arrive at a frequency different from that of the logger, which is acceptable. I will completely remove this logic as it would introduce misleading information. For example, if the exogenous signal arrives from a controller running at 100 Hz while the logger operates at 1 kHz, there are no missing packets.

Copy link
Contributor Author

@nicktrem nicktrem Feb 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to discuss face-to-face. I understand the issue here. This logic was initially put in to disconnect exogenous signals which were no longer running and to reset the signal.connected flag. If an exogenous signal is not disconnected when a YARP device is restarted, it was noticed that it will not be able to receive new data from that device

Comment on lines 1671 to 1672
if(sendDataRT)
m_vectorCollectionRTDataServer.sendData();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(sendDataRT)
m_vectorCollectionRTDataServer.sendData();
if(sendDataRT)
{
m_vectorCollectionRTDataServer.sendData();
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in cf0370b

@@ -62,6 +65,9 @@ class YarpRobotLoggerDevice : public yarp::dev::DeviceDriver,
std::unique_ptr<BipedalLocomotion::RobotInterface::YarpSensorBridge> m_robotSensorBridge;
std::unique_ptr<BipedalLocomotion::RobotInterface::YarpCameraBridge> m_cameraBridge;

bool sendDataRT;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool sendDataRT;
bool m_sendDataRT;

Copy link
Contributor Author

@nicktrem nicktrem Feb 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 70e0b6f

@@ -93,16 +99,17 @@ class YarpRobotLoggerDevice : public yarp::dev::DeviceDriver,
BipedalLocomotion::YarpUtilities::VectorsCollectionClient client;
BipedalLocomotion::YarpUtilities::VectorsCollectionMetadata metadata;
std::string signalName;
unsigned int numMissedPackets;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As explained below I would remove this information

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to discuss face-to-face

Comment on lines 1614 to 1619
Eigen::Matrix<double, 1, 1> newMetadataVector;
if(newMetadata)
m_updatedMetadataSignalVal = (m_updatedMetadataSignalVal + 1) % 2;
newMetadataVector << m_updatedMetadataSignalVal;

m_vectorCollectionRTDataServer.populateData(ROBOT_RT_ROOT_NAME + TREE_DELIM + "newMetadata", newMetadataVector);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me the what is the purpose of this code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to discuss face-to-face. This code informs the robot-log-visualizer when new metadata has been added to the vectors collection thus allowing the visualizer to append the data to the variable tree so the user can visualize it. It is a flag

@nicktrem nicktrem closed this Mar 4, 2024
@nicktrem
Copy link
Contributor Author

nicktrem commented Mar 4, 2024

After face-to-face discussions with @S-Dafarra, @GiulioRomualdi, and @gabrielenava. This PR will be broken up into smaller PRs so it is easier to manage

See the list of smaller PRs below:
Part 1) pull request #817
Part 2) to be created soon
Part 3) to be created soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants