Documentation ¶
Index ¶
- Constants
- func CountSteps(stepData <-chan int8)
- func DrawMeander(startCircle Circle, endCircle Circle, scale float64, narrowness float64, ...)
- func DrawToImage(imageName string, plotCoords <-chan Coordinate)
- func GaussianImage(imageData image.Image) image.Image
- func GenerateArc(setup Arc, imageData image.Image, plotCoords chan<- Coordinate)
- func GenerateBouncingLine(setup BouncingLine, plotCoords chan<- Coordinate)
- func GenerateCrossHatch(setup CrossHatch, imageData image.Image, plotCoords chan<- Coordinate)
- func GenerateGcodePath(data GcodeData, scale float64, plotCoords chan<- Coordinate)
- func GenerateGrid(setup Grid, plotCoords chan<- Coordinate)
- func GenerateHilbertCurve(setup HilbertCurve, plotCoords chan<- Coordinate)
- func GenerateMeander(circles []Circle, size float64, narrowness float64, radMulty float64, ...)
- func GenerateParabolic(setup Parabolic, plotCoords chan<- Coordinate)
- func GenerateParametric(posFunc func(float64) Coordinate, plotCoords chan<- Coordinate)
- func GenerateRaster(setup Raster, imageData image.Image, plotCoords chan<- Coordinate)
- func GenerateSlidingCircle(setup SlidingCircle, plotCoords chan<- Coordinate)
- func GenerateSpiral(setup Spiral, plotCoords chan<- Coordinate)
- func GenerateSteps(plotCoords <-chan Coordinate, stepData chan<- int8)
- func GenerateSvgBoxPath(data Coordinates, size float64, plotCoords chan<- Coordinate)
- func GenerateSvgCenterPath(data Coordinates, size float64, plotCoords chan<- Coordinate)
- func GenerateSvgTopPath(data Coordinates, size float64, plotCoords chan<- Coordinate)
- func GenerateTextPath(text string, height float64, plotCoords chan<- Coordinate)
- func InteractiveMoveSpool()
- func LoadImage(imageFileName string) image.Image
- func MoveSpool(leftSpool bool, distance float64)
- func OutputCoords(plotCoords <-chan Coordinate)
- func PerformMouseTracking()
- func SobelImage(imageData image.Image) image.Image
- func TestGenerateMeander(circles []Circle, size float64, narrowness float64, radMulty float64, ...)
- func WriteStepsToChart(stepData <-chan int8)
- func WriteStepsToFile(stepData <-chan int8)
- func WriteStepsToSerial(stepData <-chan int8, pauseOnPenUp bool)
- type Arc
- type BouncingLine
- type Circle
- 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) 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) Scaled(factor float64) Coordinate
- func (coord Coordinate) ScaledBoth(xfactor, yfactor float64) Coordinate
- func (coord Coordinate) String() string
- func (coord Coordinate) ToPolar(system PolarSystem) (polarCoord PolarCoordinate)
- type CoordinateRingBuffer
- type Coordinates
- type CrossHatch
- type GcodeCommand
- type GcodeData
- type GcodeLine
- type Grid
- type Group
- type GroupStipple
- type HilbertCurve
- type LineSegment
- type LinearInterpolater
- type MouseReader
- type Parabolic
- type Path
- type PathCommand
- type PathParser
- 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 Raster
- type SettingsData
- type SlidingCircle
- type Spiral
- type Stipple
- type TrapezoidInterpolater
Constants ¶
const ( MOVE_RAPID GcodeCommand = 0 MOVE = 1 SET_UNITS_INCHES = 20 SET_UNITS_MM = 21 )
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 DrawMeander ¶
func DrawMeander(startCircle Circle, endCircle Circle, scale float64, narrowness float64, radMulty float64, cutOff float64, plotCoords chan<- Coordinate)
* Draws a meander like path between the center coordinate of the two circles * where the where the amplitude of the meander morphes from radius 1 to * radius 2. The darkness of the path can be controlled with the narowness * argument. Parameter cutOff controlles the minimum radius to meander. Any * radius below cutOff will be drawn as straight line. * The parameter radMulty multiplies the radius of each circle. * * 12 Dezember 2014 Sergio Daniels E-Mail: daniels.sergio@gmail.com
func DrawToImage ¶
func DrawToImage(imageName string, plotCoords <-chan Coordinate)
Draw coordinates to image
func GaussianImage ¶
Return a new image that is the result of applying a 3x3 gaussion blur to the image
func GenerateArc ¶
func GenerateArc(setup Arc, imageData image.Image, plotCoords chan<- Coordinate)
Draw image by generate a series of arcs, where darknes of a pixel is a movement along the arc white is drawn with PenUp=true
func GenerateBouncingLine ¶
func GenerateBouncingLine(setup BouncingLine, plotCoords chan<- Coordinate)
Generate a line that bounces off the edges of the grid
func GenerateCrossHatch ¶
func GenerateCrossHatch(setup CrossHatch, imageData image.Image, plotCoords chan<- Coordinate)
Draw image by generate a series of arcs, where darknes of a pixel is a movement along the arc
func GenerateGcodePath ¶
func GenerateGcodePath(data GcodeData, scale float64, plotCoords chan<- Coordinate)
Given GCodeData, returns all of the
func GenerateGrid ¶
func GenerateGrid(setup Grid, plotCoords chan<- Coordinate)
Generate parabolic curve out of a bunch of straight lines
func GenerateHilbertCurve ¶
func GenerateHilbertCurve(setup HilbertCurve, plotCoords chan<- Coordinate)
Generate a Hilbert curve, based on code from http://en.wikipedia.org/wiki/Hilbert_curve
func GenerateMeander ¶
func GenerateMeander(circles []Circle, size float64, narrowness float64, radMulty float64, cutOff float64, plotCoords chan<- Coordinate)
* Sends the array of circles to the DrawMeander function * * 12 Dezember 2014 Sergio Daniels E-Mail: daniels.sergio@gmail.com
func GenerateParabolic ¶
func GenerateParabolic(setup Parabolic, plotCoords chan<- Coordinate)
Generate parabolic curve out of a bunch of straight lines
func GenerateParametric ¶
func GenerateParametric(posFunc func(float64) Coordinate, plotCoords chan<- Coordinate)
Generate spirograph
func GenerateRaster ¶
func GenerateRaster(setup Raster, imageData image.Image, plotCoords chan<- Coordinate)
Draw image by generate a series of arcs, where darknes of a pixel is a movement along the arc
func GenerateSlidingCircle ¶
func GenerateSlidingCircle(setup SlidingCircle, plotCoords chan<- Coordinate)
Generate a circle that slides along a given axis
func GenerateSpiral ¶
func GenerateSpiral(setup Spiral, plotCoords chan<- Coordinate)
Generate a spiral
func GenerateSteps ¶
func GenerateSteps(plotCoords <-chan Coordinate, stepData chan<- int8)
Takes in coordinates and outputs stepData
func GenerateSvgBoxPath ¶
func GenerateSvgBoxPath(data Coordinates, size float64, plotCoords chan<- Coordinate)
Send svg path points to channel
func GenerateSvgCenterPath ¶
func GenerateSvgCenterPath(data Coordinates, size float64, plotCoords chan<- Coordinate)
Send svg path points to channel
func GenerateSvgTopPath ¶
func GenerateSvgTopPath(data Coordinates, size float64, plotCoords chan<- Coordinate)
Send svg path points to channel
func GenerateTextPath ¶
func GenerateTextPath(text string, height float64, plotCoords chan<- Coordinate)
Pring this text
func OutputCoords ¶
func OutputCoords(plotCoords <-chan Coordinate)
Output the coordinates to the screen
func PerformMouseTracking ¶
func PerformMouseTracking()
Do mouse tracking, must open up serial port directly in order to send steps in realtime as requested
func SobelImage ¶
Return a new image that is the result of applying the sobel filter on the image
func TestGenerateMeander ¶
func WriteStepsToChart ¶
func WriteStepsToChart(stepData <-chan int8)
Writes step data and position to a graph
func WriteStepsToFile ¶
func WriteStepsToFile(stepData <-chan int8)
Sends the given stepData to a file
func WriteStepsToSerial ¶
Sends the given stepData to the stepper driver
Types ¶
type BouncingLine ¶
type BouncingLine struct { // Initial angle of line Angle float64 // Total distance that the line will travel TotalDistance float64 }
Parameters needed to generate a bouncing line
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 Coordinate ¶
A Cartession coordinate or vector
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) 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) 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) 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 CrossHatch ¶
type CrossHatch struct { // Size of longest axis Size float64 // Distance between lines Dist float64 }
Parameters for arc
type GcodeData ¶
type GcodeData struct {
Lines []GcodeLine
}
All of the data from a file
func ParseGcode ¶
read all of the fileData lines, generating a GcodeData object
func ParseGcodeFile ¶
read a file and parse its Gcode
type GcodeLine ¶
type GcodeLine struct { Command GcodeCommand //data map[string]float64 Dest Coordinate }
Data on a single line, the command followed by any values on the line
type Grid ¶
type Grid struct { // Size of each axis Width float64 // Number of cells to divide grid into, will be Cells x Cells total cells Cells float64 }
Parameters for grid
type GroupStipple ¶
type HilbertCurve ¶
type HilbertCurve struct { // Integer of how complex it is, 2^Degree is the order Degree int // Total size in mm Size float64 }
Parameters needed for hilbert curve
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 MouseReader ¶
type MouseReader interface { Start(string) Close() GetPos() (int32, int32) GetLeftButton() bool GetRightButton() bool }
Interface needed
func CreateAndStartMouseReader ¶
func CreateAndStartMouseReader() MouseReader
Return an implementation of MouseReader specific to the current platform
type Parabolic ¶
type Parabolic struct { // Height of each axis Radius float64 // number of faces on polygon PolygonEdgeCount float64 // Number of lines Lines float64 }
Parameters for parabolic curve
type PathCommand ¶
type PathCommand int
All supported Path Commands
const ( NotAValidCommand PathCommand = iota MoveToAbsolute MoveToRelative ClosePath LineToAbsolute LineToRelative )
func ParseCommand ¶
func ParseCommand(commandString string) PathCommand
Convert string to command, returns NotAValidCommand if not valid
func (PathCommand) IsRelative ¶
func (command PathCommand) IsRelative() bool
True if the given PathCommand is relative
type PathParser ¶
type PathParser struct {
// contains filtered or unexported fields
}
Used to parse a path string
func NewParser ¶
func NewParser(originalPathData string, scaleX, scaleY float64) (parser *PathParser)
Create new parser
func (*PathParser) PeekHasMoreArguments ¶
func (this *PathParser) PeekHasMoreArguments() bool
Return if the next token is a command or not
func (*PathParser) ReadCoord ¶
func (this *PathParser) ReadCoord(penUp bool)
Read two strings as a pair of doubles
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 Raster ¶
type Raster struct { // Size of longest axis Size float64 // Width of the pen used when filling in a pixel PenWidth float64 // contains filtered or unexported fields }
Parameters for raster
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 // 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 SlidingCircle ¶
type SlidingCircle struct { // Radius of the circle Radius float64 // Distance traveled while one circle is traced CircleDisplacement float64 // Number of cirlces that will be drawn NumbCircles int }
Parameters needed to generate a sliding circle
type Spiral ¶
type Spiral struct { // Initial radius of spiral RadiusBegin float64 // Spiral ends when this radius is reached RadiusEnd float64 // How much each revolution changes the radius RadiusDeltaPerRev float64 }
Parameters needed to generate a spiral
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()