Skip to content

Sending IMC messages with Matlab

zepinto edited this page Dec 1, 2014 · 2 revisions

IMCJava is a Java library than can be used by any Java application (Android included) to receive and send IMC messages. Moreover, you can also import this Java library in Matlab to receive real-time data and control vehicles that are connected to the same network.

Importing the IMCJava library in Matlab

From Matlab you can add the library libimc.jar to Matlab by entering the following command:

javaaddpath('/path/to/libimc.jar')

Also, you should be interested in importing packages required for sending and receiving messages:

import pt.lsts.imc.*
import pt.lsts.imc.net.*

Using IMCProtocol to interact with a network of vehicles

You can now start using IMC from Matlab by creating an instance of an IMCProtocol java object:

imc = IMCProtocol()

This will result in the creation of a new IMC node in the network that will discover other systems and connect to them. In order to list the names of the connected systems, you can type:

imc.systems()

When you are done, you can stop the IMC protocol in Matlab by calling the method stop():

imc.stop()

Sending out messages

You can create any IMCMessage by creating a corresponding Java object. See also http://lsts.github.io/imcjava/api-doc/pt/up/fe/dceg/neptus/imc/package-summary.html. You can address a message to a specific vehicle by using its name:

msg = Abort()
imc.send('lauv-xtreme-2', msg)

If needed you can also send a message to all of the connected peers:

msg = Abort()
imc.sendToPeers(msg)