SteeringAngleCorrection.emam 1002 Bytes
Newer Older
Jean-Marc Ronck's avatar
Jean-Marc Ronck committed
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
package de.rwth.armin.modeling.autopilot.motion;

component SteeringAngleCorrection {
  port
    in Q signedDistanceToTrajectory,
    out Q steeringAngleCorrection;

  implementation Math {
    // TODO convert into parameter when parameters start working (bug #28)
    static Q MAX_STEERING_ANGLE = 0.785;
    static Q EPSILON = 0.01;
    // exponent params
    static Q X1 = 0.1;
    static Q Y1 = 0.01 * MAX_STEERING_ANGLE;
    static Q X2 = 5.0;
    static Q Y2 = 0.05 * MAX_STEERING_ANGLE;
    static Q COEF_K = log( (Y1 / Y2) ) / (X2 - X1);

    steeringAngleCorrection = 0.0;

    Q dist = abs(signedDistanceToTrajectory);
    if (dist > EPSILON)
      if (dist < X1)
        steeringAngleCorrection = Y1;
      elseif (dist > X2)
        steeringAngleCorrection = Y2;
      else
        steeringAngleCorrection = Y1 * exp(-COEF_K * (dist - X1));
      end
      // take sign into account
      if (signedDistanceToTrajectory < 0)
        steeringAngleCorrection *= -1.0;
      end
    end
  }
}