RSBm » History » Version 9

« Previous - Version 9/29 (diff) - Next » - Current version
S. Wrede, 10/17/2011 12:31 AM


RSB.m

We are currently exploring the best way to expose RSB in Matlab. The most straightforward way to do this is to use the Java implementation directly from within Matlab. However, as the Matlab Java interpreter is not able to handle Java's Generic types, we need to wrap around some parts of the RSBJava API which use generics.

For this, a very preliminary support library for Matlab is available in the Trunk repository: https://code.cor-lab.org/projects/rsb/repository/show/trunk/matlab

It currently includes a simple example demonstrating the live plotting of rst.JointAngles data.

After installation of this library, the current steps in using RSB in Matlab are as follows:

Loading the Java RSB libraries into Matlab

javaaddpath /usr/share/java/RSBJava-0.5.0.jar
javaaddpath /usr/share/java/protobuf.jar
javaaddpath /usr/share/java/rst.jar
javaaddpath /usr/share/java/rstsandbox.jar
javaaddpath /${home}/workspace/RSB.m/dist/lib/rsb.m-0.5.0.jar
rsb.matlab.ConverterRegistration.register()

The last call initializes the ProtocolBufferConverter instances with a few selected RST types. This mechanism will definitely be changed as it currently introduces an unwanted dependency (at this stage) to RST.

Get queue object for domain-specific data

%   Scope must map to a rst.kinematics.JointAngles type
angles = rsb.matlab.JointAnglesQueue;

JointAnglesQueue is a class of the RSB.m library that maps the RSB domain type rst.JointAngles to a matlab vector with floats. Furthermore, it allows access to the underlying BlockingQueue that provides further methods for queue management. See the RSBJava API documentation for more information.

Connect queue to RSB listener

s = rsb.Scope('/oncilla');
sub = rsb.Factory.getInstance().createListener(s);
sub.activate()
sub.addHandler(angles, true)

Pretty standard RSB API here. After the call to addHandler the angles queue receives data. You can easily check this by calling: angles.getQueue().isEmpty()

Doing something useful, e.g., data visualization

Having the queue, we can now operate directly on the returned floats. For instance, display them in a live plot:

a = zeros(1,200)
while(1)
a(1:end - 1) = a(2:end);
% blocks until new data is available
a(end) = angles.take;
angles.getQueue.clear;
plot(a);
getframe;
end

To prevent memory leaks, the above code clears the queue after each (blocking) call to take.

Unload the RSB Java libraries

javarmpath /vol/cit/share/java/rsb.m-0.5.0.jar
javarmpath /vol/cit/share/java/rst.jar
javarmpath /vol/cit/share/java/rstsandbox.jar
javarmpath /vol/cit/share/java/RSBJava-0.5.0.jar
javarmpath /opt/local/share/java/protobuf.jar

This example code is available as Matlab functions in the RSB.m project here: https://code.cor-lab.org/projects/rsb/repository/show/trunk/matlab/matlab

Older notes

First successful test of sending data from Matlab to RSB:

>> javaaddpath /vol/cit/share/java/RSBJava-0.4.0.jar
>> javaaddpath /opt/local/share/java/protobuf.jar
>> f = rsb.Factory.getInstance()

f =

rsb.Factory@5c4e0c39

>> s = Scope('/example/informer')

s =

/example/informer/

>> i = f.createInformer(s)
No rsb.conf found in configuration directory '/Users/swrede/.config'
No rsb.conf found in working directory '/Users/swrede/Documents/MATLAB'

i =

rsb.Informer@75222b8e

>> i.activate
18.07.2011 18:21:22 rsb.Informer$InformerStateInactive activate
INFO: Informer activated: [Scope:/example/informer/,Type:String]
>> i.send('RSB')

ans =

Event[id=4145dcfd-aff7-45de-b00f-0c6c315f0ce7, scope=/example/informer/, type =String, metaData=MetaData[senderId = 4d619c1a-b516-4474-9eed-eb216546ff01, createTime = 1311006099963000, sendTime = 1311006099966000, receiveTime = 0, userTimes = {}, userInfos = {}]]