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

Get parameter on initialize #893

Closed
wants to merge 10 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ static const rclcpp::Logger LOGGER = rclcpp::get_logger("moveit_ros.trajectory_e
const std::string TrajectoryExecutionManager::EXECUTION_EVENT_TOPIC = "trajectory_execution_event";

static const auto DEFAULT_CONTROLLER_INFORMATION_VALIDITY_AGE = rclcpp::Duration::from_seconds(1);
static const double DEFAULT_CONTROLLER_GOAL_DURATION_MARGIN = 0.5; // allow 0.5s more than the expected execution time
constexpr double DEFAULT_CONTROLLER_GOAL_DURATION_MARGIN = 0.5; // allow 0.5s more than the expected execution time
// before triggering a trajectory cancel (applied
// after scaling)
static const double DEFAULT_CONTROLLER_GOAL_DURATION_SCALING =
1.1; // allow the execution of a trajectory to take more time than expected (scaled by a value > 1)
// allow the execution of a trajectory to take more time than expected (scaled by a value > 1)
constexpr double DEFAULT_CONTROLLER_GOAL_DURATION_SCALING = 1.1;

constexpr double DEFAULT_ALLOWED_START_TOLERANCE = 0.01;

TrajectoryExecutionManager::TrajectoryExecutionManager(const rclcpp::Node::SharedPtr& node,
const moveit::core::RobotModelConstPtr& robot_model,
Expand Down Expand Up @@ -93,14 +95,9 @@ void TrajectoryExecutionManager::initialize()
current_context_ = -1;
last_execution_status_ = moveit_controller_manager::ExecutionStatus::SUCCEEDED;
run_continuous_execution_thread_ = true;
execution_duration_monitoring_ = true;
execution_velocity_scaling_ = 1.0;
allowed_start_tolerance_ = 0.01;
wait_for_trajectory_completion_ = true;

allowed_execution_duration_scaling_ = DEFAULT_CONTROLLER_GOAL_DURATION_SCALING;
allowed_goal_duration_margin_ = DEFAULT_CONTROLLER_GOAL_DURATION_MARGIN;

// load controller-specific values for allowed_execution_duration_scaling and allowed_goal_duration_margin
loadControllerParams();

Expand Down Expand Up @@ -181,10 +178,19 @@ void TrajectoryExecutionManager::initialize()
EXECUTION_EVENT_TOPIC, 100, std::bind(&TrajectoryExecutionManager::receiveEvent, this, std::placeholders::_1),
options);

execution_duration_monitoring_ = true;
controller_mgr_node_->get_parameter("trajectory_execution.execution_duration_monitoring",
execution_duration_monitoring_);
Copy link
Member

@AndyZe AndyZe Dec 6, 2021

Choose a reason for hiding this comment

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

This generally makes sense to me! I would like to see L96 & 98 moved closer to these lines of code so it's more clear that they are the default and they might get overwritten.

Suggested change
execution_duration_monitoring_);
execution_duration_monitoring_ = true;
controller_mgr_node_->get_parameter("trajectory_execution.execution_duration_monitoring",
execution_duration_monitoring_);
controller_mgr_node_->get_parameter("trajectory_execution.allowed_execution_duration_scaling",
allowed_execution_duration_scaling_);
controller_mgr_node_->get_parameter("trajectory_execution.allowed_goal_duration_margin",
allowed_start_tolerance_ = 0.01;
controller_mgr_node_->get_parameter("trajectory_execution.allowed_start_tolerance", allowed_start_tolerance_);

Copy link
Member

Choose a reason for hiding this comment

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

get_parameter_or() is probably a better way to set a default value if none is defined.

Copy link
Member

Choose a reason for hiding this comment

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

I think the regular get_parameter will throw an exception if it is not declared first (or someone didn't use the setting that decades everything in your yaml file and it was in the yaml file).


allowed_execution_duration_scaling_ = DEFAULT_CONTROLLER_GOAL_DURATION_SCALING;
controller_mgr_node_->get_parameter("trajectory_execution.allowed_execution_duration_scaling",
allowed_execution_duration_scaling_);

allowed_goal_duration_margin_ = DEFAULT_CONTROLLER_GOAL_DURATION_MARGIN;
controller_mgr_node_->get_parameter("trajectory_execution.allowed_goal_duration_margin",
allowed_goal_duration_margin_);

allowed_start_tolerance_ = DEFAULT_ALLOWED_START_TOLERANCE;
controller_mgr_node_->get_parameter("trajectory_execution.allowed_start_tolerance", allowed_start_tolerance_);

if (manage_controllers_)
Expand Down