-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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
Add mavlink play tune message to simulator class #11431
Conversation
struct { | ||
unsigned int frequency; | ||
unsigned int duration; | ||
unsigned int silence_length; |
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.
@catch-twenty-two , if you change silence_length
to silence
you will match the naming convention of the tune_control_s
type. (You could consider utilizing that type to store these values, although it could require modifying how you are using the union's memory space to transfer values to the message.)
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.
I ended up removing the union, I didn't really need it any more. I still create a local structure just to be on the safe side in case the tune_control_s structure changes, and I think it makes the code a little more readable.
@catch-twenty-two and @dagar , this PR looks good to me. @dagar, do we need to add EDIT: I see now that the class is broken across a few files, so the constructor/destructor definitions need to stay put. |
unsigned int duration; | ||
unsigned int silence_length; | ||
}; | ||
uint8_t a[sizeof(tune_msg.tune)]; |
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.
@catch-twenty-two , I'm not a huge fan of single letter variables outside of index usage,... Any chance we could come up with a more descriptive name for a
?
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.
this is gone now
@catch-twenty-two , can you resolve the merge conflicts and push up a rebase ? https://github.com/edx/edx-platform/wiki/How-to-Rebase-a-Pull-Request Here's the gist:
some commit sha will magically appear, copy it to paste it later
ctrl+O to write Out, ctrl+X to save and eXit review your commit comments and update as needed...
force push your rebased changes to the PR. Done! find and message me on PX4 slack if you need a hand. |
@dagar and @catch-twenty-two , I have work ready to follow this PR as a clean-up pass. |
df5ce64
to
e695ba5
Compare
@mcsauder Something went wrong with my rebase, please hold off on merging this until I fix it...I seem to have a copy and paste issue |
Okay should be all good now |
@catch-twenty-two , in case you find it helpful, if you'd like to have a tidy commit history that shows the steps you'd like to have followed in future code forensics, you can use a handy rebase command, NOTE: It is always tricky re-writing history in a repo, and there can be consequences, so be aware of them, but the very best time to do it is before it becomes part of the permanent record in in the main repository. https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History Good work so far! |
See also PR #11447 |
unsigned int silence; | ||
} tune_info = {}; | ||
|
||
_tunes.get_next_tune(tune_info.frequency, tune_info.duration, tune_info.silence); |
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.
It's not enough to call this only when the topic gets updated. I think we need similar logic as in ToneAlarm.cpp.
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 got it, ill take a look at the logic and try to replicate it here.
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.
It should be fixed now, Thanks for the help.
I've found a solution, working on it now... |
e42ede3
to
271937b
Compare
unsigned int silence; | ||
} tone_info = {}; | ||
|
||
if (_tunes.get_next_note(tone_info.frequency, tone_info.duration, tone_info.silence) > 0) { |
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.
I'm not saying you must, but you could additionally check if the note you are going to send is audible with the condition ... && tone_info.frequency > 0 && tone_info.duration > 0 && tone_info.strength > 0
. Then you won't send the pause notes.
@catch-twenty-two Please rebase to fix CI |
Done, thx |
df4652e
to
dbec7b4
Compare
squashed commit |
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.
Looks almost good, thanks for the update.
One more thing: can we disable it by default, e.g. via CBRK_BUZZER
parameter? If you're sitting in a room with people all running the sim, it's not cool to hear the tunes all the time ;)
@@ -782,6 +825,8 @@ void Simulator::poll_for_MAVLink_messages() | |||
_actuator_outputs_sub = orb_subscribe_multi(ORB_ID(actuator_outputs), 0); | |||
_vehicle_status_sub = orb_subscribe(ORB_ID(vehicle_status)); | |||
|
|||
_tune_control_sub = orb_subscribe(ORB_ID(tune_control)); |
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.
This and the other topics are missing an orb_unsubscribe
at the bottom of the method.
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.
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.
In that case at the end of poll_for_MAVLink_messages
.
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.
Apologies, I didn't make things very clear by pointing to those commits,
This and the other topics are missing an orb_unsubscribe at the bottom of the method
In that case at the end of poll_for_MAVLink_messages.
Indeed, they are the same.
Adding the orb unsubscribe calls at the end of this method causes a segfualt. Placing the unsubscribe() calls in the destructor does not. Additional usage of the subscription vars occurs in send()
, send_controls
, and poll_topics()
. The destructor seems to be the appropriate location for the unsubscribe() calls given their usage outside of poll_for_MAVLINK_messages()
, but I can find no other examples where subscriptions take place outside of the constructor, (in a class method), and then unsubscribed in the destructor.
It seems appropriate to move these subscribe calls to the constructor in this case, but let me know if you have other feedback in PR #11631. Thanks!
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.
Adding the orb unsubscribe calls at the end of this method causes a segfualt. Placing the unsubscribe() calls in the destructor does not.
If I saw it correctly, you called unsubscribe still within the loop, not at the very end of poll_for_MAVLINK_messages
.
The destructor seems to be the appropriate location for the unsubscribe()
If you subscribe in the constructor it's the right place. That's my prefered solution as well, and it should work with the current structure (refactoring to ModuleBase is another thing we can do).
|
||
void Simulator::send_sim_tone() | ||
{ | ||
static long tone_timer = 0; |
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.
Can you make this a class attribute?
All pr review requests should be addressed now |
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.
There are still problems, can you check please?
@@ -759,6 +792,8 @@ void Simulator::poll_for_MAVLink_messages() | |||
_actuator_outputs_sub = orb_subscribe_multi(ORB_ID(actuator_outputs), 0); | |||
_vehicle_status_sub = orb_subscribe(ORB_ID(vehicle_status)); | |||
|
|||
_tune_control_sub = orb_subscribe(ORB_ID(tune_control)); |
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.
I don't see where this is unsubscribed.
unsigned int silence; | ||
} tune_info = {}; | ||
|
||
_tunes.get_next_note(tune_info.frequency, tune_info.duration, tune_info.silence); |
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.
I think I raised this before, you need to move this out of the updated
condition. A single tune_control topic update might lead to several notes.
|
||
if (updated) { | ||
|
||
orb_copy(ORB_ID(_control), _control_sub, &_tune_control); |
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.
orb_copy(ORB_ID(_control), _control_sub, &_tune_control); | |
orb_copy(ORB_ID(tune_control), _control_sub, &_tune_control); |
_cbrk = circuit_breaker_enabled("CBRK_BUZZER", CBRK_BUZZER_KEY); | ||
} | ||
|
||
if (_cbrk == CBRK_OFF) { |
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.
Please make sure this is set by default for SITL
@@ -293,10 +297,15 @@ class Simulator : public ModuleParams | |||
uint64_t _hil_ref_timestamp{0}; | |||
|
|||
// uORB data containers | |||
|
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.
Unnecessary newline
tune_control_s _tune_control {}; | ||
|
||
Tunes _tunes; | ||
int _cbrk{CBRK_UNINIT}; ///< If true, no audio output. |
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.
It's an int, so true
is not appropriate here
Hi @mcsauder, I'm going to close this pr until I have time to finish it up. I just don't have the bandwidth right now. |
I think this is good work, so I'll try to carry it on in #12507. (Please re-open if you'd like it to stick around!) |
…ded #includes, add volume to send_sim_tone() message and minor formatting.
This revisits and finishes up the ability to send a tone alarm over mavlink to a simulator when in simulator mode. There is a JMAVSim update that adds a 'peripheral class' which takes advantage of the new message here:
PX4/jMAVSim#92
Original concept/prototype demonstration is here (this pr adds same functionality):
https://www.youtube.com/watch?v=t7cvCfbbXbE