Test: The ekf Switch of the Launch Files
The ekf argument has to do several things at once in several launch files, as Which launch file starts what shows. With ekf:=true, a launch file that starts the robot or the simulation starts the EKF and the IMU sample validator and turns off the drive controller's transform odom → base_footprint. A launch file that starts a planner makes the planner read the EKF's odometry by default. diffbot_navigation's move_base.launch also takes the argument odom_topic, which names another topic. Without ekf:=true, none of this may happen. The test proves that the launch files are written this way, for both positions of the switch and for its default. The test reads the launch files and starts nothing. So the test doesn't prove that the nodes run or that they work together. The stepped-clock test and the test in Gazebo start them.
Two launch files, read without starting them
roslaunch has a loader that reads a launch file and everything that the file includes, and returns what roslaunch would start: the nodes, the parameters and the remappings. The test calls this loader and looks at the result. No ROS master and no node run. Two examples show what the loader returns, in a run at the commit 27d72a4 of the diffbot repository:
- A launch file that starts the simulation: for
roslaunch diffbot_gazebo diffbot.launch ekf:=true, the loader returns nine nodes. Two of them are the EKF,/diffbot/ekf_localization, and the IMU sample validator,/diffbot/imu_validator. The parameter/diffbot/mobile_base_controller/enable_odom_tfisFalse, so the drive controller doesn't publish the transformodom → base_footprint. Without theekfargument, the loader returns seven nodes, without these two, andenable_odom_tfisTrue. - A launch file that starts only a planner: for
roslaunch diffbot_navigation move_base.launch ekf:=true, the loader returns one node, the planner/move_base. The planner's nameodomis remapped to/diffbot/odometry/filtered, the EKF's odometry. Without theekfargument,odomis remapped to/diffbot/mobile_base_controller/odom, the drive controller's wheel odometry. This launch file starts no EKF and sets noenable_odom_tf, so the test checks only the planner's topic here.
The figure shows this flow from top to bottom, for the first example. The test's function load() gives the launch file and its arguments to roslaunch's loader, load_config_default(). load() returns the loader's result as a LaunchConfiguration with three fields, and the test's assertions look at these fields. The box at the bottom left names one of these assertions for the first example. The dashed box is what roslaunch would do after loading, which the test leaves out.
- what roslaunch would do next and the test leaves out
test_ekf_switch.py works, from top to bottom, for one of its launch files.Run it
Run the test alone from a shell in the built workspace of the dev container:
1 2 3 4 | |
The test needs no ROS master and no Gazebo. A pass prints one line for each of the five tests, each ending in ok, and OK at the end. catkin runs the test with the repository's other tests.
The registration, the output of a run and the test dependencies
catkin runs the test with the repository's other tests. The excerpt shows where diffbot_gazebo registers the test, from CMakeLists.txt, lines 225–226:
| diffbot_gazebo/CMakeLists.txt: the test's registration | |
|---|---|
225 226 | |
The test needs no ROS master and no Gazebo. In a run at the commit 27d72a4 in the dev container's image, the test printed one line for each of its five tests, and OK at the end because every test passed:
1 2 3 4 5 6 7 8 9 10 | |
The test loads the launch files of diffbot_bringup, diffbot_navigation and diffbot_mbf, so diffbot_gazebo's package.xml lists these three packages as test dependencies.
What a pass proves and what a failure means
A pass proves these results of roslaunch's loader:
- The robot and the simulation: with
ekf:=true,diffbot_bringup's two launch files and the two simulation filesdiffbot.launchstart the EKF and the IMU sample validator and turn off the drive controller's transform. Withekf:=falseand by default, they start neither node and keep the transform on. - The planners: the four planner launch files of the table give the planner the EKF's odometry with
ekf:=trueand the wheel odometry by default.move_base.launchkeeps an explicitodom_topicalso withekf:=true. - The simulation with navigation: with
ekf:=true,diffbot_navigation'sdiffbot.launchstarts the EKF and the validator, turns off the controller's transform and gives its planner the EKF's odometry.
A failure's message includes the launch file with its arguments and names what is missing or wrong, such as a node that doesn't start or the planner's odom remapped to another topic.
What the test doesn't show
- Running nodes: the loader reads the launch files. Nothing starts, so the test can't see whether a node runs, publishes or finds its transforms.
robot_state_publisherin every file: the test assertsrobot_state_publisherfor the two bringup files and for the two simulation files nameddiffbot.launch, ofdiffbot_gazeboand ofdiffbot_control. The test doesn't assert the node forminimal.launch, which doesn't startrobot_state_publisher.ekf:=falsefor the planners: for the planners' launch files, the test loads the default andekf:=true.- Other ways to start the robot: the robot container starts
bringup.launchwithoutekf. The test doesn't read the container's settings.
The five tests
test_ekf_switch.py has five tests. Each test loads one kind of launch file:
| Test | Launch files | What it checks |
|---|---|---|
test_bringup_starts_the_ekf_and_the_validator_only_with_ekf_true |
diffbot_bringup: bringup.launch, bringup_with_laser.launch |
Both positions of the switch |
test_simulation_starts_the_ekf_and_the_validator_only_with_ekf_true |
diffbot_gazebo: diffbot.launch. diffbot_control: diffbot.launch |
Both positions of the switch |
test_planners_read_the_filtered_odometry_only_with_ekf_true |
diffbot_navigation: move_base.launch, diffbot_navigation.launch, diffbot_hw.launch. diffbot_mbf: amcl_demo.launch |
The planner's odometry topic |
test_planner_reads_an_explicit_odom_topic_also_with_ekf_true |
diffbot_navigation: move_base.launch |
The planner's odometry topic |
test_navigation_simulation_starts_the_ekf_for_its_planner_with_ekf_true |
diffbot_navigation: diffbot.launch |
The simulation with navigation |
The two simulation files named diffbot.launch are different files. diffbot_gazebo/launch/diffbot.launch starts the simulation without RViz. diffbot_control/launch/diffbot.launch starts the same simulation and RViz.
The next table lists what the test asserts. Each group of rows is one kind of launch file. A row is one way in which the test loads the files of its group: on the left the launch arguments, on the right what the test asserts about the nodes and the parameters that roslaunch would start. The table uses three short forms:
- The nodes: the table leaves out the namespace
/diffbotof the nodesekf_localization,imu_validatorandrobot_state_publisher. - A planner reads a topic: the planner's node is among the nodes, and the node's name
odomis remapped to this topic. - The controller's odometry and the EKF's odometry: the topics
/diffbot/mobile_base_controller/odomand/diffbot/odometry/filtered, the test'sWHEEL_ODOMETRY_TOPICandFILTERED_TOPIC.
| Arguments | What the test asserts |
|---|---|
The launch files that start the robot or the simulation: bringup.launch and bringup_with_laser.launch of diffbot_bringup, diffbot.launch of diffbot_gazebo, diffbot.launch of diffbot_control | |
ekf:=false, and no ekf argument | Neither ekf_localization nor imu_validator is among the nodes.enable_odom_tf is True. |
ekf:=true | ekf_localization and imu_validator are among the nodes.enable_odom_tf is False.The five parameters in EKF_PARAMETERS have their values.robot_state_publisher is among the nodes. |
The launch files that start a planner: move_base.launch, diffbot_navigation.launch and diffbot_hw.launch of diffbot_navigation, which start the planner /move_base, and amcl_demo.launch of diffbot_mbf, which starts the planner /move_base_flex | |
no ekf argument | The planner reads the controller's odometry. |
ekf:=true | The planner reads the EKF's odometry. |
ekf:=true and an explicit odom_topic | Only move_base.launch, with odom_topic:=/other/odom: the planner reads the topic /other/odom. |
The launch file that starts the simulation and a planner: diffbot.launch of diffbot_navigation, loaded with open_rviz:=false | |
ekf:=true | ekf_localization and imu_validator are among the nodes.enable_odom_tf is False.The planner /move_base reads the EKF's odometry. |
Reading a launch file without starting it
The excerpt shows the test's own result type and the function that calls the loader, from test_ekf_switch.py, lines 55–74:
| test_ekf_switch.py: LaunchConfiguration and load() | |
|---|---|
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
The result's fields, and the constants
load(): takes a package, the name of a launch file in the package'slaunchfolder and the launch arguments.load('diffbot_gazebo', 'diffbot.launch', ekf='true')stands for the commandroslaunch diffbot_gazebo diffbot.launch ekf:=true.load_config_default(): is roslaunch's loader. The loader resolves the includes, the arguments and the conditions such asif="$(arg ekf)", as roslaunch does before it starts anything.nodes: a dictionary from each node's full name, for example/diffbot/ekf_localization, to roslaunch's description of the node. The loader keeps a node's namespace and its name apart, soload()joins them.parameters: a dictionary from each parameter's full name to its value.description: the launch file with its arguments, as text. Every failure message includes this text.
The constants of test_ekf_switch.py:
The excerpt shows the names that the test looks for, from test_ekf_switch.py, lines 31–50. The name of a constant ends in _NODE for a node, in _TOPIC for a topic and in _PARAMETER for a parameter. SWITCHED_OFF holds the two ways to run without the EKF, ekf:=false and no ekf argument. EKF_PARAMETERS holds five parameters of the EKF and of the validator with the values that ekf.yaml and ekf.launch give them.
| test_ekf_switch.py: the constants | |
|---|---|
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
Both positions of the switch
The first two tests call assert_ekf_switch() for the four launch files that start the robot or the simulation. assert_ekf_on() checks the switch with ekf:=true, and assert_ekf_off() with ekf:=false and without the argument.
The two tests, the checks on and off, and the assertion methods
The excerpt shows the two tests, from test_ekf_switch.py, lines 166–172:
| test_ekf_switch.py: the bringup files and the two simulation files | |
|---|---|
166 167 168 169 170 171 172 | |
assert_ekf_switch() checks the switch in both positions. The excerpt shows assert_ekf_on(), assert_ekf_off() and assert_ekf_switch(), from test_ekf_switch.py, lines 131–149:
| test_ekf_switch.py: the switch on, off, and both | |
|---|---|
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
Off, assert_ekf_off(), once with ekf:=false and once without the argument:
assert_no_ekf_nodes_start(): neitherEKF_NODE, which is/diffbot/ekf_localization, norVALIDATOR_NODE, which is/diffbot/imu_validator, is among the nodes.assert_controller_odom_tf(configuration, enabled=True): the parameterODOM_TF_PARAMETER, which is/diffbot/mobile_base_controller/enable_odom_tf, is set, and its value isTrue. So the drive controller publishes the transform.
On, assert_ekf_on(), with ekf:=true:
assert_ekf_nodes_start(): both nodes are among the nodes,EKF_NODEfrom the packagerobot_localizationwith the executableekf_localization_node, andVALIDATOR_NODEfromdiffbot_controlwithimu_validator.py.assert_controller_odom_tf(configuration, enabled=False):enable_odom_tfis set, and its value isFalse. So only the EKF publishes the transform.assert_ekf_reads_the_controller_and_the_validator(): the five parameters inEKF_PARAMETERShave their values. The EKF works in the frameodomfor the framebase_footprint, reads the topicsmobile_base_controller/odomandimu/data_validated, and the validator expects the frameimu_link.assert_state_publisher_starts():STATE_PUBLISHER_NODE, which is/diffbot/robot_state_publisher, is among the nodes. The EKF needs the transform betweenimu_linkandbase_footprint, which TF has fromrobot_state_publisher.
The assertion methods on the nodes and the parameters:
The excerpt shows the methods that assert_ekf_on() and assert_ekf_off() call, from test_ekf_switch.py, lines 85–129. assert_controller_odom_tf() uses assertIs(): a parameter that the launch file doesn't set gives None, which is neither True nor False, so the check fails for a missing parameter in both positions.
| test_ekf_switch.py: the assertions on the nodes and the parameters | |
|---|---|
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
The launch file has to write enable_odom_tf in both positions, because a parameter stays on the ROS parameter server as long as the ROS master runs. A false from a launch with the EKF would otherwise remain for a later launch without it.
The planner's odometry topic
A planner reads the robot's velocity from an odometry topic. With the EKF on, the planner has to read the EKF's estimate, so that its velocity and the transform come from the same estimate. The test checks the remapping of the planner's name odom with ekf:=true and without it, and that an explicit odom_topic wins.
assert_planner_follows_the_switch() loads a planner's launch file without the ekf argument and with ekf:=true. The excerpt shows it, from test_ekf_switch.py, lines 159–164:
| test_ekf_switch.py: assert_planner_follows_the_switch() | |
|---|---|
159 160 161 162 163 164 | |
Without the argument, the planner has to read WHEEL_ODOMETRY_TOPIC, the topic /diffbot/mobile_base_controller/odom. With ekf:=true, it has to read FILTERED_TOPIC, the topic /diffbot/odometry/filtered.
The check of one planner, the helper remapping() and the two tests
In a launch file, the planner's node gets the topic as a remapping of the name odom. The excerpt shows what the test asserts about this remapping, from test_ekf_switch.py, lines 151–157:
| test_ekf_switch.py: assert_planner_odometry() | |
|---|---|
151 152 153 154 155 156 157 | |
assert_planner_odometry() checks that the planner's node is among the nodes and that its name odom is remapped to topic.
assert_planner_odometry() reads the remapping with the helper remapping(). The excerpt shows the helper, from test_ekf_switch.py, lines 77–79:
| test_ekf_switch.py: remapping() | |
|---|---|
77 78 79 | |
roslaunch's description of a node holds the node's remappings as pairs of the name and what the name is remapped to. remapping() returns the second part for name, or None when the node has no such remapping.
The excerpt shows the two tests that use these methods, from test_ekf_switch.py, lines 174–187:
| test_ekf_switch.py: the planners | |
|---|---|
174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
- Three files with
move_base:move_base.launch,diffbot_navigation.launchanddiffbot_hw.launchofdiffbot_navigationstart the planner/move_base, the test'sMOVE_BASE_NODE. - One file with Move Base Flex:
amcl_demo.launchofdiffbot_mbfstarts the planner/move_base_flex, the test'sMOVE_BASE_FLEX_NODE. - An explicit topic wins:
move_base.launchhas anodom_topicargument. Its default is the EKF's topic withekf:=trueand the controller's topic without it. Withodom_topic:=/other/odomandekf:=true, the planner reads/other/odom.
These launch files start no EKF, so the test checks nothing else in them.
The simulation with navigation
diffbot_navigation's diffbot.launch starts the simulation and a planner together and passes ekf to both.
The test
The excerpt shows the test, from test_ekf_switch.py, lines 189–194:
| test_ekf_switch.py: the simulation with navigation | |
|---|---|
189 190 191 192 193 194 | |
With ekf:=true, the EKF and the validator start, enable_odom_tf is False, and /move_base reads FILTERED_TOPIC, the topic /diffbot/odometry/filtered. open_rviz:=false leaves RViz out of what the loader reads.
Comments
Comments are GitHub Discussions, shown with giscus. Loading them connects to giscus.app (hosted by Vercel, USA) and GitHub (USA); you need a GitHub account to comment.