Here it is Guys…
Notice: I modified the robot design orientation a little, so it won’t look the same on the original demo video.
Overview: [url]- YouTube
On the floor: [url]- YouTube
static int percentValue = 60;
static FEZ_Components.DistanceDetector A1 = new FEZ_Components.DistanceDetector(FEZ_Pin.AnalogIn.An1, FEZ_Components.DistanceDetector.SharpSensorType.GP2D120);
static FEZ_Components.DistanceDetector A2 = new FEZ_Components.DistanceDetector(FEZ_Pin.AnalogIn.An2, FEZ_Components.DistanceDetector.SharpSensorType.GP2D120);
static FEZ_Components.DistanceDetector A3 = new FEZ_Components.DistanceDetector(FEZ_Pin.AnalogIn.An3, FEZ_Components.DistanceDetector.SharpSensorType.GP2D120);
static FEZ_Components.ReflectiveSensor InputPortA6 = new FEZ_Components.ReflectiveSensor(FEZ_Pin.AnalogIn.An6, percentValue);
static FEZ_Components.ReflectiveSensor InputPortA7 = new FEZ_Components.ReflectiveSensor(FEZ_Pin.AnalogIn.An7, percentValue);
float far = 7;
float near = 4;
while (true)
{
//all clear, go freakin full speed
if (A1.GetDistance_cm() >= far+2 &&
A2.GetDistance_cm() >= far &&
A3.GetDistance_cm() >= far &&
!((int)InputPortA6.GetState() == 1 || (int)InputPortA7.GetState() == 1))
{
if (!((int)InputPortA6.GetState() == 1 || (int)InputPortA7.GetState() == 1))
FEZMini_Robot.MoveRamp(65, 65, 0);
}
//reduce speed getting ready to stop
else if (A1.GetDistance_cm() >= near+2 && A1.GetDistance_cm() <= far+2 &&
A2.GetDistance_cm() >= near && A2.GetDistance_cm() <= far &&
A3.GetDistance_cm() >= near && A3.GetDistance_cm() <= far &&
!((int)InputPortA6.GetState() == 1 || (int)InputPortA7.GetState() == 1))
{
if (!((int)InputPortA6.GetState() == 1 || (int)InputPortA7.GetState() == 1))
FEZMini_Robot.MoveRamp(40,40, 0);
}
//at least one sensor closes to an object
else if ((A1.GetDistance_cm() <= near+2 ||
A2.GetDistance_cm() <= near ||
A3.GetDistance_cm() <= near) &&
(A2.GetDistance_cm() >= A3.GetDistance_cm()) &&
!((int)InputPortA6.GetState() == 1 || (int)InputPortA7.GetState() == 1)) {
//turn left
while (
A1.GetDistance_cm() <= near+2 ||
A3.GetDistance_cm() <= near &&
!((int)InputPortA6.GetState() == 1 || (int)InputPortA7.GetState() == 1) )
FEZMini_Robot.MoveRamp(-22,80,0);
for (int ii = 0; ii < 7 && !((int)InputPortA6.GetState() == 1 || (int)InputPortA7.GetState() == 1); ii++)
FEZMini_Robot.MoveRamp(80,-10,0);
}
//at least one sensor closes to an object
else if ((A1.GetDistance_cm() <= near+2 ||
A2.GetDistance_cm() <= near ||
A3.GetDistance_cm() <= near) &&
(A2.GetDistance_cm() < A3.GetDistance_cm() &&
!((int)InputPortA6.GetState() == 1 || (int)InputPortA7.GetState() == 1))
) {
//turn right
while (
A1.GetDistance_cm() <= near+2 ||
A2.GetDistance_cm() <= near &&
!((int)InputPortA6.GetState() == 1 || (int)InputPortA7.GetState() == 1))
FEZMini_Robot.MoveRamp(80,-22,0);
for (int ii = 0; ii < 7 && !((int)InputPortA6.GetState() == 1 || (int)InputPortA7.GetState() == 1) ; ii++)
FEZMini_Robot.MoveRamp(-10,80,0);
}
//possibly stuck, back up a litle
if ((int)InputPortA6.GetState() == 1 || (int)InputPortA7.GetState() == 1)
{
FEZMini_Robot.MoveRamp(0,0,0);
for (int ii = 0; ii <2; ii++)
{
FEZMini_Robot.Beep(5000, 300);
Thread.Sleep(300);
FEZMini_Robot.MoveRamp(-40, -40, 0);
Debug.Print("II: " + ii.ToString());
}
}
}//while