-
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, 1.2)
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, 4 is the desired depth and 1.2 is the desired speed (in meters per second).
After a vehicle is commanded to go to a waypoint, it will continue going towards that location until it arrives there or a new waypoint is commanded. After a vehicle arrives at the waypoint, if the waypoint is underwater it will continue loitering around that location (going around in circles to maintain the depth) if the waypoint is on the surface, the vehicle will turn off its motor and let itself drift up to 20 meters away from the desired location.
In order to check if the vehicle as arrived at the destination, you can use the following methods:
myVehicle.arrivedZ() % has the vehicle arrived at the desired depth/altitude?
myVehicle.arrivedXY() % has the vehicle arrived at the desired horizontal location?
myVehicle.arrived() % has the vehicle arrived at the desired location (both XY and Z)?