2 from math import pi, cos, sin, atan
5 WHEELBASE = 2.895 # JUPITER (Porsche Cayenne)
9 return (0 < x) - (x < 0)
20 def pose_on_circle_given_by(angle, mtr, wa, x0, y0, angle0):
21 """Return pose on circle based on parameters:
23 :param angle: Angle from circle center in degrees, probably -90 to +90.
24 :param mtr: Minimum turning radius.
25 :param wa: Wheel angle to be in resulting pose in degrees.
26 :param x0: How much shift resulting x coordinate.
27 :param y0: How much shift resulting y coordinate.
28 :param angle0: How much shift resulting heading from requested angle.
30 x = mtr * cos(dtor(angle)) + x0
31 y = mtr * sin(dtor(angle)) + y0
32 h = dtor(angle + angle0)
33 wa = atan(WHEELBASE / mtr) * sgn(angle0)
34 return [x, y, h, 1, rtod(wa), False]
37 def poses_on_circle(*, from_angle, to_angle, by_angle, **kwargs):
38 def should_continue(a, to_a):
39 if from_angle < to_angle:
45 while should_continue(angle, to_angle):
46 poses.append(pose_on_circle_given_by(angle, **kwargs))
51 def swap_to_second_half_of(oval):
52 oval["from_angle"] += 180
53 oval["to_angle"] += 180
58 def gen_path_of(oval):
60 path.append([0, 0, 0, 1, 0, True])
61 path.append([oval["x0"], 0, 0, 1, 0, False])
62 path += poses_on_circle(**oval)
63 swap_to_second_half_of(oval)
64 path.append([oval["x0"], 2 * oval["y0"], pi, 1, 0, False])
65 path += poses_on_circle(**oval)
66 path.append([0, 0, 0, 1, 0, False])
96 "y0": -3.984628, # eq. mtr
105 "y0": 3.984628, # eq. mtr
110 if __name__ == "__main__":
111 with open("oval-mtr-min-to-left.json", "w") as f:
114 "path": gen_path_of(OVAL["mtr_min_left"]),
115 "ispath": [[0, 0, 0, 0, False]]}, f, indent="\t")
116 with open("oval-mtr-min-to-right.json", "w") as f:
119 "path": gen_path_of(OVAL["mtr_min_right"]),
120 "ispath": [[0, 0, 0, 0, False]]}, f, indent="\t")
121 with open("oval-mtr-5-to-left.json", "w") as f:
124 "path": gen_path_of(OVAL["mtr_5_left"]),
125 "ispath": [[0, 0, 0, 0, False]]}, f, indent="\t")
126 with open("oval-mtr-5-to-right.json", "w") as f:
129 "path": gen_path_of(OVAL["mtr_5_right"]),
130 "ispath": [[0, 0, 0, 0, False]]}, f, indent="\t")