-
Notifications
You must be signed in to change notification settings - Fork 186
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 #1644 from RoboJackets/new_gameplay_passing
New gameplay passing
- Loading branch information
Showing
12 changed files
with
388 additions
and
48 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
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,34 @@ | ||
"""This module contains the interface and action for receive.""" | ||
|
||
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, SettleMotionCommand | ||
|
||
class Receive(action.IAction): | ||
""" | ||
Receive action | ||
""" | ||
|
||
def __init__(self, robot_id: int = None): | ||
self.robot_id = robot_id | ||
|
||
|
||
def tick(self, intent) -> None: | ||
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 self.robot_id is None: | ||
return False | ||
#TODO: Use local params for this threshold | ||
if world_state.our_robots[self.robot_id].has_ball_sense or np.linalg.norm(world_state.ball.vel) < 10**(-6): | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import stp.play as play | ||
import stp.tactic as tactic | ||
|
||
from rj_gameplay.tactic import pass_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 | ||
import numpy as np | ||
|
||
class PassPlay(play.IPlay): | ||
"""A play which makes one robot pass to another | ||
""" | ||
|
||
def __init__(self): | ||
self.target_point = np.array([1.0,1.0]) | ||
self.pass_tactic = pass_tactic.Pass(self.target_point) | ||
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 = {} | ||
if not self.pass_tactic.is_done(world_state): | ||
role_requests[self.pass_tactic] = self.pass_tactic.get_requests(world_state, None) | ||
else: | ||
pass | ||
# 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 skills with assigned roles from tactics | ||
skill_dict = {} | ||
if not self.pass_tactic.is_done(world_state): | ||
skills = self.pass_tactic.tick(role_results[self.pass_tactic], world_state) | ||
skill_dict.update(role_results[self.pass_tactic]) | ||
else: | ||
skills = [] | ||
|
||
return (skill_dict, skills) | ||
|
||
def is_done(self, world_state: rc.WorldState): | ||
return self.pass_tactic.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
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 numpy as np | ||
from typing import Optional | ||
|
||
import stp.skill as skill | ||
import stp.role as role | ||
import stp.action as action | ||
from rj_gameplay.action import receive, capture | ||
from stp.skill.action_behavior import ActionBehavior | ||
from stp.skill.rj_sequence import RjSequence as Sequence | ||
import stp.rc as rc | ||
from rj_msgs import msg | ||
|
||
class IReceive(skill.ISkill, ABC): | ||
... | ||
|
||
|
||
""" | ||
A skill version of receive so that actions don't have to be called in tactics | ||
""" | ||
class Receive(IReceive): | ||
|
||
def __init__(self, | ||
robot:rc.Robot = None): | ||
|
||
self.robot = robot | ||
if self.robot is not None: | ||
self.receive = receive.Receive(self.robot.id) | ||
self.capture = capture.Capture(self.robot.id) | ||
else: | ||
self.receive = receive.Receive(self.robot) | ||
self.capture = capture.Capture() | ||
self.receive_behavior = ActionBehavior('Receive', self.receive) | ||
self.capture_behavior = ActionBehavior('Capture', self.capture) | ||
self.root = Sequence('Sequence') | ||
self.root.add_children([self.receive_behavior, self.capture_behavior]) | ||
self.root.setup_with_descendants() | ||
self.__name__ = 'receive skill' | ||
|
||
def tick(self, robot:rc.Robot, world_state:rc.WorldState): #returns dict of robot and actions | ||
self.robot = robot | ||
actions = self.root.tick_once(self.robot, world_state) | ||
return actions | ||
|
||
def is_done(self, world_state:rc.WorldState): | ||
return self.capture.is_done(world_state) |
Oops, something went wrong.