![]() |
Autonomous Photosensor Programming
So my team wants me to program a photosensor in Java for our Autonomous code, but no matter where I look I can not find anything on any sample code that can help me. Is there anybody out there who can help me in the slightest? You help would be much appreciated :yikes:
|
Re: Autonomous Photosensor Programming
In NetBeans, if you create a new FRC Project, and choose from the FRC Sample Projects, you can see one that is a line following project. If you create that project, you can see the example code. It's a bit hard to follow, but it works on the a few basic premises:
1) Using the driver station's digital inputs to choose whether to follow the straight or narrow, and whether to go left or right at the fork 2) Changing the motor's speed based on the time that has elapsed 3) Getting the values from the light sensors and storing it in an integer as a single binary string, i.e. 111 (7) is all sensors on, 000 (0) is all sensors off, 010 (2) is the middle sensor on, etc. 4) Running a switch statement based on the binary string to determine how much to turn. Take a look through it, and if you have any questions, feel free to come back and ask. |
Re: Autonomous Photosensor Programming
Quote:
The sensors are DigitalInputs, and they have a get() function that returns true if the tape is sensed, false if not. See the example below. Code:
DigitalInput middle, right, left; |
Re: Autonomous Photosensor Programming
In the best of worlds (you starting off right on the line) that will probably keep you on the line, though in any case you'll be wobbling back and forth (and if you can't count on your orientation, good luck hanging a tube!), and if you happen to pass the line by a bit (as will likely happen) you'll just stop.
That's a really good concept to start with, but it needs more fleshing out. |
Re: Autonomous Photosensor Programming
This is all helpful, I only wish I had more expertise in Java. This is still kind of a new thing for me to learn so I am completely out of my league. Thank you for your help! If you are able to help a little more on the
if(middle.get()) concept that would help. I can't help but feel I am missing something here. |
Re: Autonomous Photosensor Programming
Quote:
|
Re: Autonomous Photosensor Programming
Well heres a new development, we only own one photosensor, so should I only have the middle part of the code? Or should I use a whole new code?
|
Re: Autonomous Photosensor Programming
You should have gotten three of the photoelectic sensors in the Kit of Parts.
As others have said, you want to put the three line sensors in a row, spaced apart a little. Then you have to adjust them such that the LED's on the sensors change colors as you move the robot past the tape. Then, depending on how you wired them, you will get a value from the sensor with a digitalinput. The Get method returns a value, 1 or 0 when the sensor sees the line, or doesn't, depending on how you wired them. From there, you basically go forward while the center one is on the line, then if either side sees the tape, turn a bit until only the center sees the line. |
Re: Autonomous Photosensor Programming
Here's my teams code that I wrote for this. We can do the Y + the straight profiles of the line. Since this is fairly outdated I am not to worried about leeching.
Code:
/* |
Re: Autonomous Photosensor Programming
How are you guys programming your Y's? I'm having some trouble with mine. Any tips would be really appreciated.
|
Re: Autonomous Photosensor Programming
Quote:
Code:
if(left.get() && !middle.get() && right.get()) { |
| All times are GMT -5. The time now is 11:29. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi