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

Add rpc commands to YarpLoggerDevice #915

Merged
merged 11 commits into from
Dec 5, 2024
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ All notable changes to this project are documented in this file.
- Implement `velMANN` class to perform inference on MANN model with velocity-based features in `ML` component (https://github.com/ami-iit/bipedal-locomotion-framework/pull/889)
- Implement `velMANNAutoregressive`, `velMANNAutoregressiveInputBuilder`, and `velMANNTrajectoryGenerator` to generate trajectories using MANN model with velocity-based features in `ML` component (https://github.com/ami-iit/bipedal-locomotion-framework/pull/889)
- Added option `FRAMEWORK_COMPILE_Ros1Publisher` to enable or disable the compilation of the `BipedalLocomotion::YarpUtilities::RosPublisher` class (https://github.com/ami-iit/bipedal-locomotion-framework/pull/914)
- Added rpc commands to `YarpLoggerDevice` to trigger the saving of data to a local file (https://github.com/ami-iit/bipedal-locomotion-framework/pull/915)

### Changed
- Change device jtcvc to use motor velocity and joint velocity in input to PINN models (https://github.com/ami-iit/bipedal-locomotion-framework/pull/903)
Expand Down
6 changes: 6 additions & 0 deletions devices/YarpRobotLoggerDevice/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ if(FRAMEWORK_COMPILE_YarpRobotLoggerDevice)
endif()
endif()

add_bipedal_locomotion_yarp_thrift(
NAME YarpRobotLoggerDeviceCommands
THRIFT thrifts/YarpRobotLoggerDeviceCommands.thrift
INSTALLATION_FOLDER YarpRobotLoggerDevice)

# Warning: the <package> option of yarp_configure_plugins_installation should be different from the plugin name
add_bipedal_yarp_device(
NAME YarpRobotLoggerDevice
Expand All @@ -55,6 +60,7 @@ if(FRAMEWORK_COMPILE_YarpRobotLoggerDevice)
BipedalLocomotion::PerceptionInterfaceYarpImplementation
BipedalLocomotion::TextLoggingYarpImplementation
BipedalLocomotion::SystemYarpImplementation
BipedalLocomotion::YarpRobotLoggerDeviceCommands
tiny-process-library::tiny-process-library
CONFIGURE_PACKAGE_NAME yarp_robot_logger_device)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@
#include <BipedalLocomotion/YarpUtilities/VectorsCollectionClient.h>
#include <BipedalLocomotion/YarpUtilities/VectorsCollectionServer.h>

#include <YarpRobotLoggerDeviceCommands.h>

namespace BipedalLocomotion
{

class YarpRobotLoggerDevice : public yarp::dev::DeviceDriver,
public yarp::dev::IMultipleWrapper,
public yarp::os::PeriodicThread
public yarp::os::PeriodicThread,
public YarpRobotLoggerDeviceCommands
{
public:
YarpRobotLoggerDevice(double period,
Expand Down Expand Up @@ -177,6 +180,10 @@ class YarpRobotLoggerDevice : public yarp::dev::DeviceDriver,
std::mutex m_bufferManagerMutex;
robometry::BufferManager m_bufferManager;

const std::string m_rpcPortName{"/commands/rpc:i"}; /**< name of Remote
Procedure Call port. */
yarp::os::Port m_rpcPort; /**< Remote Procedure Call port. */

void lookForNewLogs();
void lookForExogenousSignals();

Expand Down Expand Up @@ -254,6 +261,8 @@ class YarpRobotLoggerDevice : public yarp::dev::DeviceDriver,
const std::string robotDescriptionList = "description_list";

const std::string timestampsName = "timestamps";

virtual bool saveData();
};

} // namespace BipedalLocomotion
Expand Down
25 changes: 25 additions & 0 deletions devices/YarpRobotLoggerDevice/src/YarpRobotLoggerDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,24 @@ bool YarpRobotLoggerDevice::open(yarp::os::Searchable& config)
return false;
}

// open rpc port for YarpRobotLoggerDevice commands
std::string portPrefix{"/yarp-robot-logger"};

if (!params->getParameter("port_prefix", portPrefix))
{

log()->info("{} The 'port_prefix' is not provided. It willnot be used.", logPrefix);
LoreMoretti marked this conversation as resolved.
Show resolved Hide resolved
}

std::string rpcPortFullName = portPrefix + m_rpcPortName;

this->yarp().attachAsServer(this->m_rpcPort);
if (!m_rpcPort.open(rpcPortFullName))
{
log()->error("{} Could not open", logPrefix);
return false;
}

return true;
}

Expand Down Expand Up @@ -1998,3 +2016,10 @@ bool YarpRobotLoggerDevice::close()

return true;
}

bool YarpRobotLoggerDevice::saveData()
{
std::string fileName;
m_bufferManager.saveToFile(fileName);
return this->saveCallback(fileName, robometry::SaveCallbackSaveMethod::periodic);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @file YarpRobotLoggerDeviceCommands.thrift
* @authors Lorenzo Moretti <[email protected]>
* @copyright 2024 Artificial and Mechanical Intelligence - Istituto Italiano di Tecnologia
traversaro marked this conversation as resolved.
Show resolved Hide resolved
LoreMoretti marked this conversation as resolved.
Show resolved Hide resolved
* Released under the terms of the BSD-3-Clause license.
* @date 2024
*/

service YarpRobotLoggerDeviceCommands
{
bool saveData();
}
Loading