@@ -18,31 +18,37 @@ rcl_timer_t timer;
18
18
19
19
#define LED_PIN 13
20
20
21
- #define RCCHECK (fn ) { rcl_ret_t temp_rc = fn; if ((temp_rc != RCL_RET_OK)){error_loop ();}}
22
- #define RCSOFTCHECK (fn ) { rcl_ret_t temp_rc = fn; if ((temp_rc != RCL_RET_OK)){error_loop ();}}
23
-
21
+ #define RCCHECK (fn ) \
22
+ { \
23
+ rcl_ret_t temp_rc = fn; \
24
+ if ((temp_rc != RCL_RET_OK)) \
25
+ { \
26
+ error_loop (); \
27
+ } \
28
+ }
29
+ #define RCSOFTCHECK (fn ) \
30
+ { \
31
+ rcl_ret_t temp_rc = fn; \
32
+ if ((temp_rc != RCL_RET_OK)) \
33
+ { \
34
+ error_loop (); \
35
+ } \
36
+ }
24
37
25
- void error_loop (){
26
- while (1 ){
38
+ void error_loop ()
39
+ {
40
+ while (1 )
41
+ {
27
42
digitalWrite (LED_PIN, !digitalRead (LED_PIN));
28
43
delay (100 );
29
44
}
30
45
}
31
46
32
- void timer_callback (rcl_timer_t * timer, int64_t last_call_time)
33
- {
34
- RCLC_UNUSED (last_call_time);
35
- if (timer != NULL ) {
36
- RCSOFTCHECK (rcl_publish (&publisher, &msg, NULL ));
37
- msg.data ++;
38
- }
39
- }
40
-
41
- void setup () {
42
-
47
+ void setup ()
48
+ {
43
49
pinMode (LED_PIN, OUTPUT);
44
- digitalWrite (LED_PIN, HIGH);
45
-
50
+ digitalWrite (LED_PIN, HIGH);
51
+
46
52
delay (2000 );
47
53
48
54
allocator = rcl_get_default_allocator ();
@@ -56,32 +62,16 @@ void setup() {
56
62
57
63
// create publisher
58
64
RCCHECK (rclc_publisher_init_default (
59
- &publisher,
60
- &node,
61
- ROSIDL_GET_MSG_TYPE_SUPPORT (std_msgs, msg, Int32),
62
- " micro_ros_arduino_node_publisher" ));
63
-
64
- // create timer,
65
- timer = rcl_get_zero_initialized_timer ();
66
- const unsigned int timer_timeout = 1000 ;
67
- RCCHECK (rclc_timer_init_default (
68
- &timer,
69
- &support,
70
- RCL_MS_TO_NS (timer_timeout),
71
- timer_callback));
72
-
73
- // create executor
74
- executor = rclc_executor_get_zero_initialized_executor ();
75
- RCCHECK (rclc_executor_init (&executor, &support.context , 1 , &allocator));
76
-
77
- unsigned int rcl_wait_timeout = 100 ; // in ms
78
- RCCHECK (rclc_executor_set_timeout (&executor, RCL_MS_TO_NS (rcl_wait_timeout)));
79
- RCCHECK (rclc_executor_add_timer (&executor, &timer));
80
-
65
+ &publisher,
66
+ &node,
67
+ ROSIDL_GET_MSG_TYPE_SUPPORT (std_msgs, msg, Int32),
68
+ " micro_ros_arduino_node_publisher" ));
81
69
msg.data = 0 ;
82
70
}
83
71
84
- void loop () {
72
+ void loop ()
73
+ {
85
74
delay (100 );
86
- RCCHECK (rclc_executor_spin_some (&executor, RCL_MS_TO_NS (100 )));
75
+ RCSOFTCHECK (rcl_publish (&publisher, &msg, NULL ));
76
+ msg.data ++;
87
77
}
0 commit comments