Skip to content

Commit 48e2e7b

Browse files
committed
Update index.md
1 parent 113ad60 commit 48e2e7b

1 file changed

Lines changed: 20 additions & 27 deletions

File tree

  • _docs/tutorials/core/programming_rcl_rclc

_docs/tutorials/core/programming_rcl_rclc/index.md

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -36,50 +36,43 @@ if (rc != RCL_RET_OK) {
3636
```
3737

3838
## <a name="pub_sub"/>Publishers and Subscriptions
39-
Publisher and subscribers are created with the rclc-package with the following functions
40-
`rclc_publisher_init_default(..)` and `rclc_subscription_init_default(..)` in [rclc/publisher.h](https://github.com/micro-ROS/rclc/blob/master/rclc/include/rclc/publisher.h) and [rclc/node.h](https://github.com/micro-ROS/rclc/blob/master/rclc/include/rclc/subscription.h), respectively:
4139

40+
Publisher and subscribers are created with the rclc-package.
41+
42+
Creating a publisher by `rclc_publisher_init_default(..)` from [rclc/publisher.h](https://github.com/micro-ROS/rclc/blob/master/rclc/include/rclc/publisher.h):
4243

4344
```c
44-
// create publisher
4545
rcl_publisher_t my_pub;
46-
std_msgs__msg__String pub_msg;
47-
const char * topic_name = "topic_0";
48-
const rosidl_message_type_support_t * my_type_support =
49-
ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, String);
50-
51-
rc = rclc_publisher_init_default(
52-
&my_pub,
53-
&my_node,
54-
my_type_support,
55-
topic_name);
46+
std_msgs__msg__String my_msg;
47+
const char * my_topic = "topic_0";
48+
const rosidl_message_type_support_t * my_type_support = ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, String);
49+
50+
rc = rclc_publisher_init_default(&my_pub, &my_node, &my_type_support, &my_topic_name);
5651
if (RCL_RET_OK != rc) {
57-
printf("Error in rclc_publisher_init_default %s.\n", topic_name);
52+
printf("Error in rclc_publisher_init_default.\n");
5853
return -1;
5954
}
60-
// create publisher message
55+
```
56+
57+
Publishing a message:
58+
59+
```c
6160
std_msgs__msg__String__init(&pub_msg);
6261
const unsigned int PUB_MSG_SIZE = 20;
6362
char pub_string[PUB_MSG_SIZE];
6463
snprintf(pub_string, 13, "%s", "Hello World!");
6564
rosidl_generator_c__String__assignn(&pub_msg, pub_string, PUB_MSG_SIZE);
65+
```
66+
67+
Creating a subscription by `rclc_subscription_init_default(..)` from [rclc/subscription.h](https://github.com/micro-ROS/rclc/blob/master/rclc/include/rclc/subscription.h), respectively:
6668
67-
// create subscription
69+
```c
6870
rcl_subscription_t my_sub = rcl_get_zero_initialized_subscription();
69-
rc = rclc_subscription_init_default(
70-
&my_sub,
71-
&my_node,
72-
my_type_support,
73-
topic_name);
71+
rc = rclc_subscription_init_default(&my_sub, &my_node, &my_type_support, &my_topic_name);
7472
if (rc != RCL_RET_OK) {
75-
printf("Failed to create subscriber %s.\n", topic_name);
73+
printf("Failed to create subscriber.\n");
7674
return -1;
77-
} else {
78-
printf("Created subscriber %s:\n", topic_name);
7975
}
80-
81-
// initialize string message for subscriber
82-
std_msgs__msg__String__init(&sub_msg);
8376
```
8477

8578
## <a name="services"/>Services

0 commit comments

Comments
 (0)