### Third-Party Library Integration in C++ Source: https://context7.com/miroboticslab/cyberdog_ws/llms.txt Examples for HTTP communication, JSON serialization, and MQTT messaging using integrated C++ libraries. ```cpp // 使用 cpp-httplib 进行 HTTP 通信 // third_party/cpp_httplib/include/cpp_httplib/httplib.h #include httplib::Client cli("http://localhost:8080"); auto res = cli.Get("/api/status"); if (res && res->status == 200) { std::cout << res->body << std::endl; } // 使用 rapidjson 进行 JSON 序列化 // third_party/rapidjson/include/rapidjson/document.h #include #include #include rapidjson::Document doc; doc.SetObject(); doc.AddMember("status", "ok", doc.GetAllocator()); doc.AddMember("value", 42, doc.GetAllocator()); rapidjson::StringBuffer buffer; rapidjson::Writer writer(buffer); doc.Accept(writer); std::cout << buffer.GetString() << std::endl; // 使用 MQTT-C 进行消息传输 // third_party/mqttc/include/mqttc/mqtt.h #include // 发布消息示例 mqtt_publish(&client, "cyberdog/status", message, message_len, MQTT_PUBLISH_QOS_0); // 订阅主题示例 mqtt_subscribe(&client, "cyberdog/command", 0); ``` -------------------------------- ### 拉取仓库与子模块 Source: https://context7.com/miroboticslab/cyberdog_ws/llms.txt 使用 git 和 vcstool 初始化工作空间并展开所有依赖的子模块。 ```bash # 克隆主仓库 git clone git@github.com:MiRoboticsLab/cyberdog_ws.git cd cyberdog_ws # 使用 vcstools 展开所有子模块 vcs import . < cyberdog.repos # 子模块仓库列表 # - bridges: ROS消息服务定义文件、与APP端通讯程序、CAN数据收发封装库 # - devices: 设备管理节点、BMS数据发布、LED设置、Touch插件、UWB插件 # - interaction: 语音节点、可视化编程节点、小爱训练词节点、图传节点 # - manager: 全局管理节点 # - motion: 运控管理 # - sensors: 传感器节点、GPS/雷达/ToF/超声插件 # - utils: 通用接口库 # - cyberdog_nav2: 算法任务管理 # - cyberdog_tracking_base: navigation2相关的docking、navigation、tracking功能 ``` -------------------------------- ### 构建与运行 Docker 编译环境 Source: https://context7.com/miroboticslab/cyberdog_ws/llms.txt 通过 Docker 构建 ARM64 编译镜像,并在容器内完成 ROS2 项目的编译与测试。 ```bash # 进入 tools 目录 cd tools # 构建 Docker 镜像 docker build -t cyberdog-dev . # 运行编译容器 docker run -it -v $(pwd)/../:/home/ros2/src cyberdog-dev bash # 容器内启用 ROS2 环境 ros2_galactic_on source /opt/ros2/galactic/setup.bash # 编译项目 cd /home/ros2 colcon build --packages-up-to cyberdog_bringup # 运行测试 colcon test --event-handlers console_cohesion+ --return-code-on-test-failure --packages-select cyberdog_bringup ``` -------------------------------- ### GitHub Actions CI Workflow Configuration Source: https://context7.com/miroboticslab/cyberdog_ws/llms.txt Automates the build and test process using Docker containers and ROS 2 build tools. ```yaml # .github/workflows/workflow.yml name: GitHub Actions CI run-name: ${{ github.actor }} is run GitHub Actions on: [push] defaults: run: shell: bash jobs: build-job: runs-on: ubuntu-latest steps: - name: Login to Docker Hub uses: docker/login-action@v2 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GIT_TOKEN }} - name: Install dependence run: | sudo apt install -y qemu-user-static binfmt-support - name: Download code uses: actions/checkout@v3 - name: Build and code test run: | docker pull ghcr.io/miroboticslab/cyberdog:v1 docker run -i -v $GITHUB_WORKSPACE:/home/ros2/src \ ghcr.io/miroboticslab/cyberdog:v1 bash -c \ "cd /home/ros2 && source /opt/ros2/galactic/setup.bash \ && colcon build --packages-up-to cyberdog_bringup \ && colcon test --event-handlers console_cohesion+ \ --return-code-on-test-failure \ --packages-select cyberdog_bringup" ``` -------------------------------- ### 配置 ROS2 节点 (node.yaml) Source: https://context7.com/miroboticslab/cyberdog_ws/llms.txt 定义节点的命名空间、参数、话题重映射及模拟器模式配置。 ```yaml # cyberdog_bringup/automatic/node.yaml type: namespace: &Namespace cyberdog simulator_tag: device: - &BMS bms - &TOUCH touch sensor: - &GPS gps - &LIDAR lidar - &TOF tof - &ULTRASONIC ultrasonic data: # 设备管理器节点 device_manager: package: device_manager executable: device_manager # 传感器管理器节点 sensor_manager: package: sensor_manager executable: sensor_manager # 运动管理器节点 motion_manager: package: motion_manager executable: motion_manager # 里程计发布节点 odom_out_publisher: package: motion_bridge executable: odom_out_publisher parameters: - {odom_frame: "odom", description: "腿式里程计的坐标系名称"} - {base_frame: "base_link_leg", description: "腿式里程计的子坐标系名称"} - {map_frame: "map", description: "全局坐标系名称"} - {tf_pub: False, description: "是否发布tf"} # gRPC 服务器节点 cyberdog_grpc: package: cyberdog_grpc executable: app_server # 模拟器模式下的设备管理器 sim_device_manager: package: device_manager executable: device_manager parameters: - {simulator: [*BMS, *TOUCH], description: "需要开启模拟器模式的设备"} # 模拟器模式下的传感器管理器 sim_sensor_manager: package: sensor_manager executable: sensor_manager parameters: - {simulator: [*GPS, *LIDAR, *TOF, *ULTRASONIC], description: "需要开启模拟器模式的传感器"} # 带参数和重映射的完整节点示例 bringup_test: namespace: *Namespace package: cyberdog_bringup_test executable: cyberdog_bringup_test name: bringup_test exec_name: bringup_test parameters: - {simulator: [xxx, xxx], description: "需要开启模拟器模式的对象"} - {parameters_bool: True, description: "bool 键值对"} - {parameters_int: 100, description: "int 键值对"} - {parameters_double: 0.1, description: "double 键值对"} - {parameters_string0: string_message, description: "string 键值对"} - {: test.yaml, description: "加载参数文件"} remappings: - {from: xxx1_topic, to: xxx2_topic} - {from: xxx1_service, to: xxx2_service} arguments: usr-args: - 'args1' - 'args2' ros-args: - '--log-level debug' - '--disable-stdout-logs' output: screen emulate_tty: True respawn: True ``` -------------------------------- ### System Identification Utilities in Python Source: https://context7.com/miroboticslab/cyberdog_ws/llms.txt Provides functions to retrieve network MAC addresses and generate unique namespaces based on hostname and hardware identifiers. ```python import os import re import socket import subprocess import uuid def get_shell(cmd): """执行 shell 命令并返回输出""" cmd_ret = subprocess.Popen( cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding='utf_8') return cmd_ret.communicate()[0] def get_mac(target_network_card_name=''): """ 获取计算机 MAC 地址 默认网卡:随机第一个非0地址 """ mac = '00:00:00:00:00:00' net_list = get_shell('ls /sys/class/net/').split('\n') if len(target_network_card_name) == 0: for net in net_list: if len(net) == 0: continue net = re.sub('[^0-9a-zA-Z:]+', '', net) mac = get_shell(f'cat /sys/class/net/{net}/address').strip() if mac != '00:00:00:00:00:00' and len(mac) != 0: break else: if net_list.count(target_network_card_name): mac = get_shell( f'cat /sys/class/net/{target_network_card_name}/address').strip() if len(mac) == 0: mac = uuid.UUID(int=uuid.getnode()).hex[-12:] mac = ':'.join([mac[e:e+2] for e in range(0, 11, 2)]) return re.sub('[:]+', '_', mac) def get_namespace(): """ 获取唯一命名空间 格式:hostname_macaddress """ hostname = socket.getfqdn(socket.gethostname()) mac = get_mac('eth0') namespace = f'{hostname}_{mac}' return re.sub('[^0-9a-zA-Z]+', '_', namespace) # 使用示例 if __name__ == '__main__': print(f"Namespace: {get_namespace()}") print(f"MAC Address: {get_mac()}") print(f"ETH0 MAC: {get_mac('eth0')}") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.