robocar-throttle/pkg/throttle/processor.go

17 lines
425 B
Go
Raw Normal View History

package throttle
2022-09-05 13:30:26 +00:00
import (
"github.com/cyrilix/robocar-throttle/pkg/types"
"math"
)
type SteeringProcessor struct {
2022-09-05 13:30:26 +00:00
minThrottle, maxThrottle types.Throttle
}
// Process compute throttle from steering value
2022-09-05 13:30:26 +00:00
func (sp *SteeringProcessor) Process(steering float32) types.Throttle {
absSteering := math.Abs(float64(steering))
2022-09-05 13:30:26 +00:00
return sp.minThrottle + types.Throttle(float64(sp.maxThrottle-sp.minThrottle)*(1-absSteering))
}