Skip to content

Commit

Permalink
Use foxglove_bridge_base library
Browse files Browse the repository at this point in the history
  • Loading branch information
jhurliman committed Nov 2, 2022
1 parent 5684176 commit 4595363
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 33 deletions.
9 changes: 6 additions & 3 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ ReflowComments: true
SortIncludes: true

IncludeCategories:
- Regex: "^<foxglove"
Priority: 1
- Regex: "^\".*"
Priority: 4
SortPriority: 0
- Regex: "^<foxglove.*"
Priority: 3
SortPriority: 0
- Regex: "^<.*/"
Priority: 2
SortPriority: 0
- Regex: "^<.*"
Priority: 3
Priority: 1
SortPriority: 0
7 changes: 2 additions & 5 deletions .devcontainer/Dockerfile.ros1
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
git \
&& rm -rf /var/lib/apt/lists/*

# Create a Catkin workspace
RUN source /opt/ros/noetic/setup.bash \
&& mkdir -p /ros_ws/src \
&& cd /ros_ws/src \
&& catkin_init_workspace
# Create a ROS 1 workspace
RUN mkdir -p /ros1_ws/src/ros-foxglove-bridge

# Source the ROS environment in .bashrc
RUN echo "source /opt/ros/noetic/setup.bash" >> /root/.bashrc
1 change: 1 addition & 0 deletions .devcontainer/Dockerfile.ros2
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
git \
&& rm -rf /var/lib/apt/lists/*

# Create a ROS 2 workspace
RUN mkdir -p /ros2_ws/src/ros-foxglove-bridge

# Source the ROS environment in .bashrc
Expand Down
8 changes: 6 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
{
// ROS 2 dev environment
"name": "ROS 2",
"workspaceFolder": "/ros2_ws/src/ros-foxglove-bridge",
"workspaceMount": "source=${localWorkspaceFolder},target=/ros2_ws/src/ros-foxglove-bridge,type=bind,consistency=cached",
"dockerFile": "./Dockerfile.ros2",
// Comment the lines above and uncomment these lines to switch the VS Code
// dev container from a ROS 2 environment to ROS 1

// ROS 1 dev environment
// "name": "ROS 1",
// "workspaceFolder": "/ros1_ws/src/ros-foxglove-bridge",
// "workspaceMount": "source=${localWorkspaceFolder},target=/ros1_ws/src/ros-foxglove-bridge,type=bind,consistency=cached",
// "dockerFile": "./Dockerfile.ros1",

// Shared configuration between ROS 1 and ROS 2 environments
"context": "..",
"forwardPorts": [
8080
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"C_Cpp.autoAddFileAssociations": false,
"editor.defaultFormatter": "xaver.clang-format",
"editor.formatOnSave": true,
"files.eol": "\n",
Expand Down
25 changes: 16 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)

option(ENABLE_ASAN "Enable Address Sanitizer" OFF)

find_package(Threads REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(websocketpp REQUIRED)

Expand Down Expand Up @@ -43,8 +44,18 @@ IF(NOT WIN32 AND ENABLE_ASAN)
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=address")
endif()

include_directories(foxglove_bridge_base/include)

# Build the foxglove_bridge_base library
add_library(foxglove_bridge_base STATIC
foxglove_bridge_base/src/foxglove_bridge.cpp
)
target_include_directories(foxglove_bridge_base
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/foxglove_bridge_base/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(foxglove_bridge_base OpenSSL::Crypto OpenSSL::SSL ${CMAKE_THREAD_LIBS_INIT})

# Compile the ROS 1 or ROS 2 node
# http://answers.ros.org/question/230877/optionally-build-a-package-with-catkin/
if(CATKIN_DEVEL_PREFIX OR catkin_FOUND OR CATKIN_BUILD_BINARY_PACKAGE)
set(COMPILING_ROS1 1)
Expand All @@ -59,15 +70,13 @@ if(CATKIN_DEVEL_PREFIX OR catkin_FOUND OR CATKIN_BUILD_BINARY_PACKAGE)
INCLUDE_DIRS foxglove_bridge_base/include
LIBRARIES foxglove_bridge_base
CATKIN_DEPENDS roslib roscpp
DEPENDS OpenSSL websocketpp
)

message(STATUS ${catkin_INCLUDE_DIRS})
add_definitions(-DIS_ROS1)

add_executable(foxglove_bridge ros1_foxglove_bridge/ros1_foxglove_bridge.cpp)
target_include_directories(foxglove_bridge SYSTEM PRIVATE ${catkin_INCLUDE_DIRS})
target_link_libraries(foxglove_bridge OpenSSL::Crypto OpenSSL::SSL ${catkin_LIBRARIES})
target_link_libraries(foxglove_bridge foxglove_bridge_base ${catkin_LIBRARIES})
elseif(DEFINED ENV{AMENT_PREFIX_PATH})
set(COMPILING_ROS2 1)

Expand All @@ -79,14 +88,12 @@ elseif(DEFINED ENV{AMENT_PREFIX_PATH})
message(STATUS "foxglove_bridge is being built for ROS 2.")
message(STATUS "--------------------------------------------------")

message(STATUS ${catkin_INCLUDE_DIRS})

add_definitions(-DIS_ROS2)

add_executable(foxglove_bridge ros2_foxglove_bridge/ros2_foxglove_bridge.cpp)
target_include_directories(foxglove_bridge SYSTEM PRIVATE ${ament_index_cpp_INCLUDE_DIRS})
ament_target_dependencies(foxglove_bridge rclcpp OpenSSL websocketpp)
target_link_libraries(foxglove_bridge OpenSSL::Crypto OpenSSL::SSL)
ament_target_dependencies(foxglove_bridge rclcpp)
target_link_libraries(foxglove_bridge foxglove_bridge_base)
else()
message(FATAL_ERROR "No ROS 1 or ROS 2 build environment detected.")
endif()
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
#pragma once

namespace foxglove {

const char* WebSocketUserAgent();

} // namespace foxglove
14 changes: 14 additions & 0 deletions foxglove_bridge_base/src/foxglove_bridge.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
#include "foxglove_bridge/foxglove_bridge.hpp"

#define ASIO_STANDALONE
#include <websocketpp/config/asio.hpp>
#include <websocketpp/server.hpp>

using Server = websocketpp::server<websocketpp::config::asio_tls>;
using ConnectionHdl = websocketpp::connection_hdl;
using SslContext = websocketpp::lib::asio::ssl::context;
using websocketpp::lib::placeholders::_1;
using websocketpp::lib::placeholders::_2;

const char* foxglove::WebSocketUserAgent() {
return websocketpp::user_agent;
}
5 changes: 4 additions & 1 deletion ros1_foxglove_bridge/ros1_foxglove_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <websocketpp/config/asio.hpp>
#include <websocketpp/server.hpp>

#include <foxglove_bridge/foxglove_bridge.hpp>

using Server = websocketpp::server<websocketpp::config::asio_tls>;
using ConnectionHdl = websocketpp::connection_hdl;
using SslContext = websocketpp::lib::asio::ssl::context;
Expand All @@ -14,7 +16,8 @@ class FoxgloveBridge {
public:
explicit FoxgloveBridge(ros::NodeHandle& node) {
(void)node;
ROS_INFO("Starting %s", ros::this_node::getName().c_str());
ROS_INFO("Starting %s with %s", ros::this_node::getName().c_str(),
foxglove::WebSocketUserAgent());
}

private:
Expand Down
17 changes: 4 additions & 13 deletions ros2_foxglove_bridge/ros2_foxglove_bridge.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
#define ASIO_STANDALONE

#include <rclcpp/rclcpp.hpp>
#include <websocketpp/config/asio.hpp>
#include <websocketpp/server.hpp>

#include <chrono>
#include <memory>

using Server = websocketpp::server<websocketpp::config::asio_tls>;
using ConnectionHdl = websocketpp::connection_hdl;
using SslContext = websocketpp::lib::asio::ssl::context;
using websocketpp::lib::placeholders::_1;
using websocketpp::lib::placeholders::_2;
#include <rclcpp/rclcpp.hpp>

using namespace std::chrono_literals;
#include <foxglove_bridge/foxglove_bridge.hpp>

class FoxgloveBridge : public rclcpp::Node {
public:
FoxgloveBridge()
: Node("foxglove_bridge") {
RCLCPP_INFO(this->get_logger(), "Starting %s", this->get_name());
RCLCPP_INFO(this->get_logger(), "Starting %s with %s", this->get_name(),
foxglove::WebSocketUserAgent());
}

private:
Expand Down

0 comments on commit 4595363

Please sign in to comment.