-
Notifications
You must be signed in to change notification settings - Fork 5
Receiving real time data in Matlab
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.
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.*
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()
You can access the data received from any system by means of querying its state. For instance, in order to get the last received message of type EstimatedState produced by lauv-xtreme-2 vehicles, you can type:
estate = imc.state('lauv-xtreme-2').get('EstimatedState')
All received messages are Java objects from which you can retrieve specific field values as follows:
x = imc.state('lauv-xtreme-2').get('EstimatedState').getX()
y = imc.state('lauv-xtreme-2').get('EstimatedState').getY()
Alternativaly you can wait for the next message of certain type to arrive by polling for some time (in milliseconds) as follows:
nextState = imc.state('lauv-xtreme-2').poll('EstimatedState', 1000)