def reset(self, manual=False): """Re-launch torcs""" if manual: self.__reset_torcs_manual() else: self.__reset_torcs() self.client = snakeoil.Client(p=3001) self.client.MAX_STEPS = np.inf self.client.get_servers_input() self.obs.update_obs(self.client.S.d)
def __init__(self, manual=False): """API for communicating with snakeoil.py and torcs. Launches torcs""" print("Launching torcs...") if manual: self.__reset_torcs_manual() else: self.__reset_torcs() print("Connecting to torcs...") self.client = snakeoil.Client(p=3001) self.client.maxSteps = np.inf self.client.get_servers_input() self.obs = observation.Observation() self.obs.update_obs(self.client.S.d) self.act = action.Action() self.PI = 3.14159265359
def run(self): global prediction # establish connection with TORCS server C = snakeoil.Client() # load PID controller and set vehicle speed pid = PID(1.0, 0.1, 0.1) pid.setPoint(15.5) try: while True: C.get_servers_input() R = C.R.d S = C.S.d R['steer'] = prediction R['accel'] = pid.update(S['speedX']) R['accel'] = np.clip(R['accel'], 0, 0.1) snakeoil.drive_example(C) C.respond_to_server() C.shutdown() except KeyboardInterrupt: print('\nShutdown requested. Exiting...')
#!/usr/bin/python from matplotlib import pyplot as plt import snakeoil import screenpipe from time import sleep if __name__ == "__main__": C = snakeoil.Client() pipe = screenpipe.screenpipe() for step in xrange(C.maxSteps,0,-1): img = pipe.get_image() #plt.imshow(img) #plt.show() #print 1 C.get_servers_input() snakeoil.drive_example(C) C.respond_to_server() # print 2 C.shutdown()
def main(P, port, m=1): global lap T = Track() C = snakeoil.Client(P=P, port=port) lastLapTime = [] damages = [] distance = [] positions_out = [] times_out = 0 max_out = 0 out = False lastLapTime.append(0) if C.stage == 1 or C.stage == 2: try: T.load_track(C.trackname) except: print "Could not load the track: %s" % C.trackname sys.exit() print "Track loaded!" initialize_car(C) C.respond_to_server() C.S.d['stucktimer'] = 0 C.S.d['targetSpeed'] = 0 # gear = 0 lap = 1 for step in xrange(C.maxSteps, 0, -1): C.get_servers_input() drive(C, T, step) C.respond_to_server() # print C.S.d['rpm'] # # if gear != C.S.d['gear']: # print 'Cambio marcia da', gear, 'a', C.S.d['gear'] # gear = C.S.d['gear'] if lap > 1: tp = abs(C.S.d['trackPos']) # print tp if tp >= 0.95: times_out += 1 out = True if tp > max_out: max_out = tp if tp < 0.95 and out: out = False if times_out > 30: # print "out", [max_out, times_out] positions_out.append([max_out, times_out]) times_out = 0 max_out = 0 if (lastLapTime[len(lastLapTime) - 1] != C.S.d['lastLapTime']): lap += 1 lastLapTime.append(C.S.d['lastLapTime']) damages.append(C.S.d['damage']) distance.append(C.S.d['distRaced']) if (len(lastLapTime) == 3) and m == 1: C.R.d['meta'] = 1 C.respond_to_server() C.shutdown() return lastLapTime, damages, distance, positions_out, port if C.S.d['damage'] > 8000 or C.S.d['curLapTime'] > 200: damages.append(50000) C.R.d['meta'] = 1 C.respond_to_server() C.shutdown() return lastLapTime, damages, distance, positions_out, port if not C.stage: T.write_track(C.trackname)