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

Allow default values even if axis_linear is defined #34

Open
wants to merge 1 commit into
base: indigo-devel
Choose a base branch
from
Open
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
32 changes: 8 additions & 24 deletions src/teleop_twist_joy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,30 +74,14 @@ TeleopTwistJoy::TeleopTwistJoy(ros::NodeHandle* nh, ros::NodeHandle* nh_param)
nh_param->param<int>("enable_button", pimpl_->enable_button, 0);
nh_param->param<int>("enable_turbo_button", pimpl_->enable_turbo_button, -1);

if (nh_param->getParam("axis_linear", pimpl_->axis_linear_map))
Copy link
Member

Choose a reason for hiding this comment

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

@dave992 this checks if the param is a map .

Copy link
Author

Choose a reason for hiding this comment

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

It however does not ensure that all parameters of the map are set (in this case scale_linear and scale_linear_turbo), or alternatively provide any default value in case they are missing.

In teleop_ps4.yaml it only sets the yaw axis for example. It then does check for both scale_linear and scale_linear_turbo, but as they do not exist they use the value resulting from the initialization of the pimpl_ object. This does not correspond to the default values that are used when the axis_linear is not set.

{
nh_param->getParam("scale_linear", pimpl_->scale_linear_map["normal"]);
nh_param->getParam("scale_linear_turbo", pimpl_->scale_linear_map["turbo"]);
}
else
{
nh_param->param<int>("axis_linear", pimpl_->axis_linear_map["x"], 1);
nh_param->param<double>("scale_linear", pimpl_->scale_linear_map["normal"]["x"], 0.5);
nh_param->param<double>("scale_linear_turbo", pimpl_->scale_linear_map["turbo"]["x"], 1.0);
}

if (nh_param->getParam("axis_angular", pimpl_->axis_angular_map))
{
nh_param->getParam("scale_angular", pimpl_->scale_angular_map["normal"]);
nh_param->getParam("scale_angular_turbo", pimpl_->scale_angular_map["turbo"]);
}
else
{
nh_param->param<int>("axis_angular", pimpl_->axis_angular_map["yaw"], 0);
nh_param->param<double>("scale_angular", pimpl_->scale_angular_map["normal"]["yaw"], 0.5);
nh_param->param<double>("scale_angular_turbo",
pimpl_->scale_angular_map["turbo"]["yaw"], pimpl_->scale_angular_map["normal"]["yaw"]);
}
nh_param->param<int>("axis_linear", pimpl_->axis_linear_map["x"], 1);
nh_param->param<double>("scale_linear", pimpl_->scale_linear_map["normal"]["x"], 0.5);
nh_param->param<double>("scale_linear_turbo", pimpl_->scale_linear_map["turbo"]["x"], 1.0);

nh_param->param<int>("axis_angular", pimpl_->axis_angular_map["yaw"], 0);
nh_param->param<double>("scale_angular", pimpl_->scale_angular_map["normal"]["yaw"], 0.5);
nh_param->param<double>("scale_angular_turbo",
pimpl_->scale_angular_map["turbo"]["yaw"], pimpl_->scale_angular_map["normal"]["yaw"]);

ROS_INFO_NAMED("TeleopTwistJoy", "Teleop enable button %i.", pimpl_->enable_button);
ROS_INFO_COND_NAMED(pimpl_->enable_turbo_button >= 0, "TeleopTwistJoy",
Expand Down