-
Notifications
You must be signed in to change notification settings - Fork 13
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
Adding acoustic subsystem examples #236
Changes from 1 commit
64efc0b
f13dfff
ba2c76b
83e7a3d
af9cace
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,61 @@ | ||
/* | ||
* Copyright (C) 2021 Open Source Robotics Foundation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
/* | ||
* Development of this module has been funded by the Monterey Bay Aquarium | ||
* Research Institute (MBARI) and the David and Lucile Packard Foundation | ||
*/ | ||
|
||
/** | ||
* This is a small example of usage of CommsClient to send and receive data | ||
* packets using the acoustic subsystem. For more info: | ||
* https:/osrf/lrauv/wiki/Examples-and-tutorials#using-commsclient | ||
* | ||
* Usage: | ||
* $ ./LRAUV_example_comms_client | ||
*/ | ||
|
||
#include <lrauv_ignition_plugins/comms/CommsClient.hh> | ||
|
||
using namespace tethys; | ||
using AcousticMsg = lrauv_ignition_plugins::msgs::LRAUVAcousticMessage; | ||
|
||
int main(int _argc, char **_argv) | ||
{ | ||
|
||
// For sending data | ||
// Bind client to address 1 | ||
CommsClient client(1, [](const auto msg){ | ||
// Your callback function | ||
// To get who the message is from | ||
std::cout << "From: " << msg.from(); | ||
// To get the data call | ||
std::cout << "Data: " << msg.data(); | ||
}); | ||
|
||
AcousticMsg msg; | ||
// Who to send to | ||
msg.set_to(2); | ||
// From who | ||
msg.set_from(1); | ||
// `LRAUVAcousticMessage_MessageType_Other` means its a data packet | ||
msg.set_type(AcousticMsg::MessageType::LRAUVAcousticMessage_MessageType_Other); | ||
// The data | ||
msg.set_data("test_message"); | ||
client.SendPacket(msg); | ||
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. @marcoag hmm, isn't the service response racing with process shutdown? 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. tbh, I'm not sure... but could be? I mostly copied whatever was there on the documentation example before. 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. @marcoag could we wait for the response to arrive before exiting? 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. Sure, just added a sender and a receiver for extra clarity and some more verbosity to the example. |
||
|
||
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. @marcoag nit: unnecessary blank line. 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. Removed. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright (C) 2021 Open Source Robotics Foundation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
/* | ||
* Development of this module has been funded by the Monterey Bay Aquarium | ||
* Research Institute (MBARI) and the David and Lucile Packard Foundation | ||
*/ | ||
|
||
/** | ||
* This is a small example of usage of gazebo transport to send and receive | ||
* data packets using the acoustic subsystem. For more info: | ||
* https:/osrf/lrauv/wiki/Examples-and-tutorials#direct-method | ||
hidmic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* Usage: | ||
* $ ./LRAUV_example_comms_echo | ||
*/ | ||
|
||
#include <unistd.h> | ||
#include <gz/transport/Node.hh> | ||
#include "lrauv_ignition_plugins/lrauv_acoustic_message.pb.h" | ||
|
||
int address = 1; | ||
hidmic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
gz::transport::Node node; | ||
gz::transport::Node::Publisher transmitter; | ||
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. @marcoag perhaps we move these to the 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. Moved the |
||
using AcousticMsg = lrauv_ignition_plugins::msgs::LRAUVAcousticMessage; | ||
|
||
////////////////////////////////////////////////// | ||
/// \brief Function called each time a message is recieved by the comms subsystem. | ||
void cb(const lrauv_ignition_plugins::msgs::LRAUVAcousticMessage &_msg) | ||
{ | ||
std::cout << _msg.from() << ": " << _msg.data(); | ||
|
||
lrauv_ignition_plugins::msgs::LRAUVAcousticMessage returnMsg; | ||
// Who to send to | ||
returnMsg.set_to(_msg.from()); | ||
|
||
// From who | ||
returnMsg.set_from(address); | ||
|
||
// `LRAUVAcousticMessage_MessageType_Other` means its a data packet | ||
returnMsg.set_type(AcousticMsg::MessageType::LRAUVAcousticMessage_MessageType_Other); | ||
|
||
// The data | ||
returnMsg.set_data(_msg.data()); | ||
|
||
// Send the data | ||
transmitter.Publish(returnMsg); | ||
} | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
transmitter = node.Advertise<lrauv_ignition_plugins::msgs::LRAUVAcousticMessage>( | ||
"/comms/external/" + std::to_string(address) + "/tx"); | ||
|
||
node.Subscribe( | ||
"/comms/external/" + std::to_string(address) + "/rx", | ||
cb | ||
); | ||
|
||
while(true) { sleep(1); } | ||
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. @marcoag IIRC there's a 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. Good point, added. |
||
} |
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.
@marcoag nit: unnecessary blank line.
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.
Removed.