rts-sim-module/component/motor.go
2023-12-26 17:52:28 +08:00

52 lines
1.2 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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]() //电机变频器
)