ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • EuroTruckSimulation2 에서 data 가져오기
    Python 2023. 3. 24. 02:02
    반응형
    🚛

    For Only Windows

    https://github.com/nlhans/ets2-sdk-plugin

    Releases · nlhans/ets2-sdk-plugin
    You can't perform that action at this time. You signed in with another tab or window. You signed out in another tab or window. Reload to refresh your session. Reload to refresh your session.
    https://github.com/nlhans/ets2-sdk-plugin/releases
    https://github.com/Madricas/ets2-python-telemetry

    Installation

    1. 먼저 release git repo link를 따라가 release*.zip 파일을 다운받아 풀어준다.
    1. 유로트럭 수행 파일이 설치된 곳아래 plugins 에 win_64 아래 있는 dll file을 찾아서 넣어준다. 보통 아래와 같은 경로에 설치돼있다. plugins 폴더가 없으면 만들어준다. (구체적인 경로는 추후 추가 예정) bin/win_x86/plugins/

    Usage

    1. 유로트럭 시뮬레이션을 실행한다. 초반에 sdk를 사용할 것이냐는 안내문이 나오면 install에 성공한 것이다.
    1. 유로트럭의 telemetry data들은 ssd에 저장되지 않고(굉장히 빠른 시간에 read, write가 진행되며 디시크를 손상시킬 수 있다.) memory mapped file에 저장된다. (Shared Memory)
    1. ets2-python-telemetry git repo코드는 python code로 memory mapped file에 저장된 값들을 불러올 수 있는 API를 제공한다. 수행 예제는 아래와 같다.
    1. 먼저 ets2-python-telemetry git repo를 clone 해온다.
      cd
      git clone https://github.com/Madricas/ets2-python-telemetry.git
      cd ets2-python-telemetry
    1. 아래 코드를 수행한다.
      • 해당 코드는 1초에 한 번 _format과 같은 형식으로 log.txt 파일에 이를 저장한다.
      import time
      import numpy as np
      from shareedmemory import SharedMemory
      
      sm = SharedMemory()
      sm.connect()
      
      _format = f"""
          time:   {time.ctime(time.time())}
          coordX: {data.coordinateX}
          coordY: {data.coordinateY}
          accX:   {data.accelerationX}
          accY:   {data.accelerationY}
          rotX:   {data.rotationX}
          speed:  {(data.speed * 3.6)}km/h
      """  
      with open('log.txt', 'a+') as f:
      		while True:
      				data = sm.update()
      			   
      			  f.write(_format)
      			  print(_format)
      			  time.sleep(1)
      			


    Uploaded by N2T

    반응형
Designed by Tistory.