Decision Module  1.0
ICRA2020 AI Challenge Northwestern Polytechnical University Aoxiang Team Strategy Code
tworoborts_chase.h
Go to the documentation of this file.
1 //
2 // Created by song on 2020/4/13.
3 //
4 
5 #ifndef ROBORTS_DECISION_TWOROBORTS_CHASE_H
6 #define ROBORTS_DECISION_TWOROBORTS_CHASE_H
7 
8 #include <ros/ros.h>
9 
10 #include "../blackboard/blackboard.h"
11 #include "../behavior/robot_behaviors.h"
12 
13 namespace roborts_decision {
15 public:
16  TwoRobortsChase(std::shared_ptr<MyRobot> p_my_robot1,
17  std::shared_ptr<MyRobot> p_my_robot2,
18  std::shared_ptr<Blackboard> p_blackboard,
19  std::shared_ptr<RobotBehaviors> p_robot1_behaviors,
20  std::shared_ptr<RobotBehaviors> p_robot2_behaviors)
21  : p_my_robot1(std::move(p_my_robot1)),
22  p_my_robot2(std::move(p_my_robot2)),
23  p_blackboard_(std::move(p_blackboard)),
26 
27  void run(RobotId emeny_id) {
28 
29  auto current_behavior = p_my_robot1->GetCurrentBehavior();
30  if (current_behavior != CHASE) {
32  }
33 
34  current_behavior = p_my_robot2->GetCurrentBehavior();
35  if (current_behavior != CHASE) {
37  }
38 
39  p_my_robot1->SetCurrentBehavior(CHASE);
40  p_my_robot2->SetCurrentBehavior(CHASE);
41  p_robot1_behaviors->GetPursueAttackBehavior()->Run(emeny_id, 1.2);
42  p_robot2_behaviors->GetPursueAttackBehavior()->Run(emeny_id, 1.2);
43  }
44 
45  static void
46  CancelBehavior(const std::shared_ptr<MyRobot> &myRobot,
47  const std::shared_ptr<RobotBehaviors> &robotBehaviors) {
48  auto current_behavior = myRobot->GetCurrentBehavior();
49  if (current_behavior == ESCAPE) {
50  robotBehaviors->GetEscapeBehavior()->Cancel();
51  } else if (current_behavior == SUPPLY) {
52  robotBehaviors->GetSupplyBehavior()->Cancel();
53  } else if (current_behavior == GOAL) {
54  robotBehaviors->GetGoalBehavior()->Cancel();
55  }
56  }
57 
58  void cancel() {
59  p_robot1_behaviors->GetPursueAttackBehavior()->Cancel();
60  p_robot2_behaviors->GetPursueAttackBehavior()->Cancel();
61  }
62 
63 private:
64  std::shared_ptr<MyRobot> p_my_robot1;
65  std::shared_ptr<MyRobot> p_my_robot2;
66  std::shared_ptr<Blackboard> p_blackboard_;
67  std::shared_ptr<RobotBehaviors> p_robot1_behaviors;
68  std::shared_ptr<RobotBehaviors> p_robot2_behaviors;
69 };
70 } // namespace roborts_decision
71 
72 #endif // ROBORTS_DECISION_TWOROBORTS_CHASE_H
roborts_decision::TwoRobortsChase::p_robot1_behaviors
std::shared_ptr< RobotBehaviors > p_robot1_behaviors
Definition: tworoborts_chase.h:67
roborts_decision::TwoRobortsChase::p_my_robot2
std::shared_ptr< MyRobot > p_my_robot2
Definition: tworoborts_chase.h:65
roborts_decision::TwoRobortsChase::p_robot2_behaviors
std::shared_ptr< RobotBehaviors > p_robot2_behaviors
Definition: tworoborts_chase.h:68
roborts_decision::TwoRobortsChase::cancel
void cancel()
Definition: tworoborts_chase.h:58
roborts_decision::SUPPLY
@ SUPPLY
Definition: blackboard_common.h:51
roborts_decision::ESCAPE
@ ESCAPE
Definition: blackboard_common.h:49
roborts_decision::TwoRobortsChase::CancelBehavior
static void CancelBehavior(const std::shared_ptr< MyRobot > &myRobot, const std::shared_ptr< RobotBehaviors > &robotBehaviors)
Definition: tworoborts_chase.h:46
roborts_decision::CHASE
@ CHASE
Definition: blackboard_common.h:48
roborts_decision::TwoRobortsChase::TwoRobortsChase
TwoRobortsChase(std::shared_ptr< MyRobot > p_my_robot1, std::shared_ptr< MyRobot > p_my_robot2, std::shared_ptr< Blackboard > p_blackboard, std::shared_ptr< RobotBehaviors > p_robot1_behaviors, std::shared_ptr< RobotBehaviors > p_robot2_behaviors)
Definition: tworoborts_chase.h:16
roborts_decision::TwoRobortsChase::run
void run(RobotId emeny_id)
Definition: tworoborts_chase.h:27
roborts_decision::TwoRobortsChase::p_blackboard_
std::shared_ptr< Blackboard > p_blackboard_
Definition: tworoborts_chase.h:66
roborts_decision
Definition: behavior_test_node.h:14
roborts_decision::TwoRobortsChase
Definition: tworoborts_chase.h:14
roborts_decision::GOAL
@ GOAL
Definition: blackboard_common.h:50
roborts_decision::RobotId
RobotId
Definition: blackboard_common.h:89
roborts_decision::TwoRobortsChase::p_my_robot1
std::shared_ptr< MyRobot > p_my_robot1
Definition: tworoborts_chase.h:64