Skip to content
Merged
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
83 changes: 83 additions & 0 deletions apps/int32_wifi_publisher/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.13.1)

set(COMPATIBLE_BOARDS disco_l475_iot1)
if(NOT ${BOARD} IN_LIST COMPATIBLE_BOARDS)
message(FATAL_ERROR "App $ENV{UROS_APP} not compatible with board ${BOARD}")
endif()

include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(microrosapp C CXX)

FILE(GLOB app_sources src/*.c ../../microros_extensions/libatomic.c)

target_sources(app PRIVATE ${app_sources})

zephyr_get_include_directories_for_lang_as_string( C includes)
zephyr_get_system_include_directories_for_lang_as_string(C system_includes)
zephyr_get_compile_definitions_for_lang_as_string( C definitions)
zephyr_get_compile_options_for_lang_as_string( C options)

zephyr_get_include_directories_for_lang_as_string( CXX includes_cxx)
zephyr_get_system_include_directories_for_lang_as_string(CXX system_includes_cxx)
zephyr_get_compile_definitions_for_lang_as_string( CXX definitions_cxx)
zephyr_get_compile_options_for_lang_as_string( CXX options_cxx)

set(external_project_cflags
"${includes} ${definitions} ${options} ${system_includes}"
)

set(external_project_cxxflags
"${includes_cxx} ${definitions_cxx} ${options_cxx} ${system_includes_cxx}"
)

include(ExternalProject)

set(microros_src_dir ${CMAKE_CURRENT_SOURCE_DIR}/../../microros_extensions)
set(microros_build_dir ${CMAKE_CURRENT_BINARY_DIR}/microros_extensions)

if(CMAKE_GENERATOR STREQUAL "Unix Makefiles")
set(submake "$(MAKE)")
else()
set(submake "make")
endif()

ExternalProject_Add(
microroslib_project # Name for custom target
PREFIX ${microros_build_dir} # Root dir for entire project
SOURCE_DIR ${microros_src_dir}
BINARY_DIR ${microros_src_dir} # This particular build system is invoked from the root
CONFIGURE_COMMAND "" # Skip configuring the project, e.g. with autoconf
BUILD_COMMAND
${submake}
PREFIX=${microros_src_dir}
CC=${CMAKE_C_COMPILER}
AR=${CMAKE_AR}
CFLAGS=${external_project_cflags}
CXX=${CMAKE_CXX_COMPILER}
CXXFLAGS=${external_project_cxxflags}
APP_META=$ENV{UROS_APP_FOLDER}/app-colcon.meta

INSTALL_COMMAND "" # This particular build system has no install command
BUILD_BYPRODUCTS ${MICROROS_LIB_DIR}/libmicroros.a
)

file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../../mcu_ws/install)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../../mcu_ws/install/include)

set(MICROROS_LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../mcu_ws/install)
set(MICROROS_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../mcu_ws/install/include)

add_library(microroslib STATIC IMPORTED GLOBAL)
add_dependencies(
microroslib
microroslib_project
)

add_dependencies(microroslib_project offsets_h)

set_target_properties(microroslib PROPERTIES IMPORTED_LOCATION ${MICROROS_LIB_DIR}/libmicroros.a)
set_target_properties(microroslib PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${MICROROS_INCLUDE_DIR})

target_link_libraries(app PUBLIC microroslib)
14 changes: 14 additions & 0 deletions apps/int32_wifi_publisher/app-colcon.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"names": {
"rmw_microxrcedds": {
"cmake-args": [
"-DRMW_UXRCE_MAX_NODES=1",
"-DRMW_UXRCE_MAX_PUBLISHERS=1",
"-DRMW_UXRCE_MAX_SUBSCRIPTIONS=0",
"-DRMW_UXRCE_MAX_SERVICES=0",
"-DRMW_UXRCE_MAX_CLIENTS=0",
"-DRMW_UXRCE_MAX_HISTORY=1"
]
}
}
}
36 changes: 36 additions & 0 deletions apps/int32_wifi_publisher/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
CONFIG_MAIN_STACK_SIZE=25000
CONFIG_MAIN_THREAD_PRIORITY=3

CONFIG_NEWLIB_LIBC=y
CONFIG_NEWLIB_LIBC_NANO=n
CONFIG_CPLUSPLUS=y
CONFIG_LIB_CPLUSPLUS=y
CONFIG_PTHREAD_IPC=n

CONFIG_POSIX_API=y
CONFIG_NATIVE_POSIX_TIMER=y
CONFIG_APP_LINK_WITH_POSIX_SUBSYS=y
CONFIG_POSIX_CLOCK=y

CONFIG_HEAP_MEM_POOL_SIZE=8192
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
CONFIG_NET_IPV4=y
CONFIG_NET_CONFIG_NEED_IPV4=y
CONFIG_NET_IPV6=n
CONFIG_NET_DHCPV4=y
CONFIG_SHELL=y
CONFIG_LOG=y
CONFIG_WIFI=y
CONFIG_NET_L2_WIFI_MGMT=y
CONFIG_NETWORKING=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POSIX_NAMES=y
CONFIG_DNS_RESOLVER=y

CONFIG_NET_TX_STACK_SIZE=2048
CONFIG_NET_RX_STACK_SIZE=2048
CONFIG_NET_PKT_RX_COUNT=10
CONFIG_NET_PKT_TX_COUNT=10
CONFIG_NET_BUF_RX_COUNT=20
CONFIG_NET_BUF_TX_COUNT=20
CONFIG_NET_MAX_CONTEXTS=10
100 changes: 100 additions & 0 deletions apps/int32_wifi_publisher/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#include <zephyr.h>
#include <device.h>
#include <stdio.h>
#include <sys/util.h>
#include <string.h>
#include <sys/printk.h>

#include <net/net_if.h>
#include <net/wifi_mgmt.h>
#include <net/net_event.h>

#include <rcl/rcl.h>
#include <rcl_action/rcl_action.h>
#include <rcl/error_handling.h>
#include <std_msgs/msg/int32.h>
#include <std_msgs/msg/bool.h>

#define RCCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){printk("Failed status on line %d: %d. Aborting.\n",__LINE__,(int)temp_rc);}}
#define RCSOFTCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){printk("Failed status on line %d: %d. Continuing.\n",__LINE__,(int)temp_rc);}}

static struct net_mgmt_event_callback wifi_shell_mgmt_cb;
static bool connected = 0;

static void wifi_mgmt_event_handler(struct net_mgmt_event_callback *cb,
u32_t mgmt_event, struct net_if *iface)
{
if(NET_EVENT_IPV4_ADDR_ADD == mgmt_event){
printf("DHCP Connected\n");
connected = 1;
}
}

void main(void)
{
// Wifi Configuration
net_mgmt_init_event_callback(&wifi_shell_mgmt_cb,
wifi_mgmt_event_handler,
NET_EVENT_IPV4_ADDR_ADD);

net_mgmt_add_event_callback(&wifi_shell_mgmt_cb);

struct net_if *iface = net_if_get_default();
static struct wifi_connect_req_params cnx_params;


cnx_params.ssid = "WIFI_SSID_HERE";
cnx_params.ssid_length = strlen(cnx_params.ssid);
cnx_params.channel = 0;
cnx_params.psk = "WIFI_PSK_HERE";
cnx_params.psk_length = strlen(cnx_params.psk);
cnx_params.security = WIFI_SECURITY_TYPE_PSK;

if (net_mgmt(NET_REQUEST_WIFI_CONNECT, iface, &cnx_params, sizeof(struct wifi_connect_req_params))) {
printf("Connection request failed\n");
} else {
printf("Connection requested\n");
}

while (!connected)
{
printf("Waiting for connection\n");
usleep(10000);
}
printf("Connection OK\n");

// micro-ROS
rcl_init_options_t options = rcl_get_zero_initialized_init_options();

RCCHECK(rcl_init_options_init(&options, rcl_get_default_allocator()))

// Optional RMW configuration
rmw_init_options_t* rmw_options = rcl_init_options_get_rmw_init_options(&options);
RCCHECK(rmw_uros_options_set_client_key(0xDEADBEEF, rmw_options))

rcl_context_t context = rcl_get_zero_initialized_context();
RCCHECK(rcl_init(0, NULL, &options, &context))

rcl_node_options_t node_ops = rcl_node_get_default_options();

rcl_node_t node = rcl_get_zero_initialized_node();
RCCHECK(rcl_node_init(&node, "zephyr_int32_wifi_publisher", "", &context, &node_ops))

rcl_publisher_options_t publisher_ops = rcl_publisher_get_default_options();
publisher_ops.qos.reliability = RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT;
rcl_publisher_t publisher = rcl_get_zero_initialized_publisher();
RCCHECK(rcl_publisher_init(&publisher, &node, ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Int32), "zephyr_int32_publisher", &publisher_ops))

std_msgs__msg__Int32 msg;
msg.data = 0;

rcl_ret_t rc;
do {
rc = rcl_publish(&publisher, (const void*)&msg, NULL);
msg.data++;
// usleep(10000);
} while (true);

RCCHECK(rcl_publisher_fini(&publisher, &node))
RCCHECK(rcl_node_fini(&node))
}
2 changes: 1 addition & 1 deletion microros_extensions/arm_toolchain.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set(CMAKE_SYSTEM_NAME Generic)
# set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_CROSSCOMPILING 1)
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
# set(PLATFORM_NAME "Zephyr")
set(PLATFORM_NAME "nuttx")

set(CMAKE_SYSROOT @CMAKE_SYSROOT@)

Expand Down