polargraph

package
v0.0.0-...-086b16a Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2021 License: LGPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
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 CountSteps

func CountSteps(stepData <-chan int8)

Count steps

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 InteractiveMoveSpool

func InteractiveMoveSpool()

Used to manually adjust length of each step

func MoveSpool

func MoveSpool(leftSpool bool, distance float64)

Move a specific spool a given distance

func OutputCoords

func OutputCoords(plotCoords <-chan Coordinate)

Output the coordinates to the screen

func PxFromSVGUnit

func PxFromSVGUnit(value SVGUnit) float64

func StringFromSVGUnit

func StringFromSVGUnit(value SVGUnit) string

func TotalPenUpTravelForGlyphs

func TotalPenUpTravelForGlyphs(glyphs []Glyph) float64

func TotalTravelForGlyphs

func TotalTravelForGlyphs(glyphs []Glyph) float64

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

type Coordinate struct {
	X, Y  float64
	PenUp bool
}

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) Ceil

func (coord Coordinate) Ceil() Coordinate

Apply math.Ceil to each value

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) Floor

func (coord Coordinate) Floor() Coordinate

Apply math.Floor to each value

func (Coordinate) IsNaN

func (coord Coordinate) IsNaN() bool

Returns true if either value is NaN

func (Coordinate) Len

func (coord Coordinate) Len() float64

Calculates length of vector

func (Coordinate) Minus

func (source Coordinate) Minus(dest Coordinate) Coordinate

Return the vector from source to dest

func (Coordinate) Normalized

func (coord Coordinate) Normalized() Coordinate

Normalize the vector

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) String

func (coord Coordinate) String() string

Coordinate ToString

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 ReorderGlyphs(glyphs []Glyph) (sorted []Glyph)

func (*Glyph) CanBeMergedWith

func (g *Glyph) CanBeMergedWith(other Glyph) bool

func (*Glyph) DistanceTo

func (g *Glyph) DistanceTo(other Glyph) float64

func (*Glyph) DistanceToReversed

func (g *Glyph) DistanceToReversed(other Glyph) float64

func (*Glyph) Equals

func (g *Glyph) Equals(other Glyph) bool

func (*Glyph) Length

func (g *Glyph) Length() float64

func (*Glyph) MergeWith

func (g *Glyph) MergeWith(other Glyph) Glyph

func (*Glyph) Reversed

func (g *Glyph) Reversed() Glyph

func (*Glyph) SeparationFrom

func (g *Glyph) SeparationFrom(other Glyph) float64

Not real distance, but much faster to calculate

func (*Glyph) SeparationFromReversed

func (g *Glyph) SeparationFromReversed(other Glyph) float64

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

func (*LinearInterpolater) WriteData

func (data *LinearInterpolater) WriteData()

output data

type PolarCoordinate

type PolarCoordinate struct {
	LeftDist, RightDist float64
	PenUp               bool
}

A polar coordinate

func (PolarCoordinate) Add

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

func SVGNumberFromString(value string) (number SVGNumber, err error)

func (SVGNumber) ValueIn

func (number SVGNumber) ValueIn(unit SVGUnit) float64

type SVGSize

type SVGSize struct {
	// contains filtered or unexported fields
}

func SVGSizeFromValues

func SVGSizeFromValues(width string, height string, viewBox []float64) (size SVGSize, err error)

func (SVGSize) CoordinateFromM

func (size SVGSize) CoordinateFromM(m [2]float64, penUp bool) Coordinate

type SVGUnit

type SVGUnit int
const (
	Px SVGUnit = iota
	In
	Pt
	Pc
	Cm
	Mm
)

func SVGUnitFromString

func SVGUnitFromString(value string) (SVGUnit, error)

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

func (*SettingsData) Write

func (settings *SettingsData) Write()

Write settings to file

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()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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