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

Replanning trigger for the navigation stack. #144

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5bc9154
Replanning trigger for the navigation stack.
SimoneMic Apr 12, 2023
9950902
moved all navigation pertinent functions and parameters to a separate…
SimoneMic Apr 17, 2023
2d14446
removed unused dependencies
SimoneMic Apr 17, 2023
2ac5531
bugfix: Removed unused code
SimoneMic Apr 17, 2023
f5a0dbb
removed continuous print
SimoneMic Apr 17, 2023
3d6ec29
removed setStatus. Added comments in header
SimoneMic Apr 17, 2023
04a99e4
added port prefix and publish info config flag
SimoneMic Apr 18, 2023
2dfffb7
Update src/WalkingModule/app/robots/ergoCubGazeboV1/dcm_walking/commo…
SimoneMic Apr 27, 2023
d87e0c6
Update src/NavigationHelper/src/NavigationHelper.cpp
SimoneMic Apr 27, 2023
0a8c6af
removed leftovers variables and include not needed
SimoneMic Apr 27, 2023
012f9c9
Merge branch 'nav_sync' of https://github.com/SimoneMic/walking-contr…
SimoneMic Apr 27, 2023
95b59cf
navigation helper is initialized only if its conf options are found
SimoneMic Apr 27, 2023
a085571
removed Yarp stamp and clock header includes
SimoneMic Apr 27, 2023
c48bd21
updated comments and improved explainations
SimoneMic Apr 28, 2023
6725373
added thread safety for updating feet contacts deques
SimoneMic Apr 28, 2023
56e6997
added config param to switch between system and network clock for nav…
SimoneMic Apr 28, 2023
c78bb24
updated with minor improvements and comment fix
SimoneMic Apr 28, 2023
d9ab019
updateFeetDeques also in advanceReferenceSignals
SimoneMic Apr 28, 2023
8ba752d
Update m_navHelperUsed{false}
SimoneMic Apr 28, 2023
5827344
Formatting
SimoneMic Apr 28, 2023
f947612
moved closeThreads to private, added comments
SimoneMic May 2, 2023
0bd4df7
Merge branch 'robotology:master' into nav_sync
SimoneMic Jun 26, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ sampling_time 0.01
# Specify the frame to use to control the robot height. Currently, we support only the following options: com, root_link
height_reference_frame root_link

# Navigation trigger delay in seconds. Time to wait before sending the replanning command after exiting the double support stance.
navigationReplanningDelay 0.9
# Loop rate for the thread computing the navigation trigger
navigationTriggerLoopRate 100

