Welcome to the project that achieved second place at ASTI 2024. It contains all the packages and programs used for the different challenges. This includes:
- ROS 2 Foxy with TurtleBot3 integration
- Gazebo simulation
- ROS packages
- A Docker setup
Operating system:
- Any OS, as long as it supports Docker. (In principle, this repository would require Ubuntu 20.04 with ROS 2 Foxy, which is what was used for development. However, since the degree courses recommend Ubuntu 22.04 with Humble, using Docker helps avoid compatibility problems.)
First, make sure you have installed on your system:
- Git (to clone this repository).
- Docker (like a virtual machine so you don’t break your laptop during installations). In this tutorial and this other one you can learn more about how Docker works and why it matters.
git clone https://github.com/diegomarzaa/asti2024.git
cd asti2024Use the included Dockerfile to build the full working environment. In that file you can see the full process used to set everything up. Run:
sudo docker build -t asti2024 .This will create an image named asti2024. You can verify it was created correctly with:
sudo docker imagesYou should see something similar to:
REPOSITORY TAG IMAGE ID CREATED SIZE
asti2024 latest 535bcd5d8e02 14 seconds ago 900MBchmod +x abrir-workspace-asti.sh
./abrir-workspace-asti.shSince it’s the first time, all ROS 2 workspace files will be built automatically. After that, you’ll be inside the container.
In the container opened with the abrir-workspace-asti.sh script, any change you make inside the asti2024_ws folder will also be reflected on your laptop. This way you can modify the code without fear of breaking anything.
There is also an alternative script, abrir-workspace-asti-tests.sh, which opens a fully isolated container. You can modify anything you want without worrying about breaking things, because once you exit the container, everything you did will be lost.
ros2 launch turtlebot3_gazebo turtlebot3_world.launch.pyros2 run final keyboard_teleop-
Permission denied on USB devices:
sudo chmod 777 /dev/ttyUSB0
-
Build failures: make sure you sourced everything correctly:
source /opt/ros/foxy/setup.bash source /root/asti2024/asti2024_ws/install/setup.bash
- Rosbags
# Record movements
ros2 bag record /cmd_vel# Play back movements
ros2 bag play rosbag2_<date>/rosbag2_<date>.db3- Raspberry Pi IP (on any Wi-Fi, no monitor)
sudo apt-get install arp-scan
sudo arp-scan --interface=wlo1 --localnet-
If it still doesn’t work:
sudo usermod -aG dialout pisudo chmod 777 /dev/ttyUSB0(or whatever port it is; it could be ttyUSB1, ttyUSB2, etc. Usels /dev/ttyUSB*to check)- Restart the motor controller. Connect USB + power.
- Try a different USB port.
-
Motor testing
ros2 run final keyboard_teleopros2 run teleop_twist_keyboard teleop_twist_keyboardros2 topic pub cmd_vel geometry_msgs/Twist "{linear: {x: 0.1, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.0}}"ros2 topic pub -1 /set_velocity custom_interfaces/SetVelocity "{id: 1, velocity: 50}"- (Id can be 1 or 2, and velocity can be + or -)
-
/etc/netplan/01-network-manager-all.yaml- The Wi-Fi network configuration is in this file.
- It allows the Raspberry Pi to automatically connect to whichever Wi-Fi you define. If it’s not configured here, you’d need an external screen, log in, etc. With this approach, the Pi can connect to the desired Wi-Fi without doing anything on the Pi—not even logging in.
- To change this configuration, you’ll need to connect a screen, or log in over a Wi-Fi network that is already configured.
-
Write Wi-Fis into the Wi-Fi configuration file. Ours looks like this:
network:
version: 2
renderer: NetworkManager
wifis:
wlan0:
optional: true
access-points:
"ego": # Network name
password: "whatever_it_is" # Password
"PIROBOTNET": {} # No password needed; open network
# etc... add as many as needed
dhcp4: true-
Apply changes:
sudo netplan apply
- To see the Raspberry Pi IP on any Wi-Fi without a monitor:
sudo apt-get install arp-scansudo arp-scan --interface=wlo1 --localnet
-
Connect the Raspberry Pi to power / battery.
-
SSH into the Raspberry Pi from another laptop connected to the same Wi-Fi network.
- ADRIA:
ssh -X pi@192.168.183.xxx - DIEGO:
ssh -X pi@192.168.54.22 ssh -X pi@192.168.113.22ssh -X pi@192.168.245.104(ssh -X pi@192.168.0.114used to be this one, but not anymore)- Password: (Ask the leader)
- The Wi-Fi network can be the PIROBOTNET router or mobile hotspot data already configured.
- To connect to a mobile hotspot or an unconfigured network, you’d need to do it via the Raspberry Pi GUI by connecting keyboard, mouse, and monitor… or by using an Ethernet cable.
- ADRIA:
-
Source the environment.
cd Documents/asti2024/asti2024_wssource install/setup.bash(or use thesrcalias to do it faster)
-
Run the desired program.
ros2 run bringup motor_vel_controller(to enable the motors; do not close this terminal. Make sure the motors are locked by trying to rotate the wheels by hand)ros2 run final dibuja_figura(in another terminal; this is where the desired program would run)
-
If there’s an error:
-
Re-source:
source /opt/ros/foxy/setup.bashsource install/setup.bash
-
Build the code on the Raspberry Pi (in principle it should already be built and stay that way).
colcon build --packages-select custom_interfacescolcon build --packages-select dynamixel_sdksource install/setup.bashcolcon build --symlink-install --packages-select bringup- Build the remaining programs (final…)
source install/setup.bash
-
If it still doesn’t work:
sudo usermod -aG dialout pisudo chmod 777 /dev/ttyUSB0(or the correct port; it could be ttyUSB1, ttyUSB2, etc. Usels /dev/ttyUSB*to check)- Restart the motor controller. Connect USB + power.
- Try a different USB port.
-
-
To shut down the Raspberry Pi:
sudo shutdown now(wait until the red LED turns off; don’t disconnect power before it’s off)
-
To close the SSH connection:
exit
-
Download the repository.
-
Build the code:
colcon build --packages-select custom_interfacescolcon build --packages-select dynamixel_sdksource install/setup.bashcolcon build --symlink-install --packages-select bringupsource install/setup.bashcolcon build --symlink-install --packages-select pruebas final(etc… any packages you want to use)
-
Run the desired program:
ros2 run final dibuja_figura(in another terminal; this is where the desired program would run)
-
If we want to test the motors:
-
Connect the motor controller to the laptop with a USB cable.
-
Also power the controller with another USB or a battery. The USB option would be via an Arduino that provides 5V.
-
(Needs a better explanation)
-
Give permissions to the computer to control the motors:
sudo usermod -aG dialout pisudo chmod 777 /dev/ttyUSB0(or the correct port; it could be ttyUSB1, ttyUSB2, etc. Usels /dev/ttyUSB*to check)
-
ros2 run bringup motor_vel_controller(to enable the motors; do not close this terminal. Make sure the motors are locked by trying to rotate the wheels by hand) -
If it doesn’t work, try a different USB port or run:
ros2 run bringup motor_vel_controller /dev/ttyUSB0(or the correct port; it could be ttyUSB1, ttyUSB2, etc. Usels /dev/ttyUSB*to check)
-
-
Create the program in
asti2024/asti2024_ws/src/pruebas/pruebas(for example). -
If the program is in Python, go to
asti2024/asti2024_ws/src/pruebas/setup.pyand add the program name to theentry_pointslist. -
Example:
entry_points={ 'console_scripts': [ 'test_vision_gazebo = pruebas.test_vision_gazebo:main', 'distance_sensor = pruebas.distance_sensor:main', ], },
-
Build the code:
colcon build --symlink-install --packages-select pruebassource install/setup.bash
-
You wouldn’t need to rebuild after every change if you used
--symlink-install, but if you modifysetup.pyagain, you'll need to.