public MoveClickEventArgs(MotorMove mv, Axe a, Sens s, Couronne c)
 {
     MotorMove = mv;
     Axe       = a;
     Sens      = s;
     Couronne  = c;
 }
        private void moveClick(object sender, EventArgs e)
        {
            var txt = (sender as Button)?.Tag as string;

            if (txt?.Length != 3)
            {
                return;                   // le tag du bouton doit être de la forme X2+ (X:axe, 2:nieme courronne, +:sens)
            }
            Axe axe;

            if (!Enum.TryParse <Axe>(txt[0].ToString(), out axe))
            {
                return;
            }

            var mv = new MotorMove(axe);

            int sens;

            switch (txt[2])
            {
            case '+':
                sens = 1;
                break;

            case '-':
                sens = -1;
                break;

            default:
                return;
            }

            Couronne couronne;

            switch (txt[1])
            {
            case '1':
                mv.MaxMovesCount = sens;
                couronne         = Couronne.Max;
                break;

            case '2':
                mv.MidMaxMovesCount = sens;
                couronne            = Couronne.MidMax;
                break;

            case '3':
                mv.MidMinMovesCount = sens;
                couronne            = Couronne.MidMin;
                break;

            default:
                return;
            }

            MoveClick(sender, new MoveClickEventArgs(mv, axe, (Sens)sens, couronne));
        }
Esempio n. 3
0
        public void BlockingMove(MotorMove mv, TimeSpan timeout)
        {
            var config = GetHardwareConfig();

            if (config.Simulated)
            {
                System.Threading.Thread.Sleep(mv.QuarterNumber * config.SimulatedTime);
                return;
            }

            byte[] m = new byte[2] {
                0xFF, 0xFF
            };
            int[] r = new int[2] {
                0, 0
            };

            Motor[] motors;
            using (var state = GlobalState.GetState())
            {
                motors = state.Motors.Motors.Where((x) => x.Axe == mv.Axe && x.Board == this.Index).Select((x) => (Motor)x.Clone()).ToArray();
            }

            if (motors.Count() == 0)
            {
                return;
            }
            else if (motors.Count() > 2)
            {
                throw new Exception("Il ne peut pas y avoir plus de deux moteurs pas à pas pilotés en même temps pour des questions de performance");
            }

            using (var state = GlobalState.GetState())
            {
                for (int i = 0; i < motors.Length; i++)
                {
                    m[i] = motors[i].Index;

                    //r[i] = state.HardwareConfigGlobal.ConvertMoveToSteps(mv.GetMoves(motors[i].Courronne), motors[i].Inverted);
                }
            }

            // pas de mouvement, rien ne sert d'envoyer 0
            if (r[0] == 0 && r[1] == 0)
            {
                return;
            }

            AssertConnectedAndConfigured(config);
            var ret = BlockingMove(timeout, m[0], r[0], m[1], r[1]);

            if (!ret.Value)
            {
                throw new Exception("Impossible d'exécuter le mouvement " + mv.ToString());
            }
        }
        private void btnTestMotorMoves_Click(object sender, EventArgs e)
        {
            Axe axe;

            if (Enum.TryParse <Axe>(cbAxe.Text, out axe))
            {
                var mv = new MotorMove(axe);
                mv.MaxMovesCount    = (int)udCourronneMax.Value;
                mv.MidMaxMovesCount = (int)udCourronneMidMax.Value;
                mv.MidMinMovesCount = (int)udCourronneMidMin.Value;

                ExecuteMachineMove(mv);
            }
        }
        public void ExecuteMachineMove(MotorMove mv)
        {
            int[] moves = { 0, mv.MaxMovesCount, mv.MidMaxMovesCount, mv.MidMinMovesCount };

            int[,] indexes = { { 1, 3 }, { 1, 2 }, { 1, 1 }, { 2, 3 }, { 2, 2 }, { 3, 3 } };

            while (moves[1] != 0 || moves[2] != 0 || moves[3] != 0)
            {
                for (int i = 0; i < indexes.Length / 2; i++)
                {
                    int startLayer = indexes[i, 0];
                    int endLayer   = indexes[i, 1];
                    int amount     = moves[startLayer];

                    for (int j = startLayer + 1; j <= endLayer; j++)
                    {
                        if (Math.Sign(moves[j]) != Math.Sign(amount))
                        {
                            amount = 0;;
                            break;
                        }
                        else if (amount > 0 && moves[j] < amount || amount <0 && moves[j]> amount)
                        {
                            amount = moves[j];
                        }
                    }

                    if (amount != 0)
                    {
                        for (int j = startLayer; j <= endLayer; j++)
                        {
                            moves[j] -= amount;
                        }

                        Move(mv.Axe, startLayer, endLayer, amount);

                        break;
                    }
                }
            }
        }