Skip to content

Commit e2d321d

Browse files
committed
updated client.py
1 parent eb4ee74 commit e2d321d

File tree

1 file changed

+89
-18
lines changed

1 file changed

+89
-18
lines changed

PythonClient/airsim/client.py

Lines changed: 89 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def simContinueForTime(self, seconds):
110110
seconds (float): Time to run the simulation for
111111
"""
112112
self.client.call('simContinueForTime', seconds)
113-
113+
114114
def simContinueForFrames(self, frames):
115115
"""
116116
Continue (or resume if paused) the simulation for the specified number of frames, after which the simulation will be paused.
@@ -158,6 +158,19 @@ def confirmConnection(self):
158158
print(ver_info)
159159
print('')
160160

161+
def simSetLightIntensity(self, light_name, intensity):
162+
"""
163+
Change intensity of named light
164+
165+
Args:
166+
light_name (str): Name of light to change
167+
intensity (float): New intensity value
168+
169+
Returns:
170+
bool: True if successful, otherwise False
171+
"""
172+
return self.client.call("simSetLightIntensity", light_name, intensity)
173+
161174
def simSwapTextures(self, tags, tex_id = 0, component_id = 0, material_id = 0):
162175
"""
163176
Runtime Swap Texture API
@@ -178,6 +191,35 @@ def simSwapTextures(self, tags, tex_id = 0, component_id = 0, material_id = 0):
178191
return self.client.call("simSwapTextures", tags, tex_id, component_id, material_id)
179192

180193
#time - of - day control
194+
def simSetObjectMaterial(self, object_name, material_name):
195+
"""
196+
Runtime Swap Texture API
197+
See https://microsoft.github.io/AirSim/retexturing/ for details
198+
Args:
199+
object_name (str): name of object to set material for
200+
material_name (str): name of material to set for object
201+
202+
Returns:
203+
bool: True if material was set
204+
"""
205+
return self.client.call("simSetObjectMaterial", object_name, material_name)
206+
207+
def simSetObjectMaterialFromTexture(self, object_name, texture_path):
208+
"""
209+
Runtime Swap Texture API
210+
See https://microsoft.github.io/AirSim/retexturing/ for details
211+
Args:
212+
object_name (str): name of object to set material for
213+
texture_path (str): path to texture to set for object
214+
215+
Returns:
216+
bool: True if material was set
217+
"""
218+
return self.client.call("simSetObjectMaterialFromTexture", object_name, texture_path)
219+
220+
221+
# time-of-day control
222+
181223
def simSetTimeOfDay(self, is_enabled, start_datetime = "", is_start_datetime_dst = False, celestial_clock_speed = 1, update_interval_secs = 60, move_sun = True):
182224
"""
183225
Control the position of Sun in the environment
@@ -333,6 +375,7 @@ def simGetCurrentFieldOfView(self, camera_name, vehicle_name = '', external = Fa
333375
return result
334376

335377
#End CinemAirSim
378+
336379
def simTestLineOfSightToPoint(self, point, vehicle_name = ''):
337380
"""
338381
Returns whether the target point is visible from the perspective of the inputted vehicle
@@ -345,7 +388,7 @@ def simTestLineOfSightToPoint(self, point, vehicle_name = ''):
345388
[bool]: Success
346389
"""
347390
return self.client.call('simTestLineOfSightToPoint', point, vehicle_name)
348-
391+
349392
def simTestLineOfSightBetweenPoints(self, point1, point2):
350393
"""
351394
Returns whether the target point is visible from the perspective of the source point
@@ -358,7 +401,7 @@ def simTestLineOfSightBetweenPoints(self, point1, point2):
358401
[bool]: Success
359402
"""
360403
return self.client.call('simTestLineOfSightBetweenPoints', point1, point2)
361-
404+
362405
def simGetWorldExtents(self):
363406
"""
364407
Returns a list of GeoPoints representing the minimum and maximum extents of the world
@@ -510,7 +553,7 @@ def simListSceneObjects(self, name_regex = '.*'):
510553
list[str]: List containing all the names
511554
"""
512555
return self.client.call('simListSceneObjects', name_regex)
513-
556+
514557
def simLoadLevel(self, level_name):
515558
"""
516559
Loads a level specified by its name
@@ -523,26 +566,37 @@ def simLoadLevel(self, level_name):
523566
"""
524567
return self.client.call('simLoadLevel', level_name)
525568

526-
def simSpawnObject(self, object_name, asset_name, pose, scale, physics_enabled=False):
569+
def simListAssets(self):
570+
"""
571+
Lists all the assets present in the Asset Registry
572+
573+
Returns:
574+
list[str]: Names of all the assets
575+
"""
576+
return self.client.call('simListAssets')
577+
578+
def simSpawnObject(self, object_name, asset_name, pose, scale, physics_enabled=False, is_blueprint=False):
527579
"""Spawned selected object in the world
528-
580+
529581
Args:
530582
object_name (str): Desired name of new object
531583
asset_name (str): Name of asset(mesh) in the project database
532584
pose (airsim.Pose): Desired pose of object
533585
scale (airsim.Vector3r): Desired scale of object
534-
586+
physics_enabled (bool, optional): Whether to enable physics for the object
587+
is_blueprint (bool, optional): Whether to spawn a blueprint or an actor
588+
535589
Returns:
536590
str: Name of spawned object, in case it had to be modified
537591
"""
538-
return self.client.call('simSpawnObject', object_name, asset_name, pose, scale, physics_enabled)
592+
return self.client.call('simSpawnObject', object_name, asset_name, pose, scale, physics_enabled, is_blueprint)
539593

540594
def simDestroyObject(self, object_name):
541595
"""Removes selected object from the world
542-
596+
543597
Args:
544598
object_name (str): Name of object to be removed
545-
599+
546600
Returns:
547601
bool: True if object is queued up for removal
548602
"""
@@ -592,7 +646,7 @@ def simAddDetectionFilterMeshName(self, camera_name, image_type, mesh_name, vehi
592646
593647
"""
594648
self.client.call('simAddDetectionFilterMeshName', camera_name, image_type, mesh_name, vehicle_name, external)
595-
649+
596650
def simSetDetectionFilterRadius(self, camera_name, image_type, radius_cm, vehicle_name = '', external = False):
597651
"""
598652
Set detection radius for all cameras
@@ -605,7 +659,7 @@ def simSetDetectionFilterRadius(self, camera_name, image_type, radius_cm, vehicl
605659
external (bool, optional): Whether the camera is an External Camera
606660
"""
607661
self.client.call('simSetDetectionFilterRadius', camera_name, image_type, radius_cm, vehicle_name, external)
608-
662+
609663
def simClearDetectionMeshNames(self, camera_name, image_type, vehicle_name = '', external = False):
610664
"""
611665
Clear all mesh names from detection filter
@@ -679,7 +733,7 @@ def simGetDistortionParams(self, camera_name, vehicle_name = '', external = Fals
679733
Returns:
680734
List (float): List of distortion parameter values corresponding to K1, K2, K3, P1, P2 respectively.
681735
"""
682-
736+
683737
return self.client.call('simGetDistortionParams', str(camera_name), vehicle_name, external)
684738

685739
def simSetDistortionParams(self, camera_name, distortion_params, vehicle_name = '', external = False):
@@ -750,6 +804,19 @@ def simGetGroundTruthKinematics(self, vehicle_name = ''):
750804
return KinematicsState.from_msgpack(kinematics_state)
751805
simGetGroundTruthKinematics.__annotations__ = {'return': KinematicsState}
752806

807+
def simSetKinematics(self, state, ignore_collision, vehicle_name = ''):
808+
"""
809+
Set the kinematics state of the vehicle
810+
811+
If you don't want to change position (or orientation) then just set components of position (or orientation) to floating point nan values
812+
813+
Args:
814+
state (KinematicsState): Desired Pose pf the vehicle
815+
ignore_collision (bool): Whether to ignore any collision or not
816+
vehicle_name (str, optional): Name of the vehicle to move
817+
"""
818+
self.client.call('simSetKinematics', state, ignore_collision, vehicle_name)
819+
753820
def simGetGroundTruthEnvironment(self, vehicle_name = ''):
754821
"""
755822
Get ground truth environment state
@@ -988,7 +1055,7 @@ def simSetWind(self, wind):
9881055
Set simulated wind, in World frame, NED direction, m/s
9891056
9901057
Args:
991-
wind (Vector3r): Wind, in World frame, NED direction, in m/s
1058+
wind (Vector3r): Wind, in World frame, NED direction, in m/s
9921059
"""
9931060
self.client.call('simSetWind', wind)
9941061

@@ -1152,6 +1219,10 @@ def moveToPositionAsync(self, x, y, z, velocity, timeout_sec = 3e+38, drivetrain
11521219
lookahead = -1, adaptive_lookahead = 1, vehicle_name = ''):
11531220
return self.client.call_async('moveToPosition', x, y, z, velocity, timeout_sec, drivetrain, yaw_mode, lookahead, adaptive_lookahead, vehicle_name)
11541221

1222+
def moveToGPSAsync(self, latitude, longitude, altitude, velocity, timeout_sec = 3e+38, drivetrain = DrivetrainType.MaxDegreeOfFreedom, yaw_mode = YawMode(),
1223+
lookahead = -1, adaptive_lookahead = 1, vehicle_name = ''):
1224+
return self.client.call_async('moveToGPS', latitude, longitude, altitude, velocity, timeout_sec, drivetrain, yaw_mode, lookahead, adaptive_lookahead, vehicle_name)
1225+
11551226
def moveToZAsync(self, z, velocity, timeout_sec = 3e+38, yaw_mode = YawMode(), lookahead = -1, adaptive_lookahead = 1, vehicle_name = ''):
11561227
return self.client.call_async('moveToZ', z, velocity, timeout_sec, yaw_mode, lookahead, adaptive_lookahead, vehicle_name)
11571228

@@ -1243,7 +1314,7 @@ def moveByRollPitchYawZAsync(self, roll, pitch, yaw, z, duration, vehicle_name =
12431314
def moveByRollPitchYawThrottleAsync(self, roll, pitch, yaw, throttle, duration, vehicle_name = ''):
12441315
"""
12451316
- Desired throttle is between 0.0 to 1.0
1246-
- Roll angle, pitch angle, and yaw angle are given in **radians**, in the body frame.
1317+
- Roll angle, pitch angle, and yaw angle are given in **degrees** when using PX4 and in **radians** when using SimpleFlight, in the body frame.
12471318
- The body frame follows the Front Left Up (FLU) convention, and right-handedness.
12481319
12491320
- Frame Convention:
@@ -1263,9 +1334,9 @@ def moveByRollPitchYawThrottleAsync(self, roll, pitch, yaw, throttle, duration,
12631334
| Hence, yawing with a positive angle is equivalent to rotated towards the **left** direction wrt our FLU body frame. Or in an anticlockwise fashion in the body XY / FL plane.
12641335
12651336
Args:
1266-
roll (float): Desired roll angle, in radians.
1267-
pitch (float): Desired pitch angle, in radians.
1268-
yaw (float): Desired yaw angle, in radians.
1337+
roll (float): Desired roll angle.
1338+
pitch (float): Desired pitch angle.
1339+
yaw (float): Desired yaw angle.
12691340
throttle (float): Desired throttle (between 0.0 to 1.0)
12701341
duration (float): Desired amount of time (seconds), to send this command for
12711342
vehicle_name (str, optional): Name of the multirotor to send this command to

0 commit comments

Comments
 (0)