我想要得到這個代碼在Python的3.x的如何解決:類型錯誤:unorderable類型:NoneType()<浮動()
這是出現的線部分運行:
#Here we check to make sure horizon (19) and ovveride (16) digital pins aren't on
#print("GPIO 16 (ovveride) is " + str(GPIO.input(16)))
#print("GPIO 19 (horizon) is " + str(GPIO.input(19)))
#print(GPIO.input(19))
if (GPIO.input(16) == False) and (GPIO.input(19) == False): #check to see if the passive mode switch is on
# GPIO 16 is for override and GPIO 19 is for horizon mode
#In this section we rotate as needed
starttime = datetime.datetime.utcnow()
if (getcurheading() > getsolarheading()) and (getsolarangle() > 2) and (getcurheading() != 999):
while (getcurheading() > (getsolarheading() + hmargin)) and (starttime + datetime.timedelta(seconds=pan_time_limit) > datetime.datetime.utcnow()):
if debug == True:
print("1: Moving " + str(getcurheading()) + " to " + str(getsolarheading()))
motor2neg()
motors.setSpeeds(0, 0)
starttime = datetime.datetime.utcnow()
if (getcurheading() < getsolarheading()) and (getsolarangle() > 2) and (getcurheading() != 999):
while (getcurheading() < (getsolarheading() - hmargin)) and (starttime + datetime.timedelta(seconds=pan_time_limit) > datetime.datetime.utcnow()):
if debug == True:
print("2: Moving " + str(getcurheading()) + " to " + str(getsolarheading()))
motor2pos()
motors.setSpeeds(0, 0)
starttime = datetime.datetime.utcnow()
if (getcurheading() > tomorrow_static) and (getsolarangle()<0) and (getcurheading() != 999):
if (getcurheading() - tomorrow_static) > sleep_tolerance:
while (getcurheading() > (tomorrow_static + hmargin)) and (starttime + datetime.timedelta(seconds=pan_time_limit) > datetime.datetime.utcnow()):
其中產生的錯誤是:
Traceback (most recent call last):
File "solarrobot7-core.py", line 261, in <module>
if (getcurheading() < getsolarheading()) and (getsolarangle() > 2) and (getcurheading() != 999):
TypeError: unorderable types: NoneType() < float()
這是Unicode字符串與字節另一種情況?
下面是我認爲是curheading的定義。
#Translate the IMU from magnetic north to true north since the calcs use true north
def getcurheading():
# The escape character for # is \x23 in hex
serialport.write(b"\x23o0 \x23f")
headresponse = serialport.readline()
# print(headresponse)
words = headresponse.split(",")
if len(words) > 2:
try:
curheading = (float(words[0])) + 180
if curheading + Declination > 360: curheading = curheading - 360 + Declination
else: curheading = curheading + Declination
except:
curheading = 999
# print(curheading)
return curheading
感謝您指出我沒有包含定義j。
什麼'getcurheading'? – pivanchy
感謝您的回覆,pvanchy!我會試一試並回復你。正如你所看到的,我已經在serialport.write(b「\ x23o0 \ x23f」)中引入了「b」,因爲它將Unicode轉換爲字節錯誤。 – frazelle09
目前的問題是不相關爲unicode的問題,它的東西,另一個 – pivanchy