Simulation Testing - ArcturusNavigation/all_seaing_vehicle GitHub Wiki
Back: Tutorials |
---|
Running the launch file
To run the VRX simulation environment, run the following command. Remember to source your setup.bash
file.
ros2 launch all_seaing_bringup sim.launch.py
A Gazebo simulation environment, RViz 3D visualizer, and a keyboard popup window will open up. If you have the keyboard popup window selected, you can press Enter to toggle between autonomous and teleop mode, and press Space to E-stop. While in teleop mode, use the WASDQE keys to control the boat.
There are also a couple of flags you can use for launching sim.launch.py
. If you just want to see RViz and have Gazebo run in the background (no Gazebo GUI), you can do
ros2 launch all_seaing_bringup sim.launch.py no_gui:=true
To prevent RViz from launching, add launch_rviz:=false
.
Using RViz to move the boat
In addition to using the keyboard controller, you can use RViz to move the boat to a specified location. Once RViz is loaded, click on the Publish Point
button shown in the image below:
Then, click anywhere on the map. You should see a path get generated on the RViz map:
Now you are ready to move your boat autonomously! Press enter to toggle teleop <--> autonomous. Once in autonomous mode, the boat should follow the generated path!
Force-quitting the simulation environment
Typically, ctrl+c
is enough to stop running the simulation. However, there are some occasions where ctrl+c
gets "stuck." In this case, press ctrl+\
to force-quit.
When force-quitting, some processes (primarily gazebo) may continue to run in the background. To kill unwanted processes, install htop
, an interactive process viewer:
sudo apt update && sudo apt install htop
Now run htop
and navigate to the unfinished processes (look for anything with gazebo
or gz sim
) with the arrow keys and press F9
then 9
to kill.
Modifying the simulation script
The simulation script is located in all_seaing_vehicle/all_seaing_bringup/launch/vehicle.launch.py
. The script is in the form of a ROS launch file, which is essentially how to run multiple nodes with specified parameters all at once. Moving all the way to the bottom of the script, you should see something like
return [
ekf_node,
navsat_node,
controller_node,
...
keyboard_ld,
sim_ld,
perception_eval_node,
]
which are all the nodes that gets launched. A quick way to remove some node from being launched is to comment out the corresponding line in the Python list above.
Adding a new node to the launch file
To add a new node to the simulation script, use the following template:
some_cool_node = launch_ros.actions.Node(
package="package_name",
executable="name_of_the_executable",
remappings=[("some_topic", "remapped_topic")],
parameters=[
{"some_parameter": some_value},
],
output="screen",
)
In this case, the node is assigned to a variable named some_cool_node
. This node is in the package package_name
and it's executable name is name_of_the_executable
. The executable name is the same as what you need to type when you use ros2 run package_name executable_name
. For all_seaing_vehicle
, all Python node executables will have a .py
ending (this is because we are using CMake
as a build tool to allow cross-compatibility between Python and C++).
Only package=
and executable=
must be filled in to launch your node. However, there are some additional specifications you may add to your nodes. remappings=[("some_topic", "remapped_topic")]
assumes you use a topic named some_topic
inside your node, and you want to change that topic name to remapped_topic
when using this launch file. Thus, topic names inside your node should be quite generic (e.g. image
, and not /zed/zed_node/rgb/image_rect_color
); the generic topic name should be remapped in the launch file. parameters=
is used to assign values to ROS parameters used in your node. Finally, output="screen"
lets you see the ROS info/debug statements on your console. Removing this line prevents these messages from being printed on the console.
Using a different world to test your code
The various worlds you can use to test your code are listed here. Find the following lines:
sim_ld = IncludeLaunchDescription(
PythonLaunchDescriptionSource([vrx_gz_prefix, "/launch/competition.launch.py"]),
launch_arguments={
"world": "rb2025/rb2025_task1_task2.sdf",
"urdf": f"{description_prefix}/urdf/xdrive_wamv/wamv_target.urdf",
"extra_gz_args": extra_gz_args,
}.items(),
)
then, replace rb2025/rb2025_task1_task2.sdf
with the world you would like to test your code in. The worlds are from the Virtual RobotX competition; refer to the VRX 2023 task tutorials website for the different tasks.