invert servo option

This commit is contained in:
legop3
2025-12-07 20:41:15 -05:00
parent b72c58452e
commit d857668109
5 changed files with 8 additions and 0 deletions
Vendored
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+6
View File
@@ -118,6 +118,9 @@ func (s *CameraServo) angleToPulse(angle float64) int {
} }
norm := (angle - s.cfg.MinAngle) / totalRange norm := (angle - s.cfg.MinAngle) / totalRange
norm = math.Max(0, math.Min(1, norm)) norm = math.Max(0, math.Min(1, norm))
if s.cfg.Invert {
norm = 1 - norm
}
pulseRange := s.cfg.MaxPulseUs - s.cfg.MinPulseUs pulseRange := s.cfg.MaxPulseUs - s.cfg.MinPulseUs
return s.cfg.MinPulseUs + int(math.Round(norm*float64(pulseRange))) return s.cfg.MinPulseUs + int(math.Round(norm*float64(pulseRange)))
} }
@@ -129,6 +132,9 @@ func (s *CameraServo) pulseToAngle(pulse int) float64 {
} }
norm := float64(pulse-s.cfg.MinPulseUs) / float64(pulseRange) norm := float64(pulse-s.cfg.MinPulseUs) / float64(pulseRange)
norm = math.Max(0, math.Min(1, norm)) norm = math.Max(0, math.Min(1, norm))
if s.cfg.Invert {
norm = 1 - norm
}
return s.cfg.MinAngle + norm*(s.cfg.MaxAngle-s.cfg.MinAngle) return s.cfg.MinAngle + norm*(s.cfg.MaxAngle-s.cfg.MinAngle)
} }
+1
View File
@@ -93,6 +93,7 @@ type CameraServoConfig struct {
HomeAngle float64 `yaml:"homeAngle" json:"homeAngle"` HomeAngle float64 `yaml:"homeAngle" json:"homeAngle"`
NudgeDegrees float64 `yaml:"nudgeDegrees" json:"nudgeDegrees"` NudgeDegrees float64 `yaml:"nudgeDegrees" json:"nudgeDegrees"`
AllowRawPulse bool `yaml:"allowRawPulse" json:"allowRawPulse"` AllowRawPulse bool `yaml:"allowRawPulse" json:"allowRawPulse"`
Invert bool `yaml:"invert" json:"invert"`
} }
type NightVisionConfig struct { type NightVisionConfig struct {
+1
View File
@@ -32,6 +32,7 @@ cameraServo:
cycleLen: 20000 cycleLen: 20000
minPulseUs: 900 minPulseUs: 900
maxPulseUs: 2100 maxPulseUs: 2100
invert: false
minAngle: -15 minAngle: -15
maxAngle: 30 maxAngle: 30
homeAngle: 0 homeAngle: 0