質問編集履歴
2
修正
    
        title	
    CHANGED
    
    | 
         
            File without changes
         
     | 
    
        body	
    CHANGED
    
    | 
         @@ -39,9 +39,9 @@ 
     | 
|
| 
       39 
39 
     | 
    
         
             
                 cv2.imshow('Output', image)
         
     | 
| 
       40 
40 
     | 
    
         
             
                    cv2.waitKey(1000)
         
     | 
| 
       41 
41 
     | 
    
         
             
                    print("進みます")
         
     | 
| 
       42 
     | 
    
         
            -
            #ポテンシャル法により経路を連続描写により書いている
         
     | 
| 
      
 42 
     | 
    
         
            +
                 #ポテンシャル法により経路を連続描写により書いている
         
     | 
| 
       43 
     | 
    
         
            -
            # <10になるまで点をループで描写
         
     | 
| 
      
 43 
     | 
    
         
            +
                 # <10になるまで点をループで描写
         
     | 
| 
       44 
     | 
    
         
            -
            while Position.calculate_distance(agent.position, goal.position) > 10:
         
     | 
| 
      
 44 
     | 
    
         
            +
                 while Position.calculate_distance(agent.position, goal.position) > 10:
         
     | 
| 
       45 
45 
     | 
    
         
             
                        possible_moves = agent.get_possible_moves()
         
     | 
| 
       46 
46 
     | 
    
         
             
                        min_value = math.inf
         
     | 
| 
       47 
47 
     | 
    
         
             
                        best_move = possible_moves[0] # initializing best move with first move
         
     | 
| 
         @@ -147,7 +147,9 @@ 
     | 
|
| 
       147 
147 
     | 
    
         | 
| 
       148 
148 
     | 
    
         
             
                    cap.release()
         
     | 
| 
       149 
149 
     | 
    
         
             
                    cv2.destroyAllWindows()  
         
     | 
| 
      
 150 
     | 
    
         
            +
               
         
     | 
| 
       150 
151 
     | 
    
         | 
| 
      
 152 
     | 
    
         
            +
             
     | 
| 
       151 
153 
     | 
    
         
             
            def main():
         
     | 
| 
       152 
154 
     | 
    
         
             
                pt = Potential()
         
     | 
| 
       153 
155 
     | 
    
         
             
                th1 = threading.Thread(target=pt.potential)
         
     | 
1
追加で編集しました
    
        title	
    CHANGED
    
    | 
         
            File without changes
         
     | 
    
        body	
    CHANGED
    
    | 
         @@ -8,6 +8,13 @@ 
     | 
|
| 
       8 
