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

Velocity Command Ignored Checking #321

Merged
merged 10 commits into from
Jul 31, 2023
Merged

Conversation

cli18
Copy link
Contributor

@cli18 cli18 commented Jul 13, 2023

Problem Summary:
When the robot is disabled/not moving due to hardware/firmware issues or obstacles, and the planner keeps feeding non-zero velocity commands to the robot, we need to inform the users know something is wrong with the robot that it is ignoring cmd_vel.

Feature:
This is an implementation of the velocity ignored checking and error displaying feature. When the robot is not moving for N seconds(set by a parameter) while the planner keeps publishing non-zero commands, it will output an error and fatal message on the ROS console and sends a error code. Velocity command ignored check is performed every time we got an new velocity command from the planner.

If user would like to enable the feature, change the cmd_vel_ignored_tolerance parameter to be higher than zero. Otherwise, set a value below zero.

@siferati siferati requested review from corot and siferati July 13, 2023 03:27
@siferati siferati marked this pull request as ready for review July 13, 2023 03:29
@cli18 cli18 requested review from siferati and corot July 18, 2023 04:14
* @param cmd_velocity the latest cmd_vel being published to the robot
* @return true if cmd_vel is being ignored by the robot longer than tolerance time, false otherwise
*/
bool checkVelocityIgnore(const geometry_msgs::Twist& cmd_velocity);
Copy link
Collaborator

@corot corot Jul 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: a bit more precise; and cmd_vel is the conventional name we use

Suggested change
bool checkVelocityIgnore(const geometry_msgs::Twist& cmd_velocity);
bool checkCmdVelIgnored(const geometry_msgs::Twist& cmd_vel);

Comment on lines 422 to 423
// check if robot ignores velocity command
if (robot_ignore_vel_enabled && checkVelocityIgnore(cmd_vel_stamped.twist))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// check if robot ignores velocity command
if (robot_ignore_vel_enabled && checkVelocityIgnore(cmd_vel_stamped.twist))
// check if robot is ignoring velocity commands
if (robot_ignore_vel_enabled && checkVelocityIgnore(cmd_vel_stamped.twist))


// check if the velocity ignore check is enabled or not
bool robot_ignore_vel_enabled = (robot_ignore_check_tolerance_ > 0.0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: don't need ()

const double cmd_linear = std::hypot(cmd_velocity.linear.x, cmd_velocity.linear.y);
const double cmd_angular = std::abs(cmd_velocity.angular.z);

bool cmd_is_not_zero = (cmd_linear > 0.01 || cmd_angular > 0.01);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: this is forcing u to make a double negation on the if below (avoid contorted logic whenever possible)

// check if robot ignores the cmd_vel
double ignored_duration = (ros::Time::now() - first_ignored_time_).toSec();
ROS_WARN_THROTTLE(1,
"Robot ignores velocity command for %.2f seconds.\n The cmd_vel being ignored is: (x=%.2f, "
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Robot ignores velocity command for %.2f seconds.\n The cmd_vel being ignored is: (x=%.2f, "
"Robot ignores velocity command for %.2f seconds (commanded velocity: x=%.2f, "

if (ignored_duration > robot_ignore_check_tolerance_)
{
// the robot is ignoring the velocity command more the threshold time
ROS_ERROR("Robot is disabled and the time it ignored velocity command exceeded the tolerance time: %.2f seconds",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

F: we don't know why is ignoring vel commands, so better not to make statements like "robot is disabled" can be off, can be blocked against a wall,,,, we don't know

Copy link
Collaborator

@corot corot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

much better, but still needs some work

general comment: I think here "is ignoring" makes more sense than "ignores" (but u live in USA, so i trust your criteria)

mbf_abstract_nav/src/abstract_controller_execution.cpp Outdated Show resolved Hide resolved
mbf_abstract_nav/src/abstract_controller_execution.cpp Outdated Show resolved Hide resolved
mbf_abstract_nav/src/abstract_controller_execution.cpp Outdated Show resolved Hide resolved
mbf_abstract_nav/src/abstract_controller_execution.cpp Outdated Show resolved Hide resolved
mbf_abstract_nav/src/abstract_controller_execution.cpp Outdated Show resolved Hide resolved
mbf_abstract_nav/src/abstract_controller_execution.cpp Outdated Show resolved Hide resolved
mbf_abstract_nav/src/controller_action.cpp Outdated Show resolved Hide resolved
@cli18 cli18 requested review from corot and siferati July 19, 2023 02:52
@cli18 cli18 changed the title Velocity Command Checking for Disabled Robot Velocity Command Ignored Checking Jul 20, 2023
const double cmd_linear = std::hypot(cmd_vel.linear.x, cmd_vel.linear.y);
const double cmd_angular = std::abs(cmd_vel.angular.z);

const bool cmd_is_zero = (cmd_linear < 0.01 && cmd_angular < 0.01);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: maybe use 1e-3 here too?
S: I think u can remove the brackets (not 100% sure)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested without the brackets and it was working fine. So I removed it.

// the robot is ignoring the velocity command more the threshold time
ROS_ERROR("Robot is ignoring velocity command for more than the tolerance time: %.2f seconds",
cmd_vel_ignored_tolerance_);
return true; // return true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return true; // return true
return true;



Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra line?

@cli18 cli18 requested a review from corot July 24, 2023 01:02
@@ -185,6 +186,63 @@ void AbstractControllerExecution::setVelocityCmd(const geometry_msgs::TwistStamp
// TODO so there should be no loss of information in the feedback stream
}

bool AbstractControllerExecution::checkCmdVelIgnored(const geometry_msgs::Twist& cmd_vel)
{
// check if the velocity ignore check is enabled or not
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// check if the velocity ignore check is enabled or not
// check if the velocity ignored check is enabled or not

Comment on lines 194 to 198
// set to zero if not already zero
if (!first_ignored_time_.is_zero())
{
first_ignored_time_ = ros::Time();
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

F: not needed if we are not checking vel ignored

// velocity is not being ignored
if (!robot_stopped || cmd_is_zero)
{
// set to zero if not already zero
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

F: this comment says the same as the code. Write comments only to clarify non-obvious steps

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same goes for the next 2 comments

first_ignored_time_ = ros::Time::now();
}

// check if robot ignores the cmd_vel
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

F: comment is wrong. you already know that the robot is ignoring

@@ -310,6 +310,14 @@ void ControllerAction::runImpl(GoalHandle &goal_handle, AbstractControllerExecut
goal_handle.setAborted(result, result.message);
break;

case AbstractControllerExecution::ROBOT_DISABLED:
ROS_FATAL_STREAM_NAMED(name_, "Robot ignored velocity commands for more than tolerance time");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

F: You will have almost the same error log twice

Copy link
Collaborator

@corot corot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

almost there...

@cli18 cli18 requested a review from corot July 25, 2023 01:15
@@ -234,6 +242,9 @@ namespace mbf_abstract_nav
//! The time the controller responded with a success output (output < 10).
ros::Time last_valid_cmd_time_;

//! The first time when the robot is ignoring velocity command
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//! The first time when the robot is ignoring velocity command
//! The time when the robot started ignoring velocity commands

Copy link
Collaborator

@corot corot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good!

I added some extra suggestion

}

const double ignored_duration = (ros::Time::now() - first_ignored_time_).toSec();
ROS_WARN_THROTTLE(1,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: maybe this should go after the error (line 234) so you don't show both WARN and ERROR together

@corot corot merged commit ac5adb4 into naturerobots:master Jul 31, 2023
3 of 5 checks passed
@cli18 cli18 deleted the cl/vel_checking branch August 1, 2023 00:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants