MAVSDK-Proto icon indicating copy to clipboard operation
MAVSDK-Proto copied to clipboard

Add callbacks that provide a result (for server commands)

Open bazfp opened this issue 3 years ago • 4 comments

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.

bazfp avatar Aug 09 '21 13:08 bazfp

This sort of callback would be useful for a camera server as well.

dlech avatar Nov 10 '21 18:11 dlech

Looking at what is possible with gRPC, it looks like the closest thing is a bidirectional stream.

dlech avatar Nov 11 '21 17:11 dlech

It looks like the TrackingServer is implemented in a way where the ack is deferred.

dlech avatar Nov 11 '21 18:11 dlech

@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.

julianoes avatar Dec 17 '23 20:12 julianoes