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

Gimbal protocol v2 plugin - addressing PR comments #1953

Merged
merged 7 commits into from
Jun 6, 2024

Conversation

Crowdedlight
Copy link
Contributor

Addressing the PR comments from #1825 to help get the work done by Mark-Beaty merged in.

Copied in his PR description here:

This plugin has been tested with ROS2 Foxy and Humble and everything appears to be working correctly. Certain services and topics haven't been observed as working due to limitations of my testing hardware (Freefly Astro) and software (Auterion Simulator), but everything follows the documentation currently available for MAVLink's Gimbal Protocol v2. I also plan on adding another branch on my fork with the plugin separate from Mavros to enable use as a standalone plugin prior to the PR being approved/incorporated in a release.

Mark-Beaty and others added 7 commits May 21, 2024 10:07
Added all functionality to support a plugin to enable compatibility with MAVLink Gimbal Protocol v2
Added functionality that was overlooked for camera tracking if supported, added copyright info, added custom exception thrown when mode enumerator is not understood
Replaced with service call failure with MAV_RESULT_DENIED result value (2)
Comment on lines +74 to +77
<description>@brief Gimbal Control Plugin
@plugin gimbal_control

Adds support for Mavlink Gimbal Protocol v2.</description>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Original comment by "vooon":
"I think you haven't used cog.py to re-generate that file?"

I am not sure how to run it so it effects this file? I can the ./mavros/tools/cogall.sh but it did not seem to regenerate this file. Could you point me in the right direction to figure out how to regenerate it?

Copy link
Member

Choose a reason for hiding this comment

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

https://github.com/mavlink/mavros/blob/ros2/cog-requirements.txt

Cogall depends on installed cog.py, probbly in today's world that be easier with pipx, but i haven't exact directions for that.

So in general, you must do like that (beware, not tested!):

python3 -m venv ~/ros/.venv
source ~/ros/.venv
pip3 install -r cog-requirements.txt
pip3 install pymavlink
ln mavros_cog.py ~/ros/.venv/lib/python3.11/site-packages/

Then

cog -cr mavros_extras/mavros_plugins.xml

Copy link
Member

Choose a reason for hiding this comment

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

Also note, cog would raise an error if generated part didn't match md5. But you simply can remove hash after [[[end]]].

Comment on lines +182 to +185
cmdClient = node->create_client<mavros_msgs::srv::CommandLong>("cmd/command", rmw_qos_profile_services_default, cb_group);
while (!cmdClient->wait_for_service(std::chrono::seconds(5))) {
RCLCPP_ERROR(node->get_logger(), "GimbalControl: mavros/cmd/command service not available after waiting");
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Original comment by vooon:

Locking in the constructor might be a bad idea.
Maybe better to check for that service later?

As the rest is callbacks based on ros/mavlink message traffic, then you would have to add a check to every callback needing this client, instead of having it in the constructor once.
The locking here is also set with a timeout of 5s, so worst-case is locked for 5s before moving on.

If you have a suggestion to how to handle it better, let me know :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

edit: I miswrote. I can see it will block here in periods of 5s forever.
Potential change could be to make it to only try once with that timeout and then abandon the plugin and throw the error, if the service can't be made?

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 better to trow away client after the use, so you don't need to keep it between calls.

Copy link
Contributor Author

@Crowdedlight Crowdedlight Jun 2, 2024

Choose a reason for hiding this comment

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

I can change to do that, I just thought the constant recreation of the client would be worse?
As if a caller is using the service to set ROI region, or pitchyaw with even just 1hz it is still initializing a client and destroying it per call.

I could create it in the constructor, but move the check if the service is available to each message using it? And change so it only tries for 5s then just returns error to the caller to let them know?

Would keep the constructor free from blocking, but still ensure the service exist before calling it, and otherwise return message to caller that the request could not be completed due to the mavros/cmd service not being found?

Copy link
Member

Choose a reason for hiding this comment

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

You can cache the client, but must create it on request, not in the constructor.

Something like that pseudo:

*Client get_cmd_long() {
  mutex Locker();

  if _cache {
    return _cache;
  }

  client = node_->create_client(...);
  // error handling!
  _cache = client;
  return client;  
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ofc, that makes sense. I'll do that.

Comment on lines +18 to +21
uint32 CAP_FLAGS_HAS_YAW_LOCK = 1024 # Based on GIMBAL_DEVICE_CAP_FLAGS_HAS_YAW_LOCK.
uint32 CAP_FLAGS_SUPPORTS_INFINITE_YAW = 2048 # Based on GIMBAL_DEVICE_CAP_FLAGS_SUPPORTS_INFINITE_YAW.
uint32 CAP_FLAGS_CAN_POINT_LOCATION_LOCAL = 65536 # Gimbal manager supports to point to a local position.
uint32 CAP_FLAGS_CAN_POINT_LOCATION_GLOBAL = 131072 # Gimbal manager supports to point to a global latitude, longitude, altitude position.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

original comment by vooon:

Ideally that should be generated like for MAV_CMD.

I am not sure how to do that? I looked around briefly but didn't manage to find where it was generated for MAV_CMD in the msg files. Can you help point out where to find it, or the flow to make it generated like MAV_CMD?

Copy link
Member

Choose a reason for hiding this comment

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

You may find the generator code in the comment. Cog simply execute this embedded python scripts:

# [[[cog:
# import mavros_cog
# mavros_cog.idl_decl_enum_mav_cmd()
# ]]]

@Crowdedlight
Copy link
Contributor Author

@vooon I addressed most of the comments you left on #1825 , but I have a few questions to some of them. I copy-pasted them over here and added them as comments above with my questions to them too. :)

@vooon vooon added this to the Version 2.8 milestone May 28, 2024
@vooon vooon merged commit 5646ba4 into mavlink:ros2 Jun 6, 2024
0 of 3 checks passed
@Crowdedlight
Copy link
Contributor Author

Thanks for fixing the last parts and getting it merged! Much Appricated :)

I had some priority work dumped on me at work and busy weekends so had to postpone it. Sorry about that!

@vooon
Copy link
Member

vooon commented Jun 10, 2024

@Crowdedlight thank you too. When you have time, please test it, as i didn't have all required things to setup an environment.

@Crowdedlight
Copy link
Contributor Author

@Crowdedlight thank you too. When you have time, please test it, as i didn't have all required things to setup an environment.

I just tested part of the release in simulation. I found no errors. Gimbal moves as I expect sending the quaternion to it with this topic.
image

And Using the service to take control over the gimbal with /mavros/gimbal_control/manager/configure works as well. Due to other commitments I have not had time to go through all the services and topics, but at least these work which should give you full gimbal attitude control. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants