Society of Robots - Robot Forum
Software => Software => Topic started by: ed1380 on December 04, 2009, 12:21:24 PM
-
Im making a robot for a semester project. since the programmer on our team knows nothing, im doing the programing. The prolems im having is using an IR line tracker as a linear encoder. I can make it count when it hits the black line, but it continues incrementing as long as its on the line. I dont want it to count black or white. I want it to count the amount of changes occuring.
BTW this is for a gantry crane complete with mockup construction site.
BTW using vex. i get an analong imput of 50-950
-
Add a "state" variable. That variable keeps track of what was the previous change.
For example, the robot starts on black. Set the state to 1 as black. In the loop, check what the reading is. If it is still black, don't do anything. Basically, while it is on the black, it checks to see if the state is at black, and if it is, that means the robot didn't move.
If the reading is white, and the state is black, that means it has changed state. Set the state to 0 for white, and then repeat the above, except ignore the values that are white, since the state is already white.
-
thanks :D
took a good hour but it works ^_^
made it count on both dark and light