Documentation
¶
Index ¶
- Constants
- Variables
- func Degrees(x float64) float64
- func NewDirectMotorIKGenerator() func() LegIK
- func Radians(x float64) float64
- type AxesRemapper
- type DirectMotorIK
- type DummyMotorController
- type DummyRotationSensor
- type LegIK
- type MotorController
- type PCAMotorController
- type Quadruped
- func (q *Quadruped) LoadFromFile(filename string) error
- func (q *Quadruped) SaveToFile(filename string) error
- func (q *Quadruped) SetExtraMotorNow(motorName string, angle float64)
- func (q *Quadruped) SetLegPosition(leg string, pos Vec3)
- func (q *Quadruped) ShoulderVec(leg string) Vec3
- func (q *Quadruped) Update()
- type Quat
- func (qin Quat) Apply(vec Vec3) Vec3
- func (qin Quat) Conj() Quat
- func (q Quat) HeadingAngle() float64
- func (qin Quat) Inv() Quat
- func (qin Quat) Neg() Quat
- func (q Quat) NoYaw() Quat
- func (qin Quat) Norm() float64
- func (qin Quat) Norm2() float64
- func (q Quat) Prod(q2 Quat) Quat
- func (a Quat) RotateByGlobal(b Quat) Quat
- func (a Quat) RotateByLocal(b Quat) Quat
- func (q Quat) String() string
- func (qin Quat) Unit() Quat
- type RawArduinoRotationSensor
- type RotationSensor
- type UPSTimer
- type Vec3
- func (v Vec3) Add(v2 Vec3) Vec3
- func (v Vec3) AngleTo(v2 Vec3) float64
- func (v Vec3) Cross(v2 Vec3) Vec3
- func (v Vec3) Dot(v2 Vec3) float64
- func (v Vec3) Inv() Vec3
- func (v Vec3) Len() float64
- func (v Vec3) Mul(f float64) Vec3
- func (v Vec3) MulVec(v2 Vec3) Vec3
- func (v Vec3) ProjectToPlane(normal Vec3) Vec3
- func (v Vec3) Rotated(q Quat) Vec3
- func (v Vec3) String() string
- func (v Vec3) Sub(v2 Vec3) Vec3
- func (v Vec3) Unit() Vec3
Constants ¶
const LegBackLeft = "back_left"
const LegBackRight = "back_right"
const LegFrontLeft = "front_left"
const LegFrontRight = "front_right"
Variables ¶
var ( // Downwards unit vector. DEPRECATED: USE `Down` DirDown = Vec3{0, 1, 0} // Upwards unit vector. DEPRECATED: USE `Up` DirUp = DirDown.Inv() // Forwards unit vector. DEPRECATED: USE `Forward` DirForward = Vec3{1, 0, 0} // Backwards unit vector. DEPRECATED: USE `Backward` DirBackward = DirForward.Inv() // Left unit vector. DEPRECATED: USE `Left` DirLeft = Vec3{0, 0, 1} // Right unit vector. DEPRECATED: USE `Right` DirRight = DirLeft.Inv() )
These are for compatibility. Dont use them
var ( // Downwards unit vector Down = DirDown // Upwards unit vector Up = DirUp // Left unit vector Left = DirLeft // Right unit vector Right = DirRight // Forwards unit vector Forward = DirForward // Backwards unit vector Backward = DirBackward // Zero vector Zero = Vec3{0, 0, 0} )
var AllLegs = []string{LegFrontLeft, LegFrontRight, LegBackLeft, LegBackRight}
AllLegs is an ordered list of all the legs of a robot, useful for looping
var QuatIdentity = NewQuat(1, 0, 0, 0)
Functions ¶
func NewDirectMotorIKGenerator ¶
func NewDirectMotorIKGenerator() func() LegIK
NewDirectMotorIKGenerator creates a function to create empty DirectMotorIK structs. This is used by robot to create a seperate controller for each leg
Types ¶
type AxesRemapper ¶ added in v0.1.10
type AxesRemapper struct {
SrcForwardVector Vec3 `json:"src-forward"`
SrcUpVector Vec3 `json:"src-up"`
SrcLeftVector Vec3 `json:"src-left"`
TargetForwardVector Vec3 `json:"target-forward"`
TargetUpVector Vec3 `json:"target-up"`
TargetLeftVector Vec3 `json:"target-left"`
}
AxesRemapper allows remapping of vectors from one axis space to another
func NewAxesRemapper ¶ added in v0.1.10
func NewAxesRemapper(SrcForwardVector, SrcUpVector, SrcLeftVector Vec3) *AxesRemapper
Returns an AxesRemapper with source vectors forward, up, and left. These are the vectors that represent the axes in the system we will convert from. By default, the target axes are spotpuppy Forward, Up, Left
func (*AxesRemapper) Remap ¶ added in v0.1.10
func (a *AxesRemapper) Remap(v Vec3) Vec3
Remap the vector from coordinate system with Src axes to coordinate system with Target axes, whilst keeping the meaning of the vector
func (*AxesRemapper) RemapInverse ¶ added in v0.1.10
func (a *AxesRemapper) RemapInverse(v Vec3) Vec3
Remap the vector from coordinate system with Target axes to coordinate system with Src axes, whilst keeping the meaning of the vector
type DirectMotorIK ¶
type DirectMotorIK struct {
ReverseKneeJoint bool `json:"reverse_knee_joint"`
ReverseHipXJoint bool `json:"reverse_hip_x_joint"`
ReverseHipZJoint bool `json:"reverse_hip_z_joint"`
FlipXAxis bool `json:"flip_x_axis"`
KneeOffset float64 `json:"knee_offset"`
HipXOffset float64 `json:"hip_x_offset"`
HipZOffset float64 `json:"hip_z_offset"`
// BoneLength is the length from the foot to the knee
BoneLength float64 `json:"bone_length"`
}
DirectMotorIK is an IK driver for 3 jointed legs (like Spot Mini), with one motor at each joint (no control rods or gears), and where the distance form foot to knee is the same as knee to hip
func (*DirectMotorIK) CalculateMotorRotations ¶
func (dm *DirectMotorIK) CalculateMotorRotations(pos Vec3) []float64
CalculateMotorRotations calculates the rotations of the three motors, and returns them in the order (hip left right, hip forwards backwords, knee)
func (*DirectMotorIK) GetMotorNames ¶
func (dm *DirectMotorIK) GetMotorNames() []string
func (*DirectMotorIK) GetRestingPosition ¶
func (dm *DirectMotorIK) GetRestingPosition() Vec3
GetRestingPosition returns the position where all of the joints are at 0 degrees
func (*DirectMotorIK) LoadJson ¶
func (dm *DirectMotorIK) LoadJson(data []byte) error
Loads json data into this object
type DummyMotorController ¶
DummyMotorController is a basic MotorController. It does include a dummy servo mapping
func NewDummyMotorController ¶
func NewDummyMotorController() *DummyMotorController
NewDummyMotorController creates a new dummy motor controller
func (*DummyMotorController) CalibrateAllJoints ¶ added in v0.0.6
func (d *DummyMotorController) CalibrateAllJoints()
func (*DummyMotorController) CreateMotorMapping ¶
func (d *DummyMotorController) CreateMotorMapping(names []string)
CreateMotorMapping creates a map from string to int for this dummy. It then sets all servos to channel -1
func (*DummyMotorController) SetMotor ¶
func (d *DummyMotorController) SetMotor(s string, f float64)
SetMotor does nothing for dummy motor controller
func (*DummyMotorController) Setup ¶
func (d *DummyMotorController) Setup()
Setup does nothing for DummyMotorController
type DummyRotationSensor ¶
type DummyRotationSensor struct{}
DummyRotationSensor is a rotation sensor that does nothing
func NewDummyRotationSensor ¶
func NewDummyRotationSensor() *DummyRotationSensor
NewDummyRotationSensor creates a new DummyRotationSensor
func (*DummyRotationSensor) Calibrate ¶
func (d *DummyRotationSensor) Calibrate()
Calibrate does nothing for DummyRotationSensor
func (*DummyRotationSensor) GetQuaternion ¶ added in v0.1.0
func (d *DummyRotationSensor) GetQuaternion() Quat
GetQuaternion returns identity for DummyRotationSensor
func (*DummyRotationSensor) Setup ¶ added in v0.1.7
func (d *DummyRotationSensor) Setup()
Setup does nothing for DummyRotationSensor
type LegIK ¶
type LegIK interface {
// CalculateMotorRotations gets a list of motor rotations from a foot position relative to this leg.
// The returned servo positions should be in the same order as GetMotorNames
// (ie the first value of the rotations should be for the first servo name returned by GetMotorNames)
CalculateMotorRotations(vector Vec3) []float64
// GetMotorNames returns a list of the motor names of this leg. See CalculateMotorRotations for more info
GetMotorNames() []string
// GetRestingPosition returns the position of the foot of this leg such that the motor rotations are all 0
GetRestingPosition() Vec3
// LoadJson loads the json data into this object
LoadJson(data []byte) error
}
LegIK describes types that can calculate motor rotations from a foot endpoint
type MotorController ¶
type MotorController interface {
// SetMotor allows setting of a named motor to an angle between -90 to 90
SetMotor(string, float64)
// CreateMotorMapping is for initialising any motor mapping that is stored with all possible motor names
CreateMotorMapping([]string)
// Setup is called once the motor controller has a motor mapping set up and has been loaded from a file.
// This could be used, for example, to create a servo object for each item in the mapping
Setup()
// CalibrateAllJoints is called to calibrate all joint positions. It can block until complete. It is only useful for brushless motors, not servos.
CalibrateAllJoints()
}
MotorController is an interface type to allow setting of positions to named motors
type PCAMotorController ¶ added in v0.0.4
type PCAMotorController struct {
ServoOptions *pca9685.ServOptions `json:"servo-options"`
Mapping map[string]int `json:"mapping"`
// contains filtered or unexported fields
}
func NewPCAMotorController ¶ added in v0.0.4
func NewPCAMotorController() *PCAMotorController
func (*PCAMotorController) CalibrateAllJoints ¶ added in v0.0.6
func (d *PCAMotorController) CalibrateAllJoints()
func (*PCAMotorController) CreateMotorMapping ¶ added in v0.0.4
func (d *PCAMotorController) CreateMotorMapping(names []string)
func (*PCAMotorController) SetMotor ¶ added in v0.0.4
func (d *PCAMotorController) SetMotor(s string, a float64)
func (*PCAMotorController) Setup ¶ added in v0.0.4
func (d *PCAMotorController) Setup()
type Quadruped ¶
type Quadruped struct {
Legs legs `json:"legs"`
MotorController MotorController `json:"motor_controller"`
BodyDimensionX float64 `json:"body_dimension_x"`
BodyDimensionZ float64 `json:"body_dimension_z"`
// contains filtered or unexported fields
}
Quadruped is a type to collect four LegIK objects, a motor controller, and some robot info together, to allow easy control
func NewQuadruped ¶
func NewQuadruped(newIK func() LegIK, motorController MotorController) *Quadruped
NewQuadruped creates a new quadruped from a function to create empty LegIK objects, and a MotorController. No objects in the robot will be set up correctly, and it is recommended that a file load is performed before anything else
func NewQuadrupedWithExtraMotors ¶
func NewQuadrupedWithExtraMotors(newIK func() LegIK, motorController MotorController, extraMotors []string) *Quadruped
NewQuadrupedWithExtraMotors creates a new quadruped from a function to create empty LegIK objects, and a MotorController. It also adds the specified servo names to the servo map. No objects in the robot will be set up correctly, and it is recommended that a file load is performed before anything else
func (*Quadruped) LoadFromFile ¶
LoadFromFile loads some quadruped data from a file. It is important to make sure the quadruped that created that file had the same LegIK and MotorController types
func (*Quadruped) SaveToFile ¶
SaveToFile saves this quadruped to a file
func (*Quadruped) SetExtraMotorNow ¶
SetExtraMotorNow sets the named motor to a position, without waiting for the next update loop
func (*Quadruped) SetLegPosition ¶
SetLegPosition sets a legs position for the next update call. It does not perform any calculations or movement immediately.
func (*Quadruped) ShoulderVec ¶
ShoulderVec gets the Vec3 between the robots center and the shoulder joint of the leg specified
type Quat ¶ added in v0.1.0
type Quat struct {
W float64 // Scalar component
X float64 // i component
Y float64 // j component
Z float64 // k component
}
Quat represents a quaternion W+X*i+Y*j+Z*k
func NewQuatAngleAxis ¶ added in v0.1.0
NewQuatAngleAxis returns a quaternion with rotation a in degrees around axis v
func NewQuatFromTo ¶ added in v0.1.10
func (Quat) HeadingAngle ¶ added in v0.1.9
Returns the heading angle of this quaternion in degrees. This suffers from gimbal lock
func (Quat) NoYaw ¶ added in v0.1.0
NoYaw removes the global yaw component of this quaternion. Use this to take a quaternion in global space and make it useful for robot calculations. This suffers from gimbal lock
func (Quat) Norm ¶ added in v0.1.0
Norm returns the L1-Norm of a Quat (W,X,Y,Z) -> Sqrt(W*W+X*X+Y*Y+Z*Z)
func (Quat) Norm2 ¶ added in v0.1.0
Norm2 returns the L2-Norm of a Quat (W,X,Y,Z) -> W*W+X*X+Y*Y+Z*Z
func (Quat) RotateByGlobal ¶ added in v0.1.0
RotateByGlobal rotates quaternion a by b along the global axis
func (Quat) RotateByLocal ¶ added in v0.1.0
RotateByGlobal rotates quaternion a by b along the local axis relative to a
type RawArduinoRotationSensor ¶ added in v0.1.8
type RawArduinoRotationSensor struct {
Port *serial.Port `json:"-"`
IsReady bool `json:"-"`
PortName string `json:"port_name"`
Axes *AxesRemapper `json:"axes_remap"`
ReverseGyroUp bool `json:"rev_gyro_up"`
ReverseGyroLeft bool `json:"rev_gyro_left"`
ReverseGyroForward bool `json:"rev_gyro_forward"`
// Maximum number of deg/s the accelerometer can move the rotation
AccSpeed float64 `json:"acc_speed"`
// contains filtered or unexported fields
}
func NewRawArduinoRotationSensor ¶ added in v0.1.8
func NewRawArduinoRotationSensor() *RawArduinoRotationSensor
Creates a new sensor instance. Does not connect to the arduino yet, that is done from Setup()
func (*RawArduinoRotationSensor) Calibrate ¶ added in v0.1.8
func (a *RawArduinoRotationSensor) Calibrate()
Calibrates the sensors accelerometer and gyro. Ensure the sensor is very flat for this
func (*RawArduinoRotationSensor) GetQuaternion ¶ added in v0.1.8
func (a *RawArduinoRotationSensor) GetQuaternion() Quat
Returns the last measured rotation of the sensor. Non blocking
func (*RawArduinoRotationSensor) Restart ¶ added in v0.1.8
func (a *RawArduinoRotationSensor) Restart()
Restarts the updating in background thread
func (*RawArduinoRotationSensor) Setup ¶ added in v0.1.8
func (a *RawArduinoRotationSensor) Setup()
Sets up and connects to the arduino
type RotationSensor ¶
type RotationSensor interface {
// GetQuaternion returns the quaternion rotation in global space of this sensor.
// It can also have y axis rotation, which can be cancelled out easily later to get roll and pitch.
GetQuaternion() Quat
// Calibrate tells the rotation sensor to calibrate, then waits for the action to complete
Calibrate()
// Setup should be called after the sensor is loaded
Setup()
}
RotationSensor is an interface for getting the roll and pitch from a gyroscope/accelerometer
type UPSTimer ¶
type UPSTimer struct {
UPS float64
// contains filtered or unexported fields
}
func NewUPSTimer ¶
func (*UPSTimer) WaitForNext ¶
func (u *UPSTimer) WaitForNext()
type Vec3 ¶ added in v0.1.0
A Vector with 3 dimensions X Y Z
func (Vec3) Add ¶ added in v0.1.0
Returns the elementwise addition of this vector and the parameter vector
func (Vec3) AngleTo ¶ added in v0.1.0
Returns (in degrees) the angle from this vector and the parameter vector
func (Vec3) Cross ¶ added in v0.1.0
Returns the cross product of this vector and the parameter vector
func (Vec3) MulVec ¶ added in v0.1.0
Returns the elementwise multiplication of this vector and the parameter vector
func (Vec3) ProjectToPlane ¶ added in v0.1.0
Returns this vector projected onto the plane, where the normal of the plane is the parameter vector