MAVSDK-Proto
MAVSDK-Proto copied to clipboard
Add callbacks that provide a result (for server commands)
While defining the proto API for MAVSDK autopilot server plugins I ran into an issue where I needed to provide logic to allow or disallow a certain action in a timely manner. for example with an arming request MAV_CMD_COMPONENT_ARM_DISARM
As this request is a mavlink command, it requires an ack
to be successful, failed or unsupported almost immediately. The only way for me to fulfil this at current was to store the state of is_armable
in the plugin and provide proto to change that state. This state is checked when a command is observed and the ack is sent immediately. It works, but not an ideal solution.
https://github.com/mavlink/MAVSDK/blob/main/src/plugins/action_server/action_server_impl.cpp#L57
I would like to be able to do something like the following:
action_server.subscribe_arm_request([](action_server::ArmRequest arm_request)
{
return some_check_to_see_if_can_arm(arm_request); // True if allow // False if not
});
In the plugin, this callback result could then be used to ack
the command correctly.
The return value should probably map to command ack states really - instead of just a boolean.
This sort of callback would be useful for a camera server as well.
Looking at what is possible with gRPC, it looks like the closest thing is a bidirectional stream.
It looks like the TrackingServer is implemented in a way where the ack is deferred.
@JonasVautherin what's your take on this? For now, we just use several workarounds, either state like is_armable
or explicit responses that need to be made when requests come in.