-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1671 from RoboJackets/basic_defense
Basic defense play
- Loading branch information
Showing
16 changed files
with
446 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"""This module contains the interface and action for intercept.""" | ||
|
||
from abc import ABC, abstractmethod | ||
|
||
import stp.role as role | ||
import stp.action as action | ||
import stp.rc as rc | ||
import numpy as np | ||
from rj_msgs.msg import RobotIntent, InterceptMotionCommand, SettleMotionCommand | ||
from rj_geometry_msgs.msg import Point | ||
|
||
|
||
class Intercept(action.IAction): | ||
"""Intercept action | ||
""" | ||
def __init__(self, robot_id: int = None, target_point: np.ndarray = None): | ||
self.robot_id = robot_id | ||
self.target_point = target_point | ||
|
||
def tick(self, intent: RobotIntent) -> None: | ||
""" | ||
# TODO: use this when intercept is fixed | ||
intercept_command = InterceptMotionCommand() | ||
# TODO: numpy to Point conv | ||
intercept_command.target = Point(x=self.target_point[0], y=self.target_point[1]) | ||
intent.motion_command.intercept_command = [intercept_command] | ||
""" | ||
settle_command = SettleMotionCommand() | ||
intent.motion_command.settle_command = [settle_command] | ||
intent.dribbler_speed = 1.0 | ||
intent.is_active = True | ||
|
||
return intent | ||
|
||
def is_done(self, world_state) -> bool: | ||
if world_state.our_robots[self.robot_id].has_ball_sense: | ||
return True | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import stp.play as play | ||
import stp.tactic as tactic | ||
|
||
from rj_gameplay.tactic import wall_tactic, nmark_tactic, goalie_tactic | ||
import stp.skill as skill | ||
import stp.role as role | ||
from stp.role.assignment.naive import NaiveRoleAssignment | ||
import stp.rc as rc | ||
from typing import Dict, Generic, Iterator, List, Optional, Tuple, Type, TypeVar | ||
|
||
|
||
class BasicDefense(play.IPlay): | ||
"""For when we don't have the ball and are trying to stop the opponent from scoring. | ||
""" | ||
def __init__(self): | ||
self.tactics = [ | ||
wall_tactic.WallTactic(3), | ||
nmark_tactic.NMarkTactic(2), | ||
goalie_tactic.GoalieTactic() | ||
] | ||
|
||
self.role_assigner = NaiveRoleAssignment() | ||
|
||
def compute_props(self, prev_props): | ||
pass | ||
|
||
def tick( | ||
self, | ||
world_state: rc.WorldState, | ||
prev_results: role.assignment.FlatRoleResults, | ||
props, | ||
) -> Tuple[Dict[Type[tactic.SkillEntry], List[role.RoleRequest]], | ||
List[tactic.SkillEntry]]: | ||
|
||
# Get role requests from all tactics and put them into a dictionary | ||
role_requests: play.RoleRequests = { | ||
tactic: tactic.get_requests(world_state, None) | ||
for tactic in self.tactics | ||
} | ||
|
||
# Flatten requests and use role assigner on them | ||
flat_requests = play.flatten_requests(role_requests) | ||
flat_results = self.role_assigner.assign_roles(flat_requests, | ||
world_state, | ||
prev_results) | ||
role_results = play.unflatten_results(flat_results) | ||
|
||
# Get list of all SkillEntries from all tactics | ||
skills = [] | ||
for tactic in self.tactics: | ||
skills += tactic.tick(role_results[tactic]) | ||
|
||
# Get all role assignments | ||
# SkillEntry to (list of?) RoleResult | ||
skill_dict = {} | ||
for tactic in self.tactics: | ||
skill_dict.update(role_results[tactic]) | ||
|
||
return (skill_dict, skills) | ||
|
||
def is_done(self, world_state): | ||
# returns done when all tactics are done | ||
# TODO: change all is_done() to use all()? | ||
return all([tactic.is_done(world_state) for tactic in self.tactics]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from abc import ABC, abstractmethod | ||
|
||
import rj_gameplay.eval as eval | ||
import argparse | ||
import py_trees | ||
import sys | ||
import time | ||
|
||
import stp.skill as skill | ||
import stp.role as role | ||
import stp.action as action | ||
from rj_gameplay.action import intercept | ||
from stp.skill.action_behavior import ActionBehavior | ||
import stp.rc as rc | ||
import numpy as np | ||
|
||
|
||
class IIntercept(skill.ISkill, ABC): | ||
... | ||
|
||
|
||
""" | ||
A skill version of intercept so that actions don't have to be called in tactics | ||
""" | ||
|
||
|
||
# TODO: discuss collapsing skills/actions | ||
class Intercept(IIntercept): | ||
def __init__(self, | ||
robot: rc.Robot = None, | ||
target_point: np.ndarray = np.array([0.0, 0.0])): | ||
self.robot = robot | ||
self.target_point = target_point | ||
|
||
self.__name__ = 'Intercept Skill' | ||
if self.robot is not None: | ||
self.intercept = intercept.Intercept(self.robot.id, target_point) | ||
else: | ||
self.intercept = intercept.Intercept(None, target_point) | ||
self.intercept_behavior = ActionBehavior('Intercept', self.intercept, | ||
self.robot) | ||
self.root = self.intercept_behavior | ||
self.root.setup_with_descendants() | ||
|
||
def tick(self, robot: rc.Robot, world_state: rc.WorldState): | ||
self.robot = robot | ||
self.intercept.robot_id = self.robot.id | ||
self.intercept.target_point = self.target_point | ||
return self.root.tick_once(self.robot, world_state) | ||
|
||
def is_done(self, world_state) -> bool: | ||
return self.intercept.is_done(world_state) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.