Documentation ¶
Overview ¶
Package ik contains tols for doing gradient-descent based inverse kinematics, allowing for the minimization of arbitrary metrics based on the output of calling `Transform` on the given frame.
Index ¶
- func JointMetric(segment *Segment) float64
- func L2InputMetric(segment *Segment) float64
- func NewPoseFlexOVMetricConstructor(alpha float64) func(spatial.Pose) StateMetric
- func OrientDist(o1, o2 spatial.Orientation) float64
- func OrientDistToRegion(goal spatial.Orientation, alpha float64) func(spatial.Orientation) float64
- func SquaredNormNoOrientSegmentMetric(segment *Segment) float64
- type CombinedIK
- type InverseKinematics
- type NloptIK
- type Segment
- type SegmentMetric
- type Solution
- type State
- type StateMetric
- func CombineMetrics(metrics ...StateMetric) StateMetric
- func NewPosWeightSquaredNormMetric(goal spatial.Pose) StateMetric
- func NewPositionOnlyMetric(goal spatial.Pose) StateMetric
- func NewScaledSquaredNormMetric(goal spatial.Pose, orientationDistanceScale float64) StateMetric
- func NewSquaredNormMetric(goal spatial.Pose) StateMetric
- func NewZeroMetric() StateMetric
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func JointMetric ¶
JointMetric is a metric which will sum the squared differences in each input from start to end.
func L2InputMetric ¶
L2InputMetric is a metric which will return a L2 norm of the StartConfiguration and EndConfiguration in an arc input.
func NewPoseFlexOVMetricConstructor ¶ added in v0.10.0
func NewPoseFlexOVMetricConstructor(alpha float64) func(spatial.Pose) StateMetric
NewPoseFlexOVMetricConstructor will provide a distance function which will converge on a pose with an OV within an arclength of `alpha` of the ov of the goal given.
func OrientDist ¶
func OrientDist(o1, o2 spatial.Orientation) float64
OrientDist returns the arclength between two orientations in degrees.
func OrientDistToRegion ¶
func OrientDistToRegion(goal spatial.Orientation, alpha float64) func(spatial.Orientation) float64
OrientDistToRegion will return a function which will tell you how far the unit sphere component of an orientation vector is from a region defined by a point and an arclength around it. The theta value of OV is disregarded. This is useful, for example, in defining the set of acceptable angles of attack for writing on a whiteboard.
func SquaredNormNoOrientSegmentMetric ¶
SquaredNormNoOrientSegmentMetric is a metric which will return the cartesian distance between the two positions.
Types ¶
type CombinedIK ¶
type CombinedIK struct {
// contains filtered or unexported fields
}
CombinedIK defines the fields necessary to run a combined solver.
func CreateCombinedIKSolver ¶
func CreateCombinedIKSolver(model referenceframe.Frame, logger logging.Logger, nCPU int, goalThreshold float64) (*CombinedIK, error)
CreateCombinedIKSolver creates a combined parallel IK solver with a number of nlopt solvers equal to the nCPU passed in. Each will be given a different random seed. When asked to solve, all solvers will be run in parallel and the first valid found solution will be returned.
func (*CombinedIK) DoF ¶ added in v0.18.0
func (ik *CombinedIK) DoF() []referenceframe.Limit
DoF returns the DoF of the associated referenceframe.
func (*CombinedIK) Frame ¶
func (ik *CombinedIK) Frame() referenceframe.Frame
Frame returns the associated referenceframe.
func (*CombinedIK) Solve ¶
func (ik *CombinedIK) Solve(ctx context.Context, c chan<- *Solution, seed []referenceframe.Input, m StateMetric, rseed int, ) error
Solve will initiate solving for the given position in all child solvers, seeding with the specified initial joint positions. If unable to solve, the returned error will be non-nil.
type InverseKinematics ¶
type InverseKinematics interface { referenceframe.Limited // Solve receives a context, the goal arm position, and current joint angles. Solve(context.Context, chan<- *Solution, []referenceframe.Input, StateMetric, int) error }
InverseKinematics defines an interface which, provided with seed inputs and a Metric to minimize to zero, will output all found solutions to the provided channel until cancelled or otherwise completes.
type NloptIK ¶
type NloptIK struct {
// contains filtered or unexported fields
}
NloptIK TODO.
func CreateNloptIKSolver ¶
func CreateNloptIKSolver(mdl referenceframe.Frame, logger logging.Logger, iter int, exact, useRelTol bool) (*NloptIK, error)
CreateNloptIKSolver creates an nloptIK object that can perform gradient descent on metrics for Frames. The parameters are the Frame on which Transform() will be called, a logger, and the number of iterations to run. If the iteration count is less than 1, it will be set to the default of 5000.
func (*NloptIK) DoF ¶ added in v0.18.0
func (ik *NloptIK) DoF() []referenceframe.Limit
DoF returns the DoF of the associated referenceframe.
func (*NloptIK) Frame ¶
func (ik *NloptIK) Frame() referenceframe.Frame
Frame returns the associated referenceframe.
func (*NloptIK) GenerateRandomPositions ¶
func (ik *NloptIK) GenerateRandomPositions(randSeed *rand.Rand) []referenceframe.Input
GenerateRandomPositions generates a random set of positions within the limits of this solver.
type Segment ¶
type Segment struct { StartPosition spatial.Pose EndPosition spatial.Pose StartConfiguration []referenceframe.Input EndConfiguration []referenceframe.Input Frame referenceframe.Frame }
Segment contains all the information a constraint needs to determine validity for a movement. It contains the starting inputs, the ending inputs, corresponding poses, and the frame it refers to. Pose fields may be empty, and may be filled in by a constraint that needs them.
type SegmentMetric ¶
SegmentMetric are functions which produce some score given an Segment. Lower is better. This is used to sort produced IK solutions by goodness, for example.
func NewSquaredNormSegmentMetric ¶
func NewSquaredNormSegmentMetric(orientationScaleFactor float64) SegmentMetric
NewSquaredNormSegmentMetric returns a metric which will return the cartesian distance between the two positions. It allows the caller to choose the scaling level of orientation.
type Solution ¶
type Solution struct { Configuration []referenceframe.Input Score float64 Exact bool }
Solution is the struct returned from an IK solver. It contains the solution configuration, the score of the solution, and a flag indicating whether that configuration and score met the solution criteria requested by the caller.
type State ¶
type State struct { Position spatial.Pose Configuration []referenceframe.Input Frame referenceframe.Frame }
State contains all the information a constraint needs to determine validity for a movement. It contains the starting inputs, the ending inputs, corresponding poses, and the frame it refers to. Pose fields may be empty, and may be filled in by a constraint that needs them.
type StateMetric ¶
StateMetric are functions which, given a State, produces some score. Lower is better. This is used for gradient descent to converge upon a goal pose, for example.
func CombineMetrics ¶
func CombineMetrics(metrics ...StateMetric) StateMetric
CombineMetrics will take a variable number of Metrics and return a new Metric which will combine all given metrics into one, summing their distances.
func NewPosWeightSquaredNormMetric ¶ added in v0.17.0
func NewPosWeightSquaredNormMetric(goal spatial.Pose) StateMetric
NewPosWeightSquaredNormMetric is a distance function between two poses to be used for gradient descent. This changes the magnitude of the position delta used to be smaller and avoid numeric instability issues that happens with large floats. TODO: RSDK-6053 this should probably be done more flexibly.
func NewPositionOnlyMetric ¶
func NewPositionOnlyMetric(goal spatial.Pose) StateMetric
NewPositionOnlyMetric returns a Metric that reports the point-wise distance between two poses without regard for orientation. This is useful for scenarios where there are not enough DOF to control orientation, but arbitrary spatial points may still be arrived at.
func NewScaledSquaredNormMetric ¶ added in v0.31.0
func NewScaledSquaredNormMetric(goal spatial.Pose, orientationDistanceScale float64) StateMetric
NewScaledSquaredNormMetric is a distance function between two poses. It allows the user to scale the contribution of orientation.
func NewSquaredNormMetric ¶
func NewSquaredNormMetric(goal spatial.Pose) StateMetric
NewSquaredNormMetric is the default distance function between two poses to be used for gradient descent.
func NewZeroMetric ¶
func NewZeroMetric() StateMetric
NewZeroMetric always returns zero as the distance between two points.