Contents
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.
Locking variables, waiting for changes and signals
This example shows you how you lock variables and how you trigger signals.
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.
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
System uninstall
Nodes
image2shm
Copies an image to the shared memory.Parameters
image_to_subscribe (string, default: "image")- image which should be copied
- name (identifier) of the shared image
- name (identifier) of the shared segment used
- size of shared segment used in byte
shm2image
publishes a shared imageParameters
shm_image_name (string, default: "image")- name (identifier) of the shared image
- image which should be published
- name (identifier) of the shared segment used
- size of shared segment used in byte
- publishes the image only if the shared memory updates
- if publish_on_change is false it waits x ms until it publishes the image again