1+ """
2+ @file: common_examples.py
3+ @breif: Examples of Python Motion Planning library
4+ @author: Wu Maojia
5+ @update: 2024.11.22
6+ """
7+ import sys , os
8+ sys .path .append (os .path .dirname (os .path .dirname (os .path .abspath (__file__ ))))
19from python_motion_planning import *
210
3- # -------------global planners-------------
4- # plt = AStar(start=(5, 5), goal=(45, 25), env=Grid(51, 31))
5- # plt = DStar(start=(5, 5), goal=(45, 25), env=Grid(51, 31))
6- # plt = DStarLite(start=(5, 5), goal=(45, 25), env=Grid(51, 31))
7- # plt = Dijkstra(start=(5, 5), goal=(45, 25), env=Grid(51, 31))
8- # plt = GBFS(start=(5, 5), goal=(45, 25), env=Grid(51, 31))
9- # plt = JPS(start=(5, 5), goal=(45, 25), env=Grid(51, 31))
10- # plt = ThetaStar(start=(5, 5), goal=(45, 25), env=Grid(51, 31))
11- # plt = LazyThetaStar(start=(5, 5), goal=(45, 25), env=Grid(51, 31))
12- # plt = SThetaStar(start=(5, 5), goal=(45, 25), env=Grid(51, 31))
13- # plt = LPAStar(start=(5, 5), goal=(45, 25), env=Grid(51, 31))
14- # plt = VoronoiPlanner(start=(5, 5), goal=(45, 25), env=Grid(51, 31))
15-
16- # plt = RRT(start=(18, 8), goal=(37, 18), env=Map(51, 31))
17- # plt = RRTConnect(start=(18, 8), goal=(37, 18), env=Map(51, 31))
18- # plt = RRTStar(start=(18, 8), goal=(37, 18), env=Map(51, 31))
19- # plt = InformedRRT(start=(18, 8), goal=(37, 18), env=Map(51, 31))
20-
21- # plt = ACO(start=(5, 5), goal=(45, 25), env=Grid(51, 31))
22- # plt = PSO(start=(5, 5), goal=(45, 25), env=Grid(51, 31))
23-
24- # plt.run()
25-
26- # -------------local planners-------------
27- # plt = PID(start=(5, 5, 0), goal=(45, 25, 0), env=Grid(51, 31))
28- # plt = DWA(start=(5, 5, 0), goal=(45, 25, 0), env=Grid(51, 31))
29- # plt = APF(start=(5, 5, 0), goal=(45, 25, 0), env=Grid(51, 31))
30- # plt = LQR(start=(5, 5, 0), goal=(45, 25, 0), env=Grid(51, 31))
31- # plt = RPP(start=(5, 5, 0), goal=(45, 25, 0), env=Grid(51, 31))
32- # plt = MPC(start=(5, 5, 0), goal=(45, 25, 0), env=Grid(51, 31))
33- # plt.run()
34-
35-
36- # Train the model, only for learning-based planners, such as DDPG
37- # It costs a lot of time to train the model, please be patient.
38- # If you want a faster training, try reducing num_episodes and batch_size,
39- # or increasing update_steps and evaluate_episodes, or fine-tuning other hyperparameters
40- # if you are familiar with them, usually in a cost of performance, however.
41- # plt = DDPG(start=(5, 5, 0), goal=(45, 25, 0), env=Grid(51, 31),
42- # actor_save_path="models/actor_best.pth", critic_save_path="models/critic_best.pth")
43- # plt.train(num_episodes=10000)
44-
45- # load the trained model and run
46- plt = DDPG (start = (5 , 5 , 0 ), goal = (45 , 25 , 0 ), env = Grid (51 , 31 ),
47- actor_load_path = "models/actor_best_example.pth" , critic_load_path = "models/critic_best_example.pth" )
48- plt .run ()
49-
50- # -------------curve generators-------------
51- # points = [(0, 0, 0), (10, 10, -90), (20, 5, 60), (30, 10, 120),
52- # (35, -5, 30), (25, -10, -120), (15, -15, 100), (0, -10, -90)]
53-
54- # plt = Dubins(step=0.1, max_curv=0.25)
55- # plt = Bezier(step=0.1, offset=3.0)
56- # plt = Polynomial(step=2, max_acc=1.0, max_jerk=0.5)
57- # plt = ReedsShepp(step=0.1, max_curv=0.25)
58- # plt = CubicSpline(step=0.1)
59- # plt = BSpline(step=0.01, k=3)
60-
61- # plt.run(points)
11+ if __name__ == '__main__' :
12+ # -------------global planners-------------
13+ plt = AStar (start = (5 , 5 ), goal = (45 , 25 ), env = Grid (51 , 31 ))
14+ # plt = DStar(start=(5, 5), goal=(45, 25), env=Grid(51, 31))
15+ # plt = DStarLite(start=(5, 5), goal=(45, 25), env=Grid(51, 31))
16+ # plt = Dijkstra(start=(5, 5), goal=(45, 25), env=Grid(51, 31))
17+ # plt = GBFS(start=(5, 5), goal=(45, 25), env=Grid(51, 31))
18+ # plt = JPS(start=(5, 5), goal=(45, 25), env=Grid(51, 31))
19+ # plt = ThetaStar(start=(5, 5), goal=(45, 25), env=Grid(51, 31))
20+ # plt = LazyThetaStar(start=(5, 5), goal=(45, 25), env=Grid(51, 31))
21+ # plt = SThetaStar(start=(5, 5), goal=(45, 25), env=Grid(51, 31))
22+ # plt = LPAStar(start=(5, 5), goal=(45, 25), env=Grid(51, 31))
23+ # plt = VoronoiPlanner(start=(5, 5), goal=(45, 25), env=Grid(51, 31))
24+
25+ # plt = RRT(start=(18, 8), goal=(37, 18), env=Map(51, 31))
26+ # plt = RRTConnect(start=(18, 8), goal=(37, 18), env=Map(51, 31))
27+ # plt = RRTStar(start=(18, 8), goal=(37, 18), env=Map(51, 31))
28+ # plt = InformedRRT(start=(18, 8), goal=(37, 18), env=Map(51, 31))
29+
30+ # plt = ACO(start=(5, 5), goal=(45, 25), env=Grid(51, 31))
31+ # plt = PSO(start=(5, 5), goal=(45, 25), env=Grid(51, 31))
32+
33+ plt .run ()
34+
35+ # -------------local planners-------------
36+ # plt = PID(start=(5, 5, 0), goal=(45, 25, 0), env=Grid(51, 31))
37+ # plt = DWA(start=(5, 5, 0), goal=(45, 25, 0), env=Grid(51, 31))
38+ # plt = APF(start=(5, 5, 0), goal=(45, 25, 0), env=Grid(51, 31))
39+ # plt = LQR(start=(5, 5, 0), goal=(45, 25, 0), env=Grid(51, 31))
40+ # plt = RPP(start=(5, 5, 0), goal=(45, 25, 0), env=Grid(51, 31))
41+ # plt = MPC(start=(5, 5, 0), goal=(45, 25, 0), env=Grid(51, 31))
42+ # plt.run()
43+
44+
45+ # Train the model, only for learning-based planners, such as DDPG
46+ # It costs a lot of time to train the model, please be patient.
47+ # If you want a faster training, try reducing num_episodes and batch_size,
48+ # or increasing update_steps and evaluate_episodes, or fine-tuning other hyperparameters
49+ # if you are familiar with them, usually in a cost of performance, however.
50+
51+ # plt = DDPG(start=(5, 5, 0), goal=(45, 25, 0), env=Grid(51, 31),
52+ # actor_save_path="models/actor_best.pth", critic_save_path="models/critic_best.pth")
53+ # plt.train(num_episodes=10000)
54+
55+ # load the trained model and run
56+
57+ # plt = DDPG(start=(5, 5, 0), goal=(45, 25, 0), env=Grid(51, 31),
58+ # actor_load_path="models/actor_best_example.pth", critic_load_path="models/critic_best_example.pth")
59+ # plt.run()
60+
61+ # -------------curve generators-------------
62+ # points = [(0, 0, 0), (10, 10, -90), (20, 5, 60), (30, 10, 120),
63+ # (35, -5, 30), (25, -10, -120), (15, -15, 100), (0, -10, -90)]
64+
65+ # plt = Dubins(step=0.1, max_curv=0.25)
66+ # plt = Bezier(step=0.1, offset=3.0)
67+ # plt = Polynomial(step=2, max_acc=1.0, max_jerk=0.5)
68+ # plt = ReedsShepp(step=0.1, max_curv=0.25)
69+ # plt = CubicSpline(step=0.1)
70+ # plt = BSpline(step=0.01, k=3)
71+
72+ # plt.run(points)
0 commit comments