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

mavlink: add missing uORB publication of tunes #13158

Merged
merged 6 commits into from
Apr 28, 2020
Merged

Conversation

julianoes
Copy link
Contributor

@julianoes julianoes commented Oct 11, 2019

The old tune device interface is not working anymore and we need to publish to uORB tune_control.

This solution is not optimal though because blocks the receiving thread.

@julianoes julianoes requested review from dagar and mcsauder October 11, 2019 10:29
@julianoes
Copy link
Contributor Author

In my opinion we should change the uorb tunes interface from individual notes to the string and then do the parsing and playing in the the respective tone driver. This way the uorb publisher doesn't need to wait.

Alternatively, we could increase the queue size by a lot but I'm not sure what the implications of that would be.

@bkueng do you have an opinion on that?

@bkueng
Copy link
Member

bkueng commented Oct 11, 2019

@bkueng do you have an opinion on that?

Probably one of these:

  • add a separate uORB message containing a string
  • add a string tunes handler class, used in mavlink that does the parsing non-blocking and is regularly called from the receiver thread (most efficient solution)

@julianoes
Copy link
Contributor Author

add a separate uORB message containing a string

What's your concern with changing the existing one instead?

add a string tunes handler class, used in mavlink that does the parsing non-blocking and is regularly called from the receiver thread (most efficient solution)

That's an idea. Do you think it would actually run fast enough though?

@bkueng
Copy link
Member

bkueng commented Oct 11, 2019

What's your concern with changing the existing one instead?

Unnecessary overhead as you need worst-case string length.

That's an idea. Do you think it would actually run fast enough though?

You can try. I'm not sure how accurate the timing really needs to be.

@dagar
Copy link
Member

dagar commented Oct 11, 2019

At a glance I've questioned the per note orb interface, but it hasn't quite bothered me enough to do anything about it.

I think an orb message containing the string would be fine (with a realistic length). Unless or until we know someone actually cares about doing this over mavlink we could ignore the tune2[200] extension field. https://mavlink.io/en/messages/common.html#PLAY_TUNE

@krisklau
Copy link

Hi!

Thanks for this, we just hit this ourselves.

Correct me if I have misunderstood the ToneAlarm driver, but could it be an idea to as a first step only support the pre-specified tones on the mavlink interface using the tone_id field? Then the mavlink receiver would only need to forward the tone_id specified in the mavlink message (possibly similar to here: https://github.com/PX4/Firmware/blob/45a53726d6594f6285243c1f1198fa431958e1c5/src/modules/events/rc_loss_alarm.cpp#L100)

Then we can figure out the custom string-based tone later.

@krisklau
Copy link

Ah, well I see now that the mavlink message does not have a tune_id field. Could repurpose the first bytes in the tune array, but that seems like a bit of a hack.

@krisklau
Copy link

@julianoes I incorporated the changes I thought about here: krisklau@0ae1ec3

Tested and works on a Pixhawk 4. Do you think this is a viable approach? Should I open a seperate PR for this?

@JonasVautherin
Copy link
Contributor

Ah, well I see now that the mavlink message does not have a tune_id field. Could repurpose the first bytes in the tune array, but that seems like a bit of a hack.

This sounds super custom to me, as I basically have no clue about the pre-specified tones on a MAVLink vehicle. I'm already not a big fan of the PLAY_TUNE specs that explicitly states that this is not a standard message 😅:

tune | char[30] | tune in board specific format

@krisklau
Copy link

hehe yeah I agree, but at least to be able to play something is better than nothing!

For PX4, the list is here:

https://github.com/PX4/Firmware/blob/bfab544a64e2dc3b86905771017989502ec40dd2/src/lib/tunes/tune_definition.desc#L91

@krisklau
Copy link

Our use-case is primarily just to confirm user actions from a companion computer.

Comment on lines 1675 to 1678
tune_control.frequency = (uint16_t)frequency;
tune_control.duration = (uint32_t)duration;
tune_control.silence = (uint32_t)silence;
tune_control.volume = (uint8_t)volume;
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @julianoes , would you want to use static_cast<type>(var) , (C++ style casts), here? (It allows compile time type checking where C-style casting does not.)

mcsauder
mcsauder previously approved these changes Oct 31, 2019
Copy link
Contributor

@mcsauder mcsauder left a comment

Choose a reason for hiding this comment

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

Hi @julianoes , I think this is a step in the right direction and good for now. The discussion above is all relevant and important, but perhaps another restructuring is in order after this step is complete. Bench testing checks out. I vote to get this in.

@julianoes
Copy link
Contributor Author

@mcsauder Thanks for reviewing and testing. I guess it's only stalling the MAVLink receive thread and nothing else.

While I'm at it here, I should also add PLAY_TUNE_V2 though. I'll do that next week.

@julianoes
Copy link
Contributor Author

Fixes #13158.

src/modules/mavlink/mavlink_receiver.cpp Outdated Show resolved Hide resolved
The old tune device interface is not working anymore and we need to
publish to uORB tune_control.

This solution is not optimal though because blocks the receiving thread.
Instead of blocking the receiver thread while playing a tune we now copy
the tune to a buffer and check if we can play the next note on each
iteration of the receiver thread.

The buffer and tune object is only created on the heap if we receive a
tune to play once and doesn't use resources otherwise.
@julianoes julianoes requested a review from mcsauder April 27, 2020 07:39
static constexpr unsigned MAX_TUNE_LEN {248};

// Allocated if needed.
Tunes *_tunes {nullptr};
Copy link
Member

Choose a reason for hiding this comment

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

What about moving these into a separate struct/class? Then you'd only have one allocation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bkueng done inc8c690d4da86122ac5d58b11eca8fa659d2110b8.

This makes it easier to allocate in MavlinkReceiver.
@julianoes julianoes dismissed LorenzMeier’s stale review April 27, 2020 19:00

Mentioned issue is addressed.

@bkueng bkueng merged commit 48c60d3 into master Apr 28, 2020
@bkueng bkueng deleted the fix-mavlink-tunes branch April 28, 2020 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants