我想要得到这个代码在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