Skip to content

Commit

Permalink
Build refactor (#70)
Browse files Browse the repository at this point in the history
Cleaner cmake organisation to ease switching between apps and limit compilation:

Main CMakeLists.txt with only general compilations options (app selection, NO_ROBOT and logging level)
App (i.e. statemachine) specific options loaded from a dedicated app.cmake file in each state machine folder (robot used, ROS version)
Now compiles only selected platform (robot) code for each app
Main corc cmake logic placed in corc.cmake, not to be edited for app development and testing

-------------------------------------
* X2DemoMachine, ROS and readme improvements (#52)

- Improved X2Robot ( extended parameters, simplified dynamic parameters estimation, acceleration estimation, etc.)
- X2DemoMachineRos has now access to X2DemoState, this allows publishing state-related parameters in real-time.
- Simplified X2DemoState for demonstration purposes.
- Readme for ROS X2DemoMachine.
- Improved TechnaidIMU class
- FourierHandle(4 buttons) class
------------------------------------------------

* robotName initialization and demomachineRos structure change

* FourierHandle class is added

* fix torque direction

* cmake-build-debug is added to gitignore

* gyro reading feature is added to IMU class

* message_runtime is added to package_xml

* parameter file cleaned. default robot name changed

* Additional features such as simplified dynamic parameter calculation, acceleration estimation is added under X2Robot. a demo state with 4 basic controllers are added.

* message generation related parameters are added to CMakeLists

* minor changes on sim related parameters

* additional dynamic parameters and change of publish rate

* ns parameter is added so that different robot name (therefore kinematic/inertial parameters) can be sued while using the same rviz

* errors during simulation are fixed

* keyboard no echo uncommented

* setting useImu to false for default parameters

* readme for X2DemoMachine is added

* CMakelist parameters are changed back to default for unimelb merge

* debug level changed to info

* added link to the specific page on GettingStarted

* minor readme improvements + spdlog header fix + changed default name to x2

* READme improvements: ros_controller is added under dependencies, initializing the can device is now mentioned

Co-authored-by: emekBaris <[email protected]>

* M3DemoMachine Getting started doc page (#53)

* Draft M3DemoMachine doc page

* Included M3 picture and edit doc

* Finalised draft M3DemoMachine doc page

* Link to M3DemoMachine Getting started page

* GS Typo update, GSExamples introduction changed

Co-authored-by: justinfong-unimelb <[email protected]>

* CORC documentation for M2 (#54)

Getting started main page and dedicated Getting started page for M2

* Merge main master (#4)

* Merge Unimelb master (#5)

Including new state machine

* Minimal functional update of new cmake approach

* Added missing apps .cmake

* BUG Drive.cpp getDigitalIn duplicate

* Updated documentation for new cmake structure

* Fix FLNL include error and added FLNL app specific flag

* Restored Kinco DIOs. Tested on Fourier EMU.

* Fix EMU implementation, including compatible Kinco DIO, running time logging in states, excessive RT thread warnings (now only once) and slightly extended joint limit.

* Set back to default ExoTestMachine compilation behaviour

* Improved filtering message and fix nan values

* Fix: pre-calibration filter error for EMU velocity

---------

Co-authored-by: Emek Barış Küçüktabak <[email protected]>
Co-authored-by: emekBaris <[email protected]>
Co-authored-by: justinfong-unimelb <[email protected]>
Co-authored-by: xinlianggunimelb <[email protected]>
  • Loading branch information
5 people authored Apr 12, 2024
1 parent 3ec77f5 commit ac4cd20
Show file tree
Hide file tree
Showing 27 changed files with 542 additions and 339 deletions.
248 changes: 20 additions & 228 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,238 +3,30 @@ project(CORC C CXX)

#To cross-compile for Arm (BeagleBone) use the armhf toolchain:
# cmake -DCMAKE_TOOLCHAIN_FILE=../armhf.cmake ..
################################## USER FLAGS ##################################

## Select the application by setting the state machine to use
#(it should be the class name and have corresponding header naming in a corresponding folder)
# If your application use ROS, don't forget to change the flag bellow too.

set (STATE_MACHINE_NAME "ExoTestMachine")
#set (STATE_MACHINE_NAME "M1DemoMachine")
#set (STATE_MACHINE_NAME "M1DemoMachineROS")
#set (STATE_MACHINE_NAME "M2DemoMachine")
#set (STATE_MACHINE_NAME "M3DemoMachine")
#set (STATE_MACHINE_NAME "X2DemoMachine")
#set (STATE_MACHINE_NAME "X2ROS2DemoMachine")
#set (STATE_MACHINE_NAME "LoggingDevice")
# For aarch64 (e.g. Jetson):
# cmake -DCMAKE_TOOLCHAIN_FILE=../aarch64.cmake ..

# Use this if your state machine code folder is not in CORC 'src/apps/' folder.
# Can be a relative or absolute path.
#set (STATE_MACHINE_PATH "../")
################################## USER FLAGS ##################################

# Comment to use actual hardware, uncomment for a nor robot (virtual) app
### Select the application by setting the state machine app.cmake to use
include(src/apps/ExoTestMachine/app.cmake)
#include(src/apps/M1DemoMachine/app.cmake)
#include(src/apps/M1DemoMachineROS/app.cmake)
#include(src/apps/M2DemoMachine/app.cmake)
#include(src/apps/M3DemoMachine/app.cmake)
#include(src/apps/X2DemoMachine/app.cmake)
#include(src/apps/X2ROS2DemoMachine/app.cmake)
#include(src/apps/LoggingDevice/app.cmake)
#include(../myStateMachineApp/app.cmake) ## example only, need to be defined

## Comment to use actual hardware, uncomment for a nor robot (virtual) app
set(NO_ROBOT ON)

# ROS Flag: set to 0 for a no ROS stateMachine, 1 for ROS 1 (use catkin build) and 2 for ROS2 (use colcon build)
# Remember to rename select appropriate package.xml too
set(ROS 0)

# Select desired logging level (Options: TRACE, DEBUG, INFO, WARN, ERROR, CRITICAL, OFF)
# INFO is the recommended level in normal operation
set(CORC_LOGGING_LEVEL INFO)
## Select desired logging level (Options: TRACE, DEBUG, INFO, WARN, ERROR, CRITICAL, OFF)
## INFO is the recommended level in normal operation
set(CORC_LOGGING_LEVEL DEBUG)

################################################################################



#Default path if not set
if(NOT STATE_MACHINE_PATH)
set (STATE_MACHINE_PATH "src/apps")
endif()

#ROS internal flags
if(ROS GREATER 0)
add_definitions(-DROS=${ROS})
endif()

#SIM flag is used for ROS1 simulation
if(NO_ROBOT AND (ROS EQUAL 1))
set(SIM ON)
add_definitions(-DSIM)
endif()

add_definitions(-DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_${CORC_LOGGING_LEVEL})

# For Force Plates
#add_definitions(-DFP_BBB)
add_definitions(-DFP_PB)
add_definitions(-DFP_CMDRPDO=0x3E0)
add_definitions(-DFP_STARTTPDO=0x3E1)

#######################

## Compile as C++14
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(ROS GREATER 0)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-int-in-bool-context" )
else()
if(CMAKE_CROSSCOMPILING)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-int-in-bool-context -static" )
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-int-in-bool-context" )
endif()
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)


## Flags (Release is the default)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")

## Current state machine (APP) to be build
if(NOT STATE_MACHINE_NAME)
message(FATAL_ERROR "ERROR: No state machine (APP) selected: Abort.")
else()
add_definitions(-DSTATE_MACHINE_TYPE=${STATE_MACHINE_NAME})
add_definitions(-DSTATE_MACHINE_INCLUDE="${STATE_MACHINE_NAME}.h")
endif()
if(NO_ROBOT)
add_definitions(-DNOROBOT=1)
endif()

## Get all source and header files (only the target app folder is included)
file(GLOB_RECURSE SOURCES "src/core/*.cpp" "src/core/*.c" "src/hardware/*.cpp" "src/hardware/*.c" "${STATE_MACHINE_PATH}/${STATE_MACHINE_NAME}/*.c" "${STATE_MACHINE_PATH}/${STATE_MACHINE_NAME}/*.cpp" "lib/FLNL/src/*.cpp")
file(GLOB_RECURSE HEADERS "src/core/*.h" "src/hardware/*.h" "${STATE_MACHINE_PATH}/${STATE_MACHINE_NAME}/*.h" )

## Set every folder containing .h file as include directory
set (INCLUDE_DIRS "")
foreach (_headerFile ${HEADERS})
get_filename_component(_dir ${_headerFile} PATH)
list (APPEND INCLUDE_DIRS ${_dir})
endforeach()
list(REMOVE_DUPLICATES INCLUDE_DIRS)
## Add libraries headers
list (APPEND INCLUDE_DIRS lib/)
list (APPEND INCLUDE_DIRS lib/Eigen/)
list (APPEND INCLUDE_DIRS lib/FLNL/include/)
list (APPEND INCLUDE_DIRS lib/spdlog/include/)

add_subdirectory(lib/yaml-cpp/)

## Hack for Yaml files path (absolute path required for ROS use, see X2Robot::initializeRobotParams)
if(CMAKE_CROSSCOMPILING)
add_definitions(-DBASE_DIRECTORY=.)
else()
add_definitions(-DBASE_DIRECTORY=${CMAKE_SOURCE_DIR})
endif()

if(ROS EQUAL 1)
## Add ROS 1 dependencies
#ROS 1 local compile: use catkin
message("--catkin--")
# Required ROS packages
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
std_srvs
sensor_msgs
geometry_msgs
dynamic_reconfigure
message_generation
)
if(SIM)
find_package(catkin REQUIRED COMPONENTS
controller_manager_msgs
cob_gazebo_ros_control
x2_description
)
endif()

generate_dynamic_reconfigure_options(
config/m1_dynamic_params.cfg
config/x2_dynamic_params.cfg
)

add_message_files(
FILES
X2Array.msg
X2Acceleration.msg
X2AccelerationMerge.msg
)

generate_messages(
DEPENDENCIES
std_msgs
)

catkin_package(
# INCLUDE_DIRS include
# LIBRARIES x2
CATKIN_DEPENDS
roscpp
rospy
std_msgs
std_srvs
sensor_msgs
geometry_msgs
dynamic_reconfigure
message_runtime
# DEPENDS system_lib
)

#include CATKIN
include_directories(${catkin_INCLUDE_DIRS})
set(ROS_LIBRARIES ${catkin_LIBRARIES})

## Add ROS2 dependencies
elseif(ROS EQUAL 2)
#ROS 2 local compile: use colcon
message("--colcon--")

find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
endif()



## Executable name: {STATEMACHINENAME}_APP
set (APP_NAME ${STATE_MACHINE_NAME}_APP)
if(NO_ROBOT)
set (APP_NAME ${APP_NAME}_NOROBOT)
endif()
add_executable(${APP_NAME}
${SOURCES}
)

## Includes
target_include_directories(${APP_NAME} PUBLIC ${INCLUDE_DIRS})

## Set required external packages
find_package(Threads REQUIRED)

## Link non-ROS libraries
target_link_libraries(${APP_NAME}
${CMAKE_THREAD_LIBS_INIT}
yaml-cpp)

## Link ROS libraries
if(ROS EQUAL 1)
target_link_libraries(${APP_NAME} ${ROS_LIBRARIES})

# make sure configure headers are built before any node using them
add_dependencies(${APP_NAME} ${PROJECT_NAME}_gencfg)

elseif(ROS EQUAL 2)
include_directories(${INCLUDE_DIRS})

ament_target_dependencies(${APP_NAME} rclcpp std_msgs sensor_msgs)
ament_export_dependencies(rclcpp std_msgs sensor_msgs)

install(TARGETS ${APP_NAME} DESTINATION lib/${PROJECT_NAME})
install(PROGRAMS script/initCAN0.sh DESTINATION lib/${PROJECT_NAME})
install(DIRECTORY launch DESTINATION share/${PROJECT_NAME})
install(DIRECTORY config DESTINATION share/${PROJECT_NAME})

ament_package()
endif()


message("-----------------------------------------------\nBuilding application ${APP_NAME}\n-----------------------------------------------")
## CORC internal cmake logic
include(corc.cmake)
2 changes: 1 addition & 1 deletion config/M3_params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ EMU_FOURIER:
qSpringK: [0, 2.42, 4.19] #Joint spring compensation: tau=Ko+K*q
qSpringKo: [0, 0.47, 0]

qLimits: [-42, 42, -15, 70, 0, 95] # Joints limits (in deg) {q1_min, q1_max, q2_min, q2_max, q3_min, q3_max}
qLimits: [-42, 42, -15, 70, -5, 95] # Joints limits (in deg) {q1_min, q1_max, q2_min, q2_max, q3_min, q3_max}
qCalibration: [+44, 76, 90] # Calibration configuration (in deg): posture in which the robot is when using the calibration procedure

frictionVis: [0.33, 0.76, 0.69] # Joint viscous friction compensation coefficients
Expand Down
Loading

0 comments on commit ac4cd20

Please sign in to comment.