I am currently using Pros to create a program that goes to a specific location using the vision sensor.
In order to find the location, the robot needs to spin around until it finds a certain color signature. Then the robot needs to center with the color and move forward until it gets there.
I tried to create the first part where it spins to find the color signature, but it doesn’t work. The robot spins but doesn’t stop when the vision sensor sees something (The LED on the sensor turns green).
I actually had the same question when experimenting with the vision sensor. I wanted the robot to:
Initially, I took the same approach and had the same result:
So I took a slightly different approach and asked myself: what signature is returned when the vision sensor does not see any valid signatures? It turns out it will return 255 when it does not recognize any signatures. (This may be why your robot keeps turning since 255 != 2) So you can say:
while (test.signature == 255){
//keep turning
}
If you want to take your detection one step further, you can increment a counter variable every time test.signature != 255 is detected. Once the counter exceeds n, the robot can verify that a valid signature is actually in the field of the view of the vision sensor. This can hopefully prevent the loop from ending early if it sees a valid signature just once. Then the robot knows it no longer needs to continue turning (or what I call hunting since this phase is just looking for target, and the next phase still continues to turn while making the adjustments according to the vision sensor’s feedback ).
Another thing you can do is to suggest a direction for the robot to hunt. For example, if I knew my target was consistently to the left of the robot before the vision sensor did its correction then I could specify a parameter: direction with value of either {-1,1} and multiply it by the hunting speed. That way the robot would hunt for the signature in the closer direction. This is a very basic form of feed-forward control.
In your code, you simply have to change:
I know this is a lot of information to take in, so please let me know if you have any questions or want some clarification. Also, share what your results are! I’m very interested in this topic.
I don’t get why it doesn’t work becaus the logic seems right.
Also, what @_Colossus said for moving forward, I don’t quite get it. I was thinking of getting the coordinates of the signature and use if statement to move left or right based on the x coordinates and if the object is within the ‘okay’ zone, it moves forward. Does this logic sound right?
@MiPlayer123
I think the values of test.signature and test2.signature are not being updated. Try adding test = Vision.get_by_code(0, 2); inside of the while loop, so the value of test.signature will get updated.
What you said worked, then stopped working. It spun until it detected the color and stopped. I also added the part where it mover forward, which sort of worked. I didn’t change anything, but the program stopped working. Sometimes I let it run for a while, then it would stop, but it is inconsistent. Any ideas?
Here is my code:
It might depend on the lighting in the room. Depending on the surface that you are trying to “see” or the angle of the vision sensor, it may not be able to see the color properly. You should put pros::lcd::print(7,"%s" "%d", "Sig1 Turn: ", test.signature); in driver control and see if its properly picking up the colors all the time.