/// <summary> /// This method will be called on the timer interval /// </summary> public void SetMotorValues() { MotorData intermediateData = CurrentMotorData; if (TargetMotorData == null) { TargetMotorData = CurrentMotorData; } intermediateData.LeftMotor = IntermediatePwmCalculator(CurrentMotorData.LeftMotor, TargetMotorData.LeftMotor); intermediateData.RightMotor = IntermediatePwmCalculator(CurrentMotorData.RightMotor, TargetMotorData.RightMotor); ValueHolder[(int)ArduinoValues.LeftMotorPwm] = intermediateData.LeftMotor.Speed; ValueHolder[(int)ArduinoValues.LeftMotorCcw] = intermediateData.LeftMotor.IsCcw ? 1 : 0; ValueHolder[(int)ArduinoValues.RightMotorPwm] = intermediateData.RightMotor.Speed; ValueHolder[(int)ArduinoValues.RightMotorCcw] = intermediateData.RightMotor.IsCcw ? 1 : 0; }
/// <summary> /// Set valueHolder initial values /// </summary> private void SetInitialValues() { XDocument xml = XDocument.Load(@"Data\ArduinoValues.xml"); List <XElement> elements = xml.Root.Element("ArduinoDefaultValues").Elements().ToList(); foreach (XElement element in elements) { ValueHolder.Add( (int)(ArduinoValues)Enum.Parse(typeof(ArduinoValues), (string)element.Attribute("name")), int.Parse(element.Value)); } CurrentMotorData = new MotorData( new InnerMotorData(ValueHolder[(int)ArduinoValues.LeftMotorCcw] == 1, ValueHolder[(int)ArduinoValues.LeftMotorPwm]), new InnerMotorData(ValueHolder[(int)ArduinoValues.LeftMotorCcw] == 1, ValueHolder[(int)ArduinoValues.LeftMotorPwm]) ); }
/// <summary> /// Set target /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="trigger"></param> public void UpdateMotors(int x, int y, int trigger) { TargetMotorData = GetMotorData(x, y, trigger); }