コード例 #1
0
ファイル: gym_torcs.py プロジェクト: MehaKaushik/MADRaS
"""
Gym interface to snakeoil3_gym.py.

Provides a gym interface to the traditional server-client model.
"""
import os
import math
import collections as col
from gym import spaces
import numpy as np
from utils.madras_datatypes import Madras
import utils.snakeoil3_gym as snakeoil3

madras = Madras()


class TorcsEnv:
    """The Env API for TORCS."""

    terminal_judge_start = 100
    # If after 100 timestep still no progress, terminated
    termination_limit_progress = 1
    # [km/h], episode terminates if car is running slower than this limit
    default_speed = 50
    initial_reset = False
    obs_dim = 29
    act_dim = 3

    def __init__(self, vision=False, throttle=False, gear_change=False):
        """Init Method."""
        self.vision = vision
コード例 #2
0
ファイル: lane_switch.py プロジェクト: taapasX28/MADRaS
"""Random Lane changing Traffic Agent."""
import sys
import time
import yaml
import random
import numpy as np
from controllers.pid import PID
from utils.gym_torcs import TorcsEnv
import utils.snakeoil3_gym as snakeoil3
from utils.madras_datatypes import Madras

madras = Madras()
with open("./traffic/configurations.yml", "r") as ymlfile:
    cfg = yaml.load(ymlfile)

random.seed(time.time())


def playTraffic(port=3101, target_vel=50.0, angle=0.0, sleep=0):
    """Traffic Play function."""
    env = TorcsEnv(vision=False, throttle=True, gear_change=False)
    ob = None
    while ob is None:
        try:
            client = snakeoil3.Client(p=port, vision=False)
            client.MAX_STEPS = np.inf
            client.get_servers_input(step=0)
            obs = client.S.d
            ob = env.make_observation(obs)
        except:
            pass
コード例 #3
0
ファイル: const_vel_s.py プロジェクト: taapasX28/MADRaS
"""Traffic agent created using snakeoil API."""

import sys
import numpy as np
import utils.snakeoil3_gym as snakeoil3
from utils.madras_datatypes import Madras

madras = Madras()
PORT = madras.intX(sys.argv[1])
PI = 3.14159265359
maxSteps = 5000


def drive_traffic(c, speed):
    """Drive Function."""
    S, R = c.S.d, c.R.d
    opp = np.asarray(S['opponents'])
    closest = np.min(opp)
    front = np.array([opp[15], opp[16], opp[17], opp[18], opp[19]])
    closest_front = np.min(front)
    print("CLOSEST {}".format(closest))
    print("CLOSEST_FRONT {}".format(closest_front))
    target_speed = madras.floatX(speed)

    # Steer To Corner
    R['steer'] = (S['angle'] + madras.floatX(sys.argv[3]) / 10) * 10 / PI
    # Steer To Center
    R['steer'] -= (S['trackPos'] + madras.floatX(sys.argv[3])) * .10

    # Traction Control System
    if ((S['wheelSpinVel'][2] + S['wheelSpinVel'][3]) -