|
|
|
@ -36,9 +36,11 @@ func TestDefaultThrottle(t *testing.T) {
|
|
|
|
|
rcThrottleTopic := "topic/rcThrottle"
|
|
|
|
|
steeringTopic := "topic/rcThrottle"
|
|
|
|
|
throttleFeedbackTopic := "topic/feedback/throttle"
|
|
|
|
|
maxThrottleCtrlTopic := "topic/max/throttle"
|
|
|
|
|
speedZoneTopic := "topic/speedZone"
|
|
|
|
|
|
|
|
|
|
p := New(nil, throttleTopic, driveModeTopic, rcThrottleTopic, steeringTopic, throttleFeedbackTopic, speedZoneTopic, 1., 200)
|
|
|
|
|
p := New(nil, throttleTopic, driveModeTopic, rcThrottleTopic, steeringTopic, throttleFeedbackTopic,
|
|
|
|
|
maxThrottleCtrlTopic, speedZoneTopic, 1., 200)
|
|
|
|
|
|
|
|
|
|
cases := []*struct {
|
|
|
|
|
name string
|
|
|
|
@ -57,8 +59,8 @@ func TestDefaultThrottle(t *testing.T) {
|
|
|
|
|
{"test8", 1., events.DriveModeMessage{DriveMode: events.DriveMode_COPILOT}, events.ThrottleMessage{Throttle: 0.5, Confidence: 1.0}, events.ThrottleMessage{Throttle: 0.5, Confidence: 1.0}},
|
|
|
|
|
{"test9", 1., events.DriveModeMessage{DriveMode: events.DriveMode_COPILOT}, events.ThrottleMessage{Throttle: 0.4, Confidence: 1.0}, events.ThrottleMessage{Throttle: 0.4, Confidence: 1.0}},
|
|
|
|
|
{"test10", 1., events.DriveModeMessage{DriveMode: events.DriveMode_COPILOT}, events.ThrottleMessage{Throttle: 0.6, Confidence: 1.0}, events.ThrottleMessage{Throttle: 0.6, Confidence: 1.0}},
|
|
|
|
|
{"limit max throttle on user mode", 0.4, events.DriveModeMessage{DriveMode: events.DriveMode_USER}, events.ThrottleMessage{Throttle: 0.6, Confidence: 1.0}, events.ThrottleMessage{Throttle: 0.4, Confidence: 1.0}},
|
|
|
|
|
{"limit max throttle on copilot mode", 0.4, events.DriveModeMessage{DriveMode: events.DriveMode_COPILOT}, events.ThrottleMessage{Throttle: 0.6, Confidence: 1.0}, events.ThrottleMessage{Throttle: 0.4, Confidence: 1.0}},
|
|
|
|
|
{"rescale throttle on user mode", 0.4, events.DriveModeMessage{DriveMode: events.DriveMode_USER}, events.ThrottleMessage{Throttle: 0.6, Confidence: 1.0}, events.ThrottleMessage{Throttle: 0.24000001, Confidence: 1.0}},
|
|
|
|
|
{"rescale throttle on copilot mode", 0.4, events.DriveModeMessage{DriveMode: events.DriveMode_COPILOT}, events.ThrottleMessage{Throttle: 0.6, Confidence: 1.0}, events.ThrottleMessage{Throttle: 0.24000001, Confidence: 1.0}},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
go p.Start()
|
|
|
|
@ -121,11 +123,13 @@ func TestController_Start(t *testing.T) {
|
|
|
|
|
driveModeTopic := "topic/driveMode"
|
|
|
|
|
rcThrottleTopic := "topic/rcThrottle"
|
|
|
|
|
throttleFeedbackTopic := "topic/feedback/throttle"
|
|
|
|
|
maxThrottleCtrlTopic := "topic/max/throttle"
|
|
|
|
|
speedZoneTopic := "topic/speedZone"
|
|
|
|
|
|
|
|
|
|
type fields struct {
|
|
|
|
|
max types.Throttle
|
|
|
|
|
min types.Throttle
|
|
|
|
|
driveMode events.DriveMode
|
|
|
|
|
min, max types.Throttle
|
|
|
|
|
publishPilotFrequency int
|
|
|
|
|
brakeCtl brake.Controller
|
|
|
|
|
}
|
|
|
|
@ -134,6 +138,7 @@ func TestController_Start(t *testing.T) {
|
|
|
|
|
steering *events.SteeringMessage
|
|
|
|
|
rcThrottle *events.ThrottleMessage
|
|
|
|
|
throttleFeedback *events.ThrottleMessage
|
|
|
|
|
maxThrottleCtrl *events.ThrottleMessage
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
@ -146,22 +151,23 @@ func TestController_Start(t *testing.T) {
|
|
|
|
|
{
|
|
|
|
|
name: "On user drive mode, throttle from rc",
|
|
|
|
|
fields: fields{
|
|
|
|
|
driveMode: events.DriveMode_USER,
|
|
|
|
|
max: 0.8,
|
|
|
|
|
min: 0.3,
|
|
|
|
|
driveMode: events.DriveMode_USER,
|
|
|
|
|
publishPilotFrequency: publishPilotFrequency,
|
|
|
|
|
brakeCtl: &brake.DisabledController{},
|
|
|
|
|
},
|
|
|
|
|
msgEvents: msgEvents{
|
|
|
|
|
driveMode: &events.DriveModeMessage{DriveMode: events.DriveMode_USER},
|
|
|
|
|
steering: &events.SteeringMessage{Steering: 0.0, Confidence: 1.0},
|
|
|
|
|
rcThrottle: &events.ThrottleMessage{Throttle: 0.4, Confidence: 1.0},
|
|
|
|
|
rcThrottle: &events.ThrottleMessage{Throttle: 0.5, Confidence: 1.0},
|
|
|
|
|
throttleFeedback: &events.ThrottleMessage{Throttle: 0.4, Confidence: 1.0},
|
|
|
|
|
maxThrottleCtrl: &events.ThrottleMessage{Throttle: 0.8, Confidence: 1.0},
|
|
|
|
|
},
|
|
|
|
|
want: &events.ThrottleMessage{Throttle: 0.4, Confidence: 1.0},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "On user drive mode, limit throttle to max allowed value",
|
|
|
|
|
name: "On user drive mode, rescale throttle with max allowed value",
|
|
|
|
|
fields: fields{
|
|
|
|
|
driveMode: events.DriveMode_USER,
|
|
|
|
|
max: 0.8,
|
|
|
|
@ -174,8 +180,9 @@ func TestController_Start(t *testing.T) {
|
|
|
|
|
steering: &events.SteeringMessage{Steering: 0.0, Confidence: 1.0},
|
|
|
|
|
rcThrottle: &events.ThrottleMessage{Throttle: 0.9, Confidence: 1.0},
|
|
|
|
|
throttleFeedback: &events.ThrottleMessage{Throttle: 0.8, Confidence: 1.0},
|
|
|
|
|
maxThrottleCtrl: &events.ThrottleMessage{Throttle: 0.8, Confidence: 1.0},
|
|
|
|
|
},
|
|
|
|
|
want: &events.ThrottleMessage{Throttle: 0.8, Confidence: 1.0},
|
|
|
|
|
want: &events.ThrottleMessage{Throttle: 0.71999997, Confidence: 1.0},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "On user drive mode, throttle can be < to min allowed value",
|
|
|
|
@ -191,8 +198,27 @@ func TestController_Start(t *testing.T) {
|
|
|
|
|
steering: &events.SteeringMessage{Steering: 0.0, Confidence: 1.0},
|
|
|
|
|
rcThrottle: &events.ThrottleMessage{Throttle: 0.1, Confidence: 1.0},
|
|
|
|
|
throttleFeedback: &events.ThrottleMessage{Throttle: 0.4, Confidence: 1.0},
|
|
|
|
|
maxThrottleCtrl: &events.ThrottleMessage{Throttle: 0.8, Confidence: 1.0},
|
|
|
|
|
},
|
|
|
|
|
want: &events.ThrottleMessage{Throttle: 0.1, Confidence: 1.0},
|
|
|
|
|
want: &events.ThrottleMessage{Throttle: 0.080000006, Confidence: 1.0},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "On user drive mode, brake doesn't rescale throttle",
|
|
|
|
|
fields: fields{
|
|
|
|
|
driveMode: events.DriveMode_USER,
|
|
|
|
|
max: 0.8,
|
|
|
|
|
min: 0.3,
|
|
|
|
|
publishPilotFrequency: publishPilotFrequency,
|
|
|
|
|
brakeCtl: &brake.DisabledController{},
|
|
|
|
|
},
|
|
|
|
|
msgEvents: msgEvents{
|
|
|
|
|
driveMode: &events.DriveModeMessage{DriveMode: events.DriveMode_USER},
|
|
|
|
|
steering: &events.SteeringMessage{Steering: 0.0, Confidence: 1.0},
|
|
|
|
|
rcThrottle: &events.ThrottleMessage{Throttle: -0.8, Confidence: 1.0},
|
|
|
|
|
throttleFeedback: &events.ThrottleMessage{Throttle: 0.4, Confidence: 1.0},
|
|
|
|
|
maxThrottleCtrl: &events.ThrottleMessage{Throttle: 0.8, Confidence: 1.0},
|
|
|
|
|
},
|
|
|
|
|
want: &events.ThrottleMessage{Throttle: -0.8, Confidence: 1.0},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "On copilot drive mode, throttle from rc",
|
|
|
|
@ -206,11 +232,30 @@ func TestController_Start(t *testing.T) {
|
|
|
|
|
msgEvents: msgEvents{
|
|
|
|
|
driveMode: &events.DriveModeMessage{DriveMode: events.DriveMode_COPILOT},
|
|
|
|
|
steering: &events.SteeringMessage{Steering: 0.0, Confidence: 1.0},
|
|
|
|
|
rcThrottle: &events.ThrottleMessage{Throttle: 0.4, Confidence: 1.0},
|
|
|
|
|
rcThrottle: &events.ThrottleMessage{Throttle: 0.5, Confidence: 1.0},
|
|
|
|
|
throttleFeedback: &events.ThrottleMessage{Throttle: 0.4, Confidence: 1.0},
|
|
|
|
|
maxThrottleCtrl: &events.ThrottleMessage{Throttle: 0.8, Confidence: 1.0},
|
|
|
|
|
},
|
|
|
|
|
want: &events.ThrottleMessage{Throttle: 0.4, Confidence: 1.0},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "On copilot drive mode, rescale throttle with max allowed value",
|
|
|
|
|
fields: fields{
|
|
|
|
|
driveMode: events.DriveMode_COPILOT,
|
|
|
|
|
max: 0.8,
|
|
|
|
|
min: 0.3,
|
|
|
|
|
publishPilotFrequency: publishPilotFrequency,
|
|
|
|
|
brakeCtl: &brake.DisabledController{},
|
|
|
|
|
},
|
|
|
|
|
msgEvents: msgEvents{
|
|
|
|
|
driveMode: &events.DriveModeMessage{DriveMode: events.DriveMode_COPILOT},
|
|
|
|
|
steering: &events.SteeringMessage{Steering: 0.0, Confidence: 1.0},
|
|
|
|
|
rcThrottle: &events.ThrottleMessage{Throttle: 0.9, Confidence: 1.0},
|
|
|
|
|
throttleFeedback: &events.ThrottleMessage{Throttle: 0.8, Confidence: 1.0},
|
|
|
|
|
maxThrottleCtrl: &events.ThrottleMessage{Throttle: 0.8, Confidence: 1.0},
|
|
|
|
|
},
|
|
|
|
|
want: &events.ThrottleMessage{Throttle: 0.71999997, Confidence: 1.0},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "On copilot drive mode, limit throttle to max allowed value",
|
|
|
|
|
fields: fields{
|
|
|
|
@ -225,8 +270,9 @@ func TestController_Start(t *testing.T) {
|
|
|
|
|
steering: &events.SteeringMessage{Steering: 0.0, Confidence: 1.0},
|
|
|
|
|
rcThrottle: &events.ThrottleMessage{Throttle: 0.9, Confidence: 1.0},
|
|
|
|
|
throttleFeedback: &events.ThrottleMessage{Throttle: 0.8, Confidence: 1.0},
|
|
|
|
|
maxThrottleCtrl: &events.ThrottleMessage{Throttle: 0.8, Confidence: 1.0},
|
|
|
|
|
},
|
|
|
|
|
want: &events.ThrottleMessage{Throttle: 0.8, Confidence: 1.0},
|
|
|
|
|
want: &events.ThrottleMessage{Throttle: 0.71999997, Confidence: 1.0},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "On copilot drive mode, throttle can be < to min allowed value",
|
|
|
|
@ -242,8 +288,27 @@ func TestController_Start(t *testing.T) {
|
|
|
|
|
steering: &events.SteeringMessage{Steering: 0.0, Confidence: 1.0},
|
|
|
|
|
rcThrottle: &events.ThrottleMessage{Throttle: 0.1, Confidence: 1.0},
|
|
|
|
|
throttleFeedback: &events.ThrottleMessage{Throttle: 0.4, Confidence: 1.0},
|
|
|
|
|
maxThrottleCtrl: &events.ThrottleMessage{Throttle: 0.8, Confidence: 1.0},
|
|
|
|
|
},
|
|
|
|
|
want: &events.ThrottleMessage{Throttle: 0.1, Confidence: 1.0},
|
|
|
|
|
want: &events.ThrottleMessage{Throttle: 0.080000006, Confidence: 1.0},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "On user drive mode, brake doesn't rescale throttle",
|
|
|
|
|
fields: fields{
|
|
|
|
|
driveMode: events.DriveMode_COPILOT,
|
|
|
|
|
max: 0.8,
|
|
|
|
|
min: 0.3,
|
|
|
|
|
publishPilotFrequency: publishPilotFrequency,
|
|
|
|
|
brakeCtl: &brake.DisabledController{},
|
|
|
|
|
},
|
|
|
|
|
msgEvents: msgEvents{
|
|
|
|
|
driveMode: &events.DriveModeMessage{DriveMode: events.DriveMode_COPILOT},
|
|
|
|
|
steering: &events.SteeringMessage{Steering: 0.0, Confidence: 1.0},
|
|
|
|
|
rcThrottle: &events.ThrottleMessage{Throttle: -0.8, Confidence: 1.0},
|
|
|
|
|
throttleFeedback: &events.ThrottleMessage{Throttle: 0.4, Confidence: 1.0},
|
|
|
|
|
maxThrottleCtrl: &events.ThrottleMessage{Throttle: 0.8, Confidence: 1.0},
|
|
|
|
|
},
|
|
|
|
|
want: &events.ThrottleMessage{Throttle: -0.8, Confidence: 1.0},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "On pilot drive mode and straight steering, use max throttle allowed",
|
|
|
|
@ -259,6 +324,7 @@ func TestController_Start(t *testing.T) {
|
|
|
|
|
steering: &events.SteeringMessage{Steering: 0.0, Confidence: 1.0},
|
|
|
|
|
rcThrottle: &events.ThrottleMessage{Throttle: 0.5, Confidence: 1.0},
|
|
|
|
|
throttleFeedback: &events.ThrottleMessage{Throttle: 0.4, Confidence: 1.0},
|
|
|
|
|
maxThrottleCtrl: &events.ThrottleMessage{Throttle: 0.8, Confidence: 1.0},
|
|
|
|
|
},
|
|
|
|
|
want: &events.ThrottleMessage{Throttle: 0.8, Confidence: 1.0},
|
|
|
|
|
},
|
|
|
|
@ -276,6 +342,7 @@ func TestController_Start(t *testing.T) {
|
|
|
|
|
steering: &events.SteeringMessage{Steering: -1.0, Confidence: 1.0},
|
|
|
|
|
rcThrottle: &events.ThrottleMessage{Throttle: 0.3, Confidence: 1.0},
|
|
|
|
|
throttleFeedback: &events.ThrottleMessage{Throttle: 0.4, Confidence: 1.0},
|
|
|
|
|
maxThrottleCtrl: &events.ThrottleMessage{Throttle: 0.8, Confidence: 1.0},
|
|
|
|
|
},
|
|
|
|
|
want: &events.ThrottleMessage{Throttle: 0.3, Confidence: 1.0},
|
|
|
|
|
},
|
|
|
|
@ -293,6 +360,7 @@ func TestController_Start(t *testing.T) {
|
|
|
|
|
steering: &events.SteeringMessage{Steering: 1.0, Confidence: 1.0},
|
|
|
|
|
rcThrottle: &events.ThrottleMessage{Throttle: 0.3, Confidence: 1.0},
|
|
|
|
|
throttleFeedback: &events.ThrottleMessage{Throttle: 0.4, Confidence: 1.0},
|
|
|
|
|
maxThrottleCtrl: &events.ThrottleMessage{Throttle: 0.8, Confidence: 1.0},
|
|
|
|
|
},
|
|
|
|
|
want: &events.ThrottleMessage{Throttle: 0.3, Confidence: 1.0},
|
|
|
|
|
},
|
|
|
|
@ -310,6 +378,7 @@ func TestController_Start(t *testing.T) {
|
|
|
|
|
steering: &events.SteeringMessage{Steering: -1.0, Confidence: 1.0},
|
|
|
|
|
rcThrottle: &events.ThrottleMessage{Throttle: 0.3, Confidence: 1.0},
|
|
|
|
|
throttleFeedback: &events.ThrottleMessage{Throttle: 1.0, Confidence: 1.0},
|
|
|
|
|
maxThrottleCtrl: &events.ThrottleMessage{Throttle: 0.8, Confidence: 1.0},
|
|
|
|
|
},
|
|
|
|
|
want: &events.ThrottleMessage{Throttle: -1.0, Confidence: 1.0},
|
|
|
|
|
},
|
|
|
|
@ -319,7 +388,7 @@ func TestController_Start(t *testing.T) {
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
c := New(nil,
|
|
|
|
|
throttleTopic, driveModeTopic, rcThrottleTopic, steeringTopic, throttleFeedbackTopic,
|
|
|
|
|
speedZoneTopic, tt.fields.max,
|
|
|
|
|
maxThrottleCtrlTopic, speedZoneTopic, tt.fields.max,
|
|
|
|
|
tt.fields.publishPilotFrequency,
|
|
|
|
|
WithThrottleProcessor(&SteeringProcessor{
|
|
|
|
|
minThrottle: tt.fields.min,
|
|
|
|
@ -338,6 +407,7 @@ func TestController_Start(t *testing.T) {
|
|
|
|
|
c.onRCThrottle(nil, testtools.NewFakeMessageFromProtobuf(rcThrottleTopic, tt.msgEvents.rcThrottle))
|
|
|
|
|
c.onSteering(nil, testtools.NewFakeMessageFromProtobuf(steeringTopic, tt.msgEvents.steering))
|
|
|
|
|
c.onThrottleFeedback(nil, testtools.NewFakeMessageFromProtobuf(throttleFeedbackTopic, tt.msgEvents.throttleFeedback))
|
|
|
|
|
c.onMaxThrottleCtrl(nil, testtools.NewFakeMessageFromProtobuf(maxThrottleCtrlTopic, tt.msgEvents.maxThrottleCtrl))
|
|
|
|
|
waitPublish.Wait()
|
|
|
|
|
|
|
|
|
|
var msg events.ThrottleMessage
|
|
|
|
|