-
Notifications
You must be signed in to change notification settings - Fork 13.7k
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
Conversation
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? |
fd78f79
to
70b1610
Compare
Probably one of these:
|
What's your concern with changing the existing one instead?
That's an idea. Do you think it would actually run fast enough though? |
Unnecessary overhead as you need worst-case string length.
You can try. I'm not sure how accurate the timing really needs to be. |
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 |
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. |
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. |
@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? |
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
|
hehe yeah I agree, but at least to be able to play something is better than nothing! For PX4, the list is here: |
Our use-case is primarily just to confirm user actions from a companion computer. |
tune_control.frequency = (uint16_t)frequency; | ||
tune_control.duration = (uint32_t)duration; | ||
tune_control.silence = (uint32_t)silence; | ||
tune_control.volume = (uint8_t)volume; |
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.
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.)
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.
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.
@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. |
70b1610
to
b8837e7
Compare
Fixes #13158. |
b8837e7
to
4418ea5
Compare
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.
4418ea5
to
0704870
Compare
static constexpr unsigned MAX_TUNE_LEN {248}; | ||
|
||
// Allocated if needed. | ||
Tunes *_tunes {nullptr}; |
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.
What about moving these into a separate struct/class? Then you'd only have one allocation.
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.
@bkueng done inc8c690d4da86122ac5d58b11eca8fa659d2110b8.
This makes it easier to allocate in MavlinkReceiver.
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.