Exemple #1
0
        public void AppendCommand(Command command)
        {
            var current = Command;

            if (current == null || current == Command.Default)
            {
                Command = command;
            }
            else
            {
                var group = new Commands.Group();

                if (current is Commands.Group currentGroup)
                {
                    group.AddRange(currentGroup);
                }
                else
                {
                    group.Add(current);
                }

                group.Add(command);
                Command = group;
            }
        }
Exemple #2
0
        public Program(string name, RobotSystem robotSystem, IEnumerable <IEnumerable <Target> > targets, Commands.Group initCommands = null, IEnumerable <int> multiFileIndices = null, double stepSize = 1.0)
        {
            if (targets.SelectMany(x => x).Count() == 0)
            {
                throw new Exception(" The program has to contain at least 1 target");
            }

            int targetCount = targets.First().Count();

            foreach (var subTargets in targets)
            {
                if (subTargets.Count() != targetCount)
                {
                    throw new Exception(" All sub programs have to contain the same number of targets");
                }
            }

            this.Name        = name;
            this.RobotSystem = robotSystem;

            this.InitCommands = new Commands.Group();
            if (initCommands != null)
            {
                this.InitCommands.AddRange(initCommands.Flatten());
            }

            if (multiFileIndices != null && multiFileIndices.Count() > 0)
            {
                multiFileIndices      = multiFileIndices.Where(x => x < targetCount);
                this.MultiFileIndices = multiFileIndices.ToList();
                this.MultiFileIndices.Sort();
                if (this.MultiFileIndices.Count == 0 || this.MultiFileIndices[0] != 0)
                {
                    this.MultiFileIndices.Insert(0, 0);
                }
            }
            else
            {
                this.MultiFileIndices = new int[1].ToList();
            }

            var cellTargets = new List <CellTarget>(targetCount);

            int targetIndex = 0;

            foreach (var subTargets in targets.Transpose())
            {
                var programTargets = subTargets.Select((x, i) => new ProgramTarget(subTargets[i], i));
                var cellTarget     = new CellTarget(programTargets, targetIndex);
                cellTargets.Add(cellTarget);
                targetIndex++;
            }

            var checkProgram = new CheckProgram(this, cellTargets, stepSize);
            int indexError   = checkProgram.indexError;

            if (indexError != -1)
            {
                cellTargets = cellTargets.GetRange(0, indexError + 1).ToList();
            }
            this.Targets = cellTargets;

            this.simulation = new Simulation(this, checkProgram.keyframes);

            if (Errors.Count == 0)
            {
                Code = RobotSystem.Code(this);
            }
        }