-
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
Add CAN beep #14712
Add CAN beep #14712
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,106 @@ | ||||||
/**************************************************************************** | ||||||
* | ||||||
* Copyright (c) 2014, 2015 PX4 Development Team. All rights reserved. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
* | ||||||
* Redistribution and use in source and binary forms, with or without | ||||||
* modification, are permitted provided that the following conditions | ||||||
* are met: | ||||||
* | ||||||
* 1. Redistributions of source code must retain the above copyright | ||||||
* notice, this list of conditions and the following disclaimer. | ||||||
* 2. Redistributions in binary form must reproduce the above copyright | ||||||
* notice, this list of conditions and the following disclaimer in | ||||||
* the documentation and/or other materials provided with the | ||||||
* distribution. | ||||||
* 3. Neither the name PX4 nor the names of its contributors may be | ||||||
* used to endorse or promote products derived from this software | ||||||
* without specific prior written permission. | ||||||
* | ||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | ||||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | ||||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||||||
* POSSIBILITY OF SUCH DAMAGE. | ||||||
* | ||||||
****************************************************************************/ | ||||||
|
||||||
/** | ||||||
* @file beep.cpp | ||||||
* | ||||||
* @author CUAVcaijie <caijie@cuav.net> | ||||||
*/ | ||||||
|
||||||
|
||||||
#include "beep.hpp" | ||||||
|
||||||
UavcanUavcanBeep::UavcanUavcanBeep(uavcan::INode &node) : | ||||||
_beep_pub(node), | ||||||
_timer(node) | ||||||
{ | ||||||
} | ||||||
|
||||||
int | ||||||
UavcanUavcanBeep::init() | ||||||
{ | ||||||
/* | ||||||
* Setup timer and call back function for periodic updates | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you move this description to the header file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, I will modify |
||||||
*/ | ||||||
|
||||||
if (!_timer.isRunning()) { | ||||||
_timer.setCallback(TimerCbBinder(this, &UavcanUavcanBeep::periodic_update)); | ||||||
_timer.startPeriodic(uavcan::MonotonicDuration::fromMSec(1000 / MAX_RATE_HZ)); | ||||||
} | ||||||
|
||||||
return 0; | ||||||
} | ||||||
|
||||||
void | ||||||
UavcanUavcanBeep::periodic_update(const uavcan::TimerEvent &) | ||||||
{ | ||||||
if (_tune_control_sub.updated()) { | ||||||
_tune_control_sub.copy(&_tune); | ||||||
|
||||||
if (_tune.timestamp > 0) { | ||||||
_play_tone = _tunes.set_control(_tune) == 0; | ||||||
} | ||||||
} | ||||||
|
||||||
if ((hrt_absolute_time() - interval_timestamp <= duration) | ||||||
|| (!_play_tone)) { | ||||||
return; | ||||||
} | ||||||
|
||||||
interval_timestamp = hrt_absolute_time(); | ||||||
|
||||||
if (_silence_length > 0) { | ||||||
duration = _silence_length; | ||||||
_silence_length = 0; | ||||||
|
||||||
} else if (_play_tone) { | ||||||
int parse_ret_val = _tunes.get_next_note(frequency, duration, _silence_length); | ||||||
|
||||||
if (parse_ret_val > 0) { | ||||||
// Continue playing. | ||||||
_play_tone = true; | ||||||
|
||||||
if (frequency > 0) { | ||||||
// Start playing the note. | ||||||
uavcan::equipment::indication::BeepCommand cmd; | ||||||
cmd.frequency = frequency; | ||||||
cmd.duration = duration / 1000000.f; | ||||||
(void)_beep_pub.broadcast(cmd); | ||||||
} | ||||||
|
||||||
} else { | ||||||
_play_tone = false; | ||||||
} | ||||||
|
||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,91 @@ | ||||||
/**************************************************************************** | ||||||
* | ||||||
* Copyright (c) 2014, 2015 PX4 Development Team. All rights reserved. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
* | ||||||
* Redistribution and use in source and binary forms, with or without | ||||||
* modification, are permitted provided that the following conditions | ||||||
* are met: | ||||||
* | ||||||
* 1. Redistributions of source code must retain the above copyright | ||||||
* notice, this list of conditions and the following disclaimer. | ||||||
* 2. Redistributions in binary form must reproduce the above copyright | ||||||
* notice, this list of conditions and the following disclaimer in | ||||||
* the documentation and/or other materials provided with the | ||||||
* distribution. | ||||||
* 3. Neither the name PX4 nor the names of its contributors may be | ||||||
* used to endorse or promote products derived from this software | ||||||
* without specific prior written permission. | ||||||
* | ||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | ||||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | ||||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||||||
* POSSIBILITY OF SUCH DAMAGE. | ||||||
* | ||||||
****************************************************************************/ | ||||||
|
||||||
/** | ||||||
* @file beep.hpp | ||||||
* | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a description here with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||||||
* @author CUAVcaijie <caijie@cuav.net> | ||||||
*/ | ||||||
|
||||||
|
||||||
#pragma once | ||||||
|
||||||
#include <uavcan/uavcan.hpp> | ||||||
#include <uavcan/equipment/indication/BeepCommand.hpp> | ||||||
#include <uORB/Subscription.hpp> | ||||||
#include <uORB/topics/tune_control.h> | ||||||
#include <lib/tunes/tunes.h> | ||||||
|
||||||
/** | ||||||
* @brief The UavcanUavcanBeep class | ||||||
*/ | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
class UavcanUavcanBeep | ||||||
{ | ||||||
public: | ||||||
UavcanUavcanBeep(uavcan::INode &node); | ||||||
|
||||||
/* | ||||||
* setup periodic updater | ||||||
*/ | ||||||
int init(); | ||||||
|
||||||
private: | ||||||
/* | ||||||
* Max update rate to avoid exessive bus traffic | ||||||
*/ | ||||||
static constexpr unsigned MAX_RATE_HZ = 100; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
void periodic_update(const uavcan::TimerEvent &); | ||||||
|
||||||
typedef uavcan::MethodBinder<UavcanUavcanBeep *, void (UavcanUavcanBeep::*)(const uavcan::TimerEvent &)> | ||||||
TimerCbBinder; | ||||||
|
||||||
uORB::Subscription _tune_control_sub{ORB_ID(tune_control)}; | ||||||
|
||||||
/* | ||||||
* libuavcan related things | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you replace with details on what each thing is doing instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok |
||||||
*/ | ||||||
uavcan::Publisher<uavcan::equipment::indication::BeepCommand> _beep_pub; | ||||||
|
||||||
uavcan::TimerEventForwarder<TimerCbBinder> _timer; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
hrt_abstime interval_timestamp{0}; | ||||||
tune_control_s _tune{}; | ||||||
Tunes _tunes = Tunes(); | ||||||
bool _play_tone{false}; | ||||||
unsigned int _silence_length{0}; ///< If nonzero, silence before next note. | ||||||
unsigned int frequency{0}; | ||||||
unsigned int duration{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 please move this above and make sure it is alphabetically ordered?
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.
ok