8 
     | 
    
         
             
            ### 該当のソースコード
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
            ```python3.8
         
     | 
| 
      
 11 
     | 
    
         
            +
            class Potential:
         
     | 
| 
      
 12 
     | 
    
         
            +
                def __init__(self):
         
     | 
| 
      
 13 
     | 
    
         
            +
                    
         
     | 
| 
      
 14 
     | 
    
         
            +
                    #初期スピード設定
         
     | 
| 
      
 15 
     | 
    
         
            +
                    self.speed = 100
         
     | 
| 
      
 16 
     | 
    
         
            +
                    
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
       11 
18 
     | 
    
         
             
                def potential(self):
         
     | 
| 
       12 
19 
     | 
    
         
             
                    # Defining world dimensions
         
     | 
| 
       13 
20 
     | 
    
         
             
                    world_size = (600, 700)
         
     | 
| 
         @@ -54,10 +61,73 @@ 
     | 
|
| 
       54 
61 
     | 
    
         
             
                        agent.draw(image)
         
     | 
| 
       55 
62 
     | 
    
         
             
                        # Displaying updated frame
         
     | 
| 
       56 
63 
     | 
    
         
             
                        cv2.imshow('Output', image) 
         
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
      
 64 
     | 
    
         
            +
                        key = cv2.waitKey(self.speed)
         
     | 
| 
      
 65 
     | 
    
         
            +
                        #print(self.speed)
         
     | 
| 
      
 66 
     | 
    
         
            +
                        if key & 0xFF == ord('s'):
         
     | 
| 
      
 67 
     | 
    
         
            +
                            self.speed -= 100
         
     | 
| 
      
 68 
     | 
    
         
            +
                            if self.speed <= 0:
         
     | 
| 
      
 69 
     | 
    
         
            +
                                self.speed += 100
         
     | 
| 
      
 70 
     | 
    
         
            +
                                print("これ以上速くなりません")
         
     | 
| 
      
 71 
     | 
    
         
            +
                        
         
     | 
| 
      
 72 
     | 
    
         
            +
                        if key & 0xFF == ord('d'):
         
     | 
| 
      
 73 
     | 
    
         
            +
                            self.speed += 100    
         
     | 
| 
      
 74 
     | 
    
         
            +
                            if self.speed >= 2100:
         
     | 
| 
      
 75 
     | 
    
         
            +
                                self.speed -= 100
         
     | 
| 
      
 76 
     | 
    
         
            +
                                print("これ以上遅くなりません")
         
     | 
| 
      
 77 
     | 
    
         
            +
                        if Position.calculate_distance(agent.position, goal.position)<10:
         
     | 
| 
      
 78 
     | 
    
         
            +
                            navi += 1
         
     | 
| 
      
 79 
     | 
    
         
            +
                            if navi == 1:
         
     | 
| 
      
 80 
     | 
    
         
            +
                                print("右に曲がります")
         
     | 
| 
      
 81 
     | 
    
         
            +
                                print("進みます")
         
     | 
| 
      
 82 
     | 
    
         
            +
                                goal = Goal(Position(40,180), sigma=math.sqrt(world_size[0]**2 + world_size[1]**2))
         
     | 
| 
      
 83 
     | 
    
         
            +
                             
         
     | 
| 
      
 84 
     | 
    
         
            +
                                
         
     | 
| 
      
 85 
     | 
    
         
            +
                            if navi == 2:
         
     | 
| 
      
 86 
     | 
    
         
            +
                                if Position.calculate_distance(agent.position, goal.position)<10:
         
     | 
| 
      
 87 
     | 
    
         
            +
                                    print("左に曲がります")
         
     | 
| 
      
 88 
     | 
    
         
            +
                                    print("進みます")
         
     | 
| 
      
 89 
     | 
    
         
            +
                                    goal = Goal(Position(40,620), sigma=math.sqrt(world_size[0]**2 + world_size[1]**2))
         
     | 
| 
      
 90 
     | 
    
         
            +
                                  
         
     | 
| 
      
 91 
     | 
    
         
            +
                                    
         
     | 
| 
      
 92 
     | 
    
         
            +
                            if navi ==3:
         
     | 
| 
      
 93 
     | 
    
         
            +
                                if Position.calculate_distance(agent.position, goal.position)<10:
         
     | 
| 
      
 94 
     | 
    
         
            +
                                    print("左に曲がります")
         
     | 
| 
      
 95 
     | 
    
         
            +
                                    print("進みます")
         
     | 
| 
      
 96 
     | 
    
         
            +
                                    goal = Goal(Position(320,620), sigma=math.sqrt(world_size[0]**2 + world_size[1]**2))
         
     | 
| 
      
 97 
     | 
    
         
            +
                                    
         
     | 
| 
      
 98 
     | 
    
         
            +
                                    
         
     | 
| 
      
 99 
     | 
    
         
            +
                            if navi ==4:
         
     | 
| 
      
 100 
     | 
    
         
            +
                                if Position.calculate_distance(agent.position, goal.position)<10:
         
     | 
| 
      
 101 
     | 
    
         
            +
                                    print("斜め右に曲がります")
         
     | 
| 
      
 102 
     | 
    
         
            +
                                    print("進みます")
         
     | 
| 
      
 103 
     | 
    
         
            +
                                    goal = Goal(Position(370,680), sigma=math.sqrt(world_size[0]**2 + world_size[1]**2))
         
     | 
| 
      
 104 
     | 
    
         
            +
                                    
         
     | 
| 
      
 105 
     | 
    
         
            +
                                 
         
     | 
| 
      
 106 
     | 
    
         
            +
                            if navi ==5:
         
     | 
| 
      
 107 
     | 
    
         
            +
                                if Position.calculate_distance(agent.position, goal.position)<10:
         
     | 
| 
      
 108 
     | 
    
         
            +
                                    print("左に曲がります")
         
     | 
| 
      
 109 
     | 
    
         
            +
                                    print("進みます")
         
     | 
| 
      
 110 
     | 
    
         
            +
                                    goal = Goal(Position(490,680), sigma=math.sqrt(world_size[0]**2 + world_size[1]**2))
         
     | 
| 
      
 111 
     | 
    
         
            +
                                    
         
     | 
| 
      
 112 
     | 
    
         
            +
                              
         
     | 
| 
      
 113 
     | 
    
         
            +
                            if navi ==6:
         
     | 
| 
      
 114 
     | 
    
         
            +
                                if Position.calculate_distance(agent.position, goal.position)<10:
         
     | 
| 
      
 115 
     | 
    
         
            +
                                    print("左に曲がります")
         
     | 
| 
      
 116 
     | 
    
         
            +
                                    print("進みます")
         
     | 
| 
      
 117 
     | 
    
         
            +
                                    goal = Goal(Position(490,580), sigma=math.sqrt(world_size[0]**2 + world_size[1]**2))
         
     | 
| 
      
 118 
     | 
    
         
            +
                                    
         
     | 
| 
      
 119 
     | 
    
         
            +
                                    
         
     | 
| 
      
 120 
     | 
    
         
            +
                            if navi == 7:
         
     | 
| 
      
 121 
     | 
    
         
            +
                                if Position.calculate_distance(agent.position, goal.position)<10:
         
     | 
| 
      
 122 
     | 
    
         
            +
                                    print("到着しました")
         
     | 
| 
      
 123 
     | 
    
         
            +
                                    cv2.waitKey(0)
         
     | 
| 
       58 
124 
     | 
    
         | 
| 
      
 125 
     | 
    
         
            +
                
         
     | 
| 
      
 126 
     | 
    
         
            +
                        if key & 0xFF == ord('q'):
         
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
      
 127 
     | 
    
         
            +
                            sys.exit()
         
     | 
| 
      
 128 
     | 
    
         
            +
                # Hold on last frame
         
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
      
 129 
     | 
    
         
            +
                cv2.waitKey(0)
         
     | 
| 
      
 130 
     | 
    
         
            +
                  
         
     | 
| 
       61 
131 
     | 
    
         
             
                def video(self):    
         
     | 
| 
       62 
132 
     | 
    
         
             
                    cap = cv2.VideoCapture('experiment.mp4')
         
     | 
| 
       63 
133 
     | 
    
         
             
                    if (cap.isOpened()== False):  
         
     | 
| 
         @@ -77,4 +147,16 @@ 
     | 
|
| 
       77 
147 
     | 
    
         | 
| 
       78 
148 
     | 
    
         
             
                    cap.release()
         
     | 
| 
       79 
149 
     | 
    
         
             
                    cv2.destroyAllWindows()  
         
     | 
| 
      
 150 
     | 
    
         
            +
             
     | 
| 
      
 151 
     | 
    
         
            +
            def main():
         
     | 
| 
      
 152 
     | 
    
         
            +
                pt = Potential()
         
     | 
| 
      
 153 
     | 
    
         
            +
                th1 = threading.Thread(target=pt.potential)
         
     | 
| 
      
 154 
     | 
    
         
            +
                th2 = threading.Thread(target=pt.video)
         
     | 
| 
      
 155 
     | 
    
         
            +
                th1.start()
         
     | 
| 
      
 156 
     | 
    
         
            +
                th2.start()
         
     | 
| 
      
 157 
     | 
    
         
            +
                
         
     | 
| 
      
 158 
     | 
    
         
            +
             
     | 
| 
      
 159 
     | 
    
         
            +
            if __name__ == '__main__':
         
     | 
| 
      
 160 
     | 
    
         
            +
                main()
         
     | 
| 
      
 161 
     | 
    
         
            +
             
     | 
| 
       80 
162 
     | 
    
         
             
            ```
         
     |