Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions AirLib/include/api/RpcLibClientBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ namespace airlib
Vector3r simGetObjectScale(const std::string& object_name) const;
bool simSetObjectPose(const std::string& object_name, const Pose& pose, bool teleport = true);
bool simSetObjectScale(const std::string& object_name, const Vector3r& scale);
std::string simSpawnObject(const std::string& object_name, const std::string& load_component, const Pose& pose,
const Vector3r& scale, bool physics_enabled);
bool simDestroyObject(const std::string& object_name);

//task management APIs
void cancelLastTask(const std::string& vehicle_name = "");
Expand Down Expand Up @@ -144,6 +147,8 @@ namespace airlib

std::string getSettingsString() const;

std::vector<std::string> simListAssets() const;

protected:
void* getClient();
const void* getClient() const;
Expand Down
1 change: 1 addition & 0 deletions AirLib/include/api/WorldSimApiBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace airlib
virtual bool loadLevel(const std::string& level_name) = 0;
virtual string spawnObject(const std::string& object_name, const std::string& load_component, const Pose& pose, const Vector3r& scale, bool physics_enabled, bool is_blueprint) = 0;
virtual bool destroyObject(const std::string& object_name) = 0;
virtual std::vector<std::string> listAssets() const = 0;

virtual bool isPaused() const = 0;
virtual void reset() = 0;
Expand Down
16 changes: 16 additions & 0 deletions AirLib/src/api/RpcLibClientBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,17 @@ __pragma(warning(disable : 4239))
return pimpl_->client.call("simLoadLevel", level_name).as<bool>();
}

std::string RpcLibClientBase::simSpawnObject(const std::string& object_name, const std::string& load_component, const Pose& pose,
const Vector3r& scale, bool physics_enabled)
{
return pimpl_->client.call("simSpawnObject", object_name, load_component, RpcLibAdaptorsBase::Pose(pose), RpcLibAdaptorsBase::Vector3r(scale), physics_enabled).as<std::string>();
}

bool RpcLibClientBase::simDestroyObject(const std::string& object_name)
{
return pimpl_->client.call("simDestroyObject", object_name).as<bool>();
}

msr::airlib::Vector3r RpcLibClientBase::simGetObjectScale(const std::string& object_name) const
{
return pimpl_->client.call("simGetObjectScale", object_name).as<RpcLibAdaptorsBase::Vector3r>().to();
Expand Down Expand Up @@ -543,6 +554,11 @@ __pragma(warning(disable : 4239))
return pimpl_->client.call("getSettingsString").as<std::string>();
}

std::vector<std::string> RpcLibClientBase::simListAssets() const
{
return pimpl_->client.call("simListAssets").as<std::vector<std::string>>();
}

void* RpcLibClientBase::getClient()
{
return &pimpl_->client;
Expand Down
4 changes: 4 additions & 0 deletions AirLib/src/api/RpcLibServerBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ namespace airlib
return getWorldSimApi()->destroyObject(object_name);
});

pimpl_->server.bind("simListAssets", [&]() -> std::vector<std::string> {
return getWorldSimApi()->listAssets();
});

