Skip to content

cisstMultiTask tutorial

Anton Deguet edited this page May 27, 2014 · 15 revisions

Table of Contents generated with DocToc

Introduction

In this tutorial we will create two simple components. The first component is a counter. It's main function is to periodically increment an internal counter. When the counter overflows it should send an event. One should be able to query the current value and set the increment. If the user requests an incorrect value for the increment, the counter component will throw an event with an informative message.

The second component user is designed to be connected to the counter component. In this example, we're avoiding using a GUI toolkit to make the code as simple as possible. The user interface is text based.

The latest version of the code for this tutorial can be compiled along the cisst using the CMake options CISST_BUILD_EXAMPLES and CISST_cisstMultiTask_EXAMPLES. The code itself can be found in cisst/cisstMultiTask/examples/tutorial

Counter component

Periodic task

For this component, we're using a the base class mtsTaskPeriodic, i.e. the method used to perform all user defined computations Run will be called periodically and the library will attempt to maintain a constant frequency between calls to the Run method. The amount of jitter depends on the services provided by the Operating System (the cisstOSAbstraction library provides an abstraction layer to the different OSs features).

One of the parameters provided to the constructor is the desired periodicity provided as a double representing the time in seconds. To make sure the code is readable, cisst has a set of constants used to indicate the units used, e.g. 5.0 * cmm_ms indicates 5 milliseconds.

It is possible to use different types of components; continuous, event based, triggered by an external event, ... See all component and task types in cisstMultiTask concepts.

State table

Commands

explain thread safety for read using state table and ProcessQueuedCommands

Events

explain two types of events, multiple observers and ProcessQueuedEvents

User component

Functions

explain not that not all commands in provided need a function in required. functions in required can be optional.

Event handlers

Connecting components

add, connect, set state and wait

Clone this wiki locally