-
Notifications
You must be signed in to change notification settings - Fork 10
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 #84 from gaorkl/feat/cleanup
All tests passing
- Loading branch information
Showing
365 changed files
with
564 additions
and
1,592 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
# Include requirements: | ||
include requirements.txt | ||
# Include Assets: | ||
recursive-include src/spg *.txt *.md *.url *.png *.jpg *.jpeg | ||
|
||
# Include configs: | ||
recursive-include src/spg/resources *.txt *.md *.url *.png *.jpg *.jpeg | ||
recursive-include src/spg/agent/sensor/shaders *.glsl | ||
# Include Shaders: | ||
recursive-include src/spg *.glsl | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,97 @@ | ||
import math | ||
|
||
import pymunk | ||
from gymnasium import spaces | ||
|
||
from spg.components.agents.constants import ANGULAR_VELOCITY, ARM_MASS, HEAD_MASS | ||
from spg.core.entity import Entity | ||
from spg.core.entity.body import AttachedDynamicMixin | ||
from spg.core.entity.interaction.action import ActionMixin | ||
|
||
|
||
class AttachedPart(Entity, AttachedDynamicMixin, ActionMixin): | ||
def __init__(self, rotation_range=math.pi / 3, **kwargs): | ||
self.rotation_range = rotation_range | ||
super().__init__(**kwargs) | ||
|
||
def _get_joint(self): | ||
joint = pymunk.PivotJoint( | ||
self.anchor.pm_body, | ||
self.pm_body, | ||
self.anchor.attachment_points[self][0], | ||
self.attachment_point, | ||
) | ||
joint.collide_bodies = False | ||
return joint | ||
|
||
def _get_limit(self): | ||
|
||
relative_angle = self.pm_body.angle - self.anchor.pm_body.angle | ||
|
||
limit = pymunk.RotaryLimitJoint( | ||
self.anchor.pm_body, | ||
self.pm_body, | ||
relative_angle - self.rotation_range / 2, | ||
relative_angle + self.rotation_range / 2, | ||
) | ||
limit.collide_bodies = False | ||
return limit | ||
|
||
def _get_motor(self): | ||
motor = pymunk.SimpleMotor(self.anchor.pm_body, self.pm_body, 0) | ||
motor.max_force = 5 | ||
motor.collide_bodies = False | ||
return motor | ||
|
||
@property | ||
def _action_space(self): | ||
return spaces.Box(-1, 1, shape=(1,)) | ||
|
||
def apply_action(self, action): | ||
self.motor.rate = action * ANGULAR_VELOCITY | ||
|
||
|
||
class Arm(AttachedPart): | ||
def __init__( | ||
self, | ||
mass=ARM_MASS, | ||
rotation_range=math.pi / 4, | ||
filename=":spg:agent/arm.png", | ||
sprite_front_is_up=True, | ||
**kwargs | ||
): | ||
|
||
super().__init__( | ||
mass=mass, | ||
rotation_range=rotation_range, | ||
sprite_front_is_up=sprite_front_is_up, | ||
filename=filename, | ||
**kwargs, | ||
) | ||
|
||
@property | ||
def attachment_point(self): | ||
return -self.radius, 0.0 | ||
|
||
|
||
class Head(AttachedPart): | ||
def __init__( | ||
self, | ||
mass=HEAD_MASS, | ||
filename=":spg:agent/head.png", | ||
sprite_front_is_up=True, | ||
rotation_range=math.pi / 2, | ||
**kwargs | ||
): | ||
|
||
super().__init__( | ||
mass=mass, | ||
rotation_range=rotation_range, | ||
sprite_front_is_up=sprite_front_is_up, | ||
filename=filename, | ||
**kwargs, | ||
) | ||
|
||
@property | ||
def attachment_point(self): | ||
return 0, 0 |
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,85 @@ | ||
from abc import ABC | ||
|
||
import pymunk | ||
from gymnasium import spaces | ||
|
||
from spg.core.entity import Agent | ||
from spg.core.entity.body import BaseDynamicMixin, BaseStaticMixin | ||
|
||
from .constants import ANGULAR_VELOCITY, BASE_MASS, LINEAR_FORCE | ||
|
||
|
||
class DynamicAgent(Agent, BaseDynamicMixin, ABC): | ||
def __init__(self, **kwargs): | ||
super().__init__( | ||
sprite_front_is_up=True, | ||
filename=":spg:agent/base.png", | ||
shape_approximation="decomposition", | ||
mass=BASE_MASS, | ||
**kwargs, | ||
) | ||
|
||
|
||
class HolonomicAgent(DynamicAgent, ABC): | ||
def _apply_action(self, action): | ||
|
||
forward_force, lateral_force, angular_velocity = action | ||
|
||
self.pm_body.apply_force_at_local_point( | ||
pymunk.Vec2d(forward_force, lateral_force) * LINEAR_FORCE, (0, 0) | ||
) | ||
|
||
self.pm_body.angular_velocity = angular_velocity * ANGULAR_VELOCITY | ||
|
||
|
||
class HolonomicContinuousAgent(HolonomicAgent, ABC): | ||
@property | ||
def _action_space(self): | ||
return spaces.Box(low=-1, high=1, shape=(3,)) | ||
|
||
|
||
class HolonomicDiscreteAgent(HolonomicAgent, ABC): | ||
@property | ||
def _action_space(self): | ||
return spaces.MultiDiscrete([3, 3, 3], start=[-1, -1, -1]) | ||
|
||
|
||
class ForwardAgent(DynamicAgent, ABC): | ||
def _apply_action(self, action): | ||
|
||
forward_force, angular_velocity = action | ||
|
||
self.pm_body.apply_force_at_local_point( | ||
pymunk.Vec2d(forward_force, 0) * LINEAR_FORCE, (0, 0) | ||
) | ||
|
||
self.pm_body.angular_velocity = angular_velocity * ANGULAR_VELOCITY | ||
|
||
|
||
class ForwardContinuousAgent(ForwardAgent, ABC): | ||
@property | ||
def _action_space(self): | ||
return spaces.Box(low=-1, high=1, shape=(2,)) | ||
|
||
|
||
class ForwardDiscreteAgent(ForwardAgent, ABC): | ||
@property | ||
def _action_space(self): | ||
return spaces.MultiDiscrete([3, 3], start=[-1, -1]) | ||
|
||
|
||
class StaticAgent(Agent, BaseStaticMixin, ABC): | ||
def __init__(self, **kwargs): | ||
super().__init__( | ||
sprite_front_is_up=True, | ||
filename=":spg:agent/base.png", | ||
shape_approximation="decomposition", | ||
**kwargs, | ||
) | ||
|
||
@property | ||
def _action_space(self): | ||
return None | ||
|
||
def _apply_action(self, action): | ||
pass |
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 |
---|---|---|
|
@@ -5,3 +5,7 @@ | |
|
||
|
||
DEFAULT_INTERACTION_RANGE = 5 | ||
|
||
BASE_MASS = 10 | ||
ARM_MASS = 5 | ||
HEAD_MASS = 5 |
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,57 @@ | ||
from gymnasium import spaces | ||
|
||
from spg.core.entity import Entity | ||
from spg.core.entity.body import AttachedStaticMixin | ||
from spg.core.entity.interaction.activable import ActivableMixin | ||
from spg.core.entity.interaction.grasper import GrasperHold | ||
from spg.core.entity.sprite import get_texture_from_geometry | ||
|
||
|
||
class Trigger(Entity, ActivableMixin, AttachedStaticMixin): | ||
def __init__(self, **kwargs): | ||
|
||
texture, _ = get_texture_from_geometry( | ||
geometry="circle", radius=20, color=(255, 0, 0) | ||
) | ||
|
||
super().__init__(ghost=True, texture=texture, **kwargs) | ||
|
||
self.triggered = False | ||
|
||
def activate(self, entity, **kwargs): | ||
self.activated = True | ||
|
||
def pre_step(self): | ||
self.triggered = False | ||
super().pre_step() | ||
|
||
@property | ||
def attachment_point(self): | ||
return 0, 0 | ||
|
||
@property | ||
def action_space(self): | ||
return spaces.Discrete(2) | ||
|
||
def apply_action(self, action): | ||
self.triggered = bool(action) | ||
|
||
|
||
class GrasperHand(Entity, AttachedStaticMixin, GrasperHold): | ||
def __init__(self, grasper_radius, **kwargs): | ||
|
||
texture, _ = get_texture_from_geometry( | ||
geometry="circle", radius=grasper_radius, color=(255, 0, 0) | ||
) | ||
|
||
super().__init__( | ||
texture=texture, | ||
ghost=True, | ||
**kwargs, | ||
) | ||
|
||
GrasperHold.__init__(self) | ||
|
||
@property | ||
def attachment_point(self): | ||
return 0, 0 |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.