-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR adds some infrastructure for being able to create comms systems. A comms system lets you send and receive data under the constrains of a given comms model. The comms model specifies when and how messages should be delivered to its destinations. Subscribers create a regular callback via Ignition Transport and send a request to a centralized broker to bind an address, the robot attached to the address and the topic name used as a callback. Publishers fill a Dataframe message specifying the addresses of the sender and destination and set the payload. Then, publishers need to send via Ignition Transport the message to the centralized broker. Besides the general infrastructure, this PR contains two systems: PerfectComms and CommsEndpoint. PerfectComms is an example of a comms system. As required, it implements the ICommsModel interface and it always delivers the messages to their destinations. CommsEndpoint is a helper system that can be optionally attached to a model (see examples/worlds/comms.sdf) and lets you assign an address to a robot and the subscription topic. The system automatically connects with the broker and bind this address/robot for you. You could do this process manually if needed but I think it's convenient for most of the users. Signed-off-by: Carlos Agüero <caguero@openrobotics.org> Co-authored-by: Ian Chen <ichen@osrfoundation.org> Co-authored-by: Arjo Chakravarty <arjo@openrobotics.org>
- Loading branch information
1 parent
b825c27
commit 7c88a8e
Showing
21 changed files
with
2,132 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR) | ||
|
||
project(ign-gazebo-comms) | ||
|
||
find_package(ignition-transport11 QUIET REQUIRED) | ||
set(IGN_TRANSPORT_VER ${ignition-transport11_VERSION_MAJOR}) | ||
|
||
add_executable(publisher publisher.cc) | ||
target_link_libraries(publisher | ||
ignition-transport${IGN_TRANSPORT_VER}::core) |
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,106 @@ | ||
/* | ||
* Copyright (C) 2022 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. | ||
* | ||
*/ | ||
|
||
// Example: ./publisher addr1 | ||
|
||
#include <atomic> | ||
#include <chrono> | ||
#include <csignal> | ||
#include <iostream> | ||
#include <string> | ||
#include <thread> | ||
|
||
#include <ignition/msgs.hh> | ||
#include <ignition/transport.hh> | ||
|
||
/// \brief Flag used to break the publisher loop and terminate the program. | ||
static std::atomic<bool> g_terminatePub(false); | ||
|
||
////////////////////////////////////////////////// | ||
/// \brief Usage function. | ||
void usage() | ||
{ | ||
std::cerr << "./publisher <dst_address>" << std::endl; | ||
} | ||
|
||
////////////////////////////////////////////////// | ||
/// \brief Function callback executed when a SIGINT or SIGTERM signals are | ||
/// captured. This is used to break the infinite loop that publishes messages | ||
/// and exit the program smoothly. | ||
void signal_handler(int _signal) | ||
{ | ||
if (_signal == SIGINT || _signal == SIGTERM) | ||
g_terminatePub = true; | ||
} | ||
|
||
////////////////////////////////////////////////// | ||
int main(int argc, char **argv) | ||
{ | ||
if (argc != 2) | ||
{ | ||
usage(); | ||
return -1; | ||
} | ||
|
||
// Install a signal handler for SIGINT and SIGTERM. | ||
std::signal(SIGINT, signal_handler); | ||
std::signal(SIGTERM, signal_handler); | ||
|
||
// Create a transport node and advertise a topic. | ||
ignition::transport::Node node; | ||
std::string topic = "/broker/msgs"; | ||
|
||
auto pub = node.Advertise<ignition::msgs::Dataframe>(topic); | ||
if (!pub) | ||
{ | ||
std::cerr << "Error advertising topic [" << topic << "]" << std::endl; | ||
return -1; | ||
} | ||
|
||
std::this_thread::sleep_for(std::chrono::milliseconds(100)); | ||
|
||
// Prepare the message. | ||
ignition::msgs::Dataframe msg; | ||
msg.set_src_address("addr1"); | ||
msg.set_dst_address(argv[1]); | ||
|
||
// Publish messages at 1Hz. | ||
int counter = 0; | ||
while (!g_terminatePub) | ||
{ | ||
// Prepare the payload. | ||
ignition::msgs::StringMsg payload; | ||
payload.set_data("hello world " + std::to_string(counter)); | ||
std::string serializedData; | ||
if (!payload.SerializeToString(&serializedData)) | ||
{ | ||
std::cerr << "Error serializing message\n" | ||
<< payload.DebugString() << std::endl; | ||
} | ||
msg.set_data(serializedData); | ||
|
||
if (!pub.Publish(msg)) | ||
break; | ||
|
||
++counter; | ||
|
||
std::cout << "Publishing hello on topic [" << topic << "]" << std::endl; | ||
std::this_thread::sleep_for(std::chrono::milliseconds(1000)); | ||
} | ||
|
||
return 0; | ||
} |
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,177 @@ | ||
<?xml version="1.0" ?> | ||
<!-- | ||
Ignition Gazebo comms plugin demo. | ||
Compile the comms publisher: | ||
cd ign-gazebo/examples/standalone/comms | ||
mkdir build | ||
cd build | ||
cmake .. | ||
make | ||
Try launching a comms subscriber: | ||
ign topic -e -t addr1/rx | ||
Try launching a comms publisher: | ||
./publisher addr1 | ||
--> | ||
<sdf version="1.6"> | ||
<world name="perfect_comms"> | ||
|
||
<physics name="1ms" type="ignored"> | ||
<max_step_size>0.001</max_step_size> | ||
<real_time_factor>1.0</real_time_factor> | ||
</physics> | ||
<plugin | ||
filename="ignition-gazebo-physics-system" | ||
name="ignition::gazebo::systems::Physics"> | ||
</plugin> | ||
<plugin | ||
filename="ignition-gazebo-user-commands-system" | ||
name="ignition::gazebo::systems::UserCommands"> | ||
</plugin> | ||
<plugin | ||
filename="ignition-gazebo-scene-broadcaster-system" | ||
name="ignition::gazebo::systems::SceneBroadcaster"> | ||
</plugin> | ||
<plugin | ||
filename="ignition-gazebo-perfect-comms-system" | ||
name="ignition::gazebo::systems::PerfectComms"> | ||
</plugin> | ||
|
||
<light type="directional" name="sun"> | ||
<cast_shadows>true</cast_shadows> | ||
<pose>0 0 10 0 0 0</pose> | ||
<diffuse>1 1 1 1</diffuse> | ||
<specular>0.5 0.5 0.5 1</specular> | ||
<attenuation> | ||
<range>1000</range> | ||
<constant>0.9</constant> | ||
<linear>0.01</linear> | ||
<quadratic>0.001</quadratic> | ||
</attenuation> | ||
<direction>-0.5 0.1 -0.9</direction> | ||
</light> | ||
|
||
<model name="ground_plane"> | ||
<static>true</static> | ||
<link name="link"> | ||
<collision name="collision"> | ||
<geometry> | ||
<plane> | ||
<normal>0 0 1</normal> | ||
<size>100 100</size> | ||
</plane> | ||
</geometry> | ||
</collision> | ||
<visual name="visual"> | ||
<geometry> | ||
<plane> | ||
<normal>0 0 1</normal> | ||
<size>100 100</size> | ||
</plane> | ||
</geometry> | ||
<material> | ||
<ambient>0.8 0.8 0.8 1</ambient> | ||
<diffuse>0.8 0.8 0.8 1</diffuse> | ||
<specular>0.8 0.8 0.8 1</specular> | ||
</material> | ||
</visual> | ||
</link> | ||
</model> | ||
|
||
<model name="box1"> | ||
<pose>2 0 0.5 0 0 0</pose> | ||
<link name="box_link"> | ||
<inertial> | ||
<inertia> | ||
<ixx>0.16666</ixx> | ||
<ixy>0</ixy> | ||
<ixz>0</ixz> | ||
<iyy>0.16666</iyy> | ||
<iyz>0</iyz> | ||
<izz>0.16666</izz> | ||
</inertia> | ||
<mass>1.0</mass> | ||
</inertial> | ||
<collision name="box_collision"> | ||
<geometry> | ||
<box> | ||
<size>1 1 1</size> | ||
</box> | ||
</geometry> | ||
</collision> | ||
|
||
<visual name="box_visual"> | ||
<geometry> | ||
<box> | ||
<size>1 1 1</size> | ||
</box> | ||
</geometry> | ||
<material> | ||
<ambient>1 0 0 1</ambient> | ||
<diffuse>1 0 0 1</diffuse> | ||
<specular>1 0 0 1</specular> | ||
</material> | ||
</visual> | ||
</link> | ||
|
||
<plugin | ||
filename="ignition-gazebo-comms-endpoint-system" | ||
name="ignition::gazebo::systems::CommsEndpoint"> | ||
<address>addr1</address> | ||
<topic>addr1/rx</topic> | ||
</plugin> | ||
</model> | ||
|
||
<model name="box2"> | ||
<pose>-2 0 0.5 0 0 0</pose> | ||
<link name="box_link"> | ||
<inertial> | ||
<inertia> | ||
<ixx>0.16666</ixx> | ||
<ixy>0</ixy> | ||
<ixz>0</ixz> | ||
<iyy>0.16666</iyy> | ||
<iyz>0</iyz> | ||
<izz>0.16666</izz> | ||
</inertia> | ||
<mass>1.0</mass> | ||
</inertial> | ||
<collision name="box_collision"> | ||
<geometry> | ||
<box> | ||
<size>1 1 1</size> | ||
</box> | ||
</geometry> | ||
</collision> | ||
|
||
<visual name="box_visual"> | ||
<geometry> | ||
<box> | ||
<size>1 1 1</size> | ||
</box> | ||
</geometry> | ||
<material> | ||
<ambient>0 0 1 1</ambient> | ||
<diffuse>0 0 1 1</diffuse> | ||
<specular>0 0 1 1</specular> | ||
</material> | ||
</visual> | ||
</link> | ||
|
||
<plugin | ||
filename="ignition-gazebo-comms-endpoint-system" | ||
name="ignition::gazebo::systems::CommsEndpoint"> | ||
<address>addr2</address> | ||
<topic>addr2/rx</topic> | ||
<broker> | ||
<bind_service>/broker/bind</bind_service> | ||
<unbind_service>/broker/unbind</unbind_service> | ||
</broker> | ||
</plugin> | ||
|
||
</model> | ||
|
||
</world> | ||
</sdf> |
Oops, something went wrong.