Refactor logs

This commit is contained in:
2020-02-03 19:15:51 +01:00
parent 5e9b47970a
commit dca1c25f11
5 changed files with 27 additions and 19 deletions

View File

@ -1,7 +1,7 @@
package actuator
import (
"log"
log "github.com/sirupsen/logrus"
"periph.io/x/periph/conn/i2c/i2creg"
"periph.io/x/periph/conn/physic"
"periph.io/x/periph/experimental/devices/pca9685"
@ -13,27 +13,27 @@ var (
)
func init() {
log.Print("init pca9685 controller")
log.Info("init pca9685 controller")
_, err := host.Init()
if err != nil {
log.Fatalf("unable to init host: %v", err)
}
log.Print("open i2c bus")
log.Info("open i2c bus")
bus, err := i2creg.Open("")
if err != nil {
log.Fatalf("unable to init i2c bus: %v", err)
}
log.Print("i2c bus opened")
log.Info("i2c bus opened")
device, err = pca9685.NewI2C(bus, pca9685.I2CAddr)
if err != nil {
log.Fatalf("unable to init pca9685 bus: %v", err)
}
log.Printf("set pwm frequency to %d", 60)
log.Infof("set pwm frequency to %d", 60)
err = device.SetPwmFreq(60 * physic.Hertz)
if err != nil {
log.Fatalf("unable to set pwm frequency: %v", err)
log.Panicf("unable to set pwm frequency: %v", err)
}
log.Print("init done")
log.Info("init done")
}

View File

@ -21,7 +21,7 @@ type Steering struct {
func (s *Steering) SetPulse(pulse int) {
err := s.dev.SetPwm(s.channel, 0, gpio.Duty(pulse))
if err != nil {
log.Infof("unable to set throttle pwm value: %v", err)
log.Warningf("unable to set steering pwm value: %v", err)
}
}

View File

@ -34,6 +34,7 @@ func (t *Throttle) SetPercentValue(p float32) {
} else {
pulse = util.MapRange(float64(p), MinThrottle, 0, float64(t.minPulse), float64(t.zeroPulse))
}
log.Debugf("set throttle to %v-> %v (%v, %v, %v, %v, %v)", p, pulse, LeftAngle, RightAngle, t.minPulse, t.maxPulse, t.zeroPulse)
t.SetPulse(pulse)
}
@ -46,7 +47,7 @@ func NewThrottle(channel, zeroPulse, minPulse, maxPulse int) *Throttle {
maxPulse: maxPulse,
}
log.Printf("send zero pulse to calibrate ESC: %v", zeroPulse)
log.Infof("send zero pulse to calibrate ESC")
t.SetPulse(zeroPulse)
return &t