### Install Configuration and Library Files Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/module/control_module/CMakeLists.txt Defines installation rules for configuration directories and third-party libraries. ```cmake # Install config files install( DIRECTORY cfg/ policy DESTINATION bin/cfg/${CUR_DIR} USE_SOURCE_PERMISSIONS ) # install config files to build dir install( DIRECTORY cfg/ policy DESTINATION ${CMAKE_BINARY_DIR}/cfg/${CUR_DIR} USE_SOURCE_PERMISSIONS ) install( DIRECTORY third_party/lib/ DESTINATION lib ) ``` -------------------------------- ### Install System Dependencies and ONNX Runtime Source: https://context7.com/agibottech/agibot_x1_infer/llms.txt Installs necessary system packages, CMake, Git, Protocol Buffers, and then clones, builds, and installs ONNX Runtime. Ensure you have sufficient disk space for ONNX Runtime compilation. ```bash sudo apt update sudo apt install -y build-essential cmake git libprotobuf-dev protobuf-compiler sudo apt install jstest-gtk libglfw3-dev libdart-external-lodepng-dev git clone --recursive https://github.com/microsoft/onnxruntime cd onnxruntime ./build.sh --config Release --build_shared_lib --parallel cd build/Linux/Release/ sudo make install ``` -------------------------------- ### Install ONNX Runtime Source: https://github.com/agibottech/agibot_x1_infer/blob/main/README.md Installs ONNX Runtime from source. Ensure you have GCC-13 and CMake (3.26+) installed. This process builds the shared library and installs it. ```bash sudo apt update sudo apt install -y build-essential cmake git libprotobuf-dev protobuf-compiler git clone --recursive https://github.com/microsoft/onnxruntime cd onnxruntime ./build.sh --config Release --build_shared_lib --parallel cd build/Linux/Release/ sudo make install ``` -------------------------------- ### Install Target in CMake Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/module/dcu_driver_module/xyber_controller/example/CMakeLists.txt Specifies installation rules for the target. Libraries are installed to 'lib', archives to 'lib', and runtime binaries to 'bin' with a component name matching the target name. ```cmake install( TARGETS ${CUR_TARGET_NAME} LIBRARY DESTINATION lib ARCHIVE DESTINATION lib RUNTIME DESTINATION bin COMPONENT ${CUR_TARGET_NAME}) ``` -------------------------------- ### Install Configuration Files in CMake Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/module/joy_stick_module/CMakeLists.txt Installs configuration files from the 'cfg' directory to both the build directory and the installation prefix, preserving source permissions. ```cmake install( DIRECTORY cfg/ DESTINATION bin/cfg/${CUR_DIR} USE_SOURCE_PERMISSIONS ) install( DIRECTORY cfg/ DESTINATION ${CMAKE_BINARY_DIR}/cfg/${CUR_DIR} USE_SOURCE_PERMISSIONS ) ``` -------------------------------- ### Define Library Targets and Installation Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/module/dcu_driver_module/xyber_controller/third_party/soem/CMakeLists.txt Compiles the SOEM static library, sets include directories, and defines installation rules for headers and binaries. ```cmake message(STATUS "OS is ${OS}") file(GLOB SOEM_SOURCES soem/*.c) file(GLOB OSAL_SOURCES osal/${OS}/*.c) file(GLOB OSHW_SOURCES oshw/${OS}/*.c) file(GLOB SOEM_HEADERS soem/*.h) file(GLOB OSAL_HEADERS osal/osal.h osal/${OS}/*.h) file(GLOB OSHW_HEADERS oshw/${OS}/*.h) add_library(soem STATIC ${SOEM_SOURCES} ${OSAL_SOURCES} ${OSHW_SOURCES} ${OSHW_EXTRA_SOURCES}) target_link_libraries(soem ${OS_LIBS}) target_include_directories(soem PUBLIC $ $) target_include_directories(soem PUBLIC $ $) target_include_directories(soem PUBLIC $ $) target_include_directories(soem PUBLIC $ $ $ $ ) message(STATUS "LIB_DIR: ${SOEM_LIB_INSTALL_DIR}") install(TARGETS soem EXPORT soemConfig DESTINATION ${SOEM_LIB_INSTALL_DIR}) install(EXPORT soemConfig DESTINATION share/soem/cmake) install(FILES ${SOEM_HEADERS} ${OSAL_HEADERS} ${OSHW_HEADERS} DESTINATION ${SOEM_INCLUDE_INSTALL_DIR}) ``` -------------------------------- ### Install Binary Directory Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/CMakeLists.txt Installs the binary directory from the specified source path to the destination. This command preserves source file permissions. ```cmake install( DIRECTORY ${CUR_INSTALL_SOURCE_DIR}/bin DESTINATION ./ USE_SOURCE_PERMISSIONS) ``` -------------------------------- ### Native ROS2 Channel Publisher Example Source: https://context7.com/agibottech/agibot_x1_infer/llms.txt A C++ ROS2 node that publishes JoyStickData messages to a specified topic at a regular interval. Ensure ROS2 protocol setup is sourced before running. ```cpp // native_ros2_channel_publisher/main.cc #include #include #include #include "my_ros2_proto/msg/joy_stick_data.hpp" #include "rclcpp/rclcpp.hpp" class RosTestChannelPublisher : public rclcpp::Node { public: RosTestChannelPublisher() : Node("native_ros2_channel_publisher") { using namespace std::chrono_literals; publisher_ = create_publisher("test_topic", 10); timer_ = create_wall_timer(500ms, [this]() { ++count_; my_ros2_proto::msg::JoyStickData msg; msg.name = "joy_stick_module_data"; msg.x = count_; msg.y = count_; msg.z = count_; RCLCPP_INFO(get_logger(), "Publishing msg:\n%s", my_ros2_proto::msg::to_yaml(msg).c_str()); publisher_->publish(msg); }); } private: rclcpp::TimerBase::SharedPtr timer_; rclcpp::Publisher::SharedPtr publisher_; size_t count_ = 0; }; int main(int argc, char* argv[]) { // Before running, source the ROS2 protocol setup: // source ./install/ros2_setup.sh rclcpp::init(argc, argv); rclcpp::spin(std::make_shared()); rclcpp::shutdown(); return 0; } ``` -------------------------------- ### Install Simulation Dependencies Source: https://github.com/agibottech/agibot_x1_infer/blob/main/README.md Installs necessary dependencies for the simulation environment. This includes jstest-gtk, libglfw3-dev, and libdart-external-lodepng-dev. ```bash sudo apt install jstest-gtk libglfw3-dev libdart-external-lodepng-dev ``` -------------------------------- ### Joystick Configuration Example Source: https://context7.com/agibottech/agibot_x1_infer/llms.txt This YAML file configures joystick mappings for robot control, specifying the publishing frequency. ```yaml # joy_x1.yaml - Joystick configuration freq: 20 # Publishing frequency (Hz) ``` -------------------------------- ### Configure SOEM Build System Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/module/dcu_driver_module/xyber_controller/third_party/soem/CMakeLists.txt Initializes the project, sets installation paths, and detects the target operating system to configure compiler flags and dependencies. ```cmake cmake_minimum_required(VERSION 3.9) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules") project(SOEM DESCRIPTION "Simple Open EtherCAT Master" VERSION 1.4.0 LANGUAGES C) if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) # Default to installing in SOEM source directory set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_LIST_DIR}/install) endif () set(SOEM_INCLUDE_INSTALL_DIR include/soem) set(SOEM_LIB_INSTALL_DIR lib) if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) set(BUILD_TESTS TRUE) else () message(STATUS "SOEM: not building tests when built as dependency") set(BUILD_TESTS TRUE) endif () ``` -------------------------------- ### Configure Library Paths for Real Robot Deployment Source: https://context7.com/agibottech/agibot_x1_infer/llms.txt Sets up the dynamic linker configuration to include necessary libraries for running on the real AgiBot X1 robot. This is a one-time setup step. ```bash sudo vi /etc/ld.so.conf # Add these paths: # /opt/ros/humble/lib # {YourProjectSource}/build/install/lib sudo ldconfig ``` -------------------------------- ### Install Third-Party Libraries in CMake Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/module/joy_stick_module/CMakeLists.txt Installs the contents of the 'third_party/lib' directory to the 'lib' destination in the installation prefix. ```cmake install( DIRECTORY third_party/lib/ DESTINATION lib ) ``` -------------------------------- ### Install Library Target in CMake Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/module/dcu_driver_module/xyber_controller/xyber_api/CMakeLists.txt Defines installation rules for the target library, specifying destinations for libraries, archives, and runtime components. ```cmake install( TARGETS ${CUR_TARGET_NAME} LIBRARY DESTINATION lib ARCHIVE DESTINATION lib RUNTIME DESTINATION bin COMPONENT ${CUR_TARGET_NAME}) ``` -------------------------------- ### Build Executable and Link Library Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/module/dcu_driver_module/xyber_controller/third_party/soem/test/win32/slaveinfo/CMakeLists.txt Configures the build process to create an executable named 'slaveinfo_win' from 'slaveinfo.c' and links it with the 'soem' library. The executable is then installed to the 'bin' directory. ```cmake set(SOURCES slaveinfo.c) add_executable(slaveinfo_win ${SOURCES}) target_link_libraries(slaveinfo_win soem) install(TARGETS slaveinfo_win DESTINATION bin) ``` -------------------------------- ### Platform-Specific Installation Directory Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/CMakeLists.txt Sets the installation source directory based on the system name. Currently supports Linux and will fail on other systems. ```cmake if(CMAKE_SYSTEM_NAME MATCHES "Linux") set(CUR_INSTALL_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/install/linux) else() message(FATAL_ERROR "Unsupport os") endif() ``` -------------------------------- ### Build Executable with CMake Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/module/dcu_driver_module/xyber_controller/third_party/soem/test/linux/eepromtool/CMakeLists.txt Defines the source files for an executable and links it against the 'soem' library. The executable is then installed to the 'bin' directory. ```cmake set(SOURCES eepromtool.c) add_executable(eepromtool ${SOURCES}) target_link_libraries(eepromtool soem) install(TARGETS eepromtool DESTINATION bin) ``` -------------------------------- ### Configure Xyber Controller Project Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/module/dcu_driver_module/xyber_controller/CMakeLists.txt Sets up the basic project configuration, including the minimum CMake version, project name, and languages. It also configures installation paths and C++ standard. ```cmake cmake_minimum_required(VERSION 3.23) message("Configuring Xyber Controller project") project(xyber_controller LANGUAGES CXX C) # Set cmake path list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) set(CMAKE_INSTALL_RPATH "$ORIGIN;$ORIGIN/../lib;") set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Threads REQUIRED) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -Wl,--disable-new-dtags") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wl,--disable-new-dtags") add_subdirectory(third_party/soem) add_subdirectory(xyber_api) # add_subdirectory(example) install(SCRIPT "cmake/post_install_script.cmake") # CPack set(CPACK_PACKAGE_VERSION_MAJOR 0) set(CPACK_PACKAGE_VERSION_MINOR 5) set(CPACK_PACKAGE_VERSION_PATCH 0) set(CPACK_GENERATOR "ZIP") set(CPACK_PACKAGE_NAME "XyberController") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A brief description of XyberController: version: v0.5.x") set(CPACK_PACKAGE_VENDOR "AgibotTech") set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.md") set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Richie.Li") include(CPack) ``` -------------------------------- ### Install Header Files in CMake Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/module/dcu_driver_module/xyber_controller/xyber_api/CMakeLists.txt Installs the header files from the 'include' directory to the specified destination, excluding the 'internal' subdirectory. This makes the library's public API available to users. ```cmake install( DIRECTORY include/ DESTINATION include/${CUR_TARGET_NAME} PATTERN "include/internal" EXCLUDE ) ``` -------------------------------- ### CMake Build Configuration Script Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/module/dcu_driver_module/CMakeLists.txt Configures the project environment, defines the library target, and manages dependencies and installation. ```cmake # Get the current folder name string(REGEX REPLACE ".*/\\(.*\\)" "\\1" CUR_DIR ${CMAKE_CURRENT_SOURCE_DIR}) # Get namespace get_namespace(CUR_SUPERIOR_NAMESPACE) string(REPLACE "::" "_" CUR_SUPERIOR_NAMESPACE_UNDERLINE ${CUR_SUPERIOR_NAMESPACE}) # Find packages find_package(Eigen3 REQUIRED) find_package(std_msgs REQUIRED) find_package(sensor_msgs REQUIRED) find_package(geometry_msgs REQUIRED) # Set target name set(CUR_TARGET_NAME ${CUR_SUPERIOR_NAMESPACE_UNDERLINE}_${CUR_DIR}) set(CUR_TARGET_ALIAS_NAME ${CUR_SUPERIOR_NAMESPACE}::${CUR_DIR}) # Set file collection file(GLOB_RECURSE head_files ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h) file(GLOB_RECURSE src ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cc) file(GLOB_RECURSE test_files ${CMAKE_CURRENT_SOURCE_DIR}/test/*_test.cc) list(REMOVE_ITEM src ${test_files}) # Add SDK add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/xyber_controller) # Add target add_library(${CUR_TARGET_NAME} STATIC) add_library(${CUR_TARGET_ALIAS_NAME} ALIAS ${CUR_TARGET_NAME}) # Set source file of target target_sources(${CUR_TARGET_NAME} PRIVATE ${src}) # Set include path of target target_include_directories( ${CUR_TARGET_NAME} PUBLIC $ PUBLIC $ ) # Set link libraries of target target_link_libraries( ${CUR_TARGET_NAME} PRIVATE yaml-cpp::yaml-cpp PUBLIC xyber_controller aimrt::interface::aimrt_module_cpp_interface aimrt::interface::aimrt_module_ros2_interface my_ros2_proto::my_ros2_proto__rosidl_generator_cpp my_ros2_proto::my_ros2_proto__rosidl_typesupport_cpp my_ros2_proto::my_ros2_proto__rosidl_typesupport_fastrtps_cpp my_ros2_proto::my_ros2_proto__rosidl_typesupport_introspection_cpp my_ros2_proto::my_ros2_proto__rosidl_generator_cpp my_ros2_proto::my_ros2_proto__rosidl_typesupport_cpp my_ros2_proto::my_ros2_proto__rosidl_typesupport_fastrtps_cpp my_ros2_proto::my_ros2_proto__rosidl_typesupport_introspection_cpp std_msgs::std_msgs__rosidl_generator_cpp std_msgs::std_msgs__rosidl_typesupport_cpp std_msgs::std_msgs__rosidl_typesupport_fastrtps_cpp std_msgs::std_msgs__rosidl_typesupport_introspection_cpp sensor_msgs::sensor_msgs__rosidl_generator_cpp sensor_msgs::sensor_msgs__rosidl_typesupport_cpp sensor_msgs::sensor_msgs__rosidl_typesupport_fastrtps_cpp sensor_msgs::sensor_msgs__rosidl_typesupport_introspection_cpp geometry_msgs::geometry_msgs__rosidl_generator_cpp geometry_msgs::geometry_msgs__rosidl_typesupport_cpp geometry_msgs::geometry_msgs__rosidl_typesupport_fastrtps_cpp geometry_msgs::geometry_msgs__rosidl_typesupport_introspection_cpp ) # Set test of target if(XYBER_X1_INFER_BUILD_TESTS AND test_files) add_gtest_target(TEST_TARGET ${CUR_TARGET_NAME} TEST_SRC ${test_files}) endif() # Install config files install( DIRECTORY cfg/ DESTINATION bin/cfg/${CUR_DIR} USE_SOURCE_PERMISSIONS ) # install config files to build dir install( DIRECTORY cfg/ DESTINATION ${CMAKE_BINARY_DIR}/cfg/${CUR_DIR} USE_SOURCE_PERMISSIONS ) ``` -------------------------------- ### Initialize and Control XyberController SDK Source: https://context7.com/agibottech/agibot_x1_infer/llms.txt This C++ code initializes the XyberController, configures DCUs and actuators, starts EtherCAT communication, and enters a control loop to send commands and read states. Ensure the network interface and EtherCAT IDs are correctly set. ```cpp #include "xyber_controller.h" using namespace xyber; using namespace std::chrono_literals; int main() { // Step 1: Get singleton instance XyberControllerPtr controller(XyberController::GetInstance()); // Step 2: Configure DCU and actuator network // Create DCU with EtherCAT ID (first node in bus = 1) uint8_t ethercat_id = 1; std::string dcu_name = "body"; controller->CreateDcu(dcu_name, ethercat_id); // Attach actuator to DCU channel // Actuator types: POWER_FLOW_R86, POWER_FLOW_R52, POWER_FLOW_L28, OMNI_PICKER uint8_t actuator_can_id = 1; std::string actuator_name = "PowerFlowR52"; controller->AttachActuator(dcu_name, CtrlChannel::CTRL_CH1, // CTRL_CH1, CTRL_CH2, CTRL_CH3 ActuatorType::POWER_FLOW_R52, actuator_name, actuator_can_id); // Step 3: Configure and start EtherCAT communication controller->SetRealtime(90, 1); // RT priority 90, bind to CPU core 1 bool ret = controller->Start("enp2s0", // Network interface 1000000, // Cycle time in ns (1kHz) true); // Enable DC sync if (!ret) { std::cout << "Start Failed" << std::endl; return 0; } // Step 4: Enable actuators and IMU ret = controller->EnableAllActuator(); if (!ret) { std::cout << "Enable Actuator Failed" << std::endl; return 0; } controller->ApplyDcuImuOffset(dcu_name); // Step 5: Control loop float dt = 0; float pos_begin = controller->GetPosition(actuator_name); for (size_t i = 0; i < 100 * 30; i++) { // Read IMU data DcuImu imu = controller->GetDcuImuData(dcu_name); std::cout << "IMU acc: " << imu.acc[0] << ", " << imu.acc[1] << ", " << imu.acc[2] << " gyro: " << imu.gyro[0] << ", " << imu.gyro[1] << ", " << imu.gyro[2] << std::endl; // Send MIT control command (position, velocity, effort, kp, kd) double pos_cmd = pos_begin + 2 * sin(dt); controller->SetMitCmd(actuator_name, pos_cmd, // Position (rad) 0, // Velocity (rad/s) 0, // Effort (Nm) 0.9, // Kp gain 0.2); // Kd gain // Read current state float pos_now = controller->GetPosition(actuator_name); float vel = controller->GetVelocity(actuator_name); float effort = controller->GetEffort(actuator_name); std::cout << "Position: Cmd " << pos_cmd << " Now " << pos_now << std::endl; // Update phase dt += 0.01; if (dt >= 6.28) dt = 0.0; std::this_thread::sleep_for(10ms); } // Step 6: Cleanup controller->DisableAllActuator(); controller->Stop(); return 0; } ``` -------------------------------- ### Configure CMake for simple_test Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/module/dcu_driver_module/xyber_controller/third_party/soem/test/linux/simple_test/CMakeLists.txt Defines the build process for the simple_test executable, including linking the soem library and setting the installation destination. ```cmake set(SOURCES simple_test.c) add_executable(simple_test ${SOURCES}) target_link_libraries(simple_test soem) install(TARGETS simple_test DESTINATION bin) ``` -------------------------------- ### Set Target Header Files in CMake Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/module/dcu_driver_module/xyber_controller/xyber_api/CMakeLists.txt Specifies header files to be installed with the library. BASE_DIRS ensures correct relative paths during installation. ```cmake target_sources( ${CUR_TARGET_NAME} INTERFACE FILE_SET HEADERS BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} FILES ${head_files}) ``` -------------------------------- ### Get and Format Namespace in CMake Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/module/joy_stick_module/CMakeLists.txt Retrieves the current superior namespace and then replaces '::' with '_' for use in target names. ```cmake get_namespace(CUR_SUPERIOR_NAMESPACE) string(REPLACE "::" "_" CUR_SUPERIOR_NAMESPACE_UNDERLINE ${CUR_SUPERIOR_NAMESPACE}) ``` -------------------------------- ### Configure CMake for slaveinfo executable Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/module/dcu_driver_module/xyber_controller/third_party/soem/test/linux/slaveinfo/CMakeLists.txt Defines the build process for the slaveinfo utility, including linking the soem library and setting the installation destination. ```cmake set(SOURCES slaveinfo.c) add_executable(slaveinfo ${SOURCES}) target_link_libraries(slaveinfo soem) install(TARGETS slaveinfo DESTINATION bin) ``` -------------------------------- ### CMakeLists.txt Configuration Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/assistant/ros2_utils/CMakeLists.txt Defines the minimum CMake version, project name, package dependencies, and installation directory for the ROS 2 package. ```cmake cmake_minimum_required(VERSION 3.8) project(ros2_utils) find_package(ament_cmake REQUIRED) install( DIRECTORY launch DESTINATION share/${PROJECT_NAME}/ ) ament_package() ``` -------------------------------- ### Configure EL7031 Slave with PDO Assignments Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/module/dcu_driver_module/xyber_controller/third_party/soem/doc/tutorial.txt Sets up an EL7031 EtherCAT slave by mapping velocity PDOs and configuring motor parameters. Use this function to link slave-specific setup to the pre-operational to safe-operational hook. ```c int EL7031setup(uint16 slave) { int retval; uint16 u16val; retval = 0; /* Map velocity PDO assignment via Complete Access*/ uint16 map_1c12[4] = {0x0003, 0x1601, 0x1602, 0x1604}; uint16 map_1c13[3] = {0x0002, 0x1a01, 0x1a03}; retval += ec_SDOwrite(slave, 0x1c12, 0x00, TRUE, sizeof(map_1c12), &map_1c12, EC_TIMEOUTSAFE); retval += ec_SDOwrite(slave, 0x1c13, 0x00, TRUE, sizeof(map_1c13), &map_1c13, EC_TIMEOUTSAFE); /* set some motor parameters, just as example */ u16val = 1200; // max motor current in mA retval += ec_SDOwrite(slave, 0x8010, 0x01, FALSE, sizeof(u16val), &u16val, EC_TIMEOUTSAFE); u16val = 150; // motor coil resistance in 0.01ohm retval += ec_SDOwrite(slave, 0x8010, 0x04, FALSE, sizeof(u16val), &u16val, EC_TIMEOUTSAFE); /* set other necessary parameters as needed */ ... printf("EL7031 slave %d set,retval = %d\n", slave, retval); return 1; } ``` -------------------------------- ### Configure CMake for simple_ng Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/module/dcu_driver_module/xyber_controller/third_party/soem/test/simple_ng/CMakeLists.txt Defines the build process for the simple_ng executable, including source file specification, library linking, and installation destination. ```cmake set(SOURCES simple_ng.c) add_executable(simple_ng ${SOURCES}) target_link_libraries(simple_ng soem) install(TARGETS simple_ng DESTINATION bin) ``` -------------------------------- ### Run AgiBot X1 on Real Robot Source: https://context7.com/agibottech/agibot_x1_infer/llms.txt Launches the AgiBot X1 control system on the physical robot. This command sets raw network capabilities and starts the main AimRT executable with the robot's configuration. ```bash cd build/ ./run.sh ``` ```bash # The script executes: # sudo setcap cap_net_raw=ep ./aimrt_main # ./aimrt_main --cfg_file_path=./cfg/x1_cfg.yaml ``` -------------------------------- ### RL Control Module Configuration (YAML) Source: https://context7.com/agibottech/agibot_x1_infer/llms.txt Configuration for the Reinforcement Learning Control Module. Specifies control frequency, simulation handles, and ROS2 topic names for various sensor inputs and control outputs. Ensure topic names match your ROS2 setup. ```yaml # rl_x1.yaml - RL Control Module Configuration control_frequecy: 1000 use_sim_handles: False # Topic configuration sub_joy_vel_name: /cmd_vel_limiter # Movement command input sub_imu_data_name: /imu/data # IMU data (1000 Hz) sub_joint_state_name: /joint_states # Joint feedback (1000 Hz) pub_joint_cmd_name: /joint_cmd # Joint control output (1000 Hz) ``` -------------------------------- ### Build SOEM on Windows with Visual Studio Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/module/dcu_driver_module/xyber_controller/third_party/soem/README.md Use these commands in a Visual Studio command prompt to configure and build the project using NMake. ```shell mkdir build cd build cmake .. -G "NMake Makefiles" nmake ``` -------------------------------- ### Build Executable and Link Library Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/module/dcu_driver_module/xyber_controller/third_party/soem/test/win32/simple_test/CMakeLists.txt Configures the build system to create an executable named 'simple_test_win' from 'simple_test.c' and links it with the 'soem' library. ```cmake set(SOURCES simple_test.c) add_executable(simple_test_win ${SOURCES}) target_link_libraries(simple_test_win soem) ``` -------------------------------- ### Launch Joystick GUI Source: https://github.com/agibottech/agibot_x1_infer/blob/main/doc/joy_stick_module/joy_stick_module.md Use this command to open the joystick mapping settings GUI. This helps in visualizing and configuring the joystick's button and axis mappings. ```bash jstest-gtk ``` -------------------------------- ### Build SOEM on Linux and macOS Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/module/dcu_driver_module/xyber_controller/third_party/soem/README.md Standard build procedure for Unix-like systems using CMake and make. ```shell mkdir build cd build cmake .. make ``` -------------------------------- ### Initialize SOEM with NIC Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/module/dcu_driver_module/xyber_controller/third_party/soem/doc/tutorial.txt Initializes the SOEM library and binds a socket to the specified network interface. Returns >0 on success. ```c /* initialise SOEM, bind socket to ifname */ if (ec_init(ifname) > 0) ``` -------------------------------- ### Spawn SOEM Task Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/module/dcu_driver_module/xyber_controller/third_party/soem/doc/tutorial.txt Adds a main function to spawn a new task that executes SOEM. This is typically called by startup code. ```c int main (void) { rprintp("SOEM (Simple Open EtherCAT Master)\nSimple test\n"); task_spawn ("SimpleTest", SimpleTest, 9, 8192, NULL); ``` -------------------------------- ### Launch on Real Robot Source: https://github.com/agibottech/agibot_x1_infer/blob/main/README.md Launches the AgiBot X1 on a real robot after configuring the library path. This command should be executed from the build directory. ```bash cd build/ ./run.sh ``` -------------------------------- ### Get Current Folder Name with CMake Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/module/dcu_driver_module/xyber_controller/xyber_api/CMakeLists.txt Extracts the current directory name using a regular expression. This is useful for setting relative paths within the CMake build. ```cmake string(REGEX REPLACE ".*/(.* )" "\1" CUR_DIR ${CMAKE_CURRENT_SOURCE_DIR}) ``` -------------------------------- ### Configure Library Path for Real Robot Source: https://github.com/agibottech/agibot_x1_infer/blob/main/README.md Configures the system's library path for real-robot deployment. This involves editing /etc/ld.so.conf to include the project's build/install/lib directory and then refreshing the system environment. ```bash # Open "/etc/ld.so.conf" as root sudo vi /etc/ld.so.conf # Add this path to the end of "/etc/ld.so.conf" /opt/ros/humble/lib {YourProjectSource}/build/install/lib # Refresh system env sudo ldconfig ``` -------------------------------- ### Launch Simulation Source: https://github.com/agibottech/agibot_x1_infer/blob/main/README.md Launches the simulation environment for AgiBot X1. Ensure the handle receiver is connected before running. ```bash cd build/ ./run_sim.sh ``` -------------------------------- ### Get Current Folder Name in CMake Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/module/dcu_driver_module/xyber_controller/example/CMakeLists.txt Extracts the current directory name using a regular expression. This is useful for setting relative paths or target names based on the project structure. ```cmake string(REGEX REPLACE ".*/(.* )" "\\1" CUR_DIR ${CMAKE_CURRENT_SOURCE_DIR}) ``` -------------------------------- ### Build and Test AgiBot X1 Project Source: https://github.com/agibottech/agibot_x1_infer/blob/main/README.md Builds and tests the AgiBot X1 project. Ensure ROS2 Humble is sourced and the url_gitee.bashrc is sourced to use Gitee sources for faster downloads. The DOWNLOAD_FLAGS environment variable is used for Gitee source downloads. ```bash source /opt/ros/humble/setup.bash source url_gitee.bashrc # Build ./build.sh $DOWNLOAD_FLAGS # Test ./test.sh $DOWNLOAD_FLAGS ``` -------------------------------- ### Configure CMake Target and Dependencies Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/module/control_module/CMakeLists.txt Sets up the target library, collects source files, configures include directories, and links necessary ROS2 and third-party dependencies. ```cmake # Get the current folder name string(REGEX REPLACE ".*/\(.*\)" "\\1" CUR_DIR ${CMAKE_CURRENT_SOURCE_DIR}) # Get namespace get_namespace(CUR_SUPERIOR_NAMESPACE) string(REPLACE "::" "_" CUR_SUPERIOR_NAMESPACE_UNDERLINE ${CUR_SUPERIOR_NAMESPACE}) # Set target name set(CUR_TARGET_NAME ${CUR_SUPERIOR_NAMESPACE_UNDERLINE}_${CUR_DIR}) set(CUR_TARGET_ALIAS_NAME ${CUR_SUPERIOR_NAMESPACE}::${CUR_DIR}) # Set file collection file(GLOB_RECURSE head_files ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h) file(GLOB_RECURSE src ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cc) file(GLOB_RECURSE test_files ${CMAKE_CURRENT_SOURCE_DIR}/test/*_test.cc) list(REMOVE_ITEM src ${test_files}) # Add target add_library(${CUR_TARGET_NAME} STATIC) add_library(${CUR_TARGET_ALIAS_NAME} ALIAS ${CUR_TARGET_NAME}) # Set source file of target target_sources(${CUR_TARGET_NAME} PRIVATE ${src}) # Set include path of target target_include_directories( ${CUR_TARGET_NAME} PUBLIC $ PUBLIC $ PUBLIC $ ) target_link_directories( ${CUR_TARGET_NAME} PUBLIC $ ) # Set link libraries of target find_package(std_msgs) find_package(sensor_msgs) find_package(geometry_msgs) target_link_libraries( ${CUR_TARGET_NAME} PRIVATE yaml-cpp::yaml-cpp PUBLIC aimrt::interface::aimrt_module_cpp_interface aimrt::interface::aimrt_module_ros2_interface my_ros2_proto_aimrt_rpc_gencode my_ros2_proto::my_ros2_proto__rosidl_generator_cpp my_ros2_proto::my_ros2_proto__rosidl_typesupport_cpp my_ros2_proto::my_ros2_proto__rosidl_typesupport_fastrtps_cpp my_ros2_proto::my_ros2_proto__rosidl_typesupport_introspection_cpp std_msgs::std_msgs__rosidl_generator_cpp std_msgs::std_msgs__rosidl_typesupport_cpp std_msgs::std_msgs__rosidl_typesupport_fastrtps_cpp std_msgs::std_msgs__rosidl_typesupport_introspection_cpp sensor_msgs::sensor_msgs__rosidl_generator_cpp sensor_msgs::sensor_msgs__rosidl_typesupport_cpp sensor_msgs::sensor_msgs__rosidl_typesupport_fastrtps_cpp sensor_msgs::sensor_msgs__rosidl_typesupport_introspection_cpp geometry_msgs::geometry_msgs__rosidl_generator_cpp geometry_msgs::geometry_msgs__rosidl_typesupport_cpp geometry_msgs::geometry_msgs__rosidl_typesupport_fastrtps_cpp geometry_msgs::geometry_msgs__rosidl_typesupport_introspection_cpp onnxruntime ruckig) # Set test of target if(XYBER_X1_INFER_BUILD_TESTS AND test_files) add_gtest_target(TEST_TARGET ${CUR_TARGET_NAME} TEST_SRC ${test_files}) endif() ``` -------------------------------- ### Run AgiBot X1 Simulation Source: https://context7.com/agibottech/agibot_x1_infer/llms.txt Launches the AgiBot X1 simulation environment. This script navigates to the build directory and executes the simulation with the specified configuration. ```bash cd build/ ./run_sim.sh ``` ```bash # The script executes: # source ./install/share/ros2_plugin_proto/local_setup.bash # ./aimrt_main --cfg_file_path=./cfg/x1_cfg_sim.yaml ``` -------------------------------- ### Build AgiBot X1 Project Source: https://context7.com/agibottech/agibot_x1_infer/llms.txt Builds the AgiBot X1 project using CMake. Optionally sources Gitee mirrors for faster downloads in China. Ensure ROS2 Humble environment is sourced before running. ```bash source /opt/ros/humble/setup.bash source url_gitee.bashrc # Optional: use Gitee mirrors ./build.sh $DOWNLOAD_FLAGS ``` -------------------------------- ### Configure ROS2 and AimRT RPC Build Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/protocols/my_ros2_proto/CMakeLists.txt Sets up the project, generates ROS2 interfaces, and creates an AimRT RPC stub generation target. ```cmake cmake_minimum_required(VERSION 3.24) # Get the current folder name string(REGEX REPLACE ".*/\\(.*\\)" "\\1" CUR_DIR ${CMAKE_CURRENT_SOURCE_DIR}) # Get namespace get_namespace(CUR_SUPERIOR_NAMESPACE) string(REPLACE "::" "_" CUR_SUPERIOR_NAMESPACE_UNDERLINE ${CUR_SUPERIOR_NAMESPACE}) # Set target name set(CUR_TARGET_NAME ${CUR_DIR}) project(${CUR_TARGET_NAME}) find_package(ament_cmake REQUIRED) find_package(rosidl_default_generators REQUIRED) find_package(std_msgs REQUIRED) # Set build mode as shared library (ros2 only support shared library) set(CUR_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) set(BUILD_SHARED_LIBS ON) # cmake-format: off rosidl_generate_interfaces(${CUR_TARGET_NAME} "msg/JointCommand.msg" "msg/JoyStickData.msg" "msg/JoyStickState.msg" "srv/MyRosRpc.srv" DEPENDENCIES std_msgs) # cmake-format: on # Restore build mode set(BUILD_SHARED_LIBS ${CUR_BUILD_SHARED_LIBS}) if(NOT TARGET ${CUR_TARGET_NAME}::${CUR_TARGET_NAME}__rosidl_typesupport_cpp) add_library(${CUR_TARGET_NAME}::${CUR_TARGET_NAME}__rosidl_typesupport_cpp ALIAS ${CUR_TARGET_NAME}__rosidl_typesupport_cpp) endif() if(NOT TARGET ${CUR_TARGET_NAME}::${CUR_TARGET_NAME}__rosidl_typesupport_fastrtps_cpp) add_library(${CUR_TARGET_NAME}::${CUR_TARGET_NAME}__rosidl_typesupport_fastrtps_cpp ALIAS ${CUR_TARGET_NAME}__rosidl_typesupport_fastrtps_cpp) endif() # Generate AimRT RPC stub code, target name: ${PROJECT_NAME}_aimrt_rpc_gencode add_ros2_aimrt_rpc_gencode_target_for_one_file( TARGET_NAME ${CUR_TARGET_NAME}_aimrt_rpc_gencode # Generated target name PACKAGE_NAME ${CUR_TARGET_NAME} # ros2 package name PROTO_FILE ${CMAKE_CURRENT_SOURCE_DIR}/srv/MyRosRpc.srv # ros2 srv file GENCODE_PATH ${CMAKE_CURRENT_BINARY_DIR} # Generated code save path DEP_PROTO_TARGETS # Depend on ROS2 MSG rclcpp::rclcpp ${CUR_TARGET_NAME}::${CUR_TARGET_NAME}__rosidl_generator_cpp ${CUR_TARGET_NAME}::${CUR_TARGET_NAME}__rosidl_typesupport_cpp ${CUR_TARGET_NAME}::${CUR_TARGET_NAME}__rosidl_typesupport_fastrtps_cpp ${CUR_TARGET_NAME}::${CUR_TARGET_NAME}__rosidl_typesupport_introspection_cpp) add_library(${CUR_TARGET_ALIAS_NAME}_aimrt_rpc_gencode ALIAS ${CUR_TARGET_NAME}_aimrt_rpc_gencode) ament_export_dependencies(rosidl_default_runtime) ament_package() ``` -------------------------------- ### Define Platform-Specific Build Settings Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/module/dcu_driver_module/xyber_controller/third_party/soem/CMakeLists.txt Configures compiler flags, include directories, and system libraries based on the detected operating system. ```cmake if (WIN32) set(OS "win32") add_compile_options(/WX-) include_directories(oshw/win32/wpcap/Include oshw/win32/wpcap/Include/pcap) get_property(INC_DIRS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES) if (CMAKE_SIZEOF_VOID_P EQUAL 8) link_directories(${CMAKE_CURRENT_LIST_DIR}/oshw/win32/wpcap/Lib/x64) elseif (CMAKE_SIZEOF_VOID_P EQUAL 4) link_directories(${CMAKE_CURRENT_LIST_DIR}/oshw/win32/wpcap/Lib) endif () set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_SECURE_NO_WARNINGS") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX") set(OS_LIBS wpcap.lib Packet.lib Ws2_32.lib Winmm.lib) elseif (UNIX AND NOT APPLE) set(OS "linux") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror") set(OS_LIBS pthread rt) elseif (APPLE) # This must come *before* linux or MacOSX will identify as Unix. set(OS "macosx") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror") set(OS_LIBS pthread pcap) elseif (${CMAKE_SYSTEM_NAME} MATCHES "rt-kernel") set(OS "rtk") message(STATUS "ARCH is ${ARCH}") message(STATUS "BSP is ${BSP}") include_directories(oshw/${OS}/${ARCH}) file(GLOB OSHW_EXTRA_SOURCES oshw/${OS}/${ARCH}/*.c) set(OSHW_SOURCES "${OS_HW_SOURCES} ${OSHW_ARCHSOURCES}") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-but-set-variable") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-format") set(OS_LIBS "-Wl,--start-group -l${BSP} -l${ARCH} -lkern -ldev -lsio -lblock -lfs -lusb -llwip -leth -li2c -lrtc -lcan -lnand -lspi -lnor -lpwm -ladc -ltrace -lc -lm -Wl,--end-group") elseif (${CMAKE_SYSTEM_NAME} MATCHES "rtems") message(STATUS "Building for RTEMS") set(OS "rtems") set(SOEM_LIB_INSTALL_DIR ${LIB_DIR}) set(BUILD_TESTS FALSE) endif () ``` -------------------------------- ### Configure Velocity Command Mappings Source: https://context7.com/agibottech/agibot_x1_infer/llms.txt Sets up velocity command mappings using geometry_msgs/Twist, associating buttons and joystick axes with linear and angular velocities. Includes velocity limits. ```yaml twist_pubs: - topic_name: /cmd_vel buttons: [4] # LB button (hold to enable) axis: linear-x: 1 # Left stick Y-axis -> forward/backward linear-y: 0 # Left stick X-axis -> strafe angular-z: 3 # Right stick X-axis -> rotation velocity_limit_lb: [-0.5, -0.3, -0.5] # Min velocity limits velocity_limit_ub: [0.5, 0.3, 0.5] # Max velocity limits ``` -------------------------------- ### Source ROS2 Protocol Environment Source: https://github.com/agibottech/agibot_x1_infer/blob/main/doc/tutorials.md Execute this command in the terminal to initialize the ROS2 environment before launching AimRT or associated ROS2 processes. ```bash source ./install/ros2_setup.sh ``` -------------------------------- ### Configure State Transition Button Mappings Source: https://context7.com/agibottech/agibot_x1_infer/llms.txt Defines button mappings for various state transitions like idle, zero, stand, walk, keep, and plan modes. Each state is associated with a specific button index. ```yaml float_pubs: - topic_name: /idle_mode buttons: [7] # START button - topic_name: /zero_mode buttons: [1] # B button - topic_name: /stand_mode buttons: [0] # A button - topic_name: /walk_mode buttons: [2] # X button (walk_leg mode) - topic_name: /walk_mode2 buttons: [3] # Y button (walk_leg_arm mode) - topic_name: /keep_mode buttons: [6] # BACK button - topic_name: /plan_mode buttons: [5] # RB button ``` -------------------------------- ### Configure and Add Protobuf Target Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/protocols/example_proto/CMakeLists.txt Uses directory and namespace information to define a target name and generate Protobuf code. ```cmake # Get the current folder name string(REGEX REPLACE ".*/\\(.*\\)" "\\1" CUR_DIR ${CMAKE_CURRENT_SOURCE_DIR}) # Get namespace get_namespace(CUR_SUPERIOR_NAMESPACE) string(REPLACE "::" "_" CUR_SUPERIOR_NAMESPACE_UNDERLINE ${CUR_SUPERIOR_NAMESPACE}) # Set target name set(CUR_TARGET_NAME ${CUR_SUPERIOR_NAMESPACE_UNDERLINE}_${CUR_DIR}) set(CUR_TARGET_ALIAS_NAME ${CUR_SUPERIOR_NAMESPACE}::${CUR_DIR}) # Add target add_protobuf_gencode_target_for_proto_path( TARGET_NAME ${CUR_TARGET_NAME}_pb_gencode PROTO_PATH ${CMAKE_CURRENT_SOURCE_DIR} GENCODE_PATH ${CMAKE_CURRENT_BINARY_DIR}) add_library(${CUR_TARGET_ALIAS_NAME}_pb_gencode ALIAS ${CUR_TARGET_NAME}_pb_gencode) ``` -------------------------------- ### Configure eepromtool executable in CMake Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/module/dcu_driver_module/xyber_controller/third_party/soem/test/win32/eepromtool/CMakeLists.txt Defines the source files and links the required SOEM library for the Windows eepromtool executable. ```cmake set(SOURCES eepromtool.c) add_executable(eepromtool_win ${SOURCES}) target_link_libraries(eepromtool_win soem) ``` -------------------------------- ### Add Assistant Subdirectories Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/CMakeLists.txt Includes subdirectories for assistant-related modules. Ensure these paths are correct relative to the CMakeLists.txt file. ```cmake add_subdirectory(assistant/native_ros2_channel_publisher) ``` ```cmake add_subdirectory(assistant/native_ros2_rpc_client) ``` ```cmake add_subdirectory(assistant/ros2_utils) ``` -------------------------------- ### Directory Structure Source: https://github.com/agibottech/agibot_x1_infer/blob/main/README.md Displays the directory structure of the AgiBot X1 Infer project. This includes build scripts, CMake files, source code, documentation, and test scripts. ```bash . ├── build.sh # Build scripts ├── cmake # CMake scripts for build dependencies │ ├── GetAimRT.cmake │ ├── GetGTest.cmake │ └── NamespaceTool.cmake ├── CMakeLists.txt # Top-level CMakeLists.txt ├── format.sh # Formatting scripts ├── README.md # README document ├── doc # Development guide directory ├── src # Source code directory │ ├── CMakeLists.txt # CMakeLists.txt for the source code directory │ ├── assistant # ROS2 simulation and example project directory │ ├── install # Configuration script directory │ ├── module # Module directory │ ├── pkg # Deployment directory │ └── protocols # Protocol directory └── test.sh # Testing scripts ``` -------------------------------- ### Verify Real-Time Kernel Source: https://context7.com/agibottech/agibot_x1_infer/llms.txt Checks if the system is running with a real-time kernel, which is required for the AgiBot X1 robot's real-time performance. Both commands should indicate real-time capabilities. ```bash uname -a # Should show PREEMPT_RT cat /sys/kernel/realtime # Should return 1 ``` -------------------------------- ### Set Root Namespace Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/CMakeLists.txt Sets the root namespace for the project. This should be the first configuration step. ```cmake set_root_namespace("xyber_x1_infer") ``` -------------------------------- ### Custom Build All Target Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/CMakeLists.txt Defines a custom target 'x1_rl_infer_aimrt_build_all' that copies binaries and depends on other targets. This is used to build the entire project. ```cmake add_custom_target( x1_rl_infer_aimrt_build_all ALL COMMAND ${CMAKE_COMMAND} -E copy_directory ${CUR_INSTALL_SOURCE_DIR}/bin ${CMAKE_BINARY_DIR} DEPENDS aimrt::runtime::main xyber_x1_infer::pkg1) ``` -------------------------------- ### Auto-Configure EtherCAT Slaves Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/module/dcu_driver_module/xyber_controller/third_party/soem/doc/tutorial.txt Finds and auto-configures EtherCAT slaves on the network. It sets up mailboxes for supported slaves and requests them to enter PRE_OP state. Returns the number of configured slaves. ```c /* find and auto-config slaves */ if ( ec_config_init(FALSE) > 0 ) { rprintp("%d slaves found and configured.\n",ec_slavecount); ``` -------------------------------- ### Set Target Link Directories in CMake Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/module/joy_stick_module/CMakeLists.txt Specifies the directories where libraries should be searched for linking. Uses `BUILD_INTERFACE` for build-time visibility. ```cmake target_link_directories( ${CUR_TARGET_NAME} PUBLIC $ ) ``` -------------------------------- ### Add Library and Alias Target in CMake Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/module/joy_stick_module/CMakeLists.txt Creates a static library target and an alias for it, using the previously defined target names. ```cmake add_library(${CUR_TARGET_NAME} STATIC) add_library(${CUR_TARGET_ALIAS_NAME} ALIAS ${CUR_TARGET_NAME}) ``` -------------------------------- ### Add Protocol Subdirectories Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/CMakeLists.txt Includes subdirectories for protocol definitions. These are essential for inter-process communication. ```cmake add_subdirectory(protocols/my_proto) ``` ```cmake add_subdirectory(protocols/my_ros2_proto) ``` ```cmake add_subdirectory(protocols/example_proto) ``` -------------------------------- ### Glob Source and Header Files in CMake Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/module/dcu_driver_module/xyber_controller/xyber_api/CMakeLists.txt Recursively finds all header files in the 'include' directory and source files in the root directory. Use with caution on large projects as it can slow down CMake configuration. ```cmake file(GLOB_RECURSE head_files ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h) file(GLOB_RECURSE src src/*.cpp) ``` -------------------------------- ### Configure EtherCAT Slave Groups at Once Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/module/dcu_driver_module/xyber_controller/third_party/soem/doc/tutorial.txt Configures all slave groups simultaneously by calling `ec_config_map_group` with an argument of 0. This option shares IOmap and stores group IOmap data at the `EC_LOGGROUPOFFSET`. ```c ec_config_map_group(&IOmap, 0); ``` -------------------------------- ### Set Target Include Directories in CMake Source: https://github.com/agibottech/agibot_x1_infer/blob/main/src/module/joy_stick_module/CMakeLists.txt Configures the include paths for the target library. Uses `BUILD_INTERFACE` for paths visible during build and potentially at runtime. ```cmake target_include_directories( ${CUR_TARGET_NAME} PUBLIC $ PUBLIC $ PUBLIC $ ) ```