Search
Your task will be to finish the prepared factorgraph localization pipeline to allow more precise localization of the robot and markers placed in the world.
Responsible lecturer: Martin Pecka (peckama2@fel.cvut.cz)
Relevant lectures: 00_1d_mle.pdf, 00_2d_mle.pdf
One of the drawbacks of ICP SLAM was that it was difficult to correct the ICP map built from historical measurements. Factorgraph SLAM allows to fully propagate all newly acquired knowledge about the world (observations/measurements) through the whole history of the robot motion and potentially fix even mapping/localization errors made earlier.
The particular task we solve in this homework has the following definition:
${\displaystyle \underset{x_0,\ldots,x_T,m^r}{\mathrm{argmin}} \sum_t ||w2r(x_{t+1}, x_t) − z^{odom}_t||^2_{\Sigma^{odom}_t} + \sum_t ||w2r(m^a, x_t) − z^{m^a}_t||^2_{\Sigma^{m^a}_t} + \sum_t ||w2r(m^r, x_t) − z^{m^r}_t||^2_{\Sigma^{m^r}_t} + \sum_t ||w2r(x_{t+1}, x_t) − z^{icp}_t||^2_{\Sigma^{icp}_t}}$
aro_exploration/src/aro_localization/factor_graph.py
TODO HW 4:
FIXME:
debug_localization
If you don't know how to solve some of the tasks, see Task details.
The following tests will be run to evaluate your submission:
res()
res_jac()
factor_graph_demo()
Run script aro_exploration/create_hw_04_zip.sh to create an archive for Brute. Upload the archive to Brute. Your factor_graph.py file will be used on a set of static datasets to find out it works correctly. Only the factor_graph.py will be used for tests with a predefined set of configurations. So your configuration YAML files will not be used for the Brute tests.
aro_exploration/create_hw_04_zip.sh
factor_graph.py
These files are relevant for the localization. It should be okay to edit just factor_graph.py, but you might also want to change some of the YAML configs. Other files should not be modified.
aro_exploration/config/localization
aro_exploration/launch/localization
aro_localization.launch.xml
aro_localization_sim.launch.xml
aro_exploration/aro_localization/localization/aro_localization.py
You can directly run the Python module using python3 aro_localization/factor_graph.py (run it from folder aro_exploration/src; if it cannot import aro_exploration, then export PYTHONPATH=/path/to/your/student-packages/aro_exploration/src:$PYTHONPATH). There are some static data your code will be tested on. Passing these tests is mandatory for having a chance that the whole localization algorithm will work. The script will tell you the achieved marker localization accuracy on a randomly generated trajectory. Try to achieve accuracy better than 0.2 m in most cases.
python3 aro_localization/factor_graph.py
aro_exploration/src
aro_exploration
export PYTHONPATH=/path/to/your/student-packages/aro_exploration/src:$PYTHONPATH
You can also run python3 -m unittest aro_exploration/src/aro_localization/factor_graph.py (or instruct the IDE to run unit tests). There are some unit tests your code will be tested with. Passing these tests is mandatory (but not sufficient) for getting points for the tested functionalities.
python3 -m unittest aro_exploration/src/aro_localization/factor_graph.py
You can also run ros2 launch aro_exploration aro_localization_sim.launch.xml world:=aro_maze_1 to test your code interactively in various simulated worlds. Read further to find out how to (interactively) control the robot.
ros2 launch aro_exploration aro_localization_sim.launch.xml world:=aro_maze_1
To use your random walking algorithm from HW 02, call the roslaunch like this: ros2 launch aro_exploration aro_localization_sim.launch.xml world:=aro_maze_1 reactive_control:=true
ros2 launch aro_exploration aro_localization_sim.launch.xml world:=aro_maze_1 reactive_control:=true
The launch file has also parameter fuse_icp_slam which controls whether your ICP SLAM implementation generates additional factors for the localization or not. This parameter is turned on by default.
fuse_icp_slam
The launch file has also argument debug_localization which enables debug (green) messages in the console from the aro_localization node. This argument is set to true when launching aro_localization_sim.launch.xml and defaults to false when the localization is launched by later homeworks or the semestral work. However, you are free to pass debug_localization:=true even to these later homeworks to see how the factorgraph is doing. If, in your code, you use loginfo() or logwarn() to log some information, it will be shown regardless of the setting of this argument. Only logdebug() prints are affected.
aro_localization
debug_localization:=true
loginfo()
logwarn()
logdebug()
Difficult worlds
To test the localization on a world where ICP odometry may fail horribly, test with world aro_hallway_1 and point_to_plane ICP alignment.
aro_hallway_1
point_to_plane
Gamepad teleoperation
If you have a gamepad that works on Linux, you should be able to use it to control the simulated robot. Keep top right trigger button (RB) pressed all the time and use left thumbstick to control the robot. XBox gamepads via dongle can be used with the xow or xone drivers (do not mix both!). It is, however, much easier to use them connected via USB-C cable.
On MacOS and some other computers, the touchpad may be recognized as a gamepad, too. If it is selected as the default one, use joy_dev_id:=1 argument for launch files to select a different one.
joy_dev_id:=1
Keyboard teleoperation
If you add roslaunch argument keyboard_teleop:=true, it opens a window in which you can control the robot using WXAD keys to test your algorithm.
keyboard_teleop:=true
RViz visualization
The launch file aro_exploration/launch/localization/aro_localization_sim.launch.xml starts also a preconfigured RViz window that shows several odometry estimates. It also shows a visualization of the marker pose estimates and ground truth. Color-coding of the visualized entities is the same as in the Factorgraph visualization section. The displayed image shows a superposition of the camera image and the detected Apriltags. The small pink ellipses visualize covariance of the ICP odometry (it is enlarged for visualization purposes by a factor).
aro_exploration/launch/localization/aro_localization_sim.launch.xml
Please note that there are problems with time synchronization in the RViz window, so things will be slightly jumping around when the robot is driving. It is normal and nothing to be scared of. It is only a visualization problem.
Factorgraph visualization
The launch file aro_exploration/launch/localization/aro_localization_sim.launch.xml also opens a Matplotlib window that shows some interesting parts of the factorgraph internals. Use this window to examine the values of residuals, distances from ground truth etc.
You can see multiple odometries. The blue one is the output of the factor graph localization. Red odometry is ground truth from simulator. Green one is ICP odometry, and yellow is wheel-odometry. You can also see visualization of the poses of markers (and the estimated pose of the relative marker).
Second from top, there is visualizatíon of yaw (heading) of the robot. Color coding is the same as for the first subplot.
Third and fourth are visualizations of the residuals (errors in individual factors). The first of these two shows unscaled residuals, i.e. residuals before applying cost. The latter shows the actual residual values including costs that were used for the optimization.
Last two graphs show error of the odometries compared to ground truth (you can also observe the errors in each of the 3 estimated dimensions x, y, yaw).
Working with bag files
If you found a critical point for your algorithm you want to improve or if the Gazebo simulation is too slow on your computer, you can record a bag file of the simulation and then run your Factorgraph localization again on this bag file. This has the benefits of being much faster and much more repeatable than manually driving around.
To record the bag file, add record:=true argument to your simulation launch command. After you quit the simulation, you will find the bag file at /tmp/WORLD_NAME_loc_input where WORLD_NAME is the name of the world used in simulation.
record:=true
/tmp/WORLD_NAME_loc_input
To replay the bag file and run your ICP implementation, run ros2 launch aro_exploration aro_localization_bag.launch.xml bag:=/tmp/WORLD_NAME_loc_input.
ros2 launch aro_exploration aro_localization_bag.launch.xml bag:=/tmp/WORLD_NAME_loc_input
Deadline: Before the start of Lab 9.
What to do:
ros2 launch aro_exploration aro_localization_real.launch.xml
run_driver:=false
ros2 launch aro_exploration/launch/localization/record.launch.xml record_output:=true
ros2 bag info
/tmp
fused_odom
What to submit: A single ZIP archive containing the BAG file(s), PDF and photos. File upload limit is 350 MB. Submit the archive to task hw04-bonus in Brute.
There are a few differences between the simulator and the real robot:
scipy.linalg.sqrtm()
/odom
/apriltag
res_odom
res_mr
res_ma
res_icp
J
J1
solver_options
aro_exploration/config/localization/solver.yaml
aro_exploration/config/localization/costs_icp.yaml
Jacobian as a sparse matrix.
In this homework, you are not required to touch the ROS node at all. It is quite complicated so we did all the heavy lifting for you. However, it might come handy to know how does the node behave.
This is definition of the API of the aro_localization node.
Only the important parameters are listed here. For the full view, refer to aro_exploration/aro_exploration/localization/aro_localization source code.
aro_exploration/aro_exploration/localization/aro_localization
map_frame
odom_frame
odom
body_frame
publish_tf
invert_tf
max_iters
c_
/marker_config
abs_marker_id
abs_marker_x
abs_marker_y
abs_marker_yaw
rel_marker_id
rel_marker_gt_x
rel_marker_gt_y
rel_marker_gt_yaw
apriltag
icp_odom
ground_truth_odom
mobile_base/sensors/core
bumper
fused_odom_viz
fused_odom_path
relative_marker_pose
map_frame_fast
fused_map_fast_publisher
Fig. 1: Example of Apriltags. Image courtesy of https://april.eecs.umich.edu/software/apriltag.
Apriltags are visual markers designed specifically so that it is easy to estimate their pose in full 6 DOF (x, y, z, roll, pitch, yaw). Thus they are very comfortable for being used as absolute localization markers. Moreover, they are easily distinguishable from each other, so the detector can output not only the 6 DOFs of the marker, but also its unique ID.
Here is an example of a tag localized by the ROS node from package apriltag_ros:
apriltag_ros