Hi, I am new to using sensors so i looked an old post on the forum to get some help and it helped me slightly. I am planning on using an optical sensor to sense the colour of the roller and spin a motor until it is the other colour.
I have a few questions.
First, what do i swap blueball for in this line of code
in the line of code you are using, blueball is a Function, so when it detects an object then it runs blueball, the line of code you are probably looking for would be
(Optical.color()) this should return the color of what its looking at and then you can compare that to a range of acceptable values for the red and blue sides to know which side you are looking at, and spin the roller accordingly.
All that says is when an object is detected, run the function blueball, if you have a function named blue ball that will do somthing, then you need that, otherwise it is not something you need
Hue is a good way to detect, being more precise, but the sensor already comes with color presets, as seen in Jpearman’s post here. you can just use Optical1.color() == vex::blue or a different color like Optical1.color() == vex::red. Hope this helps!
While theoretically correct, using ranges of hue values is safer in the real world as there may be different lighting, wear on the object, etc.
The value of hue in the HSV (Hue, Saturation, Value) encoding scheme is based on the orientation of the color wheel, explained in detail here: HSL and HSV - Wikipedia
I had a similar issue in my code and this is the problem. You are telling the motor to stop spinning if no bumpers are pressed regardless of what color the optical sees. This causes the motor to constantly stop even if the optical sensor sees the right color.
Not connected to why it isn’t spinning but you should maybe remove the waitUntil unless you’re fine with not having any control over your robot until the roller is the correct color. Does it spin when you place it in front of the rollers? Does it spin when you use the bumpers?
I have decided to change my plan to having the optical sensor spin the motor in autonomous. I don’t know how to do this. Can anyone help me with this