forked from microsoft/AirSim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
car_collision.py
39 lines (29 loc) · 1.02 KB
/
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
35
36
37
38
39
import setup_path
import airsim
import pprint
import time
# connect to the AirSim simulator
client = airsim.CarClient()
client.confirmConnection()
client.enableApiControl(True)
car_controls = airsim.CarControls()
client.reset()
client.simPrintLogMessage("Hello", "345", 2)
# 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.simGetCollisionInfo()
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)