diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b45e96f..f2fc4a86 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,9 +93,8 @@ target_link_libraries(cmvr_es PRIVATE jsoncpp_lib cmvr_es::utils cmvr_es::service - cmvr_es::monitor + cmvr_es::monitor_manager cmvr_es::hardware - cmvr_es::httpclient cmvr_es::device::canbus cmvr_es::device::ti5motor cmvr_es::ctrl::controller diff --git a/example/follow_traj_example.cpp b/example/follow_traj_example.cpp index 6dd8e194..c696e0a4 100644 --- a/example/follow_traj_example.cpp +++ b/example/follow_traj_example.cpp @@ -13,8 +13,8 @@ #include #include -#include "utils/dynamics/robot.h" -#include "utils/controller/cartesian_controller.h" +#include "../src/utils/dynamics/include/robot.h" +#include "../src/utils/controller/include/cartesian_controller.h" // ---------- CONFIG --------------------------------------------------------- constexpr int DOF = 14; // robot DOF diff --git a/example/moveJ.cpp b/example/moveJ.cpp index 84ff39f2..3f70f125 100644 --- a/example/moveJ.cpp +++ b/example/moveJ.cpp @@ -8,7 +8,7 @@ #include // for std::atof #include -#include "device_manager/device_manager.h" +#include "../src/device_manager/include/device_manager.h" #include using namespace cmvr::device; diff --git a/example/robot_wrapper.cpp b/example/robot_wrapper.cpp index 30302d6c..992f16aa 100644 --- a/example/robot_wrapper.cpp +++ b/example/robot_wrapper.cpp @@ -10,8 +10,8 @@ #include #include -#include "devices/abstract_robot.h" -#include "device_manager/device_manager.h" +#include "../src/devices/robot/abstract_robot.h" +#include "../src/device_manager/include/device_manager.h" #include "cmvr/msgs/geometry.pb.h" namespace py = pybind11; diff --git a/example/solve_fk.cpp b/example/solve_fk.cpp index 890c634f..8a4b7235 100644 --- a/example/solve_fk.cpp +++ b/example/solve_fk.cpp @@ -5,7 +5,7 @@ #include #include -#include "utils/dynamics/robot.h" +#include "../src/utils/dynamics/include/robot.h" constexpr int DOF = 14; using RobotT = cmvr::dyn::Robot; diff --git a/example/solve_ik.cpp b/example/solve_ik.cpp index 8f679656..eb8ee575 100644 --- a/example/solve_ik.cpp +++ b/example/solve_ik.cpp @@ -2,8 +2,8 @@ // Created by xtkuang on 2025/7/31. // -#include "utils/dynamics/robot.h" -#include "utils/controller/cartesian_controller.h" +#include "../src/utils/dynamics/include/robot.h" +#include "../src/utils/controller/include/cartesian_controller.h" #include #include #include diff --git a/example/torqueOff.cpp b/example/torqueOff.cpp index 1eac8398..cc9f34e0 100644 --- a/example/torqueOff.cpp +++ b/example/torqueOff.cpp @@ -8,7 +8,7 @@ #include // for std::atof #include -#include "device_manager/device_manager.h" +#include "../src/device_manager/include/device_manager.h" #include using namespace cmvr::device; diff --git a/example/torqueOn.cpp b/example/torqueOn.cpp index a7fad195..72692554 100644 --- a/example/torqueOn.cpp +++ b/example/torqueOn.cpp @@ -8,7 +8,7 @@ #include // for std::atof #include -#include "device_manager/device_manager.h" +#include "../src/device_manager/include/device_manager.h" #include using namespace cmvr::device; diff --git a/example/wbc_example.cpp b/example/wbc_example.cpp index 1824b75b..5b2cda09 100644 --- a/example/wbc_example.cpp +++ b/example/wbc_example.cpp @@ -2,8 +2,8 @@ // Created by xtkuang on 2025/7/9. // -#include "utils/dynamics/robot.h" -#include "utils/controller/cartesian_controller.h" +#include "../src/utils/dynamics/include/robot.h" +#include "../src/utils/controller/include/cartesian_controller.h" constexpr int DOF = 14; using RobotT = cmvr::dyn::Robot; diff --git a/include/hardware/can_interface.h b/include/hardware/can_interface.h deleted file mode 100644 index 4cc13e1b..00000000 --- a/include/hardware/can_interface.h +++ /dev/null @@ -1,16 +0,0 @@ -// -// Created by xtkuang on 2025/5/6. -// - -#ifndef CMVR_ES_CAN_INTERFACE_H -#define CMVR_ES_CAN_INTERFACE_H - -namespace cmvr { - - class can_interface { - - }; - -} // cmvr - -#endif //CMVR_ES_CAN_INTERFACE_H diff --git a/include/hardware/io_interface.h b/include/hardware/io_interface.h deleted file mode 100644 index 4f04daf5..00000000 --- a/include/hardware/io_interface.h +++ /dev/null @@ -1,14 +0,0 @@ -// -// Created by linbo on 2025/9/24. -// - -#ifndef CMVR_ES_IO_INTERFACE_H -#define CMVR_ES_IO_INTERFACE_H - - -class io_interface -{ -}; - - -#endif //CMVR_ES_IO_INTERFACE_H \ No newline at end of file diff --git a/include/http/httpclient.h b/include/http/httpclient.h deleted file mode 100644 index 4a51d125..00000000 --- a/include/http/httpclient.h +++ /dev/null @@ -1,88 +0,0 @@ -// -// Created by linbo on 2025/6/24. -// - -#ifndef HTTPCLIENT_H -#define HTTPCLIENT_H -#include -#include -#include -#include -#include -#include - -// 控制是否使用libcurl的宏 -#ifdef USE_LIBCURL -#include -#endif - -using namespace std; - -namespace cmvr { - - // HTTP响应结构 - struct HttpResponse { - int statusCode; - std::string statusText; - std::map headers; - std::string body; - }; - - // HTTP异常类 - class HttpException : public std::runtime_error { - public: - HttpException(const std::string& message) : std::runtime_error(message) {} - }; - - // HTTP客户端接口 - class HttpClientImpl { - public: - virtual ~HttpClientImpl() = default; - - virtual void setBaseUrl(const std::string& baseUrl) = 0; - virtual void setTimeout(int timeout) = 0; - virtual void addHeader(const std::string& key, const std::string& value) = 0; - virtual void clearHeaders() = 0; - - virtual HttpResponse get(const std::string& path, - const std::map& params = {}) = 0; - - virtual HttpResponse post(const std::string& path, - const std::map& params = {}, - const std::string& body = "", - const std::string& contentType = "application/x-www-form-urlencoded") = 0; - - virtual HttpResponse postJson(const std::string& path, - const std::map& params = {}, - const std::string& jsonBody = "") = 0; - }; - - // HTTP客户端类 - class HttpClient { - public: - HttpClient(); - ~HttpClient() = default; - - void setBaseUrl(const std::string& baseUrl); - void setTimeout(int timeout); - void addHeader(const std::string& key, const std::string& value); - void clearHeaders(); - - HttpResponse get(const std::string& path, - const std::map& params = {}); - - HttpResponse post(const std::string& path, - const std::map& params = {}, - const std::string& body = "", - const std::string& contentType = "application/x-www-form-urlencoded"); - - HttpResponse postJson(const std::string& path, - const std::map& params = {}, - const std::string& jsonBody = ""); - - private: - std::unique_ptr m_impl; - }; - -} -#endif //HTTPCLIENT_H \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 891065a3..2572c48f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,10 +1,10 @@ add_subdirectory(utils) add_subdirectory(hardware) add_subdirectory(devices) -add_subdirectory(monitor) add_subdirectory(device_manager) +add_subdirectory(monitor) +add_subdirectory(monitor_manager) add_subdirectory(service) -add_subdirectory(http) add_subdirectory(controller) add_subdirectory(planner) diff --git a/src/controller/CMakeLists.txt b/src/controller/CMakeLists.txt index c995c881..47a770e6 100644 --- a/src/controller/CMakeLists.txt +++ b/src/controller/CMakeLists.txt @@ -2,7 +2,7 @@ find_package(glog REQUIRED) find_package(protobuf REQUIRED) add_library(controller SHARED - ${CMAKE_CURRENT_SOURCE_DIR}/touch_controller.cpp + src/touch_controller.cpp ) target_include_directories(controller PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) @@ -36,7 +36,7 @@ link_directories( add_executable(touch_controller_test - ${CMAKE_CURRENT_SOURCE_DIR}/touch_controller_test.cpp + src/touch_controller_test.cpp ) diff --git a/include/controller/touch_controller.h b/src/controller/include/touch_controller.h similarity index 96% rename from include/controller/touch_controller.h rename to src/controller/include/touch_controller.h index a92f687a..b9377577 100644 --- a/include/controller/touch_controller.h +++ b/src/controller/include/touch_controller.h @@ -6,9 +6,9 @@ #include -#include "devices/abstract_camera.h" -#include "devices/abstract_dexhand.h" -#include "devices/abstract_robot.h" +#include "../../devices/camera/abstract_camera.h" +#include "../../devices/dexhand/abstract_dexhand.h" +#include "../../devices/robot/abstract_robot.h" #include "cmvr/msgs/geometry.pb.h" #include "librealsense2/rs.h" #include "librealsense2/h/rs_frame.h" diff --git a/src/controller/touch_controller.cpp b/src/controller/src/touch_controller.cpp similarity index 99% rename from src/controller/touch_controller.cpp rename to src/controller/src/touch_controller.cpp index c4d60872..5cbfa002 100644 --- a/src/controller/touch_controller.cpp +++ b/src/controller/src/touch_controller.cpp @@ -2,7 +2,7 @@ // Created by lgv on 2025/8/24. // -#include "controller/touch_controller.h" +#include "../include/touch_controller.h" using namespace cmvr::ctrl; using namespace cmvr::msgs; diff --git a/src/controller/touch_controller_test.cpp b/src/controller/src/touch_controller_test.cpp similarity index 95% rename from src/controller/touch_controller_test.cpp rename to src/controller/src/touch_controller_test.cpp index baa283bf..be33421f 100644 --- a/src/controller/touch_controller_test.cpp +++ b/src/controller/src/touch_controller_test.cpp @@ -3,9 +3,9 @@ // -#include "device_manager/device_manager.h" +#include "../../device_manager/include/device_manager.h" #include "gtest/gtest.h" -#include "controller/touch_controller.h" +#include "../include/touch_controller.h" #include "cmvr/msgs/geometry.pb.h" diff --git a/src/data_center/include/motors_info.h b/src/data_center/include/motors_info.h index 700f4457..d1aeb97a 100644 --- a/src/data_center/include/motors_info.h +++ b/src/data_center/include/motors_info.h @@ -5,7 +5,7 @@ #ifndef CMVR_ES_MOTORS_INFO_H #define CMVR_ES_MOTORS_INFO_H -#include "devices/abstract_canbus.h" +#include "../../devices/canbus/abstract_canbus.h" #include "canbus/can_comm/can_sender.h" #include "canbus/can_comm/can_receiver.h" #include "canbus/can_comm/message_manager.h" diff --git a/src/device_manager/CMakeLists.txt b/src/device_manager/CMakeLists.txt index c28d709a..54b26943 100644 --- a/src/device_manager/CMakeLists.txt +++ b/src/device_manager/CMakeLists.txt @@ -1,7 +1,7 @@ add_library(device_manager STATIC - device_factory.cpp - device_manager.cpp - system_monitor.cpp + src/device_factory.cpp + src/device_manager.cpp + src/system_monitor.cpp ) target_include_directories(device_manager PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/include/device_manager/device_factory.h b/src/device_manager/include/device_factory.h similarity index 70% rename from include/device_manager/device_factory.h rename to src/device_manager/include/device_factory.h index 0388fb66..e398bd54 100644 --- a/include/device_manager/device_factory.h +++ b/src/device_manager/include/device_factory.h @@ -6,15 +6,15 @@ #define CMVR_ES_DEVICE_FACTORY_H #pragma once -#include "devices/abstract_agv.h" -#include "devices/abstract_battery.h" -#include "devices/abstract_camera.h" -#include "devices/abstract_dexhand.h" -#include "devices/abstract_gripper.h" -#include "devices/abstract_robot.h" -#include "devices/abstract_microphone.h" -#include "devices/abstract_speaker.h" -#include "devices/abstract_biohead.h" +#include "../../devices/agv/abstract_agv.h" +#include "../../devices/battery/abstract_battery.h" +#include "../../devices/camera/abstract_camera.h" +#include "../../devices/dexhand/abstract_dexhand.h" +#include "../../devices/gripper/abstract_gripper.h" +#include "../../devices/robot/abstract_robot.h" +#include "../../devices/microphone/abstract_microphone.h" +#include "../../devices/speaker/abstract_speaker.h" +#include "../../devices/biohead/abstract_biohead.h" namespace cmvr::device { diff --git a/include/device_manager/device_manager.h b/src/device_manager/include/device_manager.h similarity index 97% rename from include/device_manager/device_manager.h rename to src/device_manager/include/device_manager.h index 3bd1516f..ee782e5d 100644 --- a/include/device_manager/device_manager.h +++ b/src/device_manager/include/device_manager.h @@ -11,7 +11,7 @@ #include #include "device_factory.h" #include "system_monitor.h" -#include "../utils/base/thread_pool.h" +#include "../../utils/base/include/thread_pool.h" namespace cmvr::device { diff --git a/include/device_manager/system_monitor.h b/src/device_manager/include/system_monitor.h similarity index 94% rename from include/device_manager/system_monitor.h rename to src/device_manager/include/system_monitor.h index e015fc72..f39a24b2 100644 --- a/include/device_manager/system_monitor.h +++ b/src/device_manager/include/system_monitor.h @@ -13,7 +13,7 @@ #include #include #include -#include "../utils/base/timer.h" +#include "../../utils/base/include/timer.h" #include "rapidxml/xml_parser.h" namespace cmvr::device { diff --git a/src/device_manager/device_factory.cpp b/src/device_manager/src/device_factory.cpp similarity index 89% rename from src/device_manager/device_factory.cpp rename to src/device_manager/src/device_factory.cpp index 50fbe617..d56641be 100644 --- a/src/device_manager/device_factory.cpp +++ b/src/device_manager/src/device_factory.cpp @@ -2,15 +2,15 @@ // Created by xtkuang on 2025/5/13. // -#include "device_manager/device_factory.h" -#include "biohead/biohead_esp32/biohead_esp32.h" -#include "camera/uvc_camera/uvc_camera.h" -#include "camera/mechmind/mechmind_camera.h" -#include "speaker/ffmpeg_speaker/ffmpeg_speaker.h" -#include "microphone/ffmpeg_microphone/ffmpeg_microphone.h" -#include "camera/realsense_camera/realsense_camera.h" -#include "dexhand/rh56dftp_dexhand/rh56dftp_dexhand.h" -#include "robot/humanoid_robot/humanoid_robot.h" +#include "../include/device_factory.h" +#include "../../devices/biohead/biohead_esp32/include/biohead_esp32.h" +#include "../../devices/camera/uvc_camera/include/uvc_camera.h" +#include "../../devices/camera/mechmind/include/mechmind_camera.h" +#include "../../devices/speaker/ffmpeg_speaker/include/ffmpeg_speaker.h" +#include "../../devices/microphone/ffmpeg_microphone/include/ffmpeg_microphone.h" +#include "../../devices/camera/realsense_camera/include/realsense_camera.h" +#include "../../devices/dexhand/rh56dftp_dexhand/include/rh56dftp_dexhand.h" +#include "../../devices/robot/humanoid_robot/include/humanoid_robot.h" //#include "robot/ti5_robot/ti5_robot.h" #include "data_center/include/motors_info.h" using namespace std; diff --git a/src/device_manager/device_manager.cpp b/src/device_manager/src/device_manager.cpp similarity index 99% rename from src/device_manager/device_manager.cpp rename to src/device_manager/src/device_manager.cpp index bd4c1821..5ba338e3 100644 --- a/src/device_manager/device_manager.cpp +++ b/src/device_manager/src/device_manager.cpp @@ -2,7 +2,7 @@ // Created by xtkuang on 2025/5/6. // -#include "device_manager/device_manager.h" +#include "../include/device_manager.h" using namespace std; using namespace cmvr::device; diff --git a/src/device_manager/system_monitor.cpp b/src/device_manager/src/system_monitor.cpp similarity index 98% rename from src/device_manager/system_monitor.cpp rename to src/device_manager/src/system_monitor.cpp index c5bbe05c..c529ca5f 100644 --- a/src/device_manager/system_monitor.cpp +++ b/src/device_manager/src/system_monitor.cpp @@ -2,7 +2,7 @@ // Created by xtkuang on 2025/5/13. // -#include "../../include/device_manager/system_monitor.h" +#include "../include/system_monitor.h" using namespace std; using namespace cmvr::device; diff --git a/include/devices/abstract_device.h b/src/devices/abstract_device.h similarity index 100% rename from include/devices/abstract_device.h rename to src/devices/abstract_device.h diff --git a/include/devices/abstract_agv.h b/src/devices/agv/abstract_agv.h similarity index 96% rename from include/devices/abstract_agv.h rename to src/devices/agv/abstract_agv.h index f90228e9..a838fa89 100644 --- a/include/devices/abstract_agv.h +++ b/src/devices/agv/abstract_agv.h @@ -6,7 +6,7 @@ #define CMVR_ES_ABSTRACT_AGV_H #pragma once -#include "abstract_device.h" +#include "../abstract_device.h" namespace cmvr::device{ class AbstractAGV: public AbstractDevice { diff --git a/include/devices/abstract_battery.h b/src/devices/battery/abstract_battery.h similarity index 93% rename from include/devices/abstract_battery.h rename to src/devices/battery/abstract_battery.h index 1900029d..bc0ed727 100644 --- a/include/devices/abstract_battery.h +++ b/src/devices/battery/abstract_battery.h @@ -6,7 +6,7 @@ #define CMVR_ES_ABSTRACT_BATTERY_H #pragma once -#include "abstract_device.h" +#include "../abstract_device.h" namespace cmvr::device{ class AbstractBattery: public AbstractDevice { diff --git a/include/devices/abstract_biohead.h b/src/devices/biohead/abstract_biohead.h similarity index 99% rename from include/devices/abstract_biohead.h rename to src/devices/biohead/abstract_biohead.h index 86e2998d..4ebf5233 100644 --- a/include/devices/abstract_biohead.h +++ b/src/devices/biohead/abstract_biohead.h @@ -1,7 +1,7 @@ #ifndef ABSTRACT_BIOHEAD_H #define ABSTRACT_BIOHEAD_H #pragma once -#include "abstract_device.h" +#include "../abstract_device.h" namespace cmvr::device { diff --git a/src/devices/biohead/biohead_esp32/CMakeLists.txt b/src/devices/biohead/biohead_esp32/CMakeLists.txt index a5a39bd9..8c625c0c 100644 --- a/src/devices/biohead/biohead_esp32/CMakeLists.txt +++ b/src/devices/biohead/biohead_esp32/CMakeLists.txt @@ -1,5 +1,5 @@ # 定义库目标(名称统一为 head_esp32) -add_library(head_esp32 SHARED biohead_esp32.cpp) +add_library(head_esp32 SHARED src/biohead_esp32.cpp) # 设置头文件包含路径 target_include_directories(head_esp32 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/src/devices/biohead/biohead_esp32/biohead_esp32.h b/src/devices/biohead/biohead_esp32/include/biohead_esp32.h similarity index 95% rename from src/devices/biohead/biohead_esp32/biohead_esp32.h rename to src/devices/biohead/biohead_esp32/include/biohead_esp32.h index e864cb29..6c96aa23 100644 --- a/src/devices/biohead/biohead_esp32/biohead_esp32.h +++ b/src/devices/biohead/biohead_esp32/include/biohead_esp32.h @@ -1,8 +1,8 @@ #ifndef CMVR_ES_BIOHEAD_ESP32_H #define CMVR_ES_BIOHEAD_ESP32_H -#include "devices/abstract_biohead.h" -#include "hardware/esp32_serial_port.h" +#include "../../abstract_biohead.h" +#include "../../../../hardware/include/esp32_serial_port.h" #include #include #include diff --git a/src/devices/biohead/biohead_esp32/biohead_esp32.cpp b/src/devices/biohead/biohead_esp32/src/biohead_esp32.cpp similarity index 99% rename from src/devices/biohead/biohead_esp32/biohead_esp32.cpp rename to src/devices/biohead/biohead_esp32/src/biohead_esp32.cpp index 4e7f2bab..c5aa39d6 100644 --- a/src/devices/biohead/biohead_esp32/biohead_esp32.cpp +++ b/src/devices/biohead/biohead_esp32/src/biohead_esp32.cpp @@ -1,4 +1,4 @@ -#include "biohead_esp32.h" +#include "../include/biohead_esp32.h" #include #include #include diff --git a/include/devices/abstract_camera.h b/src/devices/camera/abstract_camera.h similarity index 98% rename from include/devices/abstract_camera.h rename to src/devices/camera/abstract_camera.h index 64447f24..ee47cdb4 100644 --- a/include/devices/abstract_camera.h +++ b/src/devices/camera/abstract_camera.h @@ -3,7 +3,7 @@ #pragma once #include -#include "abstract_device.h" +#include "../abstract_device.h" #include namespace cmvr::device { diff --git a/src/devices/camera/mechmind/CMakeLists.txt b/src/devices/camera/mechmind/CMakeLists.txt index 8e6dd233..0213b969 100644 --- a/src/devices/camera/mechmind/CMakeLists.txt +++ b/src/devices/camera/mechmind/CMakeLists.txt @@ -1,6 +1,6 @@ set(MECH_EYE_SDK_PATH /opt/mech-mind/mech-eye-sdk) -add_library(mechmind mechmind_camera.cpp) +add_library(mechmind src/mechmind_camera.cpp) target_include_directories(mechmind PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} diff --git a/src/devices/camera/mechmind/mechmind_camera.h b/src/devices/camera/mechmind/include/mechmind_camera.h similarity index 97% rename from src/devices/camera/mechmind/mechmind_camera.h rename to src/devices/camera/mechmind/include/mechmind_camera.h index dc22ff91..3cb9f149 100644 --- a/src/devices/camera/mechmind/mechmind_camera.h +++ b/src/devices/camera/mechmind/include/mechmind_camera.h @@ -9,7 +9,7 @@ #include #include -#include "devices/abstract_camera.h" +#include "../../abstract_camera.h" #include "area_scan_3d_camera/Camera.h" #include "area_scan_3d_camera/api_util.h" #include "area_scan_3d_camera/Mapping2DToDepth.h" diff --git a/src/devices/camera/mechmind/mechmind_camera.cpp b/src/devices/camera/mechmind/src/mechmind_camera.cpp similarity index 99% rename from src/devices/camera/mechmind/mechmind_camera.cpp rename to src/devices/camera/mechmind/src/mechmind_camera.cpp index d9a56b06..56b2e63e 100644 --- a/src/devices/camera/mechmind/mechmind_camera.cpp +++ b/src/devices/camera/mechmind/src/mechmind_camera.cpp @@ -2,7 +2,7 @@ // Created by xtkuang on 2025/6/4. // -#include "mechmind_camera.h" +#include "../include/mechmind_camera.h" using namespace std; using namespace cmvr::device; diff --git a/src/devices/camera/realsense_camera/CMakeLists.txt b/src/devices/camera/realsense_camera/CMakeLists.txt index 42bfabd1..39befb9c 100644 --- a/src/devices/camera/realsense_camera/CMakeLists.txt +++ b/src/devices/camera/realsense_camera/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(realsense_camera SHARED realsense_camera.cpp) +add_library(realsense_camera SHARED src/realsense_camera.cpp) target_include_directories(realsense_camera PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) @@ -29,7 +29,7 @@ link_directories( add_executable(realsense_camera_test - ${CMAKE_CURRENT_SOURCE_DIR}/realsense_camera_test.cpp + src/realsense_camera_test.cpp ) diff --git a/src/devices/camera/realsense_camera/realsense_camera.h b/src/devices/camera/realsense_camera/include/realsense_camera.h similarity index 98% rename from src/devices/camera/realsense_camera/realsense_camera.h rename to src/devices/camera/realsense_camera/include/realsense_camera.h index 8fc269e5..f38b3587 100644 --- a/src/devices/camera/realsense_camera/realsense_camera.h +++ b/src/devices/camera/realsense_camera/include/realsense_camera.h @@ -5,7 +5,7 @@ #ifndef REALSENSE_CAMERA_H #define REALSENSE_CAMERA_H -#include "camera/uvc_camera/uvc_camera.h" +#include "../../uvc_camera/include/uvc_camera.h" #include #include diff --git a/src/devices/camera/realsense_camera/realsense_camera.cpp b/src/devices/camera/realsense_camera/src/realsense_camera.cpp similarity index 99% rename from src/devices/camera/realsense_camera/realsense_camera.cpp rename to src/devices/camera/realsense_camera/src/realsense_camera.cpp index 1ab767c0..7d50dfd1 100644 --- a/src/devices/camera/realsense_camera/realsense_camera.cpp +++ b/src/devices/camera/realsense_camera/src/realsense_camera.cpp @@ -2,7 +2,7 @@ // Created by linbo on 2025/6/18. // -#include "realsense_camera.h" +#include "../include/realsense_camera.h" using namespace std; using namespace cmvr::device; diff --git a/src/devices/camera/realsense_camera/realsense_camera_test.cpp b/src/devices/camera/realsense_camera/src/realsense_camera_test.cpp similarity index 90% rename from src/devices/camera/realsense_camera/realsense_camera_test.cpp rename to src/devices/camera/realsense_camera/src/realsense_camera_test.cpp index 1bc68dee..ed7e645d 100644 --- a/src/devices/camera/realsense_camera/realsense_camera_test.cpp +++ b/src/devices/camera/realsense_camera/src/realsense_camera_test.cpp @@ -2,9 +2,9 @@ // Created by lgv on 2025/9/1. // #include -#include "devices/abstract_camera.h" +#include "../../abstract_camera.h" #include -#include "device_manager/device_manager.h" +#include "../../../../device_manager/include/device_manager.h" using namespace cmvr::device; // 测试: 实时显示 RGB + Depth TEST(RealsenseCameraRealDeviceTest, SaveFrames) { diff --git a/src/devices/camera/uvc_camera/CMakeLists.txt b/src/devices/camera/uvc_camera/CMakeLists.txt index fb4c258f..385bc334 100644 --- a/src/devices/camera/uvc_camera/CMakeLists.txt +++ b/src/devices/camera/uvc_camera/CMakeLists.txt @@ -1,6 +1,6 @@ find_package(OpenCV REQUIRED) -add_library(uvc_camera SHARED uvc_camera.cpp) +add_library(uvc_camera SHARED src/uvc_camera.cpp) target_include_directories(uvc_camera PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/src/devices/camera/uvc_camera/uvc_camera.h b/src/devices/camera/uvc_camera/include/uvc_camera.h similarity index 96% rename from src/devices/camera/uvc_camera/uvc_camera.h rename to src/devices/camera/uvc_camera/include/uvc_camera.h index 88db0da6..31153d74 100644 --- a/src/devices/camera/uvc_camera/uvc_camera.h +++ b/src/devices/camera/uvc_camera/include/uvc_camera.h @@ -5,14 +5,14 @@ #ifndef CMVR_ES_UVC_CAMERA_H #define CMVR_ES_UVC_CAMERA_H -#include "../../../../include/utils/base/ring_buffer.h" -#include "devices/abstract_camera.h" +#include "../../../../utils/base/include/ring_buffer.h" +#include "../../abstract_camera.h" //使用ffmpeg来编码保存视频文件 #define USE_FFMPEG_ENCODER 1 #if USE_FFMPEG_ENCODER -#include "speaker/ffmpeg_speaker/ffmpeg_ptr.h" +#include "../../../speaker/ffmpeg_speaker/include/ffmpeg_ptr.h" #endif namespace cmvr::device { diff --git a/src/devices/camera/uvc_camera/uvc_camera.cpp b/src/devices/camera/uvc_camera/src/uvc_camera.cpp similarity index 99% rename from src/devices/camera/uvc_camera/uvc_camera.cpp rename to src/devices/camera/uvc_camera/src/uvc_camera.cpp index 3d0f01f0..8bf600e3 100644 --- a/src/devices/camera/uvc_camera/uvc_camera.cpp +++ b/src/devices/camera/uvc_camera/src/uvc_camera.cpp @@ -2,7 +2,7 @@ // Created by xtkuang on 2025/5/30. // -#include "uvc_camera.h" +#include "../include/uvc_camera.h" using namespace std; using namespace cmvr::device; diff --git a/src/devices/canbus/CMakeLists.txt b/src/devices/canbus/CMakeLists.txt index 73e6828b..76f8584c 100644 --- a/src/devices/canbus/CMakeLists.txt +++ b/src/devices/canbus/CMakeLists.txt @@ -15,6 +15,7 @@ target_link_libraries(canbus PRIVATE protobuf::libprotobuf glog::glog +# proto-objects # PUBLIC pcanbasic ) diff --git a/include/devices/abstract_canbus.h b/src/devices/canbus/abstract_canbus.h similarity index 99% rename from include/devices/abstract_canbus.h rename to src/devices/canbus/abstract_canbus.h index 3056f191..ca0399d0 100644 --- a/include/devices/abstract_canbus.h +++ b/src/devices/canbus/abstract_canbus.h @@ -3,7 +3,7 @@ // #pragma once -#include "abstract_device.h" +#include "../abstract_device.h" #include "cmvr/msgs/error_code.pb.h" #include "canbus/common/byte.h" namespace cmvr::device { diff --git a/src/devices/canbus/can_client/pcan/pcan_client.h b/src/devices/canbus/can_client/pcan/pcan_client.h index cfcb960c..ba302c4c 100644 --- a/src/devices/canbus/can_client/pcan/pcan_client.h +++ b/src/devices/canbus/can_client/pcan/pcan_client.h @@ -28,7 +28,7 @@ #include "cmvr/msgs/can_card_parameter.pb.h" #include "gflags/gflags.h" -#include "devices/abstract_canbus.h" +#include "../../abstract_canbus.h" #include "canbus/common/canbus_consts.h" #include diff --git a/src/devices/canbus/can_client/socket/socket_can_client_raw.h b/src/devices/canbus/can_client/socket/socket_can_client_raw.h index bc5d1af3..3de5b42c 100644 --- a/src/devices/canbus/can_client/socket/socket_can_client_raw.h +++ b/src/devices/canbus/can_client/socket/socket_can_client_raw.h @@ -24,7 +24,7 @@ #include "cmvr/msgs/can_card_parameter.pb.h" #include "gflags/gflags.h" -#include "devices/abstract_canbus.h" +#include "../../abstract_canbus.h" #include "canbus/common/canbus_consts.h" namespace cmvr { diff --git a/src/devices/canbus/can_comm/can_sender.h b/src/devices/canbus/can_comm/can_sender.h index 89cd47b7..ae2e8336 100644 --- a/src/devices/canbus/can_comm/can_sender.h +++ b/src/devices/canbus/can_comm/can_sender.h @@ -28,7 +28,7 @@ #include #include #include "canbus/can_comm/protocol_data.h" -#include "devices/abstract_canbus.h" +#include "../abstract_canbus.h" #include "cmvr/msgs/error_code.pb.h" namespace cmvr { diff --git a/include/devices/abstract_dexhand.h b/src/devices/dexhand/abstract_dexhand.h similarity index 99% rename from include/devices/abstract_dexhand.h rename to src/devices/dexhand/abstract_dexhand.h index a748f938..430d717f 100644 --- a/include/devices/abstract_dexhand.h +++ b/src/devices/dexhand/abstract_dexhand.h @@ -6,7 +6,7 @@ #define CMVR_ES_ABSTRACT_DEXHAND_H #pragma once -#include "abstract_device.h" +#include "../abstract_device.h" namespace cmvr::device{ // 单个触觉点数据(16位无符号整数) diff --git a/src/devices/dexhand/rh56dftp_dexhand/CMakeLists.txt b/src/devices/dexhand/rh56dftp_dexhand/CMakeLists.txt index 966d1bcb..8b39c62a 100644 --- a/src/devices/dexhand/rh56dftp_dexhand/CMakeLists.txt +++ b/src/devices/dexhand/rh56dftp_dexhand/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(rh56dftp_dexhand SHARED rh56dftp_dexhand.cpp) +add_library(rh56dftp_dexhand SHARED src/rh56dftp_dexhand.cpp) target_include_directories(rh56dftp_dexhand PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/src/devices/dexhand/rh56dftp_dexhand/rh56dftp_dexhand.h b/src/devices/dexhand/rh56dftp_dexhand/include/rh56dftp_dexhand.h similarity index 94% rename from src/devices/dexhand/rh56dftp_dexhand/rh56dftp_dexhand.h rename to src/devices/dexhand/rh56dftp_dexhand/include/rh56dftp_dexhand.h index da1b34ea..308140dd 100644 --- a/src/devices/dexhand/rh56dftp_dexhand/rh56dftp_dexhand.h +++ b/src/devices/dexhand/rh56dftp_dexhand/include/rh56dftp_dexhand.h @@ -11,9 +11,9 @@ #include #include #include -#include "../../../../include/utils/base/os.h" -#include "devices/abstract_dexhand.h" -#include "hardware/serial_interface.h" +#include "../../../../utils/base/include/os.h" +#include "../../abstract_dexhand.h" +#include "../../../../hardware/include/serial_interface.h" namespace cmvr::device { diff --git a/src/devices/dexhand/rh56dftp_dexhand/rh56dftp_dexhand.cpp b/src/devices/dexhand/rh56dftp_dexhand/src/rh56dftp_dexhand.cpp similarity index 99% rename from src/devices/dexhand/rh56dftp_dexhand/rh56dftp_dexhand.cpp rename to src/devices/dexhand/rh56dftp_dexhand/src/rh56dftp_dexhand.cpp index 62479f6a..06d04730 100644 --- a/src/devices/dexhand/rh56dftp_dexhand/rh56dftp_dexhand.cpp +++ b/src/devices/dexhand/rh56dftp_dexhand/src/rh56dftp_dexhand.cpp @@ -2,7 +2,7 @@ // Created by linbo on 2025/6/20. // -#include "rh56dftp_dexhand.h" +#include "../include/rh56dftp_dexhand.h" #include #include #include diff --git a/include/devices/abstract_gripper.h b/src/devices/gripper/abstract_gripper.h similarity index 95% rename from include/devices/abstract_gripper.h rename to src/devices/gripper/abstract_gripper.h index c16d0fc3..c8b4d3c2 100644 --- a/include/devices/abstract_gripper.h +++ b/src/devices/gripper/abstract_gripper.h @@ -6,7 +6,7 @@ #define CMVR_ES_ABSTRACT_GRIPPER_H #pragma once -#include "abstract_device.h" +#include "../abstract_device.h" namespace cmvr::device{ diff --git a/include/devices/abstract_microphone.h b/src/devices/microphone/abstract_microphone.h similarity index 96% rename from include/devices/abstract_microphone.h rename to src/devices/microphone/abstract_microphone.h index 58b0d4ed..4e8e0159 100644 --- a/include/devices/abstract_microphone.h +++ b/src/devices/microphone/abstract_microphone.h @@ -6,7 +6,7 @@ #define CMVR_ES_ABSTRACT_MICROPHONE_H #pragma once -#include "abstract_device.h" +#include "../abstract_device.h" namespace cmvr::device{ class AbstractMicrophone: public AbstractDevice { diff --git a/src/devices/microphone/ffmpeg_microphone/CMakeLists.txt b/src/devices/microphone/ffmpeg_microphone/CMakeLists.txt index c7500a86..c15d8bad 100644 --- a/src/devices/microphone/ffmpeg_microphone/CMakeLists.txt +++ b/src/devices/microphone/ffmpeg_microphone/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(ffmpeg_microphone SHARED ffmpeg_microphone.cpp) +add_library(ffmpeg_microphone SHARED src/ffmpeg_microphone.cpp) target_include_directories(ffmpeg_microphone PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/src/devices/microphone/ffmpeg_microphone/ffmpeg_microphone.h b/src/devices/microphone/ffmpeg_microphone/include/ffmpeg_microphone.h similarity index 93% rename from src/devices/microphone/ffmpeg_microphone/ffmpeg_microphone.h rename to src/devices/microphone/ffmpeg_microphone/include/ffmpeg_microphone.h index 34771e7e..563df568 100644 --- a/src/devices/microphone/ffmpeg_microphone/ffmpeg_microphone.h +++ b/src/devices/microphone/ffmpeg_microphone/include/ffmpeg_microphone.h @@ -7,10 +7,10 @@ #include #include #include -#include "devices/abstract_microphone.h" +#include "../../abstract_microphone.h" #include -#include "../../../../include/utils/base/os.h" -#include "speaker/ffmpeg_speaker/ffmpeg_ptr.h" +#include "../../../../utils/base/include/os.h" +#include "../../../speaker/ffmpeg_speaker/include/ffmpeg_ptr.h" namespace cmvr::device { diff --git a/src/devices/microphone/ffmpeg_microphone/ffmpeg_microphone.cpp b/src/devices/microphone/ffmpeg_microphone/src/ffmpeg_microphone.cpp similarity index 99% rename from src/devices/microphone/ffmpeg_microphone/ffmpeg_microphone.cpp rename to src/devices/microphone/ffmpeg_microphone/src/ffmpeg_microphone.cpp index 2531427b..0baf6236 100644 --- a/src/devices/microphone/ffmpeg_microphone/ffmpeg_microphone.cpp +++ b/src/devices/microphone/ffmpeg_microphone/src/ffmpeg_microphone.cpp @@ -1,4 +1,4 @@ -#include "ffmpeg_microphone.h" +#include "../include/ffmpeg_microphone.h" using namespace std; using namespace cmvr::device; diff --git a/include/devices/abstract_motor.h b/src/devices/motor/abstract_motor.h similarity index 98% rename from include/devices/abstract_motor.h rename to src/devices/motor/abstract_motor.h index 51e06615..d5eba11e 100644 --- a/include/devices/abstract_motor.h +++ b/src/devices/motor/abstract_motor.h @@ -7,8 +7,8 @@ #pragma once -#include "abstract_device.h" -#include "utils/dynamics/joint.h" +#include "../abstract_device.h" +#include "../../utils/dynamics/include/joint.h" #include "motor/motor_protocol_interface.h" #include diff --git a/src/devices/motor/motor_manager.h b/src/devices/motor/motor_manager.h index fb849b22..c81f40dd 100644 --- a/src/devices/motor/motor_manager.h +++ b/src/devices/motor/motor_manager.h @@ -5,7 +5,7 @@ #pragma once -#include "devices/abstract_motor.h" +#include "abstract_motor.h" #include #include diff --git a/src/devices/motor/ti5_motor/canopen/ti5_motor_canopen_protocol.h b/src/devices/motor/ti5_motor/canopen/ti5_motor_canopen_protocol.h index 33cb9fd5..09a9b955 100644 --- a/src/devices/motor/ti5_motor/canopen/ti5_motor_canopen_protocol.h +++ b/src/devices/motor/ti5_motor/canopen/ti5_motor_canopen_protocol.h @@ -5,7 +5,7 @@ #pragma once #include "cmvr/msgs/motor.pb.h" #include "motor/motor_protocol_interface.h" -#include "devices/abstract_canbus.h" +#include "../../../canbus/abstract_canbus.h" #include "canbus/can_comm/can_receiver.h" #include "canbus/can_comm/can_sender.h" #include "canbus/can_comm/message_manager.h" diff --git a/src/devices/motor/ti5_motor/ti5_motor.h b/src/devices/motor/ti5_motor/ti5_motor.h index e3765f8c..5e21788b 100644 --- a/src/devices/motor/ti5_motor/ti5_motor.h +++ b/src/devices/motor/ti5_motor/ti5_motor.h @@ -2,7 +2,7 @@ // Created by lgv on 2025/8/1. // -#include "devices/abstract_motor.h" +#include "../abstract_motor.h" #include "motor/motor_protocol_interface.h" #include "motor/ti5_motor/canopen/ti5_motor_canopen_protocol.h" diff --git a/include/devices/abstract_robot.h b/src/devices/robot/abstract_robot.h similarity index 98% rename from include/devices/abstract_robot.h rename to src/devices/robot/abstract_robot.h index ae3f3af2..38fe0df7 100644 --- a/include/devices/abstract_robot.h +++ b/src/devices/robot/abstract_robot.h @@ -7,8 +7,8 @@ #pragma once #include "jsoncpp/json/json.h" -#include "abstract_device.h" -#include "utils/controller/cartesian_controller.h" +#include "../abstract_device.h" +#include "../../utils/controller/include/cartesian_controller.h" #include "cmvr/msgs/geometry.pb.h" #include "cmvr/msgs/motor.pb.h" diff --git a/src/devices/robot/humanoid_robot/CMakeLists.txt b/src/devices/robot/humanoid_robot/CMakeLists.txt index 5964efee..9e54ccba 100644 --- a/src/devices/robot/humanoid_robot/CMakeLists.txt +++ b/src/devices/robot/humanoid_robot/CMakeLists.txt @@ -1,6 +1,6 @@ find_package(protobuf REQUIRED) -add_library(humanoid_robot SHARED humanoid_robot.cpp) +add_library(humanoid_robot SHARED src/humanoid_robot.cpp) target_include_directories(humanoid_robot PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) @@ -41,7 +41,7 @@ link_directories( ) add_executable(humanoid_robot_test - ${CMAKE_CURRENT_SOURCE_DIR}/humanoid_robot_test.cpp + src/humanoid_robot_test.cpp ) target_include_directories(humanoid_robot_test PUBLIC diff --git a/src/devices/robot/humanoid_robot/humanoid_robot.h b/src/devices/robot/humanoid_robot/include/humanoid_robot.h similarity index 96% rename from src/devices/robot/humanoid_robot/humanoid_robot.h rename to src/devices/robot/humanoid_robot/include/humanoid_robot.h index 7f73537d..73ba85cc 100644 --- a/src/devices/robot/humanoid_robot/humanoid_robot.h +++ b/src/devices/robot/humanoid_robot/include/humanoid_robot.h @@ -5,13 +5,13 @@ #ifndef CMVR_ES_HUMANOID_ROBOT_H #define CMVR_ES_HUMANOID_ROBOT_H -#include "devices/abstract_robot.h" -#include "utils/controller/cartesian_controller.h" -#include "utils/base/os.h" -#include "utils/base/timer.h" -#include "utils/base/ring_buffer.h" +#include "../../abstract_robot.h" +#include "../../../../utils/controller/include/cartesian_controller.h" +#include "../../../../utils/base/include/os.h" +#include "../../../../utils/base/include/timer.h" +#include "../../../../utils/base/include/ring_buffer.h" -#include "devices/abstract_canbus.h" +#include "../../../canbus/abstract_canbus.h" #include "canbus/can_comm/can_sender.h" #include "canbus/can_comm/can_receiver.h" #include "canbus/can_comm/message_manager.h" diff --git a/src/devices/robot/humanoid_robot/humanoid_robot.cpp b/src/devices/robot/humanoid_robot/src/humanoid_robot.cpp similarity index 99% rename from src/devices/robot/humanoid_robot/humanoid_robot.cpp rename to src/devices/robot/humanoid_robot/src/humanoid_robot.cpp index 60843950..979f858a 100644 --- a/src/devices/robot/humanoid_robot/humanoid_robot.cpp +++ b/src/devices/robot/humanoid_robot/src/humanoid_robot.cpp @@ -2,10 +2,10 @@ // Created by xtkuang on 2025/7/24. // -#include "humanoid_robot.h" +#include "../include/humanoid_robot.h" #include "motor/ti5_motor/canopen/ti5_motor_canopen_protocol.h" #include "motor/ti5_motor/ti5_motor.h" -#include "utils/base/abstract_interpolation.h" +#include "../../../../utils/base/include/abstract_interpolation.h" #include "data_center/include/motors_info.h" using namespace std; diff --git a/src/devices/robot/humanoid_robot/humanoid_robot_test.cpp b/src/devices/robot/humanoid_robot/src/humanoid_robot_test.cpp similarity index 99% rename from src/devices/robot/humanoid_robot/humanoid_robot_test.cpp rename to src/devices/robot/humanoid_robot/src/humanoid_robot_test.cpp index f92c60ce..1cbf38d4 100644 --- a/src/devices/robot/humanoid_robot/humanoid_robot_test.cpp +++ b/src/devices/robot/humanoid_robot/src/humanoid_robot_test.cpp @@ -13,13 +13,13 @@ #include "gtest/gtest.h" #include -#include "device_manager/device_manager.h" +#include "../../../../device_manager/include/device_manager.h" #include #include "cmvr/msgs/can_card_parameter.grpc.pb.h" -#include "robot/humanoid_robot/humanoid_robot.h" +#include "../include/humanoid_robot.h" #include "motor/ti5_motor/canopen/ti5_motor_canopen_protocol.h" -#include "utils/base/abstract_interpolation.h" +#include "../../../../utils/base/include/abstract_interpolation.h" // 定义一个命令行参数 --config_path DEFINE_string(config_path, "../config/cabin_robot.xml", "Path to the robot config XML file"); diff --git a/src/devices/robot/ti5_robot/CMakeLists.txt b/src/devices/robot/ti5_robot/CMakeLists.txt deleted file mode 100644 index fbbb4ab0..00000000 --- a/src/devices/robot/ti5_robot/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -#add_library(ti5robot SHARED ti5_robot.cpp) -# -#target_include_directories(ti5robot PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) -# -#add_library(cmvr_es::device::ti5robot ALIAS ti5robot) \ No newline at end of file diff --git a/src/devices/robot/ti5_robot/ti5_robot.cpp b/src/devices/robot/ti5_robot/ti5_robot.cpp deleted file mode 100644 index 704da045..00000000 --- a/src/devices/robot/ti5_robot/ti5_robot.cpp +++ /dev/null @@ -1,343 +0,0 @@ -//#include "ti5_robot.h" -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -// -//using json = nlohmann::json; -//using namespace std; -//using namespace cmvr::device; -//// 服务端地址和端口(需与服务端保持一致) -//#define SERVER_IP "10.148.108.142" // 服务端IP,本地测试用127.0.0.1 -//#define SERVER_PORT 8888 // 服务端端口,与服务端PORT一致 -//// 设置socket超时(单位:毫秒) -//void set_socket_timeout(int sock, long timeout_ms) { -// struct timeval tv; -// tv.tv_sec = timeout_ms / 1000; -// tv.tv_usec = (timeout_ms % 1000) * 1000; -// setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); -//} -// -//// 发送请求并接收响应的函数 正常返回应该是Json字符串 -//bool send_request(const string& request_str,string& result) { -// int sock = 0; -// struct sockaddr_in serv_addr; -// char buffer[1024] = {0}; -// -// // 创建socket -// if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) { -// LOG(ERROR) << "[Ti5Robot] (send_request): socket create failed"; -// return false; -// } -// -// // 设置服务端地址信息 -// serv_addr.sin_family = AF_INET; -// serv_addr.sin_port = htons(SERVER_PORT); -// if (inet_pton(AF_INET, SERVER_IP, &serv_addr.sin_addr) <= 0) { -// LOG(ERROR) << "[Ti5Robot] (send_request): invaid ip address"; -// close(sock); -// return false; -// } -// -// // 连接服务端 -// if (connect(sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) { -// LOG(ERROR) << "[Ti5Robot] (send_request): connect server failed"; -// close(sock); -// return false; -// } -// -// // 发送JSON请求 -// send(sock, request_str.c_str(), request_str.length(), 0); -// LOG(INFO) << "[Ti5Robot] (send_request): request info:" << request_str; -// // 设置接收超时为3秒 -// set_socket_timeout(sock, 2000); -// // 接收服务端响应 -// ssize_t valread = read(sock, buffer, 1024); -// -// close(sock); // 关闭连接 -// if (valread == -1 && errno == EAGAIN) { -// LOG(ERROR) << "[Ti5Robot] (send_request): timeout"; -// return false; -// } -// else if (valread <= 0) { -// LOG(ERROR) << "[Ti5Robot] (send_request): read error:" << valread; -// return false; -// } -// else { -// result = buffer; -// } -// return true; -//} -// -// -//// Ti5Robot 类的实现 -//Ti5Robot::Ti5Robot(const XmlNode& cfg) : AbstractRobot(cfg) { -// // 从配置中初始化机器人参数 -// try { -// id_ = cfg_.getAttrString("id"); -// if (id_ == "left_arm") { -// arm_ = Left_Arm; -// } else if (id_ == "right_arm") { -// arm_ = Right_Arm; -// } else { -// //报错 -// } -// canInd_ = cfg_.getAttrDefault("canInd", 1); -// deviceInd_ = cfg_.getAttrDefault("deviceInd", 1); -// } -// catch (const exception& e) { -// LOG(ERROR) << "[Ti5Robot] ([Ti5Robot]): Failed to parse XML: " << e.what(); -// } -//} -// -//Ti5Robot::~Ti5Robot() { -// LOG(INFO) << "Ti5Robot 析构函数被调用"; -//} -// -//void Ti5Robot::init() { -// // 连接socket服务 -// // 检查是否可以连接到服务端。 -// // 角度范围应该在[-π,π]之间? -// std::vector goal_j(7,0.5); -// moveJ(goal_j,0.5,0.1); -//} -// -//void Ti5Robot::start() { -// LOG(INFO) << "Ti5Robot 启动"; -// // 启动机器人运行 -// // 可以添加启动CAN通道等操作 -//} -// -//void Ti5Robot::stop() { -// LOG(INFO) << "Ti5Robot 停止"; -// // 停止机器人运行 -// // 可以添加停止CAN通道等操作 -//} -// -//void Ti5Robot::getState(RobotState &state) { -// // 获取机器人当前状态 -// LOG(INFO) << "[Ti5Robot](getState)"; -// -// // 获取左右臂的关节角度 -// float currentAngles[7]; -// get_current_angle(arm_,currentAngles,canInd_,deviceInd_); -// for (float currentAngle : currentAngles) -// { -// state.joint_positions.push_back(currentAngle); -// } -// -// // 获取末端执行器位姿 -//// float pos[6]; -//// get_current_pose(Left_Arm, pos, 0, 0); -//// state.ee_pose.position.x = pos[0]; -//// state.ee_pose.position.y = pos[1]; -//// state.ee_pose.position.z = pos[2]; -//// state.ee_pose.euler.rx = pos[3]; -//// state.ee_pose.euler.ry = pos[4]; -//// state.ee_pose.euler.rz = pos[5]; -//} -// -//void Ti5Robot::eStop() { -// LOG(WARNING) << "[Ti5Robot::eStop]: The current interface is not yet implemented."; -// throw std::runtime_error("[Ti5Robot::eStop]: The current interface is not yet implemented."); -// LOG(INFO) << "Ti5Robot 紧急停止"; -// // 实现紧急停止逻辑 -// // 例如刹车操作 -// // brake(LEFT_ARM, 0, 0); // 假设使用左臂,设备索引0,通道索引0 -// // brake(RIGHT_ARM, 0, 0); -//} -// -//void Ti5Robot::moveJ(std::vector &joints, double vel, double acc) { -// //LOG(WARNING) << "[Ti5Robot::moveJ]: The current interface is not yet implemented."; -// //throw std::runtime_error("[Ti5Robot::moveJ]: The current interface is not yet implemented."); -// LOG(INFO) << "Ti5Robot 关节空间运动: 关节角度="; -// // 实现关节空间运动控制逻辑 -// float goal_j[7]; -// for (int i = 0; i < 7; ++i) { -// goal_j[i] = static_cast(joints[i]); -// } -// joint_to_move(arm_,goal_j,deviceInd_,canInd_); -//} -// -//void Ti5Robot::moveJ_IK(math::Pose3d &pose, double vel, double acc) { -// float pos[6] = {static_cast(pose.position.x), static_cast(pose.position.y), static_cast(pose.position.z), -// static_cast(pose.euler.rx), static_cast(pose.euler.ry), static_cast(pose.euler.rz)}; -// pos_to_move(arm_, pos, 0, 0); -//} -// -//void Ti5Robot::moveL(math::Pose3d &pose, double vel, double acc) { -// LOG(WARNING) << "[Ti5Robot::moveL]: The current interface is not yet implemented."; -// throw std::runtime_error("[Ti5Robot::moveL]: The current interface is not yet implemented."); -//} -// -//void Ti5Robot::teachJ(RobotJointIndex joint, RobotJointIndexDirection dir, double vel, double acc) { -// LOG(WARNING) << "[Ti5Robot::teachJ]: The current interface is not yet implemented."; -// throw std::runtime_error("[Ti5Robot::teachJ]: The current interface is not yet implemented."); -//} -// -//void Ti5Robot::teachL(RobotCartesian cart, RobotJointIndexDirection dir, double vel, double acc) { -// LOG(WARNING) << "[Ti5Robot::teachL]: The current interface is not yet implemented."; -// throw std::runtime_error("[Ti5Robot::teachL]: The current interface is not yet implemented."); -//} -// -//void Ti5Robot::followJointTrajectory(std::vector> &traj, double dt) { -// LOG(WARNING) << "[Ti5Robot::followPoseTrajectory]: The current interface is not yet implemented."; -// throw std::runtime_error("[Ti5Robot::followPoseTrajectory]: The current interface is not yet implemented."); -//} -// -//void Ti5Robot::followPoseTrajectory(std::vector &traj, double dt) { -// LOG(WARNING) << "[Ti5Robot::followPoseTrajectory]: The current interface is not yet implemented."; -// throw std::runtime_error("[Ti5Robot::followPoseTrajectory]: The current interface is not yet implemented."); -//} -// -//void Ti5Robot::servoJ(std::vector &joints, double dt) { -// LOG(WARNING) << "[Ti5Robot::servoJ]: The current interface is not yet implemented."; -// throw std::runtime_error("[Ti5Robot::servoJ]: The current interface is not yet implemented."); -//} -// -//void Ti5Robot::servoL(math::Pose3d &pose, double dt) { -// LOG(WARNING) << "[Ti5Robot::servoL]: The current interface is not yet implemented."; -// throw std::runtime_error("[Ti5Robot::servoL]: The current interface is not yet implemented."); -//} -// -//bool Ti5Robot::get_current_angle(ArmType arm, float goal_j[7], int canInd, int deviceInd) -//{ -// // 获取关节位置 -// // 获取当前关节角度 -// bool success = false; -// json req; -// req["interface"] = "get_current_angle"; // 接口名 -// if (arm == Left_Arm) { -// req["parameters"]["side"] = "LEFT_ARM"; // 参数:右臂 -// } -// else if (arm == Right_Arm) { -// req["parameters"]["side"] = "RIGHT_ARM"; // 参数:右臂 -// } -// req["parameters"]["deviceInd"] = deviceInd; // CAN设备号 -// req["parameters"]["canInd"] = canInd; // CAN通道号 -// -// string resp_str; -// auto ret = send_request(req.dump(),resp_str); -// if (ret && !resp_str.empty()) { -// json resp = json::parse(resp_str); -// if (resp.contains("error")) { -// cerr << "接口调用失败: " << resp["error"] << endl; -// } else { -// std::vector angeles = resp["result"]; -// for (int i = 0; i < 7; ++i) { -// goal_j[i] = angeles[i]; -// success = true; -// } -// } -// } -// -// return success; -//} -// -// -//bool Ti5Robot::get_current_pose(ArmType arm, float pos[6], int canInd, int deviceInd) -//{ -// // 获取关节位置 -// // 获取当前关节角度 -// bool success = false; -// json req; -// req["interface"] = "get_current_pose"; // 接口名 -// if (arm == Left_Arm) { -// req["parameters"]["side"] = "LEFT_ARM"; // 参数:右臂 -// } -// else if (arm == Right_Arm) { -// req["parameters"]["side"] = "RIGHT_ARM"; // 参数:右臂 -// } -// req["parameters"]["deviceInd"] = deviceInd; // CAN设备号 -// req["parameters"]["canInd"] = canInd; // CAN通道号 -// -// string resp_str; -// auto ret = send_request(req.dump(),resp_str); -// if (ret && !resp_str.empty()) { -// json resp = json::parse(resp_str); -// if (resp.contains("error")) { -// cerr << "接口调用失败: " << resp["error"] << endl; -// } else { -// std::vector result = resp["result"]; -// for (int i = 0; i < 6; ++i) { -// pos[i] = result[i]; -// success = true; -// } -// } -// } -// -// return success; -//} -// -// -//bool Ti5Robot::joint_to_move(ArmType side, float *goal_j, int deviceInd, int canInd) -//{ -// bool success = false; -// -// json req; -// req["interface"] = "joint_to_move"; // 接口名 -// if (arm_ == Left_Arm) { -// req["parameters"]["side"] = "LEFT_ARM"; // 参数:右臂 -// } -// else if (arm_ == Right_Arm) { -// req["parameters"]["side"] = "RIGHT_ARM"; // 参数:右臂 -// } -// req["parameters"]["deviceInd"] = deviceInd; // CAN设备号 -// req["parameters"]["canInd"] = canInd; // CAN通道号 -// // 目标角度数组(7个关节角度,单位:弧度) -// req["parameters"]["goal_j"] = *goal_j; -// -// string resp_str; -// auto ret = send_request(req.dump(),resp_str); -// if (ret && !resp_str.empty()) { -// json resp = json::parse(resp_str); -// if (resp.contains("error")) { -// success = false; -// } else { -// success = true; -// } -// } -// return success; -//} -// -//bool Ti5Robot::pos_to_move(ArmType side, float *pos, int deviceInd, int canInd) -//{ -// bool success = false; -// json req; -// req["interface"] = "pos_to_move"; // 接口名 -// if (arm_ == Left_Arm) { -// req["parameters"]["side"] = "LEFT_ARM"; // 参数:右臂 -// } -// else if (arm_ == Right_Arm) { -// req["parameters"]["side"] = "RIGHT_ARM"; // 参数:右臂 -// } -// req["parameters"]["deviceInd"] = deviceInd_; // CAN设备号 -// req["parameters"]["canInd"] = canInd_; // CAN通道号 -// req["parameters"]["pos"] = *pos; -// -// string resp_str; -// auto ret = send_request(req.dump(),resp_str); -// if (ret && !resp_str.empty()) { -// json resp = json::parse(resp_str); -// if (resp.contains("error")) { -// success = false; -// } else { -// success = true; -// } -// } -// return success; -//} diff --git a/src/devices/robot/ti5_robot/ti5_robot.h b/src/devices/robot/ti5_robot/ti5_robot.h deleted file mode 100644 index 70e5f7b6..00000000 --- a/src/devices/robot/ti5_robot/ti5_robot.h +++ /dev/null @@ -1,49 +0,0 @@ -// -// Created by linbo on 2025/7/1. -// - -#ifndef TI5_ROBOT_H -#define TI5_ROBOT_H - -#include "devices/abstract_robot.h" - -namespace cmvr::device { - class Ti5Robot final : public AbstractRobot - { - public: - explicit Ti5Robot(const XmlNode& cfg); - ~Ti5Robot() override; - void init() override; - void start() override; - void stop() override; - - void getState(RobotState &state) override; - void eStop() override; - void moveJ(std::vector &joints, double vel=0.5, double acc=0.1) override; - void moveJ_IK(math::Pose3d &pose, double vel=0.5, double acc=0.1) override; - void moveL(math::Pose3d &pose, double vel=0.5, double acc=0.1) override; - void speedJ(std::string &joint_name, RobotJointIndexDirection dir, double vel, double acc=0.5) override; - void speedL(RobotCartesian cart, RobotJointIndexDirection dir, double vel, double acc=0.5) override; - void followJointTrajectory(std::vector> &traj, double dt) override; - void followPoseTrajectory(std::vector &traj, double dt) override; - void servoJ(std::vector &joints, double dt) override; - void servoL(math::Pose3d &pose, double dt) override; - - - // 以下为socket调用ti5robot sdk的接口 -// bool get_current_angle(ArmType arm, float goal_j[7], int canInd,int deviceInd); -// bool get_current_pose(ArmType arm, float pos[6], int canInd, int deviceInd); -// bool joint_to_move(ArmType side, float *goal_j, int deviceInd, int canInd); -// bool pos_to_move(ArmType side, float *pos, int deviceInd, int canInd); - private: -// ArmType arm_; -// int canInd_; -// int deviceInd_; - - }; - -} - - - -#endif //TI5_ROBOT_H \ No newline at end of file diff --git a/src/devices/robot/ti5_robot/ti5include/Ti5BASIC.h b/src/devices/robot/ti5_robot/ti5include/Ti5BASIC.h deleted file mode 100644 index 382a3cf4..00000000 --- a/src/devices/robot/ti5_robot/ti5include/Ti5BASIC.h +++ /dev/null @@ -1,252 +0,0 @@ -#ifndef Ti5BASIC_H -#define Ti5BASIC_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "Ti5LOGIC.h" -#include "Ti5MOVE.h" - -// #include "can/tcontrolcanfactor.h" - -#define MAX_IP_ADDR_LEN 256 // 存储IP地址的最大长度 - - -// extern float arr_s[6]; - -extern bool flag; - -extern string log_path; // log文件 - -extern char LogInfo[100]; // 存储写入log文件的信息 - -extern char Info_Str[100]; // 定义一个字符数组用于存储 flag 的字符串表示 -class ArmController; // 声明ArmController类 - -extern uint8_t l_id[IDNUM], r_id[IDNUM]; // 声明左臂和右臂的canID数组 -extern ArmController l_controller; // 声明TH_L对象 -extern ArmController r_controller; // 声明TH_R对象 - -extern class humanoidLeftArm l_solver; // 数学上的解算器 -extern class humanoidRightArm r_solver; // 解算器 - - -enum ArmSide -{ - LEFT_ARM, // 左臂 - RIGHT_ARM // 右臂 -}; - -extern "C" -{ // 添加extern "C" - - // 写入调试信息到文件 - void writeDebugInfoToFile(const char *func_name, const char *info); - - // 输出数组的调试信息 - void printArrayDebugInfo(float arr[], int size, const char *arr_name); - - /* 获取本机IP地址*/ - std::string ip_address(); - - /*std::string query_can(); - 查询can设备号 - */ - std::vector query_can(); - - void receive_fully(int sock, void *buffer, size_t size); - /*socket通信 - 参数: - deviceInd:can设备号 - canInd:can通道 - port:端口号 - 发送端发送数据格式:{标识位,数据} - 标识位 - 0x01 左臂pos - 0x02 右臂pos - 0x03 左臂joint - 0x04 右臂joint - */ - int ti5_socket_server(int deviceInd, int canInd,int port); - - /*获取电机错误状态 - 参数: - side:左臂或右臂 (LEFT_ARM 左臂,RIGHT_ARM 右臂) - deviceInd:can设备号 - canInd:can通道 - dataList:接收数据的数组,错误状态 - 返回值:为电机错误 - 0:无错误 - 1:软件错误 - 2:过压 - 4:欠压 - 16:启动错误 -*/ - // int get_mechanicalarm_Maschinen_status(ArmSide side, int deviceInd, int canInd); - void get_mechanicalarm_status(ArmSide side, int deviceInd, int canInd, int32_t *dataList); - - /*清除电机错误 - 参数: - side:左臂或右臂 (LEFT_ARM 左臂,RIGHT_ARM 右臂) - deviceInd:can设备号 - canInd:can通道 - */ - void clear_elc_error(ArmSide side, int deviceInd, int canInd); - - /*机械臂刹车 - 参数: - side:左臂或右臂 (LEFT_ARM 左臂,RIGHT_ARM 右臂) - canInd:can通道 - deviceInd:can设备号 - 返回值: - true:成功 - false:失败 - */ - bool brake(ArmSide side, int deviceInd, int canInd); - - /*将数据记录下来写入文件 -参数: - pj_flag:角度或者位姿标识,1为角度 ,0为坐标 - filename:存储文件名 - array[6]:被保存的值 -*/ - void write_value(int pj_flag, string filename, float array[7]); - - /*机械臂回到原点 - 参数: - side:左臂或右臂 (LEFT_ARM 左臂,RIGHT_ARM 右臂) - canInd:can通道 - deviceInd:can设备号 - 返回值:无 - */ - void mechanical_arm_origin(ArmSide side, int deviceInd, int canInd); - - /*机械臂关节运动 - 参数: - side:左臂或右臂 (LEFT_ARM 左臂,RIGHT_ARM 右臂) - goal_j:目标关节角 - canInd:can通道 - DeviceInd:can设备号 - 返回值:无*/ - void joint_to_move(ArmSide side, float *goal_j, int deviceInd, int canInd); - void new_joint_to_move(ArmSide side, float *goal_j, int deviceInd, int canInd); - - /*机械臂关节运动,同时获取当前位置 - 参数: - side:左臂或右臂 (LEFT_ARM 左臂,RIGHT_ARM 右臂) - goal_j:目标关节角 - CUrrentJointPosition:存储当前位置 - canInd:can通道 - deviceInd:can设备号 - 返回值:无 - */ - void GetP_joint_to_move(ArmSide side, float *goal_j, float *CUrrentJointPosition, int deviceInd, int canInd); - - /*pos运动 - 参数: - side:左臂或右臂 (LEFT_ARM 左臂,RIGHT_ARM 右臂) - pos:目标位置 - value:dim的值 - dim:-1~2 代表x,y,z, -1的时候是没有臂角约束,只会接收末端位姿,其他参数忽略 - absolute:true的时候是绝对位置(以胸部原点位置),false的时候是相对位置(以当前点胳膊轴位置) - canInd:can通道 - deviceInd:can设备号 - 返回值:无 - */ - // void pos_to_move(ArmSide side, float *pos, float value, int dim, bool absolute, int deviceInd, int canInd); - bool pos_to_move(ArmSide side, float *pos, int deviceInd, int canInd); - - /*获取当前角度 - 参数: - side:左臂或右臂 (LEFT_ARM 左臂,RIGHT_ARM 右臂) - goal_j:存储角度的数组 - canInd:can通道 - deviceInd:can设备号 - */ - void get_current_angle(ArmSide side, float goal_j[7], int deviceInd, int canInd); - - /*获取当前位姿 - 参数: - side:左臂或右臂 (LEFT_ARM 左臂,RIGHT_ARM 右臂) - posz:存储位姿的数组 - canInd:can通道 - deviceInd:can设备号 - */ - void get_current_pose(ArmSide side, float posz[7], int deviceInd, int canInd); - - /*设置为电流模式,并设置目标电流 - 参数: - side:左臂或右臂 (LEFT_ARM 左臂,RIGHT_ARM 右臂) - current: 目标电流 - canInd:can通道 - deviceInd:can设备号 - */ - void set_current_mode(ArmSide side, uint32_t current[7], int deviceInd, int canInd); - - /*设置键盘控制模式 - 参数: - canInd:can通道 - deviceInd:can设备号 - */ - void LLL_keyboard_controller_J(int deviceInd, int canInd); - void LLL_keyboard_controller_P(int deviceInd, int canInd); - void RRR_keyboard_controller_J(int deviceInd, int canInd); - void RRR_keyboard_controller_P(int deviceInd, int canInd); - // void L_keyboard_controller(int deviceInd, int canInd); - // void R_keyboard_controller(int deviceInd, int canInd); - - /*获取电机当前位置 - 参数: - canInd:can通道 - deviceInd:can设备号 - MotorsTotal:电机数量 - MotorsIDlist:电机ID列表 - data:存储电机位置数据的数组 - */ - void get_motor_position(int deviceInd, int canInd, int MotorsTotal,uint8_t *MotorsIDlist,int32_t *MotorPosition); - - /*设置电机当前位置 - 参数: - canInd:can通道 - deviceInd:can设备号 - MotorsTotal:电机数量 - MotorsIDlist:电机ID列表 - data:存储电机位置数据的数组 - */ - void set_motor_position(int deviceInd, int canInd, int MotorsTotal,uint8_t *MotorsIDlist,int32_t *MotorPosition); - - - // 设定终端为非阻塞模式 - void setNonBlocking(bool enable) ; - - // 设定文件描述符为非阻塞 - void setNonBlockingInput() ; - // 清空键盘缓冲区 - void clearStdinBuffer(); - - // 读取键盘输入 - char ssscanKeyboard(); - -} // 添加extern "C" -#endif \ No newline at end of file diff --git a/src/devices/robot/ti5_robot/ti5include/Ti5CAN_Driver.h b/src/devices/robot/ti5_robot/ti5include/Ti5CAN_Driver.h deleted file mode 100644 index 05a8e7ff..00000000 --- a/src/devices/robot/ti5_robot/ti5include/Ti5CAN_Driver.h +++ /dev/null @@ -1,171 +0,0 @@ -#ifndef TI5CAN_DRIVER_H -#define TI5CAN_DRIVER_H - -#include -#include -#include -#include -#include -#include -#include - - -#include "controlcan.h" -#include "Ti5BASIC.h" - -#define GET_MOTOR_PERSIONS 8 //获取电机当前位置指令(1字节),转化为减速机角度公式:(返回值/65536/减速比)*360 -#define GET_MOTOR_ERROR 10 //获取电机错误指令(1字节) -#define CLEAR_ERROR 11 //清除电机错误指令(1字节) -#define SET_MOTOR_CURRENTS 28 //设置电机为电流模式,并设置目标电流指令(5字节) -#define SET_MOTOR_SPEED 29 //设置电机为速度模式,并设置目标速度指令(5字节),下发参数为:(目标转速(度每秒)*减速比*100)/360 -#define SET_MOTOR_POSITION 30 //设置电机为位置模式,并设置目标位置指令(5字节),下发参数为:(减速机目标角度/360)*减速比*65536 -#define SET_MOTOR_MAX_SPEED 36 //设置电机最大正向允许速度指令(5字节),下发参数为:(目标转速(度每秒)*减速比*100)/360 -#define SET_MOTOR_MIN_SPEED 37 //设置电机最小负向允许速度指令(5字节),下发参数为:(目标转速(度每秒)*减速比*100)/360 - - -extern int CanNum; - -// 查询 CAN 设备并绑定序列号与设备索引 -std::map query_can_with_index(); - /*登录并初始化can设备 - 参数:无 - 返回值 - true:成功 - false:失败 - */ -bool Start(); -// void Start(); - -bool compare_serial_numbers(const std::string &a, const std::string &b); -std::unordered_map get_device_map(); -void operate_multiple_can_devices(); - -/*登出can设备 - 参数:无 - 返回值 - true:成功 - false:失败 - */ -bool Exit(); - -int32_t convertHexArrayToDecimal(const uint8_t hexArray[4]); - -void toIntArray(int number, int *res, int size); - -/*发送1字节指令 - 参数: - DeviceInd:can设备索引 (一个为0,2个为1) - CANInd:can通道索引 (通道1:0,通道2:1) - numOfActuator:发送指令的电机数量 - canIdList:电机canId列表 - commandList:指令列表 - dataList:接收数据列表 -*/ -void sendSimpleCanCommand(int DeviceInd, int CANInd,uint8_t numOfActuator, uint8_t *canIdList, uint8_t command,int32_t *dataList); - -void sendCanCommand(int DeviceInd,int CANInd,uint8_t numOfActuator, uint8_t *canIdList, uint8_t command, uint32_t *parameterList); -#endif // TEST_CAN_H - - - -// // 比较函数,用于按字典序排序设备序列号 -// bool compare_serial_numbers(const std::string &a, const std::string &b) -// { -// return a < b; // 字典序比较 -// } - -// std::unordered_map get_device_map() -// { -// VCI_BOARD_INFO pinfo[50]; -// std::unordered_map deviceMap; -// int num = VCI_FindUsbDevice2(pinfo); // 查询所有CAN设备 - -// // 提取所有设备的序列号 -// std::vector serialNumbers; -// for (int i = 0; i < num; i++) -// { -// std::string serialNumber = ""; -// for (int j = 0; j < 20; j++) // 提取序列号 -// { -// if (pinfo[i].str_Serial_Num[j] == '\0') // 结尾判断 -// break; -// serialNumber += pinfo[i].str_Serial_Num[j]; -// } -// serialNumbers.push_back(serialNumber); -// } - -// // 按照字典序对序列号进行排序 -// std::sort(serialNumbers.begin(), serialNumbers.end(), compare_serial_numbers); - -// // 将排序后的序列号和索引进行绑定 -// for (int i = 0; i < serialNumbers.size(); i++) -// { -// deviceMap[serialNumbers[i]] = i; -// } - -// return deviceMap; // 返回序列号与设备索引的映射关系 -// } - -// void operate_multiple_can_devices() -// { -// auto deviceMap = get_device_map(); // 获取设备序列号与设备索引的映射 - -// // 遍历所有设备 -// for (const auto &pair : deviceMap) -// { -// const std::string &serialNumber = pair.first; // 设备序列号 -// int nDeviceInd = pair.second; // 设备索引 -// int nDeviceType = 4; // 根据实际设备类型设置 -// DWORD dwRel; -// VCI_INIT_CONFIG vic; - -// std::cout << "正在操作设备: " << serialNumber << " (索引: " << nDeviceInd << ")" << std::endl; - -// // 打开设备 -// dwRel = VCI_OpenDevice(nDeviceType, nDeviceInd, 0); -// if (dwRel != 1) -// { -// std::cout << "无法打开设备 " << serialNumber << std::endl; -// continue; -// } - -// // 初始化 CAN 通道 -// vic.AccCode = 0x80000008; -// vic.AccMask = 0xFFFFFFFF; -// vic.Filter = 1; -// vic.Timing0 = 0x00; -// vic.Timing1 = 0x14; -// vic.Mode = 0; - -// if (VCI_InitCAN(nDeviceType, nDeviceInd, 0, &vic) != 1) -// { -// std::cout << "初始化设备 " << serialNumber << " 的 CAN 通道 0 失败" << std::endl; -// VCI_CloseDevice(nDeviceType, nDeviceInd); -// continue; -// } - -// if (VCI_InitCAN(nDeviceType, nDeviceInd, 1, &vic) != 1) -// { -// std::cout << "初始化设备 " << serialNumber << " 的 CAN 通道 1 失败" << std::endl; -// VCI_CloseDevice(nDeviceType, nDeviceInd); -// continue; -// } - -// // 启动 CAN 通道 -// if (VCI_StartCAN(nDeviceType, nDeviceInd, 0) != 1) -// { -// std::cout << "启动设备 " << serialNumber << " 的 CAN 通道 0 失败" << std::endl; -// VCI_CloseDevice(nDeviceType, nDeviceInd); -// continue; -// } - -// if (VCI_StartCAN(nDeviceType, nDeviceInd, 1) != 1) -// { -// std::cout << "启动设备 " << serialNumber << " 的 CAN 通道 1 失败" << std::endl; -// VCI_CloseDevice(nDeviceType, nDeviceInd); -// continue; -// } - -// std::cout << "设备 " << serialNumber << " 的所有 CAN 通道启动成功!" << std::endl; -// } -// } diff --git a/src/devices/robot/ti5_robot/ti5include/Ti5LOGIC.h b/src/devices/robot/ti5_robot/ti5include/Ti5LOGIC.h deleted file mode 100644 index 91125a4d..00000000 --- a/src/devices/robot/ti5_robot/ti5include/Ti5LOGIC.h +++ /dev/null @@ -1,160 +0,0 @@ -#ifndef _TI5LOGIC_H_ -#define _TI5LOGIC_H_ -#include "mathfunc.h" -#include -#include -#include -#include "tool.h" -using namespace std; - -extern "C" -{ // 添加extern "C" - class pos_trans - { - protected: - float j[7] = {0, 0, 0, 0, 0, 0, 0}; - float orij[7]; - float prcj = 0.017; - float scd = sin(prcj) * sin(prcj); - float prc1 = float(int(10000 * sin(prcj) + 1)) / 10000; - float prc2 = prc1 * (prc1 + 2); - float prc3 = prc1 * (3 + prc1 + prc1 * prc1) + prc2; - float P_0[19][3] = {{0, 0, 0}}; // 机械臂按线性顺序的点集 - struct ROD - { - int i1, i2; // 连杆端点为P_0[i1]和P_0[i2] - float r; // 连杆半径 - float l; // 连杆长度 - }; - ROD rod[18]; // 机械臂按线性顺序的连杆集 - float len[18]; // 数学模型的长度参数(与rod.l独立) - int rodnum; // 连杆总数 - // 检测两连杆是否碰撞,P1、P2构成一根连杆,半径为r1;P3、P4构成另一根连杆,半径为r2 - bool LLcolsp(float P1[3], float P2[3], float P3[3], float P4[3], float r1, float r2); - void init_rodindex(); - // 若点距和连杆长度一致则认为点坐标值正确 - bool check_Points(); - // 根据变换矩阵计算位姿 - void MatrixT2ypr(float T[4][4]); - // 根据位姿计算变换矩阵 - void Pos2MatrixT(float T[4][4]); - // 修正角度并检测关节范围是否合法(相邻连杆间是否碰撞) - bool mendjoints(); - bool checkcalj(); - // 检测所有连杆间的碰撞 - bool check_colsp(); - - public: - float jr1[7] = {-pi, -pi, -pi, -pi, -pi, -pi, -pi}; // 关节静态角度范围 - float jr2[7] = {pi, pi, pi, pi, pi, pi, pi}; - float gap0, gap; - float ypr[6] = {0, 0, 0}; - // float j[7] = {0, 0, 0, 0, 0, 0, 0}; - void showpointsinfo(); - }; - - class humanoidLeftArm : public pos_trans - { - protected: - // 初始化固有的机械结构 - void init_arm_structure() - { - rodnum = 3; - rod[0].r = 10, rod[1].r = 10, rod[2].r = 10; // 连杆半径 170A - rod[0].l = 171, rod[1].l = 250, rod[2].l = 250; // 连杆长度 170A - // rod[0].r = 45, rod[1].r = 42, rod[2].r = 37.5; // 连杆半径 T230 - // rod[0].l = 234.5, rod[1].l = 339, rod[2].l = 301.5; // 连杆长度 T230 - init_rodindex(); - } - // 初始化数学模型参数 - void init_model_structure() - { - float M = 1.57; - jr1[6] = -pi/6; - // jr1[0] = -M, jr1[1] = -M, jr1[2] = -0.5, jr1[3] = -M, jr1[4] = -M, jr1[5] = -M, jr1[6] = -pi/6; - // jr2[0] = M, jr2[1] = M, jr2[2] = 0.5, jr2[3] = 0, jr2[4] = M, jr2[5] = M, jr2[6] = M; - gap = abs(jr1[0]); - for (int i = 1; i < 7; i++) - if (abs(jr1[i]) > gap) - gap = abs(jr1[i]); - for (int i = 0; i < 7; i++) - if (abs(jr2[i]) > gap) - gap = abs(jr2[i]); - gap0 = gap; - len[0] = rod[0].l, len[1] = rod[1].l, len[2] = rod[2].l; - P_0[1][0] = 0, P_0[1][1] = len[0], P_0[1][2] = 0; - float goal_j[7] = {0, 0, 0, 0, 0, 0, 0}; - l_forward_move(goal_j); // show_value("pos",pos,6); - ypr[0]=ypr[2]=0; - } - - // 点或向量在不同坐标系转换(p=true表示点,p=false表示向量) - void fromS0toS1(float P0[3], float P[3], bool p); - void fromS1toS2(float P0[3], float P[3], bool p); - void fromS2toS3(float P0[3], float P[3], bool p); - void fromS3toS4(float P0[3], float P[3], bool p); - void fromS4toS5(float P0[3], float P[3], bool p); - - void fromS5toS6(float P0[3], float P[3], bool p); - void fromS6toS7(float P0[3], float P[3], bool p); - - void fromS1toS0(float P0[3], float P[3], bool p); - void fromS2toS1(float P0[3], float P[3], bool p); - void fromS3toS2(float P0[3], float P[3], bool p); - void fromS4toS3(float P0[3], float P[3], bool p); - void fromS5toS4(float P0[3], float P[3], bool p); - void fromS6toS5(float P0[3], float P[3], bool p); - void fromS7toS6(float P0[3], float P[3], bool p); - bool solve_in_S6(); - bool solve_in_S4(); - bool solve_in_S2(); - // 逆运动解算器 - bool Points2J(); - // 根据角度计算点变换矩阵 - void J2MatrixT(float T[4][4]); - - public: - humanoidLeftArm(); - // 检测逆运动解出的角是否满足原始位姿 - bool checkacc(); - // 正运动 - bool l_forward_move(float goal_j[7]); - - // 获取当前角度 - void get_crt_j(float joints[7]); - - // 获取当前位置 - void get_crt_pos(float pos[6]); - - /* - 参数: - pos:目标位置 - value:dim的值 - dim:-1~2 代表x,y,z,-1的时候是没有臂角约束,只会接收末端位姿,其他参数忽略 - absolute:true的时候是绝对位置(以胸部原点位置),false的时候是相对位置(以当前点胳膊轴位置) - */ - // bool l_backward_move(float pos[6], float value, int dim, bool absolute); - bool l_backward_move(float pos[6]); - // 测试fromSi2Sj函数是否正确(是否抄错) - void testj2p(); - void show_crt_pos(); - void show_crt_j(); - }; - class humanoidRightArm : public humanoidLeftArm - { - private: - void get_r_ypr(float r_ypr[3]); - public: - humanoidRightArm(); - bool r_forward_move(float goal_j[7]); - void get_crt_j(float joints[7]); - void get_crt_pos(float postrue[6]); - // bool r_backward_move(float postrue[6], float value, int dim, bool absolute); - bool r_backward_move(float postrue[6]); - void show_crt_pos(); - void show_crt_j(); - void showpointsinfo(); - }; - -} // 添加extern "C" -#endif diff --git a/src/devices/robot/ti5_robot/ti5include/Ti5MOVE.h b/src/devices/robot/ti5_robot/ti5include/Ti5MOVE.h deleted file mode 100644 index 3b4171d0..00000000 --- a/src/devices/robot/ti5_robot/ti5include/Ti5MOVE.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef TI5MOVE_H -#define TI5MOVE_H - -#include -#include -#include -#include -// #include "can/SingleCaninterface.h" -// #include "can/motortypehelper.h" -#include -#include "tool.h" -#include "Ti5LOGIC.h" -#include -#include -#include "Ti5CAN_Driver.h" - -#define USLEEPTIME 3000 - -extern "C"{ //添加:extern C - class ArmController{ - private: - float AG = 0.005; //启停时变速的采样间距(秒 - float scale = 101; //电机内圈与外圈的速度比 - float n2p = 655.36; //内圈转速到步速的转化系数 - // float n2p = 655.36/101; //双编码器的 内圈转速到步速的转化系数 - float mvtime = 0; - // float j2p = scale * 65536 / 2 / pi; //电机外圈角度到内圈步数的转化 - float min_time = 0; - bool jstp = false; - uint8_t canidList[IDNUM]; - float nplL[4][4]; //add 用于linear_move函数机械臂直线运动 - void setn(int npL[IDNUM],int deviceInd,int canInd); - void ACTmove(float *a,float *b,float T0,int deviceInd,int canInd);// 实际运动 - public: - ArmController(uint8_t canid[IDNUM]); - // void plan_move(float crtj[IDNUM],int canInd,int deviceInd); - void plan_move(int deviceInd, int canInd,float crtj[IDNUM]); - void new_plan_move(int deviceInd,int canInd,float crtj[IDNUM]);//mfs add 2024-12-3 - void GETP_plan_move(float crtj[IDNUM],float *CUrrentJointPosition,int deviceInd,int canInd); - float NMAX = 3000; //所有电机内核最大转速值((NMAX/100)圈/秒) - float j2p = scale * 65536 / 2 / pi; //电机外圈角度到内圈步数的转化 - // float j2p = 131072/pi; //双编码器 电机外圈角度到内圈步数的转化 - }; -}//添加:extern C - -#endif \ No newline at end of file diff --git a/src/devices/robot/ti5_robot/ti5include/controlcan.h b/src/devices/robot/ti5_robot/ti5include/controlcan.h deleted file mode 100644 index d0f99994..00000000 --- a/src/devices/robot/ti5_robot/ti5include/controlcan.h +++ /dev/null @@ -1,104 +0,0 @@ -#ifndef CONTROLCAN_H -#define CONTROLCAN_H - -////文件版本:v2.02 20190609 -//接口卡类型定义 - -#define VCI_USBCAN1 3 -#define VCI_USBCAN2 4 -#define VCI_USBCAN2A 4 - -#define VCI_USBCAN_E_U 20 -#define VCI_USBCAN_2E_U 21 - -//函数调用返回状态值 -#define STATUS_OK 1 -#define STATUS_ERR 0 - -#define USHORT unsigned short int -#define BYTE unsigned char -#define CHAR char -#define UCHAR unsigned char -#define UINT unsigned int -#define DWORD unsigned int -#define PVOID void* -#define ULONG unsigned int -#define INT int -#define UINT32 UINT -#define LPVOID void* -#define BOOL BYTE -#define TRUE 1 -#define FALSE 0 - -//1.ZLGCAN系列接口卡信息的数据类型。 -typedef struct _VCI_BOARD_INFO{ - USHORT hw_Version; - USHORT fw_Version; - USHORT dr_Version; - USHORT in_Version; - USHORT irq_Num; - BYTE can_Num; - CHAR str_Serial_Num[20]; - CHAR str_hw_Type[40]; - USHORT Reserved[4]; -} VCI_BOARD_INFO,*PVCI_BOARD_INFO; - -//2.定义CAN信息帧的数据类型。 -typedef struct _VCI_CAN_OBJ{ - UINT ID; - UINT TimeStamp; - BYTE TimeFlag; - BYTE SendType; - BYTE RemoteFlag;//是否是远程帧 - BYTE ExternFlag;//是否是扩展帧 - BYTE DataLen; - BYTE Data[8]; - BYTE Reserved[3]; -}VCI_CAN_OBJ,*PVCI_CAN_OBJ; - -//3.定义初始化CAN的数据类型 -typedef struct _INIT_CONFIG{ - DWORD AccCode; - DWORD AccMask; - DWORD Reserved; - UCHAR Filter; - UCHAR Timing0; - UCHAR Timing1; - UCHAR Mode; -}VCI_INIT_CONFIG,*PVCI_INIT_CONFIG; - -///////// new add struct for filter ///////// -typedef struct _VCI_FILTER_RECORD{ - DWORD ExtFrame; //是否为扩展帧 - DWORD Start; - DWORD End; -}VCI_FILTER_RECORD,*PVCI_FILTER_RECORD; - -#ifdef __cplusplus -#define EXTERN_C extern "C" -#else -#define EXTERN_C -#endif - -EXTERN_C DWORD VCI_OpenDevice(DWORD DeviceType,DWORD DeviceInd,DWORD Reserved); -EXTERN_C DWORD VCI_CloseDevice(DWORD DeviceType,DWORD DeviceInd); -EXTERN_C DWORD VCI_InitCAN(DWORD DeviceType, DWORD DeviceInd, DWORD CANInd, PVCI_INIT_CONFIG pInitConfig); - -EXTERN_C DWORD VCI_ReadBoardInfo(DWORD DeviceType,DWORD DeviceInd,PVCI_BOARD_INFO pInfo); - -EXTERN_C DWORD VCI_SetReference(DWORD DeviceType,DWORD DeviceInd,DWORD CANInd,DWORD RefType,PVOID pData); - -EXTERN_C ULONG VCI_GetReceiveNum(DWORD DeviceType,DWORD DeviceInd,DWORD CANInd); -EXTERN_C DWORD VCI_ClearBuffer(DWORD DeviceType,DWORD DeviceInd,DWORD CANInd); - -EXTERN_C DWORD VCI_StartCAN(DWORD DeviceType,DWORD DeviceInd,DWORD CANInd); -EXTERN_C DWORD VCI_ResetCAN(DWORD DeviceType,DWORD DeviceInd,DWORD CANInd); - -EXTERN_C ULONG VCI_Transmit(DWORD DeviceType,DWORD DeviceInd,DWORD CANInd,PVCI_CAN_OBJ pSend,ULONG Len); -EXTERN_C ULONG VCI_Receive(DWORD DeviceType,DWORD DeviceInd,DWORD CANInd,PVCI_CAN_OBJ pReceive,ULONG Len,INT WaitTime); - -EXTERN_C DWORD VCI_UsbDeviceReset(DWORD DevType,DWORD DevIndex,DWORD Reserved); -EXTERN_C DWORD VCI_FindUsbDevice2(PVCI_BOARD_INFO pInfo); - -#endif - diff --git a/src/devices/robot/ti5_robot/ti5include/mathfunc.h b/src/devices/robot/ti5_robot/ti5include/mathfunc.h deleted file mode 100644 index 88c401db..00000000 --- a/src/devices/robot/ti5_robot/ti5include/mathfunc.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef MATHFUNC_H -#define MATHFUNC_H - -#include -#define pi M_PI - -extern "C"{//添加extern "C" -float vec_dot(float v1[3],float v2[3]); -float vec_length(float v[3]); -void vec_rescale(float v[3],float l,float nv[3]); -int fx2solv(float a,float b,float c,float *p1,float *p2); -float pointsdistance(float P1[3],float P2[3]); -void vec_subtraction(float v1[3],float v2[3],float v[3]); -void vec_addition(float v1[3],float v2[3],float v[3]); - -float vec_angle(float v1[3],float v2[3],float f); -float solve_trangle(float a,float b,float c); -void vec_cross(float v1[3],float v2[3],float v[3]); -float calcu_angle(float sa,float ca,float cp2); - - -void MatrixmultPoint(float T[4][4],float P0[3],float P[3]); -void Matrixmult(float T1[4][4],float T2[4][4],float T[4][4]); -void MatrixT2MatrixI(float T[4][4],float I[4][4]); - - -} -#endif \ No newline at end of file diff --git a/src/devices/robot/ti5_robot/ti5include/tool.h b/src/devices/robot/ti5_robot/ti5include/tool.h deleted file mode 100644 index 99399437..00000000 --- a/src/devices/robot/ti5_robot/ti5include/tool.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef TOOL_H -#define TOOL_H - -#include -#include -#include -#include - -using namespace std; - -#define IDNUM 7 - - -// extern "C" -// { // 添加extern "C" - void Mcopy(float (*C)[4], float (*P)[4]); - - void show_value(string name, float (*T)[4]); - void copy_value(float *copy, float *paste, int n); - void show_value(string name, float *value); - void show_value(string name,float* value,int n); - void show_value(string name, uint32_t *value); - void show_point(string name, float *value); -void show_value(string name, uint8_t *value); - void get_cmdlist(uint8_t *L, uint8_t c); - void get_paralist(uint32_t *L, uint32_t c); - - int getch(); - char scanKeyboard(); - - // void test_demo(); - // void test(); - -// } // 添加extern "C" -#endif diff --git a/include/devices/abstract_speaker.h b/src/devices/speaker/abstract_speaker.h similarity index 95% rename from include/devices/abstract_speaker.h rename to src/devices/speaker/abstract_speaker.h index 2359047b..bfda05ae 100644 --- a/include/devices/abstract_speaker.h +++ b/src/devices/speaker/abstract_speaker.h @@ -6,7 +6,7 @@ #define CMVR_ES_ABSTRACT_SPEAKER_H #pragma once -#include "abstract_device.h" +#include "../abstract_device.h" namespace cmvr::device{ class AbstractSpeaker: public AbstractDevice { diff --git a/src/devices/speaker/ffmpeg_speaker/CMakeLists.txt b/src/devices/speaker/ffmpeg_speaker/CMakeLists.txt index 24f406b8..29aee25e 100644 --- a/src/devices/speaker/ffmpeg_speaker/CMakeLists.txt +++ b/src/devices/speaker/ffmpeg_speaker/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(ffmpeg_speaker SHARED ffmpeg_speaker.cpp) +add_library(ffmpeg_speaker SHARED src/ffmpeg_speaker.cpp) target_include_directories(ffmpeg_speaker PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/src/devices/speaker/ffmpeg_speaker/ffmpeg_ptr.h b/src/devices/speaker/ffmpeg_speaker/include/ffmpeg_ptr.h similarity index 100% rename from src/devices/speaker/ffmpeg_speaker/ffmpeg_ptr.h rename to src/devices/speaker/ffmpeg_speaker/include/ffmpeg_ptr.h diff --git a/src/devices/speaker/ffmpeg_speaker/ffmpeg_speaker.h b/src/devices/speaker/ffmpeg_speaker/include/ffmpeg_speaker.h similarity index 95% rename from src/devices/speaker/ffmpeg_speaker/ffmpeg_speaker.h rename to src/devices/speaker/ffmpeg_speaker/include/ffmpeg_speaker.h index 4c3ed890..735b1bb8 100644 --- a/src/devices/speaker/ffmpeg_speaker/ffmpeg_speaker.h +++ b/src/devices/speaker/ffmpeg_speaker/include/ffmpeg_speaker.h @@ -6,10 +6,10 @@ #include #include #include -#include "devices/abstract_speaker.h" +#include "../../abstract_speaker.h" #include #include "ffmpeg_ptr.h" -#include "../../../../include/utils/base/os.h" +#include "../../../../utils/base/include/os.h" extern "C" { #include diff --git a/src/devices/speaker/ffmpeg_speaker/ffmpeg_speaker.cpp b/src/devices/speaker/ffmpeg_speaker/src/ffmpeg_speaker.cpp similarity index 99% rename from src/devices/speaker/ffmpeg_speaker/ffmpeg_speaker.cpp rename to src/devices/speaker/ffmpeg_speaker/src/ffmpeg_speaker.cpp index 22302ecf..390cba65 100644 --- a/src/devices/speaker/ffmpeg_speaker/ffmpeg_speaker.cpp +++ b/src/devices/speaker/ffmpeg_speaker/src/ffmpeg_speaker.cpp @@ -2,7 +2,7 @@ // Created by xtkuang on 2025/6/9. // -#include "ffmpeg_speaker.h" +#include "../include/ffmpeg_speaker.h" using namespace std; using namespace cmvr::device; diff --git a/include/devices/state_define.h b/src/devices/state_define.h similarity index 98% rename from include/devices/state_define.h rename to src/devices/state_define.h index 5c787521..a0a0c34b 100644 --- a/include/devices/state_define.h +++ b/src/devices/state_define.h @@ -12,7 +12,7 @@ #include #include -#include "utils/math/geometry.h" +#include "../utils/math/include/geometry.h" namespace cmvr::device{ diff --git a/src/hardware/CMakeLists.txt b/src/hardware/CMakeLists.txt index f7ef8250..83963126 100644 --- a/src/hardware/CMakeLists.txt +++ b/src/hardware/CMakeLists.txt @@ -1,8 +1,6 @@ add_library(hardware SHARED - can_interface.cpp - serial_interface.cpp - esp32_serial_port.cpp - io_interface.cpp + src/serial_interface.cpp + src/esp32_serial_port.cpp ) target_include_directories(hardware PUBLIC diff --git a/src/hardware/can_interface.cpp b/src/hardware/can_interface.cpp deleted file mode 100644 index 846228e8..00000000 --- a/src/hardware/can_interface.cpp +++ /dev/null @@ -1,8 +0,0 @@ -// -// Created by xtkuang on 2025/5/6. -// - -#include "../../include/hardware/can_interface.h" - -namespace cmvr { -} // cmvr \ No newline at end of file diff --git a/include/hardware/esp32_serial_port.h b/src/hardware/include/esp32_serial_port.h similarity index 100% rename from include/hardware/esp32_serial_port.h rename to src/hardware/include/esp32_serial_port.h diff --git a/include/hardware/serial_interface.h b/src/hardware/include/serial_interface.h similarity index 100% rename from include/hardware/serial_interface.h rename to src/hardware/include/serial_interface.h diff --git a/src/hardware/io_interface.cpp b/src/hardware/io_interface.cpp deleted file mode 100644 index 3360857b..00000000 --- a/src/hardware/io_interface.cpp +++ /dev/null @@ -1,5 +0,0 @@ -// -// Created by linbo on 2025/9/24. -// - -#include "../../include/hardware/io_interface.h" diff --git a/src/hardware/esp32_serial_port.cpp b/src/hardware/src/esp32_serial_port.cpp similarity index 99% rename from src/hardware/esp32_serial_port.cpp rename to src/hardware/src/esp32_serial_port.cpp index 3627a8e8..3d969d2e 100644 --- a/src/hardware/esp32_serial_port.cpp +++ b/src/hardware/src/esp32_serial_port.cpp @@ -1,5 +1,5 @@ // esp32_serial_port.cpp -#include "hardware/esp32_serial_port.h" +#include "../include/esp32_serial_port.h" #include #include #include diff --git a/src/hardware/serial_interface.cpp b/src/hardware/src/serial_interface.cpp similarity index 99% rename from src/hardware/serial_interface.cpp rename to src/hardware/src/serial_interface.cpp index 14fe6979..83ddd841 100644 --- a/src/hardware/serial_interface.cpp +++ b/src/hardware/src/serial_interface.cpp @@ -2,7 +2,7 @@ // Created by xtkuang on 2025/5/6. // -#include "hardware/serial_interface.h" +#include "../include/serial_interface.h" #include #include #include diff --git a/src/http/CMakeLists.txt b/src/http/CMakeLists.txt deleted file mode 100644 index 351fafcb..00000000 --- a/src/http/CMakeLists.txt +++ /dev/null @@ -1,40 +0,0 @@ -# 定义是否使用libcurl的变量 -set(USE_LIBCURL ON CACHE BOOL "Use libcurl for HTTP requests") - -# 创建共享库 - 先定义目标 -add_library(httpclient SHARED - httpclient.cpp -) - -# 设置公共包含目录 -target_include_directories(httpclient PUBLIC - ${PROJECT_SOURCE_DIR}/include -) - -# 如果使用libcurl,查找并配置libcurl -if(USE_LIBCURL) - # 查找libcurl库 - find_package(CURL REQUIRED) - - if(CURL_FOUND) - message(STATUS "Found libcurl: ${CURL_VERSION_STRING}") - message(STATUS "libcurl include dirs: ${CURL_INCLUDE_DIRS}") - message(STATUS "libcurl libraries: ${CURL_LIBRARIES}") - - # 添加libcurl的包含目录 - target_include_directories(httpclient PUBLIC ${CURL_INCLUDE_DIRS}) - - # 将USE_LIBCURL宏应用到httpclient库 - target_compile_definitions(httpclient PUBLIC USE_LIBCURL) - - # 链接libcurl库 - target_link_libraries(httpclient PUBLIC ${CURL_LIBRARIES}) - else() - message(FATAL_ERROR "libcurl not found. Please install libcurl-dev package.") - endif() -else() - message(STATUS "Using native socket implementation for HTTP requests") -endif() - -# 添加别名 -add_library(cmvr_es::httpclient ALIAS httpclient) \ No newline at end of file diff --git a/src/http/httpclient.cpp b/src/http/httpclient.cpp deleted file mode 100644 index 5941fcfe..00000000 --- a/src/http/httpclient.cpp +++ /dev/null @@ -1,673 +0,0 @@ -// -// Created by linbo on 2025/6/24. -// - -#include "../../include/http/httpclient.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef USE_LIBCURL -#include -#endif - -namespace cmvr { - -// URL解析辅助函数 -struct UrlParts { - std::string protocol; - std::string host; - int port; - std::string path; - std::map queryParams; -}; - -UrlParts parseUrl(const std::string& url) { - UrlParts parts; - - // 解析协议 - size_t protocolEnd = url.find("://"); - if (protocolEnd != std::string::npos) { - parts.protocol = url.substr(0, protocolEnd); - } else { - throw HttpException("Invalid URL: missing protocol"); - } - - // 解析主机和端口 - size_t hostStart = protocolEnd + 3; - size_t pathStart = url.find("/", hostStart); - if (pathStart == std::string::npos) { - pathStart = url.length(); - } - - std::string hostPart = url.substr(hostStart, pathStart - hostStart); - size_t portPos = hostPart.find(":"); - - if (portPos != std::string::npos) { - parts.host = hostPart.substr(0, portPos); - parts.port = std::stoi(hostPart.substr(portPos + 1)); - } else { - parts.host = hostPart; - if (parts.protocol == "http") { - parts.port = 80; - } else if (parts.protocol == "https") { - parts.port = 443; - } else { - throw HttpException("Unsupported protocol: " + parts.protocol); - } - } - - // 解析路径和查询参数 - if (pathStart < url.length()) { - std::string pathAndQuery = url.substr(pathStart); - size_t queryStart = pathAndQuery.find("?"); - - if (queryStart != std::string::npos) { - parts.path = pathAndQuery.substr(0, queryStart); - std::string queryString = pathAndQuery.substr(queryStart + 1); - - // 解析查询参数 - size_t paramStart = 0; - while (paramStart < queryString.length()) { - size_t paramEnd = queryString.find("&", paramStart); - if (paramEnd == std::string::npos) { - paramEnd = queryString.length(); - } - - std::string param = queryString.substr(paramStart, paramEnd - paramStart); - size_t equalsPos = param.find("="); - - if (equalsPos != std::string::npos) { - std::string key = param.substr(0, equalsPos); - std::string value = param.substr(equalsPos + 1); - parts.queryParams[key] = value; - } - - paramStart = paramEnd + 1; - } - } else { - parts.path = pathAndQuery; - } - } else { - parts.path = "/"; - } - - return parts; -} - -// 构建完整URL(baseUrl + path + params) -std::string buildUrl(const std::string& baseUrl, - const std::string& path, - const std::map& params) { - std::stringstream urlStream; - - // 添加基础URL - if (!baseUrl.empty()) { - urlStream << baseUrl; - - // 确保路径以斜杠开始 - if (baseUrl.back() != '/' && (!path.empty() && path.front() != '/')) { - urlStream << '/'; - } - } - - // 添加路径 - if (!path.empty()) { - urlStream << path; - } else if (baseUrl.empty()) { - urlStream << '/'; - } - - // 添加查询参数 - if (!params.empty()) { - urlStream << '?'; - bool first = true; - - for (const auto& param : params) { - if (!first) { - urlStream << '&'; - } - - urlStream << param.first << '=' << param.second; - first = false; - } - } - - return urlStream.str(); -} - -// libcurl响应数据回调函数 -#ifdef USE_LIBCURL -static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp) { - ((std::string*)userp)->append((char*)contents, size * nmemb); - return size * nmemb; -} -#endif -// 原生socket实现 -class SocketHttpClientImpl : public HttpClientImpl { -public: - SocketHttpClientImpl() : m_baseUrl(), m_timeout(10000) {} - ~SocketHttpClientImpl() override = default; - - void setBaseUrl(const std::string& baseUrl) override { - m_baseUrl = baseUrl; - } - - void setTimeout(int timeout) override { - m_timeout = timeout; - } - - void addHeader(const std::string& key, const std::string& value) override { - m_headers[key] = value; - } - - void clearHeaders() override { - m_headers.clear(); - } - - HttpResponse get(const std::string& path, - const std::map& params) override { - return executeRequest("GET", buildUrl(m_baseUrl, path, params), "", ""); - } - - HttpResponse post(const std::string& path, - const std::map& params, - const std::string& body, - const std::string& contentType) override { - return executeRequest("POST", buildUrl(m_baseUrl, path, params), contentType, body); - } - - HttpResponse postJson(const std::string& path, - const std::map& params, - const std::string& jsonBody) override { - return executeRequest("POST", buildUrl(m_baseUrl, path, params), "application/json", jsonBody); - } - -private: - std::string m_baseUrl; - int m_timeout; - std::map m_headers; - - HttpResponse executeRequest(const std::string& method, - const std::string& url, - const std::string& contentType, - const std::string& body) { - HttpResponse response; - - try { - // 解析URL - UrlParts parts = parseUrl(url); - - // 检查协议(原生socket实现不支持HTTPS) - if (parts.protocol != "http") { - throw HttpException("Unsupported protocol: " + parts.protocol + - ". Native socket implementation only supports HTTP."); - } - - // 创建socket - int sockfd = socket(AF_INET, SOCK_STREAM, 0); - if (sockfd < 0) { - throw HttpException("Failed to create socket"); - } - - // 设置超时 - struct timeval timeout; - timeout.tv_sec = m_timeout / 1000; - timeout.tv_usec = (m_timeout % 1000) * 1000; - - if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) < 0) { - close(sockfd); - throw HttpException("Failed to set receive timeout"); - } - - if (setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout)) < 0) { - close(sockfd); - throw HttpException("Failed to set send timeout"); - } - - // 获取主机地址 - struct hostent* server = gethostbyname(parts.host.c_str()); - if (server == NULL) { - close(sockfd); - throw HttpException("Failed to resolve host: " + parts.host); - } - - // 设置服务器地址 - struct sockaddr_in serv_addr; - memset(&serv_addr, 0, sizeof(serv_addr)); - serv_addr.sin_family = AF_INET; - memcpy(&serv_addr.sin_addr.s_addr, server->h_addr, server->h_length); - serv_addr.sin_port = htons(parts.port); - - // 连接到服务器 - if (connect(sockfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) { - close(sockfd); - throw HttpException("Failed to connect to server: " + parts.host); - } - - // 构建并发送请求 - std::stringstream request; - request << method << " " << parts.path; - - // 添加查询参数 - if (!parts.queryParams.empty()) { - request << '?'; - bool first = true; - - for (const auto& param : parts.queryParams) { - if (!first) { - request << '&'; - } - - request << param.first << '=' << param.second; - first = false; - } - } - - request << " HTTP/1.1\r\n"; - request << "Host: " << parts.host; - if (parts.port != 80) { - request << ":" << parts.port; - } - request << "\r\n"; - - // 添加内容类型头(如果有) - if (!contentType.empty()) { - request << "Content-Type: " << contentType << "\r\n"; - } - - // 添加用户代理头 - request << "User-Agent: SocketHttpClient/1.0\r\n"; - - // 添加其他自定义头 - for (const auto& header : m_headers) { - request << header.first << ": " << header.second << "\r\n"; - } - - // 添加内容长度头(如果有请求体) - if (!body.empty()) { - request << "Content-Length: " << body.length() << "\r\n"; - } - - // 添加连接头 - request << "Connection: close\r\n\r\n"; - - // 添加请求体(如果有) - if (!body.empty()) { - request << body; - } - - // 发送请求 - std::string requestStr = request.str(); - if (send(sockfd, requestStr.c_str(), requestStr.length(), 0) < 0) { - close(sockfd); - throw HttpException("Failed to send request"); - } - - // 接收响应 - char buffer[4096]; - std::string responseData; - ssize_t bytesRead; - - while ((bytesRead = recv(sockfd, buffer, sizeof(buffer) - 1, 0)) > 0) { - buffer[bytesRead] = '\0'; - responseData += buffer; - } - - if (bytesRead < 0) { - close(sockfd); - throw HttpException("Failed to receive response"); - } - - // 关闭socket - close(sockfd); - - // 解析响应 - size_t headerEnd = responseData.find("\r\n\r\n"); - if (headerEnd != std::string::npos) { - // 解析状态行 - size_t statusLineEnd = responseData.find("\r\n"); - if (statusLineEnd != std::string::npos) { - std::string statusLine = responseData.substr(0, statusLineEnd); - - // 解析HTTP版本 - size_t httpVersionEnd = statusLine.find(' '); - if (httpVersionEnd != std::string::npos) { - // 解析状态码 - size_t statusCodeStart = httpVersionEnd + 1; - size_t statusCodeEnd = statusLine.find(' ', statusCodeStart); - - if (statusCodeStart != std::string::npos && statusCodeEnd != std::string::npos) { - std::string statusCodeStr = statusLine.substr(statusCodeStart, statusCodeEnd - statusCodeStart); - response.statusCode = std::stoi(statusCodeStr); - - // 解析状态文本 - response.statusText = statusLine.substr(statusCodeEnd + 1); - } - } - } - - // 解析响应头 - size_t headerStart = responseData.find("\r\n") + 2; - std::string headers = responseData.substr(headerStart, headerEnd - headerStart); - std::istringstream headerStream(headers); - std::string line; - - while (std::getline(headerStream, line) && line.length() > 1) { - if (line.back() == '\r') { - line.pop_back(); - } - - size_t colonPos = line.find(':'); - if (colonPos != std::string::npos) { - std::string key = line.substr(0, colonPos); - std::string value = line.substr(colonPos + 1); - - // 去除前后空格 - size_t start = value.find_first_not_of(" \t"); - size_t end = value.find_last_not_of(" \t"); - - if (start != std::string::npos && end != std::string::npos) { - value = value.substr(start, end - start + 1); - } - - response.headers[key] = value; - } - } - - // 获取响应体 - response.body = responseData.substr(headerEnd + 4); - } else { - // 没有找到响应头结束标记,可能是不完整的响应 - response.body = responseData; - } - } catch (const std::exception& e) { - throw HttpException(std::string("HTTP request failed: ") + e.what()); - } - - return response; - } -}; - -// libcurl实现 -#ifdef USE_LIBCURL -class LibcurlHttpClientImpl : public HttpClientImpl { -public: - LibcurlHttpClientImpl() : m_baseUrl(), m_timeout(10000) { - // 初始化libcurl - CURLcode res = curl_global_init(CURL_GLOBAL_ALL); - if (res != CURLE_OK) { - throw HttpException("Failed to initialize libcurl: " + std::string(curl_easy_strerror(res))); - } - } - - ~LibcurlHttpClientImpl() override { - // 清理libcurl - curl_global_cleanup(); - } - - void setBaseUrl(const std::string& baseUrl) override { - m_baseUrl = baseUrl; - } - - void setTimeout(int timeout) override { - m_timeout = timeout; - } - - void addHeader(const std::string& key, const std::string& value) override { - m_headers[key] = value; - } - - void clearHeaders() override { - m_headers.clear(); - } - - HttpResponse get(const std::string& path, - const std::map& params) override { - return executeRequest("GET", buildUrl(m_baseUrl, path, params), "", ""); - } - - HttpResponse post(const std::string& path, - const std::map& params, - const std::string& body, - const std::string& contentType) override { - return executeRequest("POST", buildUrl(m_baseUrl, path, params), contentType, body); - } - - HttpResponse postJson(const std::string& path, - const std::map& params, - const std::string& jsonBody) override { - return executeRequest("POST", buildUrl(m_baseUrl, path, params), "application/json", jsonBody); - } - -private: - std::string m_baseUrl; - int m_timeout; - std::map m_headers; - - HttpResponse executeRequest(const std::string& method, - const std::string& url, - const std::string& contentType, - const std::string& body) { - HttpResponse response; - CURL* curl = nullptr; - CURLcode res; - struct curl_slist* headers = nullptr; - - try { - // 初始化curl - curl = curl_easy_init(); - if (!curl) { - throw HttpException("Failed to initialize libcurl"); - } - - // 设置URL - res = curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); - if (res != CURLE_OK) { - throw HttpException("Failed to set URL: " + std::string(curl_easy_strerror(res))); - } - - // 设置超时 - res = curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, m_timeout); - if (res != CURLE_OK) { - throw HttpException("Failed to set timeout: " + std::string(curl_easy_strerror(res))); - } - - // 设置响应数据回调 - std::string responseBody; - res = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); - if (res != CURLE_OK) { - throw HttpException("Failed to set write callback: " + std::string(curl_easy_strerror(res))); - } - - res = curl_easy_setopt(curl, CURLOPT_WRITEDATA, &responseBody); - if (res != CURLE_OK) { - throw HttpException("Failed to set write data: " + std::string(curl_easy_strerror(res))); - } - - // 设置响应头回调 - std::string responseHeaders; - res = curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, WriteCallback); - if (res != CURLE_OK) { - throw HttpException("Failed to set header callback: " + std::string(curl_easy_strerror(res))); - } - - res = curl_easy_setopt(curl, CURLOPT_HEADERDATA, &responseHeaders); - if (res != CURLE_OK) { - throw HttpException("Failed to set header data: " + std::string(curl_easy_strerror(res))); - } - - // 设置HTTP方法 - if (method == "GET") { - // GET是默认方法,不需要额外设置 - } else if (method == "POST") { - // 设置为POST方法 - res = curl_easy_setopt(curl, CURLOPT_POST, 1L); - if (res != CURLE_OK) { - throw HttpException("Failed to set POST method: " + std::string(curl_easy_strerror(res))); - } - - // 设置POST数据 - if (!body.empty()) { - res = curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body.c_str()); - if (res != CURLE_OK) { - throw HttpException("Failed to set POST fields: " + std::string(curl_easy_strerror(res))); - } - } - } else { - // 对于其他HTTP方法,使用自定义请求 - res = curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, method.c_str()); - if (res != CURLE_OK) { - throw HttpException("Failed to set custom request method: " + std::string(curl_easy_strerror(res))); - } - - // 如果是PUT或PATCH等需要请求体的方法 - if ((method == "PUT" || method == "PATCH") && !body.empty()) { - res = curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body.c_str()); - if (res != CURLE_OK) { - throw HttpException("Failed to set request body: " + std::string(curl_easy_strerror(res))); - } - } - } - - // 添加请求头 - if (!contentType.empty()) { - std::string contentTypeHeader = "Content-Type: " + contentType; - headers = curl_slist_append(headers, contentTypeHeader.c_str()); - } - - // 添加用户自定义头 - for (const auto& header : m_headers) { - std::string headerStr = header.first + ": " + header.second; - headers = curl_slist_append(headers, headerStr.c_str()); - } - - // 设置请求头 - if (headers) { - res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); - if (res != CURLE_OK) { - curl_slist_free_all(headers); - throw HttpException("Failed to set HTTP headers: " + std::string(curl_easy_strerror(res))); - } - } - - // 执行请求 - res = curl_easy_perform(curl); - if (res != CURLE_OK) { - throw HttpException("Failed to perform HTTP request: " + std::string(curl_easy_strerror(res))); - } - - // 获取HTTP响应码 - long httpCode = 0; - res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode); - if (res != CURLE_OK) { - throw HttpException("Failed to get HTTP response code: " + std::string(curl_easy_strerror(res))); - } - - response.statusCode = static_cast(httpCode); - response.body = responseBody; - - // 解析响应头 - std::istringstream headerStream(responseHeaders); - std::string line; - - while (std::getline(headerStream, line) && line.length() > 1) { - if (line.back() == '\r') { - line.pop_back(); - } - - size_t colonPos = line.find(':'); - if (colonPos != std::string::npos) { - std::string key = line.substr(0, colonPos); - std::string value = line.substr(colonPos + 1); - - // 去除前后空格 - size_t start = value.find_first_not_of(" \t"); - size_t end = value.find_last_not_of(" \t"); - - if (start != std::string::npos && end != std::string::npos) { - value = value.substr(start, end - start + 1); - } - - response.headers[key] = value; - } - } - } catch (const std::exception& e) { - // 清理资源 - if (headers) { - curl_slist_free_all(headers); - } - - if (curl) { - curl_easy_cleanup(curl); - } - - throw HttpException(std::string("Libcurl request failed: ") + e.what()); - } - - // 清理资源 - if (headers) { - curl_slist_free_all(headers); - } - - if (curl) { - curl_easy_cleanup(curl); - } - - return response; - } -}; -#endif - -// HttpClient类实现 -HttpClient::HttpClient() { -#ifdef USE_LIBCURL - m_impl = std::make_unique(); -#else - m_impl = std::make_unique(); -#endif -} - -void HttpClient::setBaseUrl(const std::string& baseUrl) { - m_impl->setBaseUrl(baseUrl); -} - -void HttpClient::setTimeout(int timeout) { - m_impl->setTimeout(timeout); -} - -void HttpClient::addHeader(const std::string& key, const std::string& value) { - m_impl->addHeader(key, value); -} - -void HttpClient::clearHeaders() { - m_impl->clearHeaders(); -} - -HttpResponse HttpClient::get(const std::string& path, - const std::map& params) { - return m_impl->get(path, params); -} - -HttpResponse HttpClient::post(const std::string& path, - const std::map& params, - const std::string& body, - const std::string& contentType) { - return m_impl->post(path, params, body, contentType); -} - -HttpResponse HttpClient::postJson(const std::string& path, - const std::map& params, - const std::string& jsonBody) { - return m_impl->postJson(path, params, jsonBody); -} -} // namespace - - - diff --git a/src/main.cpp b/src/main.cpp index 61363de8..5a653032 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,19 +7,17 @@ #include #include #include -#include "device_manager/device_manager.h" -#include "monitor/monitor_manager.h" -#include "service/grpc_camera_service.h" -#include "service/grpc_system_service.h" -#include "service/grpc_speaker_service.h" -#include "service/grpc_microphone_service.h" -#include "service/grpc_dexhand_service.h" -#include "utils/base/logger.h" -#include "service/grpc_head_service.h" -#include "service/grpc_humanoid_robot_service.h" -#include "service/grpc_hlc_service.h" - -#include "http/httpclient.h" +#include "device_manager/include/device_manager.h" +#include "monitor_manager/include/monitor_manager.h" +#include "service/include/grpc_camera_service.h" +#include "service/include/grpc_system_service.h" +#include "service/include/grpc_speaker_service.h" +#include "service/include/grpc_microphone_service.h" +#include "service/include/grpc_dexhand_service.h" +#include "utils/base/include/logger.h" +#include "service/include/grpc_head_service.h" +#include "service/include/grpc_humanoid_robot_service.h" +#include "service/include/grpc_hlc_service.h" #include "json/json.h" #include void runServer(const XmlNode &cfg){ @@ -75,130 +73,6 @@ void runServer(const XmlNode &cfg){ } } -int test_httpclient() { - try { - std::cout << "HTTP Client Example" << std::endl; - std::cout << "===================" << std::endl; - - // 创建HTTP客户端 - cmvr::HttpClient client; - - // 设置基础URL - 使用Reqres.in替代JSONPlaceholder - client.setBaseUrl("https://reqres.in/api"); - - // 设置超时时间为15秒(增加超时时间以应对网络波动) - client.setTimeout(15000); - - // 示例1: GET请求 - 获取用户列表 - std::cout << "\n=== Example 1: GET Request (List Users) ===" << std::endl; - cmvr::HttpResponse response = client.get("/users?page=1"); - - std::cout << "Status: " << response.statusCode << " " << response.statusText << std::endl; - std::cout << "Content-Type: " << response.headers["Content-Type"] << std::endl; - std::cout << "Response Body: " << std::endl << response.body << std::endl; - - // 示例2: POST JSON请求 - 创建用户 - std::cout << "\n=== Example 2: POST JSON Request (Create User) ===" << std::endl; - - // 使用JsonCpp创建JSON数据 - Json::Value postData; - postData["name"] = "John Doe"; - postData["job"] = "Software Engineer"; - - // 将JSON转换为字符串 - Json::StreamWriterBuilder writer; - std::string jsonString = Json::writeString(writer, postData); - - response = client.postJson("/users", {}, jsonString); - - std::cout << "Status: " << response.statusCode << " " << response.statusText << std::endl; - std::cout << "Content-Type: " << response.headers["Content-Type"] << std::endl; - std::cout << "Response Body: " << std::endl << response.body << std::endl; - - // 示例3: 解析JSON响应 - 获取单个用户 - std::cout << "\n=== Example 3: Parsing JSON Response (Single User) ===" << std::endl; - response = client.get("/users/2"); - - if (response.statusCode == 200) { - // 使用JsonCpp解析JSON字符串 - Json::Value user; - Json::CharReaderBuilder reader; - std::string errors; - - std::istringstream stream(response.body); - bool parsingSuccessful = Json::parseFromStream(reader, stream, &user, &errors); - - if (parsingSuccessful) { - Json::Value data = user["data"]; - std::cout << "User ID: " << data["id"].asInt() << std::endl; - std::cout << "Email: " << data["email"].asString() << std::endl; - std::cout << "First Name: " << data["first_name"].asString() << std::endl; - std::cout << "Last Name: " << data["last_name"].asString() << std::endl; - } else { - std::cerr << "Failed to parse JSON: " << errors << std::endl; - } - } - - // 示例4: PUT请求 - 更新用户 - std::cout << "\n=== Example 4: PUT Request (Update User) ===" << std::endl; - - Json::Value updateData; - updateData["name"] = "Jane Doe"; - updateData["job"] = "Senior Software Engineer"; - - std::string updateJson = Json::writeString(writer, updateData); - - response = client.postJson("/users/2", {}, updateJson); // Reqres.in使用POST处理PUT请求 - - std::cout << "Status: " << response.statusCode << " " << response.statusText << std::endl; - std::cout << "Content-Type: " << response.headers["Content-Type"] << std::endl; - std::cout << "Response Body: " << std::endl << response.body << std::endl; - - // 示例5: 测试HttpBin.org - 获取请求头信息 - std::cout << "\n=== Example 5: HttpBin.org (Request Headers) ===" << std::endl; - - // 切换到HttpBin.org - client.setBaseUrl("https://httpbin.org"); - - // 添加自定义请求头 - client.clearHeaders(); - client.addHeader("X-Test-Header", "Hello from HttpClient"); - client.addHeader("Accept", "application/json"); - - response = client.get("/headers"); - - std::cout << "Status: " << response.statusCode << " " << response.statusText << std::endl; - std::cout << "Content-Type: " << response.headers["Content-Type"] << std::endl; - std::cout << "Response Body: " << std::endl << response.body << std::endl; - - // 示例6: 测试超时与错误处理 - std::cout << "\n=== Example 6: Timeout & Error Handling ===" << std::endl; - - // 设置较短的超时时间 - client.setTimeout(2000); // 2秒超时 - - try { - // 请求一个会延迟响应的端点 - response = client.get("/delay/5"); // 服务器会延迟5秒响应 - - std::cout << "Status: " << response.statusCode << " " << response.statusText << std::endl; - } catch (const cmvr::HttpException& e) { - std::cout << "Error (Expected Timeout): " << e.what() << std::endl; - } - - // 恢复正常超时 - client.setTimeout(15000); - - } catch (const cmvr::HttpException& e) { - std::cerr << "HTTP Error: " << e.what() << std::endl; - return 1; - } catch (const std::exception& e) { - std::cerr << "Error: " << e.what() << std::endl; - return 1; - } - return 0; -} - int main(int argc, char* argv[]) { std::string config_path; if(argc == 1) { diff --git a/src/monitor/CMakeLists.txt b/src/monitor/CMakeLists.txt index c45b83ec..47820768 100644 --- a/src/monitor/CMakeLists.txt +++ b/src/monitor/CMakeLists.txt @@ -1,16 +1,2 @@ # 首先添加子目录,确保disk_monitor目标被定义 -add_subdirectory(diskmonitor) - -# 然后定义monitor静态库并链接依赖 -add_library(monitor STATIC - monitor_factory.cpp - monitor_manager.cpp -) - -target_include_directories(monitor PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) - -target_link_libraries(monitor PRIVATE - cmvr_es::monitor::disk_monitor -) - -add_library(cmvr_es::monitor ALIAS monitor) \ No newline at end of file +add_subdirectory(diskmonitor) \ No newline at end of file diff --git a/include/monitor/abstract_monitor.h b/src/monitor/abstract_monitor.h similarity index 95% rename from include/monitor/abstract_monitor.h rename to src/monitor/abstract_monitor.h index 3f464cb4..6b707e9c 100644 --- a/include/monitor/abstract_monitor.h +++ b/src/monitor/abstract_monitor.h @@ -8,7 +8,7 @@ #include #include #include "rapidxml/xml_parser.h" -#include "../utils/base/timer.h" +#include "../utils/base/include/timer.h" namespace cmvr::monitor{ class AbstractMonitor { diff --git a/src/monitor/diskmonitor/CMakeLists.txt b/src/monitor/diskmonitor/CMakeLists.txt index 24462f93..d15a8fba 100644 --- a/src/monitor/diskmonitor/CMakeLists.txt +++ b/src/monitor/diskmonitor/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(disk_monitor SHARED disk_monitor.cpp) +add_library(disk_monitor SHARED src/disk_monitor.cpp) target_include_directories(disk_monitor PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/src/monitor/diskmonitor/disk_monitor.h b/src/monitor/diskmonitor/include/disk_monitor.h similarity index 94% rename from src/monitor/diskmonitor/disk_monitor.h rename to src/monitor/diskmonitor/include/disk_monitor.h index 337a4a48..89664362 100644 --- a/src/monitor/diskmonitor/disk_monitor.h +++ b/src/monitor/diskmonitor/include/disk_monitor.h @@ -7,7 +7,7 @@ #include -#include "monitor/abstract_monitor.h" +#include "../../abstract_monitor.h" namespace cmvr::monitor { diff --git a/src/monitor/diskmonitor/disk_monitor.cpp b/src/monitor/diskmonitor/src/disk_monitor.cpp similarity index 99% rename from src/monitor/diskmonitor/disk_monitor.cpp rename to src/monitor/diskmonitor/src/disk_monitor.cpp index dffd2164..20630615 100644 --- a/src/monitor/diskmonitor/disk_monitor.cpp +++ b/src/monitor/diskmonitor/src/disk_monitor.cpp @@ -2,7 +2,7 @@ // Created by linbo on 2025/6/18. // -#include "disk_monitor.h" +#include "../include/disk_monitor.h" #include #include #include diff --git a/src/monitor_manager/CMakeLists.txt b/src/monitor_manager/CMakeLists.txt new file mode 100644 index 00000000..822cdafc --- /dev/null +++ b/src/monitor_manager/CMakeLists.txt @@ -0,0 +1,13 @@ +# 然后定义monitor静态库并链接依赖 +add_library(monitor_manager STATIC + src/monitor_factory.cpp + src/monitor_manager.cpp +) + +target_include_directories(monitor_manager PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) + +target_link_libraries(monitor_manager PRIVATE + cmvr_es::monitor::disk_monitor +) + +add_library(cmvr_es::monitor_manager ALIAS monitor_manager) \ No newline at end of file diff --git a/include/monitor/monitor_factory.h b/src/monitor_manager/include/monitor_factory.h similarity index 90% rename from include/monitor/monitor_factory.h rename to src/monitor_manager/include/monitor_factory.h index 5ae4cffe..a0dbc900 100644 --- a/include/monitor/monitor_factory.h +++ b/src/monitor_manager/include/monitor_factory.h @@ -6,7 +6,7 @@ #define MONITOR_FACTORY_H -#include "monitor/abstract_monitor.h" +#include "../../monitor/abstract_monitor.h" namespace cmvr::monitor { diff --git a/include/monitor/monitor_manager.h b/src/monitor_manager/include/monitor_manager.h similarity index 96% rename from include/monitor/monitor_manager.h rename to src/monitor_manager/include/monitor_manager.h index e3963c78..8c53a401 100644 --- a/include/monitor/monitor_manager.h +++ b/src/monitor_manager/include/monitor_manager.h @@ -7,7 +7,7 @@ #include #include "rapidxml/xml_parser.h" -#include "monitor/monitor_factory.h" +#include "monitor_factory.h" namespace cmvr::monitor { diff --git a/src/monitor/monitor_factory.cpp b/src/monitor_manager/src/monitor_factory.cpp similarity index 85% rename from src/monitor/monitor_factory.cpp rename to src/monitor_manager/src/monitor_factory.cpp index ff142e0b..821373e2 100644 --- a/src/monitor/monitor_factory.cpp +++ b/src/monitor_manager/src/monitor_factory.cpp @@ -2,9 +2,9 @@ // Created by xtkuang on 2025/6/6. // -#include "monitor/monitor_factory.h" +#include "../include/monitor_factory.h" -#include "diskmonitor/disk_monitor.h" +#include "../../monitor/diskmonitor/include/disk_monitor.h" using namespace std; using namespace cmvr::monitor; diff --git a/src/monitor/monitor_manager.cpp b/src/monitor_manager/src/monitor_manager.cpp similarity index 93% rename from src/monitor/monitor_manager.cpp rename to src/monitor_manager/src/monitor_manager.cpp index 59f5ca61..2dd9e2cf 100644 --- a/src/monitor/monitor_manager.cpp +++ b/src/monitor_manager/src/monitor_manager.cpp @@ -2,9 +2,9 @@ // Created by xtkuang on 2025/6/9. // -#include "monitor/monitor_manager.h" +#include "../include/monitor_manager.h" -#include "disk_monitor.h" +#include "../../monitor/diskmonitor/include/disk_monitor.h" using namespace std; using namespace cmvr::monitor; diff --git a/src/service/CMakeLists.txt b/src/service/CMakeLists.txt index c7abb985..779ae10f 100644 --- a/src/service/CMakeLists.txt +++ b/src/service/CMakeLists.txt @@ -1,12 +1,12 @@ add_library(service - grpc_camera_service.cpp - grpc_system_service.cpp - grpc_speaker_service.cpp - grpc_microphone_service.cpp - grpc_head_service.cpp - grpc_dexhand_service.cpp - grpc_humanoid_robot_service.cpp - grpc_hlc_service.cpp + src/grpc_camera_service.cpp + src/grpc_system_service.cpp + src/grpc_speaker_service.cpp + src/grpc_microphone_service.cpp + src/grpc_head_service.cpp + src/grpc_dexhand_service.cpp + src/grpc_humanoid_robot_service.cpp + src/grpc_hlc_service.cpp ) target_include_directories(service PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) @@ -41,7 +41,7 @@ link_directories( add_executable(grpc_humanoid_robot_client_test - ${CMAKE_CURRENT_SOURCE_DIR}/grpc_humanoid_robot_client_test.cpp + src/grpc_humanoid_robot_client_test.cpp ) @@ -65,7 +65,7 @@ target_link_libraries(grpc_humanoid_robot_client_test add_executable(grpc_hlc_client_test - ${CMAKE_CURRENT_SOURCE_DIR}/grpc_hlc_client_test.cpp + src/grpc_hlc_client_test.cpp ) diff --git a/include/service/grpc_camera_service.h b/src/service/include/grpc_camera_service.h similarity index 96% rename from include/service/grpc_camera_service.h rename to src/service/include/grpc_camera_service.h index 9fd29510..b0ab40e3 100644 --- a/include/service/grpc_camera_service.h +++ b/src/service/include/grpc_camera_service.h @@ -6,8 +6,8 @@ #define GRPC_CAMERA_SERVICE_H #include "cmvr/api/camera_service.grpc.pb.h" -#include "../utils/base/grpc_utils.h" -#include "device_manager/device_manager.h" +#include "../../utils/base/include/grpc_utils.h" +#include "../../device_manager/include/device_manager.h" namespace cmvr::service { diff --git a/include/service/grpc_dexhand_service.h b/src/service/include/grpc_dexhand_service.h similarity index 94% rename from include/service/grpc_dexhand_service.h rename to src/service/include/grpc_dexhand_service.h index 87523de4..d6e6e967 100644 --- a/include/service/grpc_dexhand_service.h +++ b/src/service/include/grpc_dexhand_service.h @@ -6,8 +6,8 @@ #define GRPC_DEXHAND_SERVICE_H #include "cmvr/api/dexhand_service.grpc.pb.h" -#include "../utils/base/grpc_utils.h" -#include "device_manager/device_manager.h" +#include "../../utils/base/include/grpc_utils.h" +#include "../../device_manager/include/device_manager.h" namespace cmvr::service { class gRPCDexHandServiceImpl final: public api::DexHandService::Service { public: diff --git a/include/service/grpc_head_service.h b/src/service/include/grpc_head_service.h similarity index 97% rename from include/service/grpc_head_service.h rename to src/service/include/grpc_head_service.h index 7933be8f..4b6552e9 100644 --- a/include/service/grpc_head_service.h +++ b/src/service/include/grpc_head_service.h @@ -2,7 +2,7 @@ #define BIO_HEAD_SERVICE_H #include "cmvr/api/biohead_service.grpc.pb.h" -#include "device_manager/device_manager.h" +#include "../../device_manager/include/device_manager.h" namespace cmvr::service { diff --git a/include/service/grpc_hlc_service.h b/src/service/include/grpc_hlc_service.h similarity index 90% rename from include/service/grpc_hlc_service.h rename to src/service/include/grpc_hlc_service.h index ecdd5c11..49a9810f 100644 --- a/include/service/grpc_hlc_service.h +++ b/src/service/include/grpc_hlc_service.h @@ -3,7 +3,7 @@ // #pragma once -#include "device_manager/device_manager.h" +#include "../../device_manager/include/device_manager.h" #include "cmvr/api/hlc_service.grpc.pb.h" namespace cmvr { diff --git a/include/service/grpc_humanoid_robot_service.h b/src/service/include/grpc_humanoid_robot_service.h similarity index 96% rename from include/service/grpc_humanoid_robot_service.h rename to src/service/include/grpc_humanoid_robot_service.h index 04b4ee3a..40942e57 100644 --- a/include/service/grpc_humanoid_robot_service.h +++ b/src/service/include/grpc_humanoid_robot_service.h @@ -4,7 +4,7 @@ #pragma once -#include "device_manager/device_manager.h" +#include "../../device_manager/include/device_manager.h" #include "cmvr/api/humanoid_robot_service.grpc.pb.h" namespace cmvr { diff --git a/include/service/grpc_microphone_service.h b/src/service/include/grpc_microphone_service.h similarity index 94% rename from include/service/grpc_microphone_service.h rename to src/service/include/grpc_microphone_service.h index 81c6334a..92e4b369 100644 --- a/include/service/grpc_microphone_service.h +++ b/src/service/include/grpc_microphone_service.h @@ -6,8 +6,8 @@ #ifndef GRPC_MICROPHONE_SERVICE_H #define GRPC_MICROPHONE_SERVICE_H #include "cmvr/api/microphone_service.grpc.pb.h" -#include "device_manager/device_manager.h" -#include "../utils/base/grpc_utils.h" +#include "../../device_manager/include/device_manager.h" +#include "../../utils/base/include/grpc_utils.h" namespace cmvr::service { diff --git a/include/service/grpc_speaker_service.h b/src/service/include/grpc_speaker_service.h similarity index 93% rename from include/service/grpc_speaker_service.h rename to src/service/include/grpc_speaker_service.h index 2250bc43..8c050650 100644 --- a/include/service/grpc_speaker_service.h +++ b/src/service/include/grpc_speaker_service.h @@ -6,8 +6,8 @@ #define GRPC_SPEAKER_SERVICE_H #include "cmvr/api/speaker_service.grpc.pb.h" -#include "device_manager/device_manager.h" -#include "../utils/base/grpc_utils.h" +#include "../../device_manager/include/device_manager.h" +#include "../../utils/base/include/grpc_utils.h" namespace cmvr::service { class gRPCSpeakerServiceImpl: public api::SpeakerService::Service { diff --git a/include/service/grpc_system_service.h b/src/service/include/grpc_system_service.h similarity index 90% rename from include/service/grpc_system_service.h rename to src/service/include/grpc_system_service.h index b612632b..e8c23d4d 100644 --- a/include/service/grpc_system_service.h +++ b/src/service/include/grpc_system_service.h @@ -6,8 +6,8 @@ #define GRPC_SYSTEM_SERVICE_H #include "cmvr/api/system_service.grpc.pb.h" -#include "../utils/base/grpc_utils.h" -#include "device_manager/device_manager.h" +#include "../../utils/base/include/grpc_utils.h" +#include "../../device_manager/include/device_manager.h" namespace cmvr::service { diff --git a/src/service/grpc_camera_service.cpp b/src/service/src/grpc_camera_service.cpp similarity index 99% rename from src/service/grpc_camera_service.cpp rename to src/service/src/grpc_camera_service.cpp index 76d49a88..2405d4af 100644 --- a/src/service/grpc_camera_service.cpp +++ b/src/service/src/grpc_camera_service.cpp @@ -2,7 +2,7 @@ // Created by xtkuang on 2025/6/1. // -#include "service/grpc_camera_service.h" +#include "../include/grpc_camera_service.h" using namespace std; using namespace cmvr::service; diff --git a/src/service/grpc_dexhand_service.cpp b/src/service/src/grpc_dexhand_service.cpp similarity index 99% rename from src/service/grpc_dexhand_service.cpp rename to src/service/src/grpc_dexhand_service.cpp index aa752c45..699831ee 100644 --- a/src/service/grpc_dexhand_service.cpp +++ b/src/service/src/grpc_dexhand_service.cpp @@ -2,7 +2,7 @@ // Created by linbo on 2025/7/3. // -#include "service/grpc_dexhand_service.h" +#include "../include/grpc_dexhand_service.h" using namespace std; using namespace cmvr::service; using namespace cmvr::device; diff --git a/src/service/grpc_head_service.cpp b/src/service/src/grpc_head_service.cpp similarity index 98% rename from src/service/grpc_head_service.cpp rename to src/service/src/grpc_head_service.cpp index d6d3aa73..42075e95 100644 --- a/src/service/grpc_head_service.cpp +++ b/src/service/src/grpc_head_service.cpp @@ -1,9 +1,9 @@ -#include "service/grpc_head_service.h" +#include "../include/grpc_head_service.h" #include "cmvr/api/biohead_service.grpc.pb.h" -#include "device_manager/device_manager.h" -#include "utils/base/grpc_utils.h" -#include "biohead/biohead_esp32/biohead_esp32.h" +#include "../../device_manager/include/device_manager.h" +#include "../../utils/base/include/grpc_utils.h" +#include "../../devices/biohead/biohead_esp32/include/biohead_esp32.h" #include #include #include diff --git a/src/service/grpc_hlc_client_test.cpp b/src/service/src/grpc_hlc_client_test.cpp similarity index 97% rename from src/service/grpc_hlc_client_test.cpp rename to src/service/src/grpc_hlc_client_test.cpp index 4fb32bd6..25df06ec 100644 --- a/src/service/grpc_hlc_client_test.cpp +++ b/src/service/src/grpc_hlc_client_test.cpp @@ -4,7 +4,7 @@ #include "gtest/gtest.h" #include #include -#include "service/grpc_hlc_service.h" +#include "../include/grpc_hlc_service.h" #include "google/protobuf/timestamp.pb.h" #include #include diff --git a/src/service/grpc_hlc_service.cpp b/src/service/src/grpc_hlc_service.cpp similarity index 88% rename from src/service/grpc_hlc_service.cpp rename to src/service/src/grpc_hlc_service.cpp index 43c9067a..a14b9be7 100644 --- a/src/service/grpc_hlc_service.cpp +++ b/src/service/src/grpc_hlc_service.cpp @@ -3,10 +3,10 @@ // -#include "service/grpc_hlc_service.h" +#include "../include/grpc_hlc_service.h" #include -#include "robot/humanoid_robot/humanoid_robot.h" -#include "controller/touch_controller.h" +#include "../../devices/robot/humanoid_robot/include/humanoid_robot.h" +#include "../../controller/include/touch_controller.h" using namespace cmvr::service; diff --git a/src/service/grpc_humanoid_robot_client_test.cpp b/src/service/src/grpc_humanoid_robot_client_test.cpp similarity index 98% rename from src/service/grpc_humanoid_robot_client_test.cpp rename to src/service/src/grpc_humanoid_robot_client_test.cpp index ba6944f0..9c78c749 100644 --- a/src/service/grpc_humanoid_robot_client_test.cpp +++ b/src/service/src/grpc_humanoid_robot_client_test.cpp @@ -5,7 +5,7 @@ #include "gtest/gtest.h" #include #include -#include "service/grpc_humanoid_robot_service.h" +#include "../include/grpc_humanoid_robot_service.h" #include "google/protobuf/timestamp.pb.h" #include #include diff --git a/src/service/grpc_humanoid_robot_service.cpp b/src/service/src/grpc_humanoid_robot_service.cpp similarity index 98% rename from src/service/grpc_humanoid_robot_service.cpp rename to src/service/src/grpc_humanoid_robot_service.cpp index 4326c3f2..9a0283a4 100644 --- a/src/service/grpc_humanoid_robot_service.cpp +++ b/src/service/src/grpc_humanoid_robot_service.cpp @@ -3,9 +3,9 @@ // -#include "service/grpc_humanoid_robot_service.h" +#include "../include/grpc_humanoid_robot_service.h" #include -#include "robot/humanoid_robot/humanoid_robot.h" +#include "../../devices/robot/humanoid_robot/include/humanoid_robot.h" #include "cmvr/msgs/geometry.pb.h" using namespace cmvr::service; diff --git a/src/service/grpc_microphone_service.cpp b/src/service/src/grpc_microphone_service.cpp similarity index 99% rename from src/service/grpc_microphone_service.cpp rename to src/service/src/grpc_microphone_service.cpp index 87895473..fdb2e275 100644 --- a/src/service/grpc_microphone_service.cpp +++ b/src/service/src/grpc_microphone_service.cpp @@ -3,7 +3,7 @@ // Created by xtkuang on 2025/6/13. // -#include "service/grpc_microphone_service.h" +#include "../include/grpc_microphone_service.h" using namespace std; using namespace cmvr::device; using namespace cmvr::service; diff --git a/src/service/grpc_speaker_service.cpp b/src/service/src/grpc_speaker_service.cpp similarity index 99% rename from src/service/grpc_speaker_service.cpp rename to src/service/src/grpc_speaker_service.cpp index 41aabc65..57a1ba28 100644 --- a/src/service/grpc_speaker_service.cpp +++ b/src/service/src/grpc_speaker_service.cpp @@ -2,7 +2,7 @@ // Created by xtkuang on 2025/6/10. // -#include "service/grpc_speaker_service.h" +#include "../include/grpc_speaker_service.h" using namespace std; using namespace cmvr::device; diff --git a/src/service/grpc_system_service.cpp b/src/service/src/grpc_system_service.cpp similarity index 99% rename from src/service/grpc_system_service.cpp rename to src/service/src/grpc_system_service.cpp index 5c83dfa8..9e9a0ad6 100644 --- a/src/service/grpc_system_service.cpp +++ b/src/service/src/grpc_system_service.cpp @@ -2,7 +2,7 @@ // Created by xtkuang on 2025/6/6. // -#include "service/grpc_system_service.h" +#include "../include/grpc_system_service.h" using namespace cmvr::device; using namespace cmvr::device; diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt index 8a404bef..e874a02e 100644 --- a/src/utils/CMakeLists.txt +++ b/src/utils/CMakeLists.txt @@ -8,18 +8,18 @@ pkg_check_modules(TINYXML2 REQUIRED tinyxml2) include_directories(${TINYXML2_INCLUDE_DIRS}) add_library(utils STATIC - base/thread_pool.cpp - base/timer.cpp - base/abstract_interpolation.cpp - dynamics/inertial.cpp - dynamics/joint.cpp - dynamics/link.cpp - dynamics/robot.cpp - math/qp_solver.cpp - math/se2.cpp - math/se3.cpp - math/so3.cpp - controller/cartesian_controller.cpp + base/src/thread_pool.cpp + base/src/timer.cpp + base/src/abstract_interpolation.cpp + dynamics/src/inertial.cpp + dynamics/src/joint.cpp + dynamics/src/link.cpp + dynamics/src/robot.cpp + math/src/qp_solver.cpp + math/src/se2.cpp + math/src/se3.cpp + math/src/so3.cpp + controller/src/cartesian_controller.cpp ) target_include_directories(utils PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/include/utils/base/abstract_interpolation.h b/src/utils/base/include/abstract_interpolation.h similarity index 98% rename from include/utils/base/abstract_interpolation.h rename to src/utils/base/include/abstract_interpolation.h index 18d1341b..ffce43cb 100644 --- a/include/utils/base/abstract_interpolation.h +++ b/src/utils/base/include/abstract_interpolation.h @@ -1,7 +1,7 @@ #ifndef INTERPOLATION_BASE_H #define INTERPOLATION_BASE_H -#include "utils/math/geometry.h" +#include "../../math/include/geometry.h" #include #include diff --git a/include/utils/base/grpc_utils.h b/src/utils/base/include/grpc_utils.h similarity index 100% rename from include/utils/base/grpc_utils.h rename to src/utils/base/include/grpc_utils.h diff --git a/include/utils/base/logger.h b/src/utils/base/include/logger.h similarity index 100% rename from include/utils/base/logger.h rename to src/utils/base/include/logger.h diff --git a/include/utils/base/os.h b/src/utils/base/include/os.h similarity index 100% rename from include/utils/base/os.h rename to src/utils/base/include/os.h diff --git a/include/utils/base/ring_buffer.h b/src/utils/base/include/ring_buffer.h similarity index 100% rename from include/utils/base/ring_buffer.h rename to src/utils/base/include/ring_buffer.h diff --git a/include/utils/base/thread_pool.h b/src/utils/base/include/thread_pool.h similarity index 100% rename from include/utils/base/thread_pool.h rename to src/utils/base/include/thread_pool.h diff --git a/include/utils/base/timer.h b/src/utils/base/include/timer.h similarity index 100% rename from include/utils/base/timer.h rename to src/utils/base/include/timer.h diff --git a/src/utils/base/abstract_interpolation.cpp b/src/utils/base/src/abstract_interpolation.cpp similarity index 98% rename from src/utils/base/abstract_interpolation.cpp rename to src/utils/base/src/abstract_interpolation.cpp index 1ab6ed29..33ccf658 100644 --- a/src/utils/base/abstract_interpolation.cpp +++ b/src/utils/base/src/abstract_interpolation.cpp @@ -1,4 +1,4 @@ -#include "utils/base/abstract_interpolation.h" +#include "../include/abstract_interpolation.h" #include #include diff --git a/src/utils/base/thread_pool.cpp b/src/utils/base/src/thread_pool.cpp similarity index 99% rename from src/utils/base/thread_pool.cpp rename to src/utils/base/src/thread_pool.cpp index d8241439..34ede933 100644 --- a/src/utils/base/thread_pool.cpp +++ b/src/utils/base/src/thread_pool.cpp @@ -2,7 +2,7 @@ // Created by xtkuang on 2025/5/13. // -#include "utils/base/thread_pool.h" +#include "../include/thread_pool.h" #include void InterruptFlag::request_stop() { diff --git a/src/utils/base/timer.cpp b/src/utils/base/src/timer.cpp similarity index 98% rename from src/utils/base/timer.cpp rename to src/utils/base/src/timer.cpp index 56de4a3f..99892952 100644 --- a/src/utils/base/timer.cpp +++ b/src/utils/base/src/timer.cpp @@ -2,7 +2,7 @@ // Created by xtkuang on 2025/5/14. // -#include "utils/base/timer.h" +#include "utils/base/include/timer.h" FDTimer::FDTimer() : fd_(-1), running_(false) {} diff --git a/include/utils/controller/cartesian_controller.h b/src/utils/controller/include/cartesian_controller.h similarity index 97% rename from include/utils/controller/cartesian_controller.h rename to src/utils/controller/include/cartesian_controller.h index 72fd524c..9a5eaf09 100644 --- a/include/utils/controller/cartesian_controller.h +++ b/src/utils/controller/include/cartesian_controller.h @@ -17,9 +17,9 @@ #include #include -#include "utils/math/se3.h" -#include "utils/math/qp_solver.h" -#include "utils/dynamics/robot.h" +#include "../../math/include/se3.h" +#include "../../math/include/qp_solver.h" +#include "../../dynamics/include/robot.h" namespace cmvr::ctrl{ using cmvr::math::SE3; diff --git a/src/utils/controller/cartesian_controller.cpp b/src/utils/controller/src/cartesian_controller.cpp similarity index 99% rename from src/utils/controller/cartesian_controller.cpp rename to src/utils/controller/src/cartesian_controller.cpp index b5a4a479..34d022b5 100644 --- a/src/utils/controller/cartesian_controller.cpp +++ b/src/utils/controller/src/cartesian_controller.cpp @@ -1,4 +1,4 @@ -#include "utils/controller/cartesian_controller.h" +#include "../include/cartesian_controller.h" using namespace cmvr::ctrl; diff --git a/include/utils/dynamics/inertial.h b/src/utils/dynamics/include/inertial.h similarity index 97% rename from include/utils/dynamics/inertial.h rename to src/utils/dynamics/include/inertial.h index 17a6d481..f48feb92 100644 --- a/include/utils/dynamics/inertial.h +++ b/src/utils/dynamics/include/inertial.h @@ -10,7 +10,7 @@ #include -#include "utils/math/se3.h" +#include "../../math/include/se3.h" namespace cmvr::dyn { diff --git a/include/utils/dynamics/joint.h b/src/utils/dynamics/include/joint.h similarity index 96% rename from include/utils/dynamics/joint.h rename to src/utils/dynamics/include/joint.h index bf1ebf1f..3397ec81 100644 --- a/include/utils/dynamics/joint.h +++ b/src/utils/dynamics/include/joint.h @@ -7,9 +7,9 @@ #include #include -#include "utils/math/constants.h" -#include "utils/math/liegroup.h" -#include "utils/dynamics/link.h" +#include "../../math/include/constants.h" +#include "../../math/include/liegroup.h" +#include "link.h" namespace cmvr::dyn { class Joint : public std::enable_shared_from_this { diff --git a/include/utils/dynamics/link.h b/src/utils/dynamics/include/link.h similarity index 98% rename from include/utils/dynamics/link.h rename to src/utils/dynamics/include/link.h index 47c7c3f9..edd62fef 100644 --- a/include/utils/dynamics/link.h +++ b/src/utils/dynamics/include/link.h @@ -10,8 +10,8 @@ #include #include -#include "utils/dynamics/inertial.h" -#include "utils/math/liegroup.h" +#include "inertial.h" +#include "../../math/include/liegroup.h" namespace cmvr::dyn { template diff --git a/include/utils/dynamics/robot.h b/src/utils/dynamics/include/robot.h similarity index 98% rename from include/utils/dynamics/robot.h rename to src/utils/dynamics/include/robot.h index 10d20c37..f99aa087 100644 --- a/include/utils/dynamics/robot.h +++ b/src/utils/dynamics/include/robot.h @@ -23,8 +23,8 @@ #include "joint.h" #include "link.h" #include "state.h" -#include "utils/math/liegroup.h" -#include "utils/math/qp_solver.h" +#include "../../math/include/liegroup.h" +#include "../../math/include/qp_solver.h" namespace cmvr::dyn { /********************************************************** @@ -283,6 +283,6 @@ inline std::string to_string(GeomType type) { } } -#include "robot.tpp" +#include "../src/robot.tpp" #endif //ROBOT_H diff --git a/include/utils/dynamics/state.h b/src/utils/dynamics/include/state.h similarity index 99% rename from include/utils/dynamics/state.h rename to src/utils/dynamics/include/state.h index 0ec048e5..ce1e0da0 100644 --- a/include/utils/dynamics/state.h +++ b/src/utils/dynamics/include/state.h @@ -8,7 +8,7 @@ #pragma once #include -#include "utils/math/se3.h" +#include "../../math/include/se3.h" namespace cmvr::dyn { template diff --git a/src/utils/dynamics/inertial.cpp b/src/utils/dynamics/src/inertial.cpp similarity index 98% rename from src/utils/dynamics/inertial.cpp rename to src/utils/dynamics/src/inertial.cpp index 0db4e200..3c3bf067 100644 --- a/src/utils/dynamics/inertial.cpp +++ b/src/utils/dynamics/src/inertial.cpp @@ -2,7 +2,7 @@ // Created by xtkuang on 2025/7/8. // -#include "utils/dynamics/inertial.h" +#include "../include/inertial.h" using namespace cmvr::dyn; diff --git a/src/utils/dynamics/joint.cpp b/src/utils/dynamics/src/joint.cpp similarity index 98% rename from src/utils/dynamics/joint.cpp rename to src/utils/dynamics/src/joint.cpp index aad286c2..5332bc74 100644 --- a/src/utils/dynamics/joint.cpp +++ b/src/utils/dynamics/src/joint.cpp @@ -2,8 +2,8 @@ // Created by xtkuang on 2025/7/7. // #include -#include "utils/dynamics/joint.h" -#include "utils/dynamics/robot.h" +#include "../include/joint.h" +#include "../include/robot.h" using namespace std; using namespace cmvr::math; diff --git a/src/utils/dynamics/link.cpp b/src/utils/dynamics/src/link.cpp similarity index 99% rename from src/utils/dynamics/link.cpp rename to src/utils/dynamics/src/link.cpp index b5485eea..8e40667a 100644 --- a/src/utils/dynamics/link.cpp +++ b/src/utils/dynamics/src/link.cpp @@ -2,7 +2,7 @@ // Created by xtkuang on 2025/7/8. // -#include "utils/dynamics/link.h" +#include "../include/link.h" #include using namespace std; diff --git a/src/utils/dynamics/robot.cpp b/src/utils/dynamics/src/robot.cpp similarity index 99% rename from src/utils/dynamics/robot.cpp rename to src/utils/dynamics/src/robot.cpp index eec831fb..347b2d97 100644 --- a/src/utils/dynamics/robot.cpp +++ b/src/utils/dynamics/src/robot.cpp @@ -3,7 +3,7 @@ // #include "tinyxml2.h" -#include "utils/dynamics/robot.h" +#include "../include/robot.h" #include using namespace std; diff --git a/include/utils/dynamics/robot.tpp b/src/utils/dynamics/src/robot.tpp similarity index 99% rename from include/utils/dynamics/robot.tpp rename to src/utils/dynamics/src/robot.tpp index 5b57e429..517740d0 100644 --- a/include/utils/dynamics/robot.tpp +++ b/src/utils/dynamics/src/robot.tpp @@ -1,6 +1,6 @@ #pragma once -#include "robot.h" +#include "../include/robot.h" using namespace cmvr::dyn; diff --git a/include/utils/math/constants.h b/src/utils/math/include/constants.h similarity index 100% rename from include/utils/math/constants.h rename to src/utils/math/include/constants.h diff --git a/include/utils/math/geometry.h b/src/utils/math/include/geometry.h similarity index 100% rename from include/utils/math/geometry.h rename to src/utils/math/include/geometry.h diff --git a/include/utils/math/liegroup.h b/src/utils/math/include/liegroup.h similarity index 100% rename from include/utils/math/liegroup.h rename to src/utils/math/include/liegroup.h diff --git a/include/utils/math/qp_solver.h b/src/utils/math/include/qp_solver.h similarity index 100% rename from include/utils/math/qp_solver.h rename to src/utils/math/include/qp_solver.h diff --git a/include/utils/math/se2.h b/src/utils/math/include/se2.h similarity index 95% rename from include/utils/math/se2.h rename to src/utils/math/include/se2.h index d93f1c31..dcebb318 100644 --- a/include/utils/math/se2.h +++ b/src/utils/math/include/se2.h @@ -9,7 +9,7 @@ #pragma once #include -#include "utils/math/constants.h" +#include "constants.h" namespace cmvr::math { diff --git a/include/utils/math/se3.h b/src/utils/math/include/se3.h similarity index 100% rename from include/utils/math/se3.h rename to src/utils/math/include/se3.h diff --git a/include/utils/math/so3.h b/src/utils/math/include/so3.h similarity index 100% rename from include/utils/math/so3.h rename to src/utils/math/include/so3.h diff --git a/include/utils/math/velocity_estimator.h b/src/utils/math/include/velocity_estimator.h similarity index 100% rename from include/utils/math/velocity_estimator.h rename to src/utils/math/include/velocity_estimator.h diff --git a/src/utils/math/qp_solver.cpp b/src/utils/math/src/qp_solver.cpp similarity index 99% rename from src/utils/math/qp_solver.cpp rename to src/utils/math/src/qp_solver.cpp index 99a57834..2f14abd5 100644 --- a/src/utils/math/qp_solver.cpp +++ b/src/utils/math/src/qp_solver.cpp @@ -2,7 +2,7 @@ // Created by xtkuang on 2025/7/7. // -#include "utils/math/qp_solver.h" +#include "../include/qp_solver.h" #include "OsqpEigen/OsqpEigen.h" using namespace cmvr::math; diff --git a/src/utils/math/se2.cpp b/src/utils/math/src/se2.cpp similarity index 96% rename from src/utils/math/se2.cpp rename to src/utils/math/src/se2.cpp index f2257c83..b8b535ac 100644 --- a/src/utils/math/se2.cpp +++ b/src/utils/math/src/se2.cpp @@ -2,7 +2,7 @@ // Created by xtkuang on 2025/7/7. // -#include "utils/math/se2.h" +#include "../include/se2.h" using namespace cmvr::math; diff --git a/src/utils/math/se3.cpp b/src/utils/math/src/se3.cpp similarity index 99% rename from src/utils/math/se3.cpp rename to src/utils/math/src/se3.cpp index ea17902a..6dcc7978 100644 --- a/src/utils/math/se3.cpp +++ b/src/utils/math/src/se3.cpp @@ -2,7 +2,7 @@ // Created by xtkuang on 2025/7/7. // -#include "utils/math/se3.h" +#include "../include/se3.h" using namespace cmvr::math; diff --git a/src/utils/math/so3.cpp b/src/utils/math/src/so3.cpp similarity index 99% rename from src/utils/math/so3.cpp rename to src/utils/math/src/so3.cpp index 44fbce66..ea0bdd0d 100644 --- a/src/utils/math/so3.cpp +++ b/src/utils/math/src/so3.cpp @@ -2,7 +2,7 @@ // Created by xtkuang on 2025/7/7. // -#include "utils/math/so3.h" +#include "../include/so3.h" using namespace cmvr::math; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt deleted file mode 100644 index 7ca5dbe9..00000000 --- a/test/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -#include_directories(${CMAKE_SOURCE_DIR}/include) -# -#add_executable(wbc_example wbc_example.cpp) -#target_link_libraries(wbc_example PRIVATE cmvr_es::utils) -# -#add_executable(follow_traj_example follow_traj_example.cpp) -#target_link_libraries(follow_traj_example PRIVATE cmvr_es::utils) \ No newline at end of file diff --git a/test/get_image.py b/test/get_image.py deleted file mode 100644 index d175c8cd..00000000 --- a/test/get_image.py +++ /dev/null @@ -1,58 +0,0 @@ -import os -import time -import pyrealsense2 as rs -import numpy as np -import cv2 - -TARGET_SERIAL = "243122075614" -ctx = rs.context() -devices = ctx.query_devices() -if len(devices) == 0: - raise RuntimeError("未检测到任何 RealSense 相机,请检查连接") - -selected_device = None -for dev in devices: - if dev.get_info(rs.camera_info.serial_number) == TARGET_SERIAL: - selected_device = dev - break -if selected_device is None: - raise RuntimeError(f"未找到序列号为 {TARGET_SERIAL} 的 RealSense 相机") - -pipeline = rs.pipeline() -config = rs.config() -config.enable_device(TARGET_SERIAL) -config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30) -config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30) -pipeline.start(config) - -align = rs.align(rs.stream.color) - -# ============================= -# 3. 数据采集流程 -# ============================= - -# 捕获对齐后的彩色图像 -for i in range(10): - try: - frames = pipeline.wait_for_frames(timeout_ms=5000) - if frames: - break - except RuntimeError: - print("⚠️ 读取帧超时,重试中...") - time.sleep(1) -frames = pipeline.wait_for_frames() -aligned_frames = align.process(frames) -color_frame = aligned_frames.get_color_frame() - -if not color_frame: - print("未获取彩色图像,跳过") - exit(-1) - -color_image = np.asanyarray(color_frame.get_data()) -img_path = f"color_image.png" -cv2.imwrite(img_path, color_image) -print(f"保存图像 {img_path}") - -# 停止RealSense -pipeline.stop() -print("\n=== 数据采集完成 ===") diff --git a/test/main.cpp b/test/main.cpp deleted file mode 100644 index 33d1f6ea..00000000 --- a/test/main.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include -#include "camera_service.h" -#include "device_manager/device_factory.h" -#include - -// 定义命令行参数 -DEFINE_string(address, "0.0.0.0:50051", "服务监听地址"); -DEFINE_string(config, "config/camera_config.yaml", "相机配置文件路径"); -DEFINE_int32(device_index, 0, "相机设备索引"); - -int main(int argc, char** argv) { - // 初始化glog - google::InitGoogleLogging(argv[0]); - FLAGS_logtostderr = true; - - // 解析命令行参数 - gflags::ParseCommandLineFlags(&argc, &argv, true); - - try { - // 加载相机配置 - if (!cv::utils::fs::exists(FLAGS_config)) { - LOG(ERROR) << "Config file not found: " << FLAGS_config; - return 1; - } - - XmlNode config; - config.load(FLAGS_config); - - // 创建相机实例 - auto camera = std::make_shared(config); - if (!camera) { - LOG(ERROR) << "Failed to create camera instance"; - return 1; - } - - // 创建相机服务 - cmvr::device::CameraService service(camera); - - // 启动服务 - LOG(INFO) << "Starting camera service on " << FLAGS_address; - service.Start(FLAGS_address); - - // 等待终止信号 - std::string input; - std::cout << "Press 'q' to quit" << std::endl; - while (std::getline(std::cin, input)) { - if (input == "q") { - break; - } - } - - // 停止服务 - service.Stop(); - LOG(INFO) << "Camera service stopped"; - - } catch (const std::exception& e) { - LOG(ERROR) << "Error: " << e.what(); - return 1; - } - - return 0; -} \ No newline at end of file diff --git a/test/test_i2c_pca9528.py b/test/test_i2c_pca9528.py deleted file mode 100644 index 7dff41ee..00000000 --- a/test/test_i2c_pca9528.py +++ /dev/null @@ -1,25 +0,0 @@ -import board -import busio - -# 定义所有可能的总线编号 -possible_buses = [0, 1, 2, 3, 4, 5] - -# 扫描所有总线 -for bus_number in possible_buses: - try: - # 初始化I2C总线 - i2c = busio.I2C(f"/dev/i2c-{bus_number}") - print(f"正在扫描总线 /dev/i2c-{bus_number}...") - - # 尝试锁定并扫描设备地址 - if i2c.try_lock(): - addresses = i2c.scan() - if addresses: - print(f"在总线 /dev/i2c-{bus_number} 上找到以下设备地址:") - for address in addresses: - print(f" - {hex(address)}") - else: - print(f"未在总线 /dev/i2c-{bus_number} 上找到任何设备。") - i2c.unlock() - except Exception as e: - print(f"无法访问总线 /dev/i2c-{bus_number}: {e}") \ No newline at end of file