| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 | 
							- package shuttle
 
- import "fmt"
 
- const (
 
- 	TpXTrack   = "X"
 
- 	TpLoc      = "L"
 
- 	TpLift     = "F"
 
- 	TpNoCell   = "O"
 
- 	TpConveyor = "V"
 
- 	TpPort     = "P"
 
- )
 
- type point struct {
 
- 	X float64
 
- 	Y float64
 
- 	Z float64
 
- }
 
- // 仓库的位置,可能是货位也可能不是
 
- type addr struct {
 
- 	F int
 
- 	C int
 
- 	R int
 
- }
 
- func (a addr) getId() string {
 
- 	return getAddrId(a.F, a.C, a.R)
 
- }
 
- type IO struct {
 
- 	cells []addr
 
- }
 
- type lft struct {
 
- 	Id     string // 用户配置用于关联控制器
 
- 	C      int
 
- 	R      int    // 远离自己的Row值, 也就是数比较大的那个
 
- 	IOs    []addr // 为每层左右两侧的入口,用来定义对接的部分
 
- 	HasCnv bool   // 内置输送链 CNVxxxxx,无:“”
 
- }
 
- func (l lft) getAddrId() string {
 
- 	return fmt.Sprintf("000%2d%2d", l.C, l.R)
 
- }
 
- // 出入口,绑定在已有的实体上,可选Cel Cnv
 
- type pot struct {
 
- 	Name string // 名称可为中文
 
- 	Id   string // Id用户设置,POT
 
- 	In   bool
 
- 	Out  bool
 
- 	R    int
 
- 	C    int
 
- 	F    int
 
- 	End  string
 
- }
 
- type cnv struct {
 
- 	Id   string // 用户添加用于关联控制器
 
- 	Name string // 可以修改名称,默认跟ID相同
 
- 	End1 string // 两头,如果无则为“”
 
- 	End2 string
 
- 	F    int // 层
 
- 	C    int
 
- 	R    int
 
- 	R1   int
 
- 	Dir  string // 与列平行C,于行平行R 默认与列平行,暂不支持弯曲
 
- }
 
- type xTrc struct {
 
- 	F  int
 
- 	R  int
 
- 	CS int
 
- 	CE int
 
- }
 
- type yTrc struct {
 
- 	F  int
 
- 	C  int
 
- 	RS int
 
- 	RE int
 
- }
 
- type warehouseData struct {
 
- 	Name        string // 名称
 
- 	Id          string // Id 22041108550
 
- 	RowNum      int
 
- 	ColNum      int
 
- 	FloorNum    int
 
- 	FloorHeight float64
 
- 	CellWidth   float64 // 货位宽度
 
- 	CellLength  float64
 
- 	StoreFront  int
 
- 	StoreBack   int
 
- 	StoreLeft   int
 
- 	StoreRight  int
 
- 	// StoreX      float64 // 库区起点坐标
 
- 	// StoreY      float64
 
- 	// StoreWidth  float64 // 库区宽度,根据计算得出
 
- 	// StoreLength float64
 
- 	Pots   map[string]pot
 
- 	XTrcs  []xTrc
 
- 	YTrcs  []yTrc
 
- 	NoCels []addr // k为(00f00c00r)
 
- 	lfts   map[string]lft
 
- 	Cnvs   map[string]cnv
 
- }
 
- func (w *warehouseData) isPort(f, c, r int) bool {
 
- 	for _, p := range w.Pots {
 
- 		if p.F == f && p.C == c && p.R == r {
 
- 			return true
 
- 		}
 
- 	}
 
- 	return false
 
- }
 
- func (w *warehouseData) isCellNo(f, c, r int) bool {
 
- 	for _, a := range w.NoCels {
 
- 		if a.F == f && a.C == c && a.R == r {
 
- 			return true
 
- 		}
 
- 	}
 
- 	return false
 
- }
 
- // 判断cell是不是在提升机范围
 
- func (w *warehouseData) isInLft(c, r int) bool {
 
- 	for _, l := range w.lfts {
 
- 		if (l.C-1 <= c && c <= l.C+1) && (r == l.R || r == l.R+1) {
 
- 			return true
 
- 		}
 
- 	}
 
- 	return false
 
- }
 
- func (w *warehouseData) isCnv(f, c, r int) bool {
 
- 	for _, cv := range w.Cnvs {
 
- 		if (f == cv.F) && (cv.C == c) && (cv.R <= r && r <= cv.R1) {
 
- 			return true
 
- 		}
 
- 	}
 
- 	return false
 
- }
 
- // 判断是否为可放货格子
 
- func (w *warehouseData) isLoc(f, c, r int) bool {
 
- 	if !w.isInStore(f, r, c) {
 
- 		return false
 
- 	}
 
- 	if w.isCellNo(f, c, r) || w.isInLft(c, r) || w.isCnv(f, c, r) {
 
- 		return false
 
- 	}
 
- 	return true
 
- }
 
- func getAddrId(f, c, r int) string {
 
- 	return fmt.Sprintf("%02d%02d%02d", f, c, r)
 
- }
 
- func getCellId(tp string, f, c, r int) string {
 
- 	return fmt.Sprintf("%s%02d%02d%02d", tp, f, c, r)
 
- }
 
- func (w *warehouseData) isInStore(f, c, r int) bool {
 
- 	if f < 1 || f > w.FloorNum || c < 1 || c > w.RowNum || r < 1 || r > w.RowNum {
 
- 		return false
 
- 	}
 
- 	return true
 
- }
 
- func (w *warehouseData) isXTrc(f, c, r int) bool {
 
- 	for _, t := range w.XTrcs {
 
- 		if t.F != f || t.R != r {
 
- 			return false
 
- 		}
 
- 		if (t.CS <= c || c <= t.CE) || (t.CE <= c || c <= t.CS) {
 
- 			return true
 
- 		}
 
- 	}
 
- 	return false
 
- }
 
- func (w *warehouseData) isYTrac(f, c, r int) bool {
 
- 	for _, y := range w.YTrcs {
 
- 		if f != y.F || c != y.C {
 
- 			return false
 
- 		}
 
- 		if (y.RS <= r || r <= y.RE) || (y.RE <= r || r <= y.RS) {
 
- 			return true
 
- 		}
 
- 	}
 
- 	return false
 
- }
 
- func (w *warehouseData) getCelType(f, c, r int) string {
 
- 	if w.isInLft(c, r) {
 
- 		return TpLift
 
- 	} else if w.isCnv(f, c, r) {
 
- 		return TpConveyor
 
- 	} else if w.isXTrc(f, c, r) {
 
- 		return TpXTrack
 
- 	} else if w.isPort(f, r, c) {
 
- 		return TpPort
 
- 	} else if w.isInStore(f, c, r) {
 
- 		return TpLoc
 
- 	}
 
- 	return TpNoCell
 
- }
 
- func (w *warehouseData) newCell(f, c, r int) cell {
 
- 	return newCell(w.getCelType(f, c, r), f, c, r)
 
- }
 
- func newWarehouseDate(name string, col, row, floor int, cellWidth, cellLength float64) *warehouseData {
 
- 	o := &warehouseData{
 
- 		Name:       name,
 
- 		Id:         name,
 
- 		RowNum:     row,
 
- 		ColNum:     col,
 
- 		FloorNum:   0,
 
- 		CellWidth:  0,
 
- 		CellLength: 0,
 
- 		YTrcs:      nil,
 
- 		NoCels:     nil,
 
- 		lfts:       nil,
 
- 		Cnvs:       nil,
 
- 	}
 
- 	return o
 
- }
 
 
  |