/// <summary> /// Used for writing joint driver data. /// </summary> /// <param name="driver"></param> /// <param name="writer"></param> private static void WriteJointDriver(JointDriver driver, XmlWriter writer) { writer.WriteStartElement("JointDriver"); writer.WriteElementString("DriveType", driver.GetDriveType().ToString()); writer.WriteElementString("MotorType", driver.GetMotorType().ToString()); writer.WriteElementString("Port1", (driver.port1 + 1).ToString()); // Synthesis engine downshifts port numbers due to old code using 1 and 2 for drive. writer.WriteElementString("Port2", (driver.port2 + 1).ToString()); // For backwards compatibility, ports will be stored one larger than their actual value. if (driver.InputGear == 0) // prevents a gearing of 0 from being written to the bxdj { driver.InputGear = 1; } if (driver.OutputGear == 0)// prevents a gearing of 0 from being written to the bxdj { driver.OutputGear = 1; } writer.WriteElementString("InputGear", driver.InputGear.ToString()); // writes the input gear's string to the XMLWriter writer.WriteElementString("OutputGear", driver.OutputGear.ToString()); // writes the output gear's string to the XMLWriter writer.WriteElementString("LowerLimit", driver.lowerLimit.ToString("F4")); writer.WriteElementString("UpperLimit", driver.upperLimit.ToString("F4")); writer.WriteElementString("SignalType", driver.isCan ? "CAN" : "PWM"); writer.WriteElementString("HasBrake", driver.hasBrake.ToString().ToLower()); foreach (JointDriverMeta meta in driver.MetaInfo.Values) { WriteJointDriverMeta(meta, writer); } writer.WriteEndElement(); }
// Generation Methods private RigidNode_Base CreateNodeWithChild() { RotationalJoint_Base joint = new RotationalJoint_Base(); joint.axis = new BXDVector3(2, 2, 2); joint.basePoint = new BXDVector3(3, 131, 3); JointDriver driver = new JointDriver(JointDriverType.MOTOR); driver.SetPort(414); driver.isCan = true; WheelDriverMeta wheelDriverMeta = new WheelDriverMeta(); wheelDriverMeta.radius = 9.4F; wheelDriverMeta.center = new BXDVector3(1, 1, 1); driver.AddInfo(wheelDriverMeta); joint.cDriver = driver; Guid childID = new Guid(); RigidNode_Base baseNode = new RigidNode_Base(id); RigidNode_Base childNode = new RigidNode_Base(childID); baseNode.AddChild(joint, childNode); return(baseNode); }
public void LoadRobot(RobotDataManager robotDataManager) { SuspendLayout(); DefinePartsLayout.Controls.Clear(); DefinePartsLayout.RowStyles.Clear(); jointCards.Clear(); foreach (var node in robotDataManager.RobotBaseNode.ListAllNodes()) { if (node.GetSkeletalJoint() == null || JointDriver.GetAllowedDrivers(node.GetSkeletalJoint()).Length == 0) { continue; } var panel = new JointCardUC(node, this, robotDataManager) { Dock = DockStyle.Top }; jointCards.Add(panel); AddControlToNewTableRow(panel, DefinePartsLayout); } jointCards.ForEach(card => card.LoadPreviewIcon()); ResumeLayout(); }
public JointDriver[] GetBones(HumanBodyBones _type) { JointDriver primaryBone = GetBone(HumanBodyBones.RightShoulder); JointDriver secondaryBone = GetBone(HumanBodyBones.RightShoulder); JointDriver tertiaryBone = GetBone(HumanBodyBones.RightShoulder); switch (_type) { case HumanBodyBones.RightHand: primaryBone = GetBone(HumanBodyBones.RightUpperArm); secondaryBone = GetBone(HumanBodyBones.RightLowerArm); tertiaryBone = GetBone(HumanBodyBones.RightHand); break; case HumanBodyBones.LeftHand: primaryBone = GetBone(HumanBodyBones.LeftUpperArm); secondaryBone = GetBone(HumanBodyBones.LeftLowerArm); tertiaryBone = GetBone(HumanBodyBones.LeftHand); break; case HumanBodyBones.RightFoot: primaryBone = GetBone(HumanBodyBones.RightUpperLeg); secondaryBone = GetBone(HumanBodyBones.RightLowerLeg); tertiaryBone = GetBone(HumanBodyBones.RightFoot); break; case HumanBodyBones.LeftFoot: primaryBone = GetBone(HumanBodyBones.LeftUpperLeg); secondaryBone = GetBone(HumanBodyBones.LeftLowerLeg); tertiaryBone = GetBone(HumanBodyBones.LeftFoot); break; } return(new JointDriver[] { primaryBone, secondaryBone, tertiaryBone }); }
/// <summary> /// Reads a JointDriver from the given XmlReader. /// </summary> /// <param name="reader"></param> /// <returns></returns> private static JointDriver ReadJointDriver_2_0(XmlReader reader) { JointDriver driver = null; foreach (string name in IOUtilities.AllElements(reader)) { switch (name) { case "DriveType": // Initialize the driver. driver = new JointDriver((JointDriverType)Enum.Parse(typeof(JointDriverType), reader.ReadElementContentAsString())); break; case "PortA": // Assign a value to portA. driver.portA = reader.ReadElementContentAsInt(); break; case "PortB": // Assign a value to portB. driver.portB = reader.ReadElementContentAsInt(); break; case "LowerLimit": // Assign a value to the lowerLimit. driver.lowerLimit = float.Parse(reader.ReadElementContentAsString()); break; case "UpperLimit": // Assign a value to the upperLimit. driver.upperLimit = float.Parse(reader.ReadElementContentAsString()); break; case "SignalType": // Assign a value to isCan. driver.isCan = reader.ReadElementContentAsString().Equals("CAN") ? true : false; break; case "ElevatorDriverMeta": // Add an ElevatorDriverMeta. driver.AddInfo(ReadElevatorDriverMeta_2_0(reader.ReadSubtree())); break; case "PneumaticDriverMeta": // Add a PneumaticsDriverMeta. driver.AddInfo(ReadPneumaticDriverMeta_2_0(reader.ReadSubtree())); break; case "WheelDriverMeta": // Add a WheelDriverMeta. driver.AddInfo(ReadWheelDriverMeta_2_0(reader.ReadSubtree())); break; } } return(driver); }
void FixedUpdate() { if (!umbilicalAttached) { JointDriver hip = skeleton.GetBone(HumanBodyBones.LeftUpperLeg); hip.rb.isKinematic = false; } MoveFoot(HumanBodyBones.LeftFoot, leftLegPos); MoveFoot(HumanBodyBones.RightFoot, rightLegPos); MoveHand(HumanBodyBones.LeftHand, leftArmPos); MoveHand(HumanBodyBones.RightHand, rightArmPos); }
private static float GetOutput(JointDriver cDriver) { if (!cDriver.GetDriveType().IsMotor()) { throw new Exception("Motor controller output is not motor"); } int motor_controller_address = cDriver.port1 - 1; if (cDriver.isCan) { return(can_motor_controllers.ContainsKey(motor_controller_address) ? can_motor_controllers[motor_controller_address] : 0f); } return(pwm_motor_controllers[motor_controller_address]); }
/// <summary> /// Used for writing joint driver data. /// </summary> /// <param name="driver"></param> /// <param name="writer"></param> private static void WriteJointDriver(JointDriver driver, XmlWriter writer) { writer.WriteStartElement("JointDriver"); writer.WriteElementString("DriveType", driver.GetDriveType().ToString()); writer.WriteElementString("PortA", driver.portA.ToString()); writer.WriteElementString("PortB", driver.portB.ToString()); writer.WriteElementString("LowerLimit", driver.lowerLimit.ToString("F4")); writer.WriteElementString("UpperLimit", driver.upperLimit.ToString("F4")); writer.WriteElementString("SignalType", driver.isCan ? "CAN" : "PWM"); foreach (JointDriverMeta meta in driver.MetaInfo.Values) { WriteJointDriverMeta(meta, writer); } writer.WriteEndElement(); }
/// <summary> /// Reads the backing information for this joint from the input stream. /// </summary> /// <param name="reader">Input stream</param> public void ReadBinaryJoint(System.IO.BinaryReader reader) { // ID is already read ReadBinaryJointInternal(reader); if (reader.ReadBoolean()) { cDriver = new JointDriver(JointDriverType.MOTOR); cDriver.ReadBinaryData(reader); } else { cDriver = null; } int sensorCount = reader.ReadInt32(); attachedSensors = new List <RobotSensor>(sensorCount); for (int i = 0; i < sensorCount; i++) { attachedSensors.Add(RobotSensor.ReadSensorFully(reader)); } }
/// <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(); } }
/// <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(); }
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); }
/// <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(); } }
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); }
public void LoadValues() { advancedSettingsForm = new AdvancedJointSettingsForm(node.GetSkeletalJoint()); var joint = node.GetSkeletalJoint(); var typeOptions = JointDriver.GetAllowedDrivers(joint); // TODO: This doesn't protect multi-edit jointTypeComboBox.Items.Clear(); if (typeOptions.Contains(JointDriverType.MOTOR)) { jointTypeComboBox.Items.AddRange(new object[] { "(Select an option)", "Drivetrain Wheel", "Mechanism Joint" }); } else { jointTypeComboBox.Items.AddRange(new object[] { "(Select an option)", "Mechanism Joint" }); } driverTypeComboBox.Items.Clear(); var textInfo = new CultureInfo("en-US", true).TextInfo; foreach (var type in typeOptions) { var name = Enum.GetName(typeof(JointDriverType), type); if (name != null) // TODO: Get rid of this mess { driverTypeComboBox.Items.Add(textInfo.ToTitleCase(name.Replace('_', ' ').ToLowerInvariant())); } } jointName.Text = ToStringUtils.NodeNameString(node); // Defaults when switched: weightInput.Value = 0; dtSideComboBox.SelectedIndex = 0; wheelTypeComboBox.SelectedIndex = 0; driverTypeComboBox.SelectedIndex = 0; var jointDriver = joint.cDriver; // sometimes null if (jointDriver == null) { jointTypeComboBox.SelectedItem = "(Select an option)"; } else if (jointDriver.port1 <= 2) // Drivetrain wheel { jointTypeComboBox.SelectedItem = "Drivetrain Wheel"; dtSideComboBox.SelectedIndex = jointDriver.port1; var wheelDriverMeta = jointDriver.GetInfo <WheelDriverMeta>(); if (wheelDriverMeta != null) { wheelTypeComboBox.SelectedIndex = (int)wheelDriverMeta.type - 1; } } else // Mechanism joint { jointTypeComboBox.SelectedItem = "Mechanism Joint"; weightInput.Value = (decimal)Math.Max(joint.weight, 0); driverTypeComboBox.SelectedIndex = Array.IndexOf(typeOptions, joint.cDriver.GetDriveType()); } }
public void SaveValues() { var joint = node.GetSkeletalJoint(); if ((string)jointTypeComboBox.SelectedItem == "(Select an option)") { joint.cDriver = null; joint.weight = 0; } else { // Driver type var cType = (string)jointTypeComboBox.SelectedItem == "Drivetrain Wheel" ? JointDriverType.MOTOR : JointDriver.GetAllowedDrivers(joint)[driverTypeComboBox.SelectedIndex]; if (joint.cDriver == null || !joint.cDriver.GetDriveType().Equals(cType)) // Defaults { joint.cDriver = new JointDriver(cType) { port1 = 3, port2 = 3, InputGear = 1, OutputGear = 1, lowerLimit = 0, upperLimit = 0, isCan = true }; } // Always joint.cDriver.hasBrake = true; joint.cDriver.motor = MotorType.GENERIC; joint.cDriver.InputGear = 1; joint.cDriver.OutputGear = advancedSettingsForm.GearRatio; joint.cDriver.lowerLimit = 0; joint.cDriver.upperLimit = 0; if ((string)jointTypeComboBox.SelectedItem == "Drivetrain Wheel") { // Port/wheel side joint.cDriver.port1 = dtSideComboBox.SelectedIndex; joint.cDriver.isCan = true; // Wheel type var wheelDriver = new WheelDriverMeta { type = (WheelType)wheelTypeComboBox.SelectedIndex + 1, isDriveWheel = true }; wheelDriver.SetFrictionLevel(FrictionLevel.MEDIUM); joint.cDriver.AddInfo(wheelDriver); // Weight joint.weight = 0; } else if ((string)jointTypeComboBox.SelectedItem == "Mechanism Joint") { // Port/wheel side joint.cDriver.port1 = advancedSettingsForm.PortId; if (joint.cDriver.port1 <= 2) { joint.cDriver.port1 = 2; } joint.cDriver.isCan = advancedSettingsForm.IsCan; // Wheel driver joint.cDriver.RemoveInfo <WheelDriverMeta>(); // Weight joint.weight = (double)weightInput.Value; } } }
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); }
/// <summary> /// Reads a JointDriver from the given XmlReader. /// </summary> /// <param name="reader"></param> /// <returns></returns> private static JointDriver ReadJointDriver_4_2(XmlReader reader) { JointDriver driver = null; foreach (string name in IOUtilities.AllElements(reader)) { switch (name) { case "DriveType": // Initialize the driver. driver = new JointDriver((JointDriverType)Enum.Parse(typeof(JointDriverType), reader.ReadElementContentAsString())); break; case "Port1": // Assign a value to port1. driver.port1 = reader.ReadElementContentAsInt(); break; case "Port2": // Assign a value to port2. driver.port2 = reader.ReadElementContentAsInt(); break; case "InputGear": // Assign a value to InputGear driver.InputGear = reader.ReadElementContentAsDouble(); break; case "OutputGear": // Assign a value to OutputGear driver.OutputGear = reader.ReadElementContentAsDouble(); break; case "LowerLimit": // Assign a value to the lowerLimit. driver.lowerLimit = float.Parse(reader.ReadElementContentAsString()); break; case "UpperLimit": // Assign a value to the upperLimit. driver.upperLimit = float.Parse(reader.ReadElementContentAsString()); break; case "HasBrake": // Assign a value to the upperLimit. driver.hasBrake = reader.ReadElementContentAsBoolean(); break; case "SignalType": // Assign a value to isCan. driver.isCan = reader.ReadElementContentAsString().Equals("CAN") ? true : false; break; case "ElevatorDriverMeta": // Add an ElevatorDriverMeta. driver.AddInfo(ReadElevatorDriverMeta_4_2(reader.ReadSubtree())); break; case "PneumaticDriverMeta": // Add a PneumaticsDriverMeta. driver.AddInfo(ReadPneumaticDriverMeta_4_2(reader.ReadSubtree())); break; case "WheelDriverMeta": // Add a WheelDriverMeta. driver.AddInfo(ReadWheelDriverMeta_4_2(reader.ReadSubtree())); break; } } return(driver); }
public void ClearConfiguration() { cDriver = null; attachedSensors = new List <RobotSensor>(); }