-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Conversation
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)
…ions for string and quaternion convert
<description>@brief Gimbal Control Plugin | ||
@plugin gimbal_control | ||
|
||
Adds support for Mavlink Gimbal Protocol v2.</description> |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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]]]
.
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"); | ||
} |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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;
}
There was a problem hiding this comment.
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.
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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
mavros/mavros_msgs/msg/CommandCode.msg
Lines 5 to 8 in 072df7e
# [[[cog: | |
# import mavros_cog | |
# mavros_cog.idl_decl_enum_mav_cmd() | |
# ]]] |
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! |
@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. And Using the service to take control over the gimbal with |
Addressing the PR comments from #1825 to help get the work done by Mark-Beaty merged in.
Copied in his PR description here: