micro-ROS / zephyr_apps

Sample applications for Zephyr + micro-ROS
Apache License 2.0
19 stars 13 forks source link

int32_wifi_publisher on ST Disco L475 IOT01 (Zephyr) #31

Closed Eric7797 closed 3 years ago

Eric7797 commented 3 years ago

Hello,

i try to get my first micro-ROS application running with wifi. I want to use the example application "int32_wifi_publisher".

I have following setup: PC: Ubuntu 20.04.1 LTS (running ROS2) Micro-ROS board: ST Disco L475 IOT01 (running Zephyr)

I configure the micro-ROS application with following parameter: ros2 run micro_ros_setup configure_firmware.sh int32_wifi_publisher --transport udp --ip 192.168.178.20 --port 8888

Insert my Wifi and PSK:

cnx_params.ssid = "<myWIFI>";
cnx_params.ssid_length = strlen(cnx_params.ssid);
cnx_params.channel = 0;
cnx_params.psk = "<myPSK>";
cnx_params.psk_length = strlen(cnx_params.psk);
cnx_params.security = WIFI_SECURITY_TYPE_PSK;

build it: ros2 run micro_ros_setup build_firmware.sh

and flash it on the board: ros2 run micro_ros_setup flash_firmware.sh

But after starting the agent via: ros2 run micro_ros_agent micro_ros_agent udp4 --port 8888 the agent stock in the init state and get never a connection to the Micro-ROS.

Note: I can see the board in my Wifi overview of my router.

Is there anything more to do to get it running?

Thanks!

pablogs9 commented 3 years ago

I'll check the behavior of this app.

pablogs9 commented 3 years ago

One quick question: is 192.168.178.20 the IP of the computer where the agent is being ran?

Eric7797 commented 3 years ago

@pablogs9 Yes, this is the IP of my PC where ROS2 is running.

pablogs9 commented 3 years ago

I have been testing the app and it seems that once it connects to wifi it starts to print trash in the serial port... Do you have this same behavior in the UART attached to the STLink?

I also have tested the same application with serial-usb transports and it works smoothly... I'm wondering if there is any kind of error in the networking handling of micro-ROS for Zephyr, I'll take a look when I have some time.

Hiskias commented 3 years ago

Greetings,

I'm working together with @Eric7797 on the same project. @pablogs9 I had the same Problem that after the boards connects to wifi, it prints a lot of trash to the serial port. Through debugging the main.c I figured out that the Application crashes in the rclc_support_init function. Stepping through this function leads me to the Micro-XRCE-DDS-Client function uxr_init_udp_platform in the udp_transport_posix.c file. https://github.com/eProsima/Micro-XRCE-DDS-Client/blob/master/src/c/profile/transport/ip/udp/udp_transport_posix.c.

In the switch/case statement the funciton socket gets called with the third parameter set to zero. This leads to an error. I changed the 0 into 17, which equals to the enum-value IPPROTO_UDP in net_ip.h (line 66) https://github.com/zephyrproject-rtos/zephyr/blob/master/include/net/net_ip.h I did this because of a check on this third parameter in the __eswifi_socket_new function where a value of 0 would lead to an error (line 281ff.) https://github.com/zephyrproject-rtos/zephyr/blob/master/drivers/wifi/eswifi/eswifi_socket.c

After this change, the connection to the agent worked fine, but (sadly) the rcl_publish function didn't publish anything (in timer_callback).

This is a dirty fix and I don't know if this is the right way to do it, so further help is appreciated :)

pablogs9 commented 3 years ago

Hello, @Hiskias super cool that you found this! I guess that Zephyr does not have the same BSD Sockets as plain POSIX Linux... micro-ROS can be configured with external transports so maybe we can write a network transport for Zephyr.

Let me check this I will come back in a while.

Just by curiosity, how are you debugging the ST Disco?

pablogs9 commented 3 years ago

Using your fix it is not publishing because this line should be:

ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Int32),

I'm preparing a PR to the zephyr apps repo fixing this wifi application.

Thanks a lot for the help and the feedback!

pablogs9 commented 3 years ago

I have updated our repos to fix this, please check:

I have tested this in a clean environment and I'm able to publish Int32 over Wi-Fi in the ST Disco. Please close if resolved or provide feedback if not.

Hiskias commented 3 years ago

Hello again,

lot of thanks for your support :) How can we update our current uROS environment? Or should we use a new one?

We followed the Eclipse Debugging for zephyr documentation. For creating the eclipse project file, we edited the uROS build script for zephyr located in /home/\<username>/microros_ws/install/micro_ros_setup/config/zephyr/generic in our environment. We changed line 80 from -G'Unix Makefiles' to -G'Eclipse CDT4 - Unix Makefiles'. This will generate a .project file for eclipse in /home/\<username>/microros_ws/firmware/build folder when using the uROS Toolchain (running ros2 run micro_ros_setup build_firmware.sh). After this we imported the project in Eclipse and configured a debugger (pyOCD) as described in the zephyr documentation. There are a few problems sometimes, but it's good enough for debugging our first applications. Sadly, there is no description (or we didn't found any) how to implement a uROS project into an IDE, so we went this way.

pablogs9 commented 3 years ago

I think that the best way to update is to use a new uROS environment.

I'm closing since resolved. Do not hesitate in reopening if there is any other problem.

BTW, we are also looking to hear about user projects related to micro-ROS. Could you tell us something about your use case?