对于Linux系统,目前AirSim官方测试过的系统版本为Ubuntu 18.04LTS,推荐使用该版本。
网址:https://www.unrealengine.com/
在个人设置中,关联自己的GitHub帐号,之后GitHub中的Epic Games会团队会邀请加入到开发团队中,之后即可查看或者下载Unreal Engine
网址:https://github.com/EpicGames/UnrealEngine
git clone -b 4.24 https://github.com/EpicGames/UnrealEngine.git
cd UnrealEngine
./Setup.sh
./GenerateProjectFiles.sh
make
git clone https://github.com/Microsoft/AirSim.git
cd AirSim
./setup.sh
./build.sh
在执行./setup.sh时,会下载car_assets.zip,这可能会花费很长时间,如果仅进行无人机仿真的话,可以使用下面的命令来代替:
./setup.sh --no-full-poly-car
AirSim已经准备了一个称之为Blocks的简单仿真环境,当然,这并不一定满足您的需求,您还可以自行购买或者创建自己的仿真环境,不过值得一提的是,如果要购买仿真场景的话,只能在Windows的虚幻商城中下载,之后可以迁移到Ubuntu中。
如果您需要自行创建或者配置自己的仿真场景,可以参考:
https://qiuming.blog.csdn.net/article/details/104327689
下面我们对使用内置的Blocks场景进行简单的介绍:
cd ~/AirSim/PythonClient/multirotor/
python hello_drone.py
此时可能出错:
No module named msgpackrpc
执行下面的命令安装缺少的包:
pip install msgpack-rpc-python
而后,重新执行python hello_drone.py
,即可看到终端输出
fire@fire-P7xxTM1:~/AirSim/PythonClient/multirotor$ python hello_drone.py
Connected!
Client Ver:1 (Min Req: 1), Server Ver:1 (Min Req: 1)
state: { u'collision': { u'has_collided': False,
u'impact_point': { u'x_val': 0.0,
u'y_val': 0.0,
u'z_val': 0.0},
u'normal': { u'x_val': 0.0,
u'y_val': 0.0,
u'z_val': 0.0},
u'object_id': -1,
u'object_name': u'',
u'penetration_depth': 0.0,
u'position': { u'x_val': 0.0,
u'y_val': 0.0,
u'z_val': 0.0},
u'time_stamp': 0},
u'gps_location': { u'altitude': 123.34492492675781,
u'latitude': 47.64197914136834,
u'longitude': -122.14017833284416},
u'kinematics_estimated': { u'angular_acceleration': { u'x_val': 0.0,
u'y_val': 0.0,
u'z_val': 0.0},
u'angular_velocity': { u'x_val': 0.0,
u'y_val': 0.0,
u'z_val': 0.0},
u'linear_acceleration': { u'x_val': 0.0,
u'y_val': 0.0,
u'z_val': 0.0},
u'linear_velocity': { u'x_val': 0.0,
u'y_val': 0.0,
u'z_val': 0.0},
u'orientation': { u'w_val': 1.0,
u'x_val': 0.0,
u'y_val': 0.0,
u'z_val': 0.0},
u'position': { u'x_val': 0.0,
u'y_val': 0.0,
u'z_val': 0.6750681400299072}},
u'landed_state': 0,
u'rc_data': { u'is_initialized': False,
u'is_valid': False,
u'left_z': 0.0,
u'pitch': 0.0,
u'right_z': 0.0,
u'roll': 0.0,
u'switches': 0,
u'throttle': 0.0,
u'timestamp': 0,
u'vendor_id': u'',
u'yaw': 0.0},
u'timestamp': 1591066842833506816}
imu_data: { u'angular_velocity': { u'x_val': -0.001506683649495244,
u'y_val': 0.0007826467626728117,
u'z_val': -0.0007805040804669261},
u'linear_acceleration': { u'x_val': 0.04153737053275108,
u'y_val': -0.050786156207323074,
u'z_val': -9.817627906799316},
u'orientation': { u'w_val': 1.0,
u'x_val': 0.0,
u'y_val': 0.0,
u'z_val': 0.0},
u'time_stamp': 1591066842836506880}
barometer_data: { u'altitude': 123.32682800292969,
u'pressure': 99851.5859375,
u'qnh': 1013.25,
u'time_stamp': 1591066842824506624}
magnetometer_data: { u'magnetic_field_body': { u'x_val': 0.24743011593818665,
u'y_val': 0.03551159054040909,
u'z_val': 0.36682388186454773},
u'magnetic_field_covariance': [ ],
u'time_stamp': 1591066842824506624}
gps_data: { u'gnss': { u'eph': 0.3000044822692871,
u'epv': 0.40000447630882263,
u'fix_type': 3,
u'geo_point': { u'altitude': 123.34492492675781,
u'latitude': 47.64197914136834,
u'longitude': -122.14017833284416},
u'time_utc': 1591066842608502,
u'velocity': { u'x_val': 0.0,
u'y_val': 0.0,
u'z_val': 0.0}},
u'is_valid': True,
u'time_stamp': 1591066842608502016}
Press any key to takeoff
我们即可根据终端信息提示,进行操作,下面是一张飞行截图
hello_drone.py的代码如下:
# ready to run example: PythonClient/multirotor/hello_drone.py
import airsim
# connect to the AirSim simulator
client = airsim.MultirotorClient()
client.confirmConnection()
client.enableApiControl(True)
client.armDisarm(True)
# Async methods returns Future. Call join() to wait for task to complete.
client.takeoffAsync().join()
client.moveToPositionAsync(-10, 10, -10, 5).join()
# take images
responses = client.simGetImages([
airsim.ImageRequest("0", airsim.ImageType.DepthVis),
airsim.ImageRequest("1", airsim.ImageType.DepthPlanner, True)])
print('Retrieved images: %d', len(responses))
# do something with the images
for response in responses:
if response.pixels_as_float:
print("Type %d, size %d" % (response.image_type, len(response.image_data_float)))
airsim.write_pfm(os.path.normpath('/temp/py1.pfm'), airsim.getPfmArray(response))
else:
print("Type %d, size %d" % (response.image_type, len(response.image_data_uint8)))
airsim.write_file(os.path.normpath('/temp/py1.png'), response.image_data_uint8)
1.Build AirSim on Linux