pimpl_->server.bind("simGetObjectPose", [&](const std::string& object_name) -> RpcLibAdaptorsBase::Pose {
const auto& pose = getWorldSimApi()->getObjectPose(object_name);
return RpcLibAdaptorsBase::Pose(pose);
Expand Down
35 changes: 22 additions & 13 deletions PythonClient/airsim/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def simContinueForTime(self, seconds):
seconds (float): Time to run the simulation for
"""
self.client.call('simContinueForTime', seconds)

def simContinueForFrames(self, frames):
"""
Continue (or resume if paused) the simulation for the specified number of frames, after which the simulation will be paused.
Expand Down Expand Up @@ -305,7 +305,7 @@ def simGetImages(self, requests, vehicle_name = '', external = False):
"""
responses_raw = self.client.call('simGetImages', requests, vehicle_name, external)
return [ImageResponse.from_msgpack(response_raw) for response_raw in responses_raw]

def simTestLineOfSightToPoint(self, point, vehicle_name = ''):
"""
Returns whether the target point is visible from the perspective of the inputted vehicle
Expand All @@ -318,7 +318,7 @@ def simTestLineOfSightToPoint(self, point, vehicle_name = ''):
[bool]: Success
"""
return self.client.call('simTestLineOfSightToPoint', point, vehicle_name)

def simTestLineOfSightBetweenPoints(self, point1, point2):
"""
Returns whether the target point is visible from the perspective of the source point
Expand All @@ -331,7 +331,7 @@ def simTestLineOfSightBetweenPoints(self, point1, point2):
[bool]: Success
"""
return self.client.call('simTestLineOfSightBetweenPoints', point1, point2)

def simGetWorldExtents(self):
"""
Returns a list of GeoPoints representing the minimum and maximum extents of the world
Expand Down Expand Up @@ -483,7 +483,7 @@ def simListSceneObjects(self, name_regex = '.*'):
list[str]: List containing all the names
"""
return self.client.call('simListSceneObjects', name_regex)

def simLoadLevel(self, level_name):
"""
Loads a level specified by its name
Expand All @@ -496,28 +496,37 @@ def simLoadLevel(self, level_name):
"""
return self.client.call('simLoadLevel', level_name)

def simListAssets(self):
"""
Lists all the assets present in the Asset Registry

Returns:
list[str]: Names of all the assets
"""
return self.client.call('simListAssets')

def simSpawnObject(self, object_name, asset_name, pose, scale, physics_enabled=False, is_blueprint=False):
"""Spawned selected object in the world

Args:
object_name (str): Desired name of new object
asset_name (str): Name of asset(mesh) in the project database
pose (airsim.Pose): Desired pose of object
scale (airsim.Vector3r): Desired scale of object
physics_enabled (bool, optional): Whether to enable physics for the object
is_blueprint (bool, optional): Whether to spawn a blueprint or an actor

Returns:
str: Name of spawned object, in case it had to be modified
"""
return self.client.call('simSpawnObject', object_name, asset_name, pose, scale, physics_enabled, is_blueprint)

def simDestroyObject(self, object_name):
"""Removes selected object from the world

Args:
object_name (str): Name of object to be removed

Returns:
bool: True if object is queued up for removal
"""
Expand Down Expand Up @@ -567,7 +576,7 @@ def simAddDetectionFilterMeshName(self, camera_name, image_type, mesh_name, vehi

"""
self.client.call('simAddDetectionFilterMeshName', camera_name, image_type, mesh_name, vehicle_name, external)

def simSetDetectionFilterRadius(self, camera_name, image_type, radius_cm, vehicle_name = '', external = False):
"""
Set detection radius for all cameras
Expand All @@ -580,7 +589,7 @@ def simSetDetectionFilterRadius(self, camera_name, image_type, radius_cm, vehicl
external (bool, optional): Whether the camera is an External Camera
"""
self.client.call('simSetDetectionFilterRadius', camera_name, image_type, radius_cm, vehicle_name, external)

def simClearDetectionMeshNames(self, camera_name, image_type, vehicle_name = '', external = False):
"""
Clear all mesh names from detection filter
Expand Down Expand Up @@ -654,7 +663,7 @@ def simGetDistortionParams(self, camera_name, vehicle_name = '', external = Fals
Returns:
List (float): List of distortion parameter values corresponding to K1, K2, K3, P1, P2 respectively.
"""

return self.client.call('simGetDistortionParams', str(camera_name), vehicle_name, external)

def simSetDistortionParams(self, camera_name, distortion_params, vehicle_name = '', external = False):
Expand Down Expand Up @@ -975,7 +984,7 @@ def simSetWind(self, wind):
Set simulated wind, in World frame, NED direction, m/s

Args:
wind (Vector3r): Wind, in World frame, NED direction, in m/s
wind (Vector3r): Wind, in World frame, NED direction, in m/s
"""
self.client.call('simSetWind', wind)

Expand Down
32 changes: 32 additions & 0 deletions PythonClient/environment/create_objects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import setup_path
import airsim
import random
import time

client = airsim.VehicleClient()
client.confirmConnection()

assets = client.simListAssets()
print(f"Assets: {assets}")

scale = airsim.Vector3r(1.0, 1.0, 1.0)

# asset_name = random.choice(assets)
asset_name = '1M_Cube_Chamfer'

desired_name = f"{asset_name}_spawn_{random.randint(0, 100)}"
pose = airsim.Pose(position_val=airsim.Vector3r(5.0, 0.0, 0.0))

obj_name = client.simSpawnObject(desired_name, asset_name, pose, scale, True)

print(f"Created object {obj_name} from asset {asset_name} "
f"at pose {pose}, scale {scale}")

all_objects = client.simListSceneObjects()
if obj_name not in all_objects:
print(f"Object {obj_name} not present!")

time.sleep(10.0)

print(f"Destroying {obj_name}")
client.simDestroyObject(obj_name)
8 changes: 8 additions & 0 deletions Unity/AirLibWrapper/AirsimWrapper/Source/WorldSimApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,12 @@ std::vector<msr::airlib::DetectionInfo> WorldSimApi::getDetections(ImageCaptureB
return std::vector<msr::airlib::DetectionInfo>();
}

std::vector<std::string> WorldSimApi::listAssets() const
{
throw std::invalid_argument(common_utils::Utils::stringf(
"listAssets API is not supported on Unity")
.c_str());
return {};
}

#pragma endregion
1 change: 1 addition & 0 deletions Unity/AirLibWrapper/AirsimWrapper/Source/WorldSimApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class WorldSimApi : public msr::airlib::WorldSimApiBase
virtual bool loadLevel(const std::string& level_name) override { return false; };
virtual std::string spawnObject(const std::string& object_name, const std::string& load_component, const Pose& pose, const Vector3r& scale, bool physics_enabled, bool is_blueprint) override { return ""; };
virtual bool destroyObject(const std::string& object_name) override { return false; };
virtual std::vector<std::string> listAssets() const override;

virtual bool isPaused() const override;
virtual void reset() override;
Expand Down
2 changes: 1 addition & 1 deletion Unreal/Plugins/AirSim/Source/AirBlueprintLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ void UAirBlueprintLib::GenerateAssetRegistryMap(const UObject* context, TMap<FSt
AssetRegistryModule.Get().GetAssets(Filter, AssetData);

UObject* LoadObject = NULL;
for (auto asset : AssetData) {
for (const auto& asset : AssetData) {
FString asset_name = asset.AssetName.ToString();
asset_map.Add(asset_name, asset);
}
Expand Down
11 changes: 11 additions & 0 deletions Unreal/Plugins/AirSim/Source/WorldSimApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ bool WorldSimApi::destroyObject(const std::string& object_name)
return result;
}

std::vector<std::string> WorldSimApi::listAssets() const
{
std::vector<std::string> all_assets;

for (const TPair<FString, FAssetData>& pair : simmode_->asset_map) {
all_assets.push_back(std::string(TCHAR_TO_UTF8(*pair.Key)));
}

return all_assets;
}

std::string WorldSimApi::spawnObject(const std::string& object_name, const std::string& load_object, const WorldSimApi::Pose& pose, const WorldSimApi::Vector3r& scale, bool physics_enabled, bool is_blueprint)
{
FString asset_name(load_object.c_str());
Expand Down
1 change: 1 addition & 0 deletions Unreal/Plugins/AirSim/Source/WorldSimApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class WorldSimApi : public msr::airlib::WorldSimApiBase

virtual std::string spawnObject(const std::string& object_name, const std::string& load_name, const WorldSimApi::Pose& pose, const WorldSimApi::Vector3r& scale, bool physics_enabled, bool is_blueprint) override;
virtual bool destroyObject(const std::string& object_name) override;
virtual std::vector<std::string> listAssets() const override;

virtual bool isPaused() const override;
virtual void reset() override;
Expand Down