def step(self, action):
        # TODO Check if action is in action_space
        # TODO return info - debug information
        self.time_start("step", "start")

        car_controls = fsds.CarControls()
        car_controls.steering = action[0]
        car_controls.throttle = 0
        car_controls.brake = 0
        if action[1] > 0:
            car_controls.throttle = action[1]
        else:
            car_controls.brake = action[2]
        self.client.setCarControls(car_controls)

        network_thread = threading.Thread(target=self.getAllSimData_async)
        network_thread.start()

        # time.sleep(0.3)

        #self.getAllSimData()
        #print(self.kinematics)
        #new_state = self.compute_state()

        reward, done = self.compute_reward()
        info = ""  # TODO : Add timing data here
        #return new_state.flatten(), reward, done, info
        network_thread.join()

        self.kinematics, self.kinematics, self.gps_data, self.lidar_data, self.referee_state, self.images, self.cones, self.lidar_pc, self.state = self.network_data

        self.time_start("step", "finish")
        #self.time_print()
        self.log("reward : " + str(reward))
        return self.state, reward, done, info
def main():
    while True:
        # 20 hz
        #plt.pause(0.05)

        #plt.clf()
        #plt.axis([-cones_range_cutoff, cones_range_cutoff, -2, cones_range_cutoff])
        
        cones = find_cones()

        get_camera()

        if len(cones) == 0:
            continue

        car_controls = fsds.CarControls()
        car_controls.steering = calculate_steering(cones)
        car_controls.throttle = calculate_throttle()
        car_controls.brake = 0
        client.setCarControls(car_controls)
Ejemplo n.º 3
0
    def step(self, action):
        # TODO Check if action is in action_space
        # TODO return info - debug information

        car_controls = fsds.CarControls()
        car_controls.steering = action[0]
        car_controls.throttle = 0
        car_controls.brake = 0
        if action[1] > 0:
            car_controls.throttle = action[1]
        else:
            car_controls.brake = action[1] * -1
        self.client.setCarControls(car_controls)

        # time.sleep(0.3)

        new_state = self.compute_state()

        reward, done = self.compute_reward()
        info = self.client.getCarState()
        #return new_state.flatten(), reward, done, info
        return new_state, reward, done, info
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
    car_state = client.getCarState()

    print('car speed (m/s): {0}'.format(car_state.speed))