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

RT Capabilities Part 1 - YARP Logger Device #817

Merged
merged 91 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 76 commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
c8134c6
Edited to test sending of logging data to YARP port
nicktrem Dec 18, 2023
76c01a2
Added a test for streaming data, it was successful
nicktrem Dec 29, 2023
4267db2
Added dummy value to send for testing
nicktrem Dec 31, 2023
45bade1
temporarily removed sending all of the data for testing purposes
nicktrem Dec 31, 2023
c213ed7
Sending FT data to log visualizer
nicktrem Jan 2, 2024
c4da8b5
Moved the code for sending data to a more centralized function
nicktrem Jan 2, 2024
4667433
Added more logging data to send to the visualizer
nicktrem Jan 2, 2024
98b0563
Added Cartesian Wrench valus to be streamed in real-time
nicktrem Jan 4, 2024
d498c21
Added external data, moved current system of sending data to a better…
nicktrem Jan 4, 2024
cf20448
Fixed bug related to json key field
nicktrem Jan 5, 2024
296cd2c
Cleaned up the code a little bit
nicktrem Jan 5, 2024
a735dd4
Cleaned up the code, removed hard-coded values
nicktrem Jan 5, 2024
f43d2d7
Added back motor state logging
nicktrem Jan 9, 2024
325d378
Changed rt logging port name
nicktrem Jan 9, 2024
04c14cd
Fixed merge conflict
nicktrem Jan 11, 2024
5bd0122
Added Vector Collection Client
nicktrem Jan 15, 2024
ca1fffb
Initial test sucessful of sending vector collection data to robot-log…
nicktrem Jan 15, 2024
6ca1fe9
Added get metadata method for pybind11
nicktrem Jan 16, 2024
6284950
Added metadata values
nicktrem Jan 16, 2024
5f4c3fb
Got joint data sending over the vector Collection Network
nicktrem Jan 16, 2024
edf8b45
Added more values to send over via the vector collection server
nicktrem Jan 16, 2024
c25f25d
Cleaned up the code
nicktrem Jan 17, 2024
5409fab
got plot scaling updating correctly
nicktrem Jan 17, 2024
b83a7f6
Flight data streaming
nicktrem Jan 17, 2024
5eabf65
Got metadata naming correct
nicktrem Jan 18, 2024
554fa1e
Added ability to stream motor states
nicktrem Jan 18, 2024
f45bfb5
Cleaned up the code a bit
nicktrem Jan 18, 2024
ebf9d76
Removed whitespace in Module.cpp
nicktrem Jan 18, 2024
9def9a5
Removed whitespace from VectorsCollection.cpp
nicktrem Jan 18, 2024
d92f7f4
Cleaned up the code, removed debug statements/comments
nicktrem Jan 18, 2024
8ad4b69
Merge branch 'vectorCollectionServerRT' of https://github.com/nicktre…
nicktrem Jan 18, 2024
c3c79ad
Reorganized the code and removed hardcoded values
nicktrem Jan 19, 2024
0ce1575
Removed white space, fixed spelling mistake in comment
nicktrem Jan 19, 2024
cb4838e
Updated formatting
nicktrem Jan 19, 2024
875e190
Update YarpRobotLoggerDevice.cpp
nicktrem Jan 19, 2024
4815a61
remvoed white space
nicktrem Jan 19, 2024
1cde2ae
Update CHANGELOG.md
nicktrem Jan 19, 2024
2781076
Merge branch 'master' into vectorCollectionServerRT
nicktrem Jan 19, 2024
3ee4481
Changed vector collection RT data server member name
nicktrem Jan 22, 2024
12f1649
Added functions for processing metadata
nicktrem Jan 22, 2024
3fda2d5
Optimized the constants a bit
nicktrem Jan 22, 2024
4a6f01b
Merge branch 'vectorCollectionServerRT' of https://github.com/nicktre…
nicktrem Jan 22, 2024
20d7b65
Removed identical functions
nicktrem Jan 22, 2024
834d618
Added function for storing and sending data
nicktrem Jan 22, 2024
bf7fe13
Fixed up constants file
nicktrem Jan 22, 2024
5f62eea
Added mutex for text logging port
nicktrem Jan 22, 2024
8d3d488
Moved realtime port data to be read from config file
nicktrem Jan 22, 2024
21bdbdb
Applied the clang format
nicktrem Jan 22, 2024
3667b19
Merge branch 'ami-iit:master' into master
nicktrem Jan 24, 2024
e136188
fixed merge conflict with master
nicktrem Jan 24, 2024
2b6ef20
Removed unused functions
nicktrem Jan 25, 2024
2ccff2d
Fixed issue with header definition
nicktrem Jan 25, 2024
5ef8bb4
Moved to lock guard instead of mutex lock
nicktrem Jan 25, 2024
d24e886
Removed whitespace
nicktrem Jan 25, 2024
482e195
Fixed data prepare bug with vector server
nicktrem Feb 1, 2024
3be2c8a
Merge branch 'master' into vectorCollectionServerRT
nicktrem Feb 2, 2024
841138c
Cleaned up the code regarding constants
nicktrem Feb 5, 2024
e5d0cdb
Added pybind functions for metadata
nicktrem Feb 5, 2024
568addd
cleaned up variable locations
nicktrem Feb 5, 2024
c16b958
Merge branch 'vectorCollectionServerRT' of https://github.com/nicktre…
nicktrem Feb 5, 2024
52499b5
Added an option to open the RT port from XML
nicktrem Feb 8, 2024
7244bca
Cleaned up the code a bit more with the function pointers
nicktrem Feb 8, 2024
51f9a8a
Fixed issue with vector collection server
nicktrem Feb 13, 2024
cc97f40
Cleaned up the code
nicktrem Feb 13, 2024
609e3c2
Removed whitespace
nicktrem Feb 13, 2024
3cfaf3d
Removed whitespace
nicktrem Feb 13, 2024
6c1fdd1
Fixed but regarding closing and opening logger devices
nicktrem Feb 16, 2024
0e166b4
Removed bug regarding metadata
nicktrem Feb 22, 2024
107860c
changed function name to snake case
nicktrem Feb 29, 2024
26f7a3a
Updated the git ignore
nicktrem Feb 29, 2024
0392a04
Replaced yInfo with log()->info()
nicktrem Feb 29, 2024
cf0370b
Fixed formatting
nicktrem Feb 29, 2024
70e0b6f
Fixed variable names
nicktrem Feb 29, 2024
3efcfe5
Updated max timeout for exogenous signals
nicktrem Mar 4, 2024
3f9d725
Removed complexity for a simpler PR
nicktrem Mar 4, 2024
e392e93
Further simplified
nicktrem Mar 4, 2024
ee4cf0d
Removed leftover comments
nicktrem Mar 6, 2024
8f0e4a8
replaced unnecessary code with a function
nicktrem Mar 6, 2024
4ea7f85
Restructured reading rt setting from log file
nicktrem Mar 6, 2024
f8d16c4
Fixed code formatting
nicktrem Mar 6, 2024
9429b0e
Removed unused includes
nicktrem Mar 6, 2024
69fa835
Fixed more formatting
nicktrem Mar 6, 2024
1939bee
Added use of Eigen::Map
nicktrem Mar 6, 2024
0c6be42
Moved the remote string variable
nicktrem Mar 6, 2024
7c8d912
Fixed bug with bitwise and
nicktrem Mar 6, 2024
1c924a9
Changed variable names
nicktrem Mar 6, 2024
9555d00
reverted to previous signal name
nicktrem Mar 6, 2024
a91ee01
Cleaned up python bindings
nicktrem Mar 6, 2024
0888c96
Turned log data into a lambda
nicktrem Mar 6, 2024
01aea4e
Removed Eigen Map after logData lambda change
nicktrem Mar 6, 2024
0c28b90
removed duplicate include of vector
nicktrem Mar 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,6 @@ dmypy.json

