Пример #1
0
        private bool ShouldSave()
        {
            if (joint.cDriver == null)
            {
                return(true);
            }

            double inputGear = 1, outputGear = 1;

            inputGear  = (double)InputGeartxt.Value;
            outputGear = (double)OutputGeartxt.Value;

            PneumaticDriverMeta pneumatic = joint.cDriver.GetInfo <PneumaticDriverMeta>();
            WheelDriverMeta     wheel     = joint.cDriver.GetInfo <WheelDriverMeta>();
            ElevatorDriverMeta  elevator  = joint.cDriver.GetInfo <ElevatorDriverMeta>();

            Enum.TryParse(MotorTypeDropDown.SelectedItem.ToString(), out MotorType motor);
            if (cmbJointDriver.SelectedIndex != typeOptions.ToList().IndexOf(joint.cDriver.GetDriveType()) + 1 ||
                txtPort1.Value != joint.cDriver.port1 ||
                txtPort2.Value != joint.cDriver.port2 ||
                txtLowLimit.Value != (decimal)joint.cDriver.lowerLimit ||
                txtHighLimit.Value != (decimal)joint.cDriver.upperLimit ||
                inputGear != joint.cDriver.InputGear || outputGear != joint.cDriver.OutputGear ||
                rbCAN.Checked != joint.cDriver.isCan || chkBoxHasBrake.Checked != joint.cDriver.hasBrake ||
                motor != joint.cDriver.motor)
            {
                return(true);
            }

            if (pneumatic != null &&
                (numericUpDownPnuDia.Value != (decimal)pneumatic.width ||
                 cmbPneumaticPressure.SelectedIndex != (int)pneumatic.pressureEnum))
            {
                return(true);
            }

            if (wheel != null &&
                (cmbWheelType.SelectedIndex != (int)wheel.type ||
                 cmbFrictionLevel.SelectedIndex != (int)wheel.GetFrictionLevel() ||
                 chkBoxDriveWheel.Checked != wheel.isDriveWheel))
            {
                return(true);
            }

            if (elevator != null)
            {
                return(true);
            }

            //If going from "NOT A WHEEL" to a wheel
            if (cmbWheelType.SelectedIndex != 0 && wheel == null && joint.cDriver.GetDriveType() == JointDriverType.MOTOR)
            {
                return(true);
            }

            return(false);
        }
Пример #2
0
    /// <summary>
    /// Configures the drivers/motors for this joint.
    /// </summary>
    private void SetXDrives()
    {
        //if the node has a joint and driver
        if (GetSkeletalJoint() != null && GetSkeletalJoint().cDriver != null)
        {
            if (GetSkeletalJoint().cDriver.GetDriveType().IsElevator())
            {
                Debug.Log("swag money");
            }
            if (GetSkeletalJoint().cDriver.GetDriveType().IsPneumatic())
            {
                PneumaticDriverMeta pneum = GetSkeletalJoint().cDriver.GetInfo <PneumaticDriverMeta>();
                if (pneum != null)
                {
                    const float psiToNMm2 = 0.00689475728f * Init.PHYSICS_MASS_MULTIPLIER;
                    if (joint is ConfigurableJoint)
                    {
                        JointDrive drMode = new JointDrive();
                        drMode.mode         = JointDriveMode.Velocity;
                        drMode.maximumForce = (psiToNMm2 * pneum.pressurePSI) * (Mathf.PI * Mathf.Pow((pneum.widthMM / 2), 2));
                        ((ConfigurableJoint)joint).xDrive = drMode;
                    }
                }
            }

            if (GetSkeletalJoint().cDriver.GetDriveType().IsMotor())
            {
                if (joint is ConfigurableJoint)
                {
                    JointDrive drMode = new JointDrive();
                    drMode.mode         = JointDriveMode.Velocity;
                    drMode.maximumForce = 100.0f;
                    ((ConfigurableJoint)joint).angularXDrive = drMode;
                }
                else if (joint is HingeJoint)
                {
                    JointMotor motor = new JointMotor();
                    motor.force                  = 100.0f;
                    motor.freeSpin               = false;
                    ((HingeJoint)joint).motor    = motor;
                    ((HingeJoint)joint).useMotor = true;
                }
            }

            if (this.HasDriverMeta <WheelDriverMeta>())
            {
                JointMotor motor = new JointMotor();
                motor.force                  = 0f;
                motor.freeSpin               = true;
                ((HingeJoint)joint).motor    = motor;
                ((HingeJoint)joint).useMotor = false;
            }
        }
    }
Пример #3
0
    /// <summary>
    /// Used for writing pneumatic driver meta data.
    /// </summary>
    /// <param name="meta"></param>
    /// <param name="writer"></param>
    private static void WritePneumaticDriverMeta(PneumaticDriverMeta meta, XmlWriter writer)
    {
        writer.WriteStartElement("PneumaticDriverMeta");

        writer.WriteAttributeString("DriverMetaID", meta.GetID().ToString());

        writer.WriteElementString("WidthMM", (meta.width * 25.4).ToString("F4"));
        writer.WriteElementString("PressurePSI", meta.pressurePSI.ToString("F4"));

        writer.WriteEndElement();
    }
