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

New device: MultipleAnalogSensorsClientRemapper #2881

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

GiulioRomualdi
Copy link
Member

This PR implements the MultipleAnalogSensorsClientRemapper this device implements the same logic as the remotecontroboardremapper indeed it automatically opens all the MultipleAnalogSensorsClient the MultipleAnalogSensorsRemapper and then it performs the attach of the MultipleAnalogSensorsClients to the MultipleAnalogSensorsRemapper

cc @traversaro @S-Dafarra @randaz81

@update-docs
Copy link

update-docs bot commented Sep 28, 2022

Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would update the release notes by adding a file in doc/release/<target_branch>, based on your changes.

@GiulioRomualdi GiulioRomualdi temporarily deployed to code-analysis September 28, 2022 06:03 Inactive
@GiulioRomualdi GiulioRomualdi temporarily deployed to code-analysis September 28, 2022 06:04 Inactive
@randaz81 randaz81 self-assigned this Oct 7, 2022
@randaz81 randaz81 self-requested a review October 7, 2022 07:08
@randaz81 randaz81 added PR Type: Feat/Enh This PR adds some new feature or enhances some part of YARP Component: Devices Target: YARP v3.9.0 labels Oct 7, 2022
@randaz81 randaz81 added this to the YARP 3.9.0 milestone Jan 20, 2023
@traversaro
Copy link
Member

traversaro commented Jun 23, 2023

To clarify why this device is useful, this is the snippet of code to read data from feet FT measurements from a robot that has two FT sensors for each foot (such as iCub3 or ergoCub), without and with using the multipleanalogsensorsclientremapper device. Without counting error handling, the basic code to just read the sensor goes from 40 lines to 20 lines, and this is just a simple case in which only four seconds from two parts are used, if multiple parts of the robot were used, the case without the multipleanalogsensorsclientremapper would be even more complex.

Without multipleanalogsensorsclientremapper

// Snippet of code to read just the FT sensors on the feet of iCub, for a robot that has two FT sensors for each feet (like iCub 3 or ergoCub)

std::string robotPortPrefix = "icub"; // or icubSim for simulated robots, this is tipically passed via an option
std::string localPortPrefix = "localCode";

// Create client for left_leg
yarp::os::Property left_leg_client_options;
left_leg_client_options.put("device","multipleanalogsensorsclient");
left_leg_client_options.put("remote","/" + robotPortPrefix + "/left_leg/FT");
left_leg_client_options.put("local", "/" + localPortPrefix + "/" + robotPortPrefix + "/left_leg/FT");
yarp::os::PolyDriver left_leg_clientDevice;
bool ok = left_leg_clientDevice.open(left_leg_client_options);
// Handle if ok is not true <..>


// Create client for right_leg
yarp::os::Property right_leg_client_options;
right_leg_client_options.put("device","multipleanalogsensorsclient");
right_leg_client_options.put("remote","/" + robotPortPrefix + "/right_leg/FT");
right_leg_client_options.put("local", "/" + localPortPrefix + "/" + robotPortPrefix + "/right_leg/FT");
yarp::os::PolyDriver right_leg_clientDevice;
bool ok = right_leg_clientDevice.open(right_leg_client_options);
// Handle if ok is not true <..>

// Create remapper
yarp::os::Property remapper_options;
remapper_options.put("device", "multipleanalogsensorsremapper");
yarp::os::Bottle sixAxisForceTorqueSensorsNames;
yarp::os::Bottle& sixAxisForceTorqueSensorsList = sixAxisForceTorqueSensorsNames.addList();
sixAxisForceTorqueSensorsList.addString("l_foot_rear_ft_sensor");
sixAxisForceTorqueSensorsList.addString("l_foot_front_ft_sensor");
sixAxisForceTorqueSensorsList.addString("r_foot_rear_ft_sensor");
sixAxisForceTorqueSensorsList.addString("r_foot_front_ft_sensor");
remapper_options.put("SixAxisForceTorqueSensorsNames",sixAxisForceTorqueSensorsNames.get(0));
yarp::os::PolyDriver remapperDevice;
ok = remapperDevice.open(remapper_options);
// Handle if ok is not true <..>

// Attach remapper to the clients
yarp::dev::IMultipleWrapper* imultiwrap=nullptr;
ok = remapperDevice.view(imultiwrap);
// Handle if ok is not true <..>

yarp::dev::PolyDriverList driverList;
driverList.push(&left_leg_clientDevice, "left_leg_fts");
driverList.push(&right_leg_clientDevice, "right_leg_fts");
ok = imultiwrap->attachAll(driverList);
// Handle if ok is not true <..>

// At this point, you can read FT sensors
yarp::dev::ISixAxisForceTorqueSensors* isixaxis=nullptr;
ok = remapperDevice.view(isixaxis);
// Handle if ok is not true <..>

