Giter Club home page Giter Club logo

teensy41_uros_example_publisher_with_static_library's Introduction

ros2 topic publishing by Teensy 4.1 using static library

Masoud Iranmehr

This repository shows a simple Arduino example of uros publishing an integer into ROS2, using

  • ROS2 foxy
  • uros static library
  • Teensy 4.1 as Hardware
  • Platformio IDE

How to run this project

Install docker (for ubuntu)

sudo apt-get update
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

echo \
  "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
  
 sudo apt-get update
 sudo apt-get install docker-ce docker-ce-cli containerd.io      

Load docker image

docker run -it --net=host -v /dev:/dev --privileged ros:foxy

Install teensy_loader_cli

Just follow these steps for ubuntu users:

cd /
git clone https://github.com/PaulStoffregen/teensy_loader_cli 
cd teensy_loader_cli
sudo apt-get install libusb-dev
make

Add Teensy rules to linux

For program Teensy you need these rules to be added to the linux:

wget https://www.pjrc.com/teensy/00-teensy.rules
sudo cp 00-teensy.rules /etc/udev/rules.d/

sudo apt-get update
sudo apt-get install -y gcc-arm-none-eabi

Please see this link.

Install cross-compiler for ARM

sudo apt-get update
sudo apt-get install -y gcc-arm-none-eabi

How to compile uros static library

Install uros

# Source the ROS 2 installation
source /opt/ros/$ROS_DISTRO/setup.bash

# Create a workspace and download the micro-ROS tools
mkdir microros_ws
cd microros_ws
git clone -b $ROS_DISTRO https://github.com/micro-ROS/micro_ros_setup.git src/micro_ros_setup

# Update dependencies using rosdep
sudo apt update && rosdep update
rosdep install --from-path src --ignore-src -y

# Install pip
sudo apt-get install python3-pip

# Build micro-ROS tools and source them
colcon build
source install/local_setup.bash

Creating the micro-ROS agent

# Download micro-ROS-Agent packages
ros2 run micro_ros_setup create_agent_ws.sh

# Build step
ros2 run micro_ros_setup build_agent.sh
source install/local_setup.bash

Downloading gcc-arm-none-eabi compiler

Be careful to use only this old version of gcc-arm-none-eabi-5_4-2016q3 in order to build uros for static library. You can download this using these commands:

cd /microros_ws
wget https://developer.arm.com/-/media/Files/downloads/gnu-rm/5_4-2016q3/gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2?revision=111dee36-f88b-4672-8ac6-48cf41b4d375?product=GNU%20Arm%20Embedded%20Toolchain%20Downloads,32-bit,,Linux,5-2016-q3-update

tar -xf gcc-arm-none-eabi-5_4-2016q3-20160926-linux,-d-,tar.bz2

Creating static library workspace

ros2 run micro_ros_setup create_firmware_ws.sh generate_lib
mkdir static_library_cfg
cd static_library_cfg
wget https://github.com/micro-ROS/micro_ros_arduino/blob/foxy/extras/library_generation/teensy4_toolchain.cmake
wget https://github.com/micro-ROS/micro_ros_arduino/blob/foxy/extras/library_generation/colcon.meta

export TOOLCHAIN_PREFIX=/microros_ws/gcc-arm-none-eabi-5_4-2016q3-20160926-linux,-d-,tar/gcc-arm-none-eabi-5_4-2016q3/bin/arm-none-eabi-
ros2 run micro_ros_setup build_firmware.sh /microros_ws/static_library_cfg/teensy4_toolchain.cmake /microros_ws/static_library_cfg/colcon.meta

How to create Platformio project

You need to install vscode in your host and then install remote & docker plugins to access docker folders. This automatically installs vscode-server in your docker. Then you need to install Platformio plugin inside vscode-server in your docker.

Then clone this repo:

cd /
git clone https://github.com/masoudir/teensy41_uros_example_publisher_with_static_library

cd teensy41_uros_example_publisher_with_static_library

Then if we want to add our static library to the project, we need to remove the older one and then copy the newer one:

rm -r /teensy41_uros_example_publisher_with_static_library/lib/microros/*
rm /teensy41_uros_example_publisher_with_static_library/lib/libmicroros.a

cd /teensy41_uros_example_publisher_with_static_library/lib/microros/
wget https://github.com/masoudir/teensy41_uros_example_publisher_with_static_library/blob/master/lib/microros/default_transport.cpp
wget https://github.com/masoudir/teensy41_uros_example_publisher_with_static_library/blob/master/lib/microros/micro_ros_arduino.h

cp -r /microros_ws/firmware/build/include/* /teensy41_uros_example_publisher_with_static_library/lib/microros/
cp /microros_ws/firmware/build/libmicroros.a /teensy41_uros_example_publisher_with_static_library/lib/

By default we have added this library, so you do not need to rebuilt that and copy them.

Then build this project using platformio build in vscode. (You can use CLI commands instead, but we do not mention that in this page).

Flash the hex file to Teensy

/teensy_loader_cli/teensy_loader_cli --mcu=TEENSY41 -s /teensy41_uros_example_publisher_with_static_library/.pio/build/teensy41/firmware.hex

*Note: "-s" : Use sort reboot if device not online. Perform a sort reset request by searching for any Teensy running USB Serial code built by Teensyduino. A request to reboot is transmitted to the first device found.

Run uros agent

Open a new terminal:

cd /microros_ws
source /opt/ros/foxy/setup.bash
source install/setup.bash

ros2 run micro_ros_agent micro_ros_agent serial --dev /dev/ttyACM0

If session is not established, while this agent is on, try to reset the microcontroller (reset in hardware). Becareful do not disconnect the serial port while agent is up.

How to read the topic that is published

Open a new terminal:

source /opt/ros/foxy/setup.bash; source /opt/ros/foxy/local_setup.bash
ros2 topic list
ros2 topic echo /micro_ros_arduino_node_publisher

teensy41_uros_example_publisher_with_static_library's People

Contributors

masoudir avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.