Skip to content

Commit b059807

Browse files
committed
JSBSim initial commit
1 parent 4e4aa41 commit b059807

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2590
-689
lines changed

CMakeLists.txt

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ if (UNIX)
3333
link_directories("$ENV{UE_ROOT}/Engine/Source/ThirdParty/Unix/LibCxx/lib/Unix/x86_64-unknown-linux-gnu")
3434
else()
3535
message("Building/linking against system-installed toolchain")
36-
set(CMAKE_C_COMPILER clang-13)
37-
set(CMAKE_CXX_COMPILER clang++-13)
36+
set(CMAKE_C_COMPILER clang-15)
37+
set(CMAKE_CXX_COMPILER clang++-15)
3838
endif()
3939
endif()
4040

@@ -48,6 +48,7 @@ set(SIMLIBS_TEST_DIR ${CMAKE_BINARY_DIR}/unit_tests)
4848
set(UE_PLUGIN_SIMLIBS_DIR ${CMAKE_SOURCE_DIR}/unreal/Blocks/Plugins/ProjectAirSim/SimLibs)
4949
set(UNITY_WRAPPER_DLL_DIR ${CMAKE_SOURCE_DIR}/unity/BlocksUnity/Assets/Plugins)
5050
set(MATLAB_PHYSICS_DIR ${CMAKE_SOURCE_DIR}/physics/matlab_sfunc)
51+
set(JSBSIM_CORESIM_DIR ${CMAKE_SOURCE_DIR}/core_sim/jsbsim)
5152
set(MATLAB_CONTROL_DIR ${CMAKE_SOURCE_DIR}/vehicle_apis/multirotor_api/matlab_sfunc)
5253
# set(UE_PLUGIN_CESIUM_NATIVE_DIR ${CMAKE_SOURCE_DIR}/unreal/Blocks/Plugins/ProjectAirSim/SimLibs)
5354
# set(UE_CESIUM_PLUGIN_DIR ${CMAKE_SOURCE_DIR}/unreal/Blocks/Plugins/CesiumForUnreal/)
@@ -75,6 +76,87 @@ elseif(UNIX)
7576
# set(CESIUM_LINUX_TOOLCHAIN ${UE_CESIUM_PLUGIN_DIR}/extern/unreal-linux-toolchain.cmake)
7677
endif()
7778

