jhiggason / yahboomg1tank

ROS2 for YAHBOOM G1 Tank
https://opensar.net
MIT License
10 stars 0 forks source link
cpp python3 robotics-programming ros ros2 ros2-humble yahboom

YAHBOOM G1 Tank ROS2

Contributors Forks Stargazers Issues MIT License LinkedIn

Logo
## Overview The YAHBOOM G1 Tank ROS2 project is a Python-based node designed for the YAHBOOM G1 Tank, built on the Raspberry Pi 4. This project provides a flexible and customizable platform for controlling the YAHBOOM G1 Tank, with support for the Yahboom 4WD expansion board for robot car, SKU: 6000300085, and related vehicles. The project is built on top of the Robot Operating System 2 (ROS2), which provides a powerful and flexible framework for developing robotic applications. The YAHBOOM G1 Tank ROS2 project uses either the turtlesim teleop executable for basic control or a gamepad, such as an Xbox controller, for control. For more information on how to get started with this project, please refer to the documentation. If you encounter any issues or have any questions, feel free to open a new issue on the project's GitHub page. **Key Features:** - Controlled via `turtlesim` teleop executable. - Controlled via 'ros-humble-teleop-twist-joy` that uses the ros2 package joy to provide gamepad support- like an xbox controller. - Support for the "Yahboom 4WD expansion board for robot car, SKU: 6000300085" and related vehicles. Explore the Documentation » View Demo | Report Bug | Request Feature

Table of Contents

About The Project

Project Image

Built With

Getting Started

This guide will help you set up and run the ROS2 Python node for the YAHBOOM G1 Tank with Raspberry Pi 4.

Prerequisites

Hardware:

Software:

Installation and Setup

  1. Setting Permissions: If you encounter a "RuntimeError: No access to /dev/mem", adjust permissions for GPIO access on your Raspberry Pi:

    sudo chmod 777 /dev/mem
    sudo chmod 777 /dev/gpiomem

    After adjusting, reboot your Raspberry Pi.

  2. Clone the Repository: Navigate to your home directory, then run:

    mkdir ~/ros2_ws/
    cd ~/ros2_ws
    git clone https://github.com/jhiggason/yahboomg1tank.git .
  3. Build the ROS2 Package: Compile the project using colcon:

    colcon build
  4. Source the Workspace: After building, source the workspace:

    source ~/ros2_ws/install/setup.bash
  5. Running the Node: To activate and run your ROS2 node, execute:

    ros2 run tank_control_pkg tank_control

First Use:

Upon successfully setting up and running the node, the YAHBOOM G1 Tank should now respond to the twist messages provided by the turtlesim teleop or any other control method you've implemented.

Running the Turtlesim Node To activate and run your turtlesim node, execute:

   ros2 run turtlesim turtle_teleop_key --ros-args --remap /turtle1/cmd_vel:=/cmd_vel

Use your arrow keys on your keyboard to move the tank around.


For any issues or to contribute, engage with this GitHub repository.

(back to top)

How It Works:

The TankControl class, found in tank_control.py, is designed to control a tank-like robot using ROS2 and Raspberry Pi GPIO pins. It subscribes to ROS2 topics to receive motion commands and controls the robot's movement accordingly.

  1. Initialization: The class initializes upon instantiation, setting up GPIO pins for the left and right motors and configuring PWM (Pulse Width Modulation) for speed control.

  2. ROS2 Subscriptions: It subscribes to the /cmd_vel topic to receive Twist messages, containing linear and angular velocities for the tank's movement.

  3. Motor Speed and Direction Control: The class processes incoming Twist messages to calculate the speeds for the left and right wheels. It applies a correction factor to the linear velocity and amplifies the angular velocity. The speeds are normalized and used to control the motor direction and speed through GPIO pins.

  4. Safety Features: An inactivity timer is implemented to stop the motors if no command is received for a short duration (currently 0.1 seconds), ensuring safety.

Important Parameters:

Customization:

Careful consideration should be given when modifying GPIO configurations to prevent damage to the Raspberry Pi or connected components.

For more examples, please refer to the Documentation

(back to top)

Gamepad

In this example we are going to use an Xbox Series X/S controller, connected to bluetooth on the raspberry pi, to send twist MSGs to the /cmd_vel topic. This will control our tank.


*Setting Up Xbox Controller on Ubuntu 22 for ROS 2

  1. Disable Secure Boot: If you are doing this on a system other than raspberry pi-please disable secure boot.

    • Enter your PC's BIOS/UEFI firmware settings during boot, typically by pressing Del, F2, F12, or Esc.
    • Navigate to 'Boot' or 'Security'.
    • Find 'Secure Boot' and set it to 'Disabled'.
    • Save and exit.
  2. Update Xbox Controller:

    • On Windows:
      • Connect the controller and open the 'Xbox Accessories' app.
      • Follow on-screen instructions if an update is available.
    • On Xbox:
      • Connect the controller, navigate to 'Settings' > 'Devices & connections' > 'Accessories'.
      • Update if prompted.
  3. Install Xbox Driver for Ubuntu:

    • Install Dependencies:
      sudo apt update
      sudo apt install dkms git
    • Get xpadneo from its repository:
      git clone https://github.com/atar-axis/xpadneo.git
      cd xpadneo
      sudo ./install.sh
  4. Install Joystick Tools:

    sudo apt update
    sudo apt install jstest-gtk joystick
  5. Pair Xbox Controller via Bluetooth:

    • Start the Bluetooth CLI tool:
      sudo bluetoothctl
    • Turn on the agent and set it as default:
      agent on
      default-agent
    • Scan for devices:
      scan on
    • Turn on your Xbox controller in pairing mode. Note its MAC address.
    • Pair, trust, and connect using the MAC address (replace 'XX:XX:XX:XX:XX:XX'):
      pair XX:XX:XX:XX:XX:XX
      trust XX:XX:XX:XX:XX:XX
      connect XX:XX:XX:XX:XX:XX
    • Finish:
      scan off
      exit
  6. Install ros-humble-teleop-twist-joy:

    sudo apt update
    sudo apt install ros-humble-teleop-twist-joy
  7. Adjust xbox joy settings:

    cd /opt/ros/humble/share/teleop_twist_joy/config/
    sudo nano xbox.config.yaml

    Edit the file and change the values to 0 and 1.

    enable_button: 0  # Button A
    enable_turbo_button: 1  # Button B

    Then Ctrl+O then CTRL+X

  8. Run Teleop Twist joy

    ros2 launch teleop_twist_joy teleop-launch.py joy_config:='xbox'

Now you should be able to control your tank with the xbox controller after pressing the "A" button on the controller and moving the left stick.


Roadmap

See the open issues for a full list of proposed features (and known issues).

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE for more information.

(back to top)

Contact

Your Name - Jeff Higgason - jeffh@opensar.net

Project Link: https://github.com/jhiggason/YahBoomG1Tank

(back to top)