-
Notifications
You must be signed in to change notification settings - Fork 46
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
Replanning trigger for the navigation stack. #144
Open
SimoneMic
wants to merge
22
commits into
robotology:master
Choose a base branch
from
SimoneMic:nav_sync
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
5bc9154
Replanning trigger for the navigation stack.
SimoneMic 9950902
moved all navigation pertinent functions and parameters to a separate…
SimoneMic 2d14446
removed unused dependencies
SimoneMic 2ac5531
bugfix: Removed unused code
SimoneMic f5a0dbb
removed continuous print
SimoneMic 3d6ec29
removed setStatus. Added comments in header
SimoneMic 04a99e4
added port prefix and publish info config flag
SimoneMic 2dfffb7
Update src/WalkingModule/app/robots/ergoCubGazeboV1/dcm_walking/commo…
SimoneMic d87e0c6
Update src/NavigationHelper/src/NavigationHelper.cpp
SimoneMic 0a8c6af
removed leftovers variables and include not needed
SimoneMic 012f9c9
Merge branch 'nav_sync' of https://github.com/SimoneMic/walking-contr…
SimoneMic 95b59cf
navigation helper is initialized only if its conf options are found
SimoneMic a085571
removed Yarp stamp and clock header includes
SimoneMic c48bd21
updated comments and improved explainations
SimoneMic 6725373
added thread safety for updating feet contacts deques
SimoneMic 56e6997
added config param to switch between system and network clock for nav…
SimoneMic c78bb24
updated with minor improvements and comment fix
SimoneMic d9ab019
updateFeetDeques also in advanceReferenceSignals
SimoneMic 8ba752d
Update m_navHelperUsed{false}
SimoneMic 5827344
Formatting
SimoneMic f947612
moved closeThreads to private, added comments
SimoneMic 0bd4df7
Merge branch 'robotology:master' into nav_sync
SimoneMic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Copyright (C) 2019 Fondazione Istituto Italiano di Tecnologia (IIT) | ||
# All Rights Reserved. | ||
# Authors: Giulio Romualdi <giulio.romualdi@iit.it> | ||
|
||
add_walking_controllers_library( | ||
NAME NavigationHelper | ||
SOURCES src/NavigationHelper.cpp | ||
PUBLIC_HEADERS include/WalkingControllers/NavigationHelper/NavigationHelper.h | ||
PUBLIC_LINK_LIBRARIES WalkingControllers::YarpUtilities WalkingControllers::iDynTreeUtilities WalkingControllers::StdUtilities ctrlLib | ||
PRIVATE_LINK_LIBRARIES Eigen3::Eigen) |
69 changes: 69 additions & 0 deletions
69
src/NavigationHelper/include/WalkingControllers/NavigationHelper/NavigationHelper.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* @file NavigationHelper.h | ||
* @authors Simone Micheletti <simone.micheletti@iit.it> | ||
* @copyright 2023 iCub Facility - Istituto Italiano di Tecnologia | ||
* Released under the terms of the LGPLv2.1 or later, see LGPL.TXT | ||
* @date 2023 | ||
*/ | ||
|
||
#ifndef NAVIGATION_HELPER__HPP | ||
#define NAVIGATION_HELPER__HPP | ||
|
||
#include <yarp/os/BufferedPort.h> | ||
#include <yarp/os/Bottle.h> | ||
#include <atomic> | ||
#include <thread> | ||
#include <deque> | ||
#include <mutex> | ||
|
||
namespace WalkingControllers | ||
{ | ||
class NavigationHelper | ||
{ | ||
private: | ||
yarp::os::BufferedPort<yarp::os::Bottle> m_replanningTriggerPort; /**< Publishes the flag triggering the navigation's global planner. */ | ||
std::atomic<bool> m_runThreads{false}; /**< Global flag that allows the looping of the threads. */ | ||
std::deque<bool> m_leftInContact; /**< Copy of the deques in Module of the left feet contacts status. */ | ||
std::deque<bool> m_rightInContact; /**< Copy of the deques in Module of the left feet contacts status. */ | ||
double m_navigationReplanningDelay; /**< Delay in seconds of how much to wait before sending the trigger to the navigation stack after exiting double support. */ | ||
int m_navigationTriggerLoopRate; /**< Loop rate for the thread computing the navigation trigger*/ | ||
bool m_publishInfo; /**< Flag to whether publish information. */ | ||
std::thread m_navigationTriggerThread; /**< Thread for publishing the flag triggering the navigation's global planner. */ | ||
std::mutex m_updateFeetMutex; | ||
bool m_simulationMode{false}; /**< Flag that syncs the trigger delay with the external clock if in simulation. */ | ||
|
||
const std::string m_portPrefix = "/navigation_helper"; | ||
|
||
/** | ||
* Function launched by the looping thread | ||
*/ | ||
void computeNavigationTrigger(); | ||
|
||
public: | ||
NavigationHelper(); | ||
~NavigationHelper(); | ||
|
||
/** | ||
* Close the Navigation Helper Threads and ports | ||
* @return true/false in case of success/failure. | ||
*/ | ||
bool closeThreads(); | ||
|
||
/** | ||
* Close the Navigation Helper Threads and ports | ||
* @return true/false in case of success/failure. | ||
*/ | ||
bool closeHelper(); | ||
|
||
/** | ||
* Initialize the Navigation Helper | ||
* @param config yarp searchable object of the configuration. | ||
* @return true/false in case of success/failure. | ||
*/ | ||
bool init(const yarp::os::Searchable& config); | ||
|
||
bool updateFeetDeques(const std::deque<bool> &left, const std::deque<bool> &right); | ||
}; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
/** | ||
* @file NavigationHelper.cpp | ||
* @authors Simone Micheletti <simone.micheletti@iit.it> | ||
* @copyright 2023 iCub Facility - Istituto Italiano di Tecnologia | ||
* Released under the terms of the LGPLv2.1 or later, see LGPL.TXT | ||
* @date 2023 | ||
*/ | ||
|
||
#include <iostream> | ||
#include <thread> | ||
#include <WalkingControllers/NavigationHelper/NavigationHelper.h> | ||
|
||
#include <WalkingControllers/YarpUtilities/Helper.h> | ||
|
||
|
||
using namespace WalkingControllers; | ||
|
||
NavigationHelper::NavigationHelper() | ||
{ | ||
} | ||
|
||
NavigationHelper::~NavigationHelper() | ||
{ | ||
} | ||
|
||
bool NavigationHelper::closeThreads() | ||
{ | ||
//Close parallel threads | ||
if (m_runThreads) | ||
{ | ||
m_runThreads = false; | ||
|
||
yInfo() << "Closing m_navigationTriggerThread"; | ||
if(m_navigationTriggerThread.joinable()) | ||
{ | ||
m_navigationTriggerThread.join(); | ||
m_navigationTriggerThread = std::thread(); | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
bool NavigationHelper::closeHelper() | ||
{ | ||
try | ||
{ | ||
//close threads first | ||
if (m_runThreads) | ||
{ | ||
closeThreads(); | ||
} | ||
//close ports | ||
if(!m_replanningTriggerPort.isClosed()) | ||
m_replanningTriggerPort.close(); | ||
} | ||
catch(const std::exception& e) | ||
{ | ||
std::cerr << e.what() << std::endl; | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool NavigationHelper::init(const yarp::os::Searchable& config) | ||
{ | ||
m_navigationReplanningDelay = config.check("navigationReplanningDelay", yarp::os::Value(0.9)).asFloat64(); | ||
m_navigationTriggerLoopRate = config.check("navigationTriggerLoopRate", yarp::os::Value(100)).asInt32(); | ||
m_publishInfo = config.check("publishNavigationInfo", yarp::os::Value(false)).asBool(); | ||
m_simulationMode = config.check("simulationMode", yarp::os::Value(false)).asBool(); | ||
if (config.check("plannerMode", yarp::os::Value("manual")).asString() == "navigation") | ||
{ | ||
//if in navigation mode we need this parameter to be true | ||
m_publishInfo = true; | ||
} | ||
if (!m_publishInfo) | ||
{ //exit the funnction if the infos are not needed | ||
yInfo() << "[NavigationHelper::init] Configuring NavigationHelper without publishing infos on ports "; | ||
return true; | ||
} | ||
|
||
// format check | ||
if (m_navigationTriggerLoopRate<=0) | ||
{ | ||
yError() << "[configure] navigationTriggerLoopRate must be strictly positive, instead is: " << m_navigationTriggerLoopRate; | ||
return false; | ||
} | ||
if (m_navigationReplanningDelay<0) | ||
{ | ||
yError() << "[configure] navigationTriggerLoopRate must be positive, instead is: " << m_navigationReplanningDelay; | ||
return false; | ||
} | ||
|
||
std::string replanningTriggerPortPortName = m_portPrefix + "/replanning_trigger:o"; | ||
if (!m_replanningTriggerPort.open(replanningTriggerPortPortName)) | ||
{ | ||
yError() << "[NavigationHelper::init] Could not open" << replanningTriggerPortPortName << " port."; | ||
return false; | ||
} | ||
|
||
m_runThreads = true; | ||
m_navigationTriggerThread = std::thread(&NavigationHelper::computeNavigationTrigger, this); | ||
return true; | ||
} | ||
|
||
// This thread synchronizes the walking-controller with the navigation stack. | ||
// Writes on a port a boolean value when to replan the path | ||
void NavigationHelper::computeNavigationTrigger() | ||
{ | ||
if (!m_publishInfo) | ||
{ //exit the function if the infos are not needed | ||
return; | ||
} | ||
bool trigger = false; //flag used to fire the wait for sending the navigation replanning trigger | ||
yInfo() << "[NavigationHelper::computeNavigationTrigger] Starting Thread"; | ||
yarp::os::NetworkClock myClock; | ||
if (m_simulationMode) | ||
{ | ||
myClock.open("/clock", "/navigationTriggerClock"); | ||
} | ||
bool enteredDoubleSupport = false, exitDoubleSupport = true; | ||
while (m_runThreads) | ||
{ | ||
{ | ||
std::unique_lock<std::mutex> lock(m_updateFeetMutex); | ||
if (m_leftInContact.size()>0 && m_rightInContact.size()>0) //external consistency check | ||
{ | ||
if (m_leftInContact.at(0) && m_rightInContact.at(0)) //double support check | ||
{ | ||
if (exitDoubleSupport) | ||
{ | ||
enteredDoubleSupport = true; | ||
exitDoubleSupport = false; | ||
} | ||
} | ||
else | ||
{ | ||
if (! exitDoubleSupport) | ||
SimoneMic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
trigger = true; //in this way we have only one trigger each exit of double support | ||
} | ||
exitDoubleSupport = true; | ||
} | ||
} | ||
else | ||
{ | ||
trigger = false; | ||
} | ||
} | ||
|
||
//send the replanning trigger after a certain amount of seconds | ||
if (trigger) | ||
{ | ||
trigger = false; | ||
//waiting -> could make it dependant by the current swing step duration | ||
//if in simulation we need to sync the clock, we can't use the system clock | ||
if (m_simulationMode) | ||
{ | ||
myClock.delay(m_navigationReplanningDelay); | ||
} | ||
else | ||
{ | ||
std::this_thread::sleep_for(std::chrono::duration<double, std::milli>(m_navigationReplanningDelay*1000)); | ||
S-Dafarra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
yInfo() << "[NavigationHelper::computeNavigationTrigger] Triggering navigation replanning"; | ||
auto& b = m_replanningTriggerPort.prepare(); | ||
b.clear(); | ||
b.add((yarp::os::Value)true); //send the planning trigger | ||
m_replanningTriggerPort.write(); | ||
} | ||
|
||
std::this_thread::sleep_for(std::chrono::milliseconds(1000/m_navigationTriggerLoopRate)); | ||
} | ||
yInfo() << "[NavigationHelper::computeNavigationTrigger] Terminated thread"; | ||
} | ||
|
||
|
||
bool NavigationHelper::updateFeetDeques(const std::deque<bool> &left, const std::deque<bool> &right) | ||
{ | ||
std::unique_lock<std::mutex> lock(m_updateFeetMutex); | ||
m_leftInContact = left; | ||
m_rightInContact = right; | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/WalkingModule/app/robots/ergoCubGazeboV1/dcm_walking/common/navigation.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Navigation trigger delay in seconds. Time to wait before sending the replanning command after exiting the double support stance. | ||
navigationReplanningDelay 0.9 | ||
# Loop rate in hertz for the thread computing the navigation trigger | ||
navigationTriggerLoopRate 100 #Hz | ||
|
||
# Planner Mode: manual i.e. typical utilization of the planner for joystick use - navigation i.e. path following behavior | ||
# If in NAVIGATION mode (1), the type of the controller also specifies the behaviour of the planner: | ||
# A- in direct mode the planner behaves like an omnidirectional floating base that interpolates the path. | ||
# B- in personFollowing it tries to follow the path like an unicycle using state feedback linearization | ||
plannerMode navigation | ||
|
||
# Flag to publish Navigation info anyway (indipendently by the plannerMode) | ||
publishNavigationInfo 1 | ||
|
||
# Set to 0 if on the real robot - to 1 if in simulation on Gazebo | ||
simulationMode 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably also this can be private.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes and I would also add in the destructor (the same is valid for
closeHelper
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have moved it to private and added/fixed some comments/descriptions.
The destructor should never be called inside
closeThreads()
, since the ports could still be open.In
closeHelper()
I don't see the reason to call the destructor inside a class method, since we are not dealing with special manual memory management. I would avoid that and let the owner handle it.