S-Dafarra marked this conversation as resolved.
Show resolved Hide resolved
# include robot control parameters
[include ROBOT_CONTROL "./dcm_walking/joypad_control/robotControl.ini"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ namespace WalkingControllers
yarp::os::BufferedPort<yarp::sig::Vector> m_desiredUnyciclePositionPort; /**< Desired robot position port. */

bool m_newTrajectoryRequired; /**< if true a new trajectory will be merged soon. (after m_newTrajectoryMergeCounter - 2 cycles). */
bool m_newTrajectoryMerged; /**< true if a new trajectory has been just merged. */
size_t m_newTrajectoryMergeCounter; /**< The new trajectory will be merged after m_newTrajectoryMergeCounter - 2 cycles. */

bool m_useRootLinkForHeight;
Expand All @@ -155,6 +156,12 @@ namespace WalkingControllers
size_t m_feedbackAttempts;
double m_feedbackAttemptDelay;

std::thread m_navigationTriggerThread; /**< Thread for publishing the flag triggering the navigation's global planner. */
bool m_runThreads;
S-Dafarra marked this conversation as resolved.
Show resolved Hide resolved
yarp::os::BufferedPort<yarp::os::Bottle> m_replanningTriggerPort; /**< Publishes the flag triggering the navigation's global planner. */
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*/

// debug
std::unique_ptr<iCub::ctrl::Integrator> m_velocityIntegral{nullptr};

Expand Down Expand Up @@ -277,6 +284,11 @@ namespace WalkingControllers
*/
void applyGoalScaling(yarp::sig::Vector &plannerInput);

/**
* Parallel thread for publishing the trigger for the navigation's planner.
*/
void computeNavigationTrigger();

S-Dafarra marked this conversation as resolved.
Show resolved Hide resolved
public:

/**
Expand Down
96 changes: 96 additions & 0 deletions src/WalkingModule/src/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <iostream>
#include <memory>
#include <algorithm>
#include <chrono>
S-Dafarra marked this conversation as resolved.
Show resolved Hide resolved

// YARP
#include <yarp/eigen/Eigen.h>
Expand All @@ -20,6 +21,8 @@
#include <yarp/sig/Matrix.h>
#include <yarp/sig/Vector.h>
#include <yarp/os/LogStream.h>
#include <yarp/os/Stamp.h>
#include <yarp/os/NetworkClock.h>
S-Dafarra marked this conversation as resolved.
Show resolved Hide resolved

// iDynTree
#include <iDynTree/Core/VectorFixSize.h>
Expand Down Expand Up @@ -264,6 +267,20 @@ bool WalkingModule::configure(yarp::os::ResourceFinder& rf)
yarp::os::Bottle ellipseMangerOptions = rf.findGroup("FREE_SPACE_ELLIPSE_MANAGER");
trajectoryPlannerOptions.append(generalOptions);
trajectoryPlannerOptions.append(ellipseMangerOptions);
m_navigationReplanningDelay = trajectoryPlannerOptions.check("navigationReplanningDelay", yarp::os::Value(0.9)).asFloat64();
m_navigationTriggerLoopRate = trajectoryPlannerOptions.check("navigationTriggerLoopRate", yarp::os::Value(100)).asInt32();
// 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;
}

if(!m_trajectoryGenerator->initialize(trajectoryPlannerOptions))
{
yError() << "[configure] Unable to initialize the planner.";
Expand Down Expand Up @@ -442,6 +459,18 @@ bool WalkingModule::configure(yarp::os::ResourceFinder& rf)
m_qDesired.resize(m_robotControlHelper->getActuatedDoFs());
m_dqDesired.resize(m_robotControlHelper->getActuatedDoFs());

// open port for navigation trigger
std::string replanningTriggerPortPortName = "/" + getName() + "/replanning_trigger:o";
if (!m_replanningTriggerPort.open(replanningTriggerPortPortName))
{
yError() << "[WalkingModule::configure] Could not open" << replanningTriggerPortPortName << " port.";
return false;
}

// start the threads used for computing navigation needed infos
m_runThreads = true;
m_navigationTriggerThread = std::thread(&WalkingModule::computeNavigationTrigger, this);

yInfo() << "[WalkingModule::configure] Ready to play! Please prepare the robot.";

return true;
Expand Down Expand Up @@ -470,6 +499,14 @@ bool WalkingModule::close()
{
if(m_dumpData)
m_loggerPort.close();
//Close parallel threads
m_runThreads = false;
yInfo() << "Closing m_navigationTriggerThread";
if(m_navigationTriggerThread.joinable())
{
m_navigationTriggerThread.join();
m_navigationTriggerThread = std::thread();
}

// restore PID
m_robotControlHelper->getPIDHandler().restorePIDs();
Expand All @@ -480,6 +517,7 @@ bool WalkingModule::close()
// close the ports
m_rpcPort.close();
m_desiredUnyciclePositionPort.close();
m_replanningTriggerPort.close();

// close the connection with robot
if(!m_robotControlHelper->close())
Expand Down Expand Up @@ -770,6 +808,7 @@ bool WalkingModule::updateModule()
}
m_newTrajectoryRequired = false;
resetTrajectory = true;
m_newTrajectoryMerged = true;
S-Dafarra marked this conversation as resolved.
Show resolved Hide resolved
}

m_newTrajectoryMergeCounter--;
Expand Down Expand Up @@ -1751,3 +1790,60 @@ bool WalkingModule::stopWalking()
m_robotState = WalkingFSM::Stopped;
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 WalkingModule::computeNavigationTrigger()
{
bool trigger = false; //flag used to fire the wait for sending the navigation replanning trigger
yInfo() << "[WalkingModule::computeNavigationTrigger] Starting Thread";
yarp::os::NetworkClock myClock;
myClock.open("/clock", "/navigationTriggerClock");
bool enteredDoubleSupport = false, exitDoubleSupport = true;
while (m_runThreads)
{
// Block the thread until the robot is in the walking state
if (m_robotState != WalkingFSM::Walking)
{
std::this_thread::sleep_for(std::chrono::milliseconds(1000/m_navigationTriggerLoopRate));
continue;
}

//double support check
if (m_leftInContact.size()>0 && m_rightInContact.size()>0) //external consistency check
{
if (m_leftInContact[0] && m_rightInContact[0])
{
if (exitDoubleSupport)
{
enteredDoubleSupport = true;
exitDoubleSupport = false;
}
}
else
{
if (! exitDoubleSupport)
{
trigger = true; //in this way we have only one trigger each exit of double support
}
exitDoubleSupport = true;
}
}

//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
myClock.delay(m_navigationReplanningDelay);
yDebug() << "[WalkingModule::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() << "[WalkingModule::computeNavigationTrigger] Terminating thread";
}
S-Dafarra marked this conversation as resolved.
Show resolved Hide resolved