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

Add mavlink play tune message to simulator class #11431

Closed
wants to merge 5 commits into from

Conversation

catch-twenty-two
Copy link
Contributor

@catch-twenty-two catch-twenty-two commented Feb 11, 2019

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

@dagar
Copy link
Member

dagar commented Feb 11, 2019

@mcsauder

struct {
unsigned int frequency;
unsigned int duration;
unsigned int silence_length;
Copy link
Contributor

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

Copy link
Contributor Author

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.

@mcsauder
Copy link
Contributor

mcsauder commented Feb 12, 2019

@catch-twenty-two and @dagar , this PR looks good to me.

@dagar, do we need to add orb_unsubscribe calls to this class's destructor (and should the constructor/destructor get moved out of the header file)?

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)];
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is gone now

@mcsauder
Copy link
Contributor

mcsauder commented Feb 15, 2019

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

git fetch upstream
git merge upstream/master
git merge-base upstream/master YOUR_BRANCH_NAME    (which happens to be master)

some commit sha will magically appear, copy it to paste it later

git rebase -i THE_REBASE_COMMIT_SHA_YOU_JUST_COPIED

ctrl+O to write Out, ctrl+X to save and eXit

review your commit comments and update as needed...
ctrl +O to write Out, ctrl+X to save and eXit

git push -f

force push your rebased changes to the PR. Done!

find and message me on PX4 slack if you need a hand.

@mcsauder
Copy link
Contributor

@dagar and @catch-twenty-two , I have work ready to follow this PR as a clean-up pass.

@catch-twenty-two
Copy link
Contributor Author

catch-twenty-two commented Feb 16, 2019

@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

@catch-twenty-two
Copy link
Contributor Author

Okay should be all good now

@mcsauder
Copy link
Contributor

@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, git rebase -i HEAD~2 to allow you to squash the last two commits into one, or HEAD~3 to squash the last 3 into one, etc.. This also allows you to edit the commit comments to illustrate your intent.

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!

@mcsauder
Copy link
Contributor

See also PR #11447

@mcsauder
Copy link
Contributor

@dagar and @davids5 , looks good to me.

unsigned int silence;
} tune_info = {};

_tunes.get_next_tune(tune_info.frequency, tune_info.duration, tune_info.silence);
Copy link
Member

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.

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 got it, ill take a look at the logic and try to replicate it here.

Copy link
Contributor Author

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.

@catch-twenty-two
Copy link
Contributor Author

I've found a solution, working on it now...

@catch-twenty-two catch-twenty-two force-pushed the master branch 2 times, most recently from e42ede3 to 271937b Compare February 20, 2019 17:36
unsigned int silence;
} tone_info = {};

if (_tunes.get_next_note(tone_info.frequency, tone_info.duration, tone_info.silence) > 0) {
Copy link
Contributor

@potaito potaito Feb 21, 2019

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.

@LorenzMeier
Copy link
Member

@catch-twenty-two Please rebase to fix CI

@catch-twenty-two
Copy link
Contributor Author

@catch-twenty-two Please rebase to fix CI

Done, thx

@catch-twenty-two catch-twenty-two force-pushed the master branch 2 times, most recently from df4652e to dbec7b4 Compare March 6, 2019 04:06
@catch-twenty-two
Copy link
Contributor Author

squashed commit

Copy link
Member

@bkueng bkueng left a 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));
Copy link
Member

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @bkueng , I think I can see why the CI tests here are unhappy... do you have a preference about where the unsubscribe methods get placed?

Copy link
Member

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.

Copy link
Contributor

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!

Copy link
Member

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;
Copy link
Member

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?

@catch-twenty-two
Copy link
Contributor Author

All pr review requests should be addressed now

Copy link
Member

@bkueng bkueng left a 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));
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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) {
Copy link
Member

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

Copy link
Member

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.
Copy link
Member

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

@catch-twenty-two
Copy link
Contributor Author

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.

@mcsauder
Copy link
Contributor

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!)

@mcsauder mcsauder closed this Sep 17, 2019
mcsauder added a commit to mcsauder/PX4-Autopilot that referenced this pull request Oct 18, 2019
…ded #includes, add volume to send_sim_tone() message and minor formatting.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants