Skip to content

Commit

Permalink
Updated matlab toolbox to 3.1. Updated example to use vehicleName arg…
Browse files Browse the repository at this point in the history
…ument. Added example for two drones. Added async launch options for drone functions with join argument. Ref Cosys-Lab#32
  • Loading branch information
WouterJansen committed Oct 1, 2024
1 parent c8edc4b commit a930b71
Show file tree
Hide file tree
Showing 15 changed files with 419 additions and 296 deletions.
435 changes: 257 additions & 178 deletions Matlab/AirSimClient.m

Large diffs are not rendered by default.

Binary file modified Matlab/Cosys-AirSim Matlab API Client.mltbx
Binary file not shown.
18 changes: 5 additions & 13 deletions Matlab/Cosys-AirSim Matlab API Client.prj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<param.summary>This a client implementation of the RPC API for Matlab for the Cosys-AirSim simulation framework.</param.summary>
<param.description>This a client implementation of the RPC API for Matlab for the Cosys-AirSim simulation framework. A main class AirSimClient is available which implements all API calls.
Do note that at this point not all functions have been tested and most function documentation was auto-generated. This is still a WIP client.</param.description>
<param.screenshot />
<param.version>3.0.1.0</param.version>
<param.screenshot>D:\BigProjects\Cosys-AirSim-Public\promo\thumbnail_matlab.png</param.screenshot>
<param.version>3.1.0.0</param.version>
<param.output>${PROJECT_ROOT}\Cosys-AirSim Matlab API Client.mltbx</param.output>
<param.products.name>
<item>Aerospace Toolbox</item>
Expand All @@ -35,14 +35,7 @@ Do note that at this point not all functions have been tested and most function
&lt;example name="example" type="html"&gt;
&lt;file type="source"&gt;/html/example.html&lt;/file&gt;
&lt;file type="main"&gt;/example.m&lt;/file&gt;
&lt;file type="thumbnail"&gt;/html/example.png&lt;/file&gt;
&lt;file type="image"&gt;/html/example_01.png&lt;/file&gt;
&lt;file type="image"&gt;/html/example_02.png&lt;/file&gt;
&lt;file type="image"&gt;/html/example_03.png&lt;/file&gt;
&lt;file type="image"&gt;/html/example_04.png&lt;/file&gt;
&lt;file type="image"&gt;/html/example_05.png&lt;/file&gt;
&lt;file type="image"&gt;/html/example_06.png&lt;/file&gt;
&lt;file type="image"&gt;/html/example_07.png&lt;/file&gt;
&lt;file type="thumbnail"/&gt;
&lt;/example&gt;
&lt;/exampleCategory&gt;
&lt;/examples&gt;</param.examples>
Expand All @@ -53,7 +46,7 @@ Do note that at this point not all functions have been tested and most function
<param.getting.started.guide>${PROJECT_ROOT}\doc\GettingStarted.mlx</param.getting.started.guide>
<param.matlabpath.excludes />
<param.javaclasspath.excludes />
<param.exported.on.package>false</param.exported.on.package>
<param.exported.on.package>true</param.exported.on.package>
<param.required.addons />
<param.matlab.project.id />
<param.matlab.project.name />
Expand All @@ -74,7 +67,6 @@ Do note that at this point not all functions have been tested and most function
<param.authnamewatermark />
<param.email />
<param.company />
<param.screenshot />
<param.output />
<param.platforms />
<param.exclude.filters />
Expand All @@ -84,7 +76,6 @@ Do note that at this point not all functions have been tested and most function
<param.registered.apps />
<param.matlabpath.excludes />
<param.javaclasspath.excludes />
<param.exported.on.package />
<param.required.addons />
<param.matlab.project.id />
<param.matlab.project.name />
Expand Down Expand Up @@ -113,6 +104,7 @@ Do note that at this point not all functions have been tested and most function
<file>${PROJECT_ROOT}\demos.xml</file>
<file>${PROJECT_ROOT}\doc</file>
<file>${PROJECT_ROOT}\example.m</file>
<file>${PROJECT_ROOT}\example_twodrones.m</file>
<file>${PROJECT_ROOT}\help</file>
<file>${PROJECT_ROOT}\html</file>
<file>${PROJECT_ROOT}\info.xml</file>
Expand Down
Binary file modified Matlab/doc/GettingStarted.mlx
Binary file not shown.
55 changes: 24 additions & 31 deletions Matlab/example.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
%% Example
%
% This example works well with the default example settings found in the docs folder op the repository.
%
% This example will:
% -Connect to AirSim
% -Get/set vehicle pose
Expand All @@ -20,7 +23,7 @@

%Define client
vehicle_name = "airsimvehicle";
airSimClient = AirSimClient(IsDrone=false, ApiControl=false, IP="127.0.0.1", port=41451, vehicleName=vehicle_name);
airSimClient = AirSimClient(IsDrone=false, IP="127.0.0.1", port=41451);

%% Groundtruth labels
% Get groundtruth look-up-table of all objects and their instance
Expand All @@ -36,23 +39,15 @@
poses = airSimClient.getAllObjectPoses(false, false);

% Get vehicle pose
vehiclePoseLocal = airSimClient.getVehiclePose();
vehiclePoseLocal = airSimClient.getVehiclePose(vehicle_name);
vehiclePoseWorld = airSimClient.getObjectPose(vehicle_name, false);

% Get an random object pose or choose if you know the name of one
useChosenObject = false;
% Choose the object to get the pose from (this one is in the Blocks env)
chosenObject = "Cylinder3";

if useChosenObject
finalName = chosenObject;
else
randomIndex = randi(size(groundtruthLUT, 1), 1);
randomName = groundtruthLUT.name(randomIndex);
finalName = randomName;
end

objectPoseLocal = airSimClient.getObjectPose(finalName, true);
objectPoseWorld = airSimClient.getObjectPose(finalName, false);
% Get its pose
objectPoseLocal = airSimClient.getObjectPose(chosenObject, true);
objectPoseWorld = airSimClient.getObjectPose(chosenObject, false);

figure;
subplot(1, 2, 1);
Expand All @@ -76,19 +71,19 @@
drawnow

% Set vehicle pose
airSimClient.setVehiclePose(airSimClient.getVehiclePose().position + [1 1 0], airSimClient.getVehiclePose().orientation)
airSimClient.setVehiclePose(airSimClient.getVehiclePose(vehicle_name).position + [1 1 0], airSimClient.getVehiclePose(vehicle_name).orientation, false, vehicle_name)

%% IMU sensor Data
imuSensorName = "imu";
[imuData, imuTimestamp] = airSimClient.getIMUData(imuSensorName);
[imuData, imuTimestamp] = airSimClient.getIMUData(imuSensorName, vehicle_name)

%% Echo sensor data
% Example plots passive echo pointcloud
% and its reflection directions as 3D quivers

echoSensorName = "echo";
enablePassive = true;
[activePointCloud, activeData, passivePointCloud, passiveData , echoTimestamp, echoSensorPose] = airSimClient.getEchoData(echoSensorName, enablePassive);
[activePointCloud, activeData, passivePointCloud, passiveData , echoTimestamp, echoSensorPose] = airSimClient.getEchoData(echoSensorName, enablePassive, vehicle_name);

figure;
subplot(1, 2, 1);
Expand Down Expand Up @@ -129,7 +124,7 @@

lidarSensorName = "lidar";
enableLabels = true;
[lidarPointCloud, lidarLabels, LidarTimestamp, LidarSensorPose] = airSimClient.getLidarData(lidarSensorName, enableLabels);
[lidarPointCloud, lidarLabels, LidarTimestamp, LidarSensorPose] = airSimClient.getLidarData(lidarSensorName, enableLabels, vehicle_name);

figure;
if ~isempty(lidarPointCloud)
Expand All @@ -151,7 +146,7 @@

gpuLidarSensorName = "gpulidar";
enableLabels = true;
[gpuLidarPointCloud, gpuLidarTimestamp, gpuLidarSensorPose] = airSimClient.getGPULidarData(gpuLidarSensorName);
[gpuLidarPointCloud, gpuLidarTimestamp, gpuLidarSensorPose] = airSimClient.getGPULidarData(gpuLidarSensorName, vehicle_name);

figure;
if ~isempty(gpuLidarPointCloud)
Expand All @@ -168,20 +163,19 @@
zlim([-10 10])
drawnow

%% Cameras
%% Get camera info

% Get camera info
cameraSensorName = "frontcamera";
[intrinsics, cameraSensorPose] = airSimClient.getCameraInfo(cameraSensorName);
[intrinsics, cameraSensorPose] = airSimClient.getCameraInfo(cameraSensorName, vehicle_name);

% Get single camera images
%% Get single camera images
% Get images sequentially

cameraSensorName = "front_center";
[rgbImage, rgbCameraIimestamp] = airSimClient.getCameraImage(cameraSensorName, AirSimCameraTypes.Scene);
[segmentationImage, segmentationCameraIimestamp] = airSimClient.getCameraImage(cameraSensorName, AirSimCameraTypes.Segmentation);
[depthImage, depthCameraIimestamp] = airSimClient.getCameraImage(cameraSensorName, AirSimCameraTypes.DepthPlanar);
[annotationImage, annotationCameraIimestamp] = airSimClient.getCameraImage(cameraSensorName, AirSimCameraTypes.Annotation, "TextureTestDirect");
[rgbImage, rgbCameraIimestamp] = airSimClient.getCameraImage(cameraSensorName, AirSimCameraTypes.Scene, vehicle_name);
[segmentationImage, segmentationCameraIimestamp] = airSimClient.getCameraImage(cameraSensorName, AirSimCameraTypes.Segmentation,vehicle_name);
[depthImage, depthCameraIimestamp] = airSimClient.getCameraImage(cameraSensorName, AirSimCameraTypes.DepthPlanar,vehicle_name);
[annotationImage, annotationCameraIimestamp] = airSimClient.getCameraImage(cameraSensorName, AirSimCameraTypes.Annotation, vehicle_name, "TextureTestDirect");
figure;
subplot(4, 1, 1);
imshow(rgbImage)
Expand All @@ -197,14 +191,13 @@
title("Annotation Camera Image")
drawnow

% Get synced camera images
% By combining the image requests they will be synced
% and taken in the same frame
%% Get synced camera images
% By combining the image requests they will be synced and taken in the same frame

cameraSensorName = "front_center";
[images, cameraIimestamp] = airSimClient.getCameraImages(cameraSensorName, ...
[AirSimCameraTypes.Scene, AirSimCameraTypes.Segmentation, AirSimCameraTypes.DepthPlanar, AirSimCameraTypes.Annotation], ...
["", "", "", "GreyscaleTest"]);
vehicle_name, ["", "", "", "TextureTestDirect"]);
figure;
subplot(4, 1, 1);
imshow(images{1})
Expand Down
54 changes: 54 additions & 0 deletions Matlab/example_twodrones.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
%% Example two drones
%
% This works well with the settings below:
%
% {
% "SeeDocsAt": "https://cosys-lab.github.io/settings/",
% "SettingsVersion": 2,
% "ClockSpeed": 1,
% "LocalHostIp": "127.0.0.1",
% "ApiServerPort": 41451,
% "RpcEnabled": true,
% "SimMode": "Multirotor",
% "Vehicles": {
% "Drone1": {
% "VehicleType": "SimpleFlight",
% "AllowAPIAlways": true,
% "X": 0,
% "Y": 0,
% "Z": 0,
% "Yaw": 0
% },
% "Drone2": {
% "VehicleType": "SimpleFlight",
% "AllowAPIAlways": true,
% "X": 5,
% "Y": 0,
% "Z": 0,
% "Yaw": 0
% }
% }
% }

airSimClient = AirSimClient(IsDrone=true, IP="127.0.0.1", port=41451);

airSimClient.setEnableApiControl("Drone1");
airSimClient.setEnableApiControl("Drone2");

airSimClient.setEnableDroneArm("Drone1");
airSimClient.setEnableDroneArm("Drone2");

airSimClient.takeoffAsync("Drone1", 20, true);
airSimClient.takeoffAsync("Drone2", 20, false);

airSimClient.moveToPositionAsync(10, 10, -5, 5, 3e+38, AirSimDrivetrainTypes.MaxDegreeOfFreedom, true, 0, -1, 1, "Drone1", true);
airSimClient.moveToPositionAsync(10, 14, -5, 5, 3e+38, AirSimDrivetrainTypes.MaxDegreeOfFreedom, true, 0, -1, 1, "Drone2", true);

airSimClient.landAsync("Drone1", 60, true);
airSimClient.landAsync("Drone2", 60, false);

airSimClient.setDisableDroneArm("Drone1");
airSimClient.setDisableDroneArm("Drone2");

airSimClient.setDisableApiControl("Drone1");
airSimClient.setDisableApiControl("Drone2");
Loading

0 comments on commit a930b71

Please sign in to comment.