private void ButtonNeuralOpenPanel_Click(object sender, RoutedEventArgs e) { WindowNeuralControlPanel wnd = new WindowNeuralControlPanel(); wnd.Show(); if (wnd.DialogResult == true) { SARNeural neural = new SARNeural(); MWArray output = neural.Predict(wnd.X1, wnd.X2, wnd.X3, wnd.X4, wnd.X5, wnd.X6, wnd.X7, wnd.X8, wnd.X9, wnd.X10, wnd.X11, wnd.X12); double[,] values = (double[, ])((MWNumericArray)output).ToArray(MWArrayComponent.Real); RecorderCommand command = new RecorderCommand { Duration = TimeSpan.FromSeconds(2.0), Joints = new List <CostumeJoint> { new CostumeJoint() { Name = "R.ShoulderF", Value = (float)values[0, 0] }, new CostumeJoint() { Name = "R.ShoulderS", Value = (float)values[0, 1] }, new CostumeJoint() { Name = "R.ElbowR", Value = (float)values[0, 2] }, new CostumeJoint() { Name = "R.Elbow", Value = (float)values[0, 3] }, new CostumeJoint() { Name = "R.WristR", Value = (float)values[0, 4] }, new CostumeJoint() { Name = "R.WritsS", Value = (float)values[0, 5] } } }; RobotAnswer answer = Robot.ExecuteCommand(command.Joints, command.Duration); AppLog.Write(answer.ToString()); } }
private void buttonSend_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; buttonSend.Enabled = false; String command = String.Empty; try { if (checkBoxReset.Checked) { // RESET Command text command = "ROBOT:MOTORS:R.ShoulderF;R.Elbow:POSSET:0;0"; } else { command = textBoxCommand.Text; } Int32 timeInSeconds = 0; Int32.TryParse(textBoxTime.Text, out timeInSeconds); TimeSpan time = TimeSpan.FromSeconds(timeInSeconds); float seconds = (float)time.TotalSeconds; CultureInfo cultureInfo = new CultureInfo("en-US"); command = String.Format("{0}:{1}", command, seconds.ToString(cultureInfo)); byte[] bytes = Encoding.ASCII.GetBytes(command.Trim() + Environment.NewLine); networkStream.Write(bytes, 0, bytes.Length); RobotAnswer robotAnswer = (RobotAnswer)networkStream.ReadByte(); labelRobotAnswer.Text = RobotAnswerToString(robotAnswer); } catch (Exception E) { // Try to reconnect // buttonConnection.PerformClick(); // buttonConnection.PerformClick(); ReConnect(); // Send the command again byte[] bytes = Encoding.ASCII.GetBytes(command.Trim() + Environment.NewLine); networkStream.Write(bytes, 0, bytes.Length); RobotAnswer robotAnswer = (RobotAnswer)networkStream.ReadByte(); labelRobotAnswer.Text = RobotAnswerToString(robotAnswer); } buttonSend.Enabled = true; Cursor.Current = Cursors.Default; }
private void ButtonPlayStart_Click(object sender, RoutedEventArgs e) { if (commands == null) { AppLog.Write("Невозможно воспроизвести запись. Не загружен список команд для робота."); return; } if (!Robot.Connected) { AppLog.Write("Невозможно воспроизвести запись. Отсутствует соединение с роботом."); return; } foreach (RecorderCommand command in commands) { RobotAnswer answer = Robot.ExecuteCommand(command.Joints, command.Duration); AppLog.Write(answer.ToString()); } }
private RobotAnswer SendData(string msg) { if (!_client.Connected) { Connected = false; return(RobotAnswer.NoConnection); } _wait = true; // Переводим секунды в милисекунды //int time = (int)(waitTime *1000); try { byte[] bytes = Encoding.ASCII.GetBytes(msg.Trim() + Environment.NewLine); _stream.Write(bytes, 0, bytes.Length); } catch (Exception E) { Connected = false; _wait = false; throw new Exception($"Возникла ошибка при отправке пакета данных роботу. {E.Message}"); } try { RobotAnswer exitCode = (RobotAnswer)_stream.ReadByte();; Connected = true; return(exitCode); } catch (Exception E) { Connected = false; _wait = false; ErrorOccured?.Invoke("Возникла ошибка при отправке команды. " + E.Message); return(RobotAnswer.ExceptionOccured); } }
private String RobotAnswerToString(RobotAnswer robotAnswer) { return(robotAnswer.ToString()); }