예제 #1
0
        private void StartFromSliderChange(object sender, RoutedPropertyChangedEventArgs <double> e)
        {
            if (Global.loadingDone == true)
            {
                if (listBox.SelectedIndex == 0)
                {
                    movement.elbow0.startfrom = Math.Round(start.Value, 2);
                    startFrom.Content         = "+ " + Math.Round(Arm.PwmToDegree(start.Value), 2) + " °";

                    double avalible = 180 - Arm.PwmToDegree(start.Value) - (180 - Arm.PwmToDegree(max.Value));
                    availableD.Content = Math.Round(avalible, 2).ToString() + " °";
                }
                else if (listBox.SelectedIndex == 1)
                {
                    movement.elbow1.startfrom = Math.Round(start.Value, 2);
                    startFrom.Content         = "+ " + Math.Round(Arm.PwmToDegree(start.Value), 2) + " °";

                    double avalible = 180 - Arm.PwmToDegree(start.Value) - (180 - Arm.PwmToDegree(max.Value));
                    availableD.Content = Math.Round(avalible, 2).ToString() + " °";
                }
                else if (listBox.SelectedIndex == 2)
                {
                    movement.elbow2.startfrom = Math.Round(start.Value, 2);
                    startFrom.Content         = "+ " + Math.Round(Arm.PwmToDegree(start.Value), 2) + " °";

                    double avalible = 180 - Arm.PwmToDegree(start.Value) - (180 - Arm.PwmToDegree(max.Value));
                    availableD.Content = Math.Round(avalible, 2).ToString() + " °";
                }
                else if (listBox.SelectedIndex == 3)
                {
                    movement.baseMovemend.startfrom = Math.Round(start.Value, 2);
                    startFrom.Content = "+ " + Math.Round(Arm.PwmToDegree(start.Value), 2) + " °";

                    double avalible = 180 - Arm.PwmToDegree(start.Value) - (180 - Arm.PwmToDegree(max.Value));
                    availableD.Content = Math.Round(avalible, 2).ToString() + " °";
                }
                else if (listBox.SelectedIndex == 4)
                {
                    movement.griperRotation.startfrom = Math.Round(start.Value, 2);
                    startFrom.Content = "+ " + Math.Round(Arm.PwmToDegree(start.Value), 2) + " °";

                    double avalible = 180 - Arm.PwmToDegree(start.Value) - (180 - Arm.PwmToDegree(max.Value));
                    availableD.Content = Math.Round(avalible, 2).ToString() + " °";
                }
                else if (listBox.SelectedIndex == 5)
                {
                    movement.griper.startfrom = Math.Round(start.Value, 2);
                    startFrom.Content         = "+ " + Math.Round(Arm.PwmToDegree(start.Value), 2) + " °";

                    double avalible = 180 - Arm.PwmToDegree(start.Value) - (180 - Arm.PwmToDegree(max.Value));
                    availableD.Content = Math.Round(avalible, 2).ToString() + " °";
                }
            }
        }
예제 #2
0
        private async void ObjectFollow(string msg)
        {
            string [] data    = msg.Split('*');
            int       speed   = Convert.ToInt32(data[2]);
            string    command = "";

            if (data[0] == "1")
            {
                command = (movement.baseMovemend.AngleInDegree - speed).ToString() + "*";
            }
            else if (data[0] == "2")
            {
                command = (movement.baseMovemend.AngleInDegree + speed).ToString() + "*";
            }
            else
            {
                command = movement.baseMovemend.AngleInDegree.ToString() + "*";
            }

            command += movement.elbow0.AngleInDegree.ToString() + "*";

            if (data[1] == "2")
            {
                if (movement.elbow2.AngleInDegree - speed < Arm.PwmToDegree(movement.elbow2.startfrom))
                {
                    command += (movement.elbow1.AngleInDegree - speed).ToString() + "*" + movement.elbow2.AngleInDegree.ToString() + "*";
                }
                else
                {
                    command += movement.elbow1.AngleInDegree.ToString() + "*" + (movement.elbow2.AngleInDegree - speed).ToString() + "*";
                }
            }
            else if (data[1] == "1")
            {
                if (movement.elbow2.AngleInDegree + speed > Arm.PwmToDegree(movement.elbow2.EndAt))
                {
                    command += (movement.elbow1.AngleInDegree + speed).ToString() + "*" + movement.elbow2.AngleInDegree.ToString() + "*";
                }
                else
                {
                    command += movement.elbow1.AngleInDegree.ToString() + "*" + (movement.elbow2.AngleInDegree + speed).ToString() + "*";
                }
            }
            else
            {
                command += movement.elbow1.AngleInDegree.ToString() + "*" + movement.elbow2.AngleInDegree.ToString() + "*";
            }

            command += movement.griperRotation.AngleInDegree.ToString() + "*" + movement.griper.AngleInDegree.ToString() + "*0*0*1.5";

            await AutoModeTemplate.ScriptDefaultMovemend(command, movement);

            SendACK();
        }
