From 0b4018bb3c32107cb378a37a81b7699bf70312e6 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 19 Jul 2022 15:08:07 +0200 Subject: [PATCH 1/6] test including portentaEthernet.h --- platform_code/arduino/native_ethernet/micro_ros_transport.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform_code/arduino/native_ethernet/micro_ros_transport.h b/platform_code/arduino/native_ethernet/micro_ros_transport.h index 61a6a44a..28ba26ac 100644 --- a/platform_code/arduino/native_ethernet/micro_ros_transport.h +++ b/platform_code/arduino/native_ethernet/micro_ros_transport.h @@ -1,4 +1,4 @@ -#include +#include struct micro_ros_agent_locator { IPAddress address; From 4fd785bcaa9caeedbbbfaf258196b7976755bf71 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 19 Jul 2022 15:29:03 +0200 Subject: [PATCH 2/6] test including EthernetUdp.h --- platform_code/arduino/native_ethernet/micro_ros_transport.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform_code/arduino/native_ethernet/micro_ros_transport.h b/platform_code/arduino/native_ethernet/micro_ros_transport.h index 28ba26ac..b69c9402 100644 --- a/platform_code/arduino/native_ethernet/micro_ros_transport.h +++ b/platform_code/arduino/native_ethernet/micro_ros_transport.h @@ -1,4 +1,4 @@ -#include +#include struct micro_ros_agent_locator { IPAddress address; From 6be7aba11777ed47707a27ceb5767f5143a31a4e Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 19 Jul 2022 15:54:06 +0200 Subject: [PATCH 3/6] test including c --- platform_code/arduino/native_ethernet/micro_ros_transport.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform_code/arduino/native_ethernet/micro_ros_transport.cpp b/platform_code/arduino/native_ethernet/micro_ros_transport.cpp index 2df728cc..fab2ef85 100644 --- a/platform_code/arduino/native_ethernet/micro_ros_transport.cpp +++ b/platform_code/arduino/native_ethernet/micro_ros_transport.cpp @@ -2,7 +2,7 @@ #include -#include +#include #include #include From de7fc3bbe07c8e74481a5bf59f2f51b589409006 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 5 Aug 2022 11:21:36 +0200 Subject: [PATCH 4/6] adds example for ethernet on portenta, expands native_ethernet code --- .../platformio.ini | 7 ++ .../micro-ros_publisher_ethernet/src/Main.cpp | 66 +++++++++++++++++++ .../native_ethernet/micro_ros_transport.cpp | 6 +- .../native_ethernet/micro_ros_transport.h | 6 +- 4 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 examples/micro-ros_publisher_ethernet/platformio.ini create mode 100644 examples/micro-ros_publisher_ethernet/src/Main.cpp diff --git a/examples/micro-ros_publisher_ethernet/platformio.ini b/examples/micro-ros_publisher_ethernet/platformio.ini new file mode 100644 index 00000000..a07a6b16 --- /dev/null +++ b/examples/micro-ros_publisher_ethernet/platformio.ini @@ -0,0 +1,7 @@ +; [env:portenta_h7_m7] +; platform = ststm32 +; board = portenta_h7_m7 +framework = arduino +board_microros_transport = native_ethernet +lib_deps = + https://github.com/micro-ROS/micro_ros_platformio \ No newline at end of file diff --git a/examples/micro-ros_publisher_ethernet/src/Main.cpp b/examples/micro-ros_publisher_ethernet/src/Main.cpp new file mode 100644 index 00000000..a7f585ec --- /dev/null +++ b/examples/micro-ros_publisher_ethernet/src/Main.cpp @@ -0,0 +1,66 @@ +#include + +#include +#include +#include +#include +#include +#include + +#if !defined(TARGET_PORTENTA_H7_M7) +#error This example is only available for Arduino Portenta +#endif + +rcl_publisher_t publisher; +std_msgs__msg__Int32 msg; +rclc_support_t support; +rcl_allocator_t allocator; +rcl_node_t node; + +#define LED_PIN LEDR + +#define RCCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){error_loop();}} +#define RCSOFTCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){}} + +void error_loop(){ + while(1){ + digitalWrite(LED_PIN, !digitalRead(LED_PIN)); + delay(100); + } +} + +void setup() { + byte arduino_mac[] = { 0xAA, 0xBB, 0xCC, 0xEE, 0xDD, 0xFF }; + + IPAddress arduino_ip(192, 168, 1, 177); + IPAddress agent_ip(192, 168, 1, 113); + set_microros_native_ethernet_transports(arduino_mac, arduino_ip, agent_ip, 9999); + + pinMode(LED_PIN, OUTPUT); + digitalWrite(LED_PIN, HIGH); + + delay(2000); + + allocator = rcl_get_default_allocator(); + + //create init_options + RCCHECK(rclc_support_init(&support, 0, NULL, &allocator)); + + // create node + RCCHECK(rclc_node_init_default(&node, "micro_ros_arduino_ethernet_node", "namespace", &support)); + + // create publisher + RCCHECK(rclc_publisher_init_best_effort( + &publisher, + &node, + ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Int32), + "topic_name")); + + msg.data = 0; +} + +void loop() { + RCSOFTCHECK(rcl_publish(&publisher, &msg, NULL)); + msg.data++; + delay(100); +} \ No newline at end of file diff --git a/platform_code/arduino/native_ethernet/micro_ros_transport.cpp b/platform_code/arduino/native_ethernet/micro_ros_transport.cpp index fab2ef85..699bf24b 100644 --- a/platform_code/arduino/native_ethernet/micro_ros_transport.cpp +++ b/platform_code/arduino/native_ethernet/micro_ros_transport.cpp @@ -2,7 +2,11 @@ #include -#include +#if defined(ARDUINO_PORTENTA_H7_M7) + #include +#else + #include +#endif #include #include diff --git a/platform_code/arduino/native_ethernet/micro_ros_transport.h b/platform_code/arduino/native_ethernet/micro_ros_transport.h index b69c9402..8753387a 100644 --- a/platform_code/arduino/native_ethernet/micro_ros_transport.h +++ b/platform_code/arduino/native_ethernet/micro_ros_transport.h @@ -1,4 +1,8 @@ -#include +#if defined(ARDUINO_PORTENTA_H7_M7) + #include +#else + #include +#endif struct micro_ros_agent_locator { IPAddress address; From de8ec49c8230fe98678979d31a38c08d2c81423c Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 5 Aug 2022 11:34:36 +0200 Subject: [PATCH 5/6] adds source to example --- examples/micro-ros_publisher_ethernet/src/Main.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/micro-ros_publisher_ethernet/src/Main.cpp b/examples/micro-ros_publisher_ethernet/src/Main.cpp index a7f585ec..ca98dca0 100644 --- a/examples/micro-ros_publisher_ethernet/src/Main.cpp +++ b/examples/micro-ros_publisher_ethernet/src/Main.cpp @@ -1,3 +1,5 @@ +// based on https://github.com/micro-ROS/micro_ros_arduino/blob/humble/examples/micro-ros_publisher_ethernet/micro-ros_publisher_ethernet.ino + #include #include @@ -32,8 +34,8 @@ void error_loop(){ void setup() { byte arduino_mac[] = { 0xAA, 0xBB, 0xCC, 0xEE, 0xDD, 0xFF }; - IPAddress arduino_ip(192, 168, 1, 177); - IPAddress agent_ip(192, 168, 1, 113); + IPAddress arduino_ip(10, 100, 0, 177); + IPAddress agent_ip(10, 100, 0, 111); set_microros_native_ethernet_transports(arduino_mac, arduino_ip, agent_ip, 9999); pinMode(LED_PIN, OUTPUT); From 80d5fc698e0987ee07c39e26959b8eddad6b73c6 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 5 Aug 2022 11:37:50 +0200 Subject: [PATCH 6/6] adds newline to end of files --- examples/micro-ros_publisher_ethernet/platformio.ini | 2 +- examples/micro-ros_publisher_ethernet/src/Main.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/micro-ros_publisher_ethernet/platformio.ini b/examples/micro-ros_publisher_ethernet/platformio.ini index a07a6b16..c39632ca 100644 --- a/examples/micro-ros_publisher_ethernet/platformio.ini +++ b/examples/micro-ros_publisher_ethernet/platformio.ini @@ -4,4 +4,4 @@ framework = arduino board_microros_transport = native_ethernet lib_deps = - https://github.com/micro-ROS/micro_ros_platformio \ No newline at end of file + https://github.com/micro-ROS/micro_ros_platformio diff --git a/examples/micro-ros_publisher_ethernet/src/Main.cpp b/examples/micro-ros_publisher_ethernet/src/Main.cpp index ca98dca0..47921eb9 100644 --- a/examples/micro-ros_publisher_ethernet/src/Main.cpp +++ b/examples/micro-ros_publisher_ethernet/src/Main.cpp @@ -65,4 +65,4 @@ void loop() { RCSOFTCHECK(rcl_publish(&publisher, &msg, NULL)); msg.data++; delay(100); -} \ No newline at end of file +}