11import os
22import pytest
33import rclpy
4- import json
54from launch .substitutions import (
65 LaunchConfiguration ,
76)
2322from artefacts_toolkit_testsuite .pytest import metrics_fixture
2423import yaml
2524from datetime import datetime
25+ from artefacts_toolkit_config import merge_ros_params_files
26+ #Currently requires https://github.com/art-e-fact/artefacts-toolkit-config/pull/8
2627
2728
2829ARTEFACTS_PARAMS_FILE = os .environ .get (
2930 "ARTEFACTS_SCENARIO_PARAMS_FILE" , "scenario_params.yaml"
3031)
3132
32- waypoints = yaml .safe_load ('''
33- waypoints:
34- - position:
35- x: 0.8006443977355957
36- y: 0.5491957664489746
37- z: 0.0
38- orientation:
39- x: 0.0
40- y: 0.0
41- z: -0.0055409271259092485
42- w: 0.9999846489454652
43- - position:
44- x: 1.8789787292480469
45- y: 0.5389942526817322
46- z: 0.0
47- orientation:
48- x: 0.0
49- y: 0.0
50- z: 0.010695864295550759
51- w: 0.9999427976074288
52- - position:
53- x: 3.0792641639709473
54- y: 0.6118782758712769
55- z: 0.0
56- orientation:
57- x: 0.0
58- y: 0.0
59- z: 0.01899610435153287
60- w: 0.9998195577300264
61- - position:
62- x: 3.8347740173339844
63- y: 0.012513279914855957
64- z: 0.0
65- orientation:
66- x: 0.0
67- y: 0.0
68- z: -0.7548200584119721
69- w: 0.6559319167558071
70- ''' )
7133waypoints = yaml .safe_load ('''
7234waypoints:
7335 - position:
144106 w: 0.6960848684271199
145107''' )
146108
147- def deep_merge_dicts (source , override ):
148- """Recursively merge two dictionaries, with values from `override` taking precedence over `source`"""
149- for key , value in override .items ():
150- if isinstance (value , dict ) and key in source :
151- source [key ] = deep_merge_dicts (source [key ], value )
152- else :
153- source [key ] = value
154- return source
155-
156- def rosify_params (params : dict ):
157- """
158- Store `params` in `param_file` and convert to ros2 param file nested format,
159- to be used by the launch file
160- """
161- content = {}
162- for k , v in params .items ():
163- try :
164- node , pname = k .split ("/" )
165- except Exception :
166- print (
167- localise (
168- "Problem with parameter name. Please ensure params are in the format `node/param`"
169- )
170- )
171- return
172- if node not in content :
173- content [node ] = {"ros__parameters" : {}}
174- # handles nested keys for params in the form of dot notation
175- current_level = content [node ]["ros__parameters" ]
176- keys = pname .split ("." )
177- for key in keys [:- 1 ]:
178- if key not in current_level :
179- current_level [key ] = {}
180- current_level = current_level [key ]
181- current_level [keys [- 1 ]] = v
182- return content
183-
184-
185- def merge_ros_params_files (source , override , destination ):
186- """Merge two ROS2 yaml parameter files into one, overriding the values in the first one with the values in `override`"""
187- import yaml
188-
189- with open (source , "r" ) as f :
190- source_params = yaml .safe_load (f )
191-
192- with open (override , "r" ) as f :
193- override_param = yaml .safe_load (f )
194- override_params_ros = rosify_params (override_param )
195-
196- merged_params = deep_merge_dicts (source_params , override_params_ros )
197- with open (destination , "w" ) as f :
198- yaml .dump (merged_params , f )
199-
200109
201110@pytest .fixture (scope = "module" )
202111def follow_waypoints_proc ():
@@ -222,7 +131,7 @@ def launch_description(follow_waypoints_proc, sim): #make sure sim is initialize
222131 new_params_file = "all_params.yaml"
223132 try :
224133 merge_ros_params_files (
225- source_params_file , ARTEFACTS_PARAMS_FILE , new_params_file
134+ source_params_file , ARTEFACTS_PARAMS_FILE , new_params_file , rosify = True
226135 )
227136 except FileNotFoundError :
228137 pass
@@ -352,7 +261,7 @@ def validate_nav2_output(output):
352261@pytest .mark .parametrize ("waypoint_idx" , range (len (waypoints ["waypoints" ])))
353262def test_1_reached_waypoint (follow_waypoints_proc , launch_context , sim , artefacts_metrics , waypoint_idx ):
354263 """Check that each waypoint is reached"""
355- #TODO, without async, check timing could be way too late
264+ # Somehow the test does not seem to be called before the end of the full waypoints navigation, preventing the use of now()
356265
357266 # Additional assertion using simulation state - wait for entity to be available
358267 print ("Now checking entity state after goal completion..." )
0 commit comments