예제 #3
0
        private void GetAngle()
        {
            angles[2, 0] = movement.elbow0.AngleInDegree;
            angles[1, 0] = movement.elbow1.AngleInDegree;
            angles[0, 0] = movement.elbow2.AngleInDegree;

            angles[2, 1] = Arm.PwmToDegree(movement.elbow0.startfrom);
            angles[1, 1] = Arm.PwmToDegree(movement.elbow1.startfrom);
            angles[0, 1] = Arm.PwmToDegree(movement.elbow2.startfrom);

            angles[2, 2] = Arm.PwmToDegree(movement.elbow0.EndAt);
            angles[1, 2] = Arm.PwmToDegree(movement.elbow1.EndAt);
            angles[0, 2] = Arm.PwmToDegree(movement.elbow2.EndAt);
        }
예제 #4
0
        private void MotorCalibrationDisplay()
        {
            if (listBox.SelectedIndex == 0 && max != null)
            {
                max.Maximum    = Arm.max_Pwm;
                max.Minimum    = Arm.min_Pwm;
                max.Value      = movement.elbow0.EndAt;
                maxUse.Content = Math.Round(Arm.PwmToDegree(max.Value), 2) + " °";

                start.Maximum     = Arm.max_Pwm;;
                start.Minimum     = Arm.min_Pwm;;
                start.Value       = movement.elbow0.startfrom;
                startFrom.Content = "+ " + Math.Round(Arm.PwmToDegree(start.Value), 2) + " °";

                double avalible = 180 - Arm.PwmToDegree(start.Value) - (180 - Arm.PwmToDegree(max.Value));
                availableD.Content = Math.Round(avalible, 2).ToString() + " °";
            }
            else if (listBox.SelectedIndex == 1)
            {
                max.Maximum    = Arm.max_Pwm;
                max.Minimum    = Arm.min_Pwm;
                max.Value      = movement.elbow1.EndAt;
                maxUse.Content = Math.Round(Arm.PwmToDegree(max.Value), 2) + " °";

                start.Maximum     = Arm.max_Pwm;;
                start.Minimum     = Arm.min_Pwm;;
                start.Value       = movement.elbow1.startfrom;
                startFrom.Content = "+ " + Math.Round(Arm.PwmToDegree(start.Value), 2) + " °";

                double avalible = 180 - Arm.PwmToDegree(start.Value) - (180 - Arm.PwmToDegree(max.Value));
                availableD.Content = Math.Round(avalible, 2).ToString() + " °";
            }
            else if (listBox.SelectedIndex == 2)
            {
                max.Maximum    = Arm.max_Pwm;
                max.Minimum    = Arm.min_Pwm;
                max.Value      = movement.elbow2.EndAt;
                maxUse.Content = Math.Round(Arm.PwmToDegree(max.Value), 2) + " °";

                start.Maximum     = Arm.max_Pwm;;
                start.Minimum     = Arm.min_Pwm;;
                start.Value       = movement.elbow2.startfrom;
                startFrom.Content = "+ " + Math.Round(Arm.PwmToDegree(start.Value), 2) + " °";

                double avalible = 180 - Arm.PwmToDegree(start.Value) - (180 - Arm.PwmToDegree(max.Value));
                availableD.Content = Math.Round(avalible, 2).ToString() + " °";
            }
            else if (listBox.SelectedIndex == 3)
            {
                max.Maximum    = Arm.max_Pwm;
                max.Minimum    = Arm.min_Pwm;
                max.Value      = movement.baseMovemend.EndAt;
                maxUse.Content = Math.Round(Arm.PwmToDegree(max.Value), 2) + " °";

                start.Maximum     = Arm.max_Pwm;;
                start.Minimum     = Arm.min_Pwm;;
                start.Value       = movement.baseMovemend.startfrom;
                startFrom.Content = "+ " + Math.Round(Arm.PwmToDegree(start.Value), 2) + " °";

                double avalible = 180 - Arm.PwmToDegree(start.Value) - (180 - Arm.PwmToDegree(max.Value));
                availableD.Content = Math.Round(avalible, 2).ToString() + " °";
            }
            else if (listBox.SelectedIndex == 4)
            {
                max.Maximum    = Arm.max_Pwm;
                max.Minimum    = Arm.min_Pwm;
                max.Value      = movement.griperRotation.EndAt;
                maxUse.Content = Math.Round(Arm.PwmToDegree(max.Value), 2) + " °";

                start.Maximum     = Arm.max_Pwm;;
                start.Minimum     = Arm.min_Pwm;;
                start.Value       = movement.griperRotation.startfrom;
                startFrom.Content = "+ " + Math.Round(Arm.PwmToDegree(start.Value), 2) + " °";

                double avalible = 180 - Arm.PwmToDegree(start.Value) - (180 - Arm.PwmToDegree(max.Value));
                availableD.Content = Math.Round(avalible, 2).ToString() + " °";
            }
            else if (listBox.SelectedIndex == 5)
            {
                max.Maximum    = Arm.max_Pwm;
                max.Minimum    = Arm.min_Pwm;
                max.Value      = movement.griper.EndAt;
                maxUse.Content = Math.Round(Arm.PwmToDegree(max.Value), 2) + " °";

                start.Maximum     = Arm.max_Pwm;;
                start.Minimum     = Arm.min_Pwm;;
                start.Value       = movement.griper.startfrom;
                startFrom.Content = "+ " + Math.Round(Arm.PwmToDegree(start.Value), 2) + " °";

                double avalible = 180 - Arm.PwmToDegree(start.Value) - (180 - Arm.PwmToDegree(max.Value));
                availableD.Content = Math.Round(avalible, 2).ToString() + " °";
            }
        }
예제 #5
0
        public static async Task ScriptDefaultMovemend(string rawcommand, Movement movement)
        {
            if (Global.IsMoving == true)
            {
                Global.stopmovement = true;
                Thread.Sleep(100);
            }

            Global.stopmovement = false;
            Global.IsMoving     = true;

            string        command         = rawcommand;
            List <string> instructionsRaw = command.Split('*').ToList();
            List <double> instructions    = new List <double>();

            foreach (var item in instructionsRaw)
            {
                instructions.Add(Convert.ToDouble(item));
            }

            if (instructions[0] == -1)
            {
                instructions[0] = movement.baseMovemend.AngleInPWM;
            }
            else
            {
                instructions[0] = Arm.DegreeToPwm(instructions[0]);
            }

            if (instructions[1] == -1)
            {
                instructions[1] = movement.elbow0.AngleInPWM;
            }
            else
            {
                instructions[1] = Arm.DegreeToPwm(instructions[1]);
            }

            if (instructions[2] == -1)
            {
                instructions[2] = movement.elbow1.AngleInPWM;
            }
            else
            {
                instructions[2] = Arm.DegreeToPwm(instructions[2]);
            }

            if (instructions[3] == -1)
            {
                instructions[3] = movement.elbow2.AngleInPWM;
            }
            else
            {
                instructions[3] = Arm.DegreeToPwm(instructions[3]);
            }

            if (instructions[4] == -1)
            {
                instructions[4] = movement.griperRotation.AngleInPWM;
            }
            else
            {
                instructions[4] = Arm.DegreeToPwm(instructions[4]);
            }

            if (instructions[5] == -1)
            {
                instructions[5] = movement.griper.AngleInPWM;
            }
            else
            {
                instructions[5] = Arm.DegreeToPwm(instructions[5]);
            }

            await Task.Run(() =>
            {
                Global.stopmovement       = false;
                bool allMotorsOnPositions = false;
                do
                {
                    allMotorsOnPositions = Moving(instructions, movement);
                    Thread.Sleep(Global.MovingSpeed);

                    if (Global.ScriptEnabled == false || Global.stopmovement == true)
                    {
                        break;
                    }
                } while (allMotorsOnPositions == false);

                Global.IsMoving = false;
            });
        }