Skip to content

Commit

Permalink
Merge pull request #3167 from randaz81/returnValue_nav
Browse files Browse the repository at this point in the history
New class for return values of interface methods PART2
  • Loading branch information
randaz81 authored Jan 29, 2025
2 parents 43ba030 + a32551f commit 331d2e0
Show file tree
Hide file tree
Showing 119 changed files with 2,290 additions and 2,171 deletions.
31 changes: 28 additions & 3 deletions doc/release/master.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,33 @@ New Features
#### `libYARP_dev`

* added new class `yarp::dev::ReturnValue`
* modified interfaces `yarp::dev::ISpeechSynthesizer`,`yarp::dev::ISpeechTranscription` to use the new class ReturnValue.

* The following interfaces have been modified to the new class ReturnValue:
ISpeechSynthesizer
ISpeechTranscription
ILocalization2D
IMap2D
INavigation2D
IOdometry2D

#### `devices`

* modified devices implementing `yarp::dev::ISpeechSynthesizer`,`yarp::dev::ISpeechTranscription` to use the new class ReturnValue.
* Updated all devices which use the interfaces employing the new class `ReturnValue`:
FakeSpeechSynthesizer
FakeSpeechTranscription
FakeNavigation
FakeLocalizer
FakeOdometry2D
Map2DStorage
SpeechTranscription_nws_yarp
SpeechTranscription_nwc_yarp
SpeechSynthesizer_nws_yarp
SpeechSynthesizer_nwc_yarp
Localization2D_nws_yarp
Localization2D_nwc_yarp
Map2D_nws_yarp
Map2D_nwc_yarp
MobileBaseVelocityControl_nws_yarp
MobileBaseVelocityControl_nwc_yarp
Navigation2D_nwc_yarp
Navigation2D_nws_yarp
Odometry2D_nws_yarp
54 changes: 27 additions & 27 deletions src/devices/fake/fakeLocalizerDevice/FakeLocalizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ namespace {
YARP_LOG_COMPONENT(FAKELOCALIZER, "yarp.device.fakeLocalizer")
}

bool FakeLocalizer::getLocalizationStatus(yarp::dev::Nav2D::LocalizationStatusEnum& status)
yarp::dev::ReturnValue FakeLocalizer::getLocalizationStatus(yarp::dev::Nav2D::LocalizationStatusEnum& status)
{
std::lock_guard<std::mutex> lock(m_mutex);
if (!locThread) { yCError(FAKELOCALIZER) << "Invalid status"; return false; }
if (!locThread) { yCError(FAKELOCALIZER) << "Invalid status"; return yarp::dev::ReturnValue::return_code::return_value_error_method_failed;; }

status = yarp::dev::Nav2D::LocalizationStatusEnum::localization_status_localized_ok;
return true;
return yarp::dev::ReturnValue_ok;
}

bool FakeLocalizer::getEstimatedPoses(std::vector<Map2DLocation>& poses)
yarp::dev::ReturnValue FakeLocalizer::getEstimatedPoses(std::vector<Map2DLocation>& poses)
{
std::lock_guard<std::mutex> lock(m_mutex);
if (!locThread) { yCError(FAKELOCALIZER) << "Invalid status"; return false; }
if (!locThread) { yCError(FAKELOCALIZER) << "Invalid status"; return yarp::dev::ReturnValue::return_code::return_value_error_method_failed;; }

poses.clear();
Map2DLocation loc;
Expand All @@ -74,56 +74,56 @@ bool FakeLocalizer::getEstimatedPoses(std::vector<Map2DLocation>& poses)
poses.push_back(newloc);
}
#endif
return true;
return yarp::dev::ReturnValue_ok;
}

bool FakeLocalizer::getCurrentPosition(Map2DLocation& loc)
yarp::dev::ReturnValue FakeLocalizer::getCurrentPosition(Map2DLocation& loc)
{
std::lock_guard<std::mutex> lock(m_mutex);
if (!locThread) { yCError(FAKELOCALIZER) << "Invalid status"; return false; }
if (!locThread) { yCError(FAKELOCALIZER) << "Invalid status"; return yarp::dev::ReturnValue::return_code::return_value_error_method_failed; }

locThread->getCurrentLoc(loc);
return true;
return yarp::dev::ReturnValue_ok;
}

