Exemplo n.º 1
0
 /// <summary>
 /// Create a vehicule with 2 motors, one left and one right
 /// </summary>
 /// <param name="left">Motor port for left motor</param>
 /// <param name="right">Motor port for right motor</param>
 public Vehicule(BrickPortMotor left, BrickPortMotor right)
 {
     brick = new Brick();
     //brick.Start();
     portleft  = left;
     portright = right;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Create a motor
 /// </summary>
 /// <param name="brick">The brick controlling the motor</param>
 /// <param name="port">Motor port</param>
 /// <param name="timeout">Timeout</param>
 public Motor(Brick brick, BrickPortMotor port, int timeout)
 {
     _brick         = brick;
     Port           = port;
     _periodRefresh = timeout;
     _timer         = new Timer(UpdateSensor, this, TimeSpan.FromMilliseconds(timeout), TimeSpan.FromMilliseconds(timeout));
 }
Exemplo n.º 3
0
 /// <summary>
 /// Create a vehicule with 2 motors, one left and one right
 /// </summary>
 /// <param name="left">Motor port for left motor</param>
 /// <param name="right">Motor port for right motor</param>
 public Vehicule(BrickPortMotor left, BrickPortMotor right)
 {
     brick = new Brick();
     //brick.Start();
     portleft = left;
     portright = right;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Create a vehicule with 2 motors, one left and one right
 /// </summary>
 /// <param name="left">Motor port for left motor</param>
 /// <param name="right">Motor port for right motor</param>
 public Vehicule(Brick brick, BrickPortMotor left, BrickPortMotor right)
 {
     this.brick = brick;
     //brick.Start();
     portleft  = left;
     portright = right;
 }
Exemplo n.º 5
0
 public Motor(BrickPortMotor port, int timeout)
 {
     brick = new Brick();
     Port  = port;
     //brick.Start();
     periodRefresh = timeout;
     timer         = new Timer(UpdateSensor, this, TimeSpan.FromMilliseconds(timeout), TimeSpan.FromMilliseconds(timeout));
 }
Exemplo n.º 6
0
 private bool IsRunning(BrickPortMotor port)
 {
     if (brick.BrickPi.Motor[(int)port].Enable == 0)
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 7
0
 public Motor(BrickPortMotor port, int timeout)
 {
     brick = new Brick();
     Port = port;
     //brick.Start();
     periodRefresh = timeout;
     timer = new Timer(UpdateSensor, this, TimeSpan.FromMilliseconds(timeout), TimeSpan.FromMilliseconds(timeout));
 }
Exemplo n.º 8
0
 private bool IsRunning(BrickPortMotor port)
 {
     //if (brick.BrickPi.Motor[(int)port].Enable == 0)
     try
     {
         if (_brick.GetMotorStatus((byte)port).Speed == 0)
         {
             return(false);
         }
     }
     catch (Exception)
     { }
     return(true);
 }
Exemplo n.º 9
0
 /// <summary>
 /// Create a motor
 /// </summary>
 /// <param name="brick">The brick controlling the motor</param>
 /// <param name="port">Motor port</param>
 public Motor(Brick brick, BrickPortMotor port)
     : this(brick, port, 1000)
 {
 }
Exemplo n.º 10
0
 /// <summary>
 /// Create a vehicule with 2 motors, one left and one right
 /// </summary>
 /// <param name="brick">The brick controlling the motor</param>
 /// <param name="left">Motor port for left motor</param>
 /// <param name="right">Motor port for right motor</param>
 public Vehicule(Brick brick, BrickPortMotor left, BrickPortMotor right)
 {
     this._brick = brick;
     PortLeft    = left;
     PortRight   = right;
 }
Exemplo n.º 11
0
 /// <summary>
 /// Create a motor
 /// </summary>
 /// <param name="port">Motor port</param>
 public Motor(BrickPortMotor port) : this(port, 1000)
 {
 }
Exemplo n.º 12
0
 private bool IsRunning(BrickPortMotor port)
 {
     if (brick.BrickPi.Motor[(int)port].Enable == 0)
         return false;
     return true;
 }
Exemplo n.º 13
0
        private async Task RunMotorSyncDegrees(BrickPortMotor[] ports, int[] speeds, int[] degrees)
        {
            if ((ports == null) || (speeds == null) || degrees == null)
                return;
            if ((ports.Length != speeds.Length) && (degrees.Length != speeds.Length))
                return;
            //make sure we have only positive degrees
            for (int i = 0; i < degrees.Length; i++)
                if (degrees[i] < 0)
                    degrees[i] = -degrees[i];
            //initialize the speed and enable motors
            int[] initval = new int[ports.Length];
            for (int i = 0; i < ports.Length; i++)
            {
                initval[i] = brick.BrickPi.Motor[(int)ports[i]].Encoder;
                StartMotor((int)ports[i], speeds[i]);
            }
            bool nonstop = true;
            while(nonstop)
            {
                bool status = false;
                for (int i = 0; i < ports.Length; i++)
                {
                    if (speeds[i] > 0)
                    {
                        if (brick.BrickPi.Motor[(int)ports[i]].Encoder >= (initval[i] + degrees[i] * 2))
                        {
                            StopMotor((int)ports[i]);
                        }
                    } else
                    {
                        if (brick.BrickPi.Motor[(int)ports[i]].Encoder <= (initval[i] - degrees[i] * 2))
                        {
                            StopMotor((int)ports[i]);
                        }

                    }
                    status |= IsRunning(ports[i]);
                }
                nonstop = status;
            }


        }
Exemplo n.º 14
0
        private async Task RunMotorSyncTime(BrickPortMotor[] ports, int[] speeds, int timeout)
        {
            if ((ports == null) || (speeds == null))
                return;
            if (ports.Length != speeds.Length)
                return;
            //create a timer for the needed time to run
            if (timer == null)
                timer = new Timer(RunUntil, ports, TimeSpan.FromMilliseconds(timeout), Timeout.InfiniteTimeSpan);
            else
                timer.Change(TimeSpan.FromMilliseconds(timeout), Timeout.InfiniteTimeSpan);
            //initialize the speed and enable motors
            for(int i=0; i<ports.Length; i++)
            {
                StartMotor((int)ports[i], speeds[i]);
            }
            bool nonstop = true;
            while(nonstop)
            {
                bool status = false;
                for (int i=0; i<ports.Length;i++)
                {
                    status |= IsRunning(ports[i]);
                }
                nonstop = status;


            }
        }
Exemplo n.º 15
0
 /// <summary>
 /// Create a motor
 /// </summary>
 /// <param name="port">Motor port</param>
 public Motor(BrickPortMotor port)
     : this(port, 1000)
 {
 }