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() - starttime; //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.