This ROS package ports the rosserial-arduino
communication package for the
Teensy MCUs. It uses the same ros-lib
generated by the rosserial-arduino
package for the higher level and compiles the Teensy core Arduino library
implementation to provide the interface to serial.write()
and
serial.print()
.
There are several requirements for this package, first is the arm compiler toolchain from the GNU tools:
sudo apt-get install gcc-arm-none-eabi
Then you will obviously need the Arduino and Teensyduino libraries. You can
find the Arduino library on arduino.cc/en/Main/Software
where you will
find your latest version. Unfortunately Arduino does not provide a static URL
with the latest version of the library, so this URL might change with
time. At the time this was written, the latest version was 1.6.7
so:
curl -O https://downloads.arduino.cc/arduino-1.6.7-linux64.tar.xz
tar -xvf arduino-1.6.7-linux64.tar.xz
For Teensyduino, the URL is also not static and will change. At this time you can get it with
curl -O https://www.pjrc.com/teensy/td_127/teensyduino.64bit
chmod +x teensyduino.64bit
./teensyduino.64bit
Finally, you will need to set an environment variable to point to the where you
installed the libraries. So add a line like the following to your .bashrc
file
or any other file you source in every terminal
export arduino_location=<the_location>
To properly use the ros_teensy
package, your package containing your MCU code
to be compiled should follow this structure:
package
βββ CMakeLists.txt
βββ package.xml
βββ arch1
βΒ Β βββ CMakeLists.txt
βΒ Β βββ main.cpp
βββ arch2
βββ CMakeLists.txt
βββ main.cpp
Note that the toolchain file used to compile the sources will be determined at
a folder level, hence the reason for the arch1
and arch2
folders. These two
folders could (or not) be compiled using the same cross-compiling toolchain.
To compile using the ros_teensy
toolchain you must include the following
commands in your different CMakeLists.txt.
At the package level:
cmake_minimum_required(VERSION 2.8)
project(<package_name>)
find_package(catkin REQUIRED COMPONENTS
ros_teensy
rosserial_client
rosserial_arduino
)
rosserial_generate_ros_lib(
PACKAGE rosserial_arduino
SCRIPT make_libraries.py
)
rosserial_configure_client(
DIRECTORY architecture1
TOOLCHAIN_FILE ${ROS_TEENSY_TOOLCHAIN}
)
rosserial_configure_client(
DIRECTORY architecture2
TOOLCHAIN_FILE ${ROS_TEENSY_TOOLCHAIN}
)
rosserial_add_client_target(architecture1 target1_Firmware ALL)
rosserial_add_client_target(architecture2 target2_Firmware ALL)
Then inside each architecture folder, the CMakeLists.txt should contain the following:
include_directories(${ROS_LIB_DIR})
FILE(GLOB_RECURSE ros_src
"${ROS_LIB_DIR}/*.cpp"
"${ROS_LIB_DIR}/*.h")
add_library(ros_lib ${ros_src})
add_teensy_executable(target1 main.cpp)
target_link_libraries(target1 ros_lib)
You will need to explicitly build and link to the ros_lib
target for each
different architecture. Additionally, each target needs to be linked to those
libraries as well.
Note that it is the same principle for any other external libraries.
Additionnally, if your MCU code uses some of the Arduino/Teensy external
libraries such as Servo
, SPI
, PID
, etc. You will need to add them to the
compilation process by adding this line before you create the executable.
include_directories(${ROS_LIB_DIR})
import_arduino_library(Servo)
...
add_teensy_executable(...)
We use the import_arduino_library()
command regardless of if the library is
an Arduino or a Teensyduino library.
After the build completes, three files should be created for each Teensy target
you added: target.elf
, target.elf.eep
and target.elf.hex
. They should be
located in the build folder of the catkin workspace:
catkin_ws/src/<package_name>/architecture/bin
. Out of those files, the *.hex
file is the one that will get flashed to the micro-controller using your
favorite utility.