Skip to content

Commit 4e8d023

Browse files
committed
Update demos after 'rcl' API changes (#99)
Signed-off-by: David Laseca Perez <davidlaseca@eprosima.com>
1 parent c1c3f49 commit 4e8d023

16 files changed

Lines changed: 86 additions & 53 deletions

File tree

rclc/autodiscover_agent/main.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
rcl_publisher_t publisher;
1717
std_msgs__msg__Int32 msg;
1818

19-
void timer_callback(rcl_timer_t * timer, int64_t last_call_time)
19+
void timer_callback(rcl_timer_t * timer, int64_t last_call_time, uintptr_t user_data)
2020
{
2121
(void) last_call_time;
22+
(void) user_data;
2223
if (timer != NULL) {
2324
RCSOFTCHECK(rcl_publish(&publisher, &msg, NULL));
2425
printf("Sent: %d\n", msg.data);
@@ -58,11 +59,12 @@ int main()
5859
// create timer,
5960
rcl_timer_t timer;
6061
const unsigned int timer_timeout = 1000;
61-
RCCHECK(rclc_timer_init_default(
62+
RCCHECK(rclc_timer_init_default2(
6263
&timer,
6364
&support,
6465
RCL_MS_TO_NS(timer_timeout),
65-
timer_callback));
66+
timer_callback,
67+
true));
6668

6769
// create executor
6870
rclc_executor_t executor = rclc_executor_get_zero_initialized_executor();

rclc/configuration_example/configured_publisher/main.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
rcl_publisher_t publisher;
1616
std_msgs__msg__Int32 msg;
1717

18-
void timer_callback(rcl_timer_t * timer, int64_t last_call_time)
18+
void timer_callback(rcl_timer_t * timer, int64_t last_call_time, uintptr_t user_data)
1919
{
2020
(void) last_call_time;
21+
(void) user_data;
2122
if (timer != NULL) {
2223
RCSOFTCHECK(rcl_publish(&publisher, &msg, NULL));
2324
printf("Sent: %d\n", msg.data);
@@ -66,11 +67,12 @@ int main(int argc, char * const argv[])
6667
// create timer,
6768
rcl_timer_t timer;
6869
const unsigned int timer_timeout = 1000;
69-
RCCHECK(rclc_timer_init_default(
70+
RCCHECK(rclc_timer_init_default2(
7071
&timer,
7172
&support,
7273
RCL_MS_TO_NS(timer_timeout),
73-
timer_callback));
74+
timer_callback,
75+
true));
7476

7577
// create executor
7678
rclc_executor_t executor = rclc_executor_get_zero_initialized_executor();

rclc/configuration_example/custom_transports/main.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,10 @@ size_t custom_transport_read(struct uxrCustomTransport* transport, uint8_t* buf,
113113
rcl_publisher_t publisher;
114114
std_msgs__msg__Int32 msg;
115115

116-
void timer_callback(rcl_timer_t * timer, int64_t last_call_time)
116+
void timer_callback(rcl_timer_t * timer, int64_t last_call_time, uintptr_t user_data)
117117
{
118118
(void) last_call_time;
119+
(void) user_data;
119120
if (timer != NULL) {
120121
RCSOFTCHECK(rcl_publish(&publisher, &msg, NULL));
121122
printf("Sent: %d\n", msg.data);
@@ -161,11 +162,12 @@ int main(int argc, char * const argv[])
161162
// create timer,
162163
rcl_timer_t timer;
163164
const unsigned int timer_timeout = 1000;
164-
RCCHECK(rclc_timer_init_default(
165+
RCCHECK(rclc_timer_init_default2(
165166
&timer,
166167
&support,
167168
RCL_MS_TO_NS(timer_timeout),
168-
timer_callback));
169+
timer_callback,
170+
true));
169171

170172
// create executor
171173
rclc_executor_t executor = rclc_executor_get_zero_initialized_executor();

rclc/epoch_synchronization/main.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
rcl_publisher_t publisher;
1616
std_msgs__msg__Int32 msg;
1717

18-
void timer_callback(rcl_timer_t * timer, int64_t last_call_time)
18+
void timer_callback(rcl_timer_t * timer, int64_t last_call_time, uintptr_t user_data)
1919
{
2020
(void) last_call_time;
2121
(void) timer;
22+
(void) user_data;
2223

2324
RCSOFTCHECK(rmw_uros_sync_session(1000));
2425
int64_t time = rmw_uros_epoch_millis();
@@ -50,11 +51,12 @@ int main()
5051
// create timer,
5152
rcl_timer_t timer;
5253
const unsigned int timer_timeout = 1000;
53-
RCCHECK(rclc_timer_init_default(
54+
RCCHECK(rclc_timer_init_default2(
5455
&timer,
5556
&support,
5657
RCL_MS_TO_NS(timer_timeout),
57-
timer_callback));
58+
timer_callback,
59+
true));
5860

5961
// create executor
6062
rclc_executor_t executor = rclc_executor_get_zero_initialized_executor();

rclc/fragmented_publication/main.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
rcl_publisher_t publisher;
1717
std_msgs__msg__String msg;
1818

19-
void timer_callback(rcl_timer_t * timer, int64_t last_call_time)
19+
void timer_callback(rcl_timer_t * timer, int64_t last_call_time, uintptr_t user_data)
2020
{
2121
(void) last_call_time;
22+
(void) user_data;
2223
if (timer != NULL) {
2324
RCSOFTCHECK(rcl_publish(&publisher, &msg, NULL));
2425
printf("I sent an %ld array\n", msg.data.size);
@@ -47,11 +48,12 @@ int main(int argc, const char * const * argv)
4748
// create timer,
4849
rcl_timer_t timer;
4950
const unsigned int timer_timeout = 1000;
50-
RCCHECK(rclc_timer_init_default(
51+
RCCHECK(rclc_timer_init_default2(
5152
&timer,
5253
&support,
5354
RCL_MS_TO_NS(timer_timeout),
54-
timer_callback));
55+
timer_callback,
56+
true));
5557

5658
// create executor
5759
rclc_executor_t executor = rclc_executor_get_zero_initialized_executor();
@@ -63,9 +65,9 @@ int main(int argc, const char * const * argv)
6365
msg.data.size = 0;
6466
msg.data.capacity = ARRAY_LEN;
6567

66-
memset(msg.data.data,'z',3500);
67-
msg.data.data[3500] = '\0';
68-
msg.data.size = 3501;
68+
memset(msg.data.data,'z',1800); // Default max buffer size is 2048 bytes
69+
msg.data.data[1800] = '\0';
70+
msg.data.size = 1801;
6971

7072
rclc_executor_spin(&executor);
7173

rclc/graph_introspection/publisher_count/main.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
rcl_subscription_t subscription;
1616
rcl_node_t node;
1717

18-
void timer_callback(rcl_timer_t * timer, int64_t last_call_time)
18+
void timer_callback(rcl_timer_t * timer, int64_t last_call_time, uintptr_t user_data)
1919
{
2020
(void) last_call_time;
21+
(void) user_data;
2122
printf("Publisher count for subscription '/parameter_events':\n");
2223
size_t publisher_count = 0;
2324
RCSOFTCHECK(rcl_subscription_get_publisher_count(&subscription, &publisher_count));
@@ -48,11 +49,12 @@ int main(int argc, const char * const * argv)
4849
// create timer
4950
rcl_timer_t timer;
5051
const unsigned int timer_timeout = 1000;
51-
RCCHECK(rclc_timer_init_default(
52+
RCCHECK(rclc_timer_init_default2(
5253
&timer,
5354
&support,
5455
RCL_MS_TO_NS(timer_timeout),
55-
timer_callback));
56+
timer_callback,
57+
true));
5658

5759
// create executor
5860
rclc_executor_t executor;

rclc/graph_introspection/subscription_count/main.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
rcl_publisher_t publisher;
1616
rcl_node_t node;
1717

18-
void timer_callback(rcl_timer_t * timer, int64_t last_call_time)
18+
void timer_callback(rcl_timer_t * timer, int64_t last_call_time, uintptr_t user_data)
1919
{
2020
(void) last_call_time;
21+
(void) user_data;
2122
printf("Subscriptions count for publisher '/parameter_events':\n");
2223
size_t subscription_count = 0;
2324
RCSOFTCHECK(rcl_publisher_get_subscription_count(&publisher, &subscription_count));
@@ -48,11 +49,12 @@ int main(int argc, const char * const * argv)
4849
// create timer
4950
rcl_timer_t timer;
5051
const unsigned int timer_timeout = 1000;
51-
RCCHECK(rclc_timer_init_default(
52+
RCCHECK(rclc_timer_init_default2(
5253
&timer,
5354
&support,
5455
RCL_MS_TO_NS(timer_timeout),
55-
timer_callback));
56+
timer_callback,
57+
true));
5658

5759
// create executor
5860
rclc_executor_t executor;

rclc/int32_multinode/main.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ rcl_subscription_t subscriber_2;
2020
std_msgs__msg__Int32 send_msg_2;
2121
std_msgs__msg__Int32 recv_msg_2;
2222

23-
void timer_callback_1(rcl_timer_t * timer, int64_t last_call_time)
23+
void timer_callback_1(rcl_timer_t * timer, int64_t last_call_time, uintptr_t user_data)
2424
{
2525
(void) last_call_time;
26+
(void) user_data;
2627
if (timer != NULL) {
2728
RCSOFTCHECK(rcl_publish(&publisher_1, &send_msg_1, NULL));
2829
printf("Node 1 -- Sent: %d\n", send_msg_1.data);
@@ -36,9 +37,10 @@ void subscription_callback_1(const void * msgin)
3637
printf("Node 1 --Received: %d\n", msg->data);
3738
}
3839

39-
void timer_callback_2(rcl_timer_t * timer, int64_t last_call_time)
40+
void timer_callback_2(rcl_timer_t * timer, int64_t last_call_time, uintptr_t user_data)
4041
{
4142
(void) last_call_time;
43+
(void) user_data;
4244
if (timer != NULL) {
4345
RCSOFTCHECK(rcl_publish(&publisher_2, &send_msg_2, NULL));
4446
printf("Node 2 -- Sent: %d\n", send_msg_2.data);
@@ -82,11 +84,12 @@ int main(int argc, const char * const * argv)
8284

8385
// create timer,
8486
rcl_timer_t timer_1;
85-
RCCHECK(rclc_timer_init_default(
87+
RCCHECK(rclc_timer_init_default2(
8688
&timer_1,
8789
&support,
8890
RCL_MS_TO_NS(1000),
89-
timer_callback_1));
91+
timer_callback_1,
92+
true));
9093

9194
// create executor
9295
rclc_executor_t executor_1 = rclc_executor_get_zero_initialized_executor();
@@ -115,11 +118,12 @@ int main(int argc, const char * const * argv)
115118

116119
// create timer,
117120
rcl_timer_t timer_2;
118-
RCCHECK(rclc_timer_init_default(
121+
RCCHECK(rclc_timer_init_default2(
119122
&timer_2,
120123
&support,
121124
RCL_MS_TO_NS(1000),
122-
timer_callback_2));
125+
timer_callback_2,
126+
true));
123127

124128
// create executor
125129
rclc_executor_t executor_2 = rclc_executor_get_zero_initialized_executor();

rclc/int32_publisher/main.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
rcl_publisher_t publisher;
1515
std_msgs__msg__Int32 msg;
1616

17-
void timer_callback(rcl_timer_t * timer, int64_t last_call_time)
17+
void timer_callback(rcl_timer_t * timer, int64_t last_call_time, uintptr_t user_data)
1818
{
1919
(void) last_call_time;
20+
(void) user_data;
2021
if (timer != NULL) {
2122
RCSOFTCHECK(rcl_publish(&publisher, &msg, NULL));
2223
printf("Sent: %d\n", msg.data);
@@ -46,11 +47,12 @@ int main()
4647
// create timer,
4748
rcl_timer_t timer;
4849
const unsigned int timer_timeout = 1000;
49-
RCCHECK(rclc_timer_init_default(
50+
RCCHECK(rclc_timer_init_default2(
5051
&timer,
5152
&support,
5253
RCL_MS_TO_NS(timer_timeout),
53-
timer_callback));
54+
timer_callback,
55+
true));
5456

5557
// create executor
5658
rclc_executor_t executor = rclc_executor_get_zero_initialized_executor();

rclc/int32_publisher_subscriber/main.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ rcl_subscription_t subscriber;
1515
std_msgs__msg__Int32 send_msg;
1616
std_msgs__msg__Int32 recv_msg;
1717

18-
void timer_callback(rcl_timer_t * timer, int64_t last_call_time)
18+
void timer_callback(rcl_timer_t * timer, int64_t last_call_time, uintptr_t user_data)
1919
{
2020
(void) last_call_time;
21+
(void) user_data;
2122
if (timer != NULL) {
2223
RCSOFTCHECK(rcl_publish(&publisher, &send_msg, NULL));
2324
printf("Sent: %d\n", send_msg.data);
@@ -60,11 +61,12 @@ int main(int argc, const char * const * argv)
6061
// create timer,
6162
rcl_timer_t timer;
6263
const unsigned int timer_timeout = 1000;
63-
RCCHECK(rclc_timer_init_default(
64+
RCCHECK(rclc_timer_init_default2(
6465
&timer,
6566
&support,
6667
RCL_MS_TO_NS(timer_timeout),
67-
timer_callback));
68+
timer_callback,
69+
true));
6870

6971
// create executor
7072
rclc_executor_t executor = rclc_executor_get_zero_initialized_executor();

0 commit comments

Comments
 (0)