2. VehicleSignal Document¶
SDLBOOTCAMPに車両情報を通知するためのシミュレータ
2.1 動作確認環境¶
- Ubuntu16.04 LTS
- Python : 3.5.2
- python-OBD : 0.7.0
- websocket-client : 0.56.0
- OBD2アダプタ : ELM327 USB(SsSlct)
2.2 通信仕様¶
- SDLBOOTCAMP側仕様
- 無線仕様 : Wi-Fi direct [IEEE 802.11b/g/n]
- IPアドレス : 10.0.0.1
- ポート番号 : 固定(8088)
- SSID : sdlbootcamp
- 暗号キー : sdlbootcamp
2.3 サンプルソースコード¶
OBD2_tp.py
#!/usr/bin/env python3
import sys
import time
import websocket
import obd
import json
BC_IP_ADDR = "10.0.0.1"
BC_PORT_NUM = "8088"
webSocket = None
obd2Connection = None
def Finalize():
global webSocket
global obd2Connection
if None != webSocket:
webSocket.close()
if None != obd2Connection:
obd2Connection.close()
if __name__ == "__main__":
# WebSocket connect
webSocket = websocket.WebSocket()
webSocket.connect("ws://" + BC_IP_ADDR + ":" + BC_PORT_NUM + "/")
if False == webSocket.connected:
print("[ERR] WebSocket Connection Error")
Finalize()
sys.exit()
# OBD2 connect
obd2Connection = obd.OBD()
if obd.OBDStatus.CAR_CONNECTED != obd2Connection.status():
print("[ERR] Please connect the OBD2 adapter to the car")
Finalize()
sys.exit()
for i in range(5):
# OBD2 get param
speedObj = obd2Connection.query( obd.commands.SPEED );
if None == speedObj.value:
print("[ERR] [SPEED] Get Error")
Finalize()
sys.exit()
throttleObj = obd2Connection.query( obd.commands.THROTTLE_POS )
if None == throttleObj.value:
print("[ERR] [THROTTLE_POS] Get Error")
Finalize()
sys.exit()
# Send to SDL BOOT CAMP
speed = speedObj.value.magnitude
throttlePos = throttleObj.value.magnitude
sendData = json.dumps( {"VehicleData": {"speed":speed, "accPedalPosition":throttlePos} })
# print( sendData )
webSocket.send( sendData )
# 500msec
time.sleep(0.5)
# Exit
Finalize()
2.4 サンプルプログラム確認手順¶
実車、ubuntu-PC を OBD2アダプタ で接続
SDLBOOTCAMP と PC を wifi接続
サンプルプログラム起動し、SDLBOOTCAMPのログから速度、アクセルペダル位置が取得できることを確認
サンプルプログラム起動方法
$ python3 OBD2_tp.py
参考情報¶
python3環境構築(ubuntu 16.04(64bit))¶
$ sudo apt-get install python3-pip
$ pip3 install websocket-client
$ pip3 install obd
python-OBD詳細情報¶
実装済みパラメータ¶
SDL-CORE Ver4.5.1 に準拠している。
JSON schema
"vehicleInfo": {
"type": "object",
"properties": {
"speed": {
"description": "The vehicle speed in kilometers per hour",
"type": "number",
"minimum": 0.0,
"maximum": 700.0
},
"prndl": {
"description": "The selected gear.",
"type": "string",
"enum": [
"PARK",
"REVERSE",
"NEUTRAL",
"DRIVE",
"SPORT",
"LOWGEAR",
"FIRST",
"SECOND",
"THIRD",
"FOURTH",
"FIFTH",
"SIXTH",
"SEVENTH",
"EIGHTH",
"UNKNOWN",
"FAULT"
]
},
"gps": {
"description": "Struct with the GPS data.",
"type": "object",
"properties": {
"longitudeDegrees": {
"type": "number",
"minimum": -180.00000,
"maximum": 180.00000
},
"latitudeDegrees": {
"type": "number",
"minimum": -90.00000,
"maximum": 90.00000
},
"utcYear": {
"description": "The current UTC year.",
"type": "integer",
"minimum": 2010,
"maximum": 2100
},
"utcMonth": {
"description": "The current UTC month.",
"type": "integer",
"minimum": 1,
"maximum": 12
},
"utcDay": {
"description": "The current UTC day.",
"type": "integer",
"minimum": 1,
"maximum": 31
},
"utcHours": {
"description": "The current UTC hour.",
"type": "integer",
"minimum": 0,
"maximum": 23
},
"utcMinutes": {
"description": "The current UTC minute.",
"type": "integer",
"minimum": 0,
"maximum": 59
},
"utcSeconds": {
"description": "The current UTC second.",
"type": "integer",
"minimum": 0,
"maximum": 59
},
"compassDirection": {
"description": "See CompassDirection.",
"type": "string",
"enum": [
"NORTH",
"NORTHWEST",
"WEST",
"SOUTHWEST",
"SOUTH",
"SOUTHEAST",
"EAST",
"NORTHEAST"
]
},
"pdop": {
"description": "PDOP",
"type": "number",
"minimum": 0.00,
"maximum": 1000.00
},
"hdop": {
"description": "HDOP",
"type": "number",
"minimum": 0.00,
"maximum": 1000.00
},
"vdop": {
"description": "VDOP",
"type": "number",
"minimum": 0.00,
"maximum": 1000.00
},
"actual": {
"description": "True, if actual. False, if infered.",
"type": "boolean"
},
"satellites": {
"description": "Number of satellites in view",
"type": "integer",
"minimum": 0,
"maximum": 31
},
"dimension": {
"description": "See Dimension",
"type": "string",
"enum": [
"NO_FIX",
"2D",
"3D"
]
},
"altitude": {
"description": "Altitude in meters",
"type": "number",
"minimum": -10000.0,
"maximum": 10000.0
},
"heading": {
"description": "The heading. North is 0. Resolution is 0.01",
"type": "number",
"minimum": 0.00,
"maximum": 359.99
},
"speed": {
"description": "The speed in KPH",
"type": "number",
"minimum": 0.0,
"maximum": 500.0
}
}
},
"bodyInformation": {
"description": "The body information including power modes",
"type": "object",
"properties": {
"parkBrakeActive": {
"description": "Must be true if the park brake is active",
"type": "boolean"
},
"ignitionStableStatus": {
"description": "Information about the ignition switch. See IgnitionStableStatus.",
"type": "string",
"enum": [
"IGNITION_SWITCH_NOT_STABLE",
"IGNITION_SWITCH_STABLE",
"MISSING_FROM_TRANSMITTER"
]
},
"ignitionStatus": {
"description": "The status of the ignition. See IgnitionStatus.",
"type": "string",
"enum": [
"UNKNOWN",
"OFF",
"ACCESSORY",
"RUN",
"START",
"INVALID"
]
},
"driverDoorAjar": {
"description": "References signal \"DrStatDrv_B_Actl\".",
"type": "string",
"enum": [
"None",
"false",
"true"
]
},
"passengerDoorAjar": {
"description": "References signal \"DrStatPsngr_B_Actl\".",
"type": "string",
"enum": [
"None",
"false",
"true"
]
},
"rearLeftDoorAjar": {
"description": "References signal \"DrStatRl_B_Actl\".",
"type": "string",
"enum": [
"None",
"false",
"true"
]
},
"rearRightDoorAjar": {
"description": "References signal \"DrStatRr_B_Actl\".",
"type": "string",
"enum": [
"None",
"false",
"true"
]
}
}
},
"headLampStatus": {
"description": "Status of the head lamps",
"type": "object",
"properties": {
"lowBeamsOn": {
"description": "Status of the low beam lamps.",
"type": "boolean"
},
"highBeamsOn": {
"description": "Status of the high beam lamps.",
"type": "boolean"
},
"ambientLightSensorStatus": {
"description": "Reflects the status of the ambient light sensor.",
"type": "string",
"enum": [
"NIGHT",
"TWILIGHT_1",
"TWILIGHT_2",
"TWILIGHT_3",
"TWILIGHT_4",
"DAY",
"UNKNOWN",
"INVALID"
]
}
}
},
"accPedalPosition": {
"description": "Accelerator pedal position (percentage depressed)",
"type": "number",
"minimum": 0.0,
"maximum": 100.0
}
}
}