Code not working


I have code to make the robot follow a red ball but it isn’t working I’ve tried fixing it but it isn’t working I’m open to any tips

I am not too familiar with how vision sensors work but I would think that if the object dosn’t exist then there won’t be any x coordinate so it will only ever print red. Also it won’t ever go to the left if the ball is to the left.

  1. “Isn’t working” could mean a lot of things. Maybe you’d like to be more specific?

  2. Your code has no loops, meaning it will run through from top to bottom once and exit.

6 Likes

it’s detecting the red ball and giving the x coord but isn’t turning (there is a turn for both ways i just forgot to add it back in)

1: it gets the center x and then won’t use the number it gets from it so it will say where the center x is but won’t turn
2: I have it set to use a limit switch as a loop so I can change the item/item location without getting an error

You should not be using the if-else block in this way, as you want it to turn when it detects the red object, not when it doesn’t detect it. With the if-else block, your code says this:

If the object exists: print red on the screen.
If the object DOES NOT exist: turn towards it.

Instead, put your turning logic inside of the “if vision5 object exists then:” block.

1 Like

I feel stupid now I have overlooked that prob a million times

Don’t, it is part of the learning process.

4 Likes

after a deep look into my vision sensor struggles I’ve given up bc Ive been working on it for 4 months

1 Like

^

What else is going wrong? We might be able to help. Vision sensors are extremely useful in some cases, and cutting out such a useful sensor from your list of available solutions seems like it will hold you back in the future.

2 Likes

the code i have is detecting the color and working but won’t turn to face the ball no matter what I do including just spinning the robot when it is just seen in other words it detects it but not using any of the info gathered besides printing it

Have you tried turning right or left by the amount of degrees it is off center? What you are currently doing now is just turning infinitely, which seems like is exactly what the robot is doing.

well that’s the issue it isn’t turning at all

Can you send some more up to date code? We are unaware of what changes you have made from the original screenshot.

2 Likes

my code is on the laptop at school so I will have to send it on monday