Skip to content

Commit

Permalink
initial minimal PX4_ROS2 platform and px4_ros2_default build (PX4#20689)
Browse files Browse the repository at this point in the history
 - new ROS2 platform in PX4 intended for creating configs that build and run entirely in ROS2
 - PX4_CONFIG defaults to px4_ros2_default if no config specified and in a colcon workspace with ROS_VERSION=2
 - currently doesn't do much other than allow you to build px4 msgs interface package
  • Loading branch information
dagar authored Dec 9, 2022
1 parent cfb670f commit 8114aad
Show file tree
Hide file tree
Showing 73 changed files with 4,037 additions and 247 deletions.
3 changes: 1 addition & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,5 @@
"workbench.settings.enableNaturalLanguageSearch": false,
"yaml.schemas": {
"${workspaceFolder}/validation/module_schema.yaml": "${workspaceFolder}/src/modules/*/module.yaml"
},
"cortex-debug.openocdPath": "${env:PICO_SDK_PATH}/../openocd/src/openocd" // Added for rp2040
}
}
77 changes: 22 additions & 55 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
############################################################################
#
# Copyright (c) 2017 - 2019 PX4 Development Team. All rights reserved.
# Copyright (c) 2017 - 2022 PX4 Development Team. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -143,25 +143,17 @@ define_property(GLOBAL PROPERTY PX4_SRC_FILES
# configuration
#

set(CONFIG "px4_sitl_default" CACHE STRING "desired configuration")

include(px4_add_module)
set(config_module_list)
set(config_kernel_list)

# Find Python
# If using catkin, Python 2 is found since it points
# to the Python libs installed with the ROS distro
if (NOT CATKIN_DEVEL_PREFIX)
find_package(PythonInterp 3)
# We have a custom error message to tell users how to install python3.
if (NOT PYTHONINTERP_FOUND)
message(FATAL_ERROR "Python 3 not found. Please install Python 3:\n"
" Ubuntu: sudo apt install python3 python3-dev python3-pip\n"
" macOS: brew install python")
endif()
else()
find_package(PythonInterp REQUIRED)
find_package(PythonInterp 3)
# We have a custom error message to tell users how to install python3.
if(NOT PYTHONINTERP_FOUND)
message(FATAL_ERROR "Python 3 not found. Please install Python 3:\n"
" Ubuntu: sudo apt install python3 python3-dev python3-pip\n"
" macOS: brew install python")
endif()

option(PYTHON_COVERAGE "Python code coverage" OFF)
Expand Down Expand Up @@ -207,6 +199,11 @@ if(EXISTS "${PX4_SOURCE_DIR}/platforms/${PX4_PLATFORM}/cmake/init.cmake")
include(init)
endif()

#=============================================================================
# project definition
#
project(px4 CXX C ASM)

# CMake build type (Debug Release RelWithDebInfo MinSizeRel Coverage)
if(NOT CMAKE_BUILD_TYPE)
if(${PX4_PLATFORM} STREQUAL "nuttx")
Expand Down Expand Up @@ -235,11 +232,6 @@ endif()
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug;Release;RelWithDebInfo;MinSizeRel;Coverage;AddressSanitizer;UndefinedBehaviorSanitizer")
message(STATUS "cmake build type: ${CMAKE_BUILD_TYPE}")

#=============================================================================
# project definition
#
project(px4 CXX C ASM)

# Check if LTO option and check if toolchain supports it
if(LTO)
include(CheckIPOSupported)
Expand All @@ -256,15 +248,9 @@ set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# For the catkin build process, unset build of dynamically-linked binaries
# and do not change CMAKE_RUNTIME_OUTPUT_DIRECTORY
if (NOT CATKIN_DEVEL_PREFIX)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PX4_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PX4_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PX4_BINARY_DIR})
else()
SET(BUILD_SHARED_LIBS OFF)
endif()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PX4_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PX4_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PX4_BINARY_DIR})

#=============================================================================

Expand Down Expand Up @@ -309,21 +295,6 @@ endif()

include(ccache)

#=============================================================================
# find programs and packages
#

# see if catkin was invoked to build this
if (CATKIN_DEVEL_PREFIX)
message(STATUS "catkin ENABLED")
find_package(catkin REQUIRED)
if (catkin_FOUND)
catkin_package()
else()
message(FATAL_ERROR "catkin not found")
endif()
endif()

