Skip to content

UJI-ROBOTICS-TEAM/asti2024

Repository files navigation

ASTI 2024 - UJI ROBOTICS TEAM 🚀

What is this?

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

Prerequisites

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.

How to get started

1. Clone this repository

git clone https://github.com/diegomarzaa/asti2024.git
cd asti2024

2. Build the Docker image

Use 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 images

You should see something similar to:

REPOSITORY          TAG       IMAGE ID       CREATED            SIZE
asti2024            latest    535bcd5d8e02   14 seconds ago     900MB

3. Run the container

chmod +x abrir-workspace-asti.sh
./abrir-workspace-asti.sh

Since it’s the first time, all ROS 2 workspace files will be built automatically. After that, you’ll be inside the container.

Using the Docker environment

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.

Usage example 🎯

Run the TurtleBot3 simulation

ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py

Run keyboard teleop to move the robot

ros2 run final keyboard_teleop

Issues and things that might go wrong

  • 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

Common commands

  • 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 pi
    • sudo chmod 777 /dev/ttyUSB0 (or whatever port it is; it could be ttyUSB1, ttyUSB2, etc. Use ls /dev/ttyUSB* to check)
    • Restart the motor controller. Connect USB + power.
    • Try a different USB port.
  • Motor testing

    • ros2 run final keyboard_teleop
    • ros2 run teleop_twist_keyboard teleop_twist_keyboard
    • ros2 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 -)

How to run an existing program on the CyberCrex or on a laptop

Quick Raspberry Pi Wi-Fi tutorial

  • /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

100% Raspberry Pi option

  1. To see the Raspberry Pi IP on any Wi-Fi without a monitor:
  • sudo apt-get install arp-scan
  • sudo arp-scan --interface=wlo1 --localnet
  1. Connect the Raspberry Pi to power / battery.

  2. 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.22 ssh -X pi@192.168.245.104 (ssh -X pi@192.168.0.114 used 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.
  3. Source the environment.

    • cd Documents/asti2024/asti2024_ws
    • source install/setup.bash (or use the src alias to do it faster)
  4. 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)
  5. If there’s an error:

    • Re-source:

      • source /opt/ros/foxy/setup.bash
      • source 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_interfaces
      • colcon build --packages-select dynamixel_sdk
      • source install/setup.bash
      • colcon 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 pi
      • sudo chmod 777 /dev/ttyUSB0 (or the correct port; it could be ttyUSB1, ttyUSB2, etc. Use ls /dev/ttyUSB* to check)
      • Restart the motor controller. Connect USB + power.
      • Try a different USB port.
  6. To shut down the Raspberry Pi:

    • sudo shutdown now (wait until the red LED turns off; don’t disconnect power before it’s off)
  7. To close the SSH connection:

    • exit

Tests on the laptop

  1. Download the repository.

  2. Build the code:

    • colcon build --packages-select custom_interfaces
    • colcon build --packages-select dynamixel_sdk
    • source install/setup.bash
    • colcon build --symlink-install --packages-select bringup
    • source install/setup.bash
    • colcon build --symlink-install --packages-select pruebas final (etc… any packages you want to use)
  3. Run the desired program:

    • ros2 run final dibuja_figura (in another terminal; this is where the desired program would run)
  4. 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 pi
      • sudo chmod 777 /dev/ttyUSB0 (or the correct port; it could be ttyUSB1, ttyUSB2, etc. Use ls /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. Use ls /dev/ttyUSB* to check)

How to create a new program

  1. Create the program in asti2024/asti2024_ws/src/pruebas/pruebas (for example).

  2. If the program is in Python, go to asti2024/asti2024_ws/src/pruebas/setup.py and add the program name to the entry_points list.

  3. Example:

    entry_points={
        'console_scripts': [
            'test_vision_gazebo = pruebas.test_vision_gazebo:main',
            'distance_sensor = pruebas.distance_sensor:main',
        ],
    },
  4. Build the code:

    • colcon build --symlink-install --packages-select pruebas
    • source install/setup.bash
  5. You wouldn’t need to rebuild after every change if you used --symlink-install, but if you modify setup.py again, you'll need to.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages