Skip to content

Commit

Permalink
Added ROS 2 Topic Support to Shapes Demo (#51)
Browse files Browse the repository at this point in the history
* Refs #14447: Added TypeSupport

Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>

* Refs #14447: Added new type IDL and generated files

Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>

* Refs #14447: Modified CMakeLists, type includes and ShapesDemo

Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>

* Refs #14447: UI changes

Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>

* Refs #14447: Modified README.md

Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>

* Refs #14447: Disabled QOS parameters not relevant for ROS2

Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>

* Refs #14447: Disabled ROS 2 unnecessary QOS assignments

Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>

* Refs #14447: Applied suggestions

Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>

* Refs #14447: Typos

Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>
  • Loading branch information
jsan-rt authored May 18, 2022
1 parent 16a6cf8 commit dc1ad80
Show file tree
Hide file tree
Showing 32 changed files with 1,799 additions and 132 deletions.
29 changes: 29 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,22 @@ endif()
eprosima_find_package(fastcdr)
eprosima_find_package(fastrtps OPTION TINYXML2_FROM_SOURCE)

# Required by ContentFilteredTopic
if (NOT fastrtps_FOUND OR fastrtps_VERSION LESS 2.5.1)
message(FATAL_ERROR "Trying to use a version of Fast-DDS lower than 2.5.1. Please update your Fast-DDS installation.")
endif()

if(BUILD_ROS_COMPONENTS)
# If ROS environment is not set, disable ROS features.
if (DEFINED ENV{ROS_VERSION})
add_subdirectory(shapes_demo_typesupport)
else()
message(WARNING "ROS environment not found. Disabling requested ROS 2 integration.")
set(BUILD_ROS_COMPONENTS OFF)
endif()

endif()

###############################################################################
# Compile
###############################################################################
Expand Down Expand Up @@ -191,6 +207,14 @@ set( SHAPESDEMO_SOURCES
images/eprosima_icon.rc
)

if(BUILD_ROS_COMPONENTS)
list( APPEND SHAPESDEMO_SOURCES
src/shapesdemo/KeylessShape.cxx
src/shapesdemo/KeylessShapePubSubTypes.cxx
src/shapesdemo/KeylessShapeTypeObject.cxx
)
endif()

if(THIRDPARTY)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
Expand All @@ -204,6 +228,11 @@ endif()

target_compile_definitions(${PROJECT_NAME} PRIVATE -D${SHAPESVERSION})
target_include_directories(${PROJECT_NAME} PRIVATE include ${IU_HEADERS})

if(BUILD_ROS_COMPONENTS)
target_compile_definitions(${PROJECT_NAME} PRIVATE -DENABLE_ROS_COMPONENTS)
endif()

target_link_libraries(${PROJECT_NAME} fastrtps fastcdr Qt5::Widgets Qt5::Core Qt5::Gui)

###############################################################################
Expand Down
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,51 @@ Two methods are provided:
The other available tab in this section shows an output log:

![Output](docs/log.png)

### ROS 2 Compatibility

By default eProsima Shapes Demo can be built and used on a ROS 2 installation as long as an installation of Fast DDS version 2.5.1 or higher is available and the qt5-default package has been installed.
However, ROS 2 will not be able to interact with the Shapes Demo Topics in any way.

A CMake flag can be used to build eProsima Shapes Demo with ROS 2 support enabled.

$ colcon build --cmake-args -DBUILD_ROS_COMPONENTS=ON

This will display an additional "Use ROS2 Topics" checkbox in the Participant configuration dialog.

![Participant Windows With ROS Enabled](docs/participant_ros_enabled.png)

When using eProsima Shapes Demo with this checkbox marked, ROS 2 will be aware of the Topics transmitted.

$ ros2 topic list -t
/Square [shapes_demo_typesupport/idl/KeylessShapeType]
/parameter_events [rcl_interfaces/msg/ParameterEvent]
/rosout [rcl_interfaces/msg/Log]

When building eProsima Shapes Demo with ROS 2 capabilities enabled, a TypeSupport will be built for KeylessShapeType. Sourcing the generated environment will make it available to ROS 2 applications, allowing the usage of ROS commands like the following.

$ source install/setup.bash
$ ros2 topic echo /Square
color: RED
x: 175
y: 215
shapesize: 30
---
color: RED
x: 169
y: 210
shapesize: 30
---

$ ros2 topic pub /Square shapes_demo_typesupport/idl/KeylessShapeType "{ color: BLUE, x: 155, y: 150, shapesize: 30}"
publisher: beginning loop
publishing #1: shapes_demo_typesupport.idl.KeylessShapeType(color='BLUE', x=155, y=150, shapesize=30)


---
**NOTE**

ROS 2 Topics enablement will disable some QoS that are not supported by ROS 2 at the moment, namely Ownership and Partitions.
Their respective checkboxes will be disabled on the Publisher and Subscriber Dialogs.

---
Binary file added docs/participant_ros_enabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 29 additions & 2 deletions forms/participantdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
<item row="8" column="4">
<widget class="QLineEdit" name="lineEdit_server_ip"/>
</item>
<item row="23" column="3">
<item row="25" column="3">
<widget class="QPushButton" name="pushButton_start">
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
Expand All @@ -114,7 +114,7 @@
</property>
</widget>
</item>
<item row="23" column="4">
<item row="25" column="4">
<widget class="QPushButton" name="pushButton_stop">
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
Expand Down Expand Up @@ -161,6 +161,33 @@
</property>
</widget>
</item>
<item row="21" column="0">
<widget class="Line" name="line_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="22" column="0">
<widget class="QLabel" name="label_12">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>ROS</string>
</property>
</widget>
</item>
<item row="23" column="1">
<widget class="QCheckBox" name="rosTopicCheckBox">
<property name="text">
<string>Use ROS2 Topics</string>
</property>
</widget>
</item>
<item row="9" column="1">
<widget class="QCheckBox" name="TCPcheckBox">
<property name="text">
Expand Down
98 changes: 65 additions & 33 deletions forms/ui/ui_optionsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,46 +28,53 @@ QT_BEGIN_NAMESPACE
class Ui_OptionsDialog
{
public:
QGridLayout *gridLayout;
QDialogButtonBox *buttonBox;
QLabel *label_8;
QSpinBox *spin_updateInterval;
QPushButton *pushButton_udp;
QSlider *horizontalSlider_speed;
QLabel *label_5;
QSpinBox *spin_listen_port;
QPushButton *pushButton_tcp_client;
QPushButton *pushButton_tcp_server;
QSpinBox *spin_server_port;
QLabel *label_6;
QLabel *label_3;
QLineEdit *lineEdit_server_ip;
QLabel *label_7;
QPushButton *pushButton_tcp_WAN_server;
QLabel *label_2;
QLabel *label_4;
QFrame *line_2;
QComboBox *comboBox;
QFrame *line;
QLabel *label_9;
QFrame *line_3;
QCheckBox *statisticsCheckBox;
QSpinBox *spin_domainId;
QPushButton *pushButton_start;
QPushButton *pushButton_stop;
QLabel *label_10;

void setupUi(QDialog *OptionsDialog)

QGridLayout* gridLayout;
QDialogButtonBox* buttonBox;
QLabel* label_8;
QSpinBox* spin_updateInterval;
QPushButton* pushButton_udp;
QSlider* horizontalSlider_speed;
QLabel* label_5;
QSpinBox* spin_listen_port;
QPushButton* pushButton_tcp_client;
QPushButton* pushButton_tcp_server;
QSpinBox* spin_server_port;
QLabel* label_6;
QLabel* label_3;
QLineEdit* lineEdit_server_ip;
QLabel* label_7;
QPushButton* pushButton_tcp_WAN_server;
QLabel* label_2;
QLabel* label_4;
QFrame* line_2;
QComboBox* comboBox;
QFrame* line;
QLabel* label_9;
QFrame* line_3;
QCheckBox* statisticsCheckBox;
QFrame* line_5;
QLabel* label_12;
QCheckBox* rosTopicCheckBox;
QSpinBox* spin_domainId;
QPushButton* pushButton_start;
QPushButton* pushButton_stop;
QLabel* label_10;

void setupUi(
QDialog* OptionsDialog)
{
if (OptionsDialog->objectName().isEmpty())
{
OptionsDialog->setObjectName(QString::fromUtf8("OptionsDialog"));
}
OptionsDialog->resize(467, 335);
gridLayout = new QGridLayout(OptionsDialog);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
buttonBox = new QDialogButtonBox(OptionsDialog);
buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
buttonBox->setOrientation(Qt::Horizontal);
buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
buttonBox->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);

gridLayout->addWidget(buttonBox, 15, 3, 1, 2);

Expand Down Expand Up @@ -212,6 +219,26 @@ class Ui_OptionsDialog

gridLayout->addWidget(statisticsCheckBox, 9, 2, 1, 1);

#ifdef ENABLE_ROS_COMPONENTS
line_5 = new QFrame(OptionsDialog);
line_5->setObjectName(QString::fromUtf8("line_5"));
line_5->setFrameShape(QFrame::HLine);
line_5->setFrameShadow(QFrame::Sunken);

gridLayout->addWidget(line_5, 11, 0, 1, 1);

label_12 = new QLabel(OptionsDialog);
label_12->setObjectName(QString::fromUtf8("label_12"));
label_12->setFont(font);

gridLayout->addWidget(label_4, 9, 0, 1, 1);

rosTopicCheckBox = new QCheckBox(OptionsDialog);
rosTopicCheckBox->setObjectName(QString::fromUtf8("rosTopicCheckBox"));

gridLayout->addWidget(rosTopicCheckBox, 9, 2, 1, 1);
#endif

spin_domainId = new QSpinBox(OptionsDialog);
spin_domainId->setObjectName(QString::fromUtf8("spin_domainId"));
spin_domainId->setValue(80);
Expand Down Expand Up @@ -252,7 +279,8 @@ class Ui_OptionsDialog
QMetaObject::connectSlotsByName(OptionsDialog);
} // setupUi

void retranslateUi(QDialog *OptionsDialog)
void retranslateUi(
QDialog* OptionsDialog)
{
OptionsDialog->setWindowTitle(QApplication::translate("OptionsDialog", "Options", nullptr));
label_8->setText(QApplication::translate("OptionsDialog", "Listen Port:", nullptr));
Expand All @@ -274,6 +302,8 @@ class Ui_OptionsDialog
label_4->setText(QApplication::translate("OptionsDialog", "Statistics", nullptr));
label_9->setText(QApplication::translate("OptionsDialog", "Shape Movements", nullptr));
statisticsCheckBox->setText(QApplication::translate("OptionsDialog", "Active Statistics", nullptr));
rosTopicCheckBox->setText(QApplication::translate("OptionsDialog", "Use ROS 2 Topics", nullptr));

spin_domainId->setSpecialValueText(QString());
spin_domainId->setSuffix(QString());
pushButton_start->setText(QApplication::translate("OptionsDialog", "Start", nullptr));
Expand All @@ -284,7 +314,9 @@ class Ui_OptionsDialog
};

namespace Ui {
class OptionsDialog: public Ui_OptionsDialog {};
class OptionsDialog : public Ui_OptionsDialog
{
};
} // namespace Ui

QT_END_NAMESPACE
Expand Down
12 changes: 12 additions & 0 deletions idl/KeylessShape.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module shapes_demo_typesupport
{
module idl
{
struct KeylessShapeType {
string color;
long x;
long y;
long shapesize;
};
};
};
1 change: 1 addition & 0 deletions images/eprosimalogo.qrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<RCC>
<qresource prefix="/">
<file>eProsimaLogo.png</file>
<file>vulcanexusLogo.png</file>
</qresource>
</RCC>
Binary file added images/vulcanexusLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions include/eprosimashapesdemo/qt/participantdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ private slots:
void on_statisticsCheckBox_stateChanged(
int arg1);

void on_rosTopicCheckBox_stateChanged(
int arg1);

void on_IntraprocesscheckBox_stateChanged(
int arg1);

Expand Down
Loading

0 comments on commit dc1ad80

Please sign in to comment.