I am a student trying to create a range of coordinates for a ball detector on pi-top 4.
if blue_ball.found:
print(f"Blue ball center: {blue_ball.center}")
print()
if ((30,50) <= blue_ball.center <= (60, 80)):
led.on()
sleep(0.5)`
The second block is where I am running into issues. I get an error that
"<=" cannot be inbetween a tuple and a NoneType.
I have tried defining it as an integer and replacing it with "{blue_ball.center}" as it appears earlier in an f-string. I think it returns as NoneType because it originates from "BallDetector" from pitop.processing.algorithms, which is prewritten and which I know nothing about. I have a feeling that the coordinate ranges are not formatted correctly, but mainly I want to know how to recall the "color_ball.center" without getting an error. I would greatly appreciate any insight whether or not it fixes my problem, and I am aware that my coding skills are not amazing so I appreciate any sort of criticism.
I tried defining it as an integer, but I can't because it isn't a string or number. I tried rewriting it as it appears in a prewritten f-string but that is still a NoneType. I am not even sure what I expected because I don't really understand why it is a NoneType.
It looks like Ball.center
is None
if the ball has not been detected. There's even a property specifically for testing that:
@property
def found(self) -> bool:
"""
:return: Boolean to determine if a valid ball was found in the frame.
:rtype: bool
"""
return self.center is not None
So, you might want to test something like
if blue_ball.found and (30,50) <= blue_ball.center <= (60, 80):
I'm not certain that is exactly right for your code, it depends what you want to do if the ball isn't there. You haven't shown enough context for me to really guess. You might need to add an else
clause to your if
, if you need to actually do something in that case, rather than just skipping whatever the body of the if
has.