Skip to content

Commit 12a0fe7

Browse files
Jenifenpablogs9
authored and
mergify-bot
committed
portenta h7 m7 ethernet support (#852)
* add ethernet trasport for PORTENTA_H7_M7 in uros header * add ethernet trasport for PORTENTA_H7_M7 cpp * add ethernet publish example * correct error msg add * add comment ip * change topic_name, namespace * update mac address Co-authored-by: Pablo Garrido <[email protected]> * remove comment Co-authored-by: Pablo Garrido <[email protected]> * remove not used headers * fix error condition Co-authored-by: Pablo Garrido <[email protected]> (cherry picked from commit b12ed9b)
1 parent 26a3931 commit 12a0fe7

File tree

3 files changed

+89
-3
lines changed

3 files changed

+89
-3
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#include <micro_ros_arduino.h>
2+
3+
#include <stdio.h>
4+
#include <rcl/rcl.h>
5+
#include <rcl/error_handling.h>
6+
#include <rclc/rclc.h>
7+
#include <rclc/executor.h>
8+
#include <std_msgs/msg/int32.h>
9+
10+
#if !defined(TARGET_STM32F4) && !defined(ARDUINO_TEENSY41) && !defined(TARGET_PORTENTA_H7_M7)
11+
#error This example is only avaible for Arduino Portenta, Arduino Teensy41 and STM32F4
12+
#endif
13+
14+
rcl_publisher_t publisher;
15+
std_msgs__msg__Int32 msg;
16+
rclc_support_t support;
17+
rcl_allocator_t allocator;
18+
rcl_node_t node;
19+
20+
#define LED_PIN 13
21+
22+
#define RCCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){error_loop();}}
23+
#define RCSOFTCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){}}
24+
25+
26+
27+
void error_loop(){
28+
while(1){
29+
digitalWrite(LED_PIN, !digitalRead(LED_PIN));
30+
delay(100);
31+
}
32+
}
33+
34+
void timer_callback(rcl_timer_t * timer, int64_t last_call_time)
35+
{
36+
RCLC_UNUSED(last_call_time);
37+
if (timer != NULL) {
38+
RCSOFTCHECK(rcl_publish(&publisher, &msg, NULL));
39+
msg.data++;
40+
}
41+
}
42+
43+
void setup() {
44+
byte arduino_mac[] = { 0xAA, 0xBB, 0xCC, 0xEE, 0xDD, 0xFF };
45+
IPAddress arduino_ip(192, 168, 1, 177);
46+
IPAddress agent_ip(192, 168, 1, 113);
47+
set_microros_native_ethernet_udp_transports(arduino_mac, arduino_ip, agent_ip, 9999);
48+
49+
pinMode(LED_PIN, OUTPUT);
50+
digitalWrite(LED_PIN, HIGH);
51+
52+
delay(2000);
53+
54+
allocator = rcl_get_default_allocator();
55+
56+
//create init_options
57+
RCCHECK(rclc_support_init(&support, 0, NULL, &allocator));
58+
59+
// create node
60+
RCCHECK(rclc_node_init_default(&node, "micro_ros_arduino_ethernet_node", "namespace", &support));
61+
62+
// create publisher
63+
RCCHECK(rclc_publisher_init_best_effort(
64+
&publisher,
65+
&node,
66+
ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Int32),
67+
"topic_name"));
68+
69+
msg.data = 0;
70+
}
71+
72+
void loop() {
73+
RCSOFTCHECK(rcl_publish(&publisher, &msg, NULL));
74+
msg.data++;
75+
delay(100);
76+
}

src/micro_ros_arduino.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ static inline void set_microros_transports(){
4848
#include <NativeEthernet.h>
4949
#endif
5050

51-
#if defined(TARGET_STM32F4) || defined(ARDUINO_TEENSY41)
51+
#if defined(TARGET_PORTENTA_H7_M7)
52+
#include <PortentaEthernet.h>
53+
#endif
54+
55+
#if defined(TARGET_STM32F4) || defined(ARDUINO_TEENSY41) || defined(TARGET_PORTENTA_H7_M7)
5256
extern "C" bool arduino_native_ethernet_udp_transport_open(struct uxrCustomTransport * transport);
5357
extern "C" bool arduino_native_ethernet_udp_transport_close(struct uxrCustomTransport * transport);
5458
extern "C" size_t arduino_native_ethernet_udp_transport_write(struct uxrCustomTransport* transport, const uint8_t * buf, size_t len, uint8_t * err);
@@ -95,11 +99,12 @@ extern "C" bool arduino_wifi_transport_open(struct uxrCustomTransport * transpor
9599
extern "C" bool arduino_wifi_transport_close(struct uxrCustomTransport * transport);
96100
extern "C" size_t arduino_wifi_transport_write(struct uxrCustomTransport* transport, const uint8_t * buf, size_t len, uint8_t * err);
97101
extern "C" size_t arduino_wifi_transport_read(struct uxrCustomTransport* transport, uint8_t* buf, size_t len, int timeout, uint8_t* err);
98-
102+
#ifndef TARGET_PORTENTA_H7_M7
99103
struct micro_ros_agent_locator {
100104
IPAddress address;
101105
int port;
102106
};
107+
#endif
103108

104109
static inline void set_microros_wifi_transports(char * ssid, char * pass, char * agent_ip, uint agent_port){
105110

src/native_ethernet_transport.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@
1010
#include <NativeEthernet.h>
1111
#include <micro_ros_arduino.h>
1212
#endif
13+
#ifdef TARGET_PORTENTA_H7_M7
14+
#include <Arduino.h>
15+
#include <EthernetUdp.h>
16+
#include <micro_ros_arduino.h>
17+
#endif
1318

14-
#if defined(TARGET_STM32F4) || defined(ARDUINO_TEENSY41)
19+
#if defined(TARGET_STM32F4) || defined(ARDUINO_TEENSY41) || defined(TARGET_PORTENTA_H7_M7)
1520
extern "C" {
1621

1722
#include <stdbool.h>

0 commit comments

Comments
 (0)