Пример #4
0
    private bool shouldSave()
    {
        if (joint.cDriver == null)
        {
            return(true);
        }

        PneumaticDriverMeta pneumatic = joint.cDriver.GetInfo <PneumaticDriverMeta>();
        WheelDriverMeta     wheel     = joint.cDriver.GetInfo <WheelDriverMeta>();
        ElevatorDriverMeta  elevator  = joint.cDriver.GetInfo <ElevatorDriverMeta>();

        bool shouldSave = false;

        if (cmbJointDriver.SelectedIndex != typeOptions.ToList().IndexOf(joint.cDriver.GetDriveType()) + 1 ||
            txtPortA.Value != joint.cDriver.portA ||
            txtPortB.Value != joint.cDriver.portB ||
            txtLowLimit.Value != (decimal)joint.cDriver.lowerLimit ||
            txtHighLimit.Value != (decimal)joint.cDriver.upperLimit)
        {
            shouldSave = true;
        }

        if (pneumatic != null &&
            (cmbPneumaticDiameter.SelectedIndex != (byte)pneumatic.widthEnum ||
             cmbPneumaticPressure.SelectedIndex != (byte)pneumatic.pressureEnum))
        {
            shouldSave = true;
        }

        if (wheel != null &&
            (cmbWheelType.SelectedIndex != (byte)wheel.type ||
             cmbFrictionLevel.SelectedIndex != (byte)Math.Min(Math.Floor(wheel.forwardExtremeValue / 4), 2) || //ayy lmao
             chkBoxDriveWheel.Checked != wheel.isDriveWheel))
        {
            shouldSave = true;
        }

        if (elevator != null &&
            cmbStages.SelectedIndex != (byte)elevator.type)
        {
            shouldSave = true;
        }

        //If going from "NOT A WHEEL" to a wheel
        if (cmbWheelType.SelectedIndex != 0 && wheel == null && joint.cDriver.GetDriveType() == JointDriverType.MOTOR)
        {
            shouldSave = true;
        }

        return(shouldSave);
    }
Пример #5
0
    /// <summary>
    /// Reads a PneumaticDriverMeta from the given XmlReader.
    /// </summary>
    /// <param name="reader"></param>
    /// <returns></returns>
    private static PneumaticDriverMeta ReadPneumaticDriverMeta_3_0(XmlReader reader)
    {
        // Create a new pneumaticDriverMeta.
        PneumaticDriverMeta pneumaticDriverMeta = new PneumaticDriverMeta();

        foreach (string name in IOUtilities.AllElements(reader))
        {
            switch (name)
            {
            case "WidthMM":
                // Assign the current element value to widthMM.
                pneumaticDriverMeta.widthMM = reader.ReadElementContentAsInt();
                break;

            case "PressurePSI":
                // Assign the current element value to pressurePSI.
                pneumaticDriverMeta.pressurePSI = float.Parse(reader.ReadElementContentAsString());
                break;
            }
        }

        return(pneumaticDriverMeta);
    }
Пример #6
0
        /// <summary>
        /// Saves all the data from the DriveChooser frame to be used elsewhere in the program.  Also begins calculation of wheel radius.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SaveButton_Click(object sender, EventArgs e)
        {
            bool canClose = true;

            if (!ShouldSave())
            {
                Close();
                return;
            }

            if (cmbJointDriver.SelectedIndex <= 0)
            {
                joint.cDriver = null;
            }
            else
            {
                JointDriverType cType = typeOptions[cmbJointDriver.SelectedIndex - 1];

                double inputGear = 1, outputGear = 1;

                inputGear = (double)InputGeartxt.Value;

                outputGear = (double)OutputGeartxt.Value;// tries to parse the double from the output gear

                joint.cDriver = new JointDriver(cType)
                {
                    port1      = (int)txtPort1.Value,
                    port2      = (int)txtPort2.Value,
                    InputGear  = inputGear,  // writes the input gear to the internal joint driver so it can be exported
                    OutputGear = outputGear, // writes the output gear to the internal joint driver so it can be exported
                    lowerLimit = (float)txtLowLimit.Value,
                    upperLimit = (float)txtHighLimit.Value,
                    isCan      = rbCAN.Checked,
                    hasBrake   = chkBoxHasBrake.Checked
                };
                if (cType.IsMotor())
                {
                    if (!Enum.TryParse(MotorTypeDropDown.SelectedItem.ToString(), out MotorType motor))
                    {
                        motor = MotorType.GENERIC;
                    }
                    joint.cDriver.motor = motor;
                    RobotExporterAddInServer.Instance.AddInSettingsManager.DefaultRobotCompetition = RobotCompetitionDropDown.SelectedItem.ToString();
                }
                //Only need to store wheel driver if run by motor and is a wheel.
                if (cType.IsMotor() && (WheelType)cmbWheelType.SelectedIndex != WheelType.NOT_A_WHEEL)
                {
                    WheelDriverMeta wheelDriver = new WheelDriverMeta()
                    {
                        type         = (WheelType)cmbWheelType.SelectedIndex,
                        isDriveWheel = chkBoxDriveWheel.Checked
                    }; //The info about the wheel attached to the joint.
                       //TODO: Find real values that make sense for the friction.  Also add Mecanum wheels.

                    wheelDriver.SetFrictionLevel((FrictionLevel)cmbFrictionLevel.SelectedIndex);

                    joint.cDriver.AddInfo(wheelDriver);
                }
                else
                {
                    joint.cDriver.RemoveInfo <WheelDriverMeta>();
                }

                if (cType.IsPneumatic())
                {
                    PneumaticDriverMeta pneumaticDriver = new PneumaticDriverMeta()
                    {
                        pressureEnum = (PneumaticPressure)cmbPneumaticPressure.SelectedIndex,
                        width        = (double)numericUpDownPnuDia.Value
                    }; //The info about the wheel attached to the joint.
                    joint.cDriver.AddInfo(pneumaticDriver);
                }
                else
                {
                    joint.cDriver.RemoveInfo <PneumaticDriverMeta>();
                }

                if (cType.IsElevator())
                {
                    ElevatorDriverMeta elevatorDriver = new ElevatorDriverMeta()
                    {
                        type = ElevatorType.NOT_MULTI
                    };
                    joint.cDriver.AddInfo(elevatorDriver);
                }
                else
                {
                    joint.cDriver.RemoveInfo <ElevatorDriverMeta>();
                }
            }

            if (nodes.Count > 1)
            {
                foreach (RigidNode_Base node in nodes)
                {
                    if (joint.cDriver == null)
                    {
                        node.GetSkeletalJoint().cDriver = null;
                    }
                    else
                    {
                        JointDriver driver = new JointDriver(joint.cDriver.GetDriveType())
                        {
                            port1      = joint.cDriver.port1,
                            port2      = joint.cDriver.port2,
                            isCan      = joint.cDriver.isCan,
                            OutputGear = joint.cDriver.OutputGear,
                            InputGear  = joint.cDriver.InputGear,
                            lowerLimit = joint.cDriver.lowerLimit,
                            upperLimit = joint.cDriver.upperLimit
                        };
                        joint.cDriver.CopyMetaInfo(driver);

                        node.GetSkeletalJoint().cDriver = driver;
                    }
                }
            }

            if (canClose)// make sure there are no outstanding issues for the user to fix before we save
            {
                Saved = true;
                Close();
            }
        }
