mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-17 10:00:46 -04:00
invert servo option
This commit is contained in:
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
@@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user