Line Tracker Help

Does anyone have some code for a line tracker that I could copy for my robot to detect a ball and stop the intakes once the ball is detected?

It would be worthwhile for you to not ask to copy someone’s code and rather develop it yourself.

That being said, the basic idea is that you would have a separate task constantly monitoring the sensor value and switching a Boolean when a ball is present. You can then reference this Boolean in a separate autoIndex task which would manipulate your motors.

Hope that helps


@33691A-Gold_Dusk is quite right on all of their points, especially that you should make your own code.

Also, I’ll assume that you made a mistake and posted this exact topic twice.

Finally, a much easier way would be to simply use either the bumper switch or I would most likely use a limit switch that simply triggers when a ball hits a certain part in your roller.

You could then have a simple code of
while (button not pressed) { run roller motors }
Obviously, this is pseudocode, but I think it portrays the idea.

So as @33691A-Gold_Dusk has mentioned previously, it isn’t worth asking for code to copy on this forum. There are a couple of reasons for this. First, because everyone programs differently, it is unlikely that a segment of code would be “plug and play”. Second, copying code goes against the purpose robot competition, which involves learning to do new things yourself. If I simply give you code, I deprive you the opportunity to develop your coding skills.

Now on to your problem. When I tackle problems like this, I break the problem down into sensing and the intended response. To pick up the ball, play with the line trackers and figure out what values the sensor gives you when a ball passes in front of it. That will inform what the program needs to look for. After this, figure out how you want your intake to work. Do you want it to run until it picks up a ball? Should the driver hold a button? Should it shoot out balls on the same button or a different one? These example questions don’t have a “right” answer and will be different from team to team. Try to develop your own program once you figure out what you want from your robot. If that is too big a jump, make a new program that just detects balls and does something simple when it a ball is detected.

With these ideas in mind, I am confident that myself or the larger community can help you make a working code for your intake. Best of luck!