#=============================================================================
# get chip and chip manufacturer
#
Expand Down Expand Up @@ -450,10 +421,10 @@ add_subdirectory(src/lib/metadata EXCLUDE_FROM_ALL)
add_subdirectory(src/lib/parameters EXCLUDE_FROM_ALL)

if(${PX4_PLATFORM} STREQUAL "nuttx" AND NOT CONFIG_BUILD_FLAT)
target_link_libraries(parameters_interface INTERFACE usr_parameters)
target_link_libraries(kernel_parameters_interface INTERFACE parameters)
target_link_libraries(parameters_interface INTERFACE usr_parameters)
target_link_libraries(kernel_parameters_interface INTERFACE parameters)
else()
target_link_libraries(parameters_interface INTERFACE parameters)
target_link_libraries(parameters_interface INTERFACE parameters)
endif()

# firmware added last to generate the builtin for included modules
Expand Down Expand Up @@ -486,17 +457,13 @@ include(doxygen)
include(metadata)
include(package)

# print size
add_custom_target(size
COMMAND size $<TARGET_FILE:px4>
DEPENDS px4
WORKING_DIRECTORY ${PX4_BINARY_DIR}
USES_TERMINAL
)

# install python requirements using configured python
add_custom_target(install_python_requirements
COMMAND ${PYTHON_EXECUTABLE} -m pip install --requirement ${PX4_SOURCE_DIR}/Tools/setup/requirements.txt
DEPENDS ${PX4_SOURCE_DIR}/Tools/setup/requirements.txt
USES_TERMINAL
)

if(EXISTS "${PX4_SOURCE_DIR}/platforms/${PX4_PLATFORM}/cmake/finalize.cmake")
include(finalize)
endif()
3 changes: 3 additions & 0 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ menu "Toolchain"
bool "posix"
config PLATFORM_QURT
bool "qurt"
config PLATFORM_ROS2
bool "ros2"
endchoice

config BOARD_PLATFORM
string
default "nuttx" if PLATFORM_NUTTX
default "posix" if PLATFORM_POSIX
default "qurt" if PLATFORM_QURT
default "ros2" if PLATFORM_ROS2

config BOARD_LOCKSTEP
bool "Force enable lockstep"
Expand Down
1 change: 1 addition & 0 deletions boards/px4/ros2/default.px4board
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_PLATFORM_ROS2=y
36 changes: 36 additions & 0 deletions boards/px4/ros2/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
############################################################################
#
# Copyright (c) 2022 PX4 Development Team. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name PX4 nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################

