Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions examples/microros_pub/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# ##############################################################################
# apps/examples/microros_pub/CMakeLists.txt
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you 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.
#
# ##############################################################################

if(CONFIG_EXAMPLES_MICROROS_PUB)
nuttx_add_application(
NAME
${CONFIG_EXAMPLES_MICROROS_PUB_PROGNAME}
SRCS
microros_pub_main.c
STACKSIZE
${CONFIG_EXAMPLES_MICROROS_PUB_STACKSIZE}
PRIORITY
${CONFIG_EXAMPLES_MICROROS_PUB_PRIORITY}
DEPENDS
microros_transport)
endif()
30 changes: 30 additions & 0 deletions examples/microros_pub/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#

config EXAMPLES_MICROROS_PUB
tristate "micro-ROS int32 publisher example"
default n
depends on SYSTEM_MICROROS
---help---
Minimal micro-ROS publisher that creates a node and publishes
an std_msgs/Int32 every second on the topic /nuttx_pub. Used
to validate the NuttX-native transport layer end-to-end with
a micro-ROS agent.

if EXAMPLES_MICROROS_PUB

config EXAMPLES_MICROROS_PUB_PROGNAME
string "Program name"
default "microros_pub"

config EXAMPLES_MICROROS_PUB_PRIORITY
int "micro-ROS pub task priority"
default 100

config EXAMPLES_MICROROS_PUB_STACKSIZE
int "micro-ROS pub stack size"
default 8192

endif
25 changes: 25 additions & 0 deletions examples/microros_pub/Make.defs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
############################################################################
# apps/examples/microros_pub/Make.defs
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you 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.
#
############################################################################

ifneq ($(CONFIG_EXAMPLES_MICROROS_PUB),)
CONFIGURED_APPS += $(APPDIR)/examples/microros_pub
endif
32 changes: 32 additions & 0 deletions examples/microros_pub/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
############################################################################
# apps/examples/microros_pub/Makefile
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add cmake build file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added in the same commit alongside Makefile — uses nuttx_add_application with DEPENDS microros_transport

#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you 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.
#
############################################################################

include $(APPDIR)/Make.defs

PROGNAME = $(CONFIG_EXAMPLES_MICROROS_PUB_PROGNAME)
PRIORITY = $(CONFIG_EXAMPLES_MICROROS_PUB_PRIORITY)
STACKSIZE = $(CONFIG_EXAMPLES_MICROROS_PUB_STACKSIZE)
MODULE = $(CONFIG_EXAMPLES_MICROROS_PUB)

MAINSRC = microros_pub_main.c

include $(APPDIR)/Application.mk
109 changes: 109 additions & 0 deletions examples/microros_pub/microros_pub_main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/****************************************************************************
* apps/examples/microros_pub/microros_pub_main.c
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you 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.
*
****************************************************************************/

/****************************************************************************
* Included Files
****************************************************************************/

#include <nuttx/config.h>

#include <stdio.h>
#include <unistd.h>

#include <rcl/rcl.h>
#include <rcl/error_handling.h>
#include <rclc/rclc.h>
#include <rclc/executor.h>
#include <std_msgs/msg/int32.h>

#include <system/microros_transport.h>

/****************************************************************************
* Public Functions
****************************************************************************/

int main(int argc, FAR char *argv[])
{
rcl_publisher_t publisher;
std_msgs__msg__Int32 msg;
rcl_allocator_t allocator;
rclc_support_t support;
rcl_node_t node;
int i;

printf("microros_pub: starting\n");

if (microros_transport_init() != 0)
{
printf("microros_pub: transport init failed\n");
return 1;
}

allocator = rcl_get_default_allocator();

if (rclc_support_init(&support, 0, NULL, &allocator) != RCL_RET_OK)
{
printf("microros_pub: rclc_support_init failed\n");
return 1;
}

if (rclc_node_init_default(&node, "nuttx_node", "", &support)
!= RCL_RET_OK)
{
printf("microros_pub: node init failed\n");
return 1;
}

if (rclc_publisher_init_default(
&publisher,
&node,
ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Int32),
"nuttx_pub") != RCL_RET_OK)
{
printf("microros_pub: publisher init failed\n");
return 1;
}

msg.data = 0;

for (i = 0; i < 30; i++)
{
if (rcl_publish(&publisher, &msg, NULL) == RCL_RET_OK)
{
printf("microros_pub: sent %d\n", (int)msg.data);
}
else
{
printf("microros_pub: publish failed\n");
}

msg.data++;
sleep(1);
}

rcl_publisher_fini(&publisher, &node);
rcl_node_fini(&node);
rclc_support_fini(&support);

printf("microros_pub: done\n");
return 0;
}
50 changes: 50 additions & 0 deletions include/system/microros_transport.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/****************************************************************************
* apps/include/system/microros_transport.h
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you 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.
*
****************************************************************************/

#ifndef __APPS_INCLUDE_SYSTEM_MICROROS_TRANSPORT_H
#define __APPS_INCLUDE_SYSTEM_MICROROS_TRANSPORT_H

