Skip to content

Commit e4a5bc6

Browse files
committed
Rename to ROS2_Braccio_Driver.
1 parent 14d31bf commit e4a5bc6

File tree

2 files changed

+57
-25
lines changed

2 files changed

+57
-25
lines changed

examples/micro-ros_publisher/README.md renamed to examples/ROS2_Braccio_Driver/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
:floppydisk: `ROS2_Braccio_Driver`
2+
==================================
3+
4+
15
### Install
26
#### ROS2 Galactic
37
https://docs.ros.org/en/galactic/Installation/Ubuntu-Install-Debians.html
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/**
2+
* ROS driver for controlling the Arduino Braccio++ with ROS2.
3+
*/
4+
5+
/**************************************************************************************
6+
* INCLUDE
7+
**************************************************************************************/
8+
19
#include <micro_ros_arduino.h>
210

311
#include <stdio.h>
@@ -8,6 +16,10 @@
816

917
#include <std_msgs/msg/int32.h>
1018

19+
/**************************************************************************************
20+
* GLOBAL VARIABLES
21+
**************************************************************************************/
22+
1123
rcl_publisher_t publisher;
1224
std_msgs__msg__Int32 msg;
1325
rclc_executor_t executor;
@@ -16,29 +28,21 @@ rcl_allocator_t allocator;
1628
rcl_node_t node;
1729
rcl_timer_t timer;
1830

31+
/**************************************************************************************
32+
* DEFINES
33+
**************************************************************************************/
34+
1935
#define LED_PIN 13
2036

2137
#define RCCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){error_loop();}}
2238
#define RCSOFTCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){}}
2339

40+
/**************************************************************************************
41+
* SETUP/LOOP
42+
**************************************************************************************/
2443

25-
void error_loop(){
26-
while(1){
27-
digitalWrite(LED_PIN, !digitalRead(LED_PIN));
28-
delay(100);
29-
}
30-
}
31-
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() {
44+
void setup()
45+
{
4246
set_microros_transports();
4347

4448
pinMode(LED_PIN, OUTPUT);
@@ -48,35 +52,59 @@ void setup() {
4852

4953
allocator = rcl_get_default_allocator();
5054

51-
//create init_options
55+
/* Create init_options. */
5256
RCCHECK(rclc_support_init(&support, 0, NULL, &allocator));
5357

54-
// create node
55-
RCCHECK(rclc_node_init_default(&node, "micro_ros_arduino_node", "", &support));
58+
/* Create node. */
59+
RCCHECK(rclc_node_init_default(&node, "braccio_plusplus_node", "", &support));
5660

57-
// create publisher
61+
/* Create JointState publisher. */
5862
RCCHECK(rclc_publisher_init_default(
5963
&publisher,
6064
&node,
6165
ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Int32),
62-
"micro_ros_arduino_node_publisher"));
66+
"braccio_plusplus_node_joint_state_publisher"));
6367

64-
// create timer,
68+
/* Create Timer. */
6569
const unsigned int timer_timeout = 1000;
6670
RCCHECK(rclc_timer_init_default(
6771
&timer,
6872
&support,
6973
RCL_MS_TO_NS(timer_timeout),
7074
timer_callback));
7175

72-
// create executor
76+
/* Create executor. */
7377
RCCHECK(rclc_executor_init(&executor, &support.context, 1, &allocator));
7478
RCCHECK(rclc_executor_add_timer(&executor, &timer));
7579

7680
msg.data = 0;
7781
}
7882

79-
void loop() {
83+
void loop()
84+
{
8085
delay(100);
8186
RCSOFTCHECK(rclc_executor_spin_some(&executor, RCL_MS_TO_NS(100)));
8287
}
88+
89+
/**************************************************************************************
90+
* FUNCTIONS
91+
**************************************************************************************/
92+
93+
void error_loop()
94+
{
95+
for (;;)
96+
{
97+
digitalWrite(LED_PIN, !digitalRead(LED_PIN));
98+
delay(100);
99+
}
100+
}
101+
102+
void timer_callback(rcl_timer_t * timer, int64_t last_call_time)
103+
{
104+
RCLC_UNUSED(last_call_time);
105+
if (timer != NULL)
106+
{
107+
RCSOFTCHECK(rcl_publish(&publisher, &msg, NULL));
108+
msg.data++;
109+
}
110+
}

0 commit comments

Comments
 (0)