Author Topic: ir for linear encoder  (Read 1653 times)

0 Members and 1 Guest are viewing this topic.

Offline ed1380Topic starter

  • Supreme Robot
  • *****
  • Posts: 1,478
  • Helpful? 3
ir for linear encoder
« 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
« Last Edit: December 04, 2009, 12:42:43 PM by ed1380 »
Problems making the $50 robot circuit board?
click here. http://www.societyofrobots.com/robotforum/index.php?topic=3292.msg25198#msg25198

Offline Razor Concepts

  • Supreme Robot
  • *****
  • Posts: 1,856
  • Helpful? 53
    • RazorConcepts
Re: ir for linear encoder
« Reply #1 on: December 04, 2009, 04:17:20 PM »
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.

Offline ed1380Topic starter

  • Supreme Robot
  • *****
  • Posts: 1,478
  • Helpful? 3
Re: ir for linear encoder
« Reply #2 on: December 05, 2009, 01:58:05 PM »
thanks :D
took a good hour but it works ^_^
made it count on both dark and light
Problems making the $50 robot circuit board?
click here. http://www.societyofrobots.com/robotforum/index.php?topic=3292.msg25198#msg25198

 


data_list