Skip to content

Commit

Permalink
micro-ROS Rolling patch
Browse files Browse the repository at this point in the history
* Avoid logging on build time based on RCutils flags (#6)

* Add RCL_YAML_PARSER and RCL_LOGGING CMake options.

* Replace RCL_YAML_PARSER by RCL_COMMAND_LINE_ENABLED and RCL_LOGGING by RCL_LOGGING_ENABLED.

* Disabled logging fix

* Fix remapping (#7)

Co-authored-by: Pablo Garrido <pablogs9@gmail.com>
Co-authored-by: julibert <julianbermudez@eprosima.com>

Updates 17092020

*Release micro-ROS Foxy (#9)

Cleaning


Update


Update


Update


Add workflow checker
Update


Update


update


Test


Test


Update


Update


Update


New approach


Update


Update


Update


Update


Update


Update


Update


Update


Update


Update


Update


Update


Update


Update


Update


Update


Update


Update


Update


Update


Update


Update


Update


Update


Update


Update


Update


Disable logger name (#11) (#13)

(cherry picked from commit 1fac9bf)

Co-authored-by: Pablo Garrido <pablogs9@gmail.com>

Avoid uint64_t operation when handling context (#16) (#18)

* Update

Signed-off-by: Pablo Garrido <pablogs9@gmail.com>

Update

Signed-off-by: Pablo Garrido <pablogs9@gmail.com>

Update

Signed-off-by: Pablo Garrido <pablogs9@gmail.com>

Update

Signed-off-by: Pablo Garrido <pablogs9@gmail.com>

* Update

Signed-off-by: Pablo Garrido <pablogs9@gmail.com>

* Clean PR

* Clean id rollover check

* Fix rollover

Co-authored-by: acuadros95 <acuadros1995@gmail.com>
(cherry picked from commit 32aa288)

Co-authored-by: Pablo Garrido <pablogs9@gmail.com>

Update fork checker for Humble

Signed-off-by: Pablo Garrido <pablogs9@gmail.com>

Update micro-ROS conditional compilation
  • Loading branch information
pablogs9 committed May 6, 2024
1 parent f01409f commit b5b9062
Show file tree
Hide file tree
Showing 15 changed files with 198 additions and 59 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: [foxy, galactic, humble, 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
64 changes: 52 additions & 12 deletions rcl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,32 @@ cmake_minimum_required(VERSION 3.5)

project(rcl)

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

find_package(ament_cmake_ros 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 @@ -37,7 +45,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 @@ -53,9 +61,9 @@ 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
Expand Down Expand Up @@ -87,20 +95,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 @@ -140,13 +172,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_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
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 b5b9062

Please sign in to comment.