0
我在獲取Python OBD2讀取程序的正確速度時遇到了一些問題。即使我沒有移動,它仍然保持在13。我已經將我的代碼從git集線器上的pi2go中取出。儘管不管speed_float的值總是從十六進制轉換爲浮點數。OBD2 Python獲取速度
def speed(self, oldValues):
""" Gets the speed of the vehicle """
if self.serialIO is None:
return "Serial IO not setup."
self.serialWrite("0D")
speed_list = self.serialRead()
if speed_list == -1 or speed_list == 0:
print("There is an issue with reading the speed of the vehicle.")
return 0
else:
speed_hex = speed_list[0]
speed_float = float(int("0x" + speed_hex, 0))
print("Speed float = " + str(speed_float))
if speedFormat == "mph":
# display speed in miles per hour
#speed_float = speed_float * 0.621371
speed_float = speed_float * 1.609 - 20.917 #made it go to zero by subtracting 20.917
print("mph = " + str(speed_float))
elif speedFormat == "kph":
# display speed in kilometers per hour
print("kph = " + str(speed_float))
return speed_float
else:
# error
print("Configuration is wrong. Please check config.py for speedFormat")
return speed_float
當我將mph值設爲零後,它保持爲零。它永遠不會改變。上面的公式使得它有點像8.0。我的問題是如何獲得實際的速度。
你配置了本地回顯的串口嗎? – rfkortekaas
rkorekaas - 其他一切正在工作。 RPMs進氣溫度等我只是無法得到速度正常工作。 – crzyone9584