Skip to content

Commit 40456d1

Browse files
authored
Add rpc commands to YarpLoggerDevice (#915)
1 parent ba2a98a commit 40456d1

File tree

5 files changed

+56
-1
lines changed

5 files changed

+56
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ All notable changes to this project are documented in this file.
1313
- 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)
1414
- Add KF to estimate joint and motor velocities in JoinTorqueControlDevice (https://github.com/ami-iit/bipedal-locomotion-framework/pull/909)
1515
- 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)
16+
- 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)
1617

1718
### Changed
1819
- 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)

devices/YarpRobotLoggerDevice/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ if(FRAMEWORK_COMPILE_YarpRobotLoggerDevice)
3434
endif()
3535
endif()
3636

37+
add_bipedal_locomotion_yarp_thrift(
38+
NAME YarpRobotLoggerDeviceCommands
39+
THRIFT thrifts/YarpRobotLoggerDeviceCommands.thrift
40+
INSTALLATION_FOLDER YarpRobotLoggerDevice)
41+
3742
# Warning: the <package> option of yarp_configure_plugins_installation should be different from the plugin name
3843
add_bipedal_yarp_device(
3944
NAME YarpRobotLoggerDevice
@@ -55,6 +60,7 @@ if(FRAMEWORK_COMPILE_YarpRobotLoggerDevice)
5560
BipedalLocomotion::PerceptionInterfaceYarpImplementation
5661
BipedalLocomotion::TextLoggingYarpImplementation
5762
BipedalLocomotion::SystemYarpImplementation
63+
BipedalLocomotion::YarpRobotLoggerDeviceCommands
5864
tiny-process-library::tiny-process-library
5965
CONFIGURE_PACKAGE_NAME yarp_robot_logger_device)
6066

devices/YarpRobotLoggerDevice/include/BipedalLocomotion/YarpRobotLoggerDevice.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,15 @@
3232
#include <BipedalLocomotion/YarpUtilities/VectorsCollectionClient.h>
3333
#include <BipedalLocomotion/YarpUtilities/VectorsCollectionServer.h>
3434

35+
#include <YarpRobotLoggerDeviceCommands.h>
36+
3537
namespace BipedalLocomotion
3638
{
3739

3840
class YarpRobotLoggerDevice : public yarp::dev::DeviceDriver,
3941
public yarp::dev::IMultipleWrapper,
40-
public yarp::os::PeriodicThread
42+
public yarp::os::PeriodicThread,
43+
public YarpRobotLoggerDeviceCommands
4144
{
4245
public:
4346
YarpRobotLoggerDevice(double period,
@@ -177,6 +180,10 @@ class YarpRobotLoggerDevice : public yarp::dev::DeviceDriver,
177180
std::mutex m_bufferManagerMutex;
178181
robometry::BufferManager m_bufferManager;
179182

183+
const std::string m_rpcPortName{"/commands/rpc:i"}; /**< name of Remote
184+
Procedure Call port. */
185+
yarp::os::Port m_rpcPort; /**< Remote Procedure Call port. */
186+
180187
void lookForNewLogs();
181188
void lookForExogenousSignals();
182189

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

256263
const std::string timestampsName = "timestamps";
264+
265+
virtual bool saveData();
257266
};
258267

259268
} // namespace BipedalLocomotion

devices/YarpRobotLoggerDevice/src/YarpRobotLoggerDevice.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,26 @@ bool YarpRobotLoggerDevice::open(yarp::os::Searchable& config)
394394
return false;
395395
}
396396

397+
// open rpc port for YarpRobotLoggerDevice commands
398+
std::string portPrefix{"/yarp-robot-logger"};
399+
400+
if (!params->getParameter("port_prefix", portPrefix))
401+
{
402+
403+
log()->info("{} The 'port_prefix' is not provided. The default prefix {} will be used.",
404+
logPrefix,
405+
portPrefix);
406+
}
407+
408+
std::string rpcPortFullName = portPrefix + m_rpcPortName;
409+
410+
this->yarp().attachAsServer(this->m_rpcPort);
411+
if (!m_rpcPort.open(rpcPortFullName))
412+
{
413+
log()->error("{} Could not open", logPrefix);
414+
return false;
415+
}
416+
397417
return true;
398418
}
399419

@@ -1998,3 +2018,10 @@ bool YarpRobotLoggerDevice::close()
19982018

19992019
return true;
20002020
}
2021+
2022+
bool YarpRobotLoggerDevice::saveData()
2023+
{
2024+
std::string fileName;
2025+
m_bufferManager.saveToFile(fileName);
2026+
return this->saveCallback(fileName, robometry::SaveCallbackSaveMethod::periodic);
2027+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @file YarpRobotLoggerDeviceCommands.thrift
3+
* @authors Lorenzo Moretti <[email protected]>
4+
* @copyright 2024 Fondazione Istituto Italiano di Tecnologia
5+
* Released under the terms of the BSD-3-Clause license.
6+
* @date 2024
7+
*/
8+
9+
service YarpRobotLoggerDeviceCommands
10+
{
11+
bool saveData();
12+
}

0 commit comments

Comments
 (0)