#ifdef __cplusplus
extern "C"
{
#endif

/****************************************************************************
* Public Function Prototypes
****************************************************************************/

/* microros_transport_init
*
* Register the NuttX-native transport (UDP or Serial, selected by Kconfig)
* with the rmw_microxrcedds layer. Must be called once before
* rclc_support_init().
*
* Returns 0 on success, negated errno on failure.
*/

int microros_transport_init(void);

#ifdef __cplusplus
}
#endif

#endif /* __APPS_INCLUDE_SYSTEM_MICROROS_TRANSPORT_H */
20 changes: 20 additions & 0 deletions system/microros/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,24 @@ if(CONFIG_SYSTEM_MICROROS)
microros PROPERTIES IMPORTED_LOCATION ${MICROROS_DIR}/libmicroros.a
INTERFACE_INCLUDE_DIRECTORIES ${MICROROS_DIR}/include)
add_dependencies(microros microros_build)

# Transport glue compiled into the apps tree
set(MICROROS_TRANSPORT_SRCS ${MICROROS_DIR}/transport/microros_transport.c)

if(CONFIG_MICROROS_TRANSPORT_UDP)
list(APPEND MICROROS_TRANSPORT_SRCS
${MICROROS_DIR}/transport/microros_transport_udp.c)
endif()

if(CONFIG_MICROROS_TRANSPORT_SERIAL)
list(APPEND MICROROS_TRANSPORT_SRCS
${MICROROS_DIR}/transport/microros_transport_serial.c)
endif()

nuttx_add_library(microros_transport STATIC)
target_sources(microros_transport PRIVATE ${MICROROS_TRANSPORT_SRCS})
target_include_directories(microros_transport
PRIVATE ${MICROROS_DIR}/transport)
target_include_directories(microros_transport PUBLIC ${MICROROS_DIR}/include)
add_dependencies(microros_transport microros_build)
endif()
8 changes: 5 additions & 3 deletions system/microros/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
ifneq ($(CONFIG_SYSTEM_MICROROS),)
CONFIGURED_APPS += $(APPDIR)/system/microros

CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/system/microros/include
CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/system/microros/include
MICROROS_INC_DIRS := $(APPDIR)/system/microros/include \
Comment thread
xiaoxiang781216 marked this conversation as resolved.
$(wildcard $(APPDIR)/system/microros/include/*)
CFLAGS += $(foreach d,$(MICROROS_INC_DIRS),${INCDIR_PREFIX}$(d))
CXXFLAGS += $(foreach d,$(MICROROS_INC_DIRS),${INCDIR_PREFIX}$(d))

LDLIBS += $(APPDIR)/system/microros/libmicroros.a
EXTRA_LIBS += $(APPDIR)/system/microros/libmicroros.a
endif
14 changes: 13 additions & 1 deletion system/microros/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ include $(APPDIR)/Make.defs
MICROROS_DIR := $(APPDIR)/system/microros
MICROROS_LIB_DIR := $(MICROROS_DIR)/micro_ros_lib
MICROROS_DISTRO := $(patsubst "%",%,$(CONFIG_MICROROS_DISTRO))
MICROROS_AR := $(CROSSDEV)ar
MICROROS_AR := $(firstword $(AR))

MAX_NODES := $(CONFIG_MICROROS_MAX_NODES)
MAX_PUB := $(CONFIG_MICROROS_MAX_PUBLISHERS)
Expand All @@ -44,6 +44,18 @@ ESCAPED_CXXFLAGS := $(subst /,\/,$(subst ",,$(CXXFLAGS)))

MENUDESC = "micro-ROS Library"

# Transport sources compiled into the user-side app library

CSRCS += transport/microros_transport.c

ifeq ($(CONFIG_MICROROS_TRANSPORT_UDP),y)
CSRCS += transport/microros_transport_udp.c
endif

ifeq ($(CONFIG_MICROROS_TRANSPORT_SERIAL),y)
CSRCS += transport/microros_transport_serial.c
endif

# Architecture for CMake toolchain
ifeq ($(CONFIG_ARCH_ARM),y)
MICROROS_ARCH := arm
Expand Down
4 changes: 2 additions & 2 deletions system/microros/micro_ros_lib/toolchain.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ set(PLATFORM_NAME "nuttx")
set(CMAKE_C_COMPILER @CMAKE_C_COMPILER@)
set(CMAKE_CXX_COMPILER @CMAKE_CXX_COMPILER@)

set(CMAKE_C_FLAGS_INIT "-std=c11 @ARCH_C_FLAGS@ -D__NuttX__ -D'__attribute__(x)='" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS_INIT "-std=c++14 @ARCH_CPP_FLAGS@ -fno-rtti -D__NuttX__ -D'__attribute__(x)='" CACHE STRING "" FORCE)
set(CMAKE_C_FLAGS_INIT "-std=c11 @ARCH_C_FLAGS@ -D__NuttX__" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS_INIT "-std=c++14 @ARCH_CPP_FLAGS@ -fno-rtti -D__NuttX__" CACHE STRING "" FORCE)

set(NUTTX_TOPDIR @NUTTX_TOPDIR@)
set(NUTTX_APPDIR @NUTTX_APPDIR@)
Expand Down
Loading
Loading