# Cython debug symbols
cython_debug/

# compile commands file for resolving includes
compile_commands.json
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ All notable changes to this project are documented in this file.

## [unreleased]
### Added
- Added Vector Collection Server for publishing information for real-time users in the YARPRobotLoggerDevice (https://github.com/ami-iit/bipedal-locomotion-framework/pull/796)
- Set submodel states from IMUs in RDE and add friction torques as measurement (https://github.com/ami-iit/bipedal-locomotion-framework/pull/793)
- Add streaming of arm fts in YarpRobotLoggerDevice (https://github.com/ami-iit/bipedal-locomotion-framework/pull/803)

Expand Down Expand Up @@ -32,6 +33,7 @@ All notable changes to this project are documented in this file.
- Implement `blf-joints-grid-position-tracking` application in `utilities` (https://github.com/ami-iit/bipedal-locomotion-framework/pull/787)
- Add the possibility to resample the contact in a given contact list (https://github.com/ami-iit/bipedal-locomotion-framework/pull/788)


### Changed
- Restructure of the `CentroidalMPC` class in `ReducedModelControllers` component. Specifically, the `CentroidalMPC` now provides a contact phase list instead of indicating the next active contact. Additionally, users can now switch between `ipopt` and `sqpmethod` to solve the optimization problem. Furthermore, the update allows for setting the warm-start for the non-linear solver. (https://github.com/ami-iit/bipedal-locomotion-framework/pull/766)
- Restructured the swing foot planner to handle corners case that came out while testing DNN-MPC integration (https://github.com/ami-iit/bipedal-locomotion-framework/pull/765)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace YarpUtilities
{

void CreateVectorsCollectionServer(pybind11::module& module);
void CreateVectorsCollectionClient(pybind11::module& module);
void CreateVectorsCollectionMetadata(pybind11::module& module);

} // namespace YarpUtilities
} // namespace bindings
Expand Down
2 changes: 2 additions & 0 deletions bindings/python/YarpUtilities/src/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ void CreateModule(pybind11::module& module)
module.doc() = "YarpUtilities module.";

CreateVectorsCollectionServer(module);
CreateVectorsCollectionClient(module);
CreateVectorsCollectionMetadata(module);
}
} // namespace IK
} // namespace bindings
Expand Down
64 changes: 64 additions & 0 deletions bindings/python/YarpUtilities/src/VectorsCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <pybind11/eigen.h>

#include <BipedalLocomotion/YarpUtilities/VectorsCollectionServer.h>
#include <BipedalLocomotion/YarpUtilities/VectorsCollectionClient.h>

#include <BipedalLocomotion/bindings/YarpUtilities/BufferedPort.h>
#include <BipedalLocomotion/bindings/YarpUtilities/VectorsCollection.h>
Expand Down Expand Up @@ -46,6 +47,69 @@ void CreateVectorsCollectionServer(pybind11::module& module)
})
.def("prepare_data", &VectorsCollectionServer::prepareData);
}

