コード例 #1
0
ファイル: Actions.py プロジェクト: huanwu961/RoboRTS
 def Execute(self):
     if self.first_run == True:
         self.first_run = False
         self.target_pose = Blackboard.enemy.pose
     elif Helpers.CalcDist(self.target_pose,Blackboard.enemy.pose) > 1.5:
         self.target_pose = Blackboard.enemy.pose
     if(Helpers.CalcDist(Blackboard.myrobot.pose,self.target_pose)<=1.5):
         current_pose = Helpers.Pose2D2Pose(Blackboard.myrobot.pose)
         self.pub.publish(current_pose)
     else:
         target_pose = Helpers.Pose2D2Pose(self.target_pose)
         self.pub.publish(target_pose)
コード例 #2
0
 def Update(self):
     if Helpers.CalcDist(Blackboard.enemy.pose,
                         Blackboard.myrobot.pose) <= self.value:
         self._status = "SUCCESS"
     else:
         self._status = "FAILURE"
     return self._status
コード例 #3
0
ファイル: Actions.py プロジェクト: huanwu961/RoboRTS
 def Execute(self):
     pose2d = Blackboard.enemy.pose
     dists = [Helpers.CalcDist(pose2d,d) for d in PyConfig.DEFENCEPOINTS]
     index = dists.index(max(dists))
     target_pose = PyConfig.DEFENCEPOINTS[index]
     target_pose = Helpers.Pose2D2Pose(target_pose)
     try:
         self.pub.publish(target_pose)
     except:
         self.success_flag = False
コード例 #4
0
 def checkAttack(self):
     if self.init_flag == True:
         self.init_flag = False
         self.last_time = time.time()
     mypose = Blackboard.myrobot.pose
     enpose = Blackboard.enemy.pose
     dist = Helpers.CalcDist(mypose, enpose)
     isblock = Helpers.CheckBlock(mypose, enpose)
     if dist < 2 and dist > 1:
         if (time.time() - self.last_time) > 0.1:
             self.last_time = time.time()
             if not isblock:
                 if Blackboard.myrobot.bullet > 0 and Blackboard.myrobot.enableShoot:
                     Blackboard.enemy.blood -= 20
                     Blackboard.myrobot.bullet -= 1
                 if Blackboard.enemy.bullet > 0:
                     if Blackboard.myrobot.istwist == True:
                         Blackboard.myrobot.blood -= 10
                     else:
                         Blackboard.myrobot.blood -= 20
                     Blackboard.enemy.bullet -= 1
                 cv.setTrackbarPos("Target Blood", "Game Panel",
                                   Blackboard.enemy.blood)
                 cv.setTrackbarPos("Target Bullet", "Game Panel",
                                   Blackboard.enemy.bullet)
                 cv.setTrackbarPos("Self Blood", "Game Panel",
                                   Blackboard.myrobot.blood)
                 cv.setTrackbarPos("Self Bullet", "Game Panel",
                                   Blackboard.myrobot.bullet)
     elif dist <= 5 and dist >= 2:
         if (time.time() - self.last_time) > 0.1:
             self.last_time = time.time()
             if not isblock:
                 if Blackboard.myrobot.bullet > 0 and Blackboard.myrobot.enableShoot:
                     Blackboard.enemy.blood -= 10
                     Blackboard.myrobot.bullet -= 1
                 if Blackboard.enemy.bullet > 0:
                     if Blackboard.myrobot.istwist == True:
                         Blackboard.myrobot.blood -= 5
                     else:
                         Blackboard.myrobot.blood -= 10
                     Blackboard.enemy.bullet -= 1
                 cv.setTrackbarPos("Target Blood", "Game Panel",
                                   Blackboard.enemy.blood)
                 cv.setTrackbarPos("Target Bullet", "Game Panel",
                                   Blackboard.enemy.bullet)
                 cv.setTrackbarPos("Self Blood", "Game Panel",
                                   Blackboard.myrobot.blood)
                 cv.setTrackbarPos("Self Bullet", "Game Panel",
                                   Blackboard.myrobot.bullet)
     else:
         pass
コード例 #5
0
ファイル: Actions.py プロジェクト: huanwu961/RoboRTS
 def Execute(self):
     self.current_status = Blackboard.myrobot.chassis
     if self.first_run == True:
         self.first_run = False
         dists = [Helpers.CalcDist(Blackboard.myrobot.pose,i) for i in PyConfig.SEARCHZONES]
         self.current_i = dists.index(min(dists))
         next_goal = Helpers.Pose2D2Pose(PyConfig.SEARCHZONES[self.current_i])
         self.pub.publish(next_goal)
     elif self.last_status == "RUNNING" and self.current_status!= "RUNNING":
         self.current_i = (self.current_i + 1)%len(PyConfig.SEARCHZONES)
         next_goal = Helpers.Pose2D2Pose(PyConfig.SEARCHZONES[self.current_i])
         self.pub.publish(next_goal)
     else:
         pass # On The Way