diff --git a/Configs/buttons.binding.default.json b/Configs/buttons.binding.default.json index 8ffc87c..5eaa48c 100644 --- a/Configs/buttons.binding.default.json +++ b/Configs/buttons.binding.default.json @@ -1,14 +1,16 @@ { /* - Action: + - to_home_position: the command to return the Adam robot to the zero position + -- - execution conditions: - if binding to buttons: button pressed value { == true } => execute - if binding to trigger: trigger value { >= 0.5 } => execute - if binding to axis: axis value { <= -0.5 or >= 0.5 } => execute + + -- + + + -- + */ diff --git a/XpadControl.Common.Services/AdamActionsMethods/AdamActionsMethods.cs b/XpadControl.Common.Services/AdamActionsMethods/AdamActionsMethods.cs index dd083af..d83c2fb 100644 --- a/XpadControl.Common.Services/AdamActionsMethods/AdamActionsMethods.cs +++ b/XpadControl.Common.Services/AdamActionsMethods/AdamActionsMethods.cs @@ -43,10 +43,8 @@ public override void HomePositionCommandExecute() public override void HeadUpDown(float value) { - WriteDebubLog(); - int zeroPositions = mNeckZeroPosition; - int newGoalPosition = value.ToServoRange(zeroPositions); + int goalPosition = value.ToServoRange(zeroPositions); ServoCommands command = new() { @@ -55,7 +53,7 @@ public override void HeadUpDown(float value) new ServoCommandsItem { Name = ServoNames.Neck, - GoalPosition = newGoalPosition + GoalPosition = goalPosition } } }; @@ -69,10 +67,16 @@ public override void HeadUpDown(float value) #region HeadUp - public override void HeadUp(int value) + public override void HeadUp(float value) { WriteDebubLog(); + if (value == float.NegativeInfinity) + value = value * -1; + + int zeroPositions = mNeckZeroPosition; + int goalPosition = value.ToServoRange(zeroPositions); + ServoCommands command = new() { Motors = new List @@ -80,7 +84,7 @@ public override void HeadUp(int value) new ServoCommandsItem { Name = ServoNames.Neck, - GoalPosition = mNeckZeroPosition + value + GoalPosition = goalPosition } } }; @@ -112,10 +116,16 @@ public override void HeadUp(bool value) #region HeadDown - public override void HeadDown(int value) + public override void HeadDown(float value) { WriteDebubLog(); + if (value == float.NegativeInfinity) + value = value * -1; + + int zeroPositions = mNeckZeroPosition; + int goalPosition = value.ToServoRange(zeroPositions); + ServoCommands command = new() { Motors = new List @@ -123,7 +133,7 @@ public override void HeadDown(int value) new ServoCommandsItem { Name = ServoNames.Neck, - GoalPosition = mNeckZeroPosition - value + GoalPosition = goalPosition } } }; diff --git a/XpadControl.Common.Services/AdamActionsMethods/AdamActionsMethodsBase.cs b/XpadControl.Common.Services/AdamActionsMethods/AdamActionsMethodsBase.cs index cd9b026..b1e8ea1 100644 --- a/XpadControl.Common.Services/AdamActionsMethods/AdamActionsMethodsBase.cs +++ b/XpadControl.Common.Services/AdamActionsMethods/AdamActionsMethodsBase.cs @@ -46,7 +46,7 @@ public virtual void HeadUpDown(ActionEventArgs eventArgs) { if (eventArgs.IsButton == IsButton.IsButtonPressed) { - throw new NotImplementedException("Button can`t binding to axis value"); + throw new NotImplementedException("Button can`t binding to axis action"); } if (eventArgs.IsAxis != IsAxis.None) @@ -56,6 +56,7 @@ public virtual void HeadUpDown(ActionEventArgs eventArgs) if (eventArgs.IsTrigger != IsTrigger.None) { + throw new NotImplementedException("Trigger can`t binding to axis action"); } } @@ -74,22 +75,16 @@ public virtual void HeadDown(ActionEventArgs eventArgs) if (eventArgs.IsAxis != IsAxis.None) { - float floatValue = eventArgs.FloatValue / 2; - int intValue = (int) Math.Round(floatValue); - - HeadDown(intValue); + HeadDown(eventArgs.FloatValue); } if (eventArgs.IsTrigger != IsTrigger.None) { - float floatValue = eventArgs.FloatValue / 2; - int intValue = (int)Math.Round(floatValue); - - HeadDown(intValue); + HeadDown(eventArgs.FloatValue); } } - public abstract void HeadDown(int value); + public abstract void HeadDown(float value); public abstract void HeadDown(bool value); #endregion @@ -105,22 +100,16 @@ public virtual void HeadUp(ActionEventArgs eventArgs) if (eventArgs.IsAxis != IsAxis.None) { - float floatValue = eventArgs.FloatValue / 2; - int intValue = (int) Math.Round(floatValue); - - HeadUp(intValue); + HeadUp(eventArgs.FloatValue); } if (eventArgs.IsTrigger != IsTrigger.None) { - float floatValue = eventArgs.FloatValue / 2; - int intValue = (int)Math.Round(floatValue); - - HeadUp(intValue); + HeadUp(eventArgs.FloatValue); } } - public abstract void HeadUp(int value); + public abstract void HeadUp(float value); public abstract void HeadUp(bool value); #endregion diff --git a/XpadControl.Interfaces/BindingButtonsService.Dependencies/AdamActions.cs b/XpadControl.Interfaces/BindingButtonsService.Dependencies/AdamActions.cs index 8d752eb..41627d4 100644 --- a/XpadControl.Interfaces/BindingButtonsService.Dependencies/AdamActions.cs +++ b/XpadControl.Interfaces/BindingButtonsService.Dependencies/AdamActions.cs @@ -33,7 +33,7 @@ public enum AdamActions [EnumMember(Value = "head_left_right")] HeadLeftRight = 6, - #region head up/down + #region head head_up_down/head_up/head_down [EnumMember(Value = "head_up_down")] HeadUpDown = 7,