52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package component
|
||
|
||
import "joylink.club/ecs"
|
||
|
||
// Motor 电机、马达
|
||
type Motor struct {
|
||
Speed float32 //电机转速,r/min
|
||
Forward bool //true-正转;false-反转
|
||
Ms MotorSwitch //电机开关
|
||
}
|
||
|
||
func (m *Motor) RunningForward() bool {
|
||
return m.Forward && m.Speed > 0
|
||
}
|
||
func (m *Motor) RunningReverse() bool {
|
||
return !m.Forward && m.Speed > 0
|
||
}
|
||
|
||
// MotorFc 电机变频器
|
||
// 电机转速与变频器频率关系 计算公式:n=60f/p(其中n是同步转速,f是频率,P是磁极对数)
|
||
// 变频器的额定输出频率一般为0-100HZ
|
||
type MotorFc struct {
|
||
F uint16 //变频器频率(0-100HZ)
|
||
}
|
||
|
||
// MotorSwitch 电机电源开关定义
|
||
type MotorSwitch uint8
|
||
|
||
const (
|
||
MsOff MotorSwitch = iota //关闭
|
||
MsOnForward //正转
|
||
MsOnReverse //反转
|
||
)
|
||
|
||
func (f *MotorSwitch) Off() bool {
|
||
return *f == MsOff
|
||
}
|
||
func (f *MotorSwitch) OnForward() bool {
|
||
return *f == MsOnForward
|
||
}
|
||
func (f *MotorSwitch) OnReverse() bool {
|
||
return *f == MsOnReverse
|
||
}
|
||
func (f *MotorSwitch) On() bool {
|
||
return *f == MsOnReverse || *f == MsOnForward
|
||
}
|
||
|
||
var (
|
||
MotorType = ecs.NewComponentType[Motor]() //电机马达
|
||
MotorFcType = ecs.NewComponentType[MotorFc]() //电机变频器
|
||
)
|