micro-ROS / micro_ros_raspberrypi_pico_sdk

Raspberry Pi Pico (RP2040) and micro-ROS integration
Apache License 2.0
183 stars 56 forks source link

Trying to connect with udp4 (rmw_uros_discover_agent missing ?) #827

Open DaFray31 opened 1 year ago

DaFray31 commented 1 year ago

Hello,

I am trying to connect my pi pico w, with the docker agent in udp4 (using micro-ros + pico sdk).

Unfortunately using : rmw_uros_options_set_udp_address(), it fails to reach the agent (I run the container from wsl 2)

So I try to use the rmw_uros_discover_agent() function as in the example here

Unfortunately this function does not exist. Is this normal?

Thanks in advance

Here are my different codes: Docker agent : docker run -it --rm -v /dev:/dev --privileged --net=host microros/micro-ros-agent:humble udp4 -p 9999 -d

file.cpp with trying to use rmw_uros_discover_agent()

#include <stdio.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 <rmw_microros/rmw_microros.h>

#include "pico/stdlib.h"
#include "pico_uart_transports.h"
#include "pico/cyw43_arch.h"
[...]
    rcl_init_options_t init_options = rcl_get_zero_initialized_init_options();
    rmw_init_options_t* rmw_options = rcl_init_options_get_rmw_init_options(&init_options);
    if(rmw_uros_discover_agent(rmw_options) != RCL_RET_OK){
    printf("micro-ROS agent not found\n");
    return 1;
}
    printf("Agent found");

CMakeLists.txt :

cmake_minimum_required(VERSION 3.12)

include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake)

project(pico_micro_ros_example C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(PICO_BOARD "pico_w")

pico_sdk_init()

link_directories(libmicroros)
add_executable(pico_micro_ros_example
    pico_micro_ros_example.c
    pico_uart_transport.c
)
target_link_libraries(pico_micro_ros_example
    pico_stdlib
    microros
    pico_cyw43_arch_lwip_poll

    )

target_include_directories(pico_micro_ros_example PUBLIC
    libmicroros/include
)

SET(CMAKE_C_FLAGS  "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections")
SET(CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} -ffunction-sections -fdata-sections")

# Configure Pico
pico_enable_stdio_usb(pico_micro_ros_example 1)
pico_enable_stdio_uart(pico_micro_ros_example 0)
add_compile_definitions(PICO_UART_ENABLE_CRLF_SUPPORT=0)
add_compile_definitions(PICO_STDIO_ENABLE_CRLF_SUPPORT=0)
add_compile_definitions(PICO_STDIO_DEFAULT_CRLF=0)

# Generate UF2
pico_add_extra_outputs(pico_micro_ros_example)

file.cpp trying to use rmw_uros_options_set_udp_address() :

[...]
    rcl_init_options_t init_options = rcl_get_zero_initialized_init_options();
    rmw_init_options_t* rmw_options = rcl_init_options_get_rmw_init_options(&init_options);
    if(rmw_uros_options_set_udp_address("172.16.180.236","9999", rmw_options) != RMW_RET_OK){
        printf("micro-ROS agent not found\n");
        cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 1);
        sleep_ms(1000);
        cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 0);
        sleep_ms(1000);
        cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 1);
        sleep_ms(1000);
        cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 0);
        return 1;
    }
    printf("Agent found");
jkaniuka commented 9 months ago

Hi @DaFray31, if you want to wirelessly connect with RPi Pico W using micro-ROS, check out these repos. I hope it will help :wink: