Skip to content

Commit

Permalink
micro-ROS Jazzy patch
Browse files Browse the repository at this point in the history
  • Loading branch information
pablogs9 committed Sep 20, 2024
1 parent 7927b76 commit 8f2fd76
Show file tree
Hide file tree
Showing 27 changed files with 271 additions and 55 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/fork_checker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: micro-ROS fork Update Checker
on:
workflow_dispatch:
inputs:
name:
description: "Manual trigger"
schedule:
- cron: '0 4 * * *'

jobs:
micro_ros_fork_update_check:
runs-on: ubuntu-latest
container: ubuntu:20.04
strategy:
fail-fast: false
matrix:
branches: [galactic, humble, jazzy, rolling]
steps:
- name: Check
id: check
shell: bash
run: |
apt update; apt install -y git
REPO=$(echo ${{ github.repository }} | awk '{split($0,a,"/"); print a[2]}')
git clone -b ${{ matrix.branches }} https://github.com/micro-ros/$REPO
cd $REPO
git remote add ros2 https://github.com/ros2/$REPO
git fetch ros2
git fetch origin
echo "::set-output name=merge_required::true"
CMP=$(git rev-list --left-right --count ros2/${{ matrix.branches }}...origin/${{ matrix.branches }} | awk '{print $1}')
if [ $CMP = "0" ]; then echo "::set-output name=merge_required::false"; fi
- name: Alert
if: ${{ steps.check.outputs.merge_required == 'true' }}
run: exit 1
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"files.associations": {
"*.uml": "plantuml",
"service_event_publisher.h": "c"
}
}
69 changes: 54 additions & 15 deletions rcl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,33 @@ cmake_minimum_required(VERSION 3.5)

project(rcl)

option(RCL_MICROROS "micro-ROS build mode" ON)

find_package(ament_cmake_ros REQUIRED)
find_package(ament_cmake_gen_version_h REQUIRED)

find_package(libyaml_vendor REQUIRED)
find_package(rcl_interfaces REQUIRED)
find_package(rcl_logging_interface REQUIRED)
find_package(rcl_yaml_param_parser REQUIRED)
find_package(rcutils REQUIRED)
find_package(rmw REQUIRED)
find_package(rmw_implementation REQUIRED)
find_package(rosidl_runtime_c REQUIRED)
find_package(service_msgs REQUIRED)
find_package(tracetools REQUIRED)
find_package(type_description_interfaces REQUIRED)
find_package(yaml REQUIRED)

if(NOT RCL_MICROROS)
find_package(libyaml_vendor REQUIRED)
find_package(yaml REQUIRED)
find_package(rcl_yaml_param_parser REQUIRED)
endif()

include(cmake/rcl_set_symbol_visibility_hidden.cmake)
include(cmake/get_default_rcl_logging_implementation.cmake)
get_default_rcl_logging_implementation(RCL_LOGGING_IMPL)

if(NOT RCL_MICROROS)
include(cmake/get_default_rcl_logging_implementation.cmake)
get_default_rcl_logging_implementation(RCL_LOGGING_IMPL)
endif()

# Default to C11
if(NOT CMAKE_C_STANDARD)
Expand All @@ -38,7 +46,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
endif()

