Documentation
¶
Overview ¶
Package irpointer contains an algorithm to use your wiimote IR-sensors as pointer on a screen
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultIRParams = IRParams{
Height: 384.0 / 512.0,
MaxSbSlope: 0.7,
MinSbWidth: 0.1,
SbWidth: 19.5,
SbDotWidth: 2.25,
SbDotHeight: 1.0,
SbOffScreenX: 0.0,
SbOffScreenY: 0.0,
SbSingleNoGuessDistance: (100.0 * 100.0),
WiimoteFOVCoefficient: 0.39,
SmootherRadius: 8.0,
SmootherSpeed: 0.25,
SmootherDeadzone: 2.5,
ErrorMaxCount: 8,
GlitchMaxCount: 5,
GlitchDistance: (150.0 * 150.0),
}
Functions ¶
This section is empty.
Types ¶
type FVec2 ¶
type FVec2 struct {
X, Y float64
}
FVec2 represents a 2D floating point vector to X and Y.
type IRHealth ¶
type IRHealth uint
IRHealth describes the current tracking of sensorbars
const ( // The pointer is dead if it never had any signal yet IRDead IRHealth = iota // The pointer is lost if it had a signal which is now lost IRLost // The pointer can track one IR signal and must guess the position, a position is available but can be varying IRSingle // The pointer can track the whole sensorbar (two IR signals) and the position is good IRGood )
type IRParams ¶
type IRParams struct {
// Height is half-height of the IR sensor if half-width is 1
Height float64
// MaxSbSlope is maximum sensor bar slope
MaxSbSlope float64
// MinSbWidth is minimum sensor bar width in view, relative to half of the IR sensor area
MinSbWidth float64
// SbWidth is physical dimensions center to center of emitters
SbWidth float64
// SbDotWidth is half-width of emitters
SbDotWidth float64
// SbDotHeight is half-height of emitters (with some tolerance)
SbDotHeight float64
// dots further out than these coords are allowed to not be picked up
// otherwise assume something's wrong
SbOffScreenX float64
SbOffScreenY float64
// SbSingleNoGuessDistance is a point and if it's closer to one of the previous SB points
// when it reappears, consider it the same instead of trying to guess
// which one of the two it is
SbSingleNoGuessDistance float64
// WiimoteFOVCoefficient is distance from the center of the FOV to the left or right edge,
// when the wiimote is at one meter
WiimoteFOVCoefficient float64
SmootherRadius float64
SmootherSpeed float64
// SmootherDeadzone is distance between old and new value where nothing should change
SmootherDeadzone float64
// ErrorMaxCount is max number of errors before cooked data drops out
ErrorMaxCount int
// GlitchMaxCount is max number of glitches before cooked data updates
GlitchMaxCount int
// GlitchDistance is squared delta over which we consider something a glitch
GlitchDistance float64
}
type IRPointer ¶
type IRPointer struct {
SensorBar
// Health of pointer
Health IRHealth
// Distance from wiimote to screen in centimeters
Distance float64
// Smoothed coordinate
Position *FVec2
// contains filtered or unexported fields
}
IRPointer holds the current state of the pointer. The smoothed position is roughly in the range (-512..512) for both X and Y, where 0 is center and 512 is about the maximum offset. The actual returned values will not necessarily cover that range (e.g. don't expect more than -384..384 for Y if the wiimote is level). This range represents a square screen. The values might exceed -512 or 512 under some circumstances.
Keep in mind that you want to map the screen to a subset of this space, both because presumably your screen doesn't have a 1:1 aspect ratio, and because the Wiimote won't be able to cover the entire space. The worst case scenario is when the Wiimote is sideways, where the X coordinate might only cover about -384..384, and the corresponding Y coordinate range would only be -216..216 for a 16:9 screen. There is a tradeoff here: using a larger range means not being able to reach the edges of the screen with the wiimote turned sideways, while using a smaller range means the cursor moves faster and is harder to control.
For example, a conservative mapping for a 16:9 screen might be:
X left = -340, X right = 340 If sensor bar is below screen:
Y top = -290 Y bottom = 92
If sensor bar is above screen:
Y top = -92 Y bottom = 290
While a wider mapping might be: X left = -430, X right = 430 If sensor bar is below screen:
Y top = -290 Y bottom = 194
If sensor bar is above screen:
Y top = -194 Y bottom = 290
Wider than the above starts having trouble at the edges.
Notes on signs and ranges: Raw Wiimote IR data maps 0,0 to the bottom left corner of the sensor's field of view (this corresponds to pointing the wiimote up and to the right). This is the format expected in ir.dot. roll should be 0 when the wiimote is level and should increase as it is rotated clockwise, covering a -pi to pi range. Output data has a positive X when pointing to the right of the sensor bar, and a positive Y when pointing under the sensor bar, with 0,0 corresponding to pointing directly at the sensor bar.
func NewIRPointer ¶
NewIRPointer allocates a new IRPointer. params can alter some functionality but can also be nil'ed to use default parameters
func (*IRPointer) Update ¶
Update processes new dots and acceleration values
If acceleration data is unreliable (wiimote is significantly accelerating) then you should supply the last known good value.
func (*IRPointer) UpdateRoll ¶
UpdateRoll processes new dots and roll values
You can calculate the roll from the accel as roll=atan2(x, z). If roll data is unreliable (wiimote is significantly accelerating) then you should supply the last known good value.