forked from VDrift/vdrift
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontrol.um
66 lines (53 loc) · 1.24 KB
/
control.um
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import (
"std.um"
"mat.um"
"track.um"
)
const deg = std.pi / 180.0
const (
INPUT_THROTTLE = 0
INPUT_NOS
INPUT_BRAKE
INPUT_HANDBRAKE
INPUT_CLUTCH
INPUT_STEER_LEFT
INPUT_STEER_RIGHT
INPUT_SHIFT_UP
INPUT_SHIFT_DOWN
INPUT_START_ENGINE
INPUT_ABS_TOGGLE
INPUT_TCS_TOGGLE
INPUT_NEUTRAL
INPUT_FIRST_GEAR
INPUT_SECOND_GEAR
INPUT_THIRD_GEAR
INPUT_FOURTH_GEAR
INPUT_FIFTH_GEAR
INPUT_SIXTH_GEAR
INPUT_REVERSE
INPUT_ROLLOVER
INPUT_INVALID
)
throttle := 0.0
// Tested on a Mini Cooper on Le Mans track
fn update(dt: real, pos, vel: ^mat.Vec, attMat: ^mat.Mat, rate: ^mat.Vec, patch: track.PatchHandle, inputs: ^[INPUT_INVALID]real32): bool {
att := attMat.toAttAngles()
lookahead := 1
var patchData: track.PatchData
if !track.getPatchData(patch, 1, &patchData) {
return false
}
xTrackErr := patchData.getXTrackErr(pos, 1)
hdgErr := patchData.getHdgErr(pos, &att, 1)
xTrackErrGain := 0.5
hdgErrGain := 1.5
targetSpeed := 20.0
throttle += dt / 3.0 * (targetSpeed - vel.norm())
if throttle < 0.0 {throttle = 0.0}
if throttle > 0.5 {throttle = 0.5}
inputs[INPUT_THROTTLE] = throttle
inputs[INPUT_STEER_RIGHT] = -xTrackErrGain * xTrackErr - hdgErrGain * hdgErr
printf(repr(xTrackErr) + repr(hdgErr) + '\n')
return true
}
fn main() {}