-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: adding webots dynamic scenario tests #231
Open
abanuelo
wants to merge
14
commits into
main
Choose a base branch
from
abanuelo/add-webots-dynamic-scenario-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
efc4f85
feat: adding webots dynamic simulation, tbd tested
78fd123
feat: Adding functional webots tests
7cd82b6
fix: reformatting with black and isort and deleting unnecessary files
098f081
fix: improving code coverage
6df7598
fix: black formatting test_webots.py
96355ab
Merge branch 'main' of github.com:BerkeleyLearnVerify/Scenic into aba…
934dc90
Adding codecov yml updates from main branch
4f2ddcc
fix: also including tests directory to ignore for coverage, not relevant
f788b15
fix: adding checks for environment variables
7f1b677
fix: adjusting fixture call
2ac8d0b
fix: adding webots extension
5e5705b
fix: adding batch option to avoid popups
1182bc6
Merge branch 'abanuelo/add-webots-dynamic-scenario-tests' of github.c…
185fe3c
fix: resolving merge conflicts
abanuelo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
""" | ||
Create a Webots cube in air and have it drop | ||
""" | ||
|
||
model scenic.simulators.webots.model | ||
|
||
class Floor(Object): | ||
width: 5 | ||
length: 5 | ||
height: 0.01 | ||
position: (0,0,0) | ||
color: [0.785, 0.785, 0.785] | ||
|
||
class Block(WebotsObject): | ||
webotsAdhoc: {'physics': True} | ||
shape: BoxShape() | ||
width: 0.2 | ||
length: 0.2 | ||
height: 0.2 | ||
density: 100 | ||
color: [1, 0.502, 0] | ||
|
||
floor = new Floor | ||
ego = new Block at (0, 0, 0.5) #above floor by 0.5 | ||
|
||
terminate when ego.z < 0.1 | ||
record (ego.z) as BlockPosition |
30 changes: 30 additions & 0 deletions
30
.../simulators/webots/dynamic/webots_data/controllers/scenic_supervisor/scenic_supervisor.py
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,30 @@ | ||
import os | ||
|
||
from controller import Supervisor | ||
|
||
import scenic | ||
from scenic.simulators.webots import WebotsSimulator | ||
|
||
WEBOTS_RESULT_FILE_PATH = f"{os.path.dirname(__file__)}/../../../results.txt" | ||
|
||
|
||
def send_results(data): | ||
with open(WEBOTS_RESULT_FILE_PATH, "w") as file: | ||
file.write(data) | ||
|
||
|
||
supervisor = Supervisor() | ||
simulator = WebotsSimulator(supervisor) | ||
|
||
path = supervisor.getCustomData() | ||
print(f"Loading Scenic scenario {path}") | ||
scenario = scenic.scenarioFromFile(path) | ||
|
||
scene, _ = scenario.generate() | ||
simulation = simulator.simulate(scene, verbosity=2) | ||
block_movements = simulation.result.records["BlockPosition"] | ||
first_block_movement = block_movements[0] | ||
last_block_movement = block_movements[-1] | ||
blocks = [first_block_movement, last_block_movement] | ||
supervisor.simulationQuit(status="finished") | ||
send_results(str(blocks)) |
28 changes: 28 additions & 0 deletions
28
tests/simulators/webots/dynamic/webots_data/protos/ScenicObject.proto
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,28 @@ | ||
#VRML_SIM R2023a utf8 | ||
|
||
PROTO ScenicObject [ | ||
field SFVec3f translation 0 0 0 | ||
field SFRotation rotation 0 0 1 0 | ||
field SFString name "solid" | ||
field SFVec3f angularVelocity 0 0 0 | ||
field MFString url "" | ||
] | ||
{ | ||
Solid { | ||
translation IS translation | ||
rotation IS rotation | ||
name IS name | ||
angularVelocity IS angularVelocity | ||
children [ | ||
CadShape { | ||
url IS url | ||
castShadows FALSE | ||
} | ||
] | ||
boundingObject Shape { | ||
geometry Mesh { | ||
url IS url | ||
} | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
tests/simulators/webots/dynamic/webots_data/protos/ScenicObjectWithPhysics.proto
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 @@ | ||
#VRML_SIM R2023a utf8 | ||
|
||
PROTO ScenicObjectWithPhysics [ | ||
field SFVec3f translation 0 0 0 | ||
field SFRotation rotation 0 0 1 0 | ||
field SFString name "solid" | ||
field SFVec3f angularVelocity 0 0 0 | ||
field MFString url "" | ||
field SFFloat density 1000 # kg / m^3 | ||
] | ||
{ | ||
Solid { | ||
translation IS translation | ||
rotation IS rotation | ||
name IS name | ||
angularVelocity IS angularVelocity | ||
children [ | ||
CadShape { | ||
url IS url | ||
castShadows FALSE | ||
} | ||
] | ||
boundingObject Shape { | ||
geometry Mesh { | ||
url IS url | ||
} | ||
} | ||
physics Physics { | ||
# density will be set by the simulator | ||
density IS density | ||
mass -1 | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
tests/simulators/webots/dynamic/webots_data/worlds/world.wbt
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 @@ | ||
#VRML_SIM R2023a utf8 | ||
|
||
EXTERNPROTO "https://raw.githubusercontent.com/cyberbotics/webots/R2023a/projects/objects/backgrounds/protos/TexturedBackground.proto" | ||
EXTERNPROTO "https://raw.githubusercontent.com/cyberbotics/webots/R2023a/projects/objects/floors/protos/Floor.proto" | ||
IMPORTABLE EXTERNPROTO "../protos/ScenicObject.proto" | ||
IMPORTABLE EXTERNPROTO "../protos/ScenicObjectWithPhysics.proto" | ||
|
||
WorldInfo { | ||
gravity 3 | ||
basicTimeStep 16 | ||
contactProperties [ | ||
ContactProperties { | ||
coulombFriction [ | ||
0.8 | ||
] | ||
} | ||
] | ||
} | ||
Viewpoint { | ||
orientation -0.19729161510865992 0.07408415124219735 0.977541588446517 2.4380019050245862 | ||
position 6.683615307234937 -5.5006366813466805 4.16419445995153 | ||
} | ||
TexturedBackground { | ||
} | ||
Floor { | ||
name "FLOOR" | ||
size 5 5 | ||
} | ||
Robot { | ||
name "Supervisor" | ||
controller "scenic_supervisor" | ||
customData "../../../dynamic.scenic" | ||
supervisor TRUE | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a large upper bound to the time limit so if the test fails, it does so gracefully?