79+
# Set up dependency: jsbsim
80+
message("Setting up [jsbsim] dependency as an external project...")
81+
# CMake external projects don't adopt the parent's CMAKE_MSVC_RUNTIME_LIBRARY setting,
82+
# so to force /MD non-debug CRT to match UE, build Debug config as Relwithdebinfo and
83+
# build Release as Release.
84+
set(JSBSIM_BUILD_TYPE $<IF:$<CONFIG:Debug>,Relwithdebinfo,Release>)
85+
set(JSBSIM_SRC_DIR ${CMAKE_BINARY_DIR}/_deps/jsbsim/src/jsbsim-repo)
86+
set(JSBSIM_LIB_DIR ${CMAKE_BINARY_DIR}/_deps/jsbsim-install/lib)
87+
set(JSBSIM_INCLUDE_DIR ${CMAKE_BINARY_DIR}/_deps/jsbsim-install/include/JSBSim ${CMAKE_BINARY_DIR}/_deps/jsbsim-install/include/JSBSim/math)
88+
89+
# Platform-specific settings for JSBSim
90+
if(WIN32)
91+
set(JSBSIM_C_COMPILER ${CMAKE_C_COMPILER})
92+
set(JSBSIM_CXX_COMPILER ${CMAKE_CXX_COMPILER})
93+
set(JSBSIM_CXX_FLAGS "")
94+
set(JSBSIM_LIB_NAME JSBSim)
95+
set(JSBSIM_SHARED_LIB ${CMAKE_BINARY_DIR}/_deps/jsbsim-install/bin/JSBSim.dll)
96+
set(JSBSIM_IMPORT_LIB ${JSBSIM_LIB_DIR}/JSBSim.lib)
97+
set(JSBSIM_BYPRODUCTS ${JSBSIM_SHARED_LIB} ${JSBSIM_IMPORT_LIB})
98+
else()
99+
set(JSBSIM_C_COMPILER clang)
100+
set(JSBSIM_CXX_COMPILER clang++)
101+
set(JSBSIM_CXX_FLAGS "-stdlib=libc++")
102+
set(JSBSIM_LIB_NAME libJSBSim.so)
103+
set(JSBSIM_SHARED_LIB ${JSBSIM_LIB_DIR}/libJSBSim.so)
104+
set(JSBSIM_IMPORT_LIB "")
105+
set(JSBSIM_BYPRODUCTS ${JSBSIM_SHARED_LIB})
106+
endif()
107+
108+
ExternalProject_Add(jsbsim-repo
109+
GIT_REPOSITORY https://github.com/JSBSim-Team/jsbsim
110+
GIT_TAG "v1.1.12"
111+
GIT_CONFIG "advice.detachedHead=false"
112+
PREFIX ${CMAKE_BINARY_DIR}/_deps/jsbsim
113+
BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config ${JSBSIM_BUILD_TYPE}
114+
INSTALL_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config ${JSBSIM_BUILD_TYPE} --target install
115+
UPDATE_COMMAND "" # disable update step
116+
CMAKE_ARGS
117+
-DCMAKE_C_COMPILER=${JSBSIM_C_COMPILER}
118+
-DCMAKE_CXX_COMPILER=${JSBSIM_CXX_COMPILER}
119+
-DCMAKE_CXX_FLAGS=${JSBSIM_CXX_FLAGS}
120+
-DCMAKE_POSITION_INDEPENDENT_CODE=True
121+
-DCMAKE_BUILD_TYPE:STRING=${JSBSIM_BUILD_TYPE}
122+
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_BINARY_DIR}/_deps/jsbsim-install
123+
-DBUILD_SHARED_LIBS=ON
124+
-DBUILD_PYTHON_MODULE=OFF
125+
-DBUILD_DOCS=OFF
126+
# Disable SONAME versioning so libJSBSim.so doesn't require libJSBSim.so.1 symlink at runtime
127+
-DCMAKE_PLATFORM_NO_VERSIONED_SONAME=TRUE
128+
# Fix RPATH issue with Ninja generator
129+
-DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE
130+
TEST_COMMAND "" # disable test step
131+
BUILD_BYPRODUCTS ${JSBSIM_BYPRODUCTS}
132+
BUILD_ALWAYS 1
133+
)
134+
135+
ExternalProject_Add_Step(jsbsim-repo post-install
136+
COMMAND ${CMAKE_COMMAND} -E echo "Copying [jsbsim] library to ${JSBSIM_CORESIM_DIR}"
137+
COMMAND ${CMAKE_COMMAND} -E copy_directory "${JSBSIM_INCLUDE_DIR}" "${JSBSIM_CORESIM_DIR}/include"
138+
COMMAND ${CMAKE_COMMAND} -E copy_directory "${JSBSIM_SRC_DIR}/aircraft" "${JSBSIM_CORESIM_DIR}/models/aircraft"
139+
COMMAND ${CMAKE_COMMAND} -E copy_directory "${JSBSIM_SRC_DIR}/engine" "${JSBSIM_CORESIM_DIR}/models/engine"
140+
COMMAND ${CMAKE_COMMAND} -E copy_directory "${JSBSIM_SRC_DIR}/systems" "${JSBSIM_CORESIM_DIR}/models/systems"
141+
COMMAND ${CMAKE_COMMAND} -E copy_directory "${JSBSIM_SRC_DIR}/scripts" "${JSBSIM_CORESIM_DIR}/models/scripts"
142+
COMMAND ${CMAKE_COMMAND} -E copy "${JSBSIM_SHARED_LIB}" "${JSBSIM_CORESIM_DIR}/lib/$<IF:$<CONFIG:Release>,Release,Debug>/${JSBSIM_LIB_NAME}"
143+
DEPENDEES install
144+
)
145+
146+
# Add jsbsim as imported library
147+
add_library(jsbsim SHARED IMPORTED)
148+
if(WIN32)
149+
set_target_properties(jsbsim PROPERTIES
150+
IMPORTED_LOCATION ${JSBSIM_SHARED_LIB}
151+
IMPORTED_IMPLIB ${JSBSIM_IMPORT_LIB}
152+
)
153+
else()
154+
set_target_properties(jsbsim PROPERTIES
155+
IMPORTED_LOCATION ${JSBSIM_SHARED_LIB}
156+
)
157+
endif()
158+
159+
78160

