private void saveButton_Click(object sender, EventArgs e) { RobotSensor addedSensor; try { addedSensor = new RobotSensor(sensorTypeOptions[typeBox.SelectedIndex]); } catch { MessageBox.Show("Please select a sensor type."); return; } //Doesn't save if numbers aren't entered correctly. addedSensor.portA = (int)this.PortANumericUpDown.Value; addedSensor.portB = (int)this.PortBNumericUpDown.Value; addedSensor.conversionFactor = (double)this.ConversionNumericUpDown.Value; if (sourceIndex >= 0 && sourceIndex < joint.attachedSensors.Count) { joint.attachedSensors[sourceIndex] = addedSensor; } else { joint.attachedSensors.Add(addedSensor); } Close(); }
public static RobotSensor ReadSensorFully(BinaryReader reader) { RobotSensor sensor = new RobotSensor(RobotSensorType.LIMIT); sensor.ReadBinaryData(reader); return(sensor); }
private void saveButton_Click(object sender, EventArgs e) { RobotSensor addedSensor; try { addedSensor = new RobotSensor(sensorTypeOptions[typeBox.SelectedIndex]); } catch { MessageBox.Show("Please select a sensor type."); return; } //Doesn't save if numbers aren't entered correctly. try { addedSensor.module = Convert.ToInt16(moduleTextBox.Text); addedSensor.port = Convert.ToInt16(portTextBox.Text); } catch { MessageBox.Show("Enter an integer for the module and port numbers."); return; } ///Gets all of the entered polynomial coefficients, seperating by commas. string[] coefficients = coefficentTextBox.Text.Split(','); float[] polyCoeff = new float[coefficients.Length]; for (int i = 0; i < coefficients.Length; i++) { ///Stores the coefficents from left to right. The coefficient of the lowest power is at index 0. try { polyCoeff[coefficients.Length - 1 - i] = Convert.ToSingle(coefficients[i]); } catch { MessageBox.Show("For coefficients, enter only numbers followed by commas."); return; } } addedSensor.equation = new Polynomial(polyCoeff); addedSensor.useSecondarySource = secondaryBox.Checked; if (sourceIndex >= 0 && sourceIndex < joint.attachedSensors.Count) { joint.attachedSensors[sourceIndex] = addedSensor; } else { joint.attachedSensors.Add(addedSensor); } Close(); }
public JointSensorEditorForm(SkeletalJoint_Base passJoint, int sourceIndex = -1) { InitializeComponent(); AnalyticsUtils.LogPage("Advanced Joint Editor / Sensor List", "Sensor Editor"); this.sourceIndex = sourceIndex; joint = passJoint; typeBox.Items.Clear(); sensorTypeOptions = RobotSensor.GetAllowedSensors(joint); foreach (RobotSensorType sensorType in sensorTypeOptions) { typeBox.Items.Add(char.ToUpper(Enum.GetName(typeof(RobotSensorType), sensorType).Replace('_', ' ')[0]) + Enum.GetName(typeof(RobotSensorType), sensorType).Replace('_', ' ').Substring(1).ToLower()); } Console.WriteLine(sourceIndex >= 0 && sourceIndex < joint.attachedSensors.Count); base.Text = (sourceIndex >= 0 && sourceIndex < joint.attachedSensors.Count) ? ("Editing Sensor # " + sourceIndex) : "New Sensor"; if (sourceIndex >= 0 && sourceIndex < joint.attachedSensors.Count) { RobotSensor sensor = joint.attachedSensors[sourceIndex]; typeBox.SelectedIndex = Array.IndexOf(sensorTypeOptions, sensor.type); PortANumericUpDown.Value = (decimal)sensor.portA; PortBNumericUpDown.Value = (decimal)sensor.portB; ConversionNumericUpDown.Value = (decimal)sensor.conversionFactor; } switch (joint.GetJointType()) { case SkeletalJointType.ROTATIONAL: this.ConversionLbl.Text = "Counts Per Rev"; break; case SkeletalJointType.LINEAR: this.ConversionLbl.Text = "Counts Per Inch"; break; case SkeletalJointType.CYLINDRICAL: this.ConversionLbl.Text = "Counts Per Rev"; break; } if (typeBox.SelectedIndex == 0) { this.PortALbl.Enabled = true; this.PortANumericUpDown.Enabled = true; this.PortBLbl.Visible = true; this.PortBNumericUpDown.Visible = true; this.ConversionLbl.Visible = true; this.ConversionNumericUpDown.Visible = true; } else { this.PortALbl.Enabled = false; this.PortANumericUpDown.Enabled = false; this.PortBLbl.Visible = false; this.PortBNumericUpDown.Visible = false; this.ConversionLbl.Visible = false; this.ConversionNumericUpDown.Visible = false; } }
/// <summary> /// Used for writing the data from a RobotSensor. /// </summary> /// <param name="sensor"></param> /// <param name="writer"></param> private static void WriteRobotSensor(RobotSensor sensor, XmlWriter writer) { writer.WriteStartElement("RobotSensor"); writer.WriteElementString("SensorType", sensor.type.ToString()); writer.WriteElementString("SensorModule", sensor.module.ToString()); writer.WriteElementString("SensorPort", sensor.port.ToString()); WritePolynomial(sensor.equation, writer); writer.WriteElementString("UseSecondarySource", sensor.useSecondarySource.ToString().ToLower()); writer.WriteEndElement(); }
/// <summary> /// Used for writing the data from a RobotSensor. /// </summary> /// <param name="sensor"></param> /// <param name="writer"></param> private static void WriteRobotSensor(RobotSensor sensor, XmlWriter writer) { writer.WriteStartElement("RobotSensor"); writer.WriteElementString("SensorType", sensor.type.ToString()); writer.WriteElementString("SensorPortNumberA", sensor.portA.ToString()); writer.WriteElementString("SensorSignalTypeA", sensor.conTypePortA.ToString()); writer.WriteElementString("SensorPortNumberB", sensor.portB.ToString()); writer.WriteElementString("SensorSignalTypeB", sensor.conTypePortB.ToString()); writer.WriteElementString("SensorConversionFactor", sensor.conversionFactor.ToString()); writer.WriteEndElement(); }
/// <summary> /// Read a RobotSensor from the given XmlReader. /// </summary> /// <param name="reader"></param> /// <returns></returns> private static RobotSensor ReadRobotSensor_4_2(XmlReader reader) { RobotSensor robotSensor = null; //throw (new Exception("Reading thing")); foreach (string name in IOUtilities.AllElements(reader)) { switch (name) { case "SensorType": // Initialize the RobotSensor. robotSensor = new RobotSensor((RobotSensorType)Enum.Parse(typeof(RobotSensorType), reader.ReadElementContentAsString())); break; case "SensorPortNumberA": // Assign a value to the 1st port. robotSensor.portA = float.Parse(reader.ReadElementContentAsString()); break; case "SensorSignalTypeA": // Assign a value to the 2nd port. robotSensor.conTypePortA = (SensorConnectionType)Enum.Parse(typeof(SensorConnectionType), reader.ReadElementContentAsString()); break; case "SensorPortNumberB": // Assign a port type to the 1st port robotSensor.portB = float.Parse(reader.ReadElementContentAsString()); break; case "SensorSignalTypeB": // Assign a port type to the 1st port robotSensor.conTypePortB = (SensorConnectionType)Enum.Parse(typeof(SensorConnectionType), reader.ReadElementContentAsString()); break; case "SensorConversionFactor": // assings the generic conversion facter, this is a different type/ unit for every robot (CPR in encoders) robotSensor.conversionFactor = double.Parse(reader.ReadElementContentAsString()); if (robotSensor.conversionFactor == 0) { robotSensor.conversionFactor = 1; } break; } } return(robotSensor); }
/// <summary> /// Read a RobotSensor from the given XmlReader. /// </summary> /// <param name="reader"></param> /// <returns></returns> private static RobotSensor ReadRobotSensor_5_0(XmlReader reader) { RobotSensor robotSensor = null; //throw (new Exception("Reading thing")); foreach (string name in IOUtilities.AllElements(reader)) { switch (name) { case "SensorType": // Initialize the RobotSensor. robotSensor = new RobotSensor((RobotSensorType)Enum.Parse(typeof(RobotSensorType), reader.ReadElementContentAsString())); break; case "SensorPortNumberA": // Assign a value to the port. robotSensor.portA = float.Parse(reader.ReadElementContentAsString()); break; case "SensorSignalTypeA": // Assign a value to the port. robotSensor.conTypePortA = (SensorConnectionType)Enum.Parse(typeof(SensorConnectionType), reader.ReadElementContentAsString()); break; case "SensorPortNumberB": // Assign a value to the port. robotSensor.portB = float.Parse(reader.ReadElementContentAsString()); break; case "SensorSignalTypeB": // Assign a value to the port. robotSensor.conTypePortB = (SensorConnectionType)Enum.Parse(typeof(SensorConnectionType), reader.ReadElementContentAsString()); break; case "SensorConversionFactor": // Assign a value to useSecondarySource. robotSensor.conversionFactor = double.Parse(reader.ReadElementContentAsString()); if (robotSensor.conversionFactor == 0) { robotSensor.conversionFactor = 1; } break; } } return(robotSensor); }
public EditSensorForm(SkeletalJoint_Base passJoint, int sourceIndex = -1) { InitializeComponent(); this.sourceIndex = sourceIndex; joint = passJoint; typeBox.Items.Clear(); sensorTypeOptions = RobotSensor.GetAllowedSensors(joint); foreach (RobotSensorType sensorType in sensorTypeOptions) { typeBox.Items.Add(Enum.GetName(typeof(RobotSensorType), sensorType).Replace('_', ' ').ToLowerInvariant()); } Console.WriteLine(sourceIndex >= 0 && sourceIndex < joint.attachedSensors.Count); base.Text = (sourceIndex >= 0 && sourceIndex < joint.attachedSensors.Count) ? ("Editing Sensor # " + sourceIndex) : "New Sensor"; if (sourceIndex >= 0 && sourceIndex < joint.attachedSensors.Count) { RobotSensor sensor = joint.attachedSensors[sourceIndex]; typeBox.SelectedIndex = Array.IndexOf(sensorTypeOptions, sensor.type); portTextBox.Text = Convert.ToString(sensor.port); moduleTextBox.Text = Convert.ToString(sensor.module); secondaryBox.Checked = sensor.useSecondarySource; { StringBuilder coeffTxt = new StringBuilder(); for (int i = sensor.equation.coeff.Length - 1; i >= 0; i--) { coeffTxt.Append(sensor.equation.coeff[i]); if (i > 0) { coeffTxt.Append(","); } } coefficentTextBox.Text = coeffTxt.ToString(); coefficentTextBox_TextChanged(null, null); } } ///Only applies to cylindrical joints. True use secondary means to use the linear component rather than rotation. if (joint.GetJointType() == SkeletalJointType.CYLINDRICAL) { secondaryBox.Visible = true; } FormClosing += delegate(object sender, FormClosingEventArgs e) { LegacyInterchange.LegacyEvents.OnRobotModified(); }; }
/// <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> /// Read a RobotSensor from the given XmlReader. /// </summary> /// <param name="reader"></param> /// <returns></returns> private static RobotSensor ReadRobotSensor_3_0(XmlReader reader) { RobotSensor robotSensor = null; foreach (string name in IOUtilities.AllElements(reader)) { switch (name) { case "SensorType": // Initialize the RobotSensor. robotSensor = new RobotSensor((RobotSensorType)Enum.Parse(typeof(RobotSensorType), reader.ReadElementContentAsString())); break; case "SensorModule": // Assign a value to the module. short m = (short)reader.ReadElementContentAsInt(); break; case "SensorPort": // Assign a value to the port. short s = (short)reader.ReadElementContentAsInt(); break; case "Polynomial": // Create a polynomial and assign it to the equation. Polynomial e = ReadPolynomial_3_0(reader.ReadSubtree()); break; case "UseSecondarySource": // Assign a value to useSecondarySource. reader.ReadElementContentAsBoolean(); break; } } return(robotSensor); }
/// <summary> /// Compares two sensors, returns true if all fields are identical. /// </summary> /// <param name="otherSensor"></param> public bool Equals(RobotSensor otherSensor) { return(module == otherSensor.module && port == otherSensor.port); // Other fields are not important for equivalancy }
/// <summary> /// Recursive utility for JointDataLoad. /// </summary> /// <param name="propertySets">Group of property sets to add any new property sets to.</param> /// <param name="currentNode">Current node to save joint data of.</param> /// <returns>True if all data was loaded successfully.</returns> private static bool LoadJointData(PropertySets propertySets, RigidNode_Base currentNode) { var allSuccessful = true; foreach (var connection in currentNode.Children) { var joint = connection.Key; var child = connection.Value; // Name of the property set in inventor var setName = "bxd-jointdata-" + child.GetModelID(); // Attempt to open the property set var propertySet = InventorDocumentIOUtils.GetPropertySet(propertySets, setName, false); // If the property set does not exist, stop loading data if (propertySet == null) { return(false); } joint.weight = InventorDocumentIOUtils.GetProperty(propertySet, "weight", 10); // Get joint properties from set // Get driver information if (InventorDocumentIOUtils.GetProperty(propertySet, "has-driver", false)) { if (joint.cDriver == null) { joint.cDriver = new JointDriver((JointDriverType)InventorDocumentIOUtils.GetProperty(propertySet, "driver-type", (int)JointDriverType.MOTOR)); } var driver = joint.cDriver; joint.cDriver.motor = (MotorType)InventorDocumentIOUtils.GetProperty(propertySet, "motor-type", (int)MotorType.GENERIC); joint.cDriver.port1 = InventorDocumentIOUtils.GetProperty(propertySet, "driver-port1", 0); joint.cDriver.port2 = InventorDocumentIOUtils.GetProperty(propertySet, "driver-port2", -1); joint.cDriver.isCan = InventorDocumentIOUtils.GetProperty(propertySet, "driver-isCan", false); joint.cDriver.lowerLimit = InventorDocumentIOUtils.GetProperty(propertySet, "driver-lowerLimit", 0.0f); joint.cDriver.upperLimit = InventorDocumentIOUtils.GetProperty(propertySet, "driver-upperLimit", 0.0f); joint.cDriver.InputGear = InventorDocumentIOUtils.GetProperty(propertySet, "driver-inputGear", 0.0f); // writes the gearing that the user last had in the exporter to the current gearing value joint.cDriver.OutputGear = InventorDocumentIOUtils.GetProperty(propertySet, "driver-outputGear", 0.0f); // writes the gearing that the user last had in the exporter to the current gearing value joint.cDriver.hasBrake = InventorDocumentIOUtils.GetProperty(propertySet, "driver-hasBrake", false); // Get other properties stored in meta // Wheel information if (InventorDocumentIOUtils.GetProperty(propertySet, "has-wheel", false)) { if (driver.GetInfo <WheelDriverMeta>() == null) { driver.AddInfo(new WheelDriverMeta()); } var wheel = joint.cDriver.GetInfo <WheelDriverMeta>(); wheel.type = (WheelType)InventorDocumentIOUtils.GetProperty(propertySet, "wheel-type", (int)WheelType.NORMAL); wheel.isDriveWheel = InventorDocumentIOUtils.GetProperty(propertySet, "wheel-isDriveWheel", false); wheel.SetFrictionLevel((FrictionLevel)InventorDocumentIOUtils.GetProperty(propertySet, "wheel-frictionLevel", (int)FrictionLevel.MEDIUM)); } // Pneumatic information if (InventorDocumentIOUtils.GetProperty(propertySet, "has-pneumatic", false)) { if (driver.GetInfo <PneumaticDriverMeta>() == null) { driver.AddInfo(new PneumaticDriverMeta()); } var pneumatic = joint.cDriver.GetInfo <PneumaticDriverMeta>(); pneumatic.width = InventorDocumentIOUtils.GetProperty(propertySet, "pneumatic-diameter", (double)0.5); pneumatic.pressureEnum = (PneumaticPressure)InventorDocumentIOUtils.GetProperty(propertySet, "pneumatic-pressure", (int)PneumaticPressure.MEDIUM); } // Elevator information if (InventorDocumentIOUtils.GetProperty(propertySet, "has-elevator", false)) { if (driver.GetInfo <ElevatorDriverMeta>() == null) { driver.AddInfo(new ElevatorDriverMeta()); } var elevator = joint.cDriver.GetInfo <ElevatorDriverMeta>(); elevator.type = (ElevatorType)InventorDocumentIOUtils.GetProperty(propertySet, "elevator-type", (int)ElevatorType.NOT_MULTI); if (((int)elevator.type) > 7) { elevator.type = ElevatorType.NOT_MULTI; } } for (var i = 0; i < InventorDocumentIOUtils.GetProperty(propertySet, "num-sensors", 0); i++) { RobotSensor addedSensor; addedSensor = new RobotSensor((RobotSensorType)InventorDocumentIOUtils.GetProperty(propertySet, "sensorType" + i, (int)RobotSensorType.ENCODER)); addedSensor.portA = ((int)InventorDocumentIOUtils.GetProperty(propertySet, "sensorPortA" + i, 0)); addedSensor.portB = ((int)InventorDocumentIOUtils.GetProperty(propertySet, "sensorPortB" + i, 0)); addedSensor.conTypePortA = ((SensorConnectionType)InventorDocumentIOUtils.GetProperty(propertySet, "sensorPortConA" + i, (int)SensorConnectionType.DIO)); addedSensor.conTypePortB = ((SensorConnectionType)InventorDocumentIOUtils.GetProperty(propertySet, "sensorPortConB" + i, (int)SensorConnectionType.DIO)); addedSensor.conversionFactor = InventorDocumentIOUtils.GetProperty(propertySet, "sensorConversion" + i, 0.0); joint.attachedSensors.Add(addedSensor); } } // Recur along this child if (!LoadJointData(propertySets, child)) { allSuccessful = false; } } // Save was successful return(allSuccessful); }
/// <summary> /// Compares two sensors, returns true if all fields are identical. /// </summary> /// <param name="otherSensor"></param> public bool Equals(RobotSensor otherSensor) { return(portA == otherSensor.portA && portB == otherSensor.portB && conversionFactor == otherSensor.conversionFactor); // Other fields are not important for equivalancy }