View Single Post
  #3   Spotlight this post!  
Unread 22-11-2014, 20:52
Jared's Avatar
Jared Jared is offline
Registered User
no team
Team Role: Programmer
 
Join Date: Aug 2013
Rookie Year: 2012
Location: Connecticut
Posts: 602
Jared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond repute
Re: Parallax PING))) Java Coding

Quote:
Originally Posted by cgmv123 View Post
Code:
DigitalOutput.set(true); //Needs to be a properly constructed DigitalOutput object.
Timer.delay(0.00003); //This is a static method.
DigitalOutput*.set(false); //Same object from above.
while {DigitalInput.get()=false} ////Needs to be a properly constructed DigitalInput object.
double starttime=Timer.getFPGATimestamp(); //This is a static method. You can use a Timer object, but I like this method better.
while{DigitalInput.get() = true} //Same object from above.
double pingtime = Timer.getFPGATimestamp(); //Same method from above.
double distance = pingtime * (appropriate scalar);
This should be separately threaded so the microsecond timing doesn't depend on the control loop and so the wait loops don't cause a loss of robot control.
I'm not sure this will work for a few reasons. First, I doubt that our setup with Java on the cRIO (or Java running on anything) will time the 30 microsecond pulse very accurately if you set it up the way you have it now.

Also, you'd need to run this loop really quickly to capture the pulse. If you're one inch away, your pulse is less than a millisecond away. It's possible to miss pulses entirely.

You really should use interrupts for this, or you should just add an arduino board that communicates with the cRIO with serial. I bet somebody has written an arduino library for this sensor.

Also, your timing method doesn't seem to compare the two FPGA timestamps to find the duration of the pulse. I don't think your two while loops will work the way you'd like them to.