mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-16 01:21:20 -04:00
invert servo option
This commit is contained in:
@@ -118,6 +118,9 @@ func (s *CameraServo) angleToPulse(angle float64) int {
|
||||
}
|
||||
norm := (angle - s.cfg.MinAngle) / totalRange
|
||||
norm = math.Max(0, math.Min(1, norm))
|
||||
if s.cfg.Invert {
|
||||
norm = 1 - norm
|
||||
}
|
||||
pulseRange := s.cfg.MaxPulseUs - s.cfg.MinPulseUs
|
||||
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 = 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)
|
||||
}
|
||||
|
||||
|
||||
@@ -93,6 +93,7 @@ type CameraServoConfig struct {
|
||||
HomeAngle float64 `yaml:"homeAngle" json:"homeAngle"`
|
||||
NudgeDegrees float64 `yaml:"nudgeDegrees" json:"nudgeDegrees"`
|
||||
AllowRawPulse bool `yaml:"allowRawPulse" json:"allowRawPulse"`
|
||||
Invert bool `yaml:"invert" json:"invert"`
|
||||
}
|
||||
|
||||
type NightVisionConfig struct {
|
||||
|
||||
@@ -32,6 +32,7 @@ cameraServo:
|
||||
cycleLen: 20000
|
||||
minPulseUs: 900
|
||||
maxPulseUs: 2100
|
||||
invert: false
|
||||
minAngle: -15
|
||||
maxAngle: 30
|
||||
homeAngle: 0
|
||||
|
||||
Reference in New Issue
Block a user