-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow Indirect Field Accesses in Proto Templates (#6614)
* allow indirectly referencing proto fields * update other regular expression * add test * fix test worlds * update changelog * use spaces for indentation * update proto headers * run clang-format * enable fields variable with a tag * update regex tests * update docs * update changelog * run clang-format * add curly brackets * fix comment indentation * fix proto name * fix controller name * update the changelog * fix indentation Co-authored-by: Olivier Michel <[email protected]> --------- Co-authored-by: Olivier Michel <[email protected]>
- Loading branch information
Showing
12 changed files
with
213 additions
and
27 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
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
1 change: 1 addition & 0 deletions
1
tests/protos/controllers/template_indirect_field_access/.gitignore
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 @@ | ||
/template_indirect_field_access |
19 changes: 19 additions & 0 deletions
19
tests/protos/controllers/template_indirect_field_access/Makefile
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,19 @@ | ||
# Copyright 1996-2023 Cyberbotics Ltd. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
### Do not modify: this includes Webots global Makefile.include | ||
null := | ||
space := $(null) $(null) | ||
WEBOTS_HOME_PATH?=$(subst $(space),\ ,$(strip $(subst \,/,$(WEBOTS_HOME)))) | ||
include $(WEBOTS_HOME_PATH)/resources/Makefile.include |
19 changes: 19 additions & 0 deletions
19
tests/protos/controllers/template_indirect_field_access/template_indirect_field_access.c
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,19 @@ | ||
#include <webots/motor.h> | ||
#include <webots/robot.h> | ||
#include <webots/supervisor.h> | ||
|
||
#include "../../../lib/ts_assertion.h" | ||
#include "../../../lib/ts_utils.h" | ||
|
||
#define TIME_STEP 32 | ||
|
||
int main(int argc, char **argv) { | ||
ts_setup(argv[1]); // give the controller args | ||
WbNodeRef proto = wb_supervisor_node_get_from_def("PROTO_template_indirect_field_access"); | ||
WbFieldRef radarCrossSection = wb_supervisor_node_get_proto_field(proto, "radarCrossSection"); | ||
ts_assert_double_in_delta(wb_supervisor_field_get_sf_float(radarCrossSection), 6.0, 0.0001, | ||
"radarCrossSection should be 6.0"); | ||
ts_send_success(); | ||
|
||
return EXIT_SUCCESS; | ||
} |
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,18 @@ | ||
#VRML_SIM R2024a utf8 | ||
# tags: indirectFieldAccess | ||
# template language: javascript | ||
|
||
PROTO TemplateIndirectFieldAccess [ | ||
unconnectedField SFFloat field1 1 | ||
unconnectedField SFFloat field2 5 | ||
] | ||
{ | ||
Solid { | ||
%< | ||
function sum(fieldsObj) { | ||
return fieldsObj.field1.value + fieldsObj.field2.value; | ||
} | ||
>% | ||
radarCrossSection %<= sum(fields) >% | ||
} | ||
} |
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,17 @@ | ||
#VRML_SIM R2024a utf8 | ||
# tags: indirectFieldAccess | ||
|
||
PROTO TemplateIndirectFieldAccessLua [ | ||
unconnectedField SFFloat field1 1 | ||
unconnectedField SFFloat field2 5 | ||
] | ||
{ | ||
Solid { | ||
%{ | ||
function sum(fieldsObj) | ||
return fieldsObj.field1.value + fieldsObj.field2.value; | ||
end | ||
}% | ||
radarCrossSection %{= sum(fields) }% | ||
} | ||
} |
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,39 @@ | ||
#VRML_SIM R2024a utf8 | ||
|
||
EXTERNPROTO "webots://tests/protos/protos/TemplateIndirectFieldAccess.proto" | ||
EXTERNPROTO "webots://tests/default/protos/TestSuiteEmitter.proto" | ||
EXTERNPROTO "webots://tests/default/protos/TestSuiteSupervisor.proto" | ||
|
||
WorldInfo { | ||
coordinateSystem "NUE" | ||
lineScale 1 | ||
} | ||
Viewpoint { | ||
orientation -0.8999515417256047 0.42450878383113183 0.0993957493855782 0.509061 | ||
position 0.303563 0.46348 0.936228 | ||
} | ||
Background { | ||
skyColor [ | ||
0 0.811765 0.992157 | ||
] | ||
} | ||
DirectionalLight { | ||
direction 0 0.5 -1 | ||
} | ||
Robot { | ||
translation 0.1 0 0.15 | ||
rotation 0 1 0 1.5708 | ||
children [ | ||
DEF PROTO_template_indirect_field_access TemplateIndirectFieldAccess { | ||
} | ||
TestSuiteEmitter { | ||
} | ||
] | ||
controller "template_indirect_field_access" | ||
controllerArgs [ | ||
"template_indirect_field_access" | ||
] | ||
supervisor TRUE | ||
} | ||
TestSuiteSupervisor { | ||
} |
39 changes: 39 additions & 0 deletions
39
tests/protos/worlds/template_indirect_field_access_lua.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,39 @@ | ||
#VRML_SIM R2024a utf8 | ||
|
||
EXTERNPROTO "webots://tests/protos/protos/TemplateIndirectFieldAccessLua.proto" | ||
EXTERNPROTO "webots://tests/default/protos/TestSuiteEmitter.proto" | ||
EXTERNPROTO "webots://tests/default/protos/TestSuiteSupervisor.proto" | ||
|
||
WorldInfo { | ||
coordinateSystem "NUE" | ||
lineScale 1 | ||
} | ||
Viewpoint { | ||
orientation -0.8999515417256047 0.42450878383113183 0.0993957493855782 0.509061 | ||
position 0.303563 0.46348 0.936228 | ||
} | ||
Background { | ||
skyColor [ | ||
0 0.811765 0.992157 | ||
] | ||
} | ||
DirectionalLight { | ||
direction 0 0.5 -1 | ||
} | ||
Robot { | ||
translation 0.1 0 0.15 | ||
rotation 0 1 0 1.5708 | ||
children [ | ||
DEF PROTO_template_indirect_field_access TemplateIndirectFieldAccessLua { | ||
} | ||
TestSuiteEmitter { | ||
} | ||
] | ||
controller "template_indirect_field_access" | ||
controllerArgs [ | ||
"template_indirect_field_access (lua)" | ||
] | ||
supervisor TRUE | ||
} | ||
TestSuiteSupervisor { | ||
} |