feat: asymetric throttle

This commit is contained in:
Cyrille Nofficial 2022-06-13 18:35:27 +02:00
parent ed1f210a83
commit 973ebb9df9
2 changed files with 16 additions and 3 deletions

View File

@ -170,7 +170,16 @@ func (a *Part) processChannel2(v string) {
} else if value > a.pwmThrottleConfig.Max { } else if value > a.pwmThrottleConfig.Max {
value = a.pwmThrottleConfig.Max value = a.pwmThrottleConfig.Max
} }
a.throttle = ((float32(value)-MinPwmThrottle)/(MaxPwmThrottle-MinPwmThrottle))*2.0 - 1.0
throttle := 0.
if value > a.pwmThrottleConfig.Zero {
throttle = (float64(value) - float64(a.pwmThrottleConfig.Zero)) / float64(a.pwmThrottleConfig.Max-a.pwmThrottleConfig.Zero)
}
if value < a.pwmThrottleConfig.Zero {
throttle = -1. * (float64(a.pwmThrottleConfig.Zero) - float64(value)) / (float64(a.pwmThrottleConfig.Zero - a.pwmThrottleConfig.Min))
}
a.throttle = float32(throttle)
} }
func (a *Part) processChannel3(v string) { func (a *Part) processChannel3(v string) {

View File

@ -148,7 +148,7 @@ func TestArduinoPart_Update(t *testing.T) {
{"Throttle: stop", {"Throttle: stop",
fmt.Sprintf("12430,%d,%d,%d,%d,%d,%d,50,%d\n", channel1, 1450, channel3, channel4, channel5, channel6, distanceCm), fmt.Sprintf("12430,%d,%d,%d,%d,%d,%d,50,%d\n", channel1, 1450, channel3, channel4, channel5, channel6, distanceCm),
defaultPwmThrottleConfig, defaultPwmThrottleConfig,
-0.03, -1., events.DriveMode_USER, false}, 0.0, -1., events.DriveMode_USER, false},
{"Throttle: up", {"Throttle: up",
fmt.Sprintf("12435,%d,%d,%d,%d,%d,%d,50,%d\n", channel1, 1948, channel3, channel4, channel5, channel6, distanceCm), fmt.Sprintf("12435,%d,%d,%d,%d,%d,%d,50,%d\n", channel1, 1948, channel3, channel4, channel5, channel6, distanceCm),
defaultPwmThrottleConfig, defaultPwmThrottleConfig,
@ -157,6 +157,10 @@ func TestArduinoPart_Update(t *testing.T) {
fmt.Sprintf("12440,%d,%d,%d,%d,%d,%d,50,%d\n", channel1, 2998, channel3, channel4, channel5, channel6, distanceCm), fmt.Sprintf("12440,%d,%d,%d,%d,%d,%d,50,%d\n", channel1, 2998, channel3, channel4, channel5, channel6, distanceCm),
defaultPwmThrottleConfig, defaultPwmThrottleConfig,
1., -1., events.DriveMode_USER, false}, 1., -1., events.DriveMode_USER, false},
{"Throttle: zero not middle",
fmt.Sprintf("12440,%d,%d,%d,%d,%d,%d,50,%d\n", channel1, 1600, channel3, channel4, channel5, channel6, distanceCm),
PWMThrottleConfig{1000, 1700, 1500},
0.5, -1., events.DriveMode_USER, false},
} }
for _, c := range cases { for _, c := range cases {
@ -169,7 +173,7 @@ func TestArduinoPart_Update(t *testing.T) {
if err != nil { if err != nil {
t.Error("unable to flush content") t.Error("unable to flush content")
} }
a.pwmThrottleConfig = c.throttlePwmConfig a.pwmThrottleConfig = c.throttlePwmConfig
time.Sleep(10 * time.Millisecond) time.Sleep(10 * time.Millisecond)