Skip to content

Commit

Permalink
Merge branch 'main' into fix-pytests
Browse files Browse the repository at this point in the history
  • Loading branch information
hollandjg authored Oct 9, 2024
2 parents b8b0b06 + 661945c commit 1187754
Show file tree
Hide file tree
Showing 20 changed files with 444 additions and 316 deletions.
6 changes: 6 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@
"version": "3.11"
}
}
"customizations": {
"vscode": {
"extensions": [
"ms-python.black-formatter"
]
}
}
10 changes: 10 additions & 0 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Lint

on: pull_request

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: psf/black@stable
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ __pycache__/
# due to using tox and pytest
.tox
.cache
.venv/
.venv/

# Project specific files
db.json
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
"python.testing.pytestArgs": [
"."
],
Expand Down
81 changes: 43 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,44 @@
# A sample Python project
# Social Norms Trees
Experiments on teaching social norms to autonomous agents.

## Developer Setup

Prerequisites:
- Python 3.11+
- git

Clone the repository:
```bash
git clone https://github.com/brown-ccv/social-norms-trees
```

Enter the repository directory:
```bash
cd social-norms-trees
```

Create a virtual environment:
```bash
python3 -m venv .venv
```

Activate the environment:
```bash
. .venv/bin/activate
```

Install the package in editable mode for development:
```bash
pip install --editable ".[test]"
```

Run the tests:
```bash
pytest
```

Run the example experiment:
```bash
social-norms-trees examples/entering-a-room.json
```

![Python Logo](https://www.python.org/static/community_logos/python-logo.png "Sample inline image")

A sample project that exists as an aid to the [Python Packaging User
Guide][packaging guide]'s [Tutorial on Packaging and Distributing
Projects][distribution tutorial].

This project does not aim to cover best practices for Python project
development as a whole. For example, it does not provide guidance or tool
recommendations for version control, documentation, or testing.

[The source for this project is available here][src].

The metadata for a Python project is defined in the `pyproject.toml` file,
an example of which is included in this project. You should edit this file
accordingly to adapt this sample project to your needs.

----

This is the README file for the project.

The file should use UTF-8 encoding and can be written using
[reStructuredText][rst] or [markdown][md use] with the appropriate [key set][md
use]. It will be used to generate the project webpage on PyPI and will be
displayed as the project homepage on common code-hosting services, and should be
written for that purpose.

Typical contents for this file would include an overview of the project, basic
usage examples, etc. Generally, including the project changelog in here is not a
good idea, although a simple “What's New” section for the most recent version
may be appropriate.

[packaging guide]: https://packaging.python.org
[distribution tutorial]: https://packaging.python.org/tutorials/packaging-projects/
[src]: https://github.com/pypa/sampleproject
[rst]: http://docutils.sourceforge.net/rst.html
[md]: https://tools.ietf.org/html/rfc7764#section-3.5 "CommonMark variant"
[md use]: https://packaging.python.org/specifications/core-metadata/#description-content-type-optional
3 changes: 3 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Example Experiments

This directory includes configuration files for example experiments.
File renamed without changes.
84 changes: 84 additions & 0 deletions examples/entering-a-room.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"context": "A nurse assistant robot in a hospital is taking medicine to Mrs. Jones during the day. The robot has already collected the medicine and enters the corridor outside Mrs. Jones' room. It needs to enter the room to take Mrs. Jones her medicine.",
"behavior_tree": {
"name": "",
"type": "Sequence",
"children": [
{
"name": "Approach the door",
"type": "Behavior"
},
{
"name": "Open the door",
"type": "Behavior"
},
{
"name": "Go through the doorway",
"type": "Behavior"
}
]
},
"behavior_library": [
{
"id": "anonymous-sequence",
"display_name": "",
"type": "Sequence",
"show": false
},
{
"id": "approach-door",
"display_name": "Approach the door",
"type": "Behavior",
"show": true
},
{
"id": "open-door",
"display_name": "Open the door",
"type": "Behavior",
"show": true
},
{
"id": "go-through-doorway",
"display_name": "Go through the doorway",
"type": "Behavior",
"show": true
},
{
"id": "knock-on-the-door",
"display_name": "Knock on the door",
"type": "Behavior",
"show": true
},
{
"id": "sing-a-song",
"display_name": "Sing a song",
"type": "Behavior",
"show": true
},
{
"id": "announce-your-presence",
"display_name": "Announce your presence",
"type": "Behavior",
"show": true
},
{
"id": "contact-supervisor-guidance",
"display_name": "Contact supervisor for guidance",
"type": "Behavior",
"show": true
},
{
"id": "stop",
"display_name": "Stop",
"type": "Behavior",
"show": true
},
{
"id": "return-to-charging-station",
"display_name": "Return to charging station",
"type": "Behavior",
"show": false
}
]

}
7 changes: 3 additions & 4 deletions norms/ball.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,9 @@ def create_root() -> py_trees.behaviour.Behaviour:
eventually=py_trees.common.Status.SUCCESS,
)
approach = py_trees.behaviours.Running(name="Approach Ball")

move_to_ball.add_children([isClose, approach])


isGrasped = py_trees.behaviours.StatusQueue(
name="Ball Grasped?",
queue=[
Expand All @@ -160,7 +159,7 @@ def create_root() -> py_trees.behaviour.Behaviour:
eventually=py_trees.common.Status.SUCCESS,
)
grasp = py_trees.behaviours.Running(name="Grasp Ball")

obtain_ball.add_children([isGrasped, grasp])

return root
Expand Down Expand Up @@ -204,4 +203,4 @@ def main() -> None:


if __name__ == "__main__":
main()
main()
29 changes: 14 additions & 15 deletions norms/ball_blackboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
blackboard.isBallClose = False
blackboard.isBallGrasped = False


def description() -> str:
"""
Print description and usage information about the program.
Expand Down Expand Up @@ -146,28 +147,26 @@ def create_root() -> py_trees.behaviour.Behaviour:

print(blackboard)


isClose = py_trees.behaviours.CheckBlackboardVariableValue(
name="Ball Close?",
check=py_trees.common.ComparisonExpression(
variable="isBallClose", value=True, operator=operator.eq
),
)
name="Ball Close?",
check=py_trees.common.ComparisonExpression(
variable="isBallClose", value=True, operator=operator.eq
),
)

approach = py_trees.behaviours.Running(name="Approach Ball")

move_to_ball.add_children([isClose, approach])

move_to_ball.add_children([isClose, approach])

isGrasped = py_trees.behaviours.CheckBlackboardVariableValue(
name="Ball Grasped?",
check=py_trees.common.ComparisonExpression(
variable="isBallGrasped", value=True, operator=operator.eq
),
)
name="Ball Grasped?",
check=py_trees.common.ComparisonExpression(
variable="isBallGrasped", value=True, operator=operator.eq
),
)

grasp = py_trees.behaviours.Running(name="Grasp Ball")

obtain_ball.add_children([isGrasped, grasp])

return root
Expand Down Expand Up @@ -218,4 +217,4 @@ def main() -> None:


if __name__ == "__main__":
main()
main()
Loading

0 comments on commit 1187754

Please sign in to comment.