From d790d11f386f7d1a47354fa78e3121be7c492cfd Mon Sep 17 00:00:00 2001 From: xzb <223@qq.com> Date: Wed, 23 Aug 2023 09:54:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E6=8E=A5=E5=8F=A3=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E5=8F=8A=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/axle_model.go | 9 +++-- model/balise_model.go | 7 ++-- model/device_model.go | 10 ------ model/link_model.go | 74 +++++++++++++++++++++++++++++++++++------- model/psd_model.go | 4 +++ model/switch_model.go | 67 +++++++++++++++++++++++++++++--------- system/train_system.go | 12 +++++++ umi/model_umi.go | 51 +++++++++++++++++++++++++++++ 8 files changed, 192 insertions(+), 42 deletions(-) create mode 100644 system/train_system.go diff --git a/model/axle_model.go b/model/axle_model.go index 13bbd8f..9fd2a03 100644 --- a/model/axle_model.go +++ b/model/axle_model.go @@ -1,12 +1,15 @@ package model -import "joylink.club/rtsssimulation/cstate" +import ( + "joylink.club/rtsssimulation/cstate" + "joylink.club/rtsssimulation/umi" +) -//计轴检测点模型 +// 计轴检测点模型 type AxlePointModel struct { DeviceModel //计轴检测点所在轨道 - LinkOffset *LinkOffsetRef + LinkOffset umi.ILinkOffsetRef } func NewAxlePointModel(id string) *AxlePointModel { diff --git a/model/balise_model.go b/model/balise_model.go index 2e15541..2fda551 100644 --- a/model/balise_model.go +++ b/model/balise_model.go @@ -1,12 +1,15 @@ package model -import "joylink.club/rtsssimulation/cstate" +import ( + "joylink.club/rtsssimulation/cstate" + "joylink.club/rtsssimulation/umi" +) // 应答器 type BaliseModel struct { DeviceModel //应答器所在轨道 - LinkOffset *LinkOffsetRef + LinkOffset umi.ILinkOffsetRef } func NewBaliseModel(id string) *BaliseModel { diff --git a/model/device_model.go b/model/device_model.go index 3fc4132..a9992b5 100644 --- a/model/device_model.go +++ b/model/device_model.go @@ -22,13 +22,3 @@ func (me *DeviceModel) IsSame(other umi.IDeviceModel) bool { func (me *DeviceModel) GetType() cstate.DeviceType { return me.Type } - -// 端口定义,如轨道、区段、道岔的端口 -type PortEnum = int8 - -// 具体端口枚举 -const ( - A PortEnum = iota - B - C -) diff --git a/model/link_model.go b/model/link_model.go index d3af657..61a55c7 100644 --- a/model/link_model.go +++ b/model/link_model.go @@ -1,30 +1,82 @@ package model -import "joylink.club/rtsssimulation/cstate" +import ( + "joylink.club/rtsssimulation/cstate" + "joylink.club/rtsssimulation/umi" +) -//长轨道,道岔端点间的轨道 +// 长轨道,道岔端点间的轨道 type LinkModel struct { DeviceModel //轨道A端口连接的道岔 - PortA *SwitchPortRef + PortA umi.ISwitchRef //轨道B端口连接的道岔 - PortB *SwitchPortRef + PortB umi.ISwitchRef + //长度,单位mm + Length int64 } func NewLinkModel(id string) *LinkModel { return &LinkModel{DeviceModel: DeviceModel{Id: id, Type: cstate.DeviceType_Link}} } -//轨道端口引用 -type LinkPortRef struct { - Link *LinkModel - //引用轨道的端口 - Port PortEnum +// 获取轨道长度,单位mm +func (me *LinkModel) Len() int64 { + return me.Length } -//轨道偏移位置引用,轨道A端为偏移起始位置 +// 轨道A端连接的道岔 +func (me *LinkModel) PortASwitch() umi.ISwitchRef { + return me.PortA +} + +// 轨道B端连接的道岔 +func (me *LinkModel) PortBSwitch() umi.ISwitchRef { + return me.PortB +} + +/////////////////////////////////////////////////////// + +// 轨道端口引用 +type LinkRef struct { + Link umi.ILinkModel + //引用轨道的端口 + Port umi.PortEnum +} + +func NewLinkRef(link *LinkModel, port umi.PortEnum) *LinkRef { + return &LinkRef{Link: link, Port: port} +} + +// 被引用的轨道模型 +func (me *LinkRef) LinkModel() umi.ILinkModel { + return me.Link +} + +// 被引用的轨道的端口 +func (me *LinkRef) LinkPort() umi.PortEnum { + return me.Port +} + +/////////////////////////////////////////////////////////// + +// 轨道偏移位置引用,轨道A端为偏移起始位置 type LinkOffsetRef struct { - Link *LinkModel + Link umi.ILinkModel //偏移位置,单位mm Offset int64 } + +func NewLinkOffsetRef(link *LinkModel, offset int64) *LinkOffsetRef { + return &LinkOffsetRef{Link: link, Offset: offset} +} + +// 被引用的轨道模型 +func (me *LinkOffsetRef) LinkModel() umi.ILinkModel { + return me.Link +} + +// 偏移量,单位mm +func (me *LinkOffsetRef) GetOffset() int64 { + return me.Offset +} diff --git a/model/psd_model.go b/model/psd_model.go index 3413085..87e2b83 100644 --- a/model/psd_model.go +++ b/model/psd_model.go @@ -20,9 +20,13 @@ func NewPsdModel(id string) *PsdModel { func (me *PsdModel) addCell(cell *PsdCellModel) { me.Cells = append(me.Cells, cell) } + +// 屏蔽门移动从0-100耗时,单位ms func (me *PsdModel) MovingTime() int64 { return me.MoveTime } + +// 屏蔽门的所有单元门 func (me *PsdModel) AllDeviceCells() []umi.IDeviceModel { rt := make([]umi.IDeviceModel, 0, len(me.Cells)) for _, cell := range me.Cells { diff --git a/model/switch_model.go b/model/switch_model.go index 00eb982..3fcdb7e 100644 --- a/model/switch_model.go +++ b/model/switch_model.go @@ -1,31 +1,66 @@ package model -import "joylink.club/rtsssimulation/cstate" +import ( + "joylink.club/rtsssimulation/cstate" + "joylink.club/rtsssimulation/umi" +) -//道岔 +// 道岔 type SwitchModel struct { DeviceModel //道岔A端口连接的轨道 - PortA *LinkPortRef + PortA umi.ILinkRef //道岔B端口连接的轨道 - PortB *LinkPortRef + PortB umi.ILinkRef //道岔C端口连接的轨道 - PortC *LinkPortRef + PortC umi.ILinkRef //道岔转动需要的时间(从开度0-100的时间),单位ms TurnTime int64 } -func (me *SwitchModel) TurningTime() int64 { - return me.TurnTime -} - -//道岔端口引用 -type SwitchPortRef struct { - Switch *SwitchModel - //引用道岔的端口 - Port PortEnum -} - func NewSwitchModel(id string) *SwitchModel { return &SwitchModel{DeviceModel: DeviceModel{Id: id, Type: cstate.DeviceType_Switch}} } + +// 道岔转动从0-100耗时,单位ms +func (me *SwitchModel) TurningTime() int64 { + return me.TurnTime +} + +// 道岔A端口连接的轨道 +func (me *SwitchModel) PortALink() umi.ILinkRef { + return me.PortA +} + +// 道岔B端口连接的轨道 +func (me *SwitchModel) PortBLink() umi.ILinkRef { + return me.PortB +} + +// 道岔C端口连接的轨道 +func (me *SwitchModel) PortCLink() umi.ILinkRef { + return me.PortC +} + +////////////////////////////////////////////////////////// + +// 道岔端口引用 +type SwitchRef struct { + Switch umi.ISwitchModel + //引用道岔的端口 + Port umi.PortEnum +} + +func NewSwitchRef(switchModel *SwitchModel, port umi.PortEnum) *SwitchRef { + return &SwitchRef{Switch: switchModel, Port: port} +} + +// 被引用的道岔模型 +func (me *SwitchRef) SwitchModel() umi.ISwitchModel { + return me.Switch +} + +// 被引用的道岔的端口 +func (me *SwitchRef) SwitchPort() umi.PortEnum { + return me.Port +} diff --git a/system/train_system.go b/system/train_system.go new file mode 100644 index 0000000..c3846f3 --- /dev/null +++ b/system/train_system.go @@ -0,0 +1,12 @@ +package system + +import "joylink.club/ecs" + +// 实现列车在link上运行的系统 +type TrainSystem struct { +} + +// world 执行 +func (me *TrainSystem) Update(world ecs.World) { + +} diff --git a/umi/model_umi.go b/umi/model_umi.go index 9f07d59..f3b6583 100644 --- a/umi/model_umi.go +++ b/umi/model_umi.go @@ -4,6 +4,16 @@ import "joylink.club/rtsssimulation/cstate" // 用户设备模型与仿真底层设备交互定义 +// 端口定义,如轨道、区段、道岔的端口 +type PortEnum = int8 + +// 具体端口枚举 +const ( + A PortEnum = iota + B + C +) + // 仿真底层设备模型定义 // 用户所有设备模型定义须实现该接口 type IDeviceModel interface { @@ -12,11 +22,52 @@ type IDeviceModel interface { GetType() cstate.DeviceType } +// 仿真底层道岔模型 +// 用户所有轨道模型定义须实现该接口 +type ILinkModel interface { + //获取轨道长度,单位mm + Len() int64 + //轨道A端连接的道岔 + PortASwitch() ISwitchRef + //轨道B端连接的道岔 + PortBSwitch() ISwitchRef +} + +// 轨道引用 +type ILinkRef interface { + //被引用的轨道模型 + LinkModel() ILinkModel + //被引用的轨道的端口 + LinkPort() PortEnum +} + +// 轨道偏移引用 +type ILinkOffsetRef interface { + //被引用的轨道模型 + LinkModel() ILinkModel + //偏移量,单位mm + GetOffset() int64 +} + // 仿真底层道岔模型 // 用户所有道岔模型定义须实现该接口 type ISwitchModel interface { //道岔转动从0-100耗时,单位ms TurningTime() int64 + //道岔A端口连接的轨道 + PortALink() ILinkRef + //道岔B端口连接的轨道 + PortBLink() ILinkRef + //道岔C端口连接的轨道 + PortCLink() ILinkRef +} + +// 道岔引用 +type ISwitchRef interface { + //被引用的道岔模型 + SwitchModel() ISwitchModel + //被引用的道岔的端口 + SwitchPort() PortEnum } // 仿真底层屏蔽门模型