
MikeC531
USA
Asked
— Edited
Is there a way of adusting the speed of the scan of the HC-SR04 using the SDK or do you have to do your own timing ?
I noticed in the ARC the interval changes the speed of the sweep, but i can't seem to find any interval in the SDK anywhere for interval, am I missing it somewhere ?
Thanks
Mike
private void getDistances()
{
//Start on the right side
ezb.EZB.Servo.SetServoPosition(_SCAN_SERVO_PIN, _SCAN_RIGHT_MIN);
for (int x = _SCAN_RIGHT_MIN; x <= _SCAN_LEFT_MAX; x += 2)
{
ezb.EZB.HC_SR04.MinPoolTimeMS = 1; //Doesn't seem to see all objects at times above 3
//Set the servo position to x
ezb.EZB.Servo.SetServoPosition(_SCAN_SERVO_PIN, x);
//Get the distance of the object
int distance = ezb.EZB.HC_SR04.GetDistance(_PING_TRIGGER_PIN, _PING_ECHO_PIN);
//Save the distance in an array indexed by the servo position
_markDirArray[ezb.EZB.Servo.GetServoPosition(_SCAN_SERVO_PIN)] = distance;
//Show distance and direction on screen
log("Distance: {0}, Dir: {1}", distance, ezb.EZB.Servo.GetServoPosition(_SCAN_SERVO_PIN));
}
}
private void findShortestPath()
{
log("Started");
//Set _minDist to a large number
_minDist = 100;
zz = false;
do
{
// Find all objects
getDistances();
// Get the shortest path
// getShortestDist();
// turnTowardShortest();
Application.DoEvents();
System.Threading.Thread.Sleep(1150);
} while (zz == false);
}
private void timer1_Tick(object sender, EventArgs e)
{
if (_inProgress)
return;
if (!ezb.EZB.IsConnected)
{
return;
}
_inProgress = true;
findShortestPath();
Application.DoEvents();
_inProgress = false;
}
}
Code:
Got it working now, i guess i was just brain dead for a little while.
Thanks alot
Mike