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

[Base] check the execution time of main loop #578

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -19,6 +19,9 @@ class AerialRobotBase
void mainFunc(const ros::TimerEvent & e);

private:
bool param_verbose_;
double main_rate_;

ros::NodeHandle nh_;
ros::NodeHandle nhp_;
ros::Timer main_timer_;
Expand Down
28 changes: 18 additions & 10 deletions aerial_robot_base/src/aerial_robot_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ AerialRobotBase::AerialRobotBase(ros::NodeHandle nh, ros::NodeHandle nh_private)
navigator_loader_("aerial_robot_control", "aerial_robot_navigation::BaseNavigator")
{

bool param_verbose;
nhp_.param ("param_verbose", param_verbose, true);

double main_rate;
nhp_.param ("main_rate", main_rate, 0.0);
nhp_.param ("param_verbose", param_verbose_, true);
nhp_.param ("main_rate", main_rate_, 0.0);

// robot model
robot_model_ros_ = boost::make_shared<aerial_robot_model::RobotModelRos>(nh_, nhp_);
Expand Down Expand Up @@ -38,29 +35,29 @@ AerialRobotBase::AerialRobotBase(ros::NodeHandle nh, ros::NodeHandle nh_private)
ROS_DEBUG("use default class for flight navigation: aerial_robot_navigation::BaseNavigator");
navigator_ = boost::make_shared<aerial_robot_navigation::BaseNavigator>();
}
navigator_->initialize(nh_, nhp_, robot_model, estimator_, 1 / main_rate);
navigator_->initialize(nh_, nhp_, robot_model, estimator_, 1 / main_rate_);

// controller
try
{
std::string aerial_robot_control_name;
nh_.param ("aerial_robot_control_name", aerial_robot_control_name, std::string("aerial_robot_control/flatness_pid"));
controller_ = controller_loader_.createInstance(aerial_robot_control_name);
controller_->initialize(nh_, nhp_, robot_model, estimator_, navigator_, 1 / main_rate);
controller_->initialize(nh_, nhp_, robot_model, estimator_, navigator_, 1 / main_rate_);
}
catch(pluginlib::PluginlibException& ex)
{
ROS_ERROR("The plugin failed to load for some reason. Error: %s", ex.what());
}

if(param_verbose) cout << nhp_.getNamespace() << ": main_rate is " << main_rate << endl;
if(main_rate <= 0)
if(param_verbose_) cout << nhp_.getNamespace() << ": main_rate is " << main_rate_ << endl;
if(main_rate_ <= 0)
ROS_ERROR_STREAM("mian rate is negative, can not run the main timer");
else
{
// note1: separate the thread for main control (including navigation) loop to guarantee a relatively stable loop rate

ros::TimerOptions ops(ros::Duration(1.0 / main_rate),
ros::TimerOptions ops(ros::Duration(1.0 / main_rate_),
boost::bind(&AerialRobotBase::mainFunc, this, _1),
&main_loop_queue_);
main_timer_ = nhp_.createTimer(ops);
Expand All @@ -87,6 +84,17 @@ AerialRobotBase::~AerialRobotBase()

void AerialRobotBase::mainFunc(const ros::TimerEvent & e)
{
if (!e.last_real.isZero())
{
double dt_real = e.current_real.toSec() - e.last_real.toSec();
double tolerance = 0.05; // 5% tolerance. This value is set based on experience.
double dt_desire = (1.0 + tolerance) * 1.0 / main_rate_;
if (dt_real > dt_desire)
{
ROS_WARN("main loop rate is too low: (ts_real) %f s > (ts_desire with %2f%% tolerance) %f s ", dt_real,
tolerance * 100, dt_desire);
}
}
navigator_->update();
controller_->update();
}
Loading