Beispiel #1
0
    /// <summary>
    /// Checks if the given driver type is a worm screw.
    /// </summary>
    /// <param name="type">Driver type</param>
    /// <returns>Boolean</returns>
    public static bool IsWormScrew(this JointDriverType type)
    {
        switch (type)
        {
        case JointDriverType.WORM_SCREW:
            return(true);

        default:
            return(false);
        }
    }
Beispiel #2
0
    /// <summary>
    /// Checks if the given driver type is pneumatic.
    /// </summary>
    /// <param name="type">Driver type</param>
    /// <returns>Boolean</returns>
    public static bool IsPneumatic(this JointDriverType type)
    {
        switch (type)
        {
        case JointDriverType.BUMPER_PNEUMATIC:
        case JointDriverType.RELAY_PNEUMATIC:
            return(true);

        default:
            return(false);
        }
    }
Beispiel #3
0
    /// <summary>
    /// Checks if the given driver type is a motor.
    /// </summary>
    /// <param name="type">Driver type</param>
    /// <returns>Boolean</returns>
    public static bool IsMotor(this JointDriverType type)
    {
        switch (type)
        {
        case JointDriverType.MOTOR:
        case JointDriverType.DUAL_MOTOR:
            return(true);

        default:
            return(false);
        }
    }
Beispiel #4
0
    /// <summary>
    /// Reads the binary representation of this driver from the stream.
    /// </summary>
    /// <param name="reader">Input stream</param>
    public void ReadBinaryData(System.IO.BinaryReader reader)
    {
        type       = (JointDriverType)((int)reader.ReadByte());
        port1      = reader.ReadInt16();
        port2      = reader.ReadInt16();
        lowerLimit = reader.ReadSingle();
        upperLimit = reader.ReadSingle();
        isCan      = reader.ReadBoolean();
        int extensions = reader.ReadInt32();

        MetaInfo.Clear();
        for (int i = 0; i < extensions; i++)
        {
            JointDriverMeta meta = JointDriverMeta.ReadDriverMeta(reader);
            AddInfo(meta);
        }
    }
Beispiel #5
0
    /// <summary>
    /// Gets the string representation of the port for the given driver type.
    /// </summary>
    /// <param name="type">Driver type</param>
    /// <returns>Name of port type</returns>
    public static string GetPortType(this JointDriverType type)
    {
        switch (type)
        {
        case JointDriverType.MOTOR:
        case JointDriverType.SERVO:
        case JointDriverType.DUAL_MOTOR:
        case JointDriverType.WORM_SCREW:
        case JointDriverType.ELEVATOR:
            return("PWM");

        case JointDriverType.BUMPER_PNEUMATIC:
            return("Solenoid");

        case JointDriverType.RELAY_PNEUMATIC:
            return("Relay");

        default:
            return("Unknown");
        }
    }
Beispiel #6
0
 public static bool IsElevator(this JointDriverType type)
 {
     return(type == JointDriverType.ELEVATOR);
 }
Beispiel #7
0
 /// <summary>
 /// Checks if the given driver type requires two ports.
 /// </summary>
 /// <param name="type">Driver type</param>
 /// <returns>True is the given type requires two ports</returns>
 public static bool HasTwoPorts(this JointDriverType type)
 {
     return(type == JointDriverType.BUMPER_PNEUMATIC || type == JointDriverType.DUAL_MOTOR);
 }
Beispiel #8
0
 /// <summary>
 /// Creates a joint driver with the given type.
 /// </summary>
 /// <param name="type">Driver type</param>
 public JointDriver(JointDriverType type)
     : this()
 {
     this.type = type;
 }
Beispiel #9
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();
        }
    }
Beispiel #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();
    }
Beispiel #11
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);
 }