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

Added support for MAV_CMD_REQUEST_MESSAGE for mavlink streams #13481

Merged
merged 1 commit into from
Dec 16, 2019

Conversation

AmeliaEScott
Copy link
Contributor

Describe problem solved by this pull request
PX4 does not support the command MAV_CMD_REQUEST_MESSAGE

Describe your solution
Added a function to MavlinkStream which, by default, calls reset_last_sent(). It can be overridden for situations where a parameter should be used.

Describe possible alternatives
This could be handled outside of MavlinkStream.

Test data / coverage
Used MavSDK to send MAV_CMD_REQUEST_MESSAGE to PX4 running in SITL, and verified that the requested message was sent.

Copy link
Contributor

@julianoes julianoes left a comment

Choose a reason for hiding this comment

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

Nice!

src/modules/mavlink/mavlink_receiver.cpp Outdated Show resolved Hide resolved
julianoes
julianoes previously approved these changes Nov 15, 2019
Copy link
Contributor

@julianoes julianoes left a comment

Choose a reason for hiding this comment

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

Thx

@dagar
Copy link
Member

dagar commented Nov 15, 2019

I'm just curious, what's the desired use case for this? My initial thought is that it would primarily be useful for sending messages that aren't already streamed.


for (const auto &stream : _mavlink->get_streams()) {
if (stream->get_id() == message_id) {
stream->request_message(vehicle_command.param1, vehicle_command.param2, vehicle_command.param3,
Copy link
Member

Choose a reason for hiding this comment

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

Why are all the parameters passed on?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For my use case (see below), I need parameters 2, 3, and 4 (although the specifications for this are still under discussion, so that might not be the case in the end). Based on this, it seems to be fine to use any set of the parameters. So for future implementations of this method, different messages might have to use any or all of the parameters from the command.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think a good idea. We could just update the mavlink message to define all these param values properly now if that will make it easy.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's indeed a bit odd. According to the message definition no params should be really used, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

What @ItsTimmy has done is the intention of the message, but not its current implementation.

Specifically, some message, like the proposed microservices requestor, depend on parameters. If we want to use this message to request it we need to be able to provide those parameters. So if we don't do this, we'd need a dedicated message (also a valid option).

I've updated the message so that it is more clear: mavlink/mavlink#1276

Copy link
Contributor

Choose a reason for hiding this comment

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

@hamishwillee ok got it. I think in that case I just don't like the fact that we overload the REQUEST_MESSAGE with additional params. I can see how we got there but it makes it hard to understand from the outside, in my opinion.

Copy link
Contributor

Choose a reason for hiding this comment

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

@julianoes That's a reasonable argument. Certainly having dedicated messages makes microservices more compartmentalised.

But it does mean we need to create at least one dedicated message for @ItsTimmy to use for this. Tim, can you propose a message in the spec?

@AmeliaEScott
Copy link
Contributor Author

AmeliaEScott commented Nov 15, 2019

I am working on implementing microservice versioning, which will include an option to request that the autopilot send an individual message for each supported microservice. I implemented a MavlinkStream for microservice version messages, which responds to the Request Message command.

The intent there is to avoid clogging the mavlink channel by sending all of the messages at once. Instead, I am using the existing MavlinkStream infrastructure to space out the messages on a regular interval, then stop the stream when I have sent all of them.

If you want to support other messages for the Request Message command in the future, it should be as easy as adding a new MavlinkStream and setting the interval very large. (Of course, that's a bit of a hack. A slightly better option is to change MavlinkStream such that an interval value of, say, INT_MAX is treated as an infinite interval.)

@hamishwillee
Copy link
Contributor

I'm just curious, what's the desired use case for this? My initial thought is that it would primarily be useful for sending messages that aren't already streamed.

@dagar Yes. Essentially it is a generic replacement for having to create a special message every time you want to do a one-shot requester for a particular message. For Tim it's a part of the microservice handshake.

@AmeliaEScott
Copy link
Contributor Author

AmeliaEScott commented Nov 28, 2019

@dagar @julianoes @hamishwillee Will this get merged, or do you think it is unnecessary? I would like to have a decision within a few days, so that I can know whether I should start working on a different way to implement microservice versioning.

@dagar
Copy link
Member

dagar commented Nov 28, 2019

@dagar @julianoes @hamishwillee Will this get merged, or do you think it is unnecessary? I would like to have a decision within a few days, so that I can know whether I should start working on a different way to implement microservice versioning.

The round needs to be updated, but otherwise this looks safe to merge.

@hamishwillee
Copy link
Contributor

Looks good to me. I actually don't have rights to merge stuff in this repo (which is generally a good thing :-) )

@AmeliaEScott
Copy link
Contributor Author

AmeliaEScott commented Dec 12, 2019

Since the spec for microservice versioning has been updated such that it no longer uses MAV_CMD_REQUEST_MESSAGE (See #13481 (comment)), should this PR still be merged? I suppose it could still be useful in the future, but is it useful now?

Also, since mavlink/mavlink#1276 was merged, should I leave this as it is, with all of the parameters included?

@hamishwillee
Copy link
Contributor

hamishwillee commented Dec 13, 2019

@ItsTimmy my strong preference is to leave it in/merge this. The requestor is useful for many messages, not just microservices.

should I leave this as it is, with all of the parameters included?

Yes

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.

4 participants