private void onSkeletonEvent(object sender, EventArgs e, double[] data) { processor = new DataProcessing(data); bruteWheelRotation = processor.WheelRotation(); bruteWheelSpeed = processor.WheelSpeed(); bruteAssyRotation = processor.AssyRotation(); bruteAssySpeed = processor.AssySpeed(); assyRotSmoother.updateValue(bruteAssyRotation); assySpeedSmoother.updateValue(bruteAssySpeed); wheelSpeedSmoother.updateValue(bruteWheelSpeed); wheelRotSmoother.updateValue(bruteWheelRotation); double wheelRotValue = wheelRotSmoother.UpdateExponential(); double wheelSpeedValue = wheelSpeedSmoother.UpdateExponential(); double assySpeedValue = assySpeedSmoother.UpdateExponential(); double assyRotValue = assyRotSmoother.UpdateExponential(); switch (drivingMode) { case "assy": assySpeedValue = processor.ValueToPourcentage("assySpeed", assySpeedValue); assySpeedValue = (wheelSpeedValue * 2 - 100) / 100; assyRotValue = processor.ValueToPourcentage("assyRotation", assyRotValue); assyRotValue = -(wheelRotValue * 2 - 100) / 250; robot.directionAngle += assyRotValue; robot.speed = assySpeedValue * 10; break; case "wheel": wheelSpeedValue = processor.ValueToPourcentage("wheelSpeed", wheelSpeedValue); wheelSpeedValue = (wheelSpeedValue * 2 - 100) / 100; wheelRotValue = processor.ValueToPourcentage("wheelRotation", wheelRotValue); wheelRotValue = -(wheelRotValue * 2 - 100) / 250; robot.directionAngle += wheelRotValue; robot.speed = wheelSpeedValue * 20; break; } // Console.WriteLine(wheelSpeedValue); robot.update(); MainCanvas.Children.Clear(); robot.draw(MainCanvas); if (robot.x > this.Width) { robot.x = 0; } else if (robot.x < 0) { robot.x = this.Width; } else if (robot.y < 10) { robot.y = this.Height; } else if (robot.y > this.Height) { robot.y = 10; } }
//Methods where the magic happens. //Every action depending on Kinect's available frame and data is to be written here. private void onSkeletonEvent(object sender, EventArgs e, double[] data) { processor = new DataProcessing(data); bruteWheelRotation = processor.WheelRotation(); bruteWheelSpeed = processor.WheelSpeed(); bruteAssyRotation = processor.AssyRotation(); bruteAssySpeed = processor.AssySpeed(); assyRotSmoother.updateValue(bruteAssyRotation); assySpeedSmoother.updateValue(bruteAssySpeed); wheelSpeedSmoother.updateValue(bruteWheelSpeed); wheelRotSmoother.updateValue(bruteWheelRotation); double wheelRotValue = wheelRotSmoother.UpdateExponential(); double wheelSpeedValue = wheelSpeedSmoother.UpdateExponential(); double assySpeedValue = assySpeedSmoother.UpdateExponential(); double assyRotValue = assyRotSmoother.UpdateExponential(); if(drivingDebugCheckBox.IsChecked.Value) { lblConsole.Text += "Wheel Speed Value : " + Math.Round(wheelSpeedValue) + "\n"; lblConsole.Text += "Wheel Rotation Value : " + Math.Round(wheelRotValue) + "\n"; lblConsole.Text += "Assymetric Speed Value : " + Math.Round(assySpeedValue) + "\n"; lblConsole.Text += "Assymetric Rotation Value : " + Math.Round(assyRotValue) + "\n"; } switch(drivingMode) { case "assy": speed = processor.ValueToPourcentage("assySpeed", assySpeedValue); rotation = processor.ValueToPourcentage("assyRotation", assyRotValue); updateCompassWidget(assyRotValue); updatePowerBar(speed, assySpeedValue); break; case "wheel": speed = processor.ValueToPourcentage("wheelSpeed", wheelSpeedValue); rotation = processor.ValueToPourcentage("wheelRotation", wheelRotValue); updateCompassWidget(wheelRotValue); updatePowerBar(speed, wheelSpeedValue); break; } scroolConsole.ScrollToEnd(); lblConsole.Text = lblConsole.Text.ToString().Substring((int)lblConsole.Text.Length / 6); //La méthode ValueToPourcentage retourn un Int16 et prend en paramères une string et un double. //Exemples d'utilisation de la méthode de transformation des valeurs pour le format de la trame. }