set(${PROJECT_NAME}_sources
src/rcl/arguments.c
$<$<NOT:$<BOOL:${RCL_MICROROS}>>:src/rcl/arguments.c>
src/rcl/client.c
src/rcl/common.c
src/rcl/context.c
Expand All @@ -54,13 +62,13 @@ set(${PROJECT_NAME}_sources
src/rcl/lexer.c
src/rcl/lexer_lookahead.c
src/rcl/localhost.c
src/rcl/logging_rosout.c
src/rcl/logging.c
src/rcl/log_level.c
$<$<NOT:$<BOOL:${RCL_MICROROS}>>:src/rcl/logging_rosout.c>
$<$<NOT:$<BOOL:${RCL_MICROROS}>>:src/rcl/logging.c>
$<$<NOT:$<BOOL:${RCL_MICROROS}>>:src/rcl/log_level.c>
src/rcl/network_flow_endpoints.c
src/rcl/node.c
src/rcl/node_options.c
src/rcl/node_type_cache.c
$<$<NOT:$<BOOL:${RCL_MICROROS}>>:src/rcl/node_type_cache.c>
src/rcl/publisher.c
src/rcl/remap.c
src/rcl/node_resolve_name.c
Expand All @@ -72,7 +80,7 @@ set(${PROJECT_NAME}_sources
src/rcl/time.c
src/rcl/timer.c
src/rcl/type_hash.c
src/rcl/type_description_conversions.c
$<$<NOT:$<BOOL:${RCL_MICROROS}>>:src/rcl/type_description_conversions.c>
src/rcl/validate_enclave_name.c
src/rcl/validate_topic_name.c
src/rcl/wait.c
Expand All @@ -88,20 +96,44 @@ target_link_libraries(${PROJECT_NAME} PUBLIC
${rcl_interfaces_TARGETS}
# TODO(clalancette): rcl_logging_interface should be PRIVATE, but downstream depends on it for now
rcl_logging_interface::rcl_logging_interface
rcl_yaml_param_parser::rcl_yaml_param_parser
rcutils::rcutils
rmw::rmw
# TODO(clalancette): rmw_implementation should be PRIVATE, but downstream depends on it for now
rmw_implementation::rmw_implementation
rosidl_runtime_c::rosidl_runtime_c
${type_description_interfaces_TARGETS}
)

target_link_libraries(${PROJECT_NAME} PRIVATE
tracetools::tracetools
)

if(NOT RCL_MICROROS)
target_link_libraries(${PROJECT_NAME} PRIVATE
${RCL_LOGGING_IMPL}::${RCL_LOGGING_IMPL}
${service_msgs_TARGETS}
tracetools::tracetools
yaml
)
endif()

if(NOT RCL_MICROROS)
ament_target_dependencies(${PROJECT_NAME}
"rcl_yaml_param_parser"
)
endif()

if(NOT RCL_MICROROS)
ament_target_dependencies(${PROJECT_NAME}
${RCL_LOGGING_IMPL}
)
endif()

if(NOT RCL_MICROROS)
target_compile_definitions(${PROJECT_NAME}
PUBLIC
RCL_MICROROS_COMPLETE_IMPL
)
endif()

# Allow configuring the default discovery range
if(DEFINED RCL_DEFAULT_DISCOVERY_RANGE)
Expand Down Expand Up @@ -141,14 +173,21 @@ ament_export_dependencies(ament_cmake)
ament_export_dependencies(rcl_interfaces)
# TODO(clalancette): rcl_logging_interface shouldn't be exported, but downstream depends on it for now
ament_export_dependencies(rcl_logging_interface)
ament_export_dependencies(rcl_yaml_param_parser)
ament_export_dependencies(rcutils)
ament_export_dependencies(rmw)
# TODO(clalancette): rmw_implementation shouldn't be exported, but downstream depends on it for now
ament_export_dependencies(rmw_implementation)
ament_export_dependencies(rosidl_runtime_c)
ament_export_dependencies(type_description_interfaces)
ament_generate_version_header(${PROJECT_NAME})
ament_export_dependencies(tracetools)

if(NOT RCL_MICROROS)
ament_export_dependencies(rcl_yaml_param_parser)
endif()

if(NOT RCL_MICROROS)
ament_export_dependencies(${RCL_LOGGING_IMPL})
endif()

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
Expand Down
4 changes: 4 additions & 0 deletions rcl/include/rcl/arguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
#include "rcl/macros.h"
#include "rcl/types.h"
#include "rcl/visibility_control.h"
#ifdef RCL_MICROROS_COMPLETE_IMPL
#include "rcl_yaml_param_parser/types.h"
#else
typedef bool rcl_params_t;
#endif // RCL_MICROROS_COMPLETE_IMPL

#ifdef __cplusplus
extern "C"
Expand Down
11 changes: 5 additions & 6 deletions rcl/include/rcl/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ extern "C"
#include "rmw/init.h"

#include "rcl/allocator.h"
#ifdef RCL_MICROROS_COMPLETE_IMPL
#include "rcl/arguments.h"
#endif // RCL_MICROROS_COMPLETE_IMPL
#include "rcl/init_options.h"
#include "rcl/macros.h"
#include "rcl/types.h"
Expand Down Expand Up @@ -112,21 +114,18 @@ typedef struct rcl_context_impl_s rcl_context_impl_t;
*/
typedef struct rcl_context_s
{
#ifdef RCL_MICROROS_COMPLETE_IMPL
/// Global arguments for all nodes which share this context.
/** Typically generated by the parsing of argc/argv in rcl_init(). */
rcl_arguments_t global_arguments;
#endif // RCL_MICROROS_COMPLETE_IMPL

/// Implementation specific pointer.
rcl_context_impl_t * impl;

// The assumption that this is big enough for an atomic_uint_least64_t is
// ensured with a static_assert in the context.c file.
// In most cases it should just be a plain uint64_t.
/// @cond Doxygen_Suppress
#if !defined(RCL_CONTEXT_ATOMIC_INSTANCE_ID_STORAGE_SIZE)
#define RCL_CONTEXT_ATOMIC_INSTANCE_ID_STORAGE_SIZE sizeof(uint_least64_t)
#endif
/// @endcond
/// Private storage for instance ID atomic.
/**
* Accessing the instance id should be done using the function
Expand All @@ -146,7 +145,7 @@ typedef struct rcl_context_s
* See this paper for an effort to make this possible in the future:
* http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0943r1.html
*/
RCL_ALIGNAS(8) uint8_t instance_id_storage[RCL_CONTEXT_ATOMIC_INSTANCE_ID_STORAGE_SIZE];
uint32_t instance_id_storage;
} rcl_context_t;

/// Return a zero initialization context object.
Expand Down
2 changes: 2 additions & 0 deletions rcl/include/rcl/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ extern "C"
#include <stdint.h>

#include "rcl/allocator.h"
#ifdef RCL_MICROROS_COMPLETE_IMPL
#include "rcl/arguments.h"
#endif // RCL_MICROROS_COMPLETE_IMPL
#include "rcl/context.h"
#include "rcl/guard_condition.h"
#include "rcl/macros.h"
Expand Down
5 changes: 5 additions & 0 deletions rcl/include/rcl/node_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ extern "C"
#endif

#include "rcl/allocator.h"
#ifdef RCL_MICROROS_COMPLETE_IMPL
#include "rcl/arguments.h"
#endif // RCL_MICROROS_COMPLETE_IMPL
#include "rcl/macros.h"

#include "rcl/domain_id.h"

Expand All @@ -46,8 +49,10 @@ typedef struct rcl_node_options_s
/// If false then only use arguments in this struct, otherwise use global arguments also.
bool use_global_arguments;

#ifdef RCL_MICROROS_COMPLETE_IMPL
/// Command line arguments that apply only to this node.
rcl_arguments_t arguments;
#endif // RCL_MICROROS_COMPLETE_IMPL

/// Flag to enable rosout for this node
bool enable_rosout;
Expand Down
4 changes: 4 additions & 0 deletions rcl/src/rcl/arguments_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@

#include "rcl/arguments.h"
#include "rcl/log_level.h"
#ifdef RCL_MICROROS_COMPLETE_IMPL
#include "rcl_yaml_param_parser/types.h"
#else
typedef bool rcl_params_t;
#endif // RCL_MICROROS_COMPLETE_IMPL
#include "./remap_impl.h"

#ifdef __cplusplus
Expand Down
10 changes: 8 additions & 2 deletions rcl/src/rcl/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ extern "C"

#include "rcl/error_handling.h"
#include "rcl/node.h"
#ifdef RCL_MICROROS_COMPLETE_IMPL
#include "rcl/node_type_cache.h"
#endif // RCL_MICROROS_COMPLETE_IMPL
#include "rcl/publisher.h"
#include "rcl/time.h"
#include "rcutils/logging_macros.h"
Expand All @@ -49,7 +51,9 @@ struct rcl_client_impl_s
atomic_int_least64_t sequence_number;
rcl_service_event_publisher_t * service_event_publisher;
char * remapped_service_name;
#ifdef RCL_MICROROS_COMPLETE_IMPL
rosidl_type_hash_t type_hash;
#endif // RCL_MICROROS_COMPLETE_IMPL
};

rcl_client_t
Expand Down Expand Up @@ -178,6 +182,7 @@ rcl_client_init(
client->impl->options = *options;
atomic_init(&client->impl->sequence_number, 0);

#ifdef RCL_MICROROS_COMPLETE_IMPL
const rosidl_type_hash_t * hash = type_support->get_type_hash_func(type_support);
if (hash == NULL) {
RCL_SET_ERROR_MSG("Failed to get the type hash");
Expand All @@ -195,6 +200,7 @@ rcl_client_init(
goto destroy_client;
}
client->impl->type_hash = *hash;
#endif // RCL_MICROROS_COMPLETE_IMPL

RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME, "Client initialized");
TRACETOOLS_TRACEPOINT(
Expand Down Expand Up @@ -256,15 +262,15 @@ rcl_client_fini(rcl_client_t * client, rcl_node_t * node)
RCL_SET_ERROR_MSG(rmw_get_error_string().str);
result = RCL_RET_ERROR;
}

#ifdef RCL_MICROROS_COMPLETE_IMPL
if (
ROSIDL_TYPE_HASH_VERSION_UNSET != client->impl->type_hash.version &&
RCL_RET_OK != rcl_node_type_cache_unregister_type(node, &client->impl->type_hash))
{
RCUTILS_SAFE_FWRITE_TO_STDERR(rcl_get_error_string().str);
result = RCL_RET_ERROR;
}

#endif // RCL_MICROROS_COMPLETE_IMPL
allocator.deallocate(client->impl->remapped_service_name, allocator.state);
client->impl->remapped_service_name = NULL;

Expand Down
16 changes: 7 additions & 9 deletions rcl/src/rcl/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,12 @@ rcl_get_zero_initialized_context(void)
{
static rcl_context_t context = {
.impl = NULL,
.instance_id_storage = {0},
.instance_id_storage = 0,
};
// this is not constexpr so it cannot be in the struct initialization
#ifdef RCL_MICROROS_COMPLETE_IMPL
context.global_arguments = rcl_get_zero_initialized_arguments();
// ensure assumption about static storage
static_assert(
sizeof(context.instance_id_storage) >= sizeof(atomic_uint_least64_t),
"expected rcl_context_t's instance id storage to be >= size of atomic_uint_least64_t");
// initialize atomic
atomic_init((atomic_uint_least64_t *)(&context.instance_id_storage), 0);
#endif // RCL_MICROROS_COMPLETE_IMPL
return context;
}

Expand Down Expand Up @@ -76,7 +72,7 @@ rcl_context_instance_id_t
rcl_context_get_instance_id(const rcl_context_t * context)
{
RCL_CHECK_ARGUMENT_FOR_NULL(context, 0);
return rcutils_atomic_load_uint64_t((atomic_uint_least64_t *)(&context->instance_id_storage));
return context->instance_id_storage;
}

rcl_ret_t
Expand Down Expand Up @@ -110,8 +106,9 @@ __cleanup_context(rcl_context_t * context)
{
rcl_ret_t ret = RCL_RET_OK;
// reset the instance id to 0 to indicate "invalid" (should already be 0, but this is defensive)
rcutils_atomic_store((atomic_uint_least64_t *)(&context->instance_id_storage), 0);
context->instance_id_storage = 0;

#ifdef RCL_MICROROS_COMPLETE_IMPL
// clean up global_arguments if initialized
if (NULL != context->global_arguments.impl) {
ret = rcl_arguments_fini(&(context->global_arguments));
Expand All @@ -124,6 +121,7 @@ __cleanup_context(rcl_context_t * context)
rcl_reset_error();
}
}
#endif // RCL_MICROROS_COMPLETE_IMPL

// if impl is null, nothing else can be cleaned up
if (NULL != context->impl) {
Expand Down
Loading

0 comments on commit 8f2fd76

Please sign in to comment.