Compare commits
2 Commits
a7babb862b
...
e6a5d6f781
Author | SHA1 | Date | |
---|---|---|---|
e6a5d6f781 | |||
9100cedb38 |
@ -1,4 +1,4 @@
|
|||||||
FROM --platform=$BUILDPLATFORM golang:1.17-alpine AS builder
|
FROM --platform=$BUILDPLATFORM golang:1.19-alpine AS builder
|
||||||
|
|
||||||
ARG TARGETPLATFORM
|
ARG TARGETPLATFORM
|
||||||
ARG BUILDPLATFORM
|
ARG BUILDPLATFORM
|
||||||
|
2
go.mod
2
go.mod
@ -1,6 +1,6 @@
|
|||||||
module github.com/cyrilix/robocar-steering
|
module github.com/cyrilix/robocar-steering
|
||||||
|
|
||||||
go 1.18
|
go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/cyrilix/robocar-base v0.1.7
|
github.com/cyrilix/robocar-base v0.1.7
|
||||||
|
2
go.sum
2
go.sum
@ -2,8 +2,6 @@ github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLj
|
|||||||
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
|
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
|
||||||
github.com/cyrilix/robocar-base v0.1.7 h1:EVzZ0KjigSFpke5f3A/PybEH3WFUEIrYSc3z/dhOZ48=
|
github.com/cyrilix/robocar-base v0.1.7 h1:EVzZ0KjigSFpke5f3A/PybEH3WFUEIrYSc3z/dhOZ48=
|
||||||
github.com/cyrilix/robocar-base v0.1.7/go.mod h1:4E11HQSNy2NT8e7MW188y6ST9C0RzarKyn7sK/3V/Lk=
|
github.com/cyrilix/robocar-base v0.1.7/go.mod h1:4E11HQSNy2NT8e7MW188y6ST9C0RzarKyn7sK/3V/Lk=
|
||||||
github.com/cyrilix/robocar-protobuf/go v1.0.5 h1:PX1At+pf6G7gJwT4LzJLQu3/LPFTTNNlZmZSYtnSELY=
|
|
||||||
github.com/cyrilix/robocar-protobuf/go v1.0.5/go.mod h1:Y3AE28K5V7EZxMXp/6A8RhkRz15VOfFy4CjST35FbtQ=
|
|
||||||
github.com/cyrilix/robocar-protobuf/go v1.1.0 h1:txIjGnnCF3UzedpsWu+sL7nMA+pNjSnX6HZlAmuReH4=
|
github.com/cyrilix/robocar-protobuf/go v1.1.0 h1:txIjGnnCF3UzedpsWu+sL7nMA+pNjSnX6HZlAmuReH4=
|
||||||
github.com/cyrilix/robocar-protobuf/go v1.1.0/go.mod h1:Y3AE28K5V7EZxMXp/6A8RhkRz15VOfFy4CjST35FbtQ=
|
github.com/cyrilix/robocar-protobuf/go v1.1.0/go.mod h1:Y3AE28K5V7EZxMXp/6A8RhkRz15VOfFy4CjST35FbtQ=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
type Corrector struct {
|
type Corrector struct {
|
||||||
gridMap *GridMap
|
gridMap *GridMap
|
||||||
|
objectMoveFactors *GridMap
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -43,6 +44,8 @@ AdjustFromObjectPosition modify steering value according object positions
|
|||||||
func (c *Corrector) AdjustFromObjectPosition(currentSteering float64, objects []*events.Object) float64 {
|
func (c *Corrector) AdjustFromObjectPosition(currentSteering float64, objects []*events.Object) float64 {
|
||||||
// TODO, group rectangle
|
// TODO, group rectangle
|
||||||
|
|
||||||
|
var deltaMiddle = 0.1
|
||||||
|
|
||||||
if len(objects) == 0 {
|
if len(objects) == 0 {
|
||||||
return currentSteering
|
return currentSteering
|
||||||
}
|
}
|
||||||
@ -53,9 +56,55 @@ func (c *Corrector) AdjustFromObjectPosition(currentSteering float64, objects []
|
|||||||
return currentSteering
|
return currentSteering
|
||||||
}
|
}
|
||||||
|
|
||||||
if currentSteering > -0.1 && currentSteering < 0.1 {
|
if currentSteering > -1*deltaMiddle && currentSteering < deltaMiddle {
|
||||||
|
// Straight
|
||||||
|
return currentSteering + c.computeDeviation(currentSteering, nearest)
|
||||||
|
}
|
||||||
|
|
||||||
|
if currentSteering < -1*deltaMiddle {
|
||||||
|
// Turn to left, so search to avoid collision with objects on the left
|
||||||
|
// Apply factor to object to move it at middle. This factor is function of distance
|
||||||
|
factor, err := c.objectMoveFactors.ValueOf(float64(nearest.Left), float64(nearest.Bottom))
|
||||||
|
if err != nil {
|
||||||
|
zap.S().Warnf("unable to compute factor to apply to object: %v", err)
|
||||||
|
return currentSteering
|
||||||
|
}
|
||||||
|
objMoved := events.Object{
|
||||||
|
Type: nearest.Type,
|
||||||
|
Left: nearest.Left * float32(factor),
|
||||||
|
Top: nearest.Top,
|
||||||
|
Right: nearest.Right * float32(factor),
|
||||||
|
Bottom: nearest.Bottom,
|
||||||
|
Confidence: nearest.Confidence,
|
||||||
|
}
|
||||||
|
return currentSteering + c.computeDeviation(currentSteering, &objMoved)
|
||||||
|
}
|
||||||
|
|
||||||
|
if currentSteering > deltaMiddle {
|
||||||
|
// Turn to right, so search to avoid collision with objects on the right
|
||||||
|
// Apply factor to object to move it at middle. This factor is function of distance
|
||||||
|
factor, err := c.objectMoveFactors.ValueOf(float64(nearest.Left), float64(nearest.Bottom))
|
||||||
|
if err != nil {
|
||||||
|
zap.S().Warnf("unable to compute factor to apply to object: %v", err)
|
||||||
|
return currentSteering
|
||||||
|
}
|
||||||
|
objMoved := events.Object{
|
||||||
|
Type: nearest.Type,
|
||||||
|
Left: nearest.Left * float32(factor),
|
||||||
|
Top: nearest.Top,
|
||||||
|
Right: nearest.Right * float32(factor),
|
||||||
|
Bottom: nearest.Bottom,
|
||||||
|
Confidence: nearest.Confidence,
|
||||||
|
}
|
||||||
|
return currentSteering + c.computeDeviation(currentSteering, &objMoved)
|
||||||
|
}
|
||||||
|
|
||||||
|
return currentSteering
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Corrector) computeDeviation(currentSteering float64, nearest *events.Object) float64 {
|
||||||
var delta float64
|
var delta float64
|
||||||
|
var err error
|
||||||
|
|
||||||
if nearest.Left < 0 && nearest.Right < 0 {
|
if nearest.Left < 0 && nearest.Right < 0 {
|
||||||
delta, err = c.gridMap.ValueOf(float64(nearest.Right)*2-1., float64(nearest.Bottom))
|
delta, err = c.gridMap.ValueOf(float64(nearest.Right)*2-1., float64(nearest.Bottom))
|
||||||
@ -70,11 +119,6 @@ func (c *Corrector) AdjustFromObjectPosition(currentSteering float64, objects []
|
|||||||
delta = 0
|
delta = 0
|
||||||
}
|
}
|
||||||
return currentSteering + delta
|
return currentSteering + delta
|
||||||
}
|
|
||||||
|
|
||||||
// Search if current steering is near of Right or Left
|
|
||||||
|
|
||||||
return currentSteering
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Corrector) nearObject(objects []*events.Object) (*events.Object, error) {
|
func (c *Corrector) nearObject(objects []*events.Object) (*events.Object, error) {
|
||||||
|
@ -39,6 +39,22 @@ var (
|
|||||||
Bottom: 0.9,
|
Bottom: 0.9,
|
||||||
Confidence: 0.9,
|
Confidence: 0.9,
|
||||||
}
|
}
|
||||||
|
objectOnRightNear = events.Object{
|
||||||
|
Type: events.TypeObject_ANY,
|
||||||
|
Left: 0.7,
|
||||||
|
Top: 0.8,
|
||||||
|
Right: 0.9,
|
||||||
|
Bottom: 0.9,
|
||||||
|
Confidence: 0.9,
|
||||||
|
}
|
||||||
|
objectOnLeftNear = events.Object{
|
||||||
|
Type: events.TypeObject_ANY,
|
||||||
|
Left: 0.1,
|
||||||
|
Top: 0.8,
|
||||||
|
Right: 0.3,
|
||||||
|
Bottom: 0.9,
|
||||||
|
Confidence: 0.9,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -53,6 +69,17 @@ var (
|
|||||||
{0.25, 0.5, 1, -1, -0.5, -0.25},
|
{0.25, 0.5, 1, -1, -0.5, -0.25},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
defaultObjectFactors = GridMap{
|
||||||
|
DistanceSteps: []float64{0., 0.2, 0.4, 0.6, 0.8, 1.},
|
||||||
|
SteeringSteps: []float64{-1., -0.66, -0.33, 0., 0.33, 0.66, 1.},
|
||||||
|
Data: [][]float64{
|
||||||
|
{0., 0., 0., 0., 0., 0.},
|
||||||
|
{0., 0., 0., 0., 0., 0.},
|
||||||
|
{0., 0., 0.25, -0.25, 0., 0.},
|
||||||
|
{0., 0.25, 0.5, -0.5, -0.25, 0.},
|
||||||
|
{0.25, 0.5, 1, -1, -0.5, -0.25},
|
||||||
|
},
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCorrector_AdjustFromObjectPosition(t *testing.T) {
|
func TestCorrector_AdjustFromObjectPosition(t *testing.T) {
|
||||||
@ -128,7 +155,7 @@ func TestCorrector_AdjustFromObjectPosition(t *testing.T) {
|
|||||||
currentSteering: -0.9,
|
currentSteering: -0.9,
|
||||||
objects: []*events.Object{&objectOnMiddleNear},
|
objects: []*events.Object{&objectOnMiddleNear},
|
||||||
},
|
},
|
||||||
want: -0.4,
|
want: -0.9,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "run to right with 1 near object",
|
name: "run to right with 1 near object",
|
||||||
@ -136,10 +163,24 @@ func TestCorrector_AdjustFromObjectPosition(t *testing.T) {
|
|||||||
currentSteering: 0.9,
|
currentSteering: 0.9,
|
||||||
objects: []*events.Object{&objectOnMiddleNear},
|
objects: []*events.Object{&objectOnMiddleNear},
|
||||||
},
|
},
|
||||||
want: 0.4,
|
want: 0.9,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "run to right with 1 near object on the right",
|
||||||
|
args: args{
|
||||||
|
currentSteering: 0.9,
|
||||||
|
objects: []*events.Object{&objectOnRightNear},
|
||||||
|
},
|
||||||
|
want: 0.1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "run to left with 1 near object on the left",
|
||||||
|
args: args{
|
||||||
|
currentSteering: -0.9,
|
||||||
|
objects: []*events.Object{&objectOnLeftNear},
|
||||||
|
},
|
||||||
|
want: -0.1,
|
||||||
},
|
},
|
||||||
|
|
||||||
// Todo Object on left/right near/distant
|
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user