-
Notifications
You must be signed in to change notification settings - Fork 1
/
drive_circles.py
51 lines (36 loc) · 1.33 KB
/
drive_circles.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
40
41
42
43
44
45
46
47
48
49
50
51
import sys
import os
## adds the fsds package located the parent directory to the pyhthon path
#sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
fsds_lib_path = os.path.join(os.getcwd(),"Formula-Student-Driverless-Simulator","python")
sys.path.insert(0, fsds_lib_path)
print(f'FSDS simulator path: {fsds_lib_path}')
import time
import fsds
import numpy as np
# connect to the AirSim simulator
client = fsds.FSDSClient()
# Check network connection, exit if not connected
client.confirmConnection()
# After enabling api controll only the api can controll the car.
# Direct keyboard and joystick into the simulator are disabled.
client.enableApiControl(True)
# Data stucture for controlling the car
car_controls = fsds.CarControls()
# -1 is full steering left, +1 is full right, 0 is neutral
car_controls.steering = -0.7
# 0 is no throttle, 1 is full throttle
car_controls.throttle = 0
# 0 brake is no break, 1 is full break
car_controls.brake = 0
while (True):
# Get the car state
state = client.getCarState()
print('car speed (m/s): {0}'.format(state.speed))
if (state.speed < 5):
car_controls.throttle = 0.5
else:
car_controls.throttle = 0.0
print('throttle = {0}'.format(car_controls.throttle))
client.setCarControls(car_controls)
time.sleep(0.5)