add_library(drivers_board
init.cpp
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/****************************************************************************
*
* Copyright (C) 2012 PX4 Development Team. All rights reserved.
* Author: @author Lorenz Meier <[email protected]>
* Copyright (c) 2022 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -33,25 +32,19 @@
****************************************************************************/

/**
* @file conversions.c
* Implementation of commonly used conversions.
* @file board_config.h
*
* SITL internal definitions
*/

#include <px4_platform_common/px4_config.h>
#include <float.h>
#pragma once

#include "conversions.h"
#define BOARD_OVERRIDE_UUID "SIMULATIONID0000" // must be of length 16
#define PX4_SOC_ARCH_ID PX4_SOC_ARCH_ID_SITL

int16_t
int16_t_from_bytes(uint8_t bytes[])
{
union {
uint8_t b[2];
int16_t w;
} u;
#define BOARD_HAS_POWER_CONTROL 1

u.b[1] = bytes[0];
u.b[0] = bytes[1];
#define BOARD_NUMBER_BRICKS 0

return u.w;
}
#include <system_config.h>
#include <px4_platform_common/board_common.h>
Empty file added boards/px4/ros2/src/init.cpp
Empty file.
5 changes: 4 additions & 1 deletion cmake/package.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,7 @@ else()
endif()

include(CPack)
include(bloaty)

if(${PX4_PLATFORM} MATCHES "nuttx")
include(bloaty)
endif()
3 changes: 0 additions & 3 deletions cmake/px4_add_common_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,6 @@ function(px4_add_common_flags)
# CXX only flags
set(cxx_flags)
list(APPEND cxx_flags
-fno-exceptions
-fno-threadsafe-statics

-Wreorder

# disabled warnings
Expand Down
4 changes: 3 additions & 1 deletion cmake/px4_add_library.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ include(px4_list_make_absolute)
# Like add_library but with PX4 platform dependencies
#
function(px4_add_library target)
add_library(${target} EXCLUDE_FROM_ALL ${ARGN})
add_library(${target} STATIC EXCLUDE_FROM_ALL
${ARGN}
)

target_compile_definitions(${target} PRIVATE MODULE_NAME="${target}")

Expand Down
32 changes: 18 additions & 14 deletions cmake/px4_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,23 @@

# find PX4 config
# look for in tree board config that matches CONFIG input

if(NOT CONFIG)
# default to px4_ros2_default if building within a ROS2 colcon environment
if(("$ENV{COLCON}" MATCHES "1") AND ("$ENV{ROS_VERSION}" MATCHES "2"))
set(CONFIG "px4_ros2_default" CACHE STRING "desired configuration")
else()
set(CONFIG "px4_sitl_default" CACHE STRING "desired configuration")
endif()
endif()

if(NOT PX4_CONFIG_FILE)

file(GLOB_RECURSE board_configs
RELATIVE "${PX4_SOURCE_DIR}/boards"
"boards/*.px4board"
)

set(PX4_CONFIGS ${board_configs} CACHE STRING "PX4 board configs" FORCE)

foreach(filename ${board_configs})
# parse input CONFIG into components to match with existing in tree configs
# the platform prefix (eg nuttx_) is historical, and removed if present
Expand All @@ -63,9 +71,9 @@ if(NOT PX4_CONFIG_FILE)
)
set(PX4_CONFIG_FILE "${PX4_SOURCE_DIR}/boards/${filename}" CACHE FILEPATH "path to PX4 CONFIG file" FORCE)
set(PX4_BOARD_DIR "${PX4_SOURCE_DIR}/boards/${vendor}/${model}" CACHE STRING "PX4 board directory" FORCE)
set(MODEL "${model}" CACHE STRING "PX4 board model" FORCE)
set(VENDOR "${vendor}" CACHE STRING "PX4 board vendor" FORCE)
set(LABEL "${label}" CACHE STRING "PX4 board vendor" FORCE)
set(MODEL "${model}" CACHE STRING "PX4 board model" FORCE)
set(VENDOR "${vendor}" CACHE STRING "PX4 board vendor" FORCE)
set(LABEL "${label}" CACHE STRING "PX4 board vendor" FORCE)
break()
endif()

Expand All @@ -76,19 +84,15 @@ if(NOT PX4_CONFIG_FILE)
)
set(PX4_CONFIG_FILE "${PX4_SOURCE_DIR}/boards/${filename}" CACHE FILEPATH "path to PX4 CONFIG file" FORCE)
set(PX4_BOARD_DIR "${PX4_SOURCE_DIR}/boards/${vendor}/${model}" CACHE STRING "PX4 board directory" FORCE)
set(MODEL "${model}" CACHE STRING "PX4 board model" FORCE)
set(VENDOR "${vendor}" CACHE STRING "PX4 board vendor" FORCE)
set(LABEL "${label}" CACHE STRING "PX4 board vendor" FORCE)
set(MODEL "${model}" CACHE STRING "PX4 board model" FORCE)
set(VENDOR "${vendor}" CACHE STRING "PX4 board vendor" FORCE)
set(LABEL "${label}" CACHE STRING "PX4 board vendor" FORCE)
break()
endif()
endif()
endforeach()
endif()

if(NOT PX4_CONFIG_FILE)
message(FATAL_ERROR "PX4 config file not set, try one of ${PX4_CONFIGS}")
endif()

message(STATUS "PX4 config file: ${PX4_CONFIG_FILE}")

include_directories(${PX4_BOARD_DIR}/src)
Expand All @@ -108,9 +112,9 @@ set(PX4_BOARD_LABEL ${LABEL} CACHE STRING "PX4 board label" FORCE)
set(PX4_CONFIG "${PX4_BOARD_VENDOR}_${PX4_BOARD_MODEL}_${PX4_BOARD_LABEL}" CACHE STRING "PX4 config" FORCE)

if(EXISTS "${PX4_BOARD_DIR}/uavcan_board_identity")
include ("${PX4_BOARD_DIR}/uavcan_board_identity")
include ("${PX4_BOARD_DIR}/uavcan_board_identity")
endif()

if(EXISTS "${PX4_BOARD_DIR}/sitl.cmake")
include ("${PX4_BOARD_DIR}/sitl.cmake")
include ("${PX4_BOARD_DIR}/sitl.cmake")
endif()
Loading

0 comments on commit 8114aad

Please sign in to comment.