Upgrading API Client Code#
There have been several API changes in AirSim v1.2 that we hope removes inconsistency, adds future extensibility and presents cleaner interface. Many of these changes are however breaking changes which means you will need to modify your client code that talks to AirSim.
from AirSimClient import *
Above assumes you have installed AirSim module using,
pip install --user airsim
If you are running you code from PythonClient folder in repo then you can also do this:
import setup_path import airsim
Here setup_path.py should exist in your folder and it will set the path of
airsim package in
PythonClient repo folder. All examples in PythonClient folder uses this method.
Using AirSim Classes#
As we have everything now in package, you will need to use explicit namespace for AirSim classes like shown below.
client1 = CarClient()
client1 = airsim.CarClient()
We have moved all types in
image_type = AirSimImageType.DepthVis d = DrivetrainType.MaxDegreeOfFreedom
image_type = airsim.ImageType.DepthVis d = airsim.DrivetrainType.MaxDegreeOfFreedom
Nothing new below, it's just combination of above. Note that all APIs that previously took
camera_id, now takes
camera_name instead. You can take a look at available cameras here.
responses = client.simGetImages([ImageRequest(0, AirSimImageType.DepthVis)])
responses = client.simGetImages([airsim.ImageRequest("0", airsim.ImageType.DepthVis)])
In earlier version, we provided several utility methods as part of
AirSimClientBase. These methods are now moved to
airsim namespace for more pythonic interface.
AirSimClientBase.write_png(my_path, img_rgba) AirSimClientBase.wait_key('Press any key')
airsim.write_png(my_path, img_rgba) airsim.wait_key('Press any key')
AirSim now uses names to reference cameras instead of index numbers. However to retain backward compatibility, these names are aliased with old index numbers as string.
client.simGetCameraInfo("0") # or client.simGetCameraInfo("front-center")
For multirotors, AirSim had various methods such as
moveByVelocityZ that would take long time to complete. All of such methods are now renamed by adding the suffix Async as shown below.
client.takeoff() client.moveToPosition(-10, 10, -10, 5)
client.takeoffAsync().join() client.moveToPositionAsync(-10, 10, -10, 5).join()
.join() is a call on Python's
Future class to wait for the async call to complete. You can also choose to do some other computation instead while the call is in progress.
Now we have clear distinction between methods that are only available in simulation from the ones that may be available on actual vehicle. The simulation only methods are prefixed with
sim as shown below.
getCollisionInfo() is renamed to simGetCollisionInfo() getCameraInfo() is renamed to simGetCameraInfo() setCameraOrientation() is renamed to simSetCameraOrientation()
CarState mixed simulation-only information like
kinematics_true. Moving forward,
CarState will only contain information that can be obtained in real world.
k = car_state.kinematics_true
k = car_state.kinematics_estimated # or k = client.simGetGroundTruthKinematics()