Skip to content

Commit 50a00fd

Browse files
GiulioRomualdiergocub
authored andcommitted
Add a logic to stop the robot if the goal is not set for more than a given ammount of time
1 parent 69aaa5e commit 50a00fd

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

src/WalkingModule/include/WalkingControllers/WalkingModule/Module.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ namespace WalkingControllers
6363

6464
double m_dT; /**< RFModule period. */
6565
double m_time; /**< Current time. */
66+
double m_lastSetGoalTime; /**< Time of the last set goal. */
67+
double m_maxTimeToWaitForGoal; /**< Maximum time to wait for a goal. */
6668
std::string m_robot; /**< Robot name. */
6769

6870
bool m_useMPC; /**< True if the MPC controller is used. */

src/WalkingModule/src/Module.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ bool WalkingModule::configure(yarp::os::ResourceFinder &rf)
138138
std::string goalSuffix = rf.check("goal_port_suffix", yarp::os::Value("/goal:i")).asString();
139139
m_skipDCMController = rf.check("skip_dcm_controller", yarp::os::Value(false)).asBool();
140140
m_removeZMPOffset = rf.check("remove_zmp_offset", yarp::os::Value(false)).asBool();
141+
m_maxTimeToWaitForGoal = rf.check("max_time_to_wait_for_goal", yarp::os::Value(1.0)).asFloat64();
141142

142143
m_goalScaling.resize(3);
143144
if (!YarpUtilities::getVectorFromSearchable(rf, "goal_port_scaling", m_goalScaling))
@@ -683,6 +684,17 @@ bool WalkingModule::updateModule()
683684
yError() << "[WalkingModule::updateModule] Unable to set the planner input";
684685
return false;
685686
}
687+
m_lastSetGoalTime = m_time;
688+
}
689+
else if (!m_firstRun && ((m_time - m_lastSetGoalTime) > m_maxTimeToWaitForGoal))
690+
{
691+
yWarning() << "[WalkingModule::updateModule] The goal has not been set for more than " << m_maxTimeToWaitForGoal << " seconds.";
692+
yarp::sig::Vector dummy(3, 0.0);
693+
if (!setPlannerInput(dummy))
694+
{
695+
yError() << "[WalkingModule::updateModule] Unable to set the planner input";
696+
return false;
697+
}
686698
}
687699

688700
// if a new trajectory is required check if its the time to evaluate the new trajectory or

0 commit comments

Comments
 (0)