Fix car integration

This commit is contained in:
Cyrille Nofficial 2020-02-03 19:16:07 +01:00
parent dca1c25f11
commit 932e447cf1
3 changed files with 6 additions and 17 deletions

View File

@ -34,11 +34,11 @@ func (s *Steering) SetPercentValue(p float32) {
} }
func NewSteering(channel, leftPWM, rightPWM int) *Steering { func NewSteering(channel, leftPWM, rightPWM int) *Steering {
t := Steering{ s := Steering{
channel: channel, channel: channel,
dev: device, dev: device,
leftPWM: leftPWM, leftPWM: leftPWM,
rightPWM: rightPWM, rightPWM: rightPWM,
} }
return &t return &s
} }

View File

@ -48,7 +48,7 @@ func NewThrottle(channel, zeroPulse, minPulse, maxPulse int) *Throttle {
} }
log.Infof("send zero pulse to calibrate ESC") log.Infof("send zero pulse to calibrate ESC")
t.SetPulse(zeroPulse) t.SetPercentValue(0)
return &t return &t
} }

View File

@ -9,7 +9,6 @@ import (
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"sync" "sync"
"time"
) )
type Pca9685Part struct { type Pca9685Part struct {
@ -46,12 +45,12 @@ func (p *Pca9685Part) Start() error {
if err := p.registerCallbacks(); err != nil { if err := p.registerCallbacks(); err != nil {
return fmt.Errorf("unable to start service: %v", err) return fmt.Errorf("unable to start service: %v", err)
} }
ticker := time.NewTicker(time.Second / time.Duration(p.updateFrequency))
p.steeringCtrl.SetPercentValue(0)
p.throttleCtrl.SetPercentValue(0)
for { for {
select { select {
case <-ticker.C:
p.updateCtrl()
case <-p.cancel: case <-p.cancel:
return nil return nil
} }
@ -101,13 +100,3 @@ func (p *Pca9685Part) registerCallbacks() error {
return nil return nil
} }
func (p *Pca9685Part) updateCtrl() {
p.muThrottle.Lock()
defer p.muThrottle.Unlock()
p.throttleCtrl.SetPercentValue(p.throttleValue)
p.muSteering.Lock()
defer p.muSteering.Unlock()
p.steeringCtrl.SetPercentValue(p.steeringValue)
}