java.lang.Object
com.marginallyclever.ro3.node.Node
com.marginallyclever.ro3.node.nodes.limbsolver.LimbSolver

public class LimbSolver extends Node
LimbSolver calculates Inverse Kinematics for a Limb. Given a target and a linear velocity, LimbSolver will calculate and apply the joint velocities required to move the end effector towards the target in a straight line. When the end effector reaches the target (with a margin of error), LimbSolver will fire an ActionEvent "arrivedAtGoal".
  • Constructor Details

    • LimbSolver

      public LimbSolver()
    • LimbSolver

      public LimbSolver(String name)
  • Method Details

    • getTarget

      public NodePath<Pose> getTarget()
    • setTarget

      public void setTarget(Pose target)
      Set the target to move towards. target must be in the same node tree as this instance.
      Parameters:
      target - the target to move towards
    • update

      public void update(double dt)
      Description copied from class: Node
      Called every frame.
      Overrides:
      update in class Node
      Parameters:
      dt - the time since the last frame.
    • getLimb

      public NodePath<Limb> getLimb()
    • setLimb

      public void setLimb(Limb limb)
      Set the limb to be controlled by this instance. limb must be in the same node tree as this instance.
      Parameters:
      limb - the limb to control
    • readyToSolve

      public boolean readyToSolve()
      Returns:
      true if the solver has a limb, an end effector, and a target. Does not guarantee that a solution exists.
    • toJSON

      public org.json.JSONObject toJSON()
      Description copied from class: Node
      Serialize this node and its children to a JSON object and its children. Classes that override this method should call super.toJSON() first, then add to the object returned.
      Overrides:
      toJSON in class Node
      Returns:
      the JSON object.
    • fromJSON

      public void fromJSON(org.json.JSONObject from)
      Description copied from class: Node
      Deserialize this node and its children from a JSON object and its children. Classes that override this method should call super.fromJSON(). When they do it will trigger the creation of child nodes. The child nodes will then call their own fromJSON() methods.
      Overrides:
      fromJSON in class Node
      Parameters:
      from - the JSON object to read from.
    • scaleVectorToMagnitude

      public static void scaleVectorToMagnitude(double[] vector, double maxLen)

      Make sure the given vector's length does not exceed maxLen. It can be less than the given magnitude. If the maxLen is greater than the vector length, the vector is unchanged. This means as the limb approaches the target the velocity will slow down.

      Store the results in the original array.

      Parameters:
      vector - the vector to cap
      maxLen - the max length of the vector.
    • moveTargetToEndEffector

      public void moveTargetToEndEffector()
    • getComponents

      public void getComponents(List<JPanel> list)
      Description copied from class: Node
      Build a Swing Component that represents this Node.
      Overrides:
      getComponents in class Node
      Parameters:
      list - the list to add components to.
    • getLinearVelocity

      public double getLinearVelocity()
    • setLinearVelocity

      public void setLinearVelocity(double linearVelocity)
      Set the linear velocity of the end effector in cm/s.
      Parameters:
      linearVelocity - must be >= 0
    • getDistanceToTarget

      public double getDistanceToTarget()
      Returns:
      the distance to the target that is a combination of linear and angular distances.
    • getGoalMarginOfError

      public double getGoalMarginOfError()
      Returns:
      the distance to the target that is a combination of linear and angular distances.
    • setGoalMarginOfError

      public void setGoalMarginOfError(double goalMarginOfError)
      Parameters:
      goalMarginOfError - the distance to the target that is a combination of linear and angular distances.
    • addActionListener

      public void addActionListener(ActionListener listener)
    • removeActionListener

      public void removeActionListener(ActionListener listener)
    • setIsAtGoal

      public void setIsAtGoal(boolean isAtGoal)
    • getIsAtGoal

      public boolean getIsAtGoal()