forked from mavlink/mavros
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
play_tune: Use tune_id as parameter. play_tune: Run clang-format play_tune: Fix buggy conditional The check `!x > 0` evaluates as `(!x) > 0`, but this was probably intended to be `!(x > 0)`. However: The tune id is unsigned, and tune id 0 means custom tune, which we don't support, so we can simplify this to just issue an error if tune id is zero. Check out tune_definition.desc in the PX4 Firmware repo. Fix mavlink#3.
- Loading branch information
1 parent
a1dd03c
commit 55bd190
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include <mavros/mavros_plugin.h> | ||
#include <std_msgs/UInt8.h> | ||
|
||
namespace mavros | ||
{ | ||
namespace std_plugins | ||
{ | ||
|
||
class PlayTunePlugin : public plugin::PluginBase | ||
{ | ||
public: | ||
PlayTunePlugin() : PluginBase(), nh("~") {} | ||
|
||
void initialize(UAS& uas_) | ||
{ | ||
PluginBase::initialize(uas_); | ||
sub = nh.subscribe("play_tune", 1, &PlayTunePlugin::callback, this); | ||
} | ||
|
||
Subscriptions get_subscriptions() { return {/* Rx disabled */}; } | ||
|
||
private: | ||
ros::NodeHandle nh; | ||
ros::Subscriber sub; | ||
|
||
void callback(const std_msgs::UInt8::ConstPtr& tune_id) | ||
{ | ||
ROS_INFO("Got play tune request!"); | ||
|
||
if (tune_id->data == 0) | ||
{ | ||
ROS_ERROR("Tune ID 0 (custom tune) not supported, ignoring."); | ||
return; | ||
} | ||
|
||
mavlink::common::msg::PLAY_TUNE msg{}; | ||
|
||
msg.target_system = m_uas->get_tgt_system(); | ||
msg.target_component = m_uas->get_tgt_component(); | ||
|
||
/* Tune definitions: | ||
https://github.com/PX4/Firmware/blob/ | ||
bfab544a64e2dc3b86905771017989502ec40dd2/src/lib/tunes/ | ||
tune_definition.desc#L102 | ||
*/ | ||
msg.tune[0] = tune_id->data; | ||
UAS_FCU(m_uas)->send_message_ignore_drop(msg); | ||
} | ||
}; | ||
} // namespace std_plugins | ||
} // namespace mavros | ||
|
||
#include <pluginlib/class_list_macros.h> | ||
PLUGINLIB_EXPORT_CLASS(mavros::std_plugins::PlayTunePlugin, | ||
mavros::plugin::PluginBase) |