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

Fix behaviour of MultipleAnalogSensor get**Name methods in nested models #633

Merged
merged 2 commits into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format of this document is based on [Keep a Changelog](https://keepachangelo

## [Unreleased]

### Fixed
- Fix behaviour of MultipleAnalogSensor `get**Name` methods in nested models (https://github.com/robotology/gazebo-yarp-plugins/pull/633).

## [4.5.0] - 2022-08-23

### Added
Expand Down
16 changes: 16 additions & 0 deletions libraries/common/include/GazeboYarpPlugins/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ namespace GazeboYarpPlugins {
return false;
}
}

/**
* \brief Get last part of string after separator
* \param[in] fullString the full string
* \param[in] separator separator string
* \return lastPart the last part of the string, or the fullString if the seperator is not found
*/
inline std::string lastPartOfStringAfterSeparator(std::string const &fullString, std::string const &separator)
{
auto pos = fullString.find_last_of(separator);
if (pos == std::string::npos) {
return fullString;
} else {
return fullString.substr(pos + separator.size() - 1);
}
}
}


Expand Down
3 changes: 2 additions & 1 deletion plugins/forcetorque/src/ForceTorqueDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "ForceTorqueDriver.h"
#include <GazeboYarpPlugins/Handler.hh>
#include <GazeboYarpPlugins/common.h>

#include <boost/bind/bind.hpp>
#include <gazebo/sensors/ForceTorqueSensor.hh>
Expand Down Expand Up @@ -63,7 +64,7 @@ bool GazeboYarpForceTorqueDriver::open(yarp::os::Searchable& config)
//Get gazebo pointers
std::string sensorScopedName(config.find(YarpForceTorqueScopedName.c_str()).asString().c_str());

m_sensorName = config.find("sensor_name").asString();
m_sensorName = GazeboYarpPlugins::lastPartOfStringAfterSeparator(config.find("sensor_name").asString(), "::");
m_frameName = m_sensorName;

m_parentSensor = dynamic_cast<gazebo::sensors::ForceTorqueSensor*>(GazeboYarpPlugins::Handler::getHandler()->getSensor(sensorScopedName));
Expand Down
4 changes: 2 additions & 2 deletions plugins/imu/src/IMUDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ bool GazeboYarpIMUDriver::open(yarp::os::Searchable& config)
std::string sensorScopedName(config.find(YarpIMUScopedName).asString());
std::string sensorName(config.find("sensor_name").asString());

m_sensorName=sensorName;
m_frameName=sensorName;
m_sensorName = GazeboYarpPlugins::lastPartOfStringAfterSeparator(sensorName, "::");
m_frameName = GazeboYarpPlugins::lastPartOfStringAfterSeparator(sensorName, "::");

m_parentSensor = dynamic_cast<gazebo::sensors::ImuSensor*>(GazeboYarpPlugins::Handler::getHandler()->getSensor(sensorScopedName));

Expand Down