151 lines
4.4 KiB
Go
151 lines
4.4 KiB
Go
package circuit_sys
|
|
|
|
import (
|
|
"joylink.club/ecs"
|
|
"joylink.club/ecs/filter"
|
|
"joylink.club/rtsssimulation/component"
|
|
)
|
|
|
|
type PsdSys struct {
|
|
query *ecs.Query
|
|
}
|
|
|
|
func NewPsdSys() *PsdSys {
|
|
return &PsdSys{
|
|
query: ecs.NewQuery(filter.Contains(component.PsdDriveCircuitType)),
|
|
}
|
|
}
|
|
|
|
func (p *PsdSys) Update(world ecs.World) {
|
|
p.query.Each(world, func(entry *ecs.Entry) {
|
|
psdDrive := component.PsdDriveCircuitType.Get(entry)
|
|
if entry.HasComponent(component.PsdCircuitType) { //有屏蔽门电路
|
|
psdCircuit := component.PsdCircuitType.Get(entry)
|
|
p.exciteByDrive(psdCircuit, psdDrive)
|
|
p.exciteGMJ(nil, psdCircuit, psdDrive)
|
|
p.exciteKMJ4(nil, psdCircuit, psdDrive)
|
|
p.exciteKMJ8(nil, psdCircuit, psdDrive)
|
|
p.exciteMGJ(psdCircuit, nil)
|
|
} else { //无屏蔽门电路,直接驱动电机
|
|
p.driveMotor(nil, psdDrive.GMJ, psdDrive.KMJ4, psdDrive.KMJ8)
|
|
}
|
|
p.updatePsdState(entry, nil)
|
|
})
|
|
}
|
|
|
|
func (p *PsdSys) exciteByDrive(psd *component.PsdCircuit, drive *component.PsdDriveCircuit) {
|
|
if drive.GMJ {
|
|
component.RelayDriveType.Get(psd.GMJ).Td = true
|
|
component.BitStateType.Get(psd.GMJ).Val = true
|
|
}
|
|
if drive.KMJ4 {
|
|
component.RelayDriveType.Get(psd.KMJ4).Td = true
|
|
component.BitStateType.Get(psd.KMJ4).Val = true
|
|
}
|
|
if drive.KMJ8 {
|
|
component.RelayDriveType.Get(psd.KMJ8).Td = true
|
|
component.BitStateType.Get(psd.KMJ8).Val = true
|
|
}
|
|
}
|
|
|
|
// 驱动电机
|
|
func (p *PsdSys) driveMotor(psdMotorState *component.AsdMotorState, gm, km4, km8 bool) {
|
|
//if gm {
|
|
// psdMotorState.Gm_Td = true
|
|
// psdMotorState.Km4_Td = false
|
|
// psdMotorState.Km8_Td = false
|
|
//} else if km4 {
|
|
// psdMotorState.Gm_Td = false
|
|
// psdMotorState.Km4_Td = true
|
|
// psdMotorState.Km8_Td = false
|
|
//} else if km8 {
|
|
// psdMotorState.Gm_Td = false
|
|
// psdMotorState.Km4_Td = false
|
|
// psdMotorState.Km8_Td = true
|
|
//}
|
|
}
|
|
|
|
func (p *PsdSys) exciteGMJ(state *component.AsdMotorState, psd *component.PsdCircuit, psdDrive *component.PsdDriveCircuit) {
|
|
//gmj := component.BitStateType.Get(psd.GMJ)
|
|
//kmj4 := component.BitStateType.Get(psd.KMJ4)
|
|
//kmj8 := component.BitStateType.Get(psd.KMJ8)
|
|
//if psdDrive.GMJ { //驱动电路接通
|
|
// component.RelayDriveType.Get(psd.GMJ).Td = true
|
|
// gmj.Val = true
|
|
//} else if gmj.Val {
|
|
// if !kmj4.Val && !kmj8.Val {
|
|
// component.RelayDriveType.Get(psd.GMJ).Td = true
|
|
// } else {
|
|
// component.RelayDriveType.Get(psd.GMJ).Td = false
|
|
// gmj.Val = false
|
|
// }
|
|
//}
|
|
//if gmj.Val && !kmj4.Val && !kmj8.Val {
|
|
// state.Gm_Td = true
|
|
//}
|
|
}
|
|
|
|
func (p *PsdSys) exciteKMJ4(state *component.AsdMotorState, psd *component.PsdCircuit, psdDrive *component.PsdDriveCircuit) {
|
|
//kmj4 := component.BitStateType.Get(psd.KMJ4)
|
|
//gmj := component.BitStateType.Get(psd.GMJ)
|
|
//kmj8 := component.BitStateType.Get(psd.KMJ8)
|
|
//if psdDrive.KMJ4 {
|
|
// component.RelayDriveType.Get(psd.KMJ4).Td = true
|
|
// kmj4.Val = true
|
|
//} else if kmj4.Val {
|
|
// if !gmj.Val && !kmj8.Val {
|
|
// component.RelayDriveType.Get(psd.KMJ4).Td = true
|
|
// } else {
|
|
// component.RelayDriveType.Get(psd.KMJ4).Td = false
|
|
// kmj4.Val = false
|
|
// }
|
|
//}
|
|
//if kmj4.Val && !gmj.Val && !kmj8.Val {
|
|
// state.Km4_Td = true
|
|
//}
|
|
}
|
|
|
|
func (p *PsdSys) exciteKMJ8(state *component.AsdMotorState, psd *component.PsdCircuit, psdDrive *component.PsdDriveCircuit) {
|
|
//kmj8 := component.BitStateType.Get(psd.KMJ8)
|
|
//gmj := component.BitStateType.Get(psd.GMJ)
|
|
//kmj4 := component.BitStateType.Get(psd.KMJ4)
|
|
//if psdDrive.KMJ4 {
|
|
// component.RelayDriveType.Get(psd.KMJ8).Td = true
|
|
// kmj8.Val = true
|
|
//} else if kmj8.Val {
|
|
// if !gmj.Val && !kmj4.Val {
|
|
// component.RelayDriveType.Get(psd.KMJ8).Td = true
|
|
// } else {
|
|
// component.RelayDriveType.Get(psd.KMJ8).Td = false
|
|
// kmj8.Val = false
|
|
// }
|
|
//}
|
|
//if kmj8.Val && !gmj.Val && !kmj4.Val {
|
|
// state.Km8_Td = true
|
|
//}
|
|
}
|
|
|
|
func (p *PsdSys) exciteMGJ(psdCircuit *component.PsdCircuit, state *component.AsdMotorState) {
|
|
//if state.Is4Km() || state.Is8Km() {
|
|
// component.RelayDriveType.Get(psdCircuit.MGJ).Td = false
|
|
// component.BitStateType.Get(psdCircuit.MGJ).Val = false
|
|
//} else {
|
|
// component.RelayDriveType.Get(psdCircuit.MGJ).Td = true
|
|
// component.BitStateType.Get(psdCircuit.MGJ).Val = true
|
|
//}
|
|
}
|
|
|
|
func (p *PsdSys) updatePsdState(entry *ecs.Entry, psdMotorState *component.AsdMotorState) {
|
|
//psdState := component.PsdStateType.Get(entry)
|
|
//if psdMotorState.Is8Km() {
|
|
// psdState.Km8 = true
|
|
// psdState.Km4 = false
|
|
//} else if psdMotorState.Is4Km() {
|
|
// psdState.Km4 = true
|
|
// psdState.Km8 = false
|
|
//} else {
|
|
// psdState.Km4 = false
|
|
// psdState.Km8 = false
|
|
//}
|
|
}
|