Пример #7
0
        public void ShowDialog(SkeletalJoint_Base baseJoint, List <RigidNode_Base> nodes, Form owner)
        {
            Saved = false;

            if (nodes.Count > 1)
            {
                bool same = true;

                foreach (RigidNode_Base node in nodes)
                {
                    JointDriver driver = node.GetSkeletalJoint().cDriver;
                    if (driver == null || driver.CompareTo(baseJoint.cDriver) != 0)
                    {
                        same = false;
                    }
                }

                if (same)
                {
                    joint = baseJoint;
                }
                else
                {
                    joint = SkeletalJoint_Base.JOINT_FACTORY(baseJoint.GetJointType());
                }
            }
            else
            {
                joint = baseJoint;
            }
            this.nodes  = nodes;
            typeOptions = JointDriver.GetAllowedDrivers(joint);

            // Used for capitalization
            TextInfo textInfo = new CultureInfo("en-US", true).TextInfo;

            cmbJointDriver.Items.Clear();
            cmbJointDriver.Items.Add("No Driver");
            foreach (JointDriverType type in typeOptions)
            {
                cmbJointDriver.Items.Add(textInfo.ToTitleCase(Enum.GetName(typeof(JointDriverType), type).Replace('_', ' ').ToLowerInvariant()));
            }
            if (joint.cDriver != null)
            {
                cmbJointDriver.SelectedIndex = Array.IndexOf(typeOptions, joint.cDriver.GetDriveType()) + 1;

                if (joint.cDriver.port1 < txtPort1.Minimum)
                {
                    txtPort1.Value = txtPort1.Minimum;
                }
                else if (joint.cDriver.port1 > txtPort1.Maximum)
                {
                    txtPort1.Value = txtPort1.Maximum;
                }
                else
                {
                    txtPort1.Value = joint.cDriver.port1;
                }

                if (joint.cDriver.port2 < txtPort2.Minimum)
                {
                    txtPort2.Value = txtPort2.Minimum;
                }
                else if (joint.cDriver.port2 > txtPort2.Maximum)
                {
                    txtPort2.Value = txtPort2.Maximum;
                }
                else
                {
                    txtPort2.Value = joint.cDriver.port2;
                }

                txtLowLimit.Value  = (decimal)joint.cDriver.lowerLimit;
                txtHighLimit.Value = (decimal)joint.cDriver.upperLimit;

                rbPWM.Checked          = !joint.cDriver.isCan;
                rbCAN.Checked          = joint.cDriver.isCan;
                chkBoxHasBrake.Checked = joint.cDriver.hasBrake;
                if (joint.cDriver.OutputGear == 0)// prevents output gear from being 0
                {
                    joint.cDriver.OutputGear = 1;
                }
                if (joint.cDriver.InputGear == 0)// prevents input gear from being 0
                {
                    joint.cDriver.InputGear = 1;
                }
                OutputGeartxt.Value = (decimal)joint.cDriver.OutputGear; // reads the existing gearing and writes it to the input field so the user sees their existing value
                InputGeartxt.Value  = (decimal)joint.cDriver.InputGear;  // reads the existing gearing and writes it to the input field so the user sees their existing value

                {
                    PneumaticDriverMeta pneumaticMeta = joint.cDriver.GetInfo <PneumaticDriverMeta>();
                    if (pneumaticMeta != null)
                    {
                        numericUpDownPnuDia.Value          = (decimal)pneumaticMeta.width;
                        cmbPneumaticPressure.SelectedIndex = (int)pneumaticMeta.pressureEnum;
                    }
                    else
                    {
                        numericUpDownPnuDia.Value          = (decimal)1.0;
                        cmbPneumaticPressure.SelectedIndex = (int)PneumaticPressure.HIGH;
                    }
                }
                {
                    WheelDriverMeta wheelMeta = joint.cDriver.GetInfo <WheelDriverMeta>();
                    if (wheelMeta != null)
                    {
                        try
                        {
                            cmbWheelType.SelectedIndex     = (int)wheelMeta.type;
                            cmbFrictionLevel.SelectedIndex = (int)wheelMeta.GetFrictionLevel();
                        }
                        catch
                        {
                            // If an exception was thrown (System.ArguementOutOfRangeException) it means
                            // the user did not choose a wheel type when they were configuring the
                            // wheel joint
                            cmbWheelType.SelectedIndex     = (int)WheelType.NORMAL;
                            cmbFrictionLevel.SelectedIndex = (int)FrictionLevel.MEDIUM;
                        }

                        chkBoxDriveWheel.Checked = wheelMeta.isDriveWheel;
                        cmbWheelType_SelectedIndexChanged(null, null);
                    }
                    else
                    {
                        cmbWheelType.SelectedIndex     = (int)WheelType.NOT_A_WHEEL;
                        cmbFrictionLevel.SelectedIndex = (int)FrictionLevel.MEDIUM;
                    }
                }
                {
                    ElevatorDriverMeta elevatorMeta = joint.cDriver.GetInfo <ElevatorDriverMeta>();
                }
                {
                    switch (joint.cDriver.motor)
                    {
                    case MotorType.GENERIC:
                        RobotCompetitionDropDown.SelectedItem = RobotExporterAddInServer.Instance.AddInSettingsManager.DefaultRobotCompetition.ToString();
                        MotorTypeDropDown.SelectedItem        = "GENERIC";
                        break;

                    case MotorType.CIM:
                        RobotCompetitionDropDown.SelectedItem = "FRC";
                        MotorTypeDropDown.SelectedItem        = "CIM";
                        break;

                    case MotorType.MINI_CIM:
                        RobotCompetitionDropDown.SelectedItem = "FRC";
                        MotorTypeDropDown.SelectedItem        = "MIN_CIM";
                        break;

                    case MotorType.BAG_MOTOR:
                        RobotCompetitionDropDown.SelectedItem = "FRC";
                        MotorTypeDropDown.SelectedItem        = "BAG_MOTOR";
                        break;

                    case MotorType.REDLINE_775_PRO:
                        RobotCompetitionDropDown.SelectedItem = "FRC";
                        MotorTypeDropDown.SelectedItem        = "REDLINE_775_PRO";
                        break;

                    case MotorType.ANDYMARK_9015:
                        RobotCompetitionDropDown.SelectedItem = "FRC";
                        MotorTypeDropDown.SelectedItem        = "ANDYMARK_9015";
                        break;

                    case MotorType.BANEBOTS_775_18v:
                        RobotCompetitionDropDown.SelectedItem = "FRC";
                        MotorTypeDropDown.SelectedItem        = "BANEBOTS_775_18v";
                        break;

                    case MotorType.BANEBOTS_775_12v:
                        RobotCompetitionDropDown.SelectedItem = "FRC";
                        MotorTypeDropDown.SelectedItem        = "BANEBOTS_775_12v";
                        break;

                    case MotorType.BANEBOTS_550_12v:
                        RobotCompetitionDropDown.SelectedItem = "FRC";
                        MotorTypeDropDown.SelectedItem        = "BANEBOTS_550_12v";
                        break;

                    case MotorType.ANDYMARK_775_125:
                        RobotCompetitionDropDown.SelectedItem = "FRC";
                        MotorTypeDropDown.SelectedItem        = "ANDYMARK_775_125";
                        break;

                    case MotorType.SNOW_BLOWER:
                        RobotCompetitionDropDown.SelectedItem = "FRC";
                        MotorTypeDropDown.SelectedItem        = "SNOW_BLOWER";
                        break;

                    case MotorType.NIDEC_BLDC:
                        RobotCompetitionDropDown.SelectedItem = "FRC";
                        MotorTypeDropDown.SelectedItem        = "NIDEC_BLDC";
                        break;

                    case MotorType.THROTTLE_MOTOR:
                        RobotCompetitionDropDown.SelectedItem = "FRC";
                        MotorTypeDropDown.SelectedItem        = "THROTTLE_MOTOR";
                        break;

                    case MotorType.WINDOW_MOTOR:
                        RobotCompetitionDropDown.SelectedItem = "FRC";
                        MotorTypeDropDown.SelectedItem        = "WINDOW_MOTOR";
                        break;

                    case MotorType.NEVEREST:
                        RobotCompetitionDropDown.SelectedItem = "FTC";
                        MotorTypeDropDown.SelectedItem        = "NEVEREST";
                        break;

                    case MotorType.TETRIX_MOTOR:
                        RobotCompetitionDropDown.SelectedItem = "FTC";
                        MotorTypeDropDown.SelectedItem        = "TETRIX_MOTOR";
                        break;

                    case MotorType.MODERN_ROBOTICS_MATRIX:
                        RobotCompetitionDropDown.SelectedItem = "FTC";
                        MotorTypeDropDown.SelectedItem        = "MODERN_ROBOTICS_MATRIX";
                        break;

                    case MotorType.REV_ROBOTICS_HD_HEX_20_TO_1:
                        RobotCompetitionDropDown.SelectedItem = "FTC";
                        MotorTypeDropDown.SelectedItem        = "REV_ROBOTICS_HD_HEX_20_TO_1";
                        break;

                    case MotorType.REV_ROBOTICS_HD_HEX_40_TO_1:
                        RobotCompetitionDropDown.SelectedItem = "FTC";
                        MotorTypeDropDown.SelectedItem        = "REV_ROBOTICS_HD_HEX_40_TO_1";
                        break;

                    case MotorType.REV_ROBOTICS_CORE_HEX:
                        RobotCompetitionDropDown.SelectedItem = "FTC";
                        MotorTypeDropDown.SelectedItem        = "REV_ROBOTICS_CORE_HEX";
                        break;

                    case MotorType.VEX_V5_Smart_Motor_600_RPM:
                        RobotCompetitionDropDown.SelectedItem = "VEX";
                        MotorTypeDropDown.SelectedItem        = "VEX_V5_Smart_Motor_600_RPM";
                        break;

                    case MotorType.VEX_V5_Smart_Motor_200_RPM:
                        RobotCompetitionDropDown.SelectedItem = "VEX";
                        MotorTypeDropDown.SelectedItem        = "VEX_V5_Smart_Motor_200_RPM";
                        break;

                    case MotorType.VEX_V5_Smart_Motor_100_RPM:
                        RobotCompetitionDropDown.SelectedItem = "VEX";
                        MotorTypeDropDown.SelectedItem        = "VEX_V5_Smart_Motor_100_RPM";
                        break;

                    case MotorType.VEX_393_NORMAL_SPEED:
                        RobotCompetitionDropDown.SelectedItem = "VEX";
                        MotorTypeDropDown.SelectedItem        = "VEX_393_NORMAL_SPEED";
                        break;

                    case MotorType.VEX_393_HIGH_SPEED:
                        RobotCompetitionDropDown.SelectedItem = "VEX";
                        MotorTypeDropDown.SelectedItem        = "VEX_393_HIGH_SPEED";
                        break;

                    case MotorType.VEX_393_TURBO_GEAR_SET:
                        RobotCompetitionDropDown.SelectedItem = "VEX";
                        MotorTypeDropDown.SelectedItem        = "VEX_393_TURBO_GEAR_SET";
                        break;
                    }
                }
            }
            else //Default values
            {
                cmbJointDriver.SelectedIndex = 0;
                txtPort1.Value      = txtPort1.Minimum;
                txtPort2.Value      = txtPort2.Minimum;
                txtLowLimit.Value   = txtLowLimit.Minimum;
                txtHighLimit.Value  = txtHighLimit.Minimum;
                InputGeartxt.Value  = (decimal)1.0;
                OutputGeartxt.Value = (decimal)1.0;

                rbPWM.Checked = true;

                chkBoxHasBrake.Checked = false;

                numericUpDownPnuDia.Value          = (decimal)0.5;
                cmbPneumaticPressure.SelectedIndex = (int)PneumaticPressure.MEDIUM;

                cmbWheelType.SelectedIndex     = (int)WheelType.NOT_A_WHEEL;
                cmbFrictionLevel.SelectedIndex = (int)FrictionLevel.MEDIUM;
                chkBoxDriveWheel.Checked       = false;

                RobotCompetitionDropDown.SelectedItem = RobotExporterAddInServer.Instance.AddInSettingsManager.DefaultRobotCompetition;
                MotorTypeDropDown.SelectedItem        = "GENERIC";
            }

            PrepLayout();
            base.Location = new System.Drawing.Point(Cursor.Position.X - 10, Cursor.Position.Y - base.Height - 10);
            this.ShowDialog(owner);
        }
Пример #8
0
    /// <summary>
    /// Saves all the data from the DriveChooser frame to be used elsewhere in the program.  Also begins calculation of wheel radius.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void SaveButton_Click(object sender, EventArgs e)
    {
        bool canClose = true;

        if (!ShouldSave())
        {
            Close();
            return;
        }

        if (cmbJointDriver.SelectedIndex <= 0)
        {
            joint.cDriver = null;
        }
        else
        {
            JointDriverType cType = typeOptions[cmbJointDriver.SelectedIndex - 1];

            double inputGear = 1, outputGear = 1;

            inputGear = (double)InputGeartxt.Value;

            outputGear = (double)OutputGeartxt.Value;// tries to parse the double from the output gear

            joint.cDriver = new JointDriver(cType)
            {
                port1      = (int)txtPort1.Value,
                port2      = (int)txtPort2.Value,
                InputGear  = inputGear,  // writes the input gear to the internal joint driver so it can be exported
                OutputGear = outputGear, // writes the output gear to the internal joint driver so it can be exported
                lowerLimit = (float)txtLowLimit.Value,
                upperLimit = (float)txtHighLimit.Value,
                isCan      = rbCAN.Checked,
                hasBrake   = chkBoxHasBrake.Checked
            };
            //Only need to store wheel driver if run by motor and is a wheel.
            if (cType.IsMotor() && (WheelType)cmbWheelType.SelectedIndex != WheelType.NOT_A_WHEEL)
            {
                #region WHEEL_SAVING
                WheelDriverMeta wheelDriver = new WheelDriverMeta()
                {
                    type         = (WheelType)cmbWheelType.SelectedIndex,
                    isDriveWheel = chkBoxDriveWheel.Checked
                }; //The info about the wheel attached to the joint.
                   //TODO: Find real values that make sense for the friction.  Also add Mecanum wheels.

                wheelDriver.SetFrictionLevel((FrictionLevel)cmbFrictionLevel.SelectedIndex);

                joint.cDriver.AddInfo(wheelDriver);
                #endregion
            }
            else
            {
                joint.cDriver.RemoveInfo <WheelDriverMeta>();
            }

            if (cType.IsPneumatic())
            {
                #region PNEUMATIC_SAVING
                PneumaticDriverMeta pneumaticDriver = new PneumaticDriverMeta()
                {
                    pressureEnum = (PneumaticPressure)cmbPneumaticPressure.SelectedIndex,
                    widthEnum    = (PneumaticDiameter)cmbPneumaticDiameter.SelectedIndex
                }; //The info about the wheel attached to the joint.
                joint.cDriver.AddInfo(pneumaticDriver);
                #endregion
            }
            else
            {
                joint.cDriver.RemoveInfo <PneumaticDriverMeta>();
            }

            if (cType.IsElevator())
            {
                #region ELEVATOR_SAVING
                ElevatorDriverMeta elevatorDriver = new ElevatorDriverMeta()
                {
                    type = ElevatorType.NOT_MULTI
                };
                joint.cDriver.AddInfo(elevatorDriver);
                #endregion
            }
            else
            {
                joint.cDriver.RemoveInfo <ElevatorDriverMeta>();
            }
        }

        if (nodes.Count > 1)
        {
            foreach (RigidNode_Base node in nodes)
            {
                if (joint.cDriver == null)
                {
                    node.GetSkeletalJoint().cDriver = null;
                }
                else
                {
                    JointDriver driver = new JointDriver(joint.cDriver.GetDriveType())
                    {
                        port1      = joint.cDriver.port1,
                        port2      = joint.cDriver.port2,
                        isCan      = joint.cDriver.isCan,
                        OutputGear = joint.cDriver.OutputGear,
                        InputGear  = joint.cDriver.InputGear,
                        lowerLimit = joint.cDriver.lowerLimit,
                        upperLimit = joint.cDriver.upperLimit
                    };
                    joint.cDriver.CopyMetaInfo(driver);

                    node.GetSkeletalJoint().cDriver = driver;
                }
            }
        }

        if (canClose)// make sure there are no outstanding issues for the user to fix before we save
        {
            Saved = true;
            LegacyInterchange.LegacyEvents.OnRobotModified();
            Close();
        }
    }
Пример #9
0
    public void ShowDialog(SkeletalJoint_Base baseJoint, List <RigidNode_Base> nodes, Form owner)
    {
        Saved = false;

        if (nodes.Count > 1)
        {
            bool same = true;

            foreach (RigidNode_Base node in nodes)
            {
                JointDriver driver = node.GetSkeletalJoint().cDriver;
                if (driver == null || driver.CompareTo(baseJoint.cDriver) != 0)
                {
                    same = false;
                }
            }

            if (same)
            {
                joint = baseJoint;
            }
            else
            {
                joint = SkeletalJoint_Base.JOINT_FACTORY(baseJoint.GetJointType());
            }
        }
        else
        {
            joint = baseJoint;
        }
        this.nodes  = nodes;
        typeOptions = JointDriver.GetAllowedDrivers(joint);

        // Used for capitalization
        TextInfo textInfo = new CultureInfo("en-US", true).TextInfo;

        cmbJointDriver.Items.Clear();
        cmbJointDriver.Items.Add("No Driver");
        foreach (JointDriverType type in typeOptions)
        {
            cmbJointDriver.Items.Add(textInfo.ToTitleCase(Enum.GetName(typeof(JointDriverType), type).Replace('_', ' ').ToLowerInvariant()));
        }
        if (joint.cDriver != null)
        {
            cmbJointDriver.SelectedIndex = Array.IndexOf(typeOptions, joint.cDriver.GetDriveType()) + 1;

            if (joint.cDriver.port1 < txtPort1.Minimum)
            {
                txtPort1.Value = txtPort1.Minimum;
            }
            else if (joint.cDriver.port1 > txtPort1.Maximum)
            {
                txtPort1.Value = txtPort1.Maximum;
            }
            else
            {
                txtPort1.Value = joint.cDriver.port1;
            }

            if (joint.cDriver.port2 < txtPort2.Minimum)
            {
                txtPort2.Value = txtPort2.Minimum;
            }
            else if (joint.cDriver.port2 > txtPort2.Maximum)
            {
                txtPort2.Value = txtPort2.Maximum;
            }
            else
            {
                txtPort2.Value = joint.cDriver.port2;
            }

            txtLowLimit.Value  = (decimal)joint.cDriver.lowerLimit;
            txtHighLimit.Value = (decimal)joint.cDriver.upperLimit;

            rbPWM.Checked          = !joint.cDriver.isCan;
            rbCAN.Checked          = joint.cDriver.isCan;
            chkBoxHasBrake.Checked = joint.cDriver.hasBrake;
            if (joint.cDriver.OutputGear == 0)    // prevents output gear from being 0
            {
                joint.cDriver.OutputGear = 1;
            }
            if (joint.cDriver.InputGear == 0)// prevents input gear from being 0
            {
                joint.cDriver.InputGear = 1;
            }
            OutputGeartxt.Value = (decimal)joint.cDriver.OutputGear; // reads the existing gearing and writes it to the input field so the user sees their existing value
            InputGeartxt.Value  = (decimal)joint.cDriver.InputGear;  // reads the existing gearing and writes it to the input field so the user sees their existing value

            #region Meta info recovery
            {
                PneumaticDriverMeta pneumaticMeta = joint.cDriver.GetInfo <PneumaticDriverMeta>();
                if (pneumaticMeta != null)
                {
                    cmbPneumaticDiameter.SelectedIndex = (int)pneumaticMeta.widthEnum;
                    cmbPneumaticPressure.SelectedIndex = (int)pneumaticMeta.pressureEnum;
                }
                else
                {
                    cmbPneumaticDiameter.SelectedIndex = (int)PneumaticDiameter.MEDIUM;
                    cmbPneumaticPressure.SelectedIndex = (int)PneumaticPressure.HIGH;
                }
            }
            {
                WheelDriverMeta wheelMeta = joint.cDriver.GetInfo <WheelDriverMeta>();
                if (wheelMeta != null)
                {
                    try
                    {
                        cmbWheelType.SelectedIndex     = (int)wheelMeta.type;
                        cmbFrictionLevel.SelectedIndex = (int)wheelMeta.GetFrictionLevel();
                    }
                    catch
                    {
                        // If an exception was thrown (System.ArguementOutOfRangeException) it means
                        // the user did not choose a wheel type when they were configuring the
                        // wheel joint
                        cmbWheelType.SelectedIndex     = (int)WheelType.NORMAL;
                        cmbFrictionLevel.SelectedIndex = (int)FrictionLevel.MEDIUM;
                    }

                    chkBoxDriveWheel.Checked = wheelMeta.isDriveWheel;
                    cmbWheelType_SelectedIndexChanged(null, null);
                }
                else
                {
                    cmbWheelType.SelectedIndex     = (int)WheelType.NOT_A_WHEEL;
                    cmbFrictionLevel.SelectedIndex = (int)FrictionLevel.MEDIUM;
                }
            }
            {
                ElevatorDriverMeta elevatorMeta = joint.cDriver.GetInfo <ElevatorDriverMeta>();
            }
            #endregion
        }
        else //Default values
        {
            cmbJointDriver.SelectedIndex = 0;
            txtPort1.Value      = txtPort1.Minimum;
            txtPort2.Value      = txtPort2.Minimum;
            txtLowLimit.Value   = txtLowLimit.Minimum;
            txtHighLimit.Value  = txtHighLimit.Minimum;
            InputGeartxt.Value  = (decimal)1.0;
            OutputGeartxt.Value = (decimal)1.0;

            rbPWM.Checked = true;

            chkBoxHasBrake.Checked = false;

            cmbPneumaticDiameter.SelectedIndex = (int)PneumaticDiameter.MEDIUM;
            cmbPneumaticPressure.SelectedIndex = (int)PneumaticPressure.MEDIUM;

            cmbWheelType.SelectedIndex     = (int)WheelType.NOT_A_WHEEL;
            cmbFrictionLevel.SelectedIndex = (int)FrictionLevel.MEDIUM;
            chkBoxDriveWheel.Checked       = false;
        }

        PrepLayout();
        base.Location = new System.Drawing.Point(Cursor.Position.X - 10, Cursor.Position.Y - base.Height - 10);
        this.ShowDialog(owner);
    }
