添加计数器系统
断相保护器逻辑修改 转辙机电路代码整理
This commit is contained in:
parent
665adde46e
commit
9faf98f1eb
@ -6,6 +6,8 @@ const (
|
||||
|
||||
// 断相保护器超时时间,单位ms
|
||||
DBQTimeout = 13 * 1000
|
||||
// 切断继电器延时缓放电路缓放时间,单位ms
|
||||
QDJ_DELAY = 3 * 1000
|
||||
// 继电器缓放时间,单位ms
|
||||
RelayHfTime = int(0.5 * 1000)
|
||||
)
|
||||
|
@ -9,7 +9,8 @@ import (
|
||||
func NewDBQEntity(w ecs.World, uid string, entityMap map[string]*ecs.Entry) *ecs.Entry {
|
||||
entry, ok := entityMap[uid]
|
||||
if !ok {
|
||||
entry = w.Create(component.DBQTag, component.DBQStateType)
|
||||
entry = w.Create(component.DBQTag, component.DBQStateType, component.CounterType)
|
||||
component.UidType.SetValue(entry, component.Uid{Id: uid})
|
||||
entityMap[uid] = entry
|
||||
}
|
||||
return entry
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"github.com/yohamta/donburi/filter"
|
||||
"joylink.club/ecs"
|
||||
"joylink.club/rtsssimulation/component"
|
||||
"joylink.club/rtsssimulation/consts"
|
||||
)
|
||||
|
||||
// ZDJ9双机牵引道岔电路系统
|
||||
@ -98,25 +99,7 @@ func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ1_DFBJ(entry *ecs.Entry, elec *componen
|
||||
zzj := component.GetTurnoutZzj1State(entry)
|
||||
dbj_drive := component.RelayDriveType.Get(elec.TDFJ1_DBJ)
|
||||
fbj_drive := component.RelayDriveType.Get(elec.TDFJ1_FBJ)
|
||||
// 默认BB(道岔表示变压器)正常
|
||||
if !dbj_drive.Td { // 定表继电器未通电
|
||||
if !_1dqj.Val && _2dqj.Val && !zzj.JD12 && !zzj.JD34 { // 1DQJ落下,2DQJ定位,开闭器接点在1/3排
|
||||
dbj_drive.Td = true
|
||||
}
|
||||
} else { // 定表继电器通电
|
||||
if !(!_1dqj.Val && _2dqj.Val && !zzj.JD12 && !zzj.JD34) { // 励磁电路断开
|
||||
dbj_drive.Td = false
|
||||
}
|
||||
}
|
||||
if !fbj_drive.Td { // 反表继电器未通电
|
||||
if !_1dqj.Val && !_2dqj.Val && zzj.JD12 && zzj.JD34 { // 2DQJ反位,开闭器在2/4排
|
||||
fbj_drive.Td = true
|
||||
}
|
||||
} else { // 反表继电器通电
|
||||
if !(!_1dqj.Val && !_2dqj.Val && zzj.JD12 && zzj.JD34) { // 电路断开
|
||||
fbj_drive.Td = false
|
||||
}
|
||||
}
|
||||
zdj9.exciteDFBJ(_1dqj, _2dqj, zzj, dbj_drive, fbj_drive)
|
||||
}
|
||||
|
||||
// 转辙机二定表/反表继电器控制
|
||||
@ -126,6 +109,12 @@ func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ1_DFBJ(entry *ecs.Entry, elec *componen
|
||||
zzj := component.GetTurnoutZzj2State(entry)
|
||||
dbj_drive := component.RelayDriveType.Get(elec.TDFJ2_DBJ)
|
||||
fbj_drive := component.RelayDriveType.Get(elec.TDFJ2_FBJ)
|
||||
zdj9.exciteDFBJ(_1dqj, _2dqj, zzj, dbj_drive, fbj_drive)
|
||||
}
|
||||
|
||||
// 定反表励磁控制
|
||||
func (zdj9 *ZDJ9TwoDragSys) exciteDFBJ(_1dqj *component.BitState, _2dqj *component.BitState, zzj *component.ZzjState,
|
||||
dbj_drive *component.RelayDrive, fbj_drive *component.RelayDrive) {
|
||||
// 默认BB(道岔表示变压器)正常
|
||||
if !dbj_drive.Td { // 定表继电器未通电
|
||||
if !_1dqj.Val && _2dqj.Val && !zzj.JD12 && !zzj.JD34 { // 1DQJ落下,2DQJ定位,开闭器接点在1/3排
|
||||
@ -147,9 +136,6 @@ func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ1_DFBJ(entry *ecs.Entry, elec *componen
|
||||
}
|
||||
}
|
||||
|
||||
// 切断继电器延时缓放电路缓放时间,单位ms
|
||||
const QDJ_DELAY = 3 * 1000
|
||||
|
||||
// 切断继电器控制
|
||||
func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_QDJ(w ecs.World, entry *ecs.Entry, elec *component.Zdj9TwoElectronic) {
|
||||
tdfj1_bhj := component.BitStateType.Get(elec.TDFJ1_BHJ)
|
||||
@ -160,11 +146,8 @@ func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_QDJ(w ecs.World, entry *ecs.Entry, ele
|
||||
if !tdfj1_qdj.Val { // 落下状态
|
||||
if !drive.Td && (!tdfj1_bhj.Val && !tdfj2_bhj.Val) || tdfj1_zbhj.Val { // 电路导通
|
||||
drive.Td = true
|
||||
elec.TDFJ1_QDJ_Remain = QDJ_DELAY
|
||||
elec.TDFJ1_QDJ_Remain = consts.QDJ_DELAY
|
||||
fmt.Println("切断继电器通电")
|
||||
// if entry.HasComponent(component.CounterDownType) {
|
||||
// entry.RemoveComponent(component.CounterDownType)
|
||||
// }
|
||||
}
|
||||
} else { // 吸起状态
|
||||
if drive.Td && !tdfj1_zbhj.Val && !(!tdfj1_bhj.Val && !tdfj2_bhj.Val) { // 电路断开
|
||||
@ -179,18 +162,6 @@ func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_QDJ(w ecs.World, entry *ecs.Entry, ele
|
||||
elec.TDFJ1_QDJ_Remain = remain
|
||||
}
|
||||
}
|
||||
// if entry.HasComponent(component.CounterDownType) {
|
||||
// cd := component.CounterDownType.Get(entry)
|
||||
// if cd.Val <= 0 {
|
||||
// drive.Td = false
|
||||
// entry.RemoveComponent(component.CounterDownType)
|
||||
// }
|
||||
// } else {
|
||||
// entry.AddComponent(component.CounterDownType, unsafe.Pointer(&component.CounterDown{
|
||||
// Val: QDJ_DELAY,
|
||||
// Step: w.Tick(),
|
||||
// }))
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -218,25 +189,7 @@ func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_DBQ(w ecs.World, entry *ecs.Entry, ele
|
||||
_2dqj := component.BitStateType.Get(elec.TDFJ1_2DQJ)
|
||||
zzj := component.GetTurnoutZzj1State(entry)
|
||||
dbq := component.DBQStateType.Get(elec.TDFJ1_DBQ)
|
||||
zdj9.exciteDBQ(_1dqj, _1dqjf, _2dqj, dbq, zzj)
|
||||
// if dbq.Td { // 通电
|
||||
// if !(_1dqj.Val && _1dqjf.Val && !zzj.JD12 && !_2dqj.Val) &&
|
||||
// !(_1dqj.Val && _1dqjf.Val && zzj.JD34 && _2dqj.Val) { // 断开
|
||||
// dbq.Td = false
|
||||
// zzj.Td = false
|
||||
// } else { // 处理正反转
|
||||
// if zzj.Dw && !_2dqj.Val {
|
||||
// zzj.Dw = false
|
||||
// } else if !zzj.Dw && _2dqj.Val {
|
||||
// zzj.Dw = true
|
||||
// }
|
||||
// }
|
||||
// } else { // 未通电
|
||||
// if _1dqj.Val && _1dqjf.Val && ((!zzj.JD12 && !_2dqj.Val) || (zzj.JD34 && _2dqj.Val)) { // 通电
|
||||
// dbq.Td = true
|
||||
// zzj.Td = true
|
||||
// }
|
||||
// }
|
||||
zdj9.exciteDBQ(1, _1dqj, _1dqjf, _2dqj, dbq, zzj)
|
||||
}
|
||||
|
||||
// 转辙机二断相保护器控制
|
||||
@ -246,44 +199,33 @@ func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ_DBQ(w ecs.World, entry *ecs.Entry, ele
|
||||
_2dqj := component.BitStateType.Get(elec.TDFJ2_2DQJ)
|
||||
zzj := component.GetTurnoutZzj2State(entry)
|
||||
dbq := component.DBQStateType.Get(elec.TDFJ2_DBQ)
|
||||
zdj9.exciteDBQ(_1dqj, _1dqjf, _2dqj, dbq, zzj)
|
||||
// if dbq.Td { // 通电
|
||||
// if !(_1dqj.Val && _1dqjf.Val && !zzj.JD12 && !_2dqj.Val) &&
|
||||
// !(_1dqj.Val && _1dqjf.Val && zzj.JD34 && _2dqj.Val) { // 断开
|
||||
// dbq.Td = false
|
||||
// zzj.Td = false
|
||||
// }
|
||||
// } else { // 未通电
|
||||
// if _1dqj.Val && _1dqjf.Val && ((!zzj.JD12 && !_2dqj.Val) || (zzj.JD34 && _2dqj.Val)) { // 通电
|
||||
// dbq.Td = true
|
||||
// zzj.Td = true
|
||||
// zzj.Dw = _2dqj.Val
|
||||
// }
|
||||
// }
|
||||
zdj9.exciteDBQ(2, _1dqj, _1dqjf, _2dqj, dbq, zzj)
|
||||
}
|
||||
|
||||
func (zdj9 *ZDJ9TwoDragSys) exciteDBQ(_1dqj *component.BitState, _1dqjf *component.BitState, _2dqj *component.BitState,
|
||||
// 断相保护器控制
|
||||
// i - 几号转辙机(1/2)
|
||||
func (zdj9 *ZDJ9TwoDragSys) exciteDBQ(i int, _1dqj *component.BitState, _1dqjf *component.BitState, _2dqj *component.BitState,
|
||||
dbq *component.DBQState, zzj *component.ZzjState) {
|
||||
if dbq.Td { // 通电
|
||||
if !(_1dqj.Val && _1dqjf.Val && !zzj.JD12 && !_2dqj.Val) &&
|
||||
!(_1dqj.Val && _1dqjf.Val && zzj.JD34 && _2dqj.Val) { // 断开
|
||||
dbq.Td = false
|
||||
zzj.Td = false
|
||||
fmt.Println("转辙机断电")
|
||||
fmt.Printf("转辙机%v断电\n", i)
|
||||
} else { // 处理正反转
|
||||
if zzj.Dw && !_2dqj.Val {
|
||||
zzj.Dw = false
|
||||
fmt.Println("转辙机转到反位")
|
||||
fmt.Printf("转辙机%v转到反位\n", i)
|
||||
} else if !zzj.Dw && _2dqj.Val {
|
||||
zzj.Dw = true
|
||||
fmt.Println("转辙机转到定位")
|
||||
fmt.Printf("转辙机%v转到定位\n", i)
|
||||
}
|
||||
}
|
||||
} else { // 未通电
|
||||
if _1dqj.Val && _1dqjf.Val && ((!zzj.JD12 && !_2dqj.Val) || (zzj.JD34 && _2dqj.Val)) { // 通电
|
||||
dbq.Td = true
|
||||
zzj.Td = true
|
||||
fmt.Println("转辙机通电")
|
||||
fmt.Printf("转辙机%v通电\n", i)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -292,17 +234,18 @@ func (zdj9 *ZDJ9TwoDragSys) exciteDBQ(_1dqj *component.BitState, _1dqjf *compone
|
||||
func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_BHJ(elec *component.Zdj9TwoElectronic) {
|
||||
dbq := component.DBQStateType.Get(elec.TDFJ1_DBQ)
|
||||
bhj := component.RelayDriveType.Get(elec.TDFJ1_BHJ)
|
||||
if !bhj.Td && dbq.Dzkg { // BHJ励磁电路导通
|
||||
bhj.Td = true
|
||||
} else if bhj.Td && !dbq.Dzkg { // BHJ励磁电路断开
|
||||
bhj.Td = false
|
||||
}
|
||||
zdj9.exciteBHJ(dbq, bhj)
|
||||
}
|
||||
|
||||
// 转辙机二TDFJ_BHJ保护继电器励磁状态控制
|
||||
func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ_BHJ(elec *component.Zdj9TwoElectronic) {
|
||||
dbq := component.DBQStateType.Get(elec.TDFJ2_DBQ)
|
||||
bhj := component.RelayDriveType.Get(elec.TDFJ2_BHJ)
|
||||
zdj9.exciteBHJ(dbq, bhj)
|
||||
}
|
||||
|
||||
// 保护继电器励磁控制
|
||||
func (zdj9 *ZDJ9TwoDragSys) exciteBHJ(dbq *component.DBQState, bhj *component.RelayDrive) {
|
||||
if !bhj.Td && dbq.Dzkg { // BHJ励磁电路导通
|
||||
bhj.Td = true
|
||||
} else if bhj.Td && !dbq.Dzkg { // BHJ励磁电路断开
|
||||
@ -314,28 +257,25 @@ func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ_BHJ(elec *component.Zdj9TwoElectronic)
|
||||
func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_1DQJF(elec *component.Zdj9TwoElectronic) {
|
||||
tdfj_1dqj := component.BitStateType.Get(elec.TDFJ1_1DQJ)
|
||||
tdfj_1dqjf_drive := component.RelayDriveType.Get(elec.TDFJ1_1DQJF)
|
||||
if tdfj_1dqjf_drive.Td { // 通电
|
||||
if !tdfj_1dqj.Val {
|
||||
tdfj_1dqjf_drive.Td = false
|
||||
}
|
||||
} else { // 未通电
|
||||
if tdfj_1dqj.Val {
|
||||
tdfj_1dqjf_drive.Td = true
|
||||
}
|
||||
}
|
||||
zdj9.excite1DQJF(tdfj_1dqj, tdfj_1dqjf_drive)
|
||||
}
|
||||
|
||||
// 转辙机二TDFJ_1DQJF励磁电路逻辑
|
||||
func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ_1DQJF(elec *component.Zdj9TwoElectronic) {
|
||||
tdfj_1dqj := component.BitStateType.Get(elec.TDFJ2_1DQJ)
|
||||
tdfj_1dqjf_drive := component.RelayDriveType.Get(elec.TDFJ2_1DQJF)
|
||||
if tdfj_1dqjf_drive.Td { // 通电
|
||||
if !tdfj_1dqj.Val {
|
||||
tdfj_1dqjf_drive.Td = false
|
||||
zdj9.excite1DQJF(tdfj_1dqj, tdfj_1dqjf_drive)
|
||||
}
|
||||
|
||||
// 1DQJF励磁控制
|
||||
func (zdj9 *ZDJ9TwoDragSys) excite1DQJF(_1dqj *component.BitState, _1dqjf_drive *component.RelayDrive) {
|
||||
if _1dqjf_drive.Td { // 通电
|
||||
if !_1dqj.Val {
|
||||
_1dqjf_drive.Td = false
|
||||
}
|
||||
} else { // 未通电
|
||||
if tdfj_1dqj.Val {
|
||||
tdfj_1dqjf_drive.Td = true
|
||||
if _1dqj.Val {
|
||||
_1dqjf_drive.Td = true
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -393,65 +333,47 @@ func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ_1DQJ(elec *component.Zdj9TwoElectronic
|
||||
|
||||
// 转辙机一TDFJ_2DQJ励磁电路逻辑(暂时未考虑应急盘操作按钮电路)
|
||||
func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_2DQJ(elec *component.Zdj9TwoElectronic) {
|
||||
tdfj1_1dqjf := component.BitStateType.Get(elec.TDFJ1_1DQJF)
|
||||
_1dqjf := component.BitStateType.Get(elec.TDFJ1_1DQJF)
|
||||
dcj := component.BitStateType.Get(elec.TDC_DCJ)
|
||||
fcj := component.BitStateType.Get(elec.TDC_FCJ)
|
||||
drive := component.RelayDriveType.Get(elec.TDFJ1_2DQJ)
|
||||
|
||||
if drive.Td { // 通电
|
||||
if !drive.Xq && tdfj1_1dqjf.Val && dcj.Val {
|
||||
drive.Xq = true
|
||||
fmt.Println("TDFJ1_2DQJ到定位")
|
||||
} else if drive.Xq && tdfj1_1dqjf.Val && fcj.Val {
|
||||
drive.Xq = false
|
||||
fmt.Println("TDFJ1_2DQJ到反位")
|
||||
} else if !(tdfj1_1dqjf.Val && (dcj.Val || fcj.Val)) { // 断电
|
||||
drive.Td = false
|
||||
fmt.Println("TDFJ1_2DQJ断电")
|
||||
}
|
||||
} else { // 未通电
|
||||
if tdfj1_1dqjf.Val {
|
||||
if dcj.Val { // 通电,到吸起位
|
||||
drive.Td = true
|
||||
drive.Xq = true
|
||||
fmt.Println("TDFJ1_2DQJ通电,到吸起位")
|
||||
} else if fcj.Val { // 通电,到落下位
|
||||
drive.Td = true
|
||||
drive.Xq = false
|
||||
fmt.Println("TDFJ1_2DQJ通电,到落下位")
|
||||
}
|
||||
}
|
||||
}
|
||||
zdj9.excite2DQJ(1, _1dqjf, dcj, fcj, drive)
|
||||
}
|
||||
|
||||
// 转辙机二TDFJ_2DQJ励磁电路逻辑(暂时未考虑应急盘操作按钮电路)
|
||||
func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ_2DQJ(elec *component.Zdj9TwoElectronic) {
|
||||
tdfj2_1dqjf := component.BitStateType.Get(elec.TDFJ2_1DQJF)
|
||||
_1dqjf := component.BitStateType.Get(elec.TDFJ2_1DQJF)
|
||||
dcj := component.BitStateType.Get(elec.TDC_DCJ)
|
||||
fcj := component.BitStateType.Get(elec.TDC_FCJ)
|
||||
drive := component.RelayDriveType.Get(elec.TDFJ2_2DQJ)
|
||||
zdj9.excite2DQJ(2, _1dqjf, dcj, fcj, drive)
|
||||
}
|
||||
|
||||
// 2DQJ励磁控制
|
||||
// i - 几号转辙机(1/2)
|
||||
func (zdj9 *ZDJ9TwoDragSys) excite2DQJ(i int, _1dqjf *component.BitState, dcj *component.BitState, fcj *component.BitState,
|
||||
drive *component.RelayDrive) {
|
||||
if drive.Td { // 通电
|
||||
if !drive.Xq && tdfj2_1dqjf.Val && dcj.Val {
|
||||
if !drive.Xq && _1dqjf.Val && dcj.Val {
|
||||
drive.Xq = true
|
||||
fmt.Println("TDFJ2_2DQJ到定位")
|
||||
} else if drive.Xq && tdfj2_1dqjf.Val && fcj.Val {
|
||||
fmt.Printf("TDFJ%v_2DQJ到定位\n", i)
|
||||
} else if drive.Xq && _1dqjf.Val && fcj.Val {
|
||||
drive.Xq = false
|
||||
fmt.Println("TDFJ2_2DQJ到反位")
|
||||
} else if !(tdfj2_1dqjf.Val && (dcj.Val || fcj.Val)) { // 断电
|
||||
fmt.Printf("TDFJ%v_2DQJ到反位\n", i)
|
||||
} else if !(_1dqjf.Val && (dcj.Val || fcj.Val)) { // 断电
|
||||
drive.Td = false
|
||||
fmt.Println("TDFJ2_2DQJ断电")
|
||||
fmt.Printf("TDFJ%v_2DQJ断电\n", i)
|
||||
}
|
||||
} else { // 未通电
|
||||
if tdfj2_1dqjf.Val {
|
||||
if _1dqjf.Val {
|
||||
if dcj.Val { // 通电,到吸起位
|
||||
drive.Td = true
|
||||
drive.Xq = true
|
||||
fmt.Println("TDFJ2_2DQJ通电,到吸起位")
|
||||
fmt.Printf("TDFJ%v_2DQJ通电,到吸起位\n", i)
|
||||
} else if fcj.Val { // 通电,到落下位
|
||||
drive.Td = true
|
||||
drive.Xq = false
|
||||
fmt.Println("TDFJ2_2DQJ通电,到落下位")
|
||||
fmt.Printf("TDFJ%v_2DQJ通电,到落下位\n", i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
27
sys/common_sys/counter.go
Normal file
27
sys/common_sys/counter.go
Normal file
@ -0,0 +1,27 @@
|
||||
package common_sys
|
||||
|
||||
import (
|
||||
"github.com/yohamta/donburi/filter"
|
||||
"joylink.club/ecs"
|
||||
"joylink.club/rtsssimulation/component"
|
||||
)
|
||||
|
||||
type CounterSys struct {
|
||||
query *ecs.Query
|
||||
}
|
||||
|
||||
func NewCounterSys() *CounterDownSys {
|
||||
return &CounterDownSys{
|
||||
query: ecs.NewQuery(filter.Contains(component.CounterType)),
|
||||
}
|
||||
}
|
||||
|
||||
// 更新
|
||||
func (c *CounterSys) Update(w ecs.World) {
|
||||
c.query.Each(w, func(entry *ecs.Entry) {
|
||||
counter := component.CounterType.Get(entry)
|
||||
if counter.Step > 0 {
|
||||
counter.Val = counter.Val + counter.Step
|
||||
}
|
||||
})
|
||||
}
|
@ -35,11 +35,16 @@ func (q *DBQSys) Update(w ecs.World) {
|
||||
// 判断定时器是否超时,如果超时,断开电子开关
|
||||
counter := component.CounterType.Get(entry)
|
||||
if counter.Val >= consts.DBQTimeout {
|
||||
counter.Step = 0
|
||||
dbq.Dzkg = false
|
||||
}
|
||||
}
|
||||
} else if !dbq.Td && dbq.Dzkg { // 无电,断开电子开关
|
||||
} else if !dbq.Td && dbq.Dzkg { // 断电,断开电子开关
|
||||
dbq.Dzkg = false
|
||||
if entry.HasComponent(component.CounterType) { // 断电,停止计时
|
||||
counter := component.CounterType.Get(entry)
|
||||
counter.Step = 0
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user