Skip to content

Commit

Permalink
Fix #47 part 1/2/3 not finished
Browse files Browse the repository at this point in the history
  • Loading branch information
vertigra committed Oct 5, 2023
1 parent 904d531 commit a2c8ad9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 34 deletions.
14 changes: 8 additions & 6 deletions Configs/buttons.binding.default.json
Original file line number Diff line number Diff line change
@@ -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

--


--


*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -55,7 +53,7 @@ public override void HeadUpDown(float value)
new ServoCommandsItem
{
Name = ServoNames.Neck,
GoalPosition = newGoalPosition
GoalPosition = goalPosition
}
}
};
Expand All @@ -69,18 +67,24 @@ 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<ServoCommandsItem>
{
new ServoCommandsItem
{
Name = ServoNames.Neck,
GoalPosition = mNeckZeroPosition + value
GoalPosition = goalPosition
}
}
};
Expand Down Expand Up @@ -112,18 +116,24 @@ 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<ServoCommandsItem>
{
new ServoCommandsItem
{
Name = ServoNames.Neck,
GoalPosition = mNeckZeroPosition - value
GoalPosition = goalPosition
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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");
}
}

Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit a2c8ad9

Please sign in to comment.