コード例 #1
0
ファイル: uavs.py プロジェクト: wayne2000cc/UAV_simulation
    def report_result(self, result, tq):

        # 扣掉特數項 -1
        preturn_time = []
        for t in result['return_time']:
            if t != -1:
                preturn_time.append(t)

        result_text = ''
        result_text += ('Total time:%d\n' % tq)
        result_text += ('return time:%s\n' % str(result['return_time']))
        result_text += ('time sum:%d\n' % sum(preturn_time))

        if (len(preturn_time) != 0):
            result_text += ('mean time:%s\n' %
                            str(sum(preturn_time) / len(preturn_time)))
        result_text += ('risk:%s\n' % str(result['risk']))
        result_text += ('risk sum:%s\n' % str(sum(result['risk'])))
        result_text += ('mean risk:%s\n' %
                        str(sum(result['risk']) / len(result['risk'])))
        result_text += ('max risk:%s\n' % str(max(result['risk'])))
        result_text += ('complete target num:%d\n' %
                        (len(result['mission_complete'])))
        result_text += self.intp_out_range(max(result['return_time']),
                                           result['out_range'])

        print(result_text)
        self.env_detecter.reset()
        # write in a result.txt and traj
        with open('result.txt', 'w') as f:
            f.write(result_text)
        #write traj json
        M_list.write(self.traj, target='traj.json')
コード例 #2
0
    def set_data(self):

        temp = self.env_data['M_list'][:]
        if (type(self.env_data['M_list'][0]) != list):
            self.env_data['M_list'] = M_list.M_lists_as_lists(
                self.env_data['M_list'])
        M_list.write(self.env_data)
        self.env_data['M_list'] = temp
コード例 #3
0
 def __init__(self, replan=False):
     self.m = M.map_gen()
     self.m.gen()
     # record the time when UAV out of 500m constrain
     # not load the pre planning
     if (self.m.read is False or replan is True):
         Mlist = self.mission_allocation()
         self.m.M_list = M_list.as_M_lists(Mlist)
     self.m.set_env_data()
     self.m.set_data()
     self.num = self.m.num
     self.v = None
コード例 #4
0
    def set_by_data(self, ):
        env_data = self.env_data
        env_data['M_list'] = M_list.as_M_lists(env_data['M_list'])

        self.forbidden_area_vertices = env_data['Forbid']
        self.forbid_form()
        self.threaten = env_data['Threat']
        self.target = env_data['Target']
        self.M_list = env_data['M_list']
        self.fail = {
            'index': env_data['fail_index'],
            'time': env_data['fail_time']
        }
        self.thr_move = {
            'to': env_data['thr_move_to'],
            'count': env_data['thr_move_count']
        }
コード例 #5
0
    def checkCallBack(self):
        value = self.listb.get(self.listb.curselection())
        if value not in self.li:
            return
        elif value == 'gen_new_map':
            global map
            del map
            map = MAP.map_gen()
            map.gen(replan = True)
            Mlist = self.u_instance().mission_allocation()
            map.M_list = M_list.as_M_list_instances(Mlist)
            map.set_env_data()
            self.pgraph.redraw()
            return
        # module gui can't call
#        elif value == 'run_simulation':
#            self.u_instance().run(visual = True)

        
        self.showcwindow(value)
コード例 #6
0
 def gen(self):
     self.env_data = M_list.read()
     if (Fixed_map and self.env_data is not False):
         self.set_by_data()
         self.read = True
     else:
         self.gen_forbidden()
         # set up map generator
         self.g = self.rand_map()
         self.gen_threaten()
         self.gen_target()
         self.rand_auto_fail()
         self.rand_thr_move()
         self.read = False
     if len(self.thr_move['to']) != self.datanum['target'][1]:
         self.rand_thr_move()
     if (print_data):
         # forvi
         print('Forbid:' + str(self.forbidden_area_vertices))
         print('threaten:' + str(self.threaten))
         print('target:' + str(self.target))
コード例 #7
0
ファイル: uavs.py プロジェクト: wayne2000cc/UAV_simulation
 def show_traj(self):
     #read a python traj
     self.traj = M_list.read(target='traj.json')
     self.v = visualization.show_visual(self.m, self.mov)
     self.v.show_traj(self.traj)