79161
# Set up dependency: nlohmann JSON
80162
# Directly download single include file json.hpp
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
"""
2+
Copyright (C) Microsoft Corporation. All rights reserved.
3+
4+
Demonstrates flying a quadrotor drone with camera sensors.
5+
"""
6+
7+
import asyncio
8+
import math
9+
10+
from projectairsim import ProjectAirSimClient, Drone, World
11+
from projectairsim.utils import projectairsim_log
12+
from projectairsim.image_utils import ImageDisplay
13+
14+
15+
# Async main function to wrap async drone commands
16+
async def main():
17+
# Create a Project AirSim client
18+
client = ProjectAirSimClient()
19+
20+
# Initialize an ImageDisplay object to display camera sub-windows
21+
image_display = ImageDisplay()
22+
23+
try:
24+
# Connect to simulation environment
25+
client.connect()
26+
27+
# Create a World object to interact with the sim world and load a scene
28+
world = World(client, "scene_cessna310.jsonc", delay_after_load_sec=2)
29+
30+
# Create a Drone object to interact with a drone in the loaded sim world
31+
drone = Drone(client, world, "c310")
32+
#
33+
## ------------------------------------------------------------------------------
34+
#
35+
## Subscribe to chase camera sensor as a client-side pop-up window
36+
#chase_cam_window = "ChaseCam"
37+
#image_display.add_chase_cam(chase_cam_window)
38+
#client.subscribe(
39+
# drone.sensors["DownCamera"]["scene_camera"],
40+
# lambda _, chase: image_display.receive(chase, chase_cam_window),
41+
#)
42+
#
43+
## Subscribe to the downward-facing camera sensor's RGB and Depth images
44+
#rgb_name = "RGB-Image"
45+
#image_display.add_image(rgb_name, subwin_idx=0)
46+
#client.subscribe(
47+
# drone.sensors["DownCamera"]["scene_camera"],
48+
# lambda _, rgb: image_display.receive(rgb, rgb_name),
49+
#)
50+
#
51+
#depth_name = "Depth-Image"
52+
#image_display.add_image(depth_name, subwin_idx=2)
53+
#client.subscribe(
54+
# drone.sensors["DownCamera"]["depth_camera"],
55+
# lambda _, depth: image_display.receive(depth, depth_name),
56+
#)
57+
#
58+
#image_display.start()
59+
#
60+
## ------------------------------------------------------------------------------
61+
#
62+
## Set the drone to be ready to fly
63+
## JSBSim robot currently does not support control the drone at runtime
64+
#drone.enable_api_control()
65+
##set brakes to 1
66+
#drone.set_brakes(1)
67+
#drone.arm()
68+
#
69+
## ------------------------------------------------------------------------------
70+
#
71+
## set takeoff z to 120 meters
72+
#drone.set_take_off_z(-120)
73+
#
74+
## ------------------------------------------------------------------------------
75+
#
76+
## Sleep for two seconds to
77+
#await asyncio.sleep(2)
78+
#
79+
## release brakes
80+
#drone.set_brakes(0)
81+
#
82+
#projectairsim_log().info("takeoff_async: starting")
83+
#takeoff_task = (
84+
# await drone.takeoff_async(timeout_sec=1200)
85+
#) # schedule an async task to start the command
86+
#
87+
#await takeoff_task
88+
#projectairsim_log().info("takeoff_async: completed")
89+
#
90+
#projectairsim_log().info("Waiting to stabilize altitude... (10 seconds)")
91+
#await asyncio.sleep(10)
92+
#
93+
## ------------------------------------------------------------------------------
94+
#
95+
## Command the drone to move to position 1000,1000,-200
96+
#move_up_task = await drone.move_to_position_async(
97+
# north=1000, east=1000, down=-200, velocity=33.0, lookahead=100, timeout_sec=60
98+
#)
99+
#projectairsim_log().info("Move to position 1000,1000,-200 invoked")
100+
#
101+
#await move_up_task
102+
#projectairsim_log().info("Move to position completed")
103+
#
104+
## ------------------------------------------------------------------------------
105+
#
106+
## Command vehicle to fly at a specific heading and speed
107+
#projectairsim_log().info("Heading 90 invoked")
108+
#heading_45_task = await drone.move_by_heading_async(
109+
# heading=math.radians(90.0), speed=20.0, duration=10
110+
#)
111+
#await heading_45_task
112+
#projectairsim_log().info("Heading 90 complete.")
113+
#
114+
## ------------------------------------------------------------------------------
115+
#
116+
## Command the drone to move to position 0,0,-100
117+
#move_up_task = await drone.move_to_position_async(
118+
# north=0, east=0, down=-100, velocity=33.0, lookahead=100, timeout_sec=60
119+
#)
120+
#projectairsim_log().info("Move to position 0,0,-100 invoked")
121+
#
122+
#await move_up_task
123+
#projectairsim_log().info("Move to position completed")
124+
## ------------------------------------------------------------------------------
125+
#
126+
#projectairsim_log().info("land_async: starting")
127+
#land_task = await drone.land_async()
128+
#await land_task
129+
#projectairsim_log().info("land_async: completed")
130+
## set brakes to 50%
131+
#drone.set_brakes(0.5)
132+
133+
# ------------------------------------------------------------------------------
134+
135+
# Shut down the drone
136+
drone.disarm()
137+
drone.disable_api_control()
138+
139+
# logs exception on the console
140+
except Exception as err:
141+
projectairsim_log().error(f"Exception occurred: {err}", exc_info=True)
142+
143+
finally:
144+
# Always disconnect from the simulation environment to allow next connection
145+
client.disconnect()
146+
147+
image_display.stop()
148+
149+
150+
if __name__ == "__main__":
151+
asyncio.run(main()) # Runner for async main function

client/python/example_user_scripts/jsbsim_env_actor.py

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)