Overview

This package allows you to store data easily in shared memory segments. All variables stored in the shared memory are labeled and identified with a name of your choice. You can also trigger signals for subscribed processes on your shared variables instead of polling for changes.

No Nodelets needed

Nodelets are not required and you have to rethink your communication.

Interprocess communication

Using ak_shm also allows you to communicate with other programs/processes on the same computer in a very efficient way.

Tools

The package includes a program to simply access variables stored in the shared memory

shmadmin

The program shmadmin is able to read and write variables and vectors of common types. It is also able to set and release locks on variables

   1 rosrun ak_shm shmadmin -h
   2 Allowed Parameters:
   3   --help                get this help message
   4   -a [ --all ]          lists all shared variables
   5   -c [ --clear ]        clears shared memory
   6   -f [ --force ]        forces action write and ...
   7   -n [ --segment ] arg  shared memory segment
   8   -l [ --list ] arg     lists named variables
   9   -t [ --testlock ] arg tests locks
  10   -u [ --unlock ] arg   unlocks variables
  11   -k [ --lock ] arg     locks variables
  12   -s [ --signal ] arg   signals a change of a named variable
  13   -r [ --read ] arg     reads content of a named variable
  14   -w [ --write ] arg    [value] writes a value to shared variables
  15                         example:  -w Var "3:0 1.03  4 0 4, 4" writes a six 
  16                         channels vector/array six values at index 3

shmimageviewer

This program displays images stored in the shared memory

   1 rosrun ak_shm shmimageview -h
   2 Allowed Parameters:
   3   --help                 get this help message
   4   -s [ --simgleshot ]    shared rgb image
   5   -u [ --drawOnChange ]  updates only on change
   6   -n [ --segment ] arg   shared memory segment
   7   -g [ --gray ] arg      shared gray image
   8   -r [ --rgb ] arg       shared rgb image
   9   -b [ --bgr ] arg       shared bgr image
  10   -y [ --yuyv ] arg      shared yuyv image

Examples

Various examples are provided to show how you can use the shared memory for interprocess communication.

usb_cam_to_shm.launch: copies a image into the shared memory and back

This example publishes images using the usb_cam package and copies the image into the shared memory using the image2shm note. The shmimageviewer is able to draw images stored in the shared memory and the shm2image note pipes the image back to a rostopic.

   1 rosmake usb_cam ak_shm 
   2 rosrun ak_shm shmadmin -c # clears the shared memory
   3 roslaunch ak_shm usb_cam_to_shm.launch

Creating variables

This example shows you how you can create, read and write common shared variables and how you can create a shared vector of your own type/class. You should run the example multiple times to see the effect. You can also see how to access variables on a secure concurrent way.

  •    1 rosmake ak_shm
       2 rosrun ak_shm shmadmin -c # clears the shared memory
       3 rosrun ak_shm example00
    

Locking variables, waiting for changes and signals

This example shows you how you lock variables and how you trigger signals.

   1 rosrun ak_shm shmadmin -c # clears the shared memory
   2 rosrun ak_shm example01

After you run the example01 you can use the shmadmin to view the variables.

   1 rosrun ak_shm shmadmin -a # -a lists all shared variables
   2 rosrun ak_shm shmadmin -u MyPoint3D # -a Unlocks variables

Timed wait and signals

This example shows you how you lock variables and how you trigger changes.

   1 rosrun ak_shm shmadmin -c # clears the shared memory
   2 rosrun ak_shm example02

Shared images and opencv image processing

This example shows how you create a shared image and how you can view it with the shmimageviewer.

   1 rosrun ak_shm shmadmin -c # clears the shared memory
   2 # opens a image and porcesses a canny image
   3 rosrun ak_shm example03 [path to a color image] 
   4 # shows the source image form the shm
   5 rosrun ak_shm shmimageview --bgr ImgSrc 
   6 # shows a gray image 
   7 rosrun ak_shm shmimageview --gray ImgCanny  
   8 # shows a multiple images in a false color format 
   9 rosrun ak_shm shmimageview --rgb ImgSrc --gray ImgCanny

System installation

If you want the library to be available outside of ros you can run make install in your build folder

   1 roscd ak_shm
   2 cd build
   3 make install # with sudo

System uninstall

   1 rm -rf /usr/include/akshm  # with sudo
   2 rm $HOME/bin/shmimageview $HOME/bin/shmadmin

Nodes

image2shm

Copies an image to the shared memory.

Parameters

image_to_subscribe (string, default: "image")
  • image which should be copied
shm_image_name (string, default: Same as the image_to_subscribe)
  • name (identifier) of the shared image
shm_segment_name (string, default: "AKSharedMem")
  • name (identifier) of the shared segment used
shm_segment_size (int, default: 104857600 (100MB))
  • size of shared segment used in byte

shm2image

publishes a shared image

Parameters

shm_image_name (string, default: "image")
  • name (identifier) of the shared image
image_to_publish (string, default: Same as shm_image_name)
  • image which should be published
shm_segment_name (string, default: "AKSharedMem")
  • name (identifier) of the shared segment used
shm_segment_size (int, default: 104857600 (100MB))
  • size of shared segment used in byte
publish_on_change (boolean, default: false)
  • publishes the image only if the shared memory updates
timed_wait_ms (int, default: 500)
  • if publish_on_change is false it waits x ms until it publishes the image again

Wiki: ak_shm (last edited 2011-01-13 16:57:50 by Markus Bader)