當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Block.GetWord方法代碼示例

本文整理匯總了Golang中github.com/joushou/gocnc/gcode.Block.GetWord方法的典型用法代碼示例。如果您正苦於以下問題:Golang Block.GetWord方法的具體用法?Golang Block.GetWord怎麽用?Golang Block.GetWord使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/joushou/gocnc/gcode.Block的用法示例。


在下文中一共展示了Block.GetWord方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: feedRate

func (vm *Machine) feedRate(stmt *gcode.Block) {
	if val, err := stmt.GetWord('F'); err == nil {
		if vm.Imperial {
			val *= 25.4
		}
		vm.State.Feedrate = val
		stmt.RemoveAddress('F')
	} else if vm.State.FeedMode == FeedModeInvTime {
		vm.State.Feedrate = -1
	}
}
開發者ID:raylee,項目名稱:gocnc,代碼行數:11,代碼來源:main.go

示例2: calcPos

// Calculates the absolute position of the given statement, including optional I, J, K parameters.
// Units are converted, and coordinate system applied unless overridden.
func (vm *Machine) calcPos(stmt gcode.Block) (newX, newY, newZ, newI, newJ, newK float64) {
	pos := vm.curPos()
	var err error

	coordinateSystem := vm.CoordinateSystem.GetCoordinateSystem()

	if vm.CoordinateSystem.OverrideActive() {
		oldAbsolute := vm.AbsoluteMove
		vm.AbsoluteMove = true
		defer func() {
			vm.AbsoluteMove = oldAbsolute
		}()
	}

	if newX, err = stmt.GetWord('X'); err != nil {
		newX = pos.X
	} else {
		if vm.Imperial {
			newX *= 25.4
		}
		if !vm.AbsoluteMove {
			newX += pos.X
		} else {
			newX += coordinateSystem.X
		}
	}

	if newY, err = stmt.GetWord('Y'); err != nil {
		newY = pos.Y
	} else {
		if vm.Imperial {
			newY *= 25.4
		}
		if !vm.AbsoluteMove {
			newY += pos.Y
		} else {
			newY += coordinateSystem.Y
		}
	}

	if newZ, err = stmt.GetWord('Z'); err != nil {
		newZ = pos.Z
	} else {
		if vm.Imperial {
			newZ *= 25.4
		}
		if !vm.AbsoluteMove {
			newZ += pos.Z
		} else {
			newZ += coordinateSystem.Z
		}
	}

	newI = stmt.GetWordDefault('I', 0.0)
	newJ = stmt.GetWordDefault('J', 0.0)
	newK = stmt.GetWordDefault('K', 0.0)

	if vm.Imperial {
		newI *= 25.4
		newJ *= 25.4
		newK *= 25.4
	}

	if !vm.AbsoluteArc {
		newI += pos.X
		newJ += pos.Y
		newK += pos.Z
	} else {
		newI += coordinateSystem.X
		newJ += coordinateSystem.Y
		newZ += coordinateSystem.Z
	}

	return newX, newY, newZ, newI, newJ, newK
}
開發者ID:raylee,項目名稱:gocnc,代碼行數:77,代碼來源:positioning.go

示例3: nonModals

func (vm *Machine) nonModals(stmt *gcode.Block) {
	if w, err := stmt.GetModalGroup("nonModalGroup"); err == nil {
		if w != nil {
			if w.Address != 'G' {
				unknownCommand("nonModalGroup", w)
			}

			switch w.Command {
			case 4:
				if val, err := stmt.GetWord('P'); err == nil {
					if val < 0 {
						invalidCommand("nonModalGroup", "dwell", "P word negative")
					}
					vm.dwell(val)
				} else {
					invalidCommand("nonModalGroup", "dwell", "P word not specified or specified multiple times")
				}
				stmt.RemoveAddress('P')

			case 10:
				if val, err := stmt.GetWord('L'); err == nil {
					if val == 2 {
						// Set coordinate system offsets
						if cs, err := stmt.GetWord('P'); err == nil {
							cs := int(cs)
							x, y, z := stmt.GetWordDefault('X', 0), stmt.GetWordDefault('Y', 0), stmt.GetWordDefault('Z', 0)
							x, y, z = vm.axesToMetric(x, y, z)

							vm.CoordinateSystem.SetCoordinateSystem(x, y, z, cs)
							stmt.RemoveAddress('X', 'Y', 'Z')
						} else {
							invalidCommand("nonModalGroup", "coordinate system configuration", "P word not specified or specified multiple times")
						}
						stmt.RemoveAddress('P')
					}
				} else {
					invalidCommand("nonModalGroup", "G10 configuration", "L word not specified or specified multiple times")
				}
				stmt.RemoveAddress('L')

			case 28:

				oldMode := vm.State.MoveMode
				vm.State.MoveMode = MoveModeRapid
				if stmt.IncludesOneOf('X', 'Y', 'Z') {
					newX, newY, newZ, _, _, _ := vm.calcPos(*stmt)
					vm.move(newX, newY, newZ)
					stmt.RemoveAddress('X', 'Y', 'Z')
				}
				vm.move(vm.StoredPos1.X, vm.StoredPos1.Y, vm.StoredPos1.Z)
				vm.State.MoveMode = oldMode

			case 28.1:
				pos := vm.curPos()
				vm.StoredPos1 = pos.Vector()

			case 30:
				oldMode := vm.State.MoveMode
				vm.State.MoveMode = MoveModeRapid
				if stmt.IncludesOneOf('X', 'Y', 'Z') {
					newX, newY, newZ, _, _, _ := vm.calcPos(*stmt)
					vm.move(newX, newY, newZ)
					stmt.RemoveAddress('X', 'Y', 'Z')
				}
				vm.move(vm.StoredPos2.X, vm.StoredPos2.Y, vm.StoredPos2.Z)
				vm.State.MoveMode = oldMode

			case 30.1:
				pos := vm.curPos()
				vm.StoredPos2 = pos.Vector()

			case 53:
				vm.CoordinateSystem.Override()

			case 92:
				if stmt.IncludesOneOf('X', 'Y', 'Z') {
					cp := vm.curPos()
					x, y, z := stmt.GetWordDefault('X', 0), stmt.GetWordDefault('Y', 0), stmt.GetWordDefault('Z', 0)
					x, y, z = vm.axesToMetric(x, y, z)

					vm.CoordinateSystem.DisableOffset()
					x, y, z = vm.CoordinateSystem.ApplyCoordinateSystem(x, y, z)
					diffX, diffY, diffZ := cp.X-x, cp.Y-y, cp.Z-z
					vm.CoordinateSystem.SetOffset(diffX, diffY, diffZ)
					vm.CoordinateSystem.EnableOffset()

					stmt.RemoveAddress('X', 'Y', 'Z')
				} else {
					invalidCommand("nonModalGroup", "G92 configuration", "No axis words specified")
				}
			case 92.1:
				vm.CoordinateSystem.EraseOffset()

			case 92.2:
				vm.CoordinateSystem.DisableOffset()

			case 92.3:
				vm.CoordinateSystem.EnableOffset()

			default:
//.........這裏部分代碼省略.........
開發者ID:raylee,項目名稱:gocnc,代碼行數:101,代碼來源:main.go

示例4: nextTool

func (vm *Machine) nextTool(stmt *gcode.Block) {
	if val, err := stmt.GetWord('T'); err == nil {
		vm.NextTool = int(val)
		stmt.RemoveAddress('T')
	}
}
開發者ID:raylee,項目名稱:gocnc,代碼行數:6,代碼來源:main.go

示例5: spindleSpeed

func (vm *Machine) spindleSpeed(stmt *gcode.Block) {
	if val, err := stmt.GetWord('S'); err == nil {
		vm.State.SpindleSpeed = val
		stmt.RemoveAddress('S')
	}
}
開發者ID:raylee,項目名稱:gocnc,代碼行數:6,代碼來源:main.go


注:本文中的github.com/joushou/gocnc/gcode.Block.GetWord方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。