Skip to content

Commit 47f6917

Browse files
committed
re-ordered example for embedded use-case (moved to the end)
1 parent 4f104f7 commit 47f6917

1 file changed

Lines changed: 65 additions & 63 deletions

File tree

  • _docs/concepts/client_library/execution_management

_docs/concepts/client_library/execution_management/index.md

Lines changed: 65 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ redirect_from:
3030
* [Configuration phase](#configuration-phase)
3131
* [Running phase](#running-phase)
3232
* [Examples](#examples)
33-
* [Embedded use-case](#embedded-use-case)
3433
* [Sense-plan-act pipeline](#sense-plan-act-pipeline)
3534
* [Sensor fusion](#sensor-fusion)
3635
* [High priority path](#high-priority-path)
36+
* [Embedded use-case](#embedded-use-case)
3737
* [ROS 2 Executor Workshop Reference System](#ros-2-executor-workshop-reference-system)
3838
* [Future work](#future-work)
3939
* [Download](#download)
@@ -400,68 +400,7 @@ Available spin functions are
400400
- `spin` - spin indefinitly
401401

402402
### Examples
403-
We provide the relevant code snippets how to setup the rclc Executor for the embedded use case and for the software design patterns in mobile robotics applications as described above.
404-
#### Embedded use-case
405-
406-
With seqential execution the co-operative scheduling of tasks within a process can be modeled. The trigger condition is used to periodically activate the process which will then execute all callbacks in a pre-defined order. Data will be communicated using the LET-semantics. Every Executor is executed in its own tread, to which an appropriate priority can be assigned.
407-
408-
In the following example, the Executor is setup with 4 handles. We assume a process has three subscriptions `sub1`, `sub2`, `sub3`. The sequential processing order is given by the order as they are added to the Executor. A timer `timer` defines the period. The `trigger_one` with the paramter `timer` is used, so that whenever the timer is ready, all callbacks are processed. Finally the data communication semantics LET is defined.
409-
```C
410-
#include "rcl_executor/let_executor.h"
411-
412-
// define subscription callback
413-
void my_sub_cb1(const void * msgin)
414-
{
415-
// ...
416-
}
417-
// define subscription callback
418-
void my_sub_cb2(const void * msgin)
419-
{
420-
// ...
421-
}
422-
// define subscription callback
423-
void my_sub_cb3(const void * msgin)
424-
{
425-
// ...
426-
}
427-
428-
// define timer callback
429-
void my_timer_cb(rcl_timer_t * timer, int64_t last_call_time)
430-
{
431-
// ...
432-
}
433-
434-
// necessary ROS 2 objects
435-
rcl_context_t context;
436-
rcl_node_t node;
437-
rcl_subscription_t sub1, sub2, sub3;
438-
rcl_timer_t timer;
439-
rcle_let_executor_t exe;
440-
441-
// define ROS context
442-
context = rcl_get_zero_initialized_context();
443-
// initialize ROS node
444-
rcl_node_init(&node, &context,...);
445-
// create subscriptions
446-
rcl_subscription_init(&sub1, &node, ...);
447-
rcl_subscription_init(&sub2, &node, ...);
448-
rcl_subscription_init(&sub3, &node, ...);
449-
// create a timer
450-
rcl_timer_init(&timer, &my_timer_cb, ... );
451-
// initialize executor with four handles
452-
rclc_executor_init(&exe, &context, 4, ...);
453-
// define static execution order of handles
454-
rclc_executor_add_subscription(&exe, &sub1, &my_sub_cb1, ALWAYS);
455-
rclc_executor_add_subscription(&exe, &sub2, &my_sub_cb2, ALWAYS);
456-
rclc_executor_add_subscription(&exe, &sub3, &my_sub_cb3, ALWAYS);
457-
rclc_executor_add_timer(&exe, &timer);
458-
// trigger when handle 'timer' is ready
459-
rclc_executor_set_trigger(&exe, rclc_executor_trigger_one, &timer);
460-
// select LET-semantics
461-
rclc_executor_data_comm_semantics(&exe, LET);
462-
// spin forever
463-
rclc_executor_spin(&exe);
464-
```
403+
We provide the relevant code snippets how to setup the rclc Executor for the processing patterns as described above.
465404

466405
#### Sense-plan-act pipeline
467406

@@ -562,6 +501,69 @@ rclc_executor_set_trigger(&exe, rclc_executor_trigger_one, &sense_Laser);
562501
// spin
563502
rclc_executor_spin(&exe);
564503
```
504+
505+
#### Embedded use-case
506+
507+
With seqential execution the co-operative scheduling of tasks within a process can be modeled. The trigger condition is used to periodically activate the process which will then execute all callbacks in a pre-defined order. Data will be communicated using the LET-semantics. Every Executor is executed in its own tread, to which an appropriate priority can be assigned.
508+
509+
In the following example, the Executor is setup with 4 handles. We assume a process has three subscriptions `sub1`, `sub2`, `sub3`. The sequential processing order is given by the order as they are added to the Executor. A timer `timer` defines the period. The `trigger_one` with the paramter `timer` is used, so that whenever the timer is ready, all callbacks are processed. Finally the data communication semantics LET is defined.
510+
```C
511+
#include "rcl_executor/let_executor.h"
512+
513+
// define subscription callback
514+
void my_sub_cb1(const void * msgin)
515+
{
516+
// ...
517+
}
518+
// define subscription callback
519+
void my_sub_cb2(const void * msgin)
520+
{
521+
// ...
522+
}
523+
// define subscription callback
524+
void my_sub_cb3(const void * msgin)
525+
{
526+
// ...
527+
}
528+
529+
// define timer callback
530+
void my_timer_cb(rcl_timer_t * timer, int64_t last_call_time)
531+
{
532+
// ...
533+
}
534+
535+
// necessary ROS 2 objects
536+
rcl_context_t context;
537+
rcl_node_t node;
538+
rcl_subscription_t sub1, sub2, sub3;
539+
rcl_timer_t timer;
540+
rcle_let_executor_t exe;
541+
542+
// define ROS context
543+
context = rcl_get_zero_initialized_context();
544+
// initialize ROS node
545+
rcl_node_init(&node, &context,...);
546+
// create subscriptions
547+
rcl_subscription_init(&sub1, &node, ...);
548+
rcl_subscription_init(&sub2, &node, ...);
549+
rcl_subscription_init(&sub3, &node, ...);
550+
// create a timer
551+
rcl_timer_init(&timer, &my_timer_cb, ... );
552+
// initialize executor with four handles
553+
rclc_executor_init(&exe, &context, 4, ...);
554+
// define static execution order of handles
555+
rclc_executor_add_subscription(&exe, &sub1, &my_sub_cb1, ALWAYS);
556+
rclc_executor_add_subscription(&exe, &sub2, &my_sub_cb2, ALWAYS);
557+
rclc_executor_add_subscription(&exe, &sub3, &my_sub_cb3, ALWAYS);
558+
rclc_executor_add_timer(&exe, &timer);
559+
// trigger when handle 'timer' is ready
560+
rclc_executor_set_trigger(&exe, rclc_executor_trigger_one, &timer);
561+
// select LET-semantics
562+
rclc_executor_data_comm_semantics(&exe, LET);
563+
// spin forever
564+
rclc_executor_spin(&exe);
565+
```
566+
565567
#### ROS 2 Executor Workshop Reference System
566568
The rclc Executor has been presented at the workshop 'ROS 2 Executor: How to make it efficient, real-time and deterministic?' at [ROS World 2021](https://roscon.ros.org/world/2021/) (i.e. the online version of ROSCon)[[S2021](#S2021)]. A [Reference System](https://github.com/ros-realtime/reference-system) for testing and benchmarking ROS Executors has been developed for this workshop. The application of the rclc Executor on the reference system with the trigger condition can be found in the [rclc-executor branch of the Reference System](https://github.com/ros-realtime/reference-system/tree/rclc_executor).
567569

0 commit comments

Comments
 (0)