void CreateVectorsCollectionClient(pybind11::module& module)
{
namespace py = ::pybind11;

using namespace ::BipedalLocomotion::YarpUtilities;

py::class_<VectorsCollectionClient>(module, "VectorsCollectionClient")
.def(py::init())
.def(
"initialize",
[](VectorsCollectionClient& impl,
std::shared_ptr<const ::BipedalLocomotion::ParametersHandler::IParametersHandler>
handler) -> bool { return impl.initialize(handler); },
py::arg("handler"))
.def("connect", &VectorsCollectionClient::connect)
.def("disconnect", &VectorsCollectionClient::disconnect)
.def("get_metadata",
[](VectorsCollectionClient& impl) -> BipedalLocomotion::YarpUtilities::VectorsCollectionMetadata
{
BipedalLocomotion::YarpUtilities::VectorsCollectionMetadata metadata;
impl.getMetadata(metadata);
return metadata;
})
.def("read_data",
[](VectorsCollectionClient& impl, bool shouldWait) -> std::map<std::string, std::vector<double>>
{
BipedalLocomotion::YarpUtilities::VectorsCollection* collection = impl.readData(shouldWait);
return collection->vectors;
});
}

void CreateVectorsCollectionMetadata(pybind11::module& module)
{
namespace py = ::pybind11;

using namespace ::BipedalLocomotion::YarpUtilities;

py::class_<VectorsCollectionMetadata>(module, "VectorsCollectionMetadata")
.def(py::init())
.def(py::init<const std::map<std::string, std::vector<std::string>>&>())
.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);
})
nicktrem marked this conversation as resolved.
Show resolved Hide resolved
.def("to_string", &VectorsCollectionMetadata::toString)
.def("getVectors",
[](const VectorsCollectionMetadata& impl) -> std::map<std::string, std::vector<std::string>> {
return impl.vectors;
});
}
} // namespace YarpUtilities
} // namespace bindings
} // namespace BipedalLocomotion
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
#include <atomic>
#include <memory>
#include <mutex>
#include <vector>
#include <string>
#include <string_view>
#include <unordered_map>
#include <unordered_set>
#include <vector>
nicktrem marked this conversation as resolved.
Show resolved Hide resolved

