-
Notifications
You must be signed in to change notification settings - Fork 5
Controlling vehicles with Matlab
IMCJava also provides a simplified API that allows Matlab scripts to connect to vehicles in the same network and command them via waypoints.
In order to be able to access this API, you should add IMCJava support in Matlab:
javaaddpath('path/to/libimc.jar')
You should also import the package pt.lsts.imc.control:
import pt.lsts.imc.control.*
Now, you can connect to a vehicle named 'lauv-xtreme-2' by using the following expression:
myVehicle = ControlLink.acquire('lauv-xtreme-2', 30000)
Where, 30000 is the amount of time (in milliseconds) to wait for the vehicle to become visible. If no exception is thrown, this means that the vehicle started executing a special behavior which will make it accept waypoint commands only from your Matlab application. You can query the current vehicle position by using the command:
pos = myVehicle.getPosition()
Also, you can command the vehicle to go to a different location by sending it the desired coordinates:
myVehicle.guide(41.02343, -8.242333, 4)
Bear in mind that you shoud provide the WGS84 coordinates of the desired location plus a desired depth or altitude from the ground/bottom (negative value). In the previous expression, 41.02343 is the desired latitude, -8.242333 is the desired longitude and 4 is the desired depth.