(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

CMake for avr_bridge

Description: cmake compilation and programming for arduinos using avr_bridge

Tutorial Level:

To make compilation and programming easier when using avr_bridge, we have included a set of cmake scripts in the avr_bridge repository. These cmake scripts allow you to compile avr_bridge based firmware and program your arduino from the command line.

Gathering The Project Resources

Since we are using the Arduino libraries in our project, we need to compile them into our project. The easiest way to do this is to simply copy the library source and put it into a folder called arduiono in our own project. You can find the arduino src code in the Arduino installation directory under /hardware/arduino/cores/arduino. Copy this folder into your own project.

Next, we need the avr_bridge cmake scripts. The cmake scripts are located in avr_bridge/avr_cmake. Inside this folder you will find both an example CMakeLists.txtr and a cmake_scripts folder. Copy both the CMakeLists.txt file and the cmake_scripts folder into your avr project folder.

CMakeLists.txt

This cmake file does a few important things.

  1. It specifies the name of the project.
  2. It specifices the location of our arduiono library source code. We placed the source code in the arduino folder, so this is already set.
  3. It sets the type of arduino board by including the appropriate board specific cmake files. If you are not using an arduino_deicimila, you must change the included script.
  4. It grabs the avr_ros files and adds them to your project.
  5. Finally, it adds all the c++ files to the firmware hex file.

cmake_minimum_required(VERSION 2.6)

#set your project name
Project(avrBridge_example)

#set the location of your arduino source code installation
#in the example project, the arduino source code is included in the
#project folder
set(ARDUINO_CORE_DIR  arduino)

#Include the arduino board specific cmake file
include(${PROJECT_SOURCE_DIR}/cmake_scripts/arduino_diecimila.cmake)
include_directories(${PROJECT_SOURCE_DIR})


file(GLOB AVR_ROS_SRC
    "avr_ros/*.cpp"
)


#Add of your own avr c++ files to this list
set(PROJECT_SRC
    main.cpp
    avr_ros_user.cpp
    ${AVR_ROS_SRC}
    ${ARDUINO_SOURCE_FILES}
)


add_executable(firmware ${PROJECT_SRC})

With this cmake file, compilation will generate a hex file called firmware.hex for your arduino. By performing make flash, you can program it to /dev/ttyUSB0. By performing make size, you can find out the size of your hex file and how much free space you have left on your Arduino.

Wiki: avr_bridge/Tutorials/Arduino, avr_bridge, and cmake (last edited 2011-03-03 21:28:28 by AdamStambler)