|
| 1 | +# AirSim Code Tour |
| 2 | + |
| 3 | +This file is a quick orientation guide for this checkout of AirSim. It focuses on where the main subsystems live, how API calls move through the stack, and which files usually need to change for common work. |
| 4 | + |
| 5 | +## High-Level Shape |
| 6 | + |
| 7 | +AirSim is split into a platform-independent C++ core and simulator-specific front ends. |
| 8 | + |
| 9 | +1. Client code calls the RPC API from Python, C++, C#, or another msgpack-rpc client. |
| 10 | +2. `AirLib` receives and models API calls, vehicles, sensors, physics, settings, and data structures. |
| 11 | +3. `Unreal/Plugins/AirSim` adapts the core to Unreal Engine actors, pawns, cameras, rendering, weather, and world objects. |
| 12 | +4. Vehicle-specific implementations connect the shared API surface to multirotors, cars, Computer Vision mode, PX4, ArduPilot, or SimpleFlight. |
| 13 | + |
| 14 | +The docs that already cover the official architecture are: |
| 15 | + |
| 16 | +- `docs/code_structure.md` |
| 17 | +- `docs/design.md` |
| 18 | +- `docs/dev_workflow.md` |
| 19 | +- `docs/adding_new_apis.md` |
| 20 | + |
| 21 | +## Repository Map |
| 22 | + |
| 23 | +| Path | Purpose | |
| 24 | +| --- | --- | |
| 25 | +| `AirLib/` | Platform-independent C++ library: APIs, physics, sensors, settings, safety, vehicles, RPC client/server code. | |
| 26 | +| `Unreal/Plugins/AirSim/` | Unreal Engine plugin implementation: sim modes, pawns, cameras, rendering, sensors, recording, weather, object control. | |
| 27 | +| `PythonClient/` | Python package and sample scripts for AirSim RPC APIs. Main client binding is `PythonClient/airsim/client.py`. | |
| 28 | +| `MavLinkCom/` | Standalone MAVLink communication library used by PX4 and ArduPilot integrations. | |
| 29 | +| `HelloDrone/`, `HelloCar/`, `DroneShell/`, `DroneServer/` | Native sample and utility programs. | |
| 30 | +| `ros/`, `ros2/` | ROS integration packages and wrappers. | |
| 31 | +| `Unity/` | Experimental Unity integration. | |
| 32 | +| `docs/` | MkDocs documentation source. Navigation is configured by `mkdocs.yml`. | |
| 33 | +| `AirLibUnitTests/` | Native unit test project for core AirLib behavior. | |
| 34 | +| `azure/`, `docker/`, `pipelines/` | Cloud, container, and CI support. | |
| 35 | + |
| 36 | +## Core AirLib Areas |
| 37 | + |
| 38 | +`AirLib` is the C++ core that should remain independent of Unreal-specific classes. |
| 39 | + |
| 40 | +- API base classes: `AirLib/include/api/` |
| 41 | +- RPC server/client implementation: `AirLib/src/api/RpcLibServerBase.cpp`, `AirLib/src/api/RpcLibClientBase.cpp` |
| 42 | +- RPC adaptors and shared structs: `AirLib/include/api/RpcLibAdaptorsBase.hpp`, `AirLib/include/common/CommonStructs.hpp` |
| 43 | +- Settings parsing: `AirLib/include/common/AirSimSettings.hpp` |
| 44 | +- Physics: `AirLib/include/physics/` |
| 45 | +- Sensors: `AirLib/include/sensors/` |
| 46 | +- Multirotor models and APIs: `AirLib/include/vehicles/multirotor/`, `AirLib/src/vehicles/multirotor/` |
| 47 | +- Car APIs and firmware adapters: `AirLib/include/vehicles/car/`, `AirLib/src/vehicles/car/` |
| 48 | +- Safety and geofence logic: `AirLib/include/safety/`, `AirLib/src/safety/` |
| 49 | + |
| 50 | +When adding fields to `settings.json`, start at `AirLib/include/common/AirSimSettings.hpp`. |
| 51 | + |
| 52 | +## Unreal Plugin Areas |
| 53 | + |
| 54 | +`Unreal/Plugins/AirSim/Source` is the Unreal-facing layer. |
| 55 | + |
| 56 | +- Plugin module and game mode: `AirSim.cpp`, `AirSim.h`, `AirSimGameMode.cpp` |
| 57 | +- Base sim-mode lifecycle: `SimMode/SimModeBase.*`, `SimMode/SimModeWorldBase.*` |
| 58 | +- Vehicle modes: |
| 59 | + - Multirotor: `Vehicles/Multirotor/` |
| 60 | + - Car: `Vehicles/Car/` |
| 61 | + - Computer Vision mode: `Vehicles/ComputerVision/` |
| 62 | +- Environment and world APIs: `WorldSimApi.*` |
| 63 | +- Camera and image capture: `PIPCamera.*`, `UnrealImageCapture.*`, `RenderRequest.*` |
| 64 | +- Sensor adapters backed by Unreal scene data: `UnrealSensors/` |
| 65 | +- Recording: `Recording/` |
| 66 | +- Weather: `Weather/` |
| 67 | +- Common Unreal helpers: `AirBlueprintLib.*`, `NedTransform.*` |
| 68 | + |
| 69 | +Most environment-only APIs eventually land in `WorldSimApi.cpp`. Most camera behavior eventually lands in `PIPCamera.cpp`, `UnrealImageCapture.cpp`, or `RenderRequest.cpp`. |
| 70 | + |
| 71 | +## RPC Call Flow |
| 72 | + |
| 73 | +For a typical Python API call: |
| 74 | + |
| 75 | +1. `PythonClient/airsim/client.py` exposes a method and calls `self.client.call(...)`. |
| 76 | +2. `AirLib/src/api/RpcLibServerBase.cpp` binds that RPC method name to a C++ lambda. |
| 77 | +3. The lambda delegates to a vehicle API or `WorldSimApiBase`. |
| 78 | +4. Unreal implementations in `Unreal/Plugins/AirSim/Source` perform the simulator work. |
| 79 | +5. Result structs are converted through RPC adaptor types, then returned to the client. |
| 80 | + |
| 81 | +For C++ clients, the public methods are declared in `AirLib/include/api/RpcLibClientBase.hpp` and implemented in `AirLib/src/api/RpcLibClientBase.cpp`. |
| 82 | + |
| 83 | +Vehicle-specific RPC surfaces extend this pattern: |
| 84 | + |
| 85 | +- Multirotor RPC: `AirLib/include/vehicles/multirotor/api/`, `AirLib/src/vehicles/multirotor/api/` |
| 86 | +- Car RPC: `AirLib/include/vehicles/car/api/`, `AirLib/src/vehicles/car/api/` |
| 87 | + |
| 88 | +## Adding or Changing an API |
| 89 | + |
| 90 | +Use `docs/adding_new_apis.md` for the full upstream checklist. The usual file set is: |
| 91 | + |
| 92 | +1. Implement core behavior in the relevant AirLib or Unreal class. |
| 93 | +2. Add or update an abstract method if the call belongs on `WorldSimApiBase` or a vehicle API base. |
| 94 | +3. Bind the RPC method in `RpcLibServerBase.cpp` or the vehicle-specific RPC server. |
| 95 | +4. Add the C++ client wrapper in `RpcLibClientBase.hpp` and `RpcLibClientBase.cpp`. |
| 96 | +5. Add Python bindings in `PythonClient/airsim/client.py`. |
| 97 | +6. Add or update msgpack adaptor structs if the API returns a new structured type. |
| 98 | +7. Add docs and an example script when the API is user-facing. |
| 99 | + |
| 100 | +If the API is vehicle-control-specific, check the multirotor or car API base classes first. If it changes the scene, cameras, weather, objects, textures, or levels, check `WorldSimApi.*` first. |
| 101 | + |
| 102 | +## CinemAirSim Notes |
| 103 | + |
| 104 | +This checkout includes CinemAirSim camera extensions marked with `//CinemAirSim`. |
| 105 | + |
| 106 | +Important files: |
| 107 | + |
| 108 | +- `Unreal/Plugins/AirSim/Source/PIPCamera.h` |
| 109 | +- `Unreal/Plugins/AirSim/Source/PIPCamera.cpp` |
| 110 | +- `Unreal/Plugins/AirSim/Source/WorldSimApi.h` |
| 111 | +- `Unreal/Plugins/AirSim/Source/WorldSimApi.cpp` |
| 112 | +- `AirLib/include/api/WorldSimApiBase.hpp` |
| 113 | +- `AirLib/include/api/RpcLibClientBase.hpp` |
| 114 | +- `AirLib/src/api/RpcLibClientBase.cpp` |
| 115 | +- `AirLib/src/api/RpcLibServerBase.cpp` |
| 116 | +- `PythonClient/airsim/client.py` |
| 117 | + |
| 118 | +The main change is that `APIPCamera` derives from `ACineCameraActor` and uses `UCineCameraComponent` for lens, filmback, focal length, manual focus, focus distance, aperture, focus plane, and current field-of-view controls. If you touch these APIs, keep the declarations, RPC binding names, C++ client methods, Unreal implementation, and Python wrapper in sync. |
| 119 | + |
| 120 | +## Build and Local Workflow |
| 121 | + |
| 122 | +Windows is the most mature development path for this Unreal-based repo. |
| 123 | + |
| 124 | +- Build AirSim plugin from the repo root: `build.cmd` |
| 125 | +- Linux build path: `setup.sh`, then `build.sh` |
| 126 | +- Clean/rebuild helpers: `clean.cmd`, `clean_rebuild.bat`, `clean.sh`, `clean_rebuild.sh` |
| 127 | +- Documentation build helpers: `build_docs.bat`, `build_docs.sh` |
| 128 | + |
| 129 | +For Unreal plugin development, the documented workflow is: |
| 130 | + |
| 131 | +1. Build the plugin from the AirSim repo root. |
| 132 | +2. Deploy `Unreal/Plugins` into an Unreal environment such as Blocks. |
| 133 | +3. Regenerate project files for the Unreal project. |
| 134 | +4. Build and run from Visual Studio. |
| 135 | + |
| 136 | +See `docs/dev_workflow.md` and `docs/unreal_blocks.md` for details. |
| 137 | + |
| 138 | +## Testing Touchpoints |
| 139 | + |
| 140 | +- Native core tests: `AirLibUnitTests/` |
| 141 | +- Python smoke examples: |
| 142 | + - `PythonClient/multirotor/hello_drone.py` |
| 143 | + - `PythonClient/car/hello_car.py` |
| 144 | + - `PythonClient/computer_vision/cv_mode.py` |
| 145 | +- Camera/image API examples: |
| 146 | + - `PythonClient/computer_vision/external_camera.py` |
| 147 | + - `PythonClient/computer_vision/fov_change.py` |
| 148 | + - `PythonClient/multirotor/gimbal.py` |
| 149 | + |
| 150 | +When testing Python changes from source, scripts usually import local package paths through `setup_path.py` so they use the checkout version instead of an installed PyPI package. |
| 151 | + |
| 152 | +## Good Starting Points |
| 153 | + |
| 154 | +- Understanding settings: `AirLib/include/common/AirSimSettings.hpp` |
| 155 | +- Understanding world APIs: `AirLib/include/api/WorldSimApiBase.hpp`, `Unreal/Plugins/AirSim/Source/WorldSimApi.cpp` |
| 156 | +- Understanding RPC exposure: `AirLib/src/api/RpcLibServerBase.cpp` |
| 157 | +- Understanding client wrappers: `AirLib/src/api/RpcLibClientBase.cpp`, `PythonClient/airsim/client.py` |
| 158 | +- Understanding cameras: `Unreal/Plugins/AirSim/Source/PIPCamera.cpp`, `Unreal/Plugins/AirSim/Source/UnrealImageCapture.cpp` |
| 159 | +- Understanding simulation modes: `Unreal/Plugins/AirSim/Source/SimMode/` |
| 160 | +- Understanding multirotor behavior: `AirLib/include/vehicles/multirotor/`, `Unreal/Plugins/AirSim/Source/Vehicles/Multirotor/` |
| 161 | +- Understanding car behavior: `AirLib/include/vehicles/car/`, `Unreal/Plugins/AirSim/Source/Vehicles/Car/` |
0 commit comments