yarp::sig::Vector measure(6).
for(int ftIdx=0; ftIdx < isixaxis->getNrOfSixAxisForceTorqueSensors(); ftIdx++)
{
    std::string sensorName;
    isixaxis->getSixAxisForceTorqueSensorName(ftIdx, sensorName);
    isixaxis->getSixAxisForceTorqueSensorMeasure(ftIdx, measure);
    std::string << "The measure of FT sensor " << sensorName << " is " << measure.toString() << std::endl;
}

With multipleanalogsensorsclientremapper

// Snippet of code to read just the FT sensors on the feet of iCub, for a robot that has two FT sensors for each feet (like iCub 3 or ergoCub)

std::string robotPortPrefix = "icub"; // or icubSim for simulated robots, this is tipically passed via an option
std::string localPortPrefix = "localCode";

// Create device to read FT sensors
yarp::os::Property options;
options.put("device","multipleanalogsensorsclientremapper");

yarp::os::Bottle sixAxisForceTorqueSensorsNames;
yarp::os::Bottle& sixAxisForceTorqueSensorsList = sixAxisForceTorqueSensorsNames.addList();
sixAxisForceTorqueSensorsList.addString("l_foot_rear_ft_sensor");
sixAxisForceTorqueSensorsList.addString("l_foot_front_ft_sensor");
sixAxisForceTorqueSensorsList.addString("r_foot_rear_ft_sensor");
sixAxisForceTorqueSensorsList.addString("r_foot_front_ft_sensor");
options.put("SixAxisForceTorqueSensorsNames",sixAxisForceTorqueSensorsNames.get(0));

yarp::os::Bottle multipleAnalogSensorsClients;
yarp::os::Bottle& multipleAnalogSensorsClientsList = multipleAnalogSensorsClients.addList();
multipleAnalogSensorsClientsList.addString("/" + robotPortPrefix + "/left_leg/FT");
multipleAnalogSensorsClientsList.addString("/" + robotPortPrefix + "/right_leg/FT");
options.put("multipleAnalogSensorsClients", multipleAnalogSensorsClients.get(0));
options.put("localPortPrefix",localPortPrefix);

yarp::os::PolyDriver device;
ok = device.open(options);


// At this point, you can read FT sensors
yarp::dev::ISixAxisForceTorqueSensors* isixaxis=nullptr;
ok = device.view(isixaxis);
// Handle if ok is not true <..>

yarp::sig::Vector measure(6).
for(int ftIdx=0; ftIdx < isixaxis->getNrOfSixAxisForceTorqueSensors(); ftIdx++)
{
    std::string sensorName;
    isixaxis->getSixAxisForceTorqueSensorName(ftIdx, sensorName);
    isixaxis->getSixAxisForceTorqueSensorMeasure(ftIdx, measure);
    std::string << "The measure of FT sensor " << sensorName << " is " << measure.toString() << std::endl;
}

@GiulioRomualdi
Copy link
Member Author

Thank you @traversaro for better clarifying the rationale behind the PR

@randaz81 randaz81 force-pushed the multipleanalogsensorsclientremapper branch from 6b00ec7 to 1151dcb Compare September 19, 2023 08:14
@randaz81
Copy link
Member

@GiulioRomualdi can you add a test for this device?
It's pretty easy since you can use another device as a template. (You'll notice that every device has a subfolder called tests with the relevant code)

Copy link
Member

@randaz81 randaz81 left a comment

Choose a reason for hiding this comment

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

Missing tests subfolder

@traversaro
Copy link
Member

A relevant test is https://github.com/robotology/yarp/blob/a454a3b2781a6761c23d0c1c8460d73cd6924e66/src/devices/controlBoardRemapper/tests/controlBoardRemapper_t1_test.cpp, that is testing the remotecontrolboardremapper, that is basically the same device for controlBoard devices.

@randaz81 randaz81 temporarily deployed to code-analysis September 19, 2023 09:18 — with GitHub Actions Inactive
@randaz81 randaz81 temporarily deployed to code-analysis September 19, 2023 09:18 — with GitHub Actions Inactive
@randaz81 randaz81 temporarily deployed to code-analysis September 19, 2023 09:18 — with GitHub Actions Inactive
@sonarcloud
Copy link

sonarcloud bot commented Sep 19, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 10 Code Smells

0.7% 0.7% Coverage
0.0% 0.0% Duplication

warning The version of Java (11.0.3) you have used to run this analysis is deprecated and we will stop accepting it soon. Please update to at least Java 17.
Read more here

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@randaz81
Copy link
Member

@GiulioRomualdi any update? Otherwise, I'm going to move this PR to the next release...

@GiulioRomualdi
Copy link
Member Author

Hi @randaz81, if it's fine with you, I can provide the test within the beginning of next week. If it's too late, we can postpone this feature in the next release

@randaz81 randaz81 force-pushed the master branch 3 times, most recently from 71900d2 to ead1caf Compare November 30, 2023 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Devices PR Type: Feat/Enh This PR adds some new feature or enhances some part of YARP Target: YARP v3.9.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants