I think I figured out what was wrong with the Distance US3 driver and it might be a .NetMF problem (or maybe this is how it works now) which might impact other modules.
I needed a ranger finder for my robot that I’m building for my presentation tomorrow night (like an idiot I promised a robot and some other devices) and so after blowing a day working on drivers for different ranging devices, I might have found out what was wrong with the Distance US3 Driver, but I thought I better check and see if its a known problem and waiting on a fix.
I’ll do a full CodeShare Wednesday if anyone thinks its a good idea, but the guts of it is:
public double GetDistance()
{
long start = 0;
long end = 0;
int counter = 0;
this.trigger.Write(false);
Thread.Sleep(10);
this.trigger.Write(true);
Thread.Sleep(1);
this.trigger.Write(false);
while (!this.echo.Read())
{
if (counter++ > 1000)
return -1.0;
Thread.Sleep(0);
}
start = Utility.GetMachineTime().Ticks;
counter = 0;
while (echo.Read())
{
if (counter++ > 1000)
return -2.0;
Thread.Sleep(0);
}
end = Utility.GetMachineTime().Ticks;
if (counter == 0)
return -3.0;
Debug.Print("delta: " + (end - start).ToString());
double echoTime = (((end - start) / TicksPerMicrosecond)) / 2.0;
Debug.Print("Echo: " + echoTime.ToString());
double distance = echoTime * 34.32;
Debug.Print("Distance: " +distance.ToString());
return distance;
}
The issue was I was looking for the read to go true, when in fact when it goes false works, hence why I wonder if its a .NetMF thing.
My code might need some tuning etc, but it seemed to be giving me workable distances which at the moment is good enough for the girls I date.