private void InicializarArduino() { AngulosDefault = new AngulosServos(ArduinoController.BRAZO_GB); try { Arduino = new ArduinoController(); if (String.IsNullOrEmpty(Ejercicio.EstadoInicial)) { Angulos = new AngulosServos(AngulosDefault.ToString()); } else { Angulos = new AngulosServos(Ejercicio.EstadoInicial); } Arduino.Inicializar(Angulos.ToString()); } catch (Exception) { Arduino = null; } }
private void WindowLoaded(object sender, RoutedEventArgs e) { //Asigno lo delegates consumoHombroArribaAbajoDelegate = new ConsumoHombroArribaAbajoDelegate(SetConsumoHombroArribaAbajo); consumoHombroAdelanteAtrasDelegate = new ConsumoHombroAdelanteAtras(SetConsumoHombroAdelanteAtras); consumoCodoArribaAbajoDelegate = new ConsumoCodoArribaAbajo(SetConsumoCodoArribaAbajo); consumoCodoDerechaIzquierdaDelegate = new ConsumoCodoDerechaIzquierda(SetConsumoCodoDerechaIzquierda); // Create the drawing group we'll use for drawing this.drawingGroup = new DrawingGroup(); // Create an image source that we can use in our image control this.imageSource = new DrawingImage(this.drawingGroup); // Display the drawing using our image control Image.Source = this.imageSource; foreach (var potentialSensor in KinectSensor.KinectSensors) { if (potentialSensor.Status == KinectStatus.Connected) { this.sensor = potentialSensor; break; } } if (null != this.sensor) { // Turn on the skeleton stream to receive skeleton frames this.sensor.SkeletonStream.Enable(); this.sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30); this.sensor.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30); this.colorPixels = new byte[this.sensor.ColorStream.FramePixelDataLength]; this.colorBitmap = new WriteableBitmap(this.sensor.ColorStream.FrameWidth, this.sensor.ColorStream.FrameHeight, 96.0, 96.0, PixelFormats.Bgr32, null); this.colorCoordinates = new ColorImagePoint[this.sensor.DepthStream.FramePixelDataLength]; this.depthWidth = this.sensor.DepthStream.FrameWidth; this.depthHeight = this.sensor.DepthStream.FrameHeight; int colorWidth = this.sensor.ColorStream.FrameWidth; int colorHeight = this.sensor.ColorStream.FrameHeight; this.colorToDepthDivisor = colorWidth / this.depthWidth; this.sensor.AllFramesReady += this.SensorAllFramesReady; this.colorToDepthDivisor = colorWidth / this.depthWidth; depthPixels = new DepthImagePixel[sensor.DepthStream.FramePixelDataLength]; // Start the sensor! try { this.sensor.Start(); } catch (IOException) { this.sensor = null; } } if (null == this.sensor) { //Image.Source = new BitmapImage( // new Uri("pack://application:,,,/AtaxiaVision;component/Imagenes/KinectAV.png")); //EstadoSnackBar("Kinect no lista."); if (null != this.sensor) { this.sensor.Stop(); this.sensor.Dispose(); } arduinoController.CerrarPuerto(); var win = new Inicio("Kinect no detectada, para el ejercicio de reach se requiere una. Conéctela e intente nuevamente"); win.Show(); Close(); } else { if (!arduinoController.Inicializar(ArduinoController.BRAZO_GB)) { if (null != this.sensor) { this.sensor.Stop(); this.sensor.Dispose(); } arduinoController.CerrarPuerto(); var win = new Inicio("Exoesqueleto no detectado. No se puede ejecutar el ejecicio sin el mismo."); win.Show(); Close(); } } TensionesServosBG(); //ReviarFaltaDeKinectOExoesqueleto(); existenciaKinectExoesqueletoDelegate = new ExistenciaKinectExoesqueletoDelegate(ReviarFaltaDeKinectOExoesqueleto); ExistenciaKinectExoesqueletoBackgroundWorker.DoWork += ReviarFaltaDeKinectOExoesqueletoBG; ExistenciaKinectExoesqueletoBackgroundWorker.RunWorkerAsync(); }
private void Window_Loaded(object sender, RoutedEventArgs e) { this.drawingGroup = new DrawingGroup(); this.imageSource = new DrawingImage(this.drawingGroup); Image.Source = this.imageSource; foreach (var potentialSensor in KinectSensor.KinectSensors) { if (potentialSensor.Status == KinectStatus.Connected) { this.sensor = potentialSensor; break; } } if (null != this.sensor) { this.sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30); this.colorPixels = new byte[this.sensor.ColorStream.FramePixelDataLength]; this.colorBitmap = new WriteableBitmap(this.sensor.ColorStream.FrameWidth, this.sensor.ColorStream.FrameHeight, 96.0, 96.0, PixelFormats.Bgr32, null); sensor.ColorFrameReady += Sensor_ColorFrameReady; try { this.sensor.Start(); } catch (IOException) { this.sensor = null; } } if (null == this.sensor) { Image.Source = new BitmapImage( new Uri("pack://application:,,,/AtaxiaVision;component/Imagenes/KinectAV.png")); EstadoSnackBar("Kinect no lista."); } seCortoExoesqueletoDelegate = new SeCortoExoesqueletoDelegate(DehabilitarBotones); estadoLabelDelegate = new EstadoLabelDelegate(EstadoCard); repetecionesLabelDelegate = new RepetecionesLabelDelegate(MostrarRepeticiones); repeticionButtonDelegate = new RepeticionButtonDelegate(EstadoRepetecionesButton); snackBarDelegate = new SnackBarDelegate(EstadoSnackBar); consumoHombroArribaAbajoDelegate = new ConsumoHombroArribaAbajoDelegate(SetConsumoHombroArribaAbajo); consumoHombroAdelanteAtrasDelegate = new ConsumoHombroAdelanteAtras(SetConsumoHombroAdelanteAtras); consumoCodoArribaAbajoDelegate = new ConsumoCodoArribaAbajo(SetConsumoCodoArribaAbajo); consumoCodoDerechaIzquierdaDelegate = new ConsumoCodoDerechaIzquierda(SetConsumoCodoDerechaIzquierda); reportesButtonDelegate = new ReportesButtonDelegate(VisibilidadReportesButton); TensionesServosBG(); EjecutarEjercicioManualBG(); // Preparo ejercicio manual LlenarComboBoxs(); // Lleno los combo boxs MostrarRepeticiones(0); // Lleno el campo de repeticiones //Si no se logra iniciar el arduino se vuelve a inicio //arduinoController.Inicializar(ArduinoController.BRAZO_GB); if (!arduinoController.Inicializar(ArduinoController.BRAZO_GB)) { Cerrar(); var win = new Inicio("Exoesqueleto no detectado. No se puede ejecutar el ejecicio sin el mismo."); win.Show(); Close(); } IniciarButton.Focus(); }