#include <opencv2/opencv.hpp>
#include <opencv2/videoio.hpp>
Expand All @@ -30,6 +31,7 @@
#include <BipedalLocomotion/RobotInterface/YarpSensorBridge.h>
#include <BipedalLocomotion/YarpUtilities/VectorsCollection.h>
#include <BipedalLocomotion/YarpUtilities/VectorsCollectionClient.h>
#include <BipedalLocomotion/YarpUtilities/VectorsCollectionServer.h>

namespace BipedalLocomotion
{
Expand Down Expand Up @@ -62,6 +64,9 @@ class YarpRobotLoggerDevice : public yarp::dev::DeviceDriver,
std::unique_ptr<BipedalLocomotion::RobotInterface::YarpSensorBridge> m_robotSensorBridge;
std::unique_ptr<BipedalLocomotion::RobotInterface::YarpCameraBridge> m_cameraBridge;

bool m_sendDataRT;
BipedalLocomotion::YarpUtilities::VectorsCollectionServer m_vectorCollectionRTDataServer;

template <typename T> struct ExogenousSignal
{
std::mutex mutex;
Expand Down Expand Up @@ -98,7 +103,6 @@ class YarpRobotLoggerDevice : public yarp::dev::DeviceDriver,

bool connect();
void disconnect();

};

std::unordered_map<std::string, VectorsCollectionSignal> m_vectorsCollectionSignals;
Expand Down Expand Up @@ -167,10 +171,17 @@ class YarpRobotLoggerDevice : public yarp::dev::DeviceDriver,
std::vector<std::string> m_codeStatusCmdPrefixes;

std::mutex m_bufferManagerMutex;
std::mutex m_textLoggingPortMutex;
Copy link
Member

Choose a reason for hiding this comment

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

I think this is a leftover

Suggested change
std::mutex m_textLoggingPortMutex;
std::mutex m_textLoggingPortMutex;

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 mutex is not leftover, it is used to guard the text logging port for when it is reading and when it is looking for new logs.

robometry::BufferManager m_bufferManager;

void lookForNewLogs();
void lookForExogenousSignals();

bool initMetadata(const std::string& nameKey, const std::vector<std::string>& metadata);
void logData(const std::string& name,
const Eigen::VectorXd& data,
const double time);
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
void logData(const std::string& name,
const Eigen::VectorXd& data,
const double time);
void logData(const std::string& name,
Eigen::Ref<const Eigen::VectorXd> data,
const double time);

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 0888c96. The change of just adding Eigen::Ref<> causes issues when saving the data via buffer manager. This is because the push_back method of the buffer manager uses a template for the data and is storing the raw data of the Eigen::Ref and not the Eigen::VectorXd. The solution was discussed and implemented with the help of @S-Dafarra in which we used a lambda function to still pass the Eigen::Vector by a reference.


bool hasSubstring(const std::string& str, const std::vector<std::string>& substrings) const;
void recordVideo(const std::string& cameraName, VideoWriter& writer);
void unpackIMU(Eigen::Ref<const analog_sensor_t> signal,
Expand All @@ -191,8 +202,59 @@ class YarpRobotLoggerDevice : public yarp::dev::DeviceDriver,
bool createFramesFolder(std::shared_ptr<VideoWriter::ImageSaver> imageSaver,
const std::string& camera,
const std::string& imageType);

const std::string treeDelim = "::";

const std::string robotRtRootName = "robot_realtime";
GiulioRomualdi marked this conversation as resolved.
Show resolved Hide resolved

const std::string jointStatePositionsName = "joints_state::positions";
const std::string jointStateVelocitiesName = "joints_state::velocities";
const std::string jointStateAccelerationsName = "joints_state::accelerations";
const std::string jointStateTorquesName = "joints_state::torques";

const std::string motorStatePositionsName = "motors_state::positions";
const std::string motorStateVelocitiesName = "motors_state::velocities";
const std::string motorStateAccelerationsName = "motors_state::accelerations";
const std::string motorStateCurrentsName = "motors_state::currents";
const std::string motorStatePwmName = "motors_state::PWM";

const std::string motorStatePidsName = "PIDs";

const std::string ftsName = "FTs";

const std::vector<std::string> ftElementNames = {"f_x", "f_y", "f_z", "mu_x", "mu_y", "mu_z"};

const std::string gyrosName = "gyros";
const std::vector<std::string> gyroElementNames = {"omega_x", "omega_y", "omega_z"};

const std::string accelerometersName = "accelerometers";
const std::vector<std::string> AccelerometerElementNames = {"a_x", "a_y", "a_z"};

const std::string orientationsName = "orientations";
const std::vector<std::string> orientationElementNames = {"r", "p", "y"};

const std::string magnetometersName = "magnetometers";
const std::vector<std::string> magnetometerElementNames = {"mag_x", "mag_y", "mag_z"};

const std::string cartesianWrenchesName = "cartesian_wrenches";
const std::vector<std::string> cartesianWrenchNames = {ftElementNames[0],
ftElementNames[1],
ftElementNames[2],
ftElementNames[3],
ftElementNames[4],
ftElementNames[5]};
GiulioRomualdi marked this conversation as resolved.
Show resolved Hide resolved

const std::string temperatureName = "temperatures";
const std::vector<std::string> temperatureNames = {"temperature"};

const std::string robotName = "yarp_robot_name";

const std::string robotDescriptionList = "description_list";

const std::string timestampsName = "timestamps";
};

} // namespace BipedalLocomotion


#endif // BIPEDAL_LOCOMOTION_FRAMEWORK_YARP_ROBOT_LOGGER_DEVICE_H
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#ifndef BIPEDAL_LOCOMOTION_FRAMEWORK_YARP_ROBOT_LOGGER_DEVICE_YARP_TEXT_LOGGING_UTILITIES_H
#define BIPEDAL_LOCOMOTION_FRAMEWORK_YARP_ROBOT_LOGGER_DEVICE_YARP_TEXT_LOGGING_UTILITIES_H

#include <string>
#include <cstdint>
#include <string>

#include <yarp/os/Bottle.h>

Expand Down Expand Up @@ -57,5 +57,4 @@ struct TextLoggingEntry

} // namespace BipedalLocomotion


#endif // BIPEDAL_LOCOMOTION_FRAMEWORK_YARP_ROBOT_LOGGER_DEVICE_YARP_TEXT_LOGGING_UTILITIES_H
Loading
Loading