Documentation ¶
Index ¶
- Constants
- func CountSteps(stepData <-chan int8)
- func DrawToImageExact(imageName string, widthMM float64, heightMM float64, ...)
- func GenerateSteps(plotCoords <-chan Coordinate, stepData chan<- int8)
- func GenerateSvgPath(data Coordinates, plotCoords chan<- Coordinate)
- func InteractiveMoveSpool()
- func MoveSpool(leftSpool bool, distance float64)
- func OutputCoords(plotCoords <-chan Coordinate)
- func PxFromSVGUnit(value SVGUnit) float64
- func StringFromSVGUnit(value SVGUnit) string
- func TotalPenUpTravelForGlyphs(glyphs []Glyph) float64
- func TotalTravelForGlyphs(glyphs []Glyph) float64
- func WriteStepsToChart(stepData <-chan int8)
- func WriteStepsToSerial(stepData <-chan int8)
- type Circle
- type ConfigData
- type ConfigInterface
- type ConfigReader
- type Coordinate
- func (source Coordinate) Add(dest Coordinate) Coordinate
- func (coord Coordinate) Ceil() Coordinate
- func (coord Coordinate) Clamp(max, min float64) Coordinate
- func (coord Coordinate) DistanceTo(other Coordinate) float64
- func (coord Coordinate) DotProduct(other Coordinate) float64
- func (coord Coordinate) Equals(other Coordinate) bool
- func (coord Coordinate) Floor() Coordinate
- func (coord Coordinate) IsNaN() bool
- func (coord Coordinate) Len() float64
- func (source Coordinate) Minus(dest Coordinate) Coordinate
- func (coord Coordinate) Normalized() Coordinate
- func (coord Coordinate) Same(other Coordinate) bool
- func (coord Coordinate) Scaled(factor float64) Coordinate
- func (coord Coordinate) ScaledBoth(xfactor, yfactor float64) Coordinate
- func (coord Coordinate) SeparationFrom(other Coordinate) float64
- func (coord Coordinate) String() string
- func (coord Coordinate) ToPolar(system PolarSystem) (polarCoord PolarCoordinate)
- type CoordinateRingBuffer
- type Coordinates
- type Glyph
- func (g *Glyph) CanBeMergedWith(other Glyph) bool
- func (g *Glyph) DistanceTo(other Glyph) float64
- func (g *Glyph) DistanceToReversed(other Glyph) float64
- func (g *Glyph) Equals(other Glyph) bool
- func (g *Glyph) Length() float64
- func (g *Glyph) MergeWith(other Glyph) Glyph
- func (g *Glyph) Reversed() Glyph
- func (g *Glyph) SeparationFrom(other Glyph) float64
- func (g *Glyph) SeparationFromReversed(other Glyph) float64
- type LineSegment
- type LinearInterpolater
- type PolarCoordinate
- func (source PolarCoordinate) Add(dest PolarCoordinate) PolarCoordinate
- func (coord PolarCoordinate) Ceil() PolarCoordinate
- func (coord PolarCoordinate) Clamp(max, min float64) PolarCoordinate
- func (source PolarCoordinate) Minus(dest PolarCoordinate) PolarCoordinate
- func (coord PolarCoordinate) Scaled(factor float64) PolarCoordinate
- func (polarCoord PolarCoordinate) String() string
- func (polarCoord PolarCoordinate) ToCoord(system PolarSystem) (coord Coordinate)
- type PolarSystem
- type PositionInterpolater
- type SVGNumber
- type SVGSize
- type SVGUnit
- type SettingsData
- type TrapezoidInterpolater
Constants ¶
const ( // Time step used to control motion, ie the amount of time that the stepper motors will be going a constant speed // decreasing this increases CPU usage and serial communication // increasing it decreases rendering quality // when running on a raspberry pi 2048 us (2 milliseconds) seems like a good number TimeSlice_US float64 = 2048 // The factor the steps are multiplied by, needs to be the same as set in the arduino code StepsFixedPointFactor float64 = 32.0 // Determined because 1 byte is sent per value, so have range -128 to 127, and -128, -127, 127 are reserved values with special meanings StepsMaxValue float64 = 126.0 // Special Steps value that when received causes the arduino to flush its buffers and reset its internal state ResetCommand byte = 0x80 // -128 // Special Steps value that raises the pen PenUpCommand int8 = -127 // Special Steps value that lowers the pen PenDownCommand int8 = 127 )
These constants are also set in StepperDriver.ino, must be changed in both places
Variables ¶
This section is empty.
Functions ¶
func DrawToImageExact ¶
func DrawToImageExact(imageName string, widthMM float64, heightMM float64, plotCoords <-chan Coordinate)
func GenerateSteps ¶
func GenerateSteps(plotCoords <-chan Coordinate, stepData chan<- int8)
Takes in coordinates and outputs stepData
func GenerateSvgPath ¶
func GenerateSvgPath(data Coordinates, plotCoords chan<- Coordinate)
func OutputCoords ¶
func OutputCoords(plotCoords <-chan Coordinate)
Output the coordinates to the screen
func PxFromSVGUnit ¶
func StringFromSVGUnit ¶
func TotalTravelForGlyphs ¶
func WriteStepsToChart ¶
func WriteStepsToChart(stepData <-chan int8)
Writes step data and position to a graph
func WriteStepsToSerial ¶
func WriteStepsToSerial(stepData <-chan int8)
Sends the given stepData to the stepper driver
Types ¶
type Circle ¶
type Circle struct { // Center coordinates of circle Center Coordinate // Radius of circle Radius float64 // flag to set start point Start bool }
Defines a circle
func (Circle) Intersection ¶
func (circle Circle) Intersection(line LineSegment) (firstPoint Coordinate, firstPointValid bool, secondPoint Coordinate, secondPointValid bool)
Calculates the intersection between a circle and line segment, based on http://stackoverflow.com/questions/1073336/circle-line-collision-detection If there is only one interesection it will always be in firstPoint
type ConfigData ¶
type ConfigData struct { Board struct { Width float64 `yaml:"width"` } `yaml:"board"` Hardware struct { SpoolCircumference float64 `yaml:"spool_circumference_mm"` SinglStep float64 `yaml:"single_step_degrees"` MaxAcceleration float64 `yaml:"max_acceleration_s"` SerialPort string `yaml:"serial_port"` } `yaml:"hardware"` Position struct { // contains filtered or unexported fields } `yaml:"position"` }
var Config ConfigData
func (*ConfigData) Read ¶
func (config *ConfigData) Read()
type ConfigInterface ¶
type ConfigInterface interface { ReadConfig(path string, cfg interface{}) error ConfigPath() string DefaultConfigPath() string }
Mocking config reading
type ConfigReader ¶
type ConfigReader struct{}
func (ConfigReader) ConfigPath ¶
func (reader ConfigReader) ConfigPath() string
func (ConfigReader) DefaultConfigPath ¶
func (reader ConfigReader) DefaultConfigPath() string
func (ConfigReader) ReadConfig ¶
func (reader ConfigReader) ReadConfig(path string, cfg interface{}) error
type Coordinate ¶
A Cartession coordinate or vector
func MakeCoordinates ¶
func MakeCoordinates(glyphs []Glyph) (coordinates []Coordinate)
func OptimizeTravel ¶
func OptimizeTravel(input []Coordinate) (output []Coordinate)
func ParseSvgFile ¶
func ParseSvgFile(fileName string) (data []Coordinate, svgWidth float64, svgHeight float64)
read a file
func (Coordinate) Add ¶
func (source Coordinate) Add(dest Coordinate) Coordinate
Add two coordinates together
func (Coordinate) Clamp ¶
func (coord Coordinate) Clamp(max, min float64) Coordinate
Clamp the values of X,Y to the given max/min
func (Coordinate) DistanceTo ¶
func (coord Coordinate) DistanceTo(other Coordinate) float64
Distance from this coordinate to other
func (Coordinate) DotProduct ¶
func (coord Coordinate) DotProduct(other Coordinate) float64
Dot product between two vectors
func (Coordinate) Equals ¶
func (coord Coordinate) Equals(other Coordinate) bool
Test if the two coordinates are equal within a constant epsilon
func (Coordinate) Minus ¶
func (source Coordinate) Minus(dest Coordinate) Coordinate
Return the vector from source to dest
func (Coordinate) Same ¶
func (coord Coordinate) Same(other Coordinate) bool
func (Coordinate) Scaled ¶
func (coord Coordinate) Scaled(factor float64) Coordinate
Scales the Coordinate by the specified factor
func (Coordinate) ScaledBoth ¶
func (coord Coordinate) ScaledBoth(xfactor, yfactor float64) Coordinate
Scale each axis seperately
func (Coordinate) SeparationFrom ¶
func (coord Coordinate) SeparationFrom(other Coordinate) float64
Some number that correlates with distance, faster to calculate
func (Coordinate) ToPolar ¶
func (coord Coordinate) ToPolar(system PolarSystem) (polarCoord PolarCoordinate)
Convert the given coordinate from X,Y to polar in the given PolarSystem
type CoordinateRingBuffer ¶
type CoordinateRingBuffer struct {
// contains filtered or unexported fields
}
A ring buffer used to store coordinates
func NewCoordinateRingBuffer ¶
func NewCoordinateRingBuffer(capacity int) *CoordinateRingBuffer
Create a new buffer with the given capacity
func (*CoordinateRingBuffer) Cap ¶
func (ring *CoordinateRingBuffer) Cap() int
Capacity of the buffer
func (*CoordinateRingBuffer) Dequeue ¶
func (ring *CoordinateRingBuffer) Dequeue() Coordinate
Remove a coordinate from the beginning of the buffer
func (*CoordinateRingBuffer) Enqueue ¶
func (ring *CoordinateRingBuffer) Enqueue(coord Coordinate)
Add a coordinate to the end of the buffer
func (*CoordinateRingBuffer) Len ¶
func (ring *CoordinateRingBuffer) Len() int
Amount of data in the buffer
type Coordinates ¶
type Coordinates []Coordinate
func (Coordinates) Extents ¶
func (coords Coordinates) Extents() (Coordinate, Coordinate)
Calculate the min and max coordinate in the given slice
type Glyph ¶
type Glyph struct {
Coordinates []Coordinate
}
func MakeGlyphs ¶
func MakeGlyphs(coordinates []Coordinate) (glyphs []Glyph)
func ReorderGlyphs ¶
func (*Glyph) CanBeMergedWith ¶
func (*Glyph) DistanceTo ¶
func (*Glyph) DistanceToReversed ¶
func (*Glyph) SeparationFrom ¶
Not real distance, but much faster to calculate
func (*Glyph) SeparationFromReversed ¶
type LineSegment ¶
type LineSegment struct { // Beginning point of line segment Begin Coordinate // End of line segment End Coordinate }
Defines a line segment
func (LineSegment) Intersection ¶
func (lineOne LineSegment) Intersection(lineTwo LineSegment) (intersection Coordinate, intersectionValid bool)
Calculates the intersection between two line segments, based on http://stackoverflow.com/questions/563198/how-do-you-detect-where-two-line-segments-intersect
func (LineSegment) Len ¶
func (line LineSegment) Len() float64
type LinearInterpolater ¶
type LinearInterpolater struct {
// contains filtered or unexported fields
}
func (*LinearInterpolater) Position ¶
func (data *LinearInterpolater) Position(slice float64) Coordinate
position along line at this slice
func (*LinearInterpolater) Setup ¶
func (data *LinearInterpolater) Setup(origin, dest, nextDest Coordinate)
setup data for the linear interpolater
func (*LinearInterpolater) Slices ¶
func (data *LinearInterpolater) Slices() float64
number of slices needed
type PolarCoordinate ¶
A polar coordinate
func (PolarCoordinate) Add ¶
func (source PolarCoordinate) Add(dest PolarCoordinate) PolarCoordinate
Add two coordinates together
func (PolarCoordinate) Ceil ¶
func (coord PolarCoordinate) Ceil() PolarCoordinate
ApplRightDist math.Ceil to each value
func (PolarCoordinate) Clamp ¶
func (coord PolarCoordinate) Clamp(max, min float64) PolarCoordinate
Clamp the values of LeftDist,RightDist to the given maLeftDist/min
func (PolarCoordinate) Minus ¶
func (source PolarCoordinate) Minus(dest PolarCoordinate) PolarCoordinate
Return the vector from source to dest
func (PolarCoordinate) Scaled ¶
func (coord PolarCoordinate) Scaled(factor float64) PolarCoordinate
Scales the PolarCoordinate bRightDist the specified factor
func (PolarCoordinate) String ¶
func (polarCoord PolarCoordinate) String() string
Coordinate ToString
func (PolarCoordinate) ToCoord ¶
func (polarCoord PolarCoordinate) ToCoord(system PolarSystem) (coord Coordinate)
Convert the given polarCoordinate from polar to X,Y in the given PolarSystem
type PolarSystem ¶
type PolarSystem struct {
XOffset, YOffset float64 // The location of X,Y origin relative to the motors
XMin, XMax float64
YMin, YMax float64
RightMotorDist float64
}
PolarSystem information, 0,0 is always the upper left motor
func PolarSystemFromSettings ¶
func PolarSystemFromSettings() PolarSystem
Create a PolarSystem from the settings object
type PositionInterpolater ¶
type PositionInterpolater interface { Setup(origin, dest, nextDest Coordinate) Slices() float64 Position(slice float64) Coordinate WriteData() }
Given an origin, dest, nextDest, returns how many slices it will takes to traverse it and what the position at a given slice is
type SVGNumber ¶
type SVGNumber struct {
// contains filtered or unexported fields
}
func SVGNumberFromString ¶
type SVGSize ¶
type SVGSize struct {
// contains filtered or unexported fields
}
func SVGSizeFromValues ¶
func (SVGSize) CoordinateFromM ¶
func (size SVGSize) CoordinateFromM(m [2]float64, penUp bool) Coordinate
type SettingsData ¶
type SettingsData struct { // Circumference of the motor spool SpoolCircumference_MM float64 // Degrees in a single step, set based on the stepper motor & microstepping SpoolSingleStep_Degrees float64 // Number of seconds to accelerate from 0 to MaxSpeed_MM_S Acceleration_Seconds float64 // Distance between the two motor spools SpoolHorizontalDistance_MM float64 // Minimum distance below motors that can be drawn DrawingSurfaceMinY_MM float64 // Maximum distance below motors that can be drawn DrawingSurfaceMaxY_MM float64 // Distance from the left edge that the pen can go DrawingSurfaceMinX_MM float64 // Calculated from SpoolHorizontalDistance_MM and DrawingSufaceMinX_MM DrawingSurfaceMaxX_MM float64 `xml:"-"` // Initial distance from head to left motor StartingLeftDist_MM float64 // Initial distance from head to right motor StartingRightDist_MM float64 // path to mouse event file, use evtest to find MousePath string // path to serial port SerialPortPath string // MM traveled by a single step StepSize_MM float64 `xml:"-"` // Max speed of the plot head MaxSpeed_MM_S float64 `xml:"-"` // Acceleration in mm / s^2, derived from Acceleration_Seconds and MaxSpeed_MM_S Acceleration_MM_S2 float64 `xml:"-"` }
User configurable settings
var Settings SettingsData
Global settings variable
func (*SettingsData) CalculateDerivedFields ¶
func (settings *SettingsData) CalculateDerivedFields()
setup derived fields
func (*SettingsData) Read ¶
func (settings *SettingsData) Read()
Read settings from file, setting the global variable
type TrapezoidInterpolater ¶
type TrapezoidInterpolater struct {
// contains filtered or unexported fields
}
Data needed by the interpolater
func (*TrapezoidInterpolater) Position ¶
func (data *TrapezoidInterpolater) Position(slice float64) Coordinate
Calculate current position at the given time
func (*TrapezoidInterpolater) Setup ¶
func (data *TrapezoidInterpolater) Setup(origin, dest, nextDest Coordinate)
Calculate all fields needed
func (*TrapezoidInterpolater) Slices ¶
func (data *TrapezoidInterpolater) Slices() float64
Get total time it takes to move
func (*TrapezoidInterpolater) WriteData ¶
func (data *TrapezoidInterpolater) WriteData()