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

plugin: setpoint_raw: move getParam to initializer #1669

Merged
merged 1 commit into from
Dec 8, 2021
Merged

plugin: setpoint_raw: move getParam to initializer #1669

merged 1 commit into from
Dec 8, 2021

Conversation

Hs293Go
Copy link
Contributor

@Hs293Go Hs293Go commented Dec 6, 2021

Currently attitude_cb() attempts to get the thrust_scaling parameter. This is problematic as documented in this question, and is exacerbated when attitude_cb() is called in a fast control loop. In which case, getParam() may return false spuriously and trip a fatal error. This has been observed when a control loop is run at 150Hz on a Jetson Nano.

This PR moves the getParam() call to initialize to avoid this problem, at the cost of removing the ability to dynamically change thrust_scaling (which I believe is unlikely to be important)

Copy link
Member

@vooon vooon left a comment

Choose a reason for hiding this comment

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

I'm ok with the change, but don't think that you really need pointer.

@@ -71,6 +77,8 @@ class SetpointRawPlugin : public plugin::PluginBase,
ros::Subscriber local_sub, global_sub, attitude_sub;
ros::Publisher target_local_pub, target_global_pub, target_attitude_pub;

std::unique_ptr<double> thrust_scaling_parameter;
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 that you do not need to dynamically allocate that double. You just need a sign of unset scaling, so NAN is good for that.

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'm actually inclined to use boost::optional. It would be elegant and does away with dynamic allocs. ROS already depends on boost so the added dependency is not a big issue. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

No. Please avoid Boost.

Copy link
Member

Choose a reason for hiding this comment

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

Well, i checked that there are std::optional in C++17, so it's ok to use boost::optional for ROS1. But i would rather limit boost dependency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vooon Well, I'd hate to let my design choices get in the way of this PR. Just switched to setting a -1.0 sentinel value for thrust_scaling and pushed.

Copy link
Member

@vooon vooon left a comment

Choose a reason for hiding this comment

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

LGTM, Thanks!

@vooon vooon merged commit 65becb1 into mavlink:master Dec 8, 2021
Repeatedly getting the thrust_scaling parameter in a callback that can
be invoked from a fast control loop may fail spuriously and trigger a
fatal error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants