ik

package
v0.51.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2024 License: AGPL-3.0 Imports: 14 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func JointMetric

func JointMetric(segment *Segment) float64

JointMetric is a metric which will sum the squared differences in each input from start to end.

func L2InputMetric

func L2InputMetric(segment *Segment) float64

L2InputMetric is a metric which will return a L2 norm of the StartConfiguration and EndConfiguration in an arc input.

func NewMetricMinFunc added in v0.48.1

func NewMetricMinFunc(metric StateMetric, frame referenceframe.Frame, logger logging.Logger) func([]float64) float64

NewMetricMinFunc takes a metric and a frame, and converts to a function able to be minimized with Solve().

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 SolveMetric added in v0.48.1

func SolveMetric(
	ctx context.Context,
	ik Solver,
	frame referenceframe.Frame,
	solutionChan chan<- *Solution,
	seed []referenceframe.Input,
	solveMetric StateMetric,
	rseed int,
	logger logging.Logger,
) error

SolveMetric is a wrapper for Metrics to be used easily with Solve for IK solvers.

func SquaredNormNoOrientSegmentMetric

func SquaredNormNoOrientSegmentMetric(segment *Segment) float64

SquaredNormNoOrientSegmentMetric is a metric which will return the cartesian distance between the two positions.

Types

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.

func (*Segment) String added in v0.26.0

func (s *Segment) String() string

type SegmentMetric

type SegmentMetric func(*Segment) float64

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 []float64
	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 Solver added in v0.48.1

type Solver interface {
	referenceframe.Limited
	// Solve receives a context, a channel to which solutions will be provided, a function whose output should be minimized, and a
	// number of iterations to run.
	Solve(context.Context, chan<- *Solution, []float64, func([]float64) float64, int) error
}

Solver defines an interface which, provided with seed inputs and a function to minimize to zero, will output all found solutions to the provided channel until cancelled or otherwise completes.

func CreateCombinedIKFrameSolver added in v0.48.1

func CreateCombinedIKFrameSolver(
	model referenceframe.Frame,
	logger logging.Logger,
	nCPU int,
	goalThreshold float64,
) (Solver, error)

CreateCombinedIKFrameSolver creates a combined parallel IK solver that operates on a frame 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 CreateNloptSolver added in v0.48.1

func CreateNloptSolver(
	limits []referenceframe.Limit,
	logger logging.Logger,
	iter int,
	exact, useRelTol bool,
) (Solver, error)

CreateNloptSolver creates an nloptIK object that can perform gradient descent on functions. The parameters are the limits of the solver, 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.

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

type StateMetric func(*State) float64

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL