In the last issue, we took you to understand some common API interfaces for Airsim, as well as using some simple API interfaces to simulate control models. Next we will bring some introduction to the API interfaces used in the world (map) interface, APIs for getting the state of the model system, and how to add new APIs.

First, the map interface related API 1.1 line of sight and world-wide API to test the simulation from the vehicle to a point or between the line of sight, please refer to the simTestLineOfSightToPoint (point, Vehicle_name) and simTestLineOfSightBetweenPoints (point1, point2) these two APIs, are simulated worldwide, to two The form of geoPoints vectors can be retrieved using simGetWorldExtents().
1.2 Weather API Disables all weather effects by default. To enable weather effects, first call: simEnableWeather(True) can enable various weather effects WeatherParameter using the following simSetWeatherParameter method, for example: client.simSetWeatherParameter (airsim. WeatherParameter.Rain, 0.25); The second parameter values are from 0 to 1. The first parameter provides the following options:
class WeatherParameter: Rain = 0 Roadwetness = 1 Snow = 2 RoadSnow = 3 MapleLeaf = 4 RoadLeaf = 5 Dust = 6 Fog = 7
For more details, see Sample Code: https://github.com/Microsoft/AirSim/blob/master/PythonClient/environment/weather.py
1.3 Recording API Recording API can record data through the control API interface, and data that needs to be recorded can be formulated through settings. To start recording, enter: client.startRecording() Similarly, to stop recording, use: client.stopRecording() To check if the Recording is running, call: client.isRecording()
This API works with the use of the R button (which toggles the recording state), and if recording is enabled with the R key, isRecording()] will return True and can use stopRecording(). Similarly, if you press the R key in the viewport, recordings started using the API stop. Using the API to start or stop logging, LogMessage also appears in the upper-left corner of the viewport.
1.4 Wind API API: [simSetWind()] This API can change the state of wind during simulation. Winds in the World Framework, NED direction, and wind speed can all be formulated using this API, for example to set a wind of 20,m/s in the north (i.e. forward) direction:
#Set wind to (20,0,0) in NED (forward direction)wind = airsim. Vector3r(20, 0, 0)client.simSetWind(wind)
For more related messages, see Instance: https://github.com/Microsoft/AirSim/blob/master/PythonClient/multirotor/set_wind.py
1.5 LiDAR APIAirSim provides an API to retrieve point cloud data from lidar sensors on a vehicle. You can set parameters such as the number of channels, points per second, horizontal and vertical FOVs in settings.json. For more information on the LiDAR API and settings and sensor settings, please refer to the following URL:
LiDAR API Settings: https://microsoft.github.io/AirSim/lidar/
Sensor Settings: https://microsoft.github.io/AirSim/sensors/
1.6 Coordinate System All AirSim APIs use the NED coordinate system, i.e. +X is north, +Y is east, and +Z is down. All units use the SI system. Note that this is different from the coordinate system used inside Unreal Engine. In Unreal Engine, +Z is up instead of down, and the unit of length is centimeters instead of meters.
The AirSim API takes care of the appropriate conversions. The starting point of the vehicle is always the coordinates in the NED system (0, 0, 0). So, when converting from Unreal coordinates to NED, we first subtract the starting offset and then scale 100 to convert cm to m. Vehicles are generated in the virtual engine using the Player Start component. There is a setting in settings.json called OriginGeopoint, which assigns geo-longitude, longitude, and height specifically for the Player Start component.
API 2.1 automotive API for controller model
Car has the following APIs available:
setCarControls: This allows you to set the throttle, steering, handbrake, and automatic or manual gears.
getCarState: This retrieves state information, including velocity, current gear, and 6 kinematic quantities: position, direction, linear velocity and angular velocity, linear velocity, and angular acceleration. All quantities are in the NED coordinate system, and the SI units in the world coordinate system are in the body coordinate system except for angular velocity and acceleration.
Image API (refer to the previous issue)
2.2 Multi-rotor API Multi-rotors can be controlled by specifying an angle, velocity vector, target position, or some combination of these. move* has a corresponding API correspondence for this purpose. When doing position control, we need to use some path following algorithms. By default, AirSim uses the carrot following algorithm. "Advanced Control" – only need to specify the advanced target, the rest is handled by the firmware. The lowest level of control currently available in AirSim is moveByAngleThrottleAsyncAPI.
** 2.3 Get multi-rotor status ** The API that gets multi-rotor status only requires one call to return multi-rotor status. States here include: collision, estimated kinematics (i.e., kinematics computed by fusion sensors), and timestamps (nanoseconds since epoch). The kinematics here corresponds to 6 elements: position, direction, linear velocity and angular velocity, linear velocity and angular acceleration. All quantities are in the NED coordinate system, and the SI units of the coordinate system in the world map, except for angular velocity and acceleration, are in the body coordinate system.
2.4 Asynchronous Methods, Duration, and max_wait_seconds Parameters Many APIs have parameters named the suffix "Async"; for example, the TakeoffAsync API. These parameters indicate that the task is returned immediately after the task is started in AirSim so that the code can perform other actions while the task is executed. If you want to wait for this task to complete, you can call [waitOnLastTask], for example:
//C++client.takeoffAsync()->waitOnLastTask();
#Pythonclient.takeoffAsync().join()
If you start another command, the previous task is automatically canceled and a new command is started. Each newly released track cancels the previous track, allowing the code to be constantly updated as new sensor data arrives.
2.5 Drivetrain
API: [drivetrain] Flight loader has two modes, selected by parameter settings: irsim. DrivetrainType.ForwardOnly or airsim.DrivetrainType.MaxDegreeOfFreedom.
(1) When you specify ForwardOnly, the front of the vehicle should always point to the direction of travel. So if you want the drone to turn left, then it will rotate first, so the front points to the left. This mode is useful when you have only a front camera and are using the FPV view to operate the vehicle.
(2) MaxDegreeOfFreedom means you don't need to care about where you're pointing ahead. So when you turn left, so the multi-rotor drone can go in any direction and the perspective doesn't get affected.
2.6 Yaw mode (yaw_mode) yaw_mode is a struct with two fields, yaw_or_rate and is_rate. If is_ratefield is True, the yaw_or_ratefield is the angular velocity in degrees per second at which the model rotates continuously around its axis as it moves. If the is_rate is False, the yaw_or_rate is the angle in degrees, at which point the model rotates to a specific angle (that is, yawing) and maintains that angle as it moves.
2.7 Lookahead and adaptive_lookahead AirSim uses the "carrot following" algorithm when setting up a follow path. The algorithm runs by looking forward at the path and adjusting its velocity vector. The parameters of the algorithm are adaptive_lookahead by the lookahead and the specified.
Third, adding a new API interface To add a new API, you need to modify the source code. The various levels of abstraction supported by AirSim require a lot of changes. The main files that need to be modified are described below. Also, if you're not sure how to make changes or get feedback, don't hesitate to open the question or draft PR.
3.1 Implementing apis Before adding calls and processing APIs, you need to implement the added API. Here are a few examples:
(1) The vehicle-based API [moveByVelocityBodyFrameAsync] API is used for speed-based motion adjustment in multi-rotor XY coordinate systems.
In some cases, additional structures may be required to store data, and the GetRotorStates API is a good example, where The RotorStates defines structures in 2 places, primarily for conversion from RPC to internal code. But it also needs to be modified in AirLib and Unreal/Plugins to implement it.
(2) Environment-related APIs
These environment-related APIs need to interact with the simulated environment itself, usually implemented in the Unreal/Plugins folder, such as:
【simCreateVoxelGrid】Api is mainly used to generate and save environment grids in binvox format - WorldSimApi .cpp
The simAddVehicle API is used to create vehicles at runtime - SimMode*, WorldSimApi files
For more information on Airsim's creation of new API interfaces, please refer to the https://microsoft.github.io/AirSim/adding_new_apis/
Conclusion This issue of all the APIs about AirSim ends here. As a computer-side deep learning, computer vision and reinforcement learning algorithm that can be implemented, with high-performance, real-world virtual world map simulation, the AirSim research platform is indeed promising. The API interface provided is also the key to the wide application of Airsim, so the introduction of API interfaces in these two issues is also crucial, and students who hope to pay attention to Airsim can carefully look at the article or the official website.
Official Information This issue of PX4 Update Content URL: https://microsoft.github.io/AirSim/apis/
End - With the rapid development of technology, Amu Laboratory will keep up with the pace of technology and continue to recommend the latest technology and hardware in the robot industry to everyone. Seeing our trainees make great strides in technology is the greatest value of our training. If you are in the robot industry, please pay attention to our public account, we will continue to publish the most valuable information and technology in the robot industry. Amu Lab is committed to cutting-edge IT technology education and intelligent equipment, making robot research and development more efficient!