bool FakeLocalizer::setInitialPose(const Map2DLocation& loc)
yarp::dev::ReturnValue FakeLocalizer::setInitialPose(const Map2DLocation& loc)
{
std::lock_guard<std::mutex> lock(m_mutex);
if (!locThread) { yCError(FAKELOCALIZER) << "Invalid status"; return false; }
if (!locThread) { yCError(FAKELOCALIZER) << "Invalid status"; return yarp::dev::ReturnValue::return_code::return_value_error_method_failed; }

locThread->initializeLocalization(loc);
return true;
return yarp::dev::ReturnValue_ok;
}

bool FakeLocalizer::getCurrentPosition(Map2DLocation& loc, yarp::sig::Matrix& cov)
yarp::dev::ReturnValue FakeLocalizer::getCurrentPosition(Map2DLocation& loc, yarp::sig::Matrix& cov)
{
std::lock_guard<std::mutex> lock(m_mutex);
if (!locThread) { yCError(FAKELOCALIZER) << "Invalid status"; return false; }
if (!locThread) { yCError(FAKELOCALIZER) << "Invalid status"; return yarp::dev::ReturnValue::return_code::return_value_error_method_failed;; }

locThread->getCurrentLoc(loc,cov);
return true;
return yarp::dev::ReturnValue_ok;
}

bool FakeLocalizer::setInitialPose(const Map2DLocation& loc, const yarp::sig::Matrix& cov)
yarp::dev::ReturnValue FakeLocalizer::setInitialPose(const Map2DLocation& loc, const yarp::sig::Matrix& cov)
{
std::lock_guard<std::mutex> lock(m_mutex);
if (!locThread) { yCError(FAKELOCALIZER) << "Invalid status"; return false; }
if (!locThread) { yCError(FAKELOCALIZER) << "Invalid status"; return yarp::dev::ReturnValue::return_code::return_value_error_method_failed;; }

locThread->initializeLocalization(loc);
return true;
return yarp::dev::ReturnValue_ok;
}

bool FakeLocalizer::getEstimatedOdometry(yarp::dev::OdometryData& odom)
yarp::dev::ReturnValue FakeLocalizer::getEstimatedOdometry(yarp::dev::OdometryData& odom)
{
std::lock_guard<std::mutex> lock(m_mutex);
if (!locThread) { yCError(FAKELOCALIZER) << "Invalid status" ; return false; }
if (!locThread) { yCError(FAKELOCALIZER) << "Invalid status" ; return yarp::dev::ReturnValue::return_code::return_value_error_method_failed;; }

Map2DLocation loc;
locThread->getCurrentLoc(loc);
odom.odom_x = loc.x;
odom.odom_y = loc.y;
odom.odom_theta = loc.theta;
return true;
return yarp::dev::ReturnValue_ok;
}

bool FakeLocalizer::open(yarp::os::Searchable& config)
Expand Down Expand Up @@ -151,20 +151,20 @@ FakeLocalizer::~FakeLocalizer()
{
}

bool FakeLocalizer::startLocalizationService()
yarp::dev::ReturnValue FakeLocalizer::startLocalizationService()
{
std::lock_guard<std::mutex> lock(m_mutex);
if (!locThread) { yCError(FAKELOCALIZER) << "Invalid status"; return false; }
if (!locThread) { yCError(FAKELOCALIZER) << "Invalid status"; return yarp::dev::ReturnValue::return_code::return_value_error_method_failed;; }

return true;
return yarp::dev::ReturnValue_ok;
}

bool FakeLocalizer::stopLocalizationService()
yarp::dev::ReturnValue FakeLocalizer::stopLocalizationService()
{
std::lock_guard<std::mutex> lock(m_mutex);
if (!locThread) { yCError(FAKELOCALIZER) << "Invalid status"; return false; }
if (!locThread) { yCError(FAKELOCALIZER) << "Invalid status"; return yarp::dev::ReturnValue::return_code::return_value_error_method_failed;; }

return true;
return yarp::dev::ReturnValue_ok;
}

bool FakeLocalizer::close()
Expand Down
70 changes: 10 additions & 60 deletions src/devices/fake/fakeLocalizerDevice/FakeLocalizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,64 +72,14 @@ class FakeLocalizer :
virtual bool close() override;

public:
/**
* Gets the current status of the localization task.
* @return true/false
*/
bool getLocalizationStatus(yarp::dev::Nav2D::LocalizationStatusEnum& status) override;

/**
* Gets a set of pose estimates computed by the localization algorithm.
* @return true/false
*/
bool getEstimatedPoses(std::vector<yarp::dev::Nav2D::Map2DLocation>& poses) override;

