forked from microsoft/AirSim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcar_collision.py
34 lines (26 loc) · 966 Bytes
/
car_collision.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
from AirSimClient import *
import pprint
# connect to the AirSim simulator
client = CarClient()
client.confirmConnection()
client.enableApiControl(True)
car_controls = CarControls()
client.reset()
# go forward
car_controls.throttle = 0.5
car_controls.steering = 0
client.setCarControls(car_controls)
while True:
# get state of the car
car_state = client.getCarState()
print("Speed %d, Gear %d" % (car_state.speed, car_state.gear))
collision_info = client.getCollisionInfo()
if collision_info.has_collided:
print("Collision at pos %s, normal %s, impact pt %s, penetration %f, name %s, obj id %d" % (
pprint.pformat(collision_info.position),
pprint.pformat(collision_info.normal),
pprint.pformat(collision_info.impact_point),
collision_info.penetration_depth, collision_info.object_name, collision_info.object_id))
break
time.sleep(0.1)
client.enableApiControl(False)