Skip to content

Interacting with SAM from your code

jmessias edited this page Jun 29, 2015 · 4 revisions

Since the SAM interface is service-based, that means that from within your code you must simply instantiate the respective service clients, so no header files or libraries are needed. In the following, we show examples of how to create readers and writers from within a ROS node. Note that the following code snippets are not fully executable (or even compilable) ROS nodes. For fully-functional examples of how to write SAM client nodes, you can consult the nodes that are defined within the ‘sam_client_tests’ package.

Example 1: Creating an SA Reader explicitly in Python

Example 2: Creating an SA Reader explicitly in C++

The creation of Writers is analogous, since the service request and response types are equivalent (you should advertise to the response topic instead of subscribing to it).

Since the procedure to create SAM Readers and Writers is fairly repetitive, and to ease development of client software modules, the monarch_situational_awareness package also provides a set of helper classes, visible to the general MOnarCH code as the ‘sam_helpers’ package, that can be used to abstract the service-based interaction. These can be included / imported and used directly within your code.

The following are examples of their use.

Example 3: Creating SA Readers Writers in Python using the sam_helpers

Example 4: creating SA Readers and Writers with CPP using the sam_helpers