示例#1
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();
            }
        }
示例#2
0
        /// <summary>
        /// Changes the position of window elements based on the type of driver.
        /// </summary>
        private void PrepLayout()
        {
            chkBoxDriveWheel.Hide();
            rbCAN.Hide();
            rbPWM.Hide();

            if (cmbJointDriver.SelectedIndex <= 0)      //If the joint is not driven
            {
                grpDriveOptions.Visible = false;
                tabsMeta.TabPages.Clear();
            }
            else
            {
                JointDriverType cType = typeOptions[cmbJointDriver.SelectedIndex - 1];
                lblPort.Text     = cType.GetPortType(rbCAN.Checked) + " Port" + (cType.HasTwoPorts() ? "s" : "");
                txtPort2.Visible = cType.HasTwoPorts();

                txtPort1.Maximum        = txtPort2.Maximum = cType.GetPortMax(rbCAN.Checked);
                grpDriveOptions.Visible = true;

                if (cType.IsMotor())
                {
                    tabsMeta.Visible = true;
                    tabsMeta.TabPages.Clear();
                    tabsMeta.TabPages.Add(metaWheel);
                    tabsMeta.TabPages.Add(metaGearing);
                    tabsMeta.TabPages.Add(metaBrake);
                    tabsMeta.TabPages.Add(metaMotorType);
                    chkBoxDriveWheel.Show();
                    rbCAN.Show();
                    rbPWM.Show();
                }
                else if (cType.IsPneumatic())
                {
                    tabsMeta.Visible = true;
                    tabsMeta.TabPages.Clear();
                    tabsMeta.TabPages.Add(metaPneumatic);
                    tabsMeta.TabPages.Add(metaBrake);
                }
                else if (cType.IsElevator())
                {
                    tabsMeta.Visible = true;
                    tabsMeta.TabPages.Clear();
                    tabsMeta.TabPages.Add(metaBrake);
                    chkBoxHasBrake.Show();

                    rbCAN.Show();
                    rbPWM.Show();
                }
                else if (cType.IsWormScrew())
                {
                    rbCAN.Show();
                    rbPWM.Show();
                }
                else
                {
                    tabsMeta.TabPages.Clear();
                    tabsMeta.Visible = false;
                }
            }
            // Set window size
            tabsMeta.Visible = tabsMeta.TabPages.Count > 0;
        }
示例#3
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();
    }
示例#4
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();
        }
    }
示例#5
0
 /// <summary>
 /// Changes the position of window elements based on the type of driver.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void DriveChooser_Layout(object sender, LayoutEventArgs e)
 {
     chkBoxDriveWheel.Hide();
     chkBoxHasBrake.Hide();
     rbCAN.Hide();
     rbPWM.Hide();
     if (cmbJointDriver.SelectedIndex <= 0)      //If the joint is not driven
     {
         grpDriveOptions.Visible = false;
         tabsMeta.TabPages.Clear();
     }
     else
     {
         JointDriverType cType = typeOptions[cmbJointDriver.SelectedIndex - 1];
         lblPort.Text            = cType.GetPortType() + " Port" + (cType.HasTwoPorts() ? "s" : "");
         txtPortB.Visible        = cType.HasTwoPorts();
         txtPortA.Maximum        = txtPortB.Maximum = cType.GetPortMax();
         grpDriveOptions.Visible = true;
         if (cType.IsMotor())
         {
             tabsMeta.Visible = true;
             tabsMeta.TabPages.Clear();
             tabsMeta.TabPages.Add(metaWheel);
             tabsMeta.TabPages.Add(metaGearing);
             chkBoxDriveWheel.Show();
             rbCAN.Show();
             rbPWM.Show();
             rbPWM.Checked = true;
         }
         else if (cType.IsPneumatic())
         {
             tabsMeta.Visible = true;
             tabsMeta.TabPages.Clear();
             tabsMeta.TabPages.Add(metaPneumatic);
         }
         else if (cType.IsElevator())
         {
             tabsMeta.Visible     = true;
             lblBrakePort.Enabled = false;
             brakePortA.Enabled   = false;
             brakePortB.Enabled   = false;
             tabsMeta.TabPages.Clear();
             chkBoxHasBrake.Show();
             tabsMeta.TabPages.Add(metaElevatorBrake);
             tabsMeta.TabPages.Add(metaElevatorStages);
             tabsMeta.TabPages.Add(metaGearing);
             if (cmbStages.SelectedIndex == -1)
             {
                 cmbStages.SelectedIndex = 0;
             }
         }
         else
         {
             tabsMeta.TabPages.Clear();
             tabsMeta.Visible = false;
         }
     }
     // Set window size
     tabsMeta.Visible = tabsMeta.TabPages.Count > 0;
     btnSave.Top      = tabsMeta.TabPages.Count > 0 ? tabsMeta.Bottom + 3 : (grpDriveOptions.Visible ? grpDriveOptions.Bottom + 3 : grpChooseDriver.Bottom + 3);
     base.Height      = btnSave.Bottom + 3 + (base.Height - base.ClientSize.Height);
 }