/**
* Gets the current position of the robot w.r.t world reference frame
* @param loc the location of the robot
* @return true/false
*/
bool getCurrentPosition(yarp::dev::Nav2D::Map2DLocation& loc) override;

/**
* Sets the initial pose for the localization algorithm which estimates the current position of the robot w.r.t world reference frame.
* @param loc the location of the robot
* @return true/false
*/
bool setInitialPose(const yarp::dev::Nav2D::Map2DLocation& loc) override;

/**
* Sets the initial pose for the localization algorithm which estimates the current position of the robot w.r.t world reference frame.
* @param loc the location of the robot
* @param cov the 3x3 covariance matrix
* @return true/false
*/
virtual bool setInitialPose(const yarp::dev::Nav2D::Map2DLocation& loc, const yarp::sig::Matrix& cov) override;

/**
* Gets the current position of the robot w.r.t world reference frame, plus the covariance
* @param loc the location of the robot
* @param cov the 3x3 covariance matrix
* @return true/false
*/
virtual bool getCurrentPosition(yarp::dev::Nav2D::Map2DLocation& loc, yarp::sig::Matrix& cov) override;

/**
* Gets the estimated odometry the robot, including its velocity expressed in the world and in the local reference frame.
* @param loc the estimated odometry.
* @return true/false
*/
virtual bool getEstimatedOdometry(yarp::dev::OdometryData& odom) override;

/**
* Starts the localization service
* @return true/false
*/
virtual bool startLocalizationService() override;

/**
* Stops the localization service
* @return true/false
*/
virtual bool stopLocalizationService() override;
//methods inherited from yarp::dev::Nav2D::ILocalization2D
yarp::dev::ReturnValue getLocalizationStatus(yarp::dev::Nav2D::LocalizationStatusEnum& status) override;
yarp::dev::ReturnValue getEstimatedPoses(std::vector<yarp::dev::Nav2D::Map2DLocation>& poses) override;
yarp::dev::ReturnValue getCurrentPosition(yarp::dev::Nav2D::Map2DLocation& loc) override;
yarp::dev::ReturnValue setInitialPose(const yarp::dev::Nav2D::Map2DLocation& loc) override;
yarp::dev::ReturnValue setInitialPose(const yarp::dev::Nav2D::Map2DLocation& loc, const yarp::sig::Matrix& cov) override;
yarp::dev::ReturnValue getCurrentPosition(yarp::dev::Nav2D::Map2DLocation& loc, yarp::sig::Matrix& cov) override;
yarp::dev::ReturnValue getEstimatedOdometry(yarp::dev::OdometryData& odom) override;
yarp::dev::ReturnValue startLocalizationService() override;
yarp::dev::ReturnValue stopLocalizationService() override;
};
66 changes: 33 additions & 33 deletions src/devices/fake/fakeNavigationDevice/FakeNavigation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,122 +43,122 @@ bool FakeNavigation:: close()
return true;
}

bool FakeNavigation::gotoTargetByAbsoluteLocation(Map2DLocation loc)
ReturnValue FakeNavigation::gotoTargetByAbsoluteLocation(Map2DLocation loc)
{
if (m_status == NavigationStatusEnum::navigation_status_idle)
{
m_status = NavigationStatusEnum::navigation_status_moving;
m_absgoal_loc = loc;
m_time_counter= this->m_navigation_time;
}
return true;
return ReturnValue_ok;
}

bool FakeNavigation::gotoTargetByRelativeLocation(double x, double y, double theta)
ReturnValue FakeNavigation::gotoTargetByRelativeLocation(double x, double y, double theta)
{
yCInfo(FAKENAVIGATION) << "gotoTargetByRelativeLocation not yet implemented";
return true;
return ReturnValue_ok;
}

bool FakeNavigation::gotoTargetByRelativeLocation(double x, double y)
ReturnValue FakeNavigation::gotoTargetByRelativeLocation(double x, double y)
{
yCInfo(FAKENAVIGATION) << "gotoTargetByRelativeLocation not yet implemented";
return true;
return ReturnValue_ok;
}

bool FakeNavigation::followPath(const yarp::dev::Nav2D::Map2DPath& path)
ReturnValue FakeNavigation::followPath(const yarp::dev::Nav2D::Map2DPath& path)
{
yCInfo(FAKENAVIGATION) << "followPath not yet implemented";
return true;
return ReturnValue_ok;
}

bool FakeNavigation::applyVelocityCommand(double x_vel, double y_vel, double theta_vel, double timeout)
ReturnValue FakeNavigation::applyVelocityCommand(double x_vel, double y_vel, double theta_vel, double timeout)
{
m_control_out.linear_xvel = x_vel;
m_control_out.linear_yvel = y_vel;
m_control_out.angular_vel = theta_vel;
m_control_out.timeout = timeout;
m_control_out.reception_time = yarp::os::Time::now();
return true;
return ReturnValue_ok;
}

bool FakeNavigation::getLastVelocityCommand(double& x_vel, double& y_vel, double& theta_vel)
ReturnValue FakeNavigation::getLastVelocityCommand(double& x_vel, double& y_vel, double& theta_vel)
{
double current_time = yarp::os::Time::now();
x_vel = m_control_out.linear_xvel;
y_vel = m_control_out.linear_yvel;
theta_vel = m_control_out.angular_vel;
return true;
return ReturnValue_ok;
}

bool FakeNavigation::stopNavigation()
ReturnValue FakeNavigation::stopNavigation()
{
m_status=NavigationStatusEnum::navigation_status_idle;
m_absgoal_loc=Map2DLocation();
return true;
return ReturnValue_ok;
}

bool FakeNavigation::suspendNavigation(double time)
ReturnValue FakeNavigation::suspendNavigation(double time)
{
if (m_status == NavigationStatusEnum::navigation_status_moving)
{
m_status=NavigationStatusEnum::navigation_status_paused;
}
return true;
return ReturnValue_ok;
}

bool FakeNavigation::resumeNavigation()
ReturnValue FakeNavigation::resumeNavigation()
{
if (m_status == NavigationStatusEnum::navigation_status_paused)
{
m_status = NavigationStatusEnum::navigation_status_moving;
}
return true;
return ReturnValue_ok;
}

bool FakeNavigation::getAllNavigationWaypoints(yarp::dev::Nav2D::TrajectoryTypeEnum trajectory_type, yarp::dev::Nav2D::Map2DPath& waypoints)
ReturnValue FakeNavigation::getAllNavigationWaypoints(yarp::dev::Nav2D::TrajectoryTypeEnum trajectory_type, yarp::dev::Nav2D::Map2DPath& waypoints)
{
yCInfo(FAKENAVIGATION) << "getAllNavigationWaypoints not yet implemented";
return true;
return ReturnValue_ok;
}

bool FakeNavigation::getCurrentNavigationWaypoint(Map2DLocation& curr_waypoint)
ReturnValue FakeNavigation::getCurrentNavigationWaypoint(Map2DLocation& curr_waypoint)
{
yCInfo(FAKENAVIGATION) << "getCurrentNavigationWaypoint not yet implemented";
return true;
return ReturnValue_ok;
}

bool FakeNavigation::getCurrentNavigationMap(yarp::dev::Nav2D::NavigationMapTypeEnum map_type, MapGrid2D& map)
ReturnValue FakeNavigation::getCurrentNavigationMap(yarp::dev::Nav2D::NavigationMapTypeEnum map_type, MapGrid2D& map)
{
yCInfo(FAKENAVIGATION) << "getCurrentNavigationMap not yet implemented";
return true;
return ReturnValue_ok;
}

bool FakeNavigation::getNavigationStatus(yarp::dev::Nav2D::NavigationStatusEnum& status)
ReturnValue FakeNavigation::getNavigationStatus(yarp::dev::Nav2D::NavigationStatusEnum& status)
{
status = m_status;
return true;
return ReturnValue_ok;
}

bool FakeNavigation::getAbsoluteLocationOfCurrentTarget(Map2DLocation& target)
ReturnValue FakeNavigation::getAbsoluteLocationOfCurrentTarget(Map2DLocation& target)
{
target=m_absgoal_loc;
return true;
target = m_absgoal_loc;
return ReturnValue_ok;
}

bool FakeNavigation::recomputeCurrentNavigationPath()
ReturnValue FakeNavigation::recomputeCurrentNavigationPath()
{
if (m_status == NavigationStatusEnum::navigation_status_moving)
{
//do something
}
return true;
return ReturnValue_ok;
}

bool FakeNavigation::getRelativeLocationOfCurrentTarget(double& x, double& y, double& theta)
ReturnValue FakeNavigation::getRelativeLocationOfCurrentTarget(double& x, double& y, double& theta)
{
yCInfo(FAKENAVIGATION) << "getRelativeLocationOfCurrentTarget not yet implemented";
return true;
return ReturnValue_ok;
}

bool FakeNavigation::threadInit()
Expand Down
Loading

0 comments on commit 331d2e0

Please sign in to comment.