fix(steering): reverse direction
This commit is contained in:
parent
f046bead37
commit
0d183e0f0b
@ -128,6 +128,7 @@ func main() {
|
|||||||
dev,
|
dev,
|
||||||
throttleChannel,
|
throttleChannel,
|
||||||
actuator.PWM(throttleMinPWM), actuator.PWM(throttleMaxPWM), actuator.PWM(throttleStoppedPWM),
|
actuator.PWM(throttleMinPWM), actuator.PWM(throttleMaxPWM), actuator.PWM(throttleStoppedPWM),
|
||||||
|
-1., 1.,
|
||||||
freq,
|
freq,
|
||||||
zap.S().With("actuator", "throttle"),
|
zap.S().With("actuator", "throttle"),
|
||||||
)
|
)
|
||||||
@ -139,6 +140,7 @@ func main() {
|
|||||||
dev,
|
dev,
|
||||||
steeringChannel,
|
steeringChannel,
|
||||||
actuator.PWM(steeringLeftPWM), actuator.PWM(steeringRightPWM), actuator.PWM(steeringCenterPWM),
|
actuator.PWM(steeringLeftPWM), actuator.PWM(steeringRightPWM), actuator.PWM(steeringCenterPWM),
|
||||||
|
1., -1.,
|
||||||
freq,
|
freq,
|
||||||
zap.S().With("actuator", "steering"),
|
zap.S().With("actuator", "steering"),
|
||||||
)
|
)
|
||||||
|
@ -49,9 +49,9 @@ func (c *Pca9685Controller) convertToDuty(percent float32) (gpio.Duty, error) {
|
|||||||
// map absolute angle to angle that vehicle can implement.
|
// map absolute angle to angle that vehicle can implement.
|
||||||
pw := int(c.neutralPWM)
|
pw := int(c.neutralPWM)
|
||||||
if percent > 0 {
|
if percent > 0 {
|
||||||
pw = util.MapRange(float64(percent), 0, MaxPercent, float64(c.neutralPWM), float64(c.maxPWM))
|
pw = util.MapRange(float64(percent), 0, c.maxPercent, float64(c.neutralPWM), float64(c.maxPWM))
|
||||||
} else if percent < 0 {
|
} else if percent < 0 {
|
||||||
pw = util.MapRange(float64(percent), MinPercent, 0, float64(c.minPWM), float64(c.neutralPWM))
|
pw = util.MapRange(float64(percent), c.minPercent, 0, float64(c.minPWM), float64(c.neutralPWM))
|
||||||
}
|
}
|
||||||
c.logr.Debugf("convert value %v to pw: %v", percent, pw)
|
c.logr.Debugf("convert value %v to pw: %v", percent, pw)
|
||||||
|
|
||||||
@ -59,20 +59,13 @@ func (c *Pca9685Controller) convertToDuty(percent float32) (gpio.Duty, error) {
|
|||||||
|
|
||||||
draw := float64(pw) / float64(per)
|
draw := float64(pw) / float64(per)
|
||||||
return gpio.Duty(int32(draw * float64(gpio.DutyMax))), nil
|
return gpio.Duty(int32(draw * float64(gpio.DutyMax))), nil
|
||||||
/*
|
|
||||||
d, err := gpio.ParseDuty(strconv.Itoa(int(dd)))
|
|
||||||
// d, err := gpio.ParseDuty(fmt.Sprintf("%.f%%", draw*100))
|
|
||||||
if err != nil {
|
|
||||||
return 0, fmt.Errorf("unable to parse duty, probably bad compute: %w", err)
|
|
||||||
}
|
|
||||||
return d, nil
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Pca9685Controller struct {
|
type Pca9685Controller struct {
|
||||||
logr *zap.SugaredLogger
|
logr *zap.SugaredLogger
|
||||||
pin gpio.PinIO
|
pin gpio.PinIO
|
||||||
minPWM, maxPWM, neutralPWM PWM
|
minPWM, maxPWM, neutralPWM PWM
|
||||||
|
minPercent, maxPercent float64
|
||||||
freq physic.Frequency
|
freq physic.Frequency
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,7 +96,8 @@ func (c *Pca9685Controller) SetPercentValue(p float32) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPca9685Controller(device *pca9685.Dev, channel int, minPWM, maxPWM, neutralPWM PWM, freq physic.Frequency, logr *zap.SugaredLogger) (*Pca9685Controller, error) {
|
func NewPca9685Controller(device *pca9685.Dev, channel int, minPWM, maxPWM, neutralPWM PWM, minPercent, maxPercent float64,
|
||||||
|
freq physic.Frequency, logr *zap.SugaredLogger) (*Pca9685Controller, error) {
|
||||||
p, err := device.CreatePin(channel)
|
p, err := device.CreatePin(channel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to create pin for channel %v: %w", channel, err)
|
return nil, fmt.Errorf("unable to create pin for channel %v: %w", channel, err)
|
||||||
@ -113,6 +107,8 @@ func NewPca9685Controller(device *pca9685.Dev, channel int, minPWM, maxPWM, neut
|
|||||||
minPWM: minPWM,
|
minPWM: minPWM,
|
||||||
maxPWM: maxPWM,
|
maxPWM: maxPWM,
|
||||||
neutralPWM: neutralPWM,
|
neutralPWM: neutralPWM,
|
||||||
|
minPercent: minPercent,
|
||||||
|
maxPercent: maxPercent,
|
||||||
freq: freq,
|
freq: freq,
|
||||||
logr: logr,
|
logr: logr,
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ func Test_convertToDuty(t *testing.T) {
|
|||||||
centerPWM: 1500,
|
centerPWM: 1500,
|
||||||
freq: 60 * physic.Hertz,
|
freq: 60 * physic.Hertz,
|
||||||
},
|
},
|
||||||
want: "6%",
|
want: "12%",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "right",
|
name: "right",
|
||||||
@ -59,7 +59,7 @@ func Test_convertToDuty(t *testing.T) {
|
|||||||
centerPWM: 1500,
|
centerPWM: 1500,
|
||||||
freq: 60 * physic.Hertz,
|
freq: 60 * physic.Hertz,
|
||||||
},
|
},
|
||||||
want: "12%",
|
want: "6%",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
@ -71,6 +71,8 @@ func Test_convertToDuty(t *testing.T) {
|
|||||||
maxPWM: tt.args.rightPWM,
|
maxPWM: tt.args.rightPWM,
|
||||||
neutralPWM: tt.args.centerPWM,
|
neutralPWM: tt.args.centerPWM,
|
||||||
freq: tt.args.freq,
|
freq: tt.args.freq,
|
||||||
|
minPercent: 1.,
|
||||||
|
maxPercent: -1,
|
||||||
}
|
}
|
||||||
|
|
||||||
if got, err := c.convertToDuty(tt.args.percent); got.String() != tt.want {
|
if got, err := c.convertToDuty(tt.args.percent); got.String() != tt.want {
|
||||||
|
Loading…
Reference in New Issue
Block a user