forked from rkuo2000/tf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
airsim_hello_car.py
37 lines (31 loc) · 1.24 KB
/
airsim_hello_car.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import airsim
import time
import matplotlib.pyplot as plt
# connect to the AirSim simulator
client = airsim.CarClient()
client.confirmConnection()
client.enableApiControl(True)
car_controls = airsim.CarControls()
while True:
# get state of the car
car_state = client.getCarState()
print("Speed %d, Gear %d" % (car_state.speed, car_state.gear))
# set the controls for car
car_controls.throttle = 1
car_controls.steering = 1
client.setCarControls(car_controls)
# let car drive a bit
time.sleep(1)
# get camera images from the car
responses = client.simGetImages([
airsim.ImageRequest(0, airsim.ImageType.DepthVis),
airsim.ImageRequest(1, airsim.ImageType.DepthPlanar, True)])
print('Retrieved images: %d', len(responses))
# do something with 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('py1.pfm', airsim.get_pfm_array(response))
else:
print("Type %d, size %d" % (response.image_type, len(response.image_data_uint8)))
airsim.write_file('py1.png', response.image_data_uint8)