-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathCarDriver.py
40 lines (32 loc) · 1.11 KB
/
CarDriver.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
import os
import sys
import time
import numpy as np
python_path = os.path.abspath('AirSim/PythonClient')
sys.path.append(python_path)
from AirSimClient import *
class CarDriver:
def __init__(self):
self.MAX_SPEED = 50
self.MIN_SPEED = 0
self.trajectory = 0
self.trajectories = ['acc', 'deacc', 'still', 'rand-turn', 'circle']
self.max_actions = 100
self.client = CarClient()
self.client.confirmConnection()
self.client.enableApiControl(True)
self.car_controls = CarControls()
def disconnect(self):
self._connector.enableApiControl(False)
def drive(self):
trajectories()
self.client.setCarControls(self.car_controls)
time.sleep(0.5)
def drive(self):
self.car_controls.brake = 0
self.car_controls.throttle = 1
self.car_controls.steering = 0
# if self.trajectory=0:
steer = (np.random.sample(1))*2*0.1 - 0.1
self.car_controls.steering = steer
self.trajectory = (self.trajectory + 1) % len(self.trajectories)