Пример #10
0
    /// <summary>
    /// Saves all the data from the DriveChooser frame to be used elsewhere in the program.  Also begins calculation of wheel radius.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void btnSave_Click(object sender, EventArgs e)
    {
        if (!shouldSave())
        {
            Hide();
            return;
        }

        if (cmbJointDriver.SelectedIndex <= 0)
        {
            joint.cDriver = null;
        }
        else
        {
            JointDriverType cType = typeOptions[cmbJointDriver.SelectedIndex - 1];

            joint.cDriver = new JointDriver(cType)
            {
                portA      = (int)txtPortA.Value,
                portB      = (int)txtPortB.Value,
                lowerLimit = (float)txtLowLimit.Value,
                upperLimit = (float)txtHighLimit.Value,
                isCan      = rbCAN.Checked
            };
            //Only need to store wheel driver if run by motor and is a wheel.
            if (cType.IsMotor() && (WheelType)cmbWheelType.SelectedIndex != WheelType.NOT_A_WHEEL)
            {
                #region WHEEL_SAVING
                WheelDriverMeta wheelDriver = new WheelDriverMeta()
                {
                    type         = (WheelType)cmbWheelType.SelectedIndex,
                    isDriveWheel = chkBoxDriveWheel.Checked
                }; //The info about the wheel attached to the joint.
                   //TODO: Find real values that make sense for the friction.  Also add Mecanum wheels.
                switch ((FrictionLevel)cmbFrictionLevel.SelectedIndex)
                {
                case FrictionLevel.HIGH:
                    wheelDriver.forwardExtremeSlip  = 1;    //Speed of max static friction force.
                    wheelDriver.forwardExtremeValue = 10;   //Force of max static friction force.
                    wheelDriver.forwardAsympSlip    = 1.5f; //Speed of leveled off kinetic friction force.
                    wheelDriver.forwardAsympValue   = 8;    //Force of leveld off kinetic friction force.

                    if (wheelDriver.type == WheelType.OMNI) //Set to relatively low friction, as omni wheels can move sidways.
                    {
                        wheelDriver.sideExtremeSlip  = 1;   //Same as above, but orthogonal to the movement of the wheel.
                        wheelDriver.sideExtremeValue = .01f;
                        wheelDriver.sideAsympSlip    = 1.5f;
                        wheelDriver.sideAsympValue   = .005f;
                    }
                    else
                    {
                        wheelDriver.sideExtremeSlip  = 1;
                        wheelDriver.sideExtremeValue = 10;
                        wheelDriver.sideAsympSlip    = 1.5f;
                        wheelDriver.sideAsympValue   = 8;
                    }
                    break;

                case FrictionLevel.MEDIUM:
                    wheelDriver.forwardExtremeSlip  = 1f;
                    wheelDriver.forwardExtremeValue = 7;
                    wheelDriver.forwardAsympSlip    = 1.5f;
                    wheelDriver.forwardAsympValue   = 5;

                    if (wheelDriver.type == WheelType.OMNI)
                    {
                        wheelDriver.sideExtremeSlip  = 1;
                        wheelDriver.sideExtremeValue = .01f;
                        wheelDriver.sideAsympSlip    = 1.5f;
                        wheelDriver.sideAsympValue   = .005f;
                    }
                    else
                    {
                        wheelDriver.sideExtremeSlip  = 1;
                        wheelDriver.sideExtremeValue = 7;
                        wheelDriver.sideAsympSlip    = 1.5f;
                        wheelDriver.sideAsympValue   = 5;
                    }
                    break;

                case FrictionLevel.LOW:
                    wheelDriver.forwardExtremeSlip  = 1;
                    wheelDriver.forwardExtremeValue = 5;
                    wheelDriver.forwardAsympSlip    = 1.5f;
                    wheelDriver.forwardAsympValue   = 3;

                    if (wheelDriver.type == WheelType.OMNI)
                    {
                        wheelDriver.sideExtremeSlip  = 1;
                        wheelDriver.sideExtremeValue = .01f;
                        wheelDriver.sideAsympSlip    = 1.5f;
                        wheelDriver.sideAsympValue   = .005f;
                    }
                    else
                    {
                        wheelDriver.sideExtremeSlip  = 1;
                        wheelDriver.sideExtremeValue = 5;
                        wheelDriver.sideAsympSlip    = 1.5f;
                        wheelDriver.sideAsympValue   = 3;
                    }
                    break;
                }

                joint.cDriver.AddInfo(wheelDriver);
                #endregion
            }
            else
            {
                joint.cDriver.RemoveInfo <WheelDriverMeta>();
            }

            if (cType.IsPneumatic())
            {
                #region PNEUMATIC_SAVING
                PneumaticDriverMeta pneumaticDriver = new PneumaticDriverMeta()
                {
                    pressureEnum = (PneumaticPressure)cmbPneumaticPressure.SelectedIndex,
                    widthEnum    = (PneumaticDiameter)cmbPneumaticDiameter.SelectedIndex
                }; //The info about the wheel attached to the joint.
                joint.cDriver.AddInfo(pneumaticDriver);
                #endregion
            }
            else
            {
                joint.cDriver.RemoveInfo <PneumaticDriverMeta>();
            }

            if (cType.IsElevator())
            {
                #region ELEVATOR_SAVING
                ElevatorDriverMeta elevatorDriver = new ElevatorDriverMeta()
                {
                    type = (ElevatorType)cmbStages.SelectedIndex
                };
                joint.cDriver.AddInfo(elevatorDriver);
                #endregion
            }
            else
            {
                joint.cDriver.RemoveInfo <ElevatorDriverMeta>();
            }
        }

        if (nodes.Count > 1)
        {
            foreach (RigidNode_Base node in nodes)
            {
                if (joint.cDriver == null)
                {
                    node.GetSkeletalJoint().cDriver = null;
                }
                else
                {
                    JointDriver driver = new JointDriver(joint.cDriver.GetDriveType())
                    {
                        portA      = joint.cDriver.portA,
                        portB      = joint.cDriver.portB,
                        isCan      = joint.cDriver.isCan,
                        lowerLimit = joint.cDriver.lowerLimit,
                        upperLimit = joint.cDriver.upperLimit
                    };
                    joint.cDriver.CopyMetaInfo(driver);

                    node.GetSkeletalJoint().cDriver = driver;
                }
            }
        }

        Saved = true;
        Hide();
    }
Пример #11
0
    public void ShowDialog(SkeletalJoint_Base baseJoint, List <RigidNode_Base> nodes, Form owner)
    {
        Saved = false;

        if (nodes.Count > 1)
        {
            bool same = true;

            foreach (RigidNode_Base node in nodes)
            {
                JointDriver driver = node.GetSkeletalJoint().cDriver;
                if (driver == null || driver.CompareTo(baseJoint.cDriver) != 0)
                {
                    same = false;
                }
            }

            if (same)
            {
                joint = baseJoint;
            }
            else
            {
                joint = SkeletalJoint_Base.JOINT_FACTORY(baseJoint.GetJointType());
            }
        }
        else
        {
            joint = baseJoint;
        }
        this.nodes  = nodes;
        typeOptions = JointDriver.GetAllowedDrivers(joint);

        cmbJointDriver.Items.Clear();
        cmbJointDriver.Items.Add("No Driver");
        foreach (JointDriverType type in typeOptions)
        {
            cmbJointDriver.Items.Add(Enum.GetName(typeof(JointDriverType), type).Replace('_', ' ').ToLowerInvariant());
        }
        if (joint.cDriver != null)
        {
            cmbJointDriver.SelectedIndex = Array.IndexOf(typeOptions, joint.cDriver.GetDriveType()) + 1;
            txtPortA.Value     = joint.cDriver.portA;
            txtPortB.Value     = joint.cDriver.portB;
            txtLowLimit.Value  = (decimal)joint.cDriver.lowerLimit;
            txtHighLimit.Value = (decimal)joint.cDriver.upperLimit;

            #region Meta info recovery
            {
                PneumaticDriverMeta pneumaticMeta = joint.cDriver.GetInfo <PneumaticDriverMeta>();
                if (pneumaticMeta != null)
                {
                    cmbPneumaticDiameter.SelectedIndex = (byte)pneumaticMeta.widthEnum;
                    cmbPneumaticPressure.SelectedIndex = (byte)pneumaticMeta.pressureEnum;
                }
                else
                {
                    cmbPneumaticDiameter.SelectedIndex = (byte)PneumaticDiameter.MEDIUM;
                    cmbPneumaticPressure.SelectedIndex = (byte)PneumaticPressure.HIGH;
                }
            }
            {
                WheelDriverMeta wheelMeta = joint.cDriver.GetInfo <WheelDriverMeta>();
                if (wheelMeta != null)
                {
                    try
                    {
                        // TODO:  This is a really sketchy hack and I don't even know where the cat is.
                        cmbWheelType.SelectedIndex = (byte)wheelMeta.type;
                        if (wheelMeta.forwardExtremeValue > 8)
                        {
                            cmbFrictionLevel.SelectedIndex = (byte)FrictionLevel.HIGH;
                        }
                        else if (wheelMeta.forwardExtremeValue > 4)
                        {
                            cmbFrictionLevel.SelectedIndex = (byte)FrictionLevel.MEDIUM;
                        }
                        else
                        {
                            cmbFrictionLevel.SelectedIndex = (byte)FrictionLevel.LOW;
                        }
                    }
                    catch
                    {
                        // If an exception was thrown (System.ArguementOutOfRangeException) it means
                        // the user did not choose a wheel type when they were configuring the
                        // wheel joint
                        cmbWheelType.SelectedIndex     = (byte)WheelType.NORMAL;
                        cmbFrictionLevel.SelectedIndex = (byte)FrictionLevel.MEDIUM;
                    }

                    chkBoxDriveWheel.Checked = wheelMeta.isDriveWheel;
                    cmbWheelType_SelectedIndexChanged(null, null);
                }
                else
                {
                    cmbWheelType.SelectedIndex     = (byte)WheelType.NOT_A_WHEEL;
                    cmbFrictionLevel.SelectedIndex = (byte)FrictionLevel.MEDIUM;
                }
            }
            {
                ElevatorDriverMeta elevatorMeta = joint.cDriver.GetInfo <ElevatorDriverMeta>();
                if (elevatorMeta != null)
                {
                    cmbStages.SelectedIndex = (byte)elevatorMeta.type;
                }
            }
            #endregion
        }
        else //Default values
        {
            cmbJointDriver.SelectedIndex = 0;
            txtPortA.Value     = txtPortA.Minimum;
            txtPortB.Value     = txtPortB.Minimum;
            txtLowLimit.Value  = txtLowLimit.Minimum;
            txtHighLimit.Value = txtHighLimit.Minimum;

            cmbPneumaticDiameter.SelectedIndex = (byte)PneumaticDiameter.MEDIUM;
            cmbPneumaticPressure.SelectedIndex = (byte)PneumaticPressure.MEDIUM;

            cmbWheelType.SelectedIndex     = (byte)WheelType.NOT_A_WHEEL;
            cmbFrictionLevel.SelectedIndex = (byte)FrictionLevel.MEDIUM;
            chkBoxDriveWheel.Checked       = false;

            cmbStages.SelectedIndex = (byte)ElevatorType.NOT_MULTI;
        }
        PerformLayout();
        this.ShowDialog(owner);
    }