Main Site Documentation

Robot Driving Logic Needed


#1

Hello Experts,

Anyone know of good code to drive the mini robot with say… couple distance sensors? I can crack my head and try to “re-invent the wheel”… come up with the logic for it but It will make me loose more hair, and I bet it will still be buggy.

Thank You!


#2

Always use baby steps…first, were you able to more the robot? rotate? go backwards?


#3

Yes,

I am able to move robot, read signal from reflective sensor and act acordingly like backing up, etc.
Thanks!


using System;
using Microsoft.SPOT;
using System.Threading;
using GHIElectronics.NETMF.FEZ;
namespace FEZ_Mini_DEMO
{

    public class Program
    {
        static FEZ_Components.DistanceDetector myRanger = new FEZ_Components.DistanceDetector(FEZ_Pin.AnalogIn.An1,  FEZ_Components.DistanceDetector.SharpSensorType.GP2D120);
        static FEZ_Components.ReflectiveSensor InputPortA6 = new FEZ_Components.ReflectiveSensor(FEZ_Pin.AnalogIn.An6, 10);
        static FEZ_Components.ReflectiveSensor InputPortA7 = new FEZ_Components.ReflectiveSensor(FEZ_Pin.AnalogIn.An7, 10);
        static FEZ_Components.ServoMotor myServo = new FEZ_Components.ServoMotor(FEZ_Pin.Digital.Di8);

        public static void Main()
        {           
            FEZ_Components.LED OnBoardLED = new FEZ_Components.LED(FEZ_Pin.Digital.LED);
            OnBoardLED.StartBlinking(100, 500);
 
            for (int i = 1000; i < 10000; i += 100)
                FEZMini_Robot.Beep(i, 10); 

            while (true){
               if ((byte)InputPortA6.GetState()==1 || (byte)InputPortA7.GetState()==1)
                { 
                    FEZMini_Robot.MoveRamp(-40, -40, 0);//backing up a little
                    FEZMini_Robot.MoveRamp(-60, 10, 0); //turn around
                    FEZMini_Robot.MoveRamp(0, 0, 0);
                   

                    FEZMini_Robot.Beep(6000, 300); //make some noise 
                    Thread.Sleep(500);
                    FEZMini_Robot.Beep(6000, 300);
                    Thread.Sleep(500);
                    FEZMini_Robot.Beep(6000, 300);
                }                 
                else
                {
                    FEZMini_Robot.MoveRamp(50, 50, 0); //Left +, Right + 
                } 
            }
        } 
    } 
}