Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding ethernet to portenta, using the example in micro_ros_arduino #49

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
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
7 changes: 7 additions & 0 deletions examples/micro-ros_publisher_ethernet/platformio.ini
Original file line number Diff line number Diff line change
@@ -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
68 changes: 68 additions & 0 deletions examples/micro-ros_publisher_ethernet/src/Main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// based on https://github.com/micro-ROS/micro_ros_arduino/blob/humble/examples/micro-ros_publisher_ethernet/micro-ros_publisher_ethernet.ino

#include <micro_ros_arduino.h>

#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>

#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(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);
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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

#include <micro_ros_platformio.h>

#include <NativeEthernetUdp.h>
#if defined(ARDUINO_PORTENTA_H7_M7)
#include <EthernetUdp.h>
#else
#include <NativeEthernetUdp.h>
#endif

#include <uxr/client/util/time.h>
#include <uxr/client/profile/transport/custom/custom_transport.h>
Expand Down
6 changes: 5 additions & 1 deletion platform_code/arduino/native_ethernet/micro_ros_transport.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#include <NativeEthernet.h>
#if defined(ARDUINO_PORTENTA_H7_M7)
#include <EthernetUdp.h>
#else
#include <NativeEthernet.h>
#endif

struct micro_ros_agent_locator {
IPAddress address;
Expand Down