Skip to content

Shared Memory Debugging

brindza edited this page Oct 30, 2011 · 8 revisions

Shared memory is the main source of inter-process communication that the system uses. One benefit that comes naturally from the shared memory interface is the ability to monitor the program state from outside the program itself.

All of the important information in our applications is stored into a shared memory segment. At anytime during the program execution you can connect to the shared memory segments and view the current values.

Lua Shared Memory Interface

The Lua shared memory interface can be used outside the main program the same way it is used internally. Therefore any functions/data available in main Lua program are accessible in a Lua debugging module you write.

Alternative Languages

Another benefit is the ability to access the shared memory segments from any language that supports C++ interoperability. We provide a shared memory interface for MATLAB and Python, but making a new one for your language of choice is easy.

Due to the way the shared memory segments are created in Lua there is some information not available outside of Lua. In order to connect to the segments from outside Lua you need to know the segment name. The shared memory explains how these segment names are determined.

MATLAB Shared Memory Interface

Most of the debugging tools we provide are written using MATLAB. MATLAB is a very good tool for data analysis and visualization making it ideal for debugging. We provide a mex interface to the shared memory segments called mexshm and a wrapper for that shm.m that generates accessors and setters for the available variables.

Example usage (from the UPennalizers/Lib/Util/Matlab directory):

>> wcmRobot = shm('wcmRobot12nao')

wcmRobot = 

     shmHandle: 36
      get_pose: @()mexshm('get',h.shmHandle,k)
      set_pose: @(val)mexshm('set',h.shmHandle,k,double(val))
    get_uTorso: @()mexshm('get',h.shmHandle,k)
    set_uTorso: @(val)mexshm('set',h.shmHandle,k,double(val))
>> pose = wcmRobot.get_pose()

pose =

   -0.9898    0.3431   -3.0588

Python Shared Memory Interface

We also provide a shared memory wrapper for python in the UPennalizers/Lib/Util/Python directory. This provides the same basic interface as the MATLAB interface. You provide the segment name and it will automatically generate setters and accessors from the available variables.

>>> import shm
>>> wcmRobot = shm.ShmWrapper('wcmRobot12nao')
>>> wcmRobot.get_pose()
    array([-0.98981771,  0.34309482, -3.05884778])

Numpy arrays are the default type used by the wrapper.

Clone this wiki locally