/// <summary> Creates a command. </summary> /// <param name="devices"> The devices. </param> /// <param name="addresses"> The addresses. </param> /// <param name="command"> The command. </param> /// <param name="wait"> The wait. </param> /// <param name="parameter1"> The first parameter. </param> /// <param name="parameter2"> The second parameter. </param> /// <returns> The new command. </returns> public SequenceItem CreateCommand(ELLDevices devices, List <char> addresses, ELLCommands command, TimeSpan wait, decimal parameter1, ELLBaseDevice.DeviceDirection parameter2) { if (!addresses.Any()) { return(null); } ELLDevice device = devices.AddressedDevice(addresses.First()) as ELLDevice; if (device == null) { return(null); } if (addresses.Count == 1) { switch (command) { case ELLCommands.GetPosition: return(new SequenceItem(command, device.Address, device.GetPosition, command.GetStringValue(), wait)); case ELLCommands.Forward: return(new SequenceItem(command, device.Address, device.JogForward, command.GetStringValue(), wait)); case ELLCommands.Backward: return(new SequenceItem(command, device.Address, device.JogBackward, command.GetStringValue(), wait)); case ELLCommands.Home: return(new SequenceItem(command, device.Address, () => device.Home(parameter2), command.GetStringValue(), wait)); case ELLCommands.MoveRelative: return(new SequenceItem(command, device.Address, () => device.MoveRelative(parameter1), command.GetStringValue(), wait)); case ELLCommands.MoveAbsolute: return(new SequenceItem(command, device.Address, () => device.MoveAbsolute(parameter1), command.GetStringValue(), wait)); case ELLCommands.SetJogstepSize: return(new SequenceItem(command, device.Address, () => device.SetJogstepSize(parameter1), command.GetStringValue(), wait)); } } else { switch (command) { case ELLCommands.Forward: return(new SequenceItem(command, device.Address, () => device.JogForward(addresses), command.GetStringValue(), wait)); case ELLCommands.Backward: return(new SequenceItem(command, device.Address, () => device.JogBackward(addresses), command.GetStringValue(), wait)); case ELLCommands.Home: return(new SequenceItem(command, device.Address, () => device.Home(addresses, parameter2), command.GetStringValue(), wait)); case ELLCommands.MoveRelative: return(new SequenceItem(command, device.Address, () => device.MoveRelative(addresses, parameter1), command.GetStringValue(), wait)); case ELLCommands.MoveAbsolute: return(new SequenceItem(command, device.Address, () => device.MoveAbsolute(addresses, parameter1), command.GetStringValue(), wait)); } } return(null); }
private void FeedBack(object obj, EventArgs e) { double theta; double tolerance = Convert.ToDouble(toleranceTextBox.Text) / 100.0; textBox2.Text = initialSignal.ToString(); double change = 0; var signalBeforeCorrection = ReadKrochmann(); double signalAfterCorrection = 0.0; change = (initialSignal - signalBeforeCorrection) / initialSignal; var counter = 1; while (Math.Abs(change) > tolerance) { if (change == Math.Abs(change)) { theta = Math.Acos(Math.Sqrt(signalBeforeCorrection / initialSignal)) * 180.0 / Math.PI; addressedDevice.MoveRelative(-(decimal)(theta)); } else { theta = Math.Acos(Math.Sqrt(initialSignal / signalBeforeCorrection)) * 180.0 / Math.PI; addressedDevice.MoveRelative((decimal)(theta)); } signalAfterCorrection = ReadKrochmann(); change = (initialSignal - signalAfterCorrection) / initialSignal; if (counter >= 5) { string str = ""; if (Math.Abs(change) > tolerance) { str = initialSignal.ToString() + "\t" + signalAfterCorrection + "\t" + "could not correct"; } else { str = initialSignal.ToString() + "\t" + signalAfterCorrection + "\t" + "corrected"; } WriteToFile(str); break; } } }
private void RotationMount4MoveRelativeButton_Click(object sender, EventArgs e) { string input = RotationMount4MoveRelativeTextBox.Text; if (input == "") { return; } decimal i; var s = decimal.TryParse(input, out i); addressedDevice4.MoveRelative(i); decimal val = addressedDevice4.Position; decimal roundedVal = Math.Round(val, 3); RotationMount4CurrentPosition.Text = roundedVal.ToString() + "deg"; OutputWindowString = OutputWindowString + "Device 4 move relative by " + input + "deg\n"; PrintOutBox.Text = OutputWindowString; }