Compare commits
13 Commits
main
...
calibratio
| Author | SHA1 | Date | |
|---|---|---|---|
| b3c29dbc0b | |||
| ff72592a3c | |||
| aed9f40c18 | |||
| 9b57620232 | |||
| cb66f29777 | |||
| 4054712a35 | |||
| f1316b00b7 | |||
| cfb5277e3c | |||
| 78d278dab7 | |||
| 2640bf9ec7 | |||
| d477e511f5 | |||
| 1ab6ca603f | |||
| cbfb14a843 |
@ -152,8 +152,6 @@ if(CMVR_WITH_MSQUIC)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(CMVR_SOURCES
|
set(CMVR_SOURCES
|
||||||
src/agvmapviewwidget.cpp
|
|
||||||
src/agvmapviewwidget.h
|
|
||||||
src/audiostreammanager.cpp
|
src/audiostreammanager.cpp
|
||||||
src/audiostreammanager.h
|
src/audiostreammanager.h
|
||||||
src/configeditorwidget.cpp
|
src/configeditorwidget.cpp
|
||||||
@ -193,6 +191,19 @@ set(CMVR_SOURCES
|
|||||||
ui/rpcservicewidget.ui
|
ui/rpcservicewidget.ui
|
||||||
resources.qrc)
|
resources.qrc)
|
||||||
|
|
||||||
|
list(APPEND CMVR_SOURCES
|
||||||
|
src/handeyebridge.cpp src/handeyebridge.h
|
||||||
|
src/handeyestore.cpp src/handeyestore.h
|
||||||
|
src/handeyeurdf.cpp src/handeyeurdf.h
|
||||||
|
src/touchplanner.cpp src/touchplanner.h
|
||||||
|
src/touchsequencecontroller.cpp src/touchsequencecontroller.h
|
||||||
|
src/touchvideowidget.cpp src/touchvideowidget.h
|
||||||
|
src/touchoperationwidget.cpp src/touchoperationwidget.h
|
||||||
|
src/handeyemotionwidget.cpp src/handeyemotionwidget.h
|
||||||
|
src/tcpcalibration.cpp src/tcpcalibration.h
|
||||||
|
src/tcpjogcontroller.cpp src/tcpjogcontroller.h
|
||||||
|
src/tcptoolstore.cpp src/tcptoolstore.h
|
||||||
|
src/tcpcalibrationwidget.cpp src/tcpcalibrationwidget.h)
|
||||||
add_executable(CmvrControlStation ${CMVR_SOURCES})
|
add_executable(CmvrControlStation ${CMVR_SOURCES})
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
set_target_properties(CmvrControlStation PROPERTIES WIN32_EXECUTABLE TRUE)
|
set_target_properties(CmvrControlStation PROPERTIES WIN32_EXECUTABLE TRUE)
|
||||||
@ -356,6 +367,31 @@ add_custom_command(TARGET CmvrControlStation POST_BUILD
|
|||||||
"$<TARGET_FILE_DIR:CmvrControlStation>/models")
|
"$<TARGET_FILE_DIR:CmvrControlStation>/models")
|
||||||
|
|
||||||
install(TARGETS CmvrControlStation RUNTIME DESTINATION bin)
|
install(TARGETS CmvrControlStation RUNTIME DESTINATION bin)
|
||||||
|
add_custom_command(TARGET CmvrControlStation POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_FILE_DIR:CmvrControlStation>/scripts"
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/scripts/handeye_worker.py"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/scripts/handeye_math.py"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/scripts/handeye_refinement.py"
|
||||||
|
"$<TARGET_FILE_DIR:CmvrControlStation>/scripts")
|
||||||
|
install(FILES scripts/handeye_worker.py scripts/handeye_math.py scripts/handeye_refinement.py DESTINATION bin/scripts)
|
||||||
|
if(WIN32)
|
||||||
|
set(CMVR_HAND_EYE_JPEG_PLUGIN "${CMVR_QT_PLUGIN_ROOT}/imageformats/qjpeg$<$<CONFIG:Debug>:d>.dll")
|
||||||
|
add_custom_command(TARGET CmvrControlStation POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_FILE_DIR:CmvrControlStation>/imageformats"
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMVR_HAND_EYE_JPEG_PLUGIN}"
|
||||||
|
"$<TARGET_FILE_DIR:CmvrControlStation>/imageformats/")
|
||||||
|
install(FILES "${CMVR_HAND_EYE_JPEG_PLUGIN}" DESTINATION bin/imageformats)
|
||||||
|
set(CMVR_HAND_EYE_RUNTIME_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/handeye-runtime" CACHE PATH "Bundled Windows x64 hand-eye runtime")
|
||||||
|
if(NOT EXISTS "${CMVR_HAND_EYE_RUNTIME_DIR}/manifest.json")
|
||||||
|
message(FATAL_ERROR "Build the bundled runtime with scripts/package_handeye_runtime.py first")
|
||||||
|
endif()
|
||||||
|
add_custom_command(TARGET CmvrControlStation POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_FILE_DIR:CmvrControlStation>/runtime/handeye"
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMVR_HAND_EYE_RUNTIME_DIR}"
|
||||||
|
"$<TARGET_FILE_DIR:CmvrControlStation>/runtime/handeye")
|
||||||
|
install(DIRECTORY "${CMVR_HAND_EYE_RUNTIME_DIR}/" DESTINATION bin/runtime/handeye)
|
||||||
|
endif()
|
||||||
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/models/"
|
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/models/"
|
||||||
DESTINATION bin/models)
|
DESTINATION bin/models)
|
||||||
install(PROGRAMS "${CMVR_ASSIMP_SCENE_PARSER}"
|
install(PROGRAMS "${CMVR_ASSIMP_SCENE_PARSER}"
|
||||||
|
|||||||
@ -136,7 +136,7 @@ msg_protobuf_compiler.CONFIG += target_predeps
|
|||||||
config_protobuf_compiler.name = Protobuf ${QMAKE_FILE_IN}
|
config_protobuf_compiler.name = Protobuf ${QMAKE_FILE_IN}
|
||||||
config_protobuf_compiler.input = CONFIG_PROTO_FILES
|
config_protobuf_compiler.input = CONFIG_PROTO_FILES
|
||||||
config_protobuf_compiler.output = $$PROTO_GEN_DIR/cmvr/config/${QMAKE_FILE_BASE}/${QMAKE_FILE_BASE}.pb.cc
|
config_protobuf_compiler.output = $$PROTO_GEN_DIR/cmvr/config/${QMAKE_FILE_BASE}/${QMAKE_FILE_BASE}.pb.cc
|
||||||
config_protobuf_compiler.commands = $$quote($$PROTOC) --proto_path=$$quote($$PROTO_ROOT) --cpp_out=$$quote($$PROTO_GEN_DIR) $$quote($$PWD/${QMAKE_FILE_IN})
|
config_protobuf_compiler.commands = $$quote($$PROTOC) --proto_path=$$quote($$PROTO_ROOT) --cpp_out=$$quote($$PROTO_GEN_DIR) $$quote($$PROTO_ROOT/cmvr/config/${QMAKE_FILE_BASE}/${QMAKE_FILE_BASE}.proto)
|
||||||
config_protobuf_compiler.depends = $$CONFIG_PROTO_FILES
|
config_protobuf_compiler.depends = $$CONFIG_PROTO_FILES
|
||||||
config_protobuf_compiler.variable_out = SOURCES
|
config_protobuf_compiler.variable_out = SOURCES
|
||||||
config_protobuf_compiler.CONFIG += target_predeps
|
config_protobuf_compiler.CONFIG += target_predeps
|
||||||
@ -144,7 +144,7 @@ config_protobuf_compiler.CONFIG += target_predeps
|
|||||||
config_root_protobuf_compiler.name = Protobuf ${QMAKE_FILE_IN}
|
config_root_protobuf_compiler.name = Protobuf ${QMAKE_FILE_IN}
|
||||||
config_root_protobuf_compiler.input = CONFIG_ROOT_PROTO_FILES
|
config_root_protobuf_compiler.input = CONFIG_ROOT_PROTO_FILES
|
||||||
config_root_protobuf_compiler.output = $$PROTO_GEN_DIR/cmvr/config/${QMAKE_FILE_BASE}.pb.cc
|
config_root_protobuf_compiler.output = $$PROTO_GEN_DIR/cmvr/config/${QMAKE_FILE_BASE}.pb.cc
|
||||||
config_root_protobuf_compiler.commands = $$quote($$PROTOC) --proto_path=$$quote($$PROTO_ROOT) --cpp_out=$$quote($$PROTO_GEN_DIR) $$quote($$PWD/${QMAKE_FILE_IN})
|
config_root_protobuf_compiler.commands = $$quote($$PROTOC) --proto_path=$$quote($$PROTO_ROOT) --cpp_out=$$quote($$PROTO_GEN_DIR) $$quote($$PROTO_ROOT/cmvr/config/${QMAKE_FILE_BASE}.proto)
|
||||||
config_root_protobuf_compiler.depends = $$CONFIG_ROOT_PROTO_FILES $$COMMON_PROTO_FILES
|
config_root_protobuf_compiler.depends = $$CONFIG_ROOT_PROTO_FILES $$COMMON_PROTO_FILES
|
||||||
config_root_protobuf_compiler.variable_out = SOURCES
|
config_root_protobuf_compiler.variable_out = SOURCES
|
||||||
config_root_protobuf_compiler.CONFIG += target_predeps
|
config_root_protobuf_compiler.CONFIG += target_predeps
|
||||||
@ -152,7 +152,7 @@ config_root_protobuf_compiler.CONFIG += target_predeps
|
|||||||
common_protobuf_compiler.name = Protobuf ${QMAKE_FILE_IN}
|
common_protobuf_compiler.name = Protobuf ${QMAKE_FILE_IN}
|
||||||
common_protobuf_compiler.input = COMMON_PROTO_FILES
|
common_protobuf_compiler.input = COMMON_PROTO_FILES
|
||||||
common_protobuf_compiler.output = $$PROTO_GEN_DIR/cmvr/common/${QMAKE_FILE_BASE}.pb.cc
|
common_protobuf_compiler.output = $$PROTO_GEN_DIR/cmvr/common/${QMAKE_FILE_BASE}.pb.cc
|
||||||
common_protobuf_compiler.commands = $$quote($$PROTOC) --proto_path=$$quote($$PROTO_ROOT) --cpp_out=$$quote($$PROTO_GEN_DIR) $$quote($$PWD/${QMAKE_FILE_IN})
|
common_protobuf_compiler.commands = $$quote($$PROTOC) --proto_path=$$quote($$PROTO_ROOT) --cpp_out=$$quote($$PROTO_GEN_DIR) $$quote($$PROTO_ROOT/cmvr/common/${QMAKE_FILE_BASE}.proto)
|
||||||
common_protobuf_compiler.depends = $$COMMON_PROTO_FILES
|
common_protobuf_compiler.depends = $$COMMON_PROTO_FILES
|
||||||
common_protobuf_compiler.variable_out = SOURCES
|
common_protobuf_compiler.variable_out = SOURCES
|
||||||
common_protobuf_compiler.CONFIG += target_predeps
|
common_protobuf_compiler.CONFIG += target_predeps
|
||||||
@ -160,7 +160,7 @@ common_protobuf_compiler.CONFIG += target_predeps
|
|||||||
mujoco_protobuf_compiler.name = Protobuf ${QMAKE_FILE_IN}
|
mujoco_protobuf_compiler.name = Protobuf ${QMAKE_FILE_IN}
|
||||||
mujoco_protobuf_compiler.input = MUJOCO_PROTO_FILES
|
mujoco_protobuf_compiler.input = MUJOCO_PROTO_FILES
|
||||||
mujoco_protobuf_compiler.output = $$PROTO_GEN_DIR/cmvr/config/mujoco_config/${QMAKE_FILE_BASE}.pb.cc
|
mujoco_protobuf_compiler.output = $$PROTO_GEN_DIR/cmvr/config/mujoco_config/${QMAKE_FILE_BASE}.pb.cc
|
||||||
mujoco_protobuf_compiler.commands = $$quote($$PROTOC) --proto_path=$$quote($$PROTO_ROOT) --cpp_out=$$quote($$PROTO_GEN_DIR) $$quote($$PWD/${QMAKE_FILE_IN})
|
mujoco_protobuf_compiler.commands = $$quote($$PROTOC) --proto_path=$$quote($$PROTO_ROOT) --cpp_out=$$quote($$PROTO_GEN_DIR) $$quote($$PROTO_ROOT/cmvr/config/mujoco_config/${QMAKE_FILE_BASE}.proto)
|
||||||
mujoco_protobuf_compiler.depends = $$MUJOCO_PROTO_FILES
|
mujoco_protobuf_compiler.depends = $$MUJOCO_PROTO_FILES
|
||||||
mujoco_protobuf_compiler.variable_out = SOURCES
|
mujoco_protobuf_compiler.variable_out = SOURCES
|
||||||
mujoco_protobuf_compiler.CONFIG += target_predeps
|
mujoco_protobuf_compiler.CONFIG += target_predeps
|
||||||
@ -237,7 +237,18 @@ CONFIG(debug, debug|release) {
|
|||||||
!exists($$ASSIMP_SCENE_PARSER): error("Qt3D Assimp scene parser not found in the selected Qt Kit.")
|
!exists($$ASSIMP_SCENE_PARSER): error("Qt3D Assimp scene parser not found in the selected Qt Kit.")
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
src/agvmapviewwidget.cpp \
|
src/handeyebridge.cpp \
|
||||||
|
src/handeyestore.cpp \
|
||||||
|
src/handeyeurdf.cpp \
|
||||||
|
src/touchplanner.cpp \
|
||||||
|
src/touchsequencecontroller.cpp \
|
||||||
|
src/touchvideowidget.cpp \
|
||||||
|
src/touchoperationwidget.cpp \
|
||||||
|
src/handeyemotionwidget.cpp \
|
||||||
|
src/tcpcalibration.cpp \
|
||||||
|
src/tcpjogcontroller.cpp \
|
||||||
|
src/tcptoolstore.cpp \
|
||||||
|
src/tcpcalibrationwidget.cpp \
|
||||||
src/audiostreammanager.cpp \
|
src/audiostreammanager.cpp \
|
||||||
src/configeditorwidget.cpp \
|
src/configeditorwidget.cpp \
|
||||||
src/main.cpp \
|
src/main.cpp \
|
||||||
@ -253,7 +264,18 @@ SOURCES += \
|
|||||||
ui/handeyecalibrationwidget.cpp
|
ui/handeyecalibrationwidget.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
src/agvmapviewwidget.h \
|
src/handeyebridge.h \
|
||||||
|
src/handeyestore.h \
|
||||||
|
src/handeyeurdf.h \
|
||||||
|
src/touchplanner.h \
|
||||||
|
src/touchsequencecontroller.h \
|
||||||
|
src/touchvideowidget.h \
|
||||||
|
src/touchoperationwidget.h \
|
||||||
|
src/handeyemotionwidget.h \
|
||||||
|
src/tcpcalibration.h \
|
||||||
|
src/tcpjogcontroller.h \
|
||||||
|
src/tcptoolstore.h \
|
||||||
|
src/tcpcalibrationwidget.h \
|
||||||
src/audiostreammanager.h \
|
src/audiostreammanager.h \
|
||||||
src/configeditorwidget.h \
|
src/configeditorwidget.h \
|
||||||
src/mainwindow.h \
|
src/mainwindow.h \
|
||||||
@ -292,10 +314,26 @@ quic_ca_deployment.path = $$DESTDIR
|
|||||||
assimp_scene_parser_deployment.files = $$ASSIMP_SCENE_PARSER
|
assimp_scene_parser_deployment.files = $$ASSIMP_SCENE_PARSER
|
||||||
assimp_scene_parser_deployment.path = $$DESTDIR/sceneparsers
|
assimp_scene_parser_deployment.path = $$DESTDIR/sceneparsers
|
||||||
COPIES += runtime_library_deployment quic_certificate_deployment quic_ca_deployment assimp_scene_parser_deployment
|
COPIES += runtime_library_deployment quic_certificate_deployment quic_ca_deployment assimp_scene_parser_deployment
|
||||||
|
handeye_algorithm_deployment.files = $$PWD/scripts/handeye_worker.py $$PWD/scripts/handeye_math.py $$PWD/scripts/handeye_refinement.py
|
||||||
|
handeye_algorithm_deployment.path = $$DESTDIR/scripts
|
||||||
|
COPIES += handeye_algorithm_deployment
|
||||||
|
win32 {
|
||||||
|
CONFIG(debug, debug|release): HAND_EYE_JPEG_PLUGIN = $$[QT_INSTALL_PLUGINS]/imageformats/qjpegd.dll
|
||||||
|
else: HAND_EYE_JPEG_PLUGIN = $$[QT_INSTALL_PLUGINS]/imageformats/qjpeg.dll
|
||||||
|
handeye_image_plugin.files = $$HAND_EYE_JPEG_PLUGIN
|
||||||
|
handeye_image_plugin.path = $$DESTDIR/imageformats
|
||||||
|
COPIES += handeye_image_plugin
|
||||||
|
}
|
||||||
|
DISTFILES += scripts/handeye_worker.py scripts/handeye_math.py scripts/handeye_refinement.py
|
||||||
|
DISTFILES += scripts/package_handeye_runtime.py
|
||||||
|
|
||||||
QMAKE_POST_LINK += $$QMAKE_COPY_DIR $$shell_quote($$shell_path($$MODEL_DIR)) $$shell_quote($$shell_path($$DESTDIR/models))
|
QMAKE_POST_LINK += $$QMAKE_COPY_DIR $$shell_quote($$shell_path($$MODEL_DIR)) $$shell_quote($$shell_path($$DESTDIR/models))
|
||||||
|
|
||||||
win32 {
|
win32 {
|
||||||
|
isEmpty(HAND_EYE_RUNTIME_DIR): HAND_EYE_RUNTIME_DIR = $$PWD/third_party/handeye-runtime
|
||||||
|
!exists($$HAND_EYE_RUNTIME_DIR/manifest.json): error(Build the bundled runtime with scripts/package_handeye_runtime.py first)
|
||||||
|
QMAKE_POST_LINK += $$escape_expand(\n\t) if not exist $$shell_quote($$shell_path($$DESTDIR/runtime)) $$QMAKE_MKDIR $$shell_quote($$shell_path($$DESTDIR/runtime))
|
||||||
|
QMAKE_POST_LINK += $$escape_expand(\n\t) $$QMAKE_COPY_DIR $$shell_quote($$shell_path($$HAND_EYE_RUNTIME_DIR)) $$shell_quote($$shell_path($$DESTDIR/runtime/handeye))
|
||||||
QMAKE_POST_LINK += $$escape_expand(\n\t) $$QMAKE_COPY_FILE $$shell_quote($$shell_path($$MSQUIC_TEST_CERT)) $$shell_quote($$shell_path($$DESTDIR/quic-test-server.pfx))
|
QMAKE_POST_LINK += $$escape_expand(\n\t) $$QMAKE_COPY_FILE $$shell_quote($$shell_path($$MSQUIC_TEST_CERT)) $$shell_quote($$shell_path($$DESTDIR/quic-test-server.pfx))
|
||||||
QMAKE_POST_LINK += $$escape_expand(\n\t) $$QMAKE_COPY_FILE $$shell_quote($$shell_path($$MSQUIC_TEST_CA)) $$shell_quote($$shell_path($$DESTDIR/quic-test-ca.crt))
|
QMAKE_POST_LINK += $$escape_expand(\n\t) $$QMAKE_COPY_FILE $$shell_quote($$shell_path($$MSQUIC_TEST_CA)) $$shell_quote($$shell_path($$DESTDIR/quic-test-ca.crt))
|
||||||
}
|
}
|
||||||
|
|||||||
398
feature/CMakeLists.txt
Normal file
398
feature/CMakeLists.txt
Normal file
@ -0,0 +1,398 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.16)
|
||||||
|
project(CmvrControlStation VERSION 1.0.0 LANGUAGES CXX)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 14)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
set(CMAKE_AUTORCC ON)
|
||||||
|
set(CMAKE_AUTOUIC ON)
|
||||||
|
set(CMAKE_AUTOUIC_SEARCH_PATHS "${CMAKE_CURRENT_SOURCE_DIR}/ui")
|
||||||
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||||
|
|
||||||
|
if(WIN32)
|
||||||
|
set(CMVR_MSQUIC_DEFAULT ON)
|
||||||
|
else()
|
||||||
|
set(CMVR_MSQUIC_DEFAULT OFF)
|
||||||
|
endif()
|
||||||
|
option(CMVR_WITH_MSQUIC "Build the embedded MsQuic test server" ${CMVR_MSQUIC_DEFAULT})
|
||||||
|
set(CMVR_MSQUIC_ROOT "" CACHE PATH "Optional MsQuic installation prefix on Linux")
|
||||||
|
set(CMVR_CXX_RUNTIME "" CACHE FILEPATH
|
||||||
|
"Optional libstdc++.so.6 matching a non-system Linux dependency prefix")
|
||||||
|
set(CMVR_ASSIMP_SCENE_PARSER "" CACHE FILEPATH
|
||||||
|
"Qt3D Assimp scene parser plugin used for URDF mesh files")
|
||||||
|
|
||||||
|
set(CMVR_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||||
|
set(CMVR_LIB_DIR "${CMAKE_CURRENT_SOURCE_DIR}/lib")
|
||||||
|
set(CMVR_TOOLS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tools")
|
||||||
|
set(CMVR_CERT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/certs")
|
||||||
|
set(PROTO_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/protos")
|
||||||
|
set(GENERATED_ROOT "${CMAKE_CURRENT_BINARY_DIR}/generated_cpp")
|
||||||
|
|
||||||
|
find_package(Qt5 5.12 REQUIRED COMPONENTS
|
||||||
|
Core Gui Widgets Multimedia 3DCore 3DRender 3DExtras 3DInput 3DAnimation)
|
||||||
|
|
||||||
|
get_target_property(CMVR_QMAKE_EXECUTABLE Qt5::qmake IMPORTED_LOCATION)
|
||||||
|
if(CMVR_QMAKE_EXECUTABLE)
|
||||||
|
execute_process(
|
||||||
|
COMMAND "${CMVR_QMAKE_EXECUTABLE}" -query QT_INSTALL_PLUGINS
|
||||||
|
OUTPUT_VARIABLE CMVR_QT_PLUGIN_ROOT
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
endif()
|
||||||
|
if(NOT CMVR_ASSIMP_SCENE_PARSER)
|
||||||
|
find_file(CMVR_ASSIMP_SCENE_PARSER
|
||||||
|
NAMES assimpsceneimport.dll assimpsceneimportd.dll libassimpsceneimport.so
|
||||||
|
HINTS
|
||||||
|
"${CMVR_QT_PLUGIN_ROOT}/sceneparsers"
|
||||||
|
"/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}/qt5/plugins/sceneparsers")
|
||||||
|
endif()
|
||||||
|
if(NOT CMVR_ASSIMP_SCENE_PARSER OR NOT EXISTS "${CMVR_ASSIMP_SCENE_PARSER}")
|
||||||
|
message(FATAL_ERROR
|
||||||
|
"Qt3D's Assimp scene parser was not found. It is required to display "
|
||||||
|
"STL, DAE, and 3DS meshes from bundled URDF models. On Ubuntu install "
|
||||||
|
"qt3d-assimpsceneimport-plugin, or set CMVR_ASSIMP_SCENE_PARSER to the "
|
||||||
|
"plugin file supplied by the selected Qt installation.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(WIN32)
|
||||||
|
# The checked-in native libraries use the Qt 5.12.4 MinGW 7.3 64-bit ABI.
|
||||||
|
set(PROTOC "${CMVR_TOOLS_DIR}/run_protoc.cmd")
|
||||||
|
set(GRPC_CPP_PLUGIN "${CMVR_TOOLS_DIR}/grpc_cpp_plugin.exe")
|
||||||
|
foreach(REQUIRED_FILE IN ITEMS
|
||||||
|
"${PROTOC}"
|
||||||
|
"${GRPC_CPP_PLUGIN}"
|
||||||
|
"${CMVR_LIB_DIR}/libgrpc++.a"
|
||||||
|
"${CMVR_LIB_DIR}/libprotobuf.a"
|
||||||
|
"${CMVR_LIB_DIR}/libavcodec.dll.a"
|
||||||
|
"${CMVR_LIB_DIR}/liburdfdom_model.dll.a")
|
||||||
|
if(NOT EXISTS "${REQUIRED_FILE}")
|
||||||
|
message(FATAL_ERROR "Required Windows dependency not found: ${REQUIRED_FILE}")
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
else()
|
||||||
|
find_package(Protobuf CONFIG QUIET)
|
||||||
|
if(NOT Protobuf_FOUND)
|
||||||
|
find_package(Protobuf REQUIRED)
|
||||||
|
endif()
|
||||||
|
find_package(gRPC CONFIG REQUIRED)
|
||||||
|
find_package(Threads REQUIRED)
|
||||||
|
find_package(PkgConfig REQUIRED)
|
||||||
|
pkg_check_modules(FFMPEG REQUIRED IMPORTED_TARGET
|
||||||
|
libavcodec libavutil libswscale)
|
||||||
|
find_path(CMVR_URDFDOM_INCLUDE_DIR urdf_parser/urdf_parser.h
|
||||||
|
PATH_SUFFIXES include include/urdfdom)
|
||||||
|
find_path(CMVR_TINYXML_INCLUDE_DIR tinyxml.h PATH_SUFFIXES include)
|
||||||
|
find_library(CMVR_URDFDOM_MODEL_LIBRARY NAMES urdfdom_model)
|
||||||
|
if(NOT CMVR_URDFDOM_INCLUDE_DIR OR NOT CMVR_TINYXML_INCLUDE_DIR OR
|
||||||
|
NOT CMVR_URDFDOM_MODEL_LIBRARY)
|
||||||
|
message(FATAL_ERROR
|
||||||
|
"urdfdom/tinyxml was not found. Install liburdfdom-dev or add its prefix "
|
||||||
|
"to CMAKE_PREFIX_PATH.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT TARGET protobuf::protoc)
|
||||||
|
message(FATAL_ERROR "The Protobuf package does not provide protobuf::protoc")
|
||||||
|
endif()
|
||||||
|
if(NOT TARGET gRPC::grpc_cpp_plugin)
|
||||||
|
message(FATAL_ERROR "The gRPC package does not provide gRPC::grpc_cpp_plugin")
|
||||||
|
endif()
|
||||||
|
set(PROTOC "$<TARGET_FILE:protobuf::protoc>")
|
||||||
|
set(GRPC_CPP_PLUGIN "$<TARGET_FILE:gRPC::grpc_cpp_plugin>")
|
||||||
|
|
||||||
|
# A Conda-provided Qt/gRPC stack may carry an older libstdc++ than the
|
||||||
|
# host compiler. Link against the runtime next to the imported dependency
|
||||||
|
# so symbol versions selected at link time match the library loaded from
|
||||||
|
# the generated RUNPATH. System packages resolve to the system runtime.
|
||||||
|
if(NOT CMVR_CXX_RUNTIME)
|
||||||
|
foreach(DEPENDENCY_TARGET IN ITEMS gRPC::grpc++ Qt5::Core)
|
||||||
|
get_target_property(DEPENDENCY_LOCATION
|
||||||
|
${DEPENDENCY_TARGET} IMPORTED_LOCATION_RELEASE)
|
||||||
|
if(NOT DEPENDENCY_LOCATION)
|
||||||
|
get_target_property(DEPENDENCY_LOCATION
|
||||||
|
${DEPENDENCY_TARGET} IMPORTED_LOCATION)
|
||||||
|
endif()
|
||||||
|
if(DEPENDENCY_LOCATION)
|
||||||
|
get_filename_component(DEPENDENCY_LIB_DIR
|
||||||
|
"${DEPENDENCY_LOCATION}" DIRECTORY)
|
||||||
|
if(EXISTS "${DEPENDENCY_LIB_DIR}/libstdc++.so.6")
|
||||||
|
set(CMVR_CXX_RUNTIME
|
||||||
|
"${DEPENDENCY_LIB_DIR}/libstdc++.so.6")
|
||||||
|
message(STATUS
|
||||||
|
"Using dependency-prefix C++ runtime: ${CMVR_CXX_RUNTIME}")
|
||||||
|
break()
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CMVR_WITH_MSQUIC)
|
||||||
|
if(WIN32)
|
||||||
|
if(NOT EXISTS "${CMVR_INCLUDE_DIR}/msquic.h" OR
|
||||||
|
NOT EXISTS "${CMVR_LIB_DIR}/msquic.dll")
|
||||||
|
message(FATAL_ERROR
|
||||||
|
"CMVR_WITH_MSQUIC is enabled, but include/msquic.h or lib/msquic.dll is missing")
|
||||||
|
endif()
|
||||||
|
set(CMVR_MSQUIC_INCLUDE_DIR "${CMVR_INCLUDE_DIR}")
|
||||||
|
else()
|
||||||
|
find_path(CMVR_MSQUIC_INCLUDE_DIR msquic.h
|
||||||
|
HINTS "${CMVR_MSQUIC_ROOT}"
|
||||||
|
PATH_SUFFIXES include)
|
||||||
|
find_library(CMVR_MSQUIC_LIBRARY NAMES msquic
|
||||||
|
HINTS "${CMVR_MSQUIC_ROOT}"
|
||||||
|
PATH_SUFFIXES lib lib64)
|
||||||
|
if(NOT CMVR_MSQUIC_INCLUDE_DIR OR NOT CMVR_MSQUIC_LIBRARY)
|
||||||
|
message(FATAL_ERROR
|
||||||
|
"CMVR_WITH_MSQUIC=ON requires a Linux MsQuic installation. "
|
||||||
|
"Set CMVR_MSQUIC_ROOT or configure with -DCMVR_WITH_MSQUIC=OFF.")
|
||||||
|
endif()
|
||||||
|
get_filename_component(CMVR_MSQUIC_LIBRARY_DIR
|
||||||
|
"${CMVR_MSQUIC_LIBRARY}" DIRECTORY)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(CMVR_SOURCES
|
||||||
|
src/audiostreammanager.cpp
|
||||||
|
src/audiostreammanager.h
|
||||||
|
src/configeditorwidget.cpp
|
||||||
|
src/configeditorwidget.h
|
||||||
|
src/main.cpp
|
||||||
|
src/mainwindow.cpp
|
||||||
|
src/mainwindow_ui.cpp
|
||||||
|
src/mainwindow.h
|
||||||
|
src/quictestserver.cpp
|
||||||
|
src/quictestserver.h
|
||||||
|
src/rpcservicewidget.cpp
|
||||||
|
src/rpcservicewidget.h
|
||||||
|
src/robotclient.cpp
|
||||||
|
src/robotclient.h
|
||||||
|
src/trendwidget.cpp
|
||||||
|
src/trendwidget.h
|
||||||
|
src/uiicons.h
|
||||||
|
src/urdfviewerwidget.cpp
|
||||||
|
src/urdfviewerwidget.h
|
||||||
|
src/videodecoder.cpp
|
||||||
|
src/videodecoder.h
|
||||||
|
src/videoframe.h
|
||||||
|
src/videorenderwidget.cpp
|
||||||
|
src/videorenderwidget.h
|
||||||
|
ui/handeyecalibrationwidget.cpp
|
||||||
|
ui/handeyecalibrationwidget.h
|
||||||
|
ui/handeyecalibrationwidget.ui
|
||||||
|
ui/mainwindow.ui
|
||||||
|
ui/systemservicepage.ui
|
||||||
|
ui/armservicepage.ui
|
||||||
|
ui/cameraservicepage.ui
|
||||||
|
ui/agvservicepage.ui
|
||||||
|
ui/agvstatusdialog.ui
|
||||||
|
ui/audioservicepage.ui
|
||||||
|
ui/quicserverpage.ui
|
||||||
|
ui/diagnosticspage.ui
|
||||||
|
ui/rpcservicewidget.ui
|
||||||
|
resources.qrc)
|
||||||
|
|
||||||
|
list(APPEND CMVR_SOURCES
|
||||||
|
src/handeyebridge.cpp src/handeyebridge.h
|
||||||
|
src/handeyestore.cpp src/handeyestore.h
|
||||||
|
src/handeyeurdf.cpp src/handeyeurdf.h
|
||||||
|
src/touchplanner.cpp src/touchplanner.h
|
||||||
|
src/touchsequencecontroller.cpp src/touchsequencecontroller.h
|
||||||
|
src/touchvideowidget.cpp src/touchvideowidget.h
|
||||||
|
src/touchoperationwidget.cpp src/touchoperationwidget.h
|
||||||
|
src/handeyemotionwidget.cpp src/handeyemotionwidget.h
|
||||||
|
src/tcpcalibration.cpp src/tcpcalibration.h
|
||||||
|
src/tcpjogcontroller.cpp src/tcpjogcontroller.h
|
||||||
|
src/tcptoolstore.cpp src/tcptoolstore.h
|
||||||
|
src/tcpcalibrationwidget.cpp src/tcpcalibrationwidget.h)
|
||||||
|
add_executable(CmvrControlStation ${CMVR_SOURCES})
|
||||||
|
if(WIN32)
|
||||||
|
set_target_properties(CmvrControlStation PROPERTIES WIN32_EXECUTABLE TRUE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set_target_properties(CmvrControlStation PROPERTIES
|
||||||
|
DEBUG_POSTFIX "_d"
|
||||||
|
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/$<LOWER_CASE:$<CONFIG>>")
|
||||||
|
|
||||||
|
target_compile_definitions(CmvrControlStation PRIVATE
|
||||||
|
CMVR_WITH_GRPC=1
|
||||||
|
CMVR_WITH_MSQUIC=$<BOOL:${CMVR_WITH_MSQUIC}>)
|
||||||
|
if(WIN32)
|
||||||
|
target_compile_definitions(CmvrControlStation PRIVATE _WIN32_WINNT=0x0600)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
target_include_directories(CmvrControlStation PRIVATE "${GENERATED_ROOT}")
|
||||||
|
if(WIN32)
|
||||||
|
target_include_directories(CmvrControlStation PRIVATE
|
||||||
|
"${CMVR_INCLUDE_DIR}"
|
||||||
|
"${CMVR_INCLUDE_DIR}/urdfdom_headers")
|
||||||
|
else()
|
||||||
|
target_include_directories(CmvrControlStation PRIVATE
|
||||||
|
"${CMVR_URDFDOM_INCLUDE_DIR}"
|
||||||
|
"${CMVR_TINYXML_INCLUDE_DIR}"
|
||||||
|
"${CMVR_INCLUDE_DIR}/urdfdom_headers")
|
||||||
|
endif()
|
||||||
|
if(CMVR_WITH_MSQUIC)
|
||||||
|
target_include_directories(CmvrControlStation PRIVATE "${CMVR_MSQUIC_INCLUDE_DIR}")
|
||||||
|
if(UNIX AND CMVR_MSQUIC_LIBRARY_DIR)
|
||||||
|
set_property(TARGET CmvrControlStation APPEND PROPERTY
|
||||||
|
BUILD_RPATH "${CMVR_MSQUIC_LIBRARY_DIR}")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
target_link_libraries(CmvrControlStation PRIVATE
|
||||||
|
Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Multimedia
|
||||||
|
Qt5::3DCore Qt5::3DRender Qt5::3DExtras Qt5::3DInput Qt5::3DAnimation)
|
||||||
|
|
||||||
|
# Generate every project-local CMVR message. This avoids source-tree generated
|
||||||
|
# files and automatically picks up newly added configuration messages.
|
||||||
|
file(GLOB_RECURSE PROTO_FILES CONFIGURE_DEPENDS
|
||||||
|
"${PROTO_ROOT}/cmvr/api/*.proto"
|
||||||
|
"${PROTO_ROOT}/cmvr/common/*.proto"
|
||||||
|
"${PROTO_ROOT}/cmvr/config/*.proto"
|
||||||
|
"${PROTO_ROOT}/cmvr/msgs/agv.proto"
|
||||||
|
"${PROTO_ROOT}/cmvr/quic_edge/v1/*.proto")
|
||||||
|
|
||||||
|
set(SERVICE_NAMES
|
||||||
|
cmvr/api/agv_service
|
||||||
|
cmvr/api/arm_service
|
||||||
|
cmvr/api/biohead_service
|
||||||
|
cmvr/api/camera_service
|
||||||
|
cmvr/api/configuration_service
|
||||||
|
cmvr/api/dexhand_service
|
||||||
|
cmvr/api/hlc_service
|
||||||
|
cmvr/api/microphone_service
|
||||||
|
cmvr/api/speaker_service
|
||||||
|
cmvr/api/system_service
|
||||||
|
cmvr/api/test_service)
|
||||||
|
|
||||||
|
set(GENERATED_FILES)
|
||||||
|
foreach(PROTO_FILE IN LISTS PROTO_FILES)
|
||||||
|
file(RELATIVE_PATH PROTO_RELATIVE "${PROTO_ROOT}" "${PROTO_FILE}")
|
||||||
|
string(REGEX REPLACE "\\.proto$" "" PROTO_NAME "${PROTO_RELATIVE}")
|
||||||
|
set(PB_CC "${GENERATED_ROOT}/${PROTO_NAME}.pb.cc")
|
||||||
|
set(PB_H "${GENERATED_ROOT}/${PROTO_NAME}.pb.h")
|
||||||
|
get_filename_component(PROTO_OUTPUT_DIR "${PB_CC}" DIRECTORY)
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT "${PB_CC}" "${PB_H}"
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E make_directory "${PROTO_OUTPUT_DIR}"
|
||||||
|
COMMAND "${PROTOC}"
|
||||||
|
"--proto_path=${PROTO_ROOT}"
|
||||||
|
"--cpp_out=${GENERATED_ROOT}"
|
||||||
|
"${PROTO_FILE}"
|
||||||
|
DEPENDS "${PROTO_FILE}" ${PROTO_FILES}
|
||||||
|
VERBATIM)
|
||||||
|
list(APPEND GENERATED_FILES "${PB_CC}" "${PB_H}")
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
foreach(SERVICE_NAME IN LISTS SERVICE_NAMES)
|
||||||
|
set(PROTO_FILE "${PROTO_ROOT}/${SERVICE_NAME}.proto")
|
||||||
|
set(GRPC_CC "${GENERATED_ROOT}/${SERVICE_NAME}.grpc.pb.cc")
|
||||||
|
set(GRPC_H "${GENERATED_ROOT}/${SERVICE_NAME}.grpc.pb.h")
|
||||||
|
get_filename_component(PROTO_OUTPUT_DIR "${GRPC_CC}" DIRECTORY)
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT "${GRPC_CC}" "${GRPC_H}"
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E make_directory "${PROTO_OUTPUT_DIR}"
|
||||||
|
COMMAND "${PROTOC}"
|
||||||
|
"--proto_path=${PROTO_ROOT}"
|
||||||
|
"--grpc_out=${GENERATED_ROOT}"
|
||||||
|
"--plugin=protoc-gen-grpc=${GRPC_CPP_PLUGIN}"
|
||||||
|
"${PROTO_FILE}"
|
||||||
|
DEPENDS "${PROTO_FILE}" ${PROTO_FILES}
|
||||||
|
VERBATIM)
|
||||||
|
list(APPEND GENERATED_FILES "${GRPC_CC}" "${GRPC_H}")
|
||||||
|
endforeach()
|
||||||
|
target_sources(CmvrControlStation PRIVATE ${GENERATED_FILES})
|
||||||
|
|
||||||
|
if(WIN32)
|
||||||
|
file(GLOB ABSL_STATIC_LIBS "${CMVR_LIB_DIR}/libabsl_*.a")
|
||||||
|
target_link_libraries(CmvrControlStation PRIVATE
|
||||||
|
"-Wl,--start-group"
|
||||||
|
"${CMVR_LIB_DIR}/libgrpc++.a"
|
||||||
|
"${CMVR_LIB_DIR}/libgrpc.a"
|
||||||
|
"${CMVR_LIB_DIR}/libgpr.a"
|
||||||
|
"${CMVR_LIB_DIR}/libaddress_sorting.a"
|
||||||
|
"${CMVR_LIB_DIR}/libre2.a"
|
||||||
|
"${CMVR_LIB_DIR}/libupb.a"
|
||||||
|
"${CMVR_LIB_DIR}/libcares.a"
|
||||||
|
"${CMVR_LIB_DIR}/libssl.a"
|
||||||
|
"${CMVR_LIB_DIR}/libcrypto.a"
|
||||||
|
"${CMVR_LIB_DIR}/libzlibstatic.a"
|
||||||
|
"${CMVR_LIB_DIR}/libprotobuf.a"
|
||||||
|
${ABSL_STATIC_LIBS}
|
||||||
|
"-Wl,--end-group"
|
||||||
|
"${CMVR_LIB_DIR}/libavcodec.dll.a"
|
||||||
|
"${CMVR_LIB_DIR}/libavutil.dll.a"
|
||||||
|
"${CMVR_LIB_DIR}/libswscale.dll.a"
|
||||||
|
"${CMVR_LIB_DIR}/liburdfdom_model.dll.a"
|
||||||
|
ws2_32 crypt32 advapi32 bcrypt dbghelp iphlpapi secur32 ntdll)
|
||||||
|
else()
|
||||||
|
if(CMVR_CXX_RUNTIME)
|
||||||
|
target_link_libraries(CmvrControlStation PRIVATE "${CMVR_CXX_RUNTIME}")
|
||||||
|
endif()
|
||||||
|
target_link_libraries(CmvrControlStation PRIVATE
|
||||||
|
protobuf::libprotobuf
|
||||||
|
gRPC::grpc++
|
||||||
|
PkgConfig::FFMPEG
|
||||||
|
Threads::Threads
|
||||||
|
"${CMVR_URDFDOM_MODEL_LIBRARY}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(WIN32)
|
||||||
|
file(GLOB CMVR_RUNTIME_DLLS "${CMVR_LIB_DIR}/*.dll")
|
||||||
|
foreach(RUNTIME_DLL IN LISTS CMVR_RUNTIME_DLLS)
|
||||||
|
add_custom_command(TARGET CmvrControlStation POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||||
|
"${RUNTIME_DLL}" "$<TARGET_FILE_DIR:CmvrControlStation>")
|
||||||
|
endforeach()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
foreach(CERTIFICATE IN ITEMS quic-test-server.pfx quic-test-ca.crt)
|
||||||
|
if(EXISTS "${CMVR_CERT_DIR}/${CERTIFICATE}")
|
||||||
|
add_custom_command(TARGET CmvrControlStation POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||||
|
"${CMVR_CERT_DIR}/${CERTIFICATE}"
|
||||||
|
"$<TARGET_FILE_DIR:CmvrControlStation>/${CERTIFICATE}")
|
||||||
|
install(FILES "${CMVR_CERT_DIR}/${CERTIFICATE}" DESTINATION bin)
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
add_custom_command(TARGET CmvrControlStation POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E make_directory
|
||||||
|
"$<TARGET_FILE_DIR:CmvrControlStation>/sceneparsers"
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||||
|
"${CMVR_ASSIMP_SCENE_PARSER}"
|
||||||
|
"$<TARGET_FILE_DIR:CmvrControlStation>/sceneparsers/"
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/models"
|
||||||
|
"$<TARGET_FILE_DIR:CmvrControlStation>/models")
|
||||||
|
|
||||||
|
install(TARGETS CmvrControlStation RUNTIME DESTINATION bin)
|
||||||
|
add_custom_command(TARGET CmvrControlStation POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_FILE_DIR:CmvrControlStation>/scripts"
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/scripts/handeye_worker.py"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/scripts/handeye_math.py"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/scripts/handeye_refinement.py"
|
||||||
|
"$<TARGET_FILE_DIR:CmvrControlStation>/scripts")
|
||||||
|
install(FILES scripts/handeye_worker.py scripts/handeye_math.py scripts/handeye_refinement.py DESTINATION bin/scripts)
|
||||||
|
if(WIN32)
|
||||||
|
set(CMVR_HAND_EYE_JPEG_PLUGIN "${CMVR_QT_PLUGIN_ROOT}/imageformats/qjpeg$<$<CONFIG:Debug>:d>.dll")
|
||||||
|
add_custom_command(TARGET CmvrControlStation POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_FILE_DIR:CmvrControlStation>/imageformats"
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMVR_HAND_EYE_JPEG_PLUGIN}"
|
||||||
|
"$<TARGET_FILE_DIR:CmvrControlStation>/imageformats/")
|
||||||
|
install(FILES "${CMVR_HAND_EYE_JPEG_PLUGIN}" DESTINATION bin/imageformats)
|
||||||
|
set(CMVR_HAND_EYE_RUNTIME_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/handeye-runtime" CACHE PATH "Bundled Windows x64 hand-eye runtime")
|
||||||
|
if(NOT EXISTS "${CMVR_HAND_EYE_RUNTIME_DIR}/manifest.json")
|
||||||
|
message(FATAL_ERROR "Build the bundled runtime with scripts/package_handeye_runtime.py first")
|
||||||
|
endif()
|
||||||
|
add_custom_command(TARGET CmvrControlStation POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_FILE_DIR:CmvrControlStation>/runtime/handeye"
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMVR_HAND_EYE_RUNTIME_DIR}"
|
||||||
|
"$<TARGET_FILE_DIR:CmvrControlStation>/runtime/handeye")
|
||||||
|
install(DIRECTORY "${CMVR_HAND_EYE_RUNTIME_DIR}/" DESTINATION bin/runtime/handeye)
|
||||||
|
endif()
|
||||||
|
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/models/"
|
||||||
|
DESTINATION bin/models)
|
||||||
|
install(PROGRAMS "${CMVR_ASSIMP_SCENE_PARSER}"
|
||||||
|
DESTINATION bin/sceneparsers)
|
||||||
341
feature/CmvrControlStation.pro
Normal file
341
feature/CmvrControlStation.pro
Normal file
@ -0,0 +1,341 @@
|
|||||||
|
QT += core gui widgets multimedia 3dcore 3drender 3dextras 3dinput 3danimation
|
||||||
|
|
||||||
|
CONFIG += c++14 warn_on debug_and_release
|
||||||
|
TEMPLATE = app
|
||||||
|
|
||||||
|
DEFINES += QT_DEPRECATED_WARNINGS _WIN32_WINNT=0x0600
|
||||||
|
|
||||||
|
INCLUDE_DIR = $$clean_path($$PWD/include)
|
||||||
|
LIB_DIR = $$clean_path($$PWD/lib)
|
||||||
|
TOOLS_DIR = $$clean_path($$PWD/tools)
|
||||||
|
CERT_DIR = $$clean_path($$PWD/certs)
|
||||||
|
PROTO_ROOT = $$clean_path($$PWD/protos)
|
||||||
|
PROTO_GEN_DIR = $$clean_path($$PWD/generated_cpp)
|
||||||
|
PROTOC = $$TOOLS_DIR/run_protoc.cmd
|
||||||
|
GRPC_CPP_PLUGIN = $$TOOLS_DIR/grpc_cpp_plugin.exe
|
||||||
|
MSQUIC_DLL = $$LIB_DIR/msquic.dll
|
||||||
|
MSQUIC_TEST_CERT = $$CERT_DIR/quic-test-server.pfx
|
||||||
|
MSQUIC_TEST_CA = $$CERT_DIR/quic-test-ca.crt
|
||||||
|
RUNTIME_DLLS = $$files($$LIB_DIR/*.dll)
|
||||||
|
MODEL_DIR = $$clean_path($$PWD/models)
|
||||||
|
QT_SCENEPARSER_DIR = $$clean_path($$[QT_INSTALL_PLUGINS]/sceneparsers)
|
||||||
|
|
||||||
|
!exists($$PROTOC): error("protoc launcher not found. Run scripts/build_native_deps.ps1 first.")
|
||||||
|
!exists($$GRPC_CPP_PLUGIN): error("grpc_cpp_plugin.exe not found. Run scripts/build_native_deps.ps1 first.")
|
||||||
|
!exists($$MSQUIC_DLL): error("msquic.dll not found. Run scripts/install_msquic.ps1 first.")
|
||||||
|
!exists($$MSQUIC_TEST_CERT): error("QUIC test certificate not found. Run scripts/install_msquic.ps1 first.")
|
||||||
|
!exists($$MSQUIC_TEST_CA): error("QUIC test CA not found. Run scripts/install_msquic.ps1 first.")
|
||||||
|
!exists($$INCLUDE_DIR/libavcodec/avcodec.h): error("FFmpeg headers not found in include.")
|
||||||
|
!exists($$LIB_DIR/avcodec-58.dll): error("FFmpeg runtime DLLs not found in lib.")
|
||||||
|
!exists($$INCLUDE_DIR/urdf_parser/urdf_parser.h): error("urdfdom headers not found in include.")
|
||||||
|
!exists($$LIB_DIR/liburdfdom_model.dll.a): error("urdfdom link library not found in lib.")
|
||||||
|
!exists($$LIB_DIR/liburdfdom_model.dll): error("urdfdom runtime DLL not found in lib.")
|
||||||
|
|
||||||
|
PROTO_FILES = \
|
||||||
|
$$PROTO_ROOT/cmvr/api/common.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/api/agv_command.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/api/agv_service.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/api/arm_command.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/api/arm_service.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/api/biohead_command.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/api/biohead_service.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/api/camera_command.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/api/camera_service.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/api/configuration_command.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/api/configuration_service.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/api/dexhand_command.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/api/dexhand_service.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/api/hlc_command.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/api/hlc_service.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/api/microphone_command.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/api/microphone_service.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/api/speaker_command.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/api/speaker_service.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/api/system_command.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/api/system_service.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/api/test_service.proto
|
||||||
|
|
||||||
|
GRPC_PROTO_FILES = \
|
||||||
|
$$PROTO_ROOT/cmvr/api/agv_service.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/api/arm_service.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/api/biohead_service.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/api/camera_service.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/api/configuration_service.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/api/dexhand_service.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/api/hlc_service.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/api/microphone_service.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/api/speaker_service.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/api/system_service.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/api/test_service.proto
|
||||||
|
|
||||||
|
MSG_PROTO_FILES = \
|
||||||
|
$$PROTO_ROOT/cmvr/msgs/agv.proto
|
||||||
|
|
||||||
|
CONFIG_PROTO_FILES = \
|
||||||
|
$$PROTO_ROOT/cmvr/config/agv_config/agv_config.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/config/arm_config/arm_config.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/config/aubo_robot_config/aubo_robot_config.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/config/biohead_config/biohead_config.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/config/camera_config/camera_config.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/config/cmvr_es_config/cmvr_es_config.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/config/device_manager_config/device_manager_config.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/config/dexhand_config/dexhand_config.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/config/grpc_server_config/grpc_server_config.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/config/logger_config/logger_config.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/config/microphone_config/microphone_config.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/config/motor_config/motor_config.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/config/quic_edge_config/quic_edge_config.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/config/self_collision_task_config/self_collision_task_config.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/config/speaker_config/speaker_config.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/config/task_manager_config/task_manager_config.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/config/touch_screen_task_config/touch_screen_task_config.proto
|
||||||
|
|
||||||
|
CONFIG_ROOT_PROTO_FILES = \
|
||||||
|
$$PROTO_ROOT/cmvr/config/cartesian_motion_validation_config.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/config/joint_limits_config.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/config/lawba_ik_config.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/config/pinocchio_dls_ik_config.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/config/pinocchio_qp_ik_config.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/config/srs_ik_config.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/config/touch_screen_algorithm_config.proto \
|
||||||
|
$$PROTO_ROOT/cmvr/config/touch_screen_common_config.proto
|
||||||
|
|
||||||
|
COMMON_PROTO_FILES = \
|
||||||
|
$$PROTO_ROOT/cmvr/common/geometry.proto
|
||||||
|
|
||||||
|
MUJOCO_PROTO_FILES = \
|
||||||
|
$$PROTO_ROOT/cmvr/config/mujoco_config/mujoco_world_config.proto
|
||||||
|
|
||||||
|
QUIC_PROTO_FILES = \
|
||||||
|
$$PROTO_ROOT/cmvr/quic_edge/v1/quic_edge.proto
|
||||||
|
|
||||||
|
# Show the complete local proto tree in Qt Creator without compiling unused APIs.
|
||||||
|
OTHER_FILES += $$files($$PROTO_ROOT/*.proto, true) $$files($$MODEL_DIR/*.urdf, true)
|
||||||
|
|
||||||
|
INCLUDEPATH += \
|
||||||
|
$$PROTO_GEN_DIR \
|
||||||
|
$$INCLUDE_DIR \
|
||||||
|
$$INCLUDE_DIR/urdfdom_headers
|
||||||
|
|
||||||
|
protobuf_compiler.name = Protobuf ${QMAKE_FILE_IN}
|
||||||
|
protobuf_compiler.input = PROTO_FILES
|
||||||
|
protobuf_compiler.output = $$PROTO_GEN_DIR/cmvr/api/${QMAKE_FILE_BASE}.pb.cc
|
||||||
|
protobuf_compiler.commands = $$quote($$PROTOC) --proto_path=$$quote($$PROTO_ROOT) --cpp_out=$$quote($$PROTO_GEN_DIR) $$quote($$PROTO_ROOT/cmvr/api/${QMAKE_FILE_BASE}.proto)
|
||||||
|
protobuf_compiler.depends = $$PROTO_FILES $$MSG_PROTO_FILES
|
||||||
|
protobuf_compiler.variable_out = SOURCES
|
||||||
|
protobuf_compiler.CONFIG += target_predeps
|
||||||
|
|
||||||
|
msg_protobuf_compiler.name = Protobuf ${QMAKE_FILE_IN}
|
||||||
|
msg_protobuf_compiler.input = MSG_PROTO_FILES
|
||||||
|
msg_protobuf_compiler.output = $$PROTO_GEN_DIR/cmvr/msgs/${QMAKE_FILE_BASE}.pb.cc
|
||||||
|
msg_protobuf_compiler.commands = $$quote($$PROTOC) --proto_path=$$quote($$PROTO_ROOT) --cpp_out=$$quote($$PROTO_GEN_DIR) $$quote($$PROTO_ROOT/cmvr/msgs/${QMAKE_FILE_BASE}.proto)
|
||||||
|
msg_protobuf_compiler.depends = $$MSG_PROTO_FILES
|
||||||
|
msg_protobuf_compiler.variable_out = SOURCES
|
||||||
|
msg_protobuf_compiler.CONFIG += target_predeps
|
||||||
|
|
||||||
|
config_protobuf_compiler.name = Protobuf ${QMAKE_FILE_IN}
|
||||||
|
config_protobuf_compiler.input = CONFIG_PROTO_FILES
|
||||||
|
config_protobuf_compiler.output = $$PROTO_GEN_DIR/cmvr/config/${QMAKE_FILE_BASE}/${QMAKE_FILE_BASE}.pb.cc
|
||||||
|
config_protobuf_compiler.commands = $$quote($$PROTOC) --proto_path=$$quote($$PROTO_ROOT) --cpp_out=$$quote($$PROTO_GEN_DIR) $$quote($$PROTO_ROOT/cmvr/config/${QMAKE_FILE_BASE}/${QMAKE_FILE_BASE}.proto)
|
||||||
|
config_protobuf_compiler.depends = $$CONFIG_PROTO_FILES
|
||||||
|
config_protobuf_compiler.variable_out = SOURCES
|
||||||
|
config_protobuf_compiler.CONFIG += target_predeps
|
||||||
|
|
||||||
|
config_root_protobuf_compiler.name = Protobuf ${QMAKE_FILE_IN}
|
||||||
|
config_root_protobuf_compiler.input = CONFIG_ROOT_PROTO_FILES
|
||||||
|
config_root_protobuf_compiler.output = $$PROTO_GEN_DIR/cmvr/config/${QMAKE_FILE_BASE}.pb.cc
|
||||||
|
config_root_protobuf_compiler.commands = $$quote($$PROTOC) --proto_path=$$quote($$PROTO_ROOT) --cpp_out=$$quote($$PROTO_GEN_DIR) $$quote($$PROTO_ROOT/cmvr/config/${QMAKE_FILE_BASE}.proto)
|
||||||
|
config_root_protobuf_compiler.depends = $$CONFIG_ROOT_PROTO_FILES $$COMMON_PROTO_FILES
|
||||||
|
config_root_protobuf_compiler.variable_out = SOURCES
|
||||||
|
config_root_protobuf_compiler.CONFIG += target_predeps
|
||||||
|
|
||||||
|
common_protobuf_compiler.name = Protobuf ${QMAKE_FILE_IN}
|
||||||
|
common_protobuf_compiler.input = COMMON_PROTO_FILES
|
||||||
|
common_protobuf_compiler.output = $$PROTO_GEN_DIR/cmvr/common/${QMAKE_FILE_BASE}.pb.cc
|
||||||
|
common_protobuf_compiler.commands = $$quote($$PROTOC) --proto_path=$$quote($$PROTO_ROOT) --cpp_out=$$quote($$PROTO_GEN_DIR) $$quote($$PROTO_ROOT/cmvr/common/${QMAKE_FILE_BASE}.proto)
|
||||||
|
common_protobuf_compiler.depends = $$COMMON_PROTO_FILES
|
||||||
|
common_protobuf_compiler.variable_out = SOURCES
|
||||||
|
common_protobuf_compiler.CONFIG += target_predeps
|
||||||
|
|
||||||
|
mujoco_protobuf_compiler.name = Protobuf ${QMAKE_FILE_IN}
|
||||||
|
mujoco_protobuf_compiler.input = MUJOCO_PROTO_FILES
|
||||||
|
mujoco_protobuf_compiler.output = $$PROTO_GEN_DIR/cmvr/config/mujoco_config/${QMAKE_FILE_BASE}.pb.cc
|
||||||
|
mujoco_protobuf_compiler.commands = $$quote($$PROTOC) --proto_path=$$quote($$PROTO_ROOT) --cpp_out=$$quote($$PROTO_GEN_DIR) $$quote($$PROTO_ROOT/cmvr/config/mujoco_config/${QMAKE_FILE_BASE}.proto)
|
||||||
|
mujoco_protobuf_compiler.depends = $$MUJOCO_PROTO_FILES
|
||||||
|
mujoco_protobuf_compiler.variable_out = SOURCES
|
||||||
|
mujoco_protobuf_compiler.CONFIG += target_predeps
|
||||||
|
|
||||||
|
grpc_compiler.name = gRPC ${QMAKE_FILE_IN}
|
||||||
|
grpc_compiler.input = GRPC_PROTO_FILES
|
||||||
|
grpc_compiler.output = $$PROTO_GEN_DIR/cmvr/api/${QMAKE_FILE_BASE}.grpc.pb.cc
|
||||||
|
grpc_compiler.commands = $$quote($$PROTOC) --proto_path=$$quote($$PROTO_ROOT) --grpc_out=$$quote($$PROTO_GEN_DIR) --plugin=protoc-gen-grpc=$$quote($$GRPC_CPP_PLUGIN) $$quote($$PROTO_ROOT/cmvr/api/${QMAKE_FILE_BASE}.proto)
|
||||||
|
grpc_compiler.depends = $$PROTO_FILES $$MSG_PROTO_FILES
|
||||||
|
grpc_compiler.variable_out = SOURCES
|
||||||
|
grpc_compiler.CONFIG += target_predeps
|
||||||
|
|
||||||
|
quic_protobuf_compiler.name = Protobuf ${QMAKE_FILE_IN}
|
||||||
|
quic_protobuf_compiler.input = QUIC_PROTO_FILES
|
||||||
|
quic_protobuf_compiler.output = $$PROTO_GEN_DIR/cmvr/quic_edge/v1/${QMAKE_FILE_BASE}.pb.cc
|
||||||
|
quic_protobuf_compiler.commands = $$quote($$PROTOC) --proto_path=$$quote($$PROTO_ROOT) --cpp_out=$$quote($$PROTO_GEN_DIR) $$quote($$PROTO_ROOT/cmvr/quic_edge/v1/${QMAKE_FILE_BASE}.proto)
|
||||||
|
quic_protobuf_compiler.depends = $$QUIC_PROTO_FILES
|
||||||
|
quic_protobuf_compiler.variable_out = SOURCES
|
||||||
|
quic_protobuf_compiler.CONFIG += target_predeps
|
||||||
|
|
||||||
|
QMAKE_EXTRA_COMPILERS += protobuf_compiler msg_protobuf_compiler config_protobuf_compiler config_root_protobuf_compiler common_protobuf_compiler mujoco_protobuf_compiler grpc_compiler quic_protobuf_compiler
|
||||||
|
|
||||||
|
ABSL_STATIC_LIBS = $$files($$LIB_DIR/libabsl_*.a)
|
||||||
|
LIBS += \
|
||||||
|
-Wl,--start-group \
|
||||||
|
$$LIB_DIR/libgrpc++.a \
|
||||||
|
$$LIB_DIR/libgrpc.a \
|
||||||
|
$$LIB_DIR/libgpr.a \
|
||||||
|
$$LIB_DIR/libaddress_sorting.a \
|
||||||
|
$$LIB_DIR/libre2.a \
|
||||||
|
$$LIB_DIR/libupb.a \
|
||||||
|
$$LIB_DIR/libcares.a \
|
||||||
|
$$LIB_DIR/libssl.a \
|
||||||
|
$$LIB_DIR/libcrypto.a \
|
||||||
|
$$LIB_DIR/libzlibstatic.a \
|
||||||
|
$$LIB_DIR/libprotobuf.a \
|
||||||
|
$$ABSL_STATIC_LIBS \
|
||||||
|
-Wl,--end-group \
|
||||||
|
$$LIB_DIR/libavcodec.dll.a \
|
||||||
|
$$LIB_DIR/libavutil.dll.a \
|
||||||
|
$$LIB_DIR/libswscale.dll.a \
|
||||||
|
$$LIB_DIR/liburdfdom_model.dll.a \
|
||||||
|
-lws2_32 \
|
||||||
|
-lcrypt32 \
|
||||||
|
-ladvapi32 \
|
||||||
|
-lbcrypt \
|
||||||
|
-ldbghelp \
|
||||||
|
-liphlpapi \
|
||||||
|
-lsecur32 \
|
||||||
|
-lntdll
|
||||||
|
|
||||||
|
DEFINES += CMVR_WITH_GRPC=1 CMVR_WITH_MSQUIC=1
|
||||||
|
|
||||||
|
CONFIG(debug, debug|release) {
|
||||||
|
TARGET = CmvrControlStation_d
|
||||||
|
DESTDIR = $$clean_path($$PWD/bin/debug)
|
||||||
|
OBJECTS_DIR = build/debug/obj
|
||||||
|
MOC_DIR = build/debug/moc
|
||||||
|
RCC_DIR = build/debug/rcc
|
||||||
|
UI_DIR = build/debug/ui
|
||||||
|
DEFINES += CMVR_DEBUG_BUILD
|
||||||
|
ASSIMP_SCENE_PARSER = $$QT_SCENEPARSER_DIR/assimpsceneimportd.dll
|
||||||
|
} else {
|
||||||
|
TARGET = CmvrControlStation
|
||||||
|
DESTDIR = $$clean_path($$PWD/bin/release)
|
||||||
|
OBJECTS_DIR = build/release/obj
|
||||||
|
MOC_DIR = build/release/moc
|
||||||
|
RCC_DIR = build/release/rcc
|
||||||
|
UI_DIR = build/release/ui
|
||||||
|
DEFINES += NDEBUG
|
||||||
|
ASSIMP_SCENE_PARSER = $$QT_SCENEPARSER_DIR/assimpsceneimport.dll
|
||||||
|
}
|
||||||
|
|
||||||
|
!exists($$ASSIMP_SCENE_PARSER): error("Qt3D Assimp scene parser not found in the selected Qt Kit.")
|
||||||
|
|
||||||
|
SOURCES += \
|
||||||
|
src/handeyebridge.cpp \
|
||||||
|
src/handeyestore.cpp \
|
||||||
|
src/handeyeurdf.cpp \
|
||||||
|
src/touchplanner.cpp \
|
||||||
|
src/touchsequencecontroller.cpp \
|
||||||
|
src/touchvideowidget.cpp \
|
||||||
|
src/touchoperationwidget.cpp \
|
||||||
|
src/handeyemotionwidget.cpp \
|
||||||
|
src/tcpcalibration.cpp \
|
||||||
|
src/tcpjogcontroller.cpp \
|
||||||
|
src/tcptoolstore.cpp \
|
||||||
|
src/tcpcalibrationwidget.cpp \
|
||||||
|
src/audiostreammanager.cpp \
|
||||||
|
src/configeditorwidget.cpp \
|
||||||
|
src/main.cpp \
|
||||||
|
src/mainwindow.cpp \
|
||||||
|
src/mainwindow_ui.cpp \
|
||||||
|
src/quictestserver.cpp \
|
||||||
|
src/rpcservicewidget.cpp \
|
||||||
|
src/robotclient.cpp \
|
||||||
|
src/trendwidget.cpp \
|
||||||
|
src/urdfviewerwidget.cpp \
|
||||||
|
src/videodecoder.cpp \
|
||||||
|
src/videorenderwidget.cpp \
|
||||||
|
ui/handeyecalibrationwidget.cpp
|
||||||
|
|
||||||
|
HEADERS += \
|
||||||
|
src/handeyebridge.h \
|
||||||
|
src/handeyestore.h \
|
||||||
|
src/handeyeurdf.h \
|
||||||
|
src/touchplanner.h \
|
||||||
|
src/touchsequencecontroller.h \
|
||||||
|
src/touchvideowidget.h \
|
||||||
|
src/touchoperationwidget.h \
|
||||||
|
src/handeyemotionwidget.h \
|
||||||
|
src/tcpcalibration.h \
|
||||||
|
src/tcpjogcontroller.h \
|
||||||
|
src/tcptoolstore.h \
|
||||||
|
src/tcpcalibrationwidget.h \
|
||||||
|
src/audiostreammanager.h \
|
||||||
|
src/configeditorwidget.h \
|
||||||
|
src/mainwindow.h \
|
||||||
|
src/quictestserver.h \
|
||||||
|
src/rpcservicewidget.h \
|
||||||
|
src/robotclient.h \
|
||||||
|
src/trendwidget.h \
|
||||||
|
src/uiicons.h \
|
||||||
|
src/urdfviewerwidget.h \
|
||||||
|
src/videodecoder.h \
|
||||||
|
src/videoframe.h \
|
||||||
|
src/videorenderwidget.h \
|
||||||
|
ui/handeyecalibrationwidget.h
|
||||||
|
|
||||||
|
FORMS += \
|
||||||
|
ui/handeyecalibrationwidget.ui \
|
||||||
|
ui/mainwindow.ui \
|
||||||
|
ui/systemservicepage.ui \
|
||||||
|
ui/armservicepage.ui \
|
||||||
|
ui/cameraservicepage.ui \
|
||||||
|
ui/agvservicepage.ui \
|
||||||
|
ui/agvstatusdialog.ui \
|
||||||
|
ui/audioservicepage.ui \
|
||||||
|
ui/quicserverpage.ui \
|
||||||
|
ui/diagnosticspage.ui \
|
||||||
|
ui/rpcservicewidget.ui
|
||||||
|
|
||||||
|
RESOURCES += resources.qrc
|
||||||
|
|
||||||
|
runtime_library_deployment.files = $$RUNTIME_DLLS
|
||||||
|
runtime_library_deployment.path = $$DESTDIR
|
||||||
|
quic_certificate_deployment.files = $$MSQUIC_TEST_CERT
|
||||||
|
quic_certificate_deployment.path = $$DESTDIR
|
||||||
|
quic_ca_deployment.files = $$MSQUIC_TEST_CA
|
||||||
|
quic_ca_deployment.path = $$DESTDIR
|
||||||
|
assimp_scene_parser_deployment.files = $$ASSIMP_SCENE_PARSER
|
||||||
|
assimp_scene_parser_deployment.path = $$DESTDIR/sceneparsers
|
||||||
|
COPIES += runtime_library_deployment quic_certificate_deployment quic_ca_deployment assimp_scene_parser_deployment
|
||||||
|
handeye_algorithm_deployment.files = $$PWD/scripts/handeye_worker.py $$PWD/scripts/handeye_math.py $$PWD/scripts/handeye_refinement.py
|
||||||
|
handeye_algorithm_deployment.path = $$DESTDIR/scripts
|
||||||
|
COPIES += handeye_algorithm_deployment
|
||||||
|
win32 {
|
||||||
|
CONFIG(debug, debug|release): HAND_EYE_JPEG_PLUGIN = $$[QT_INSTALL_PLUGINS]/imageformats/qjpegd.dll
|
||||||
|
else: HAND_EYE_JPEG_PLUGIN = $$[QT_INSTALL_PLUGINS]/imageformats/qjpeg.dll
|
||||||
|
handeye_image_plugin.files = $$HAND_EYE_JPEG_PLUGIN
|
||||||
|
handeye_image_plugin.path = $$DESTDIR/imageformats
|
||||||
|
COPIES += handeye_image_plugin
|
||||||
|
}
|
||||||
|
DISTFILES += scripts/handeye_worker.py scripts/handeye_math.py scripts/handeye_refinement.py
|
||||||
|
DISTFILES += scripts/package_handeye_runtime.py
|
||||||
|
|
||||||
|
QMAKE_POST_LINK += $$QMAKE_COPY_DIR $$shell_quote($$shell_path($$MODEL_DIR)) $$shell_quote($$shell_path($$DESTDIR/models))
|
||||||
|
|
||||||
|
win32 {
|
||||||
|
isEmpty(HAND_EYE_RUNTIME_DIR): HAND_EYE_RUNTIME_DIR = $$PWD/third_party/handeye-runtime
|
||||||
|
!exists($$HAND_EYE_RUNTIME_DIR/manifest.json): error(Build the bundled runtime with scripts/package_handeye_runtime.py first)
|
||||||
|
QMAKE_POST_LINK += $$escape_expand(\n\t) if not exist $$shell_quote($$shell_path($$DESTDIR/runtime)) $$QMAKE_MKDIR $$shell_quote($$shell_path($$DESTDIR/runtime))
|
||||||
|
QMAKE_POST_LINK += $$escape_expand(\n\t) $$QMAKE_COPY_DIR $$shell_quote($$shell_path($$HAND_EYE_RUNTIME_DIR)) $$shell_quote($$shell_path($$DESTDIR/runtime/handeye))
|
||||||
|
QMAKE_POST_LINK += $$escape_expand(\n\t) $$QMAKE_COPY_FILE $$shell_quote($$shell_path($$MSQUIC_TEST_CERT)) $$shell_quote($$shell_path($$DESTDIR/quic-test-server.pfx))
|
||||||
|
QMAKE_POST_LINK += $$escape_expand(\n\t) $$QMAKE_COPY_FILE $$shell_quote($$shell_path($$MSQUIC_TEST_CA)) $$shell_quote($$shell_path($$DESTDIR/quic-test-ca.crt))
|
||||||
|
}
|
||||||
|
|
||||||
|
win32:RC_ICONS =
|
||||||
1606
feature/styles.qss
Normal file
1606
feature/styles.qss
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,19 +1,21 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "videorenderwidget.h"
|
#include "videorenderwidget.h"
|
||||||
|
|
||||||
#include "agvmapviewwidget.h"
|
|
||||||
#include "audiostreammanager.h"
|
#include "audiostreammanager.h"
|
||||||
#include "configeditorwidget.h"
|
#include "configeditorwidget.h"
|
||||||
#include "robotclient.h"
|
#include "robotclient.h"
|
||||||
#include "quictestserver.h"
|
#include "quictestserver.h"
|
||||||
#include "rpcservicewidget.h"
|
#include "rpcservicewidget.h"
|
||||||
#include "trendwidget.h"
|
#include "trendwidget.h"
|
||||||
|
#include "tcpcalibrationwidget.h"
|
||||||
|
#include "tcpjogcontroller.h"
|
||||||
|
#include "../ui/handeyecalibrationwidget.h"
|
||||||
|
#include "handeyemotionwidget.h"
|
||||||
|
#include "touchoperationwidget.h"
|
||||||
#include "uiicons.h"
|
#include "uiicons.h"
|
||||||
#include "urdfviewerwidget.h"
|
#include "urdfviewerwidget.h"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
|
|
||||||
#include <QAbstractSpinBox>
|
|
||||||
#include <QApplication>
|
|
||||||
#include <QButtonGroup>
|
#include <QButtonGroup>
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
@ -29,7 +31,6 @@
|
|||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QKeyEvent>
|
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QListView>
|
#include <QListView>
|
||||||
@ -37,11 +38,11 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QProgressBar>
|
#include <QProgressBar>
|
||||||
#include <QPlainTextEdit>
|
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QResizeEvent>
|
#include <QResizeEvent>
|
||||||
#include <QScrollArea>
|
#include <QScrollArea>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
#include <QSignalBlocker>
|
||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
#include <QStackedWidget>
|
#include <QStackedWidget>
|
||||||
#include <QStyle>
|
#include <QStyle>
|
||||||
@ -64,7 +65,7 @@ const QStringList kPageTitles = {
|
|||||||
QStringLiteral("HLC 控制"), QStringLiteral("接口调试"),
|
QStringLiteral("HLC 控制"), QStringLiteral("接口调试"),
|
||||||
QStringLiteral("QUIC Server"), QStringLiteral("设备管理"),
|
QStringLiteral("QUIC Server"), QStringLiteral("设备管理"),
|
||||||
QStringLiteral("运行日志"), QStringLiteral("工具坐标标定"),
|
QStringLiteral("运行日志"), QStringLiteral("工具坐标标定"),
|
||||||
QStringLiteral("手眼标定")
|
QStringLiteral("手眼标定"), QStringLiteral("末端操作")
|
||||||
};
|
};
|
||||||
const QStringList kPageSubtitles = {
|
const QStringList kPageSubtitles = {
|
||||||
QStringLiteral("系统信息、运行资源与全局停止"),
|
QStringLiteral("系统信息、运行资源与全局停止"),
|
||||||
@ -81,41 +82,10 @@ const QStringList kPageSubtitles = {
|
|||||||
QStringLiteral("设备清单以及 cmvr_es 项目配置的查看、校验与编辑"),
|
QStringLiteral("设备清单以及 cmvr_es 项目配置的查看、校验与编辑"),
|
||||||
QStringLiteral("检查连接信息与 RPC 执行记录"),
|
QStringLiteral("检查连接信息与 RPC 执行记录"),
|
||||||
QStringLiteral("机械臂工具中心点与工具坐标系标定入口"),
|
QStringLiteral("机械臂工具中心点与工具坐标系标定入口"),
|
||||||
QStringLiteral("相机与机械臂坐标系的手眼标定入口")
|
QStringLiteral("相机与机械臂坐标系的手眼标定入口"),
|
||||||
|
QStringLiteral("视觉取点与触控笔单击、双击、滑动")
|
||||||
};
|
};
|
||||||
|
|
||||||
QWidget *createCalibrationEntryPage(const QString &title, const QString &description,
|
|
||||||
QWidget *parent)
|
|
||||||
{
|
|
||||||
QWidget *page = new QWidget(parent);
|
|
||||||
QVBoxLayout *pageLayout = new QVBoxLayout(page);
|
|
||||||
pageLayout->setContentsMargins(26, 22, 26, 22);
|
|
||||||
|
|
||||||
QFrame *panel = new QFrame(page);
|
|
||||||
panel->setObjectName(QStringLiteral("panel"));
|
|
||||||
QVBoxLayout *panelLayout = new QVBoxLayout(panel);
|
|
||||||
panelLayout->setContentsMargins(24, 22, 24, 22);
|
|
||||||
panelLayout->setSpacing(8);
|
|
||||||
|
|
||||||
QLabel *titleLabel = new QLabel(title, panel);
|
|
||||||
titleLabel->setObjectName(QStringLiteral("sectionTitle"));
|
|
||||||
QLabel *descriptionLabel = new QLabel(description, panel);
|
|
||||||
descriptionLabel->setObjectName(QStringLiteral("mutedLabel"));
|
|
||||||
descriptionLabel->setWordWrap(true);
|
|
||||||
QLabel *stateLabel = new QLabel(
|
|
||||||
QStringLiteral("功能入口已接入侧栏,标定服务接口将在后续版本中接入。"), panel);
|
|
||||||
stateLabel->setObjectName(QStringLiteral("statusChip"));
|
|
||||||
stateLabel->setAlignment(Qt::AlignCenter);
|
|
||||||
stateLabel->setMinimumWidth(320);
|
|
||||||
|
|
||||||
panelLayout->addWidget(titleLabel);
|
|
||||||
panelLayout->addWidget(descriptionLabel);
|
|
||||||
panelLayout->addSpacing(12);
|
|
||||||
panelLayout->addWidget(stateLabel, 0, Qt::AlignLeft);
|
|
||||||
panelLayout->addStretch(1);
|
|
||||||
pageLayout->addWidget(panel);
|
|
||||||
return page;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
@ -295,7 +265,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QPushButton *complexGroupButton = createGroupButton(
|
QPushButton *complexGroupButton = createGroupButton(
|
||||||
QStringLiteral("复杂控制"), grpcContent, 1);
|
QStringLiteral("复杂操作"), grpcContent, 1);
|
||||||
const auto complexSection = createNavContainer(grpcContent);
|
const auto complexSection = createNavContainer(grpcContent);
|
||||||
QWidget *complexContent = complexSection.first;
|
QWidget *complexContent = complexSection.first;
|
||||||
QVBoxLayout *complexLayout = complexSection.second;
|
QVBoxLayout *complexLayout = complexSection.second;
|
||||||
@ -303,10 +273,13 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
QStringLiteral("工具坐标标定"), complexContent, 2);
|
QStringLiteral("工具坐标标定"), complexContent, 2);
|
||||||
QPushButton *handEyeNavButton = createPageButton(
|
QPushButton *handEyeNavButton = createPageButton(
|
||||||
QStringLiteral("手眼标定"), complexContent, 2);
|
QStringLiteral("手眼标定"), complexContent, 2);
|
||||||
|
QPushButton *touchNavButton = createPageButton(
|
||||||
|
QStringLiteral("末端操作"), complexContent, 2);
|
||||||
ui.hlcNavButton->setParent(complexContent);
|
ui.hlcNavButton->setParent(complexContent);
|
||||||
ui.hlcNavButton->setProperty("navLevel", 2);
|
ui.hlcNavButton->setProperty("navLevel", 2);
|
||||||
complexLayout->addWidget(toolCalibrationNavButton);
|
complexLayout->addWidget(toolCalibrationNavButton);
|
||||||
complexLayout->addWidget(handEyeNavButton);
|
complexLayout->addWidget(handEyeNavButton);
|
||||||
|
complexLayout->addWidget(touchNavButton);
|
||||||
complexLayout->addWidget(ui.hlcNavButton);
|
complexLayout->addWidget(ui.hlcNavButton);
|
||||||
|
|
||||||
ui.configurationNavButton->setParent(grpcContent);
|
ui.configurationNavButton->setParent(grpcContent);
|
||||||
@ -338,7 +311,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
ui.agvNavButton, ui.speakerNavButton, ui.microphoneNavButton,
|
ui.agvNavButton, ui.speakerNavButton, ui.microphoneNavButton,
|
||||||
ui.dexhandNavButton, ui.bioheadNavButton, ui.hlcNavButton,
|
ui.dexhandNavButton, ui.bioheadNavButton, ui.hlcNavButton,
|
||||||
ui.testNavButton, ui.quicNavButton, ui.configurationNavButton,
|
ui.testNavButton, ui.quicNavButton, ui.configurationNavButton,
|
||||||
ui.diagnosticsNavButton, toolCalibrationNavButton, handEyeNavButton
|
ui.diagnosticsNavButton, toolCalibrationNavButton, handEyeNavButton, touchNavButton
|
||||||
};
|
};
|
||||||
const QStringList icons = {
|
const QStringList icons = {
|
||||||
QStringLiteral(":/icons/activity.svg"),
|
QStringLiteral(":/icons/activity.svg"),
|
||||||
@ -355,7 +328,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
QStringLiteral(":/icons/folder-open.svg"),
|
QStringLiteral(":/icons/folder-open.svg"),
|
||||||
QStringLiteral(":/icons/scroll-text.svg"),
|
QStringLiteral(":/icons/scroll-text.svg"),
|
||||||
QStringLiteral(":/icons/crosshair.svg"),
|
QStringLiteral(":/icons/crosshair.svg"),
|
||||||
QStringLiteral(":/icons/camera.svg")
|
QStringLiteral(":/icons/camera.svg"), QStringLiteral(":/icons/crosshair.svg")
|
||||||
};
|
};
|
||||||
for (int i = 0; i < m_navButtons.size(); ++i) {
|
for (int i = 0; i < m_navButtons.size(); ++i) {
|
||||||
m_navButtons.at(i)->setIcon(UiIcons::icon(
|
m_navButtons.at(i)->setIcon(UiIcons::icon(
|
||||||
@ -468,14 +441,73 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
selectPage(pageIndex);
|
selectPage(pageIndex);
|
||||||
});
|
});
|
||||||
m_pages->addWidget(createDiagnosticsPage());
|
m_pages->addWidget(createDiagnosticsPage());
|
||||||
m_pages->addWidget(createCalibrationEntryPage(
|
// Fill the existing TCP navigation slot; keep page order and sidebar intact.
|
||||||
QStringLiteral("工具坐标标定"),
|
auto *tcpCalibration = new TcpCalibrationWidget(m_pages);
|
||||||
QStringLiteral("用于建立工具中心点(TCP)及其相对于机械臂末端的坐标变换。"),
|
m_tcpCalibration = tcpCalibration;
|
||||||
m_pages));
|
m_tcpJog = new TcpJogController(this);
|
||||||
m_pages->addWidget(createCalibrationEntryPage(
|
connect(m_tcpJog, &TcpJogController::captureRequested, m_client, &RobotClient::requestTcpCalibrationPose);
|
||||||
QStringLiteral("手眼标定"),
|
connect(m_client, &RobotClient::tcpCalibrationPoseReceived, m_tcpJog, &TcpJogController::acceptPose);
|
||||||
QStringLiteral("用于求解相机坐标系与机械臂基座或末端坐标系之间的变换关系。"),
|
connect(m_tcpJog, &TcpJogController::moveRequested, m_client, &RobotClient::requestTcpJogMove);
|
||||||
m_pages));
|
connect(m_client, &RobotClient::commandFinished, m_tcpJog, &TcpJogController::acceptCommand);
|
||||||
|
connect(m_tcpJog, &TcpJogController::stopRequested, m_client, &RobotClient::requestArmStop);
|
||||||
|
connect(m_tcpJog, &TcpJogController::errorOccurred, this, [this](const QString &error) {
|
||||||
|
appendLog(QStringLiteral("ERROR"), error);
|
||||||
|
QMessageBox::warning(this, QStringLiteral("TCP 点动"), error);
|
||||||
|
});
|
||||||
|
// A global/other stop must invalidate any pending local continuation too.
|
||||||
|
connect(m_client, &RobotClient::armStopRequested, m_tcpJog, &TcpJogController::stop);
|
||||||
|
connect(m_client, &RobotClient::systemStopAllRequested, m_tcpJog, &TcpJogController::stop);
|
||||||
|
connect(tcpCalibration, &TcpCalibrationWidget::referenceChanged, this, [this] {
|
||||||
|
m_tcpJog->setContext(endpoint(), m_armIdEdit->text().trimmed(),
|
||||||
|
m_tcpCalibration->referenceConfirmed(), m_tcpCalibration->activeOffset());
|
||||||
|
});
|
||||||
|
connect(m_client, &RobotClient::tcpReferenceInvalidated, tcpCalibration,
|
||||||
|
[this,tcpCalibration](const QString &device) {
|
||||||
|
if (device.trimmed().isEmpty() || device.trimmed() == m_armIdEdit->text().trimmed())
|
||||||
|
tcpCalibration->invalidateReference();
|
||||||
|
});
|
||||||
|
connect(tcpCalibration, &TcpCalibrationWidget::toolsChanged, this,
|
||||||
|
[this](const QString &host, const QString &device, const QString &name) {
|
||||||
|
if (host != endpoint() || device != m_armIdEdit->text().trimmed()) return;
|
||||||
|
m_tcpJog->stop();
|
||||||
|
refreshTcpChoices(name);
|
||||||
|
});
|
||||||
|
m_pages->addWidget(tcpCalibration);
|
||||||
|
connect(tcpCalibration, &TcpCalibrationWidget::captureRequested,
|
||||||
|
m_client, &RobotClient::requestTcpCalibrationPose);
|
||||||
|
connect(m_client, &RobotClient::tcpCalibrationPoseReceived,
|
||||||
|
tcpCalibration, &TcpCalibrationWidget::acceptPose);
|
||||||
|
connect(tcpCalibration, &TcpCalibrationWidget::logMessage,
|
||||||
|
this, &MainWindow::appendLog);
|
||||||
|
const auto syncTcpContext = [this, tcpCalibration]() {
|
||||||
|
tcpCalibration->setContext(endpoint(), m_armIdEdit->text().trimmed(),
|
||||||
|
m_connected, m_demoCheck->isChecked());
|
||||||
|
refreshTcpChoices();
|
||||||
|
};
|
||||||
|
connect(m_armIdEdit, &QLineEdit::textChanged, tcpCalibration,
|
||||||
|
[syncTcpContext](const QString &) { syncTcpContext(); });
|
||||||
|
connect(m_hostEdit, &QLineEdit::textChanged, tcpCalibration,
|
||||||
|
[syncTcpContext](const QString &) { syncTcpContext(); });
|
||||||
|
connect(m_portSpin, QOverload<int>::of(&QSpinBox::valueChanged), tcpCalibration,
|
||||||
|
[syncTcpContext](int) { syncTcpContext(); });
|
||||||
|
connect(m_demoCheck, &QCheckBox::toggled, tcpCalibration,
|
||||||
|
[syncTcpContext](bool) { syncTcpContext(); });
|
||||||
|
connect(m_client, &RobotClient::connectionChanged, tcpCalibration,
|
||||||
|
[this, tcpCalibration](bool connected, int, const QString &) {
|
||||||
|
tcpCalibration->setContext(endpoint(), m_armIdEdit->text().trimmed(),
|
||||||
|
connected, m_demoCheck->isChecked());
|
||||||
|
if (!connected) m_controllerTcpFrames.clear();
|
||||||
|
refreshTcpChoices();
|
||||||
|
});
|
||||||
|
// Invalidate in-flight captures immediately, before the worker processes disconnect.
|
||||||
|
connect(m_client, &RobotClient::disconnectRequested, tcpCalibration,
|
||||||
|
[this, tcpCalibration]() {
|
||||||
|
tcpCalibration->setContext(endpoint(), m_armIdEdit->text().trimmed(),
|
||||||
|
false, m_demoCheck->isChecked());
|
||||||
|
});
|
||||||
|
syncTcpContext();
|
||||||
|
setupHandEye();
|
||||||
|
setupTouchOperation();
|
||||||
|
|
||||||
const QString comboPopupStyle = QStringLiteral(
|
const QString comboPopupStyle = QStringLiteral(
|
||||||
"QListView {"
|
"QListView {"
|
||||||
@ -520,22 +552,15 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
connect(m_client, &RobotClient::agvStateReceived, this, &MainWindow::updateAgvState);
|
connect(m_client, &RobotClient::agvStateReceived, this, &MainWindow::updateAgvState);
|
||||||
connect(m_client, &RobotClient::agvInventoryReceived, this, &MainWindow::updateAgvInventory);
|
connect(m_client, &RobotClient::agvInventoryReceived, this, &MainWindow::updateAgvInventory);
|
||||||
connect(m_client, &RobotClient::agvMapFrameReceived, this,
|
connect(m_client, &RobotClient::agvMapFrameReceived, this,
|
||||||
[this](const QImage &image, const QVariantMap &metadata,
|
[this](const QImage &image, const QString &detail) {
|
||||||
const QString &detail) {
|
m_agvMappingPreview->setText(QString());
|
||||||
if (m_agvMapView) {
|
m_agvMappingPreview->setPixmap(QPixmap::fromImage(image).scaled(
|
||||||
m_agvMapView->setMapFrame(image, metadata);
|
m_agvMappingPreview->size(), Qt::KeepAspectRatio,
|
||||||
m_agvMapView->setStreamMessage(detail);
|
Qt::SmoothTransformation));
|
||||||
}
|
m_agvMappingStateLabel->setText(detail);
|
||||||
if (m_agvMappingStateLabel)
|
|
||||||
m_agvMappingStateLabel->setText(detail);
|
|
||||||
});
|
});
|
||||||
connect(m_client, &RobotClient::agvMapStreamStateChanged, this,
|
connect(m_client, &RobotClient::agvMapStreamStateChanged, this,
|
||||||
[this](bool running, const QString &detail) {
|
[this](bool running, const QString &detail) {
|
||||||
m_agvMapStreamActive = running;
|
|
||||||
if (m_agvMapView)
|
|
||||||
m_agvMapView->setStreamMessage(detail);
|
|
||||||
if (!m_agvMappingStateLabel)
|
|
||||||
return;
|
|
||||||
m_agvMappingStateLabel->setProperty("running", running);
|
m_agvMappingStateLabel->setProperty("running", running);
|
||||||
m_agvMappingStateLabel->setText(detail);
|
m_agvMappingStateLabel->setText(detail);
|
||||||
m_agvMappingStateLabel->style()->unpolish(m_agvMappingStateLabel);
|
m_agvMappingStateLabel->style()->unpolish(m_agvMappingStateLabel);
|
||||||
@ -593,7 +618,6 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
}
|
}
|
||||||
selectPage(initialPage);
|
selectPage(initialPage);
|
||||||
setControlsEnabled(false);
|
setControlsEnabled(false);
|
||||||
qApp->installEventFilter(this);
|
|
||||||
appendLog(QStringLiteral("INFO"), QStringLiteral("CMVR 控制台已启动"));
|
appendLog(QStringLiteral("INFO"), QStringLiteral("CMVR 控制台已启动"));
|
||||||
appendLog(QStringLiteral("INFO"), m_client->grpcAvailable()
|
appendLog(QStringLiteral("INFO"), m_client->grpcAvailable()
|
||||||
? QStringLiteral("原生 gRPC 后端可用")
|
? QStringLiteral("原生 gRPC 后端可用")
|
||||||
@ -608,10 +632,8 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
{
|
{
|
||||||
qApp->removeEventFilter(this);
|
if (m_touchOperation) m_touchOperation->stop();
|
||||||
stopAgvManualMotion(false);
|
if (m_tcpJog) m_tcpJog->stop();
|
||||||
if (m_client)
|
|
||||||
m_client->stopAgvMapStream();
|
|
||||||
m_audioManager->stopSource();
|
m_audioManager->stopSource();
|
||||||
m_audioManager->stopPlayback();
|
m_audioManager->stopPlayback();
|
||||||
m_client->stopSpeakerAudioStream();
|
m_client->stopSpeakerAudioStream();
|
||||||
@ -689,77 +711,11 @@ bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *r
|
|||||||
return QMainWindow::nativeEvent(eventType, message, result);
|
return QMainWindow::nativeEvent(eventType, message, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MainWindow::eventFilter(QObject *watched, QEvent *event)
|
|
||||||
{
|
|
||||||
if (event && (event->type() == QEvent::WindowDeactivate
|
|
||||||
|| event->type() == QEvent::ApplicationDeactivate)) {
|
|
||||||
stopAgvManualMotion();
|
|
||||||
}
|
|
||||||
|
|
||||||
const bool agvControlVisible = m_connected && m_pages
|
|
||||||
&& m_pages->currentIndex() == 3 && m_agvControlWorkspace
|
|
||||||
&& m_agvControlWorkspace->isVisible();
|
|
||||||
if (!event || !agvControlVisible
|
|
||||||
|| (event->type() != QEvent::KeyPress
|
|
||||||
&& event->type() != QEvent::KeyRelease)) {
|
|
||||||
return QMainWindow::eventFilter(watched, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
QWidget *focus = QApplication::focusWidget();
|
|
||||||
if (qobject_cast<QLineEdit *>(focus)
|
|
||||||
|| qobject_cast<QAbstractSpinBox *>(focus)
|
|
||||||
|| qobject_cast<QTextEdit *>(focus)
|
|
||||||
|| qobject_cast<QPlainTextEdit *>(focus)) {
|
|
||||||
return QMainWindow::eventFilter(watched, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
|
||||||
if (keyEvent->isAutoRepeat()
|
|
||||||
|| (keyEvent->modifiers() & (Qt::ControlModifier | Qt::AltModifier
|
|
||||||
| Qt::MetaModifier))) {
|
|
||||||
return QMainWindow::eventFilter(watched, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
double vx = 0.0;
|
|
||||||
double vy = 0.0;
|
|
||||||
double wz = 0.0;
|
|
||||||
bool directionKey = true;
|
|
||||||
switch (keyEvent->key()) {
|
|
||||||
case Qt::Key_W:
|
|
||||||
vx = qAbs(m_agvVxSpin->value());
|
|
||||||
break;
|
|
||||||
case Qt::Key_S:
|
|
||||||
vx = -qAbs(m_agvVxSpin->value());
|
|
||||||
break;
|
|
||||||
case Qt::Key_A:
|
|
||||||
vy = qAbs(m_agvVySpin->value());
|
|
||||||
break;
|
|
||||||
case Qt::Key_D:
|
|
||||||
vy = -qAbs(m_agvVySpin->value());
|
|
||||||
break;
|
|
||||||
case Qt::Key_Q:
|
|
||||||
wz = qAbs(m_agvWzSpin->value());
|
|
||||||
break;
|
|
||||||
case Qt::Key_E:
|
|
||||||
wz = -qAbs(m_agvWzSpin->value());
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
directionKey = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (!directionKey)
|
|
||||||
return QMainWindow::eventFilter(watched, event);
|
|
||||||
|
|
||||||
if (event->type() == QEvent::KeyPress)
|
|
||||||
startAgvManualMotion(vx, vy, wz);
|
|
||||||
else
|
|
||||||
stopAgvManualMotion();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::changeEvent(QEvent *event)
|
void MainWindow::changeEvent(QEvent *event)
|
||||||
{
|
{
|
||||||
QMainWindow::changeEvent(event);
|
QMainWindow::changeEvent(event);
|
||||||
|
if (event && event->type() == QEvent::ActivationChange && !isActiveWindow() && m_tcpJog)
|
||||||
|
m_tcpJog->stop();
|
||||||
if (event && event->type() == QEvent::WindowStateChange)
|
if (event && event->type() == QEvent::WindowStateChange)
|
||||||
updateWindowChrome();
|
updateWindowChrome();
|
||||||
}
|
}
|
||||||
@ -879,38 +835,12 @@ void MainWindow::appendQuicLog(const QString &level, const QString &message)
|
|||||||
.arg(timestamp, color, level, message.toHtmlEscaped()));
|
.arg(timestamp, color, level, message.toHtmlEscaped()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::setArmTelemetryEnabled(bool enabled)
|
|
||||||
{
|
|
||||||
if (!m_armTelemetryButton || !m_client || !m_armIdEdit)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const QString deviceId = m_armIdEdit->text().trimmed();
|
|
||||||
const bool shouldEnable = enabled && m_connected && !deviceId.isEmpty();
|
|
||||||
m_armTelemetryButton->setChecked(shouldEnable);
|
|
||||||
m_armTelemetryButton->setText(
|
|
||||||
shouldEnable ? QStringLiteral("遥测 10 Hz")
|
|
||||||
: QStringLiteral("遥测 未启动"));
|
|
||||||
m_armTelemetryButton->setProperty("active", shouldEnable);
|
|
||||||
m_armTelemetryButton->style()->unpolish(m_armTelemetryButton);
|
|
||||||
m_armTelemetryButton->style()->polish(m_armTelemetryButton);
|
|
||||||
if (m_armSideCombo)
|
|
||||||
m_armSideCombo->setEnabled(true);
|
|
||||||
|
|
||||||
if (shouldEnable) {
|
|
||||||
m_client->requestArmInfo(deviceId);
|
|
||||||
m_client->requestArmFrames(deviceId);
|
|
||||||
}
|
|
||||||
m_client->setArmTelemetry(deviceId, shouldEnable);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::selectPage(int index)
|
void MainWindow::selectPage(int index)
|
||||||
{
|
{
|
||||||
if (!m_pages || index < 0 || index >= kPageTitles.size())
|
if (!m_pages || index < 0 || index >= kPageTitles.size())
|
||||||
return;
|
return;
|
||||||
const int previousIndex = m_pages->currentIndex();
|
if (index != 1 && m_tcpJog) m_tcpJog->stop();
|
||||||
if (previousIndex == 1 && index != 1)
|
if (index != 15 && m_touchOperation) m_touchOperation->stop();
|
||||||
setArmTelemetryEnabled(false);
|
|
||||||
m_pages->setCurrentIndex(index);
|
m_pages->setCurrentIndex(index);
|
||||||
m_pageTitle->setText(kPageTitles.at(index));
|
m_pageTitle->setText(kPageTitles.at(index));
|
||||||
m_pageSubtitle->setText(kPageSubtitles.at(index));
|
m_pageSubtitle->setText(kPageSubtitles.at(index));
|
||||||
@ -920,67 +850,12 @@ void MainWindow::selectPage(int index)
|
|||||||
m_armHeaderControls->setVisible(index == 1);
|
m_armHeaderControls->setVisible(index == 1);
|
||||||
if (index == 1)
|
if (index == 1)
|
||||||
ensureArmModelLoaded();
|
ensureArmModelLoaded();
|
||||||
if (index == 1 && previousIndex != 1 && m_connected)
|
if (index != 3 && m_agvStatusSwitch && m_agvStatusSwitch->isChecked())
|
||||||
setArmTelemetryEnabled(true);
|
m_agvStatusSwitch->setChecked(false);
|
||||||
if (index != 3) {
|
|
||||||
stopAgvManualMotion();
|
|
||||||
if (m_agvStatusRefreshTimer)
|
|
||||||
m_agvStatusRefreshTimer->stop();
|
|
||||||
if (m_agvMapStreamActive) {
|
|
||||||
m_client->stopAgvMapStream();
|
|
||||||
m_agvMapStreamActive = false;
|
|
||||||
}
|
|
||||||
} else if (m_connected) {
|
|
||||||
m_client->requestAgvRefresh(m_agvIdEdit->text().trimmed());
|
|
||||||
m_client->requestAgvInventory(m_agvIdEdit->text().trimmed());
|
|
||||||
m_agvStatusRefreshTimer->start();
|
|
||||||
restartAgvMapStream();
|
|
||||||
}
|
|
||||||
if (index < m_navButtons.size())
|
if (index < m_navButtons.size())
|
||||||
m_navButtons.at(index)->setChecked(true);
|
m_navButtons.at(index)->setChecked(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::startAgvManualMotion(double vx, double vy, double wz)
|
|
||||||
{
|
|
||||||
if (!m_connected || !m_client || !m_agvIdEdit
|
|
||||||
|| m_agvIdEdit->text().trimmed().isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_agvManualVx = vx;
|
|
||||||
m_agvManualVy = vy;
|
|
||||||
m_agvManualWz = wz;
|
|
||||||
m_agvManualMotionActive = true;
|
|
||||||
m_client->requestAgvVelocity(m_agvIdEdit->text().trimmed(), vx, vy, wz);
|
|
||||||
if (m_agvManualVelocityTimer && !m_agvManualVelocityTimer->isActive())
|
|
||||||
m_agvManualVelocityTimer->start();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::stopAgvManualMotion(bool sendStop)
|
|
||||||
{
|
|
||||||
const bool wasActive = m_agvManualMotionActive;
|
|
||||||
m_agvManualMotionActive = false;
|
|
||||||
if (m_agvManualVelocityTimer)
|
|
||||||
m_agvManualVelocityTimer->stop();
|
|
||||||
if (sendStop && wasActive && m_connected && m_client && m_agvIdEdit
|
|
||||||
&& !m_agvIdEdit->text().trimmed().isEmpty()) {
|
|
||||||
m_client->requestAgvAction(m_agvIdEdit->text().trimmed(),
|
|
||||||
QStringLiteral("StopVelocity"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::restartAgvMapStream(const QString &mapName)
|
|
||||||
{
|
|
||||||
if (!m_connected || !m_client || !m_agvIdEdit
|
|
||||||
|| m_agvIdEdit->text().trimmed().isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const QString selectedMap = mapName.trimmed().isEmpty() && m_agvMapCombo
|
|
||||||
? m_agvMapCombo->currentText().trimmed() : mapName.trimmed();
|
|
||||||
m_client->stopAgvMapStream();
|
|
||||||
m_client->startAgvMapStream(m_agvIdEdit->text().trimmed(), selectedMap,
|
|
||||||
1, true, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::ensureArmModelLoaded()
|
void MainWindow::ensureArmModelLoaded()
|
||||||
{
|
{
|
||||||
if (!m_urdfViewer || m_pendingUrdfPath.isEmpty()
|
if (!m_urdfViewer || m_pendingUrdfPath.isEmpty()
|
||||||
@ -1005,6 +880,7 @@ void MainWindow::ensureArmModelLoaded()
|
|||||||
void MainWindow::toggleConnection()
|
void MainWindow::toggleConnection()
|
||||||
{
|
{
|
||||||
if (m_connected) {
|
if (m_connected) {
|
||||||
|
if (m_tcpJog) m_tcpJog->stop();
|
||||||
m_connectButton->setEnabled(false);
|
m_connectButton->setEnabled(false);
|
||||||
m_connectButton->setText(QStringLiteral("正在断开…"));
|
m_connectButton->setText(QStringLiteral("正在断开…"));
|
||||||
m_client->disconnectFromServer();
|
m_client->disconnectFromServer();
|
||||||
@ -1016,6 +892,11 @@ void MainWindow::toggleConnection()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
saveSettings();
|
saveSettings();
|
||||||
|
// Freeze the endpoint while the worker connects so TCP records retain
|
||||||
|
// the identity of the server that actually owns the feedback.
|
||||||
|
m_hostEdit->setEnabled(false);
|
||||||
|
m_portSpin->setEnabled(false);
|
||||||
|
m_demoCheck->setEnabled(false);
|
||||||
m_connectButton->setEnabled(false);
|
m_connectButton->setEnabled(false);
|
||||||
m_connectButton->setText(QStringLiteral("正在连接…"));
|
m_connectButton->setText(QStringLiteral("正在连接…"));
|
||||||
m_connectionText->setText(QStringLiteral("连接中"));
|
m_connectionText->setText(QStringLiteral("连接中"));
|
||||||
@ -1046,24 +927,16 @@ void MainWindow::updateConnection(bool connected, int latencyMs, const QString &
|
|||||||
state->style()->polish(state);
|
state->style()->polish(state);
|
||||||
}
|
}
|
||||||
setControlsEnabled(connected);
|
setControlsEnabled(connected);
|
||||||
if (connected && m_pages && m_pages->currentIndex() == 1)
|
if (m_agvStatusRefreshTimer && m_agvStatusSwitch
|
||||||
setArmTelemetryEnabled(true);
|
&& m_agvStatusSwitch->isChecked()) {
|
||||||
if (m_agvStatusRefreshTimer) {
|
if (connected) {
|
||||||
if (connected && m_pages && m_pages->currentIndex() == 3) {
|
|
||||||
m_client->requestAgvRefresh(m_agvIdEdit->text().trimmed());
|
m_client->requestAgvRefresh(m_agvIdEdit->text().trimmed());
|
||||||
m_client->requestAgvInventory(m_agvIdEdit->text().trimmed());
|
|
||||||
m_agvStatusRefreshTimer->start();
|
m_agvStatusRefreshTimer->start();
|
||||||
restartAgvMapStream();
|
|
||||||
} else {
|
} else {
|
||||||
m_agvStatusRefreshTimer->stop();
|
m_agvStatusRefreshTimer->stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!connected) {
|
if (!connected) {
|
||||||
stopAgvManualMotion(false);
|
|
||||||
m_client->stopAgvMapStream();
|
|
||||||
m_agvMapStreamActive = false;
|
|
||||||
if (m_agvMapView)
|
|
||||||
m_agvMapView->setStreamMessage(QStringLiteral("连接已断开"));
|
|
||||||
m_audioManager->stopSource();
|
m_audioManager->stopSource();
|
||||||
m_audioManager->stopPlayback();
|
m_audioManager->stopPlayback();
|
||||||
m_runningCameraIds.clear();
|
m_runningCameraIds.clear();
|
||||||
@ -1073,8 +946,15 @@ void MainWindow::updateConnection(bool connected, int latencyMs, const QString &
|
|||||||
}
|
}
|
||||||
refreshCameraStreamControls();
|
refreshCameraStreamControls();
|
||||||
}
|
}
|
||||||
if (!connected && m_armTelemetryButton)
|
if (!connected && m_armTelemetryButton) {
|
||||||
setArmTelemetryEnabled(false);
|
m_armTelemetryButton->setChecked(false);
|
||||||
|
m_armTelemetryButton->setText(QStringLiteral("遥测 未启动"));
|
||||||
|
m_armTelemetryButton->setProperty("active", false);
|
||||||
|
m_armTelemetryButton->style()->unpolish(m_armTelemetryButton);
|
||||||
|
m_armTelemetryButton->style()->polish(m_armTelemetryButton);
|
||||||
|
if (m_armSideCombo)
|
||||||
|
m_armSideCombo->setEnabled(true);
|
||||||
|
}
|
||||||
if (!connected) {
|
if (!connected) {
|
||||||
m_armAlertStates.clear();
|
m_armAlertStates.clear();
|
||||||
const QList<QLabel *> armStates = {m_servoStatusValue, m_faultStatusValue};
|
const QList<QLabel *> armStates = {m_servoStatusValue, m_faultStatusValue};
|
||||||
@ -1181,6 +1061,8 @@ void MainWindow::rebuildArmJogControls()
|
|||||||
|
|
||||||
void MainWindow::startJointJog(int jointIndex, int direction)
|
void MainWindow::startJointJog(int jointIndex, int direction)
|
||||||
{
|
{
|
||||||
|
if (m_touchOperation && m_touchOperation->running()) { m_touchOperation->stop(); return; }
|
||||||
|
if (m_tcpJog && m_tcpJog->running()) { m_tcpJog->stop(); return; }
|
||||||
if (!m_connected || !m_jogSpeedSlider || jointIndex < 0
|
if (!m_connected || !m_jogSpeedSlider || jointIndex < 0
|
||||||
|| jointIndex >= m_activeArmJointNames.size()) {
|
|| jointIndex >= m_activeArmJointNames.size()) {
|
||||||
return;
|
return;
|
||||||
@ -1197,6 +1079,7 @@ void MainWindow::startJointJog(int jointIndex, int direction)
|
|||||||
|
|
||||||
void MainWindow::startCartesianJog(int axisIndex, int direction)
|
void MainWindow::startCartesianJog(int axisIndex, int direction)
|
||||||
{
|
{
|
||||||
|
if (m_touchOperation && m_touchOperation->running()) { m_touchOperation->stop(); return; }
|
||||||
if (!m_connected || !m_jogSpeedSlider || axisIndex < 0 || axisIndex >= 6)
|
if (!m_connected || !m_jogSpeedSlider || axisIndex < 0 || axisIndex >= 6)
|
||||||
return;
|
return;
|
||||||
static const QStringList keys = {
|
static const QStringList keys = {
|
||||||
@ -1209,6 +1092,15 @@ void MainWindow::startCartesianJog(int axisIndex, int direction)
|
|||||||
const double ratio = m_jogSpeedSlider->value() / 100.0;
|
const double ratio = m_jogSpeedSlider->value() / 100.0;
|
||||||
const double maximumVelocity = m_cartesianVelocitySpin
|
const double maximumVelocity = m_cartesianVelocitySpin
|
||||||
? m_cartesianVelocitySpin->value() : 0.25;
|
? m_cartesianVelocitySpin->value() : 0.25;
|
||||||
|
if (selectedLocalTcp()) {
|
||||||
|
TcpCalibration::Pose offset{};
|
||||||
|
const auto values = m_tcpFrameCombo->currentData(Qt::UserRole + 1).toList();
|
||||||
|
if (values.size() != 6 || !m_tcpJog) return;
|
||||||
|
for (int i=0;i<6;++i) offset[size_t(i)] = values.at(i).toDouble();
|
||||||
|
m_tcpJog->start(offset, axisIndex, direction, maximumVelocity * ratio,
|
||||||
|
m_cartesianAccelerationSpin ? m_cartesianAccelerationSpin->value() : .5);
|
||||||
|
return;
|
||||||
|
}
|
||||||
velocity.insert(keys.at(axisIndex),
|
velocity.insert(keys.at(axisIndex),
|
||||||
direction * maximumVelocity * ratio);
|
direction * maximumVelocity * ratio);
|
||||||
m_armJogActive = true;
|
m_armJogActive = true;
|
||||||
@ -1222,12 +1114,202 @@ void MainWindow::startCartesianJog(int axisIndex, int direction)
|
|||||||
|
|
||||||
void MainWindow::stopArmJog()
|
void MainWindow::stopArmJog()
|
||||||
{
|
{
|
||||||
|
if (m_touchOperation && m_touchOperation->running()) { m_touchOperation->stop(); return; }
|
||||||
|
if (m_tcpJog && m_tcpJog->running()) { m_tcpJog->stop(); return; }
|
||||||
if (!m_connected || !m_armIdEdit)
|
if (!m_connected || !m_armIdEdit)
|
||||||
return;
|
return;
|
||||||
m_armJogActive = false;
|
m_armJogActive = false;
|
||||||
m_client->requestArmStop(m_armIdEdit->text().trimmed());
|
m_client->requestArmStop(m_armIdEdit->text().trimmed());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::syncHandEyeContext()
|
||||||
|
{
|
||||||
|
if (!m_handEye || !m_handEyeMotion || !m_tcpCalibration) return;
|
||||||
|
const QString device=m_armIdEdit->text().trimmed();
|
||||||
|
const bool reference=m_tcpCalibration->referenceConfirmed();
|
||||||
|
const auto offset=m_tcpCalibration->activeOffset();
|
||||||
|
m_handEye->setContext(endpoint(),device,m_connected,m_demoCheck->isChecked(),reference,offset);
|
||||||
|
m_handEye->setCameraIds(configuredCameraIds());
|
||||||
|
m_handEyeMotion->setContext(endpoint(),device,m_connected,m_demoCheck->isChecked(),reference,offset);
|
||||||
|
if (m_touchOperation) m_touchOperation->setContext(endpoint(),device,m_connected,m_demoCheck->isChecked(),reference,offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::setupTouchOperation()
|
||||||
|
{
|
||||||
|
m_touchOperation=new TouchOperationWidget(m_pages);
|
||||||
|
m_pages->addWidget(m_touchOperation);
|
||||||
|
connect(m_touchOperation,&TouchOperationWidget::captureRequested,m_client,&RobotClient::requestTcpCalibrationPose);
|
||||||
|
connect(m_touchOperation,&TouchOperationWidget::imageRequested,m_client,&RobotClient::requestTouchRgbdImage);
|
||||||
|
connect(m_touchOperation,&TouchOperationWidget::moveRequested,m_client,&RobotClient::requestTcpJogMove);
|
||||||
|
connect(m_touchOperation,&TouchOperationWidget::stopRequested,m_client,&RobotClient::requestArmStop);
|
||||||
|
connect(m_touchOperation,&TouchOperationWidget::logMessage,this,&MainWindow::appendLog);
|
||||||
|
connect(m_client,&RobotClient::tcpCalibrationPoseReceived,m_touchOperation,&TouchOperationWidget::acceptPose);
|
||||||
|
connect(m_client,&RobotClient::touchRgbdImageReceived,m_touchOperation,&TouchOperationWidget::acceptImage);
|
||||||
|
connect(m_client,&RobotClient::videoFrameReceived,m_touchOperation,&TouchOperationWidget::acceptFrame);
|
||||||
|
connect(m_client,&RobotClient::cameraStreamStateChanged,m_touchOperation,&TouchOperationWidget::acceptStreamState);
|
||||||
|
connect(m_client,&RobotClient::commandFinished,m_touchOperation,&TouchOperationWidget::acceptCommand);
|
||||||
|
connect(m_client,&RobotClient::tcpReferenceInvalidated,m_touchOperation,[this] { m_touchOperation->stop(); });
|
||||||
|
connect(m_client,&RobotClient::armCommandStarting,m_touchOperation,[this](const QString &device) {
|
||||||
|
if(device.trimmed().isEmpty()||device.trimmed()==m_armIdEdit->text().trimmed()) m_touchOperation->stop();
|
||||||
|
});
|
||||||
|
connect(m_client,&RobotClient::armStopRequested,m_touchOperation,&TouchOperationWidget::stop);
|
||||||
|
connect(m_client,&RobotClient::systemStopAllRequested,m_touchOperation,&TouchOperationWidget::stop);
|
||||||
|
connect(m_client,&RobotClient::connectionChanged,m_touchOperation,[this](bool connected,int,const QString &) {
|
||||||
|
m_touchOperation->setContext(endpoint(),m_armIdEdit->text().trimmed(),connected,m_demoCheck->isChecked(),m_tcpCalibration->referenceConfirmed(),m_tcpCalibration->activeOffset());
|
||||||
|
});
|
||||||
|
connect(m_client,&RobotClient::disconnectRequested,m_touchOperation,[this] {
|
||||||
|
m_touchOperation->setContext(endpoint(),m_armIdEdit->text().trimmed(),false,m_demoCheck->isChecked(),false,{});
|
||||||
|
});
|
||||||
|
connect(m_touchOperation,&TouchOperationWidget::previewRequested,this,[this](const QString &camera,bool start) {
|
||||||
|
if(start) {
|
||||||
|
if(m_runningCameraIds.contains(camera)||m_touchOwnedCamera==camera) return;
|
||||||
|
m_touchOwnedCamera=camera;
|
||||||
|
m_client->startCameraStream(camera,m_cameraCodecCombo->currentIndex()==1?QStringLiteral("h265"):QStringLiteral("h264"),QStringLiteral("rgb"));
|
||||||
|
} else if(m_touchOwnedCamera==camera) { m_touchOwnedCamera.clear(); m_client->stopCameraStream(camera); }
|
||||||
|
});
|
||||||
|
connect(m_client,&RobotClient::cameraStreamStateChanged,this,[this](const QString &camera,bool running,const QString &) {
|
||||||
|
if(!running&&m_touchOwnedCamera==camera) m_touchOwnedCamera.clear();
|
||||||
|
});
|
||||||
|
auto changed=[this](const QString &host,const QString &device,const QString &) {
|
||||||
|
if(host==endpoint()&&device==m_armIdEdit->text().trimmed()) m_touchOperation->reloadCalibrations();
|
||||||
|
};
|
||||||
|
connect(m_handEye,&HandEyeCalibrationWidget::calibrationsChanged,m_touchOperation,changed);
|
||||||
|
connect(m_tcpCalibration,&TcpCalibrationWidget::toolsChanged,m_touchOperation,changed);
|
||||||
|
syncHandEyeContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::setupHandEye()
|
||||||
|
{
|
||||||
|
m_handEye=new HandEyeCalibrationWidget(m_pages);
|
||||||
|
m_pages->addWidget(m_handEye);
|
||||||
|
connect(m_handEye,&HandEyeCalibrationWidget::captureRequested,m_client,&RobotClient::requestTcpCalibrationPose);
|
||||||
|
connect(m_handEyeMotion,&HandEyeMotionWidget::captureRequested,m_client,&RobotClient::requestTcpCalibrationPose);
|
||||||
|
connect(m_client,&RobotClient::tcpCalibrationPoseReceived,m_handEye,&HandEyeCalibrationWidget::acceptPose);
|
||||||
|
connect(m_client,&RobotClient::tcpCalibrationPoseReceived,m_handEyeMotion,&HandEyeMotionWidget::acceptPose);
|
||||||
|
connect(m_handEye,&HandEyeCalibrationWidget::imageRequested,m_client,&RobotClient::requestHandEyeImage);
|
||||||
|
connect(m_client,&RobotClient::handEyeImageReceived,m_handEye,&HandEyeCalibrationWidget::acceptImage);
|
||||||
|
connect(m_client,&RobotClient::videoFrameReceived,m_handEye,&HandEyeCalibrationWidget::acceptFrame);
|
||||||
|
connect(m_client,&RobotClient::cameraStreamStateChanged,m_handEye,&HandEyeCalibrationWidget::acceptStreamState);
|
||||||
|
connect(m_handEye,&HandEyeCalibrationWidget::logMessage,this,&MainWindow::appendLog);
|
||||||
|
connect(m_handEyeMotion,&HandEyeMotionWidget::logMessage,this,&MainWindow::appendLog);
|
||||||
|
connect(m_handEyeMotion,&HandEyeMotionWidget::currentUrdfRequested,this,[this] {
|
||||||
|
if (m_urdfViewer) m_handEyeMotion->setUrdfFile(m_urdfViewer->currentFile());
|
||||||
|
});
|
||||||
|
connect(m_handEyeMotion,&HandEyeMotionWidget::urdfUpdated,this,
|
||||||
|
[this](const QString &host,const QString &device,const QString &path) {
|
||||||
|
if (host!=endpoint() || device!=m_armIdEdit->text().trimmed() || !m_urdfViewer) return;
|
||||||
|
const QString previous=m_urdfViewer->currentFile();
|
||||||
|
if (m_urdfViewer->loadUrdf(path)) {
|
||||||
|
m_pendingUrdfPath=path;
|
||||||
|
appendLog(QStringLiteral("OK"),QStringLiteral("标定 URDF 已加载:%1").arg(path));
|
||||||
|
} else {
|
||||||
|
if (!previous.isEmpty()) m_urdfViewer->loadUrdf(previous);
|
||||||
|
QMessageBox::warning(this,QStringLiteral("URDF 更新"),QStringLiteral("文件已导出,但模型加载失败。请检查网格资源路径。"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
connect(m_handEye,&HandEyeCalibrationWidget::previewRequested,this,[this](const QString &camera,bool start) {
|
||||||
|
if (start) {
|
||||||
|
// Borrow an existing session. Only a stream started for this page
|
||||||
|
// is stopped when its preview closes; no duplicate camera client.
|
||||||
|
if (m_runningCameraIds.contains(camera) || m_handEyeOwnedCamera==camera) return;
|
||||||
|
m_handEyeOwnedCamera=camera;
|
||||||
|
m_client->startCameraStream(camera,m_cameraCodecCombo->currentIndex()==1 ? QStringLiteral("h265") : QStringLiteral("h264"),QStringLiteral("rgb"));
|
||||||
|
} else if (m_handEyeOwnedCamera==camera) {
|
||||||
|
m_handEyeOwnedCamera.clear(); m_client->stopCameraStream(camera);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
connect(m_client,&RobotClient::cameraStreamStateChanged,this,[this](const QString &camera,bool running,const QString &) {
|
||||||
|
if (!running && m_handEyeOwnedCamera==camera) m_handEyeOwnedCamera.clear();
|
||||||
|
});
|
||||||
|
connect(m_handEye,&HandEyeCalibrationWidget::calibrationsChanged,this,[this](const QString &host,const QString &device,const QString &name) {
|
||||||
|
if (host==endpoint() && device==m_armIdEdit->text().trimmed()) m_handEyeMotion->reload(name);
|
||||||
|
});
|
||||||
|
connect(m_armIdEdit,&QLineEdit::textChanged,this,[this] { syncHandEyeContext(); });
|
||||||
|
connect(m_hostEdit,&QLineEdit::textChanged,this,[this] { syncHandEyeContext(); });
|
||||||
|
connect(m_portSpin,QOverload<int>::of(&QSpinBox::valueChanged),this,[this] { syncHandEyeContext(); });
|
||||||
|
connect(m_cameraIdEdit,&QLineEdit::textChanged,this,[this] { syncHandEyeContext(); });
|
||||||
|
connect(m_demoCheck,&QCheckBox::toggled,this,[this] { syncHandEyeContext(); });
|
||||||
|
connect(m_tcpCalibration,&TcpCalibrationWidget::referenceChanged,this,&MainWindow::syncHandEyeContext);
|
||||||
|
connect(m_client,&RobotClient::connectionChanged,this,[this](bool connected,int,const QString &) {
|
||||||
|
const QString device=m_armIdEdit->text().trimmed();
|
||||||
|
m_handEye->setContext(endpoint(),device,connected,m_demoCheck->isChecked(),m_tcpCalibration->referenceConfirmed(),m_tcpCalibration->activeOffset());
|
||||||
|
m_handEyeMotion->setContext(endpoint(),device,connected,m_demoCheck->isChecked(),m_tcpCalibration->referenceConfirmed(),m_tcpCalibration->activeOffset());
|
||||||
|
});
|
||||||
|
connect(m_client,&RobotClient::disconnectRequested,this,[this] {
|
||||||
|
const QString device=m_armIdEdit->text().trimmed();
|
||||||
|
m_handEye->setContext(endpoint(),device,false,m_demoCheck->isChecked(),false,{});
|
||||||
|
m_handEyeMotion->setContext(endpoint(),device,false,m_demoCheck->isChecked(),false,{});
|
||||||
|
});
|
||||||
|
syncHandEyeContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MainWindow::selectedLocalTcp() const
|
||||||
|
{
|
||||||
|
return m_tcpFrameCombo && m_tcpFrameCombo->currentData().toString().startsWith(QStringLiteral("local:"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::refreshTcpChoices(const QString &savedName)
|
||||||
|
{
|
||||||
|
if (!m_tcpFrameCombo || !m_armIdEdit) return;
|
||||||
|
const QString device = m_armIdEdit->text().trimmed();
|
||||||
|
const bool changed = m_tcpChoiceEndpoint != endpoint() || m_tcpChoiceDevice != device;
|
||||||
|
QString previous = changed ? QString() : m_tcpFrameCombo->currentData().toString();
|
||||||
|
if (changed) {
|
||||||
|
if (m_tcpJog) m_tcpJog->stop();
|
||||||
|
m_controllerTcpFrames.clear();
|
||||||
|
m_armDefaultTcpFrame.clear();
|
||||||
|
m_tcpChoiceEndpoint = endpoint(); m_tcpChoiceDevice = device;
|
||||||
|
}
|
||||||
|
TcpToolStore::Snapshot snapshot;
|
||||||
|
QSettings settings; QString error;
|
||||||
|
if (!device.isEmpty() && !TcpToolStore::load(settings,endpoint(),device,snapshot,error))
|
||||||
|
appendLog(QStringLiteral("ERROR"),error);
|
||||||
|
if (!savedName.isEmpty()) previous = QStringLiteral("local:") + savedName;
|
||||||
|
else if (changed && !snapshot.current.isEmpty()) previous = QStringLiteral("local:") + snapshot.current;
|
||||||
|
{
|
||||||
|
const QSignalBlocker blocker(m_tcpFrameCombo);
|
||||||
|
m_tcpFrameCombo->clear();
|
||||||
|
QStringList frames = m_controllerTcpFrames;
|
||||||
|
if (frames.isEmpty()) frames << (m_armDefaultTcpFrame.isEmpty() ? QStringLiteral("tool0") : m_armDefaultTcpFrame);
|
||||||
|
for (const QString &frame : frames)
|
||||||
|
m_tcpFrameCombo->addItem(frame, QStringLiteral("controller:") + frame);
|
||||||
|
for (const auto &tool : snapshot.tools) {
|
||||||
|
m_tcpFrameCombo->addItem(tool.name + QStringLiteral("(标定)"), QStringLiteral("local:") + tool.name);
|
||||||
|
QVariantList pose; for (double value : tool.offset) pose.append(value);
|
||||||
|
m_tcpFrameCombo->setItemData(m_tcpFrameCombo->count()-1,pose,Qt::UserRole+1);
|
||||||
|
}
|
||||||
|
const int index=m_tcpFrameCombo->findData(previous);
|
||||||
|
m_tcpFrameCombo->setCurrentIndex(index>=0 ? index : 0);
|
||||||
|
}
|
||||||
|
updateArmPoseFrames();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::updateArmPoseFrames()
|
||||||
|
{
|
||||||
|
if (!m_tcpFrameCombo || !m_baseFrameCombo || !m_armIdEdit) return;
|
||||||
|
const bool local = selectedLocalTcp();
|
||||||
|
if (m_tcpJog) m_tcpJog->stop();
|
||||||
|
if (local) {
|
||||||
|
const QSignalBlocker blocker(m_baseFrameCombo);
|
||||||
|
int base = m_baseFrameCombo->findText(QStringLiteral("base"));
|
||||||
|
if (base < 0) { m_baseFrameCombo->addItem(QStringLiteral("base")); base=m_baseFrameCombo->count()-1; }
|
||||||
|
m_baseFrameCombo->setCurrentIndex(base);
|
||||||
|
}
|
||||||
|
m_baseFrameCombo->setEnabled(!local);
|
||||||
|
if (m_armPoseSubtitle) m_armPoseSubtitle->setText(local
|
||||||
|
? QStringLiteral("base → %1 · 按住工具轴小步点动").arg(m_tcpFrameCombo->currentText())
|
||||||
|
: QStringLiteral("%1 → %2").arg(m_baseFrameCombo->currentText(),m_tcpFrameCombo->currentText()));
|
||||||
|
m_tcpFrameCombo->setToolTip(local
|
||||||
|
? QStringLiteral("使用当前机器人的标定偏移进行点动;单步最多 2 mm / 0.29°,松开即停止")
|
||||||
|
: QStringLiteral("控制器坐标名称;原速度命令仍使用基座方向"));
|
||||||
|
// Local names must never be sent to the server's named-frame RPC.
|
||||||
|
m_client->setArmTelemetryFrames(m_armIdEdit->text().trimmed(),
|
||||||
|
local ? QStringLiteral("base") : m_baseFrameCombo->currentText(),
|
||||||
|
local ? QString() : m_tcpFrameCombo->currentText());
|
||||||
|
for (auto *label : m_cartesianJogPoseLabels) label->setText(QStringLiteral("--"));
|
||||||
|
for (auto *label : m_poseMetricValues) label->setText(QStringLiteral("--"));
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::updateArmInfo(const QString &deviceId, const QVariantMap &info)
|
void MainWindow::updateArmInfo(const QString &deviceId, const QVariantMap &info)
|
||||||
{
|
{
|
||||||
if (!m_armIdEdit || deviceId != m_armIdEdit->text().trimmed())
|
if (!m_armIdEdit || deviceId != m_armIdEdit->text().trimmed())
|
||||||
@ -1356,8 +1438,30 @@ void MainWindow::updateTelemetry(const QString &deviceId, const QVariantList &jo
|
|||||||
}
|
}
|
||||||
m_lastArmTelemetryMs = nowMs;
|
m_lastArmTelemetryMs = nowMs;
|
||||||
|
|
||||||
if (!pose.isEmpty()) {
|
QVariantMap displayPose = pose;
|
||||||
m_latestArmPose = pose;
|
if (selectedLocalTcp()) {
|
||||||
|
displayPose.clear();
|
||||||
|
if (m_tcpCalibration && m_tcpCalibration->referenceConfirmed()) {
|
||||||
|
const QVariantMap actual = state.value(QStringLiteral("activeTcpPose")).toMap();
|
||||||
|
const auto values=m_tcpFrameCombo->currentData(Qt::UserRole+1).toList();
|
||||||
|
const char *names[]={"x","y","z","rx","ry","rz"};
|
||||||
|
TcpCalibration::Pose current{}, offset{}, flange{}, selected{};
|
||||||
|
bool valid = values.size()==6;
|
||||||
|
for(int i=0;valid && i<6;++i) {
|
||||||
|
bool ok=false; current[size_t(i)]=actual.value(names[i]).toDouble(&ok);
|
||||||
|
valid=ok; offset[size_t(i)]=values.at(i).toDouble();
|
||||||
|
}
|
||||||
|
if (valid && TcpCalibration::flangePose(current,m_tcpCalibration->activeOffset(),flange)
|
||||||
|
&& TcpCalibration::toolPose(flange,offset,selected))
|
||||||
|
for(int i=0;i<6;++i) displayPose.insert(names[i],selected[size_t(i)]);
|
||||||
|
}
|
||||||
|
if (displayPose.isEmpty()) {
|
||||||
|
for(auto *label:m_poseMetricValues) label->setText(QStringLiteral("--"));
|
||||||
|
for(auto *label:m_cartesianJogPoseLabels) label->setText(QStringLiteral("--"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!displayPose.isEmpty()) {
|
||||||
|
m_latestArmPose = displayPose;
|
||||||
static const QStringList keys = {
|
static const QStringList keys = {
|
||||||
QStringLiteral("x"), QStringLiteral("y"), QStringLiteral("z"),
|
QStringLiteral("x"), QStringLiteral("y"), QStringLiteral("z"),
|
||||||
QStringLiteral("rx"), QStringLiteral("ry"), QStringLiteral("rz")
|
QStringLiteral("rx"), QStringLiteral("ry"), QStringLiteral("rz")
|
||||||
@ -1365,13 +1469,13 @@ void MainWindow::updateTelemetry(const QString &deviceId, const QVariantList &jo
|
|||||||
for (int index = 0; index < keys.size()
|
for (int index = 0; index < keys.size()
|
||||||
&& index < m_poseMetricValues.size(); ++index) {
|
&& index < m_poseMetricValues.size(); ++index) {
|
||||||
m_poseMetricValues.at(index)->setText(
|
m_poseMetricValues.at(index)->setText(
|
||||||
QString::number(pose.value(keys.at(index)).toDouble(), 'f', 4));
|
QString::number(displayPose.value(keys.at(index)).toDouble(), 'f', 4));
|
||||||
}
|
}
|
||||||
for (int index = 0; index < keys.size()
|
for (int index = 0; index < keys.size()
|
||||||
&& index < m_cartesianJogPoseLabels.size(); ++index) {
|
&& index < m_cartesianJogPoseLabels.size(); ++index) {
|
||||||
m_cartesianJogPoseLabels.at(index)->setText(
|
m_cartesianJogPoseLabels.at(index)->setText(
|
||||||
QStringLiteral("%1 %2")
|
QStringLiteral("%1 %2")
|
||||||
.arg(pose.value(keys.at(index)).toDouble(), 0, 'f', 4)
|
.arg(displayPose.value(keys.at(index)).toDouble(), 0, 'f', 4)
|
||||||
.arg(index < 3 ? QStringLiteral("m") : QStringLiteral("rad")));
|
.arg(index < 3 ? QStringLiteral("m") : QStringLiteral("rad")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1565,13 +1669,6 @@ void MainWindow::updateSystemStatus(double cpu, double memory, double disk,
|
|||||||
m_client->requestArmInfo(firstArmId);
|
m_client->requestArmInfo(firstArmId);
|
||||||
m_client->requestArmFrames(firstArmId);
|
m_client->requestArmFrames(firstArmId);
|
||||||
}
|
}
|
||||||
if (m_connected && m_pages && m_pages->currentIndex() == 1
|
|
||||||
&& !selectedId.isEmpty() && m_armTelemetryButton
|
|
||||||
&& (selectedId != previousId
|
|
||||||
|| !m_armTelemetryButton->isChecked())) {
|
|
||||||
setArmTelemetryEnabled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::updateSystemInfo(const QVariantMap &info)
|
void MainWindow::updateSystemInfo(const QVariantMap &info)
|
||||||
@ -1586,7 +1683,6 @@ void MainWindow::updateSystemInfo(const QVariantMap &info)
|
|||||||
|
|
||||||
void MainWindow::updateAgvState(const QVariantMap &state, const QVariantMap &navigation)
|
void MainWindow::updateAgvState(const QVariantMap &state, const QVariantMap &navigation)
|
||||||
{
|
{
|
||||||
m_latestAgvState = state;
|
|
||||||
const bool controllerConnected = state.value(QStringLiteral("connected")).toBool();
|
const bool controllerConnected = state.value(QStringLiteral("connected")).toBool();
|
||||||
const bool localized = state.value(QStringLiteral("localized")).toBool();
|
const bool localized = state.value(QStringLiteral("localized")).toBool();
|
||||||
const bool fault = state.value(QStringLiteral("fault")).toBool();
|
const bool fault = state.value(QStringLiteral("fault")).toBool();
|
||||||
@ -1606,22 +1702,12 @@ void MainWindow::updateAgvState(const QVariantMap &state, const QVariantMap &nav
|
|||||||
.arg(state.value(QStringLiteral("vx")).toDouble(), 0, 'f', 2)
|
.arg(state.value(QStringLiteral("vx")).toDouble(), 0, 'f', 2)
|
||||||
.arg(state.value(QStringLiteral("vy")).toDouble(), 0, 'f', 2)
|
.arg(state.value(QStringLiteral("vy")).toDouble(), 0, 'f', 2)
|
||||||
.arg(state.value(QStringLiteral("wz")).toDouble(), 0, 'f', 2));
|
.arg(state.value(QStringLiteral("wz")).toDouble(), 0, 'f', 2));
|
||||||
const bool charging = state.value(QStringLiteral("charging")).toBool();
|
m_agvBatteryValue->setText(QStringLiteral("%1%").arg(
|
||||||
m_agvBatteryValue->setText(
|
state.value(QStringLiteral("battery")).toDouble() * 100.0, 0, 'f', 0));
|
||||||
QStringLiteral("%1%").arg(
|
|
||||||
state.value(QStringLiteral("battery")).toDouble() * 100.0, 0, 'f', 0)
|
|
||||||
+ (charging ? QStringLiteral(" · 充电中") : QString()));
|
|
||||||
m_agvNavigationValue->setText(navigation.value(QStringLiteral("message"), QStringLiteral("--")).toString());
|
m_agvNavigationValue->setText(navigation.value(QStringLiteral("message"), QStringLiteral("--")).toString());
|
||||||
m_agvErrorValue->setText(state.value(QStringLiteral("error"), QStringLiteral("无")).toString());
|
m_agvErrorValue->setText(state.value(QStringLiteral("error"), QStringLiteral("无")).toString());
|
||||||
static const QStringList modeNames = {
|
m_agvModeValue->setText(QStringLiteral("模式 %1").arg(
|
||||||
QStringLiteral("未知"), QStringLiteral("离线"), QStringLiteral("空闲"),
|
state.value(QStringLiteral("mode")).toInt()));
|
||||||
QStringLiteral("手动"), QStringLiteral("自动"), QStringLiteral("充电"),
|
|
||||||
QStringLiteral("暂停"), QStringLiteral("已停止"), QStringLiteral("故障"),
|
|
||||||
QStringLiteral("急停")
|
|
||||||
};
|
|
||||||
const int mode = state.value(QStringLiteral("mode")).toInt();
|
|
||||||
m_agvModeValue->setText(modeNames.value(
|
|
||||||
mode, QStringLiteral("模式 %1").arg(mode)));
|
|
||||||
m_agvMotionStateValue->setText(QStringLiteral("%1 / %2")
|
m_agvMotionStateValue->setText(QStringLiteral("%1 / %2")
|
||||||
.arg(localized ? QStringLiteral("已定位") : QStringLiteral("未定位"),
|
.arg(localized ? QStringLiteral("已定位") : QStringLiteral("未定位"),
|
||||||
state.value(QStringLiteral("moving")).toBool()
|
state.value(QStringLiteral("moving")).toBool()
|
||||||
@ -1629,12 +1715,9 @@ void MainWindow::updateAgvState(const QVariantMap &state, const QVariantMap &nav
|
|||||||
m_agvSafetyValue->setText(QStringLiteral("%1 / %2")
|
m_agvSafetyValue->setText(QStringLiteral("%1 / %2")
|
||||||
.arg(fault ? QStringLiteral("有故障") : QStringLiteral("正常"),
|
.arg(fault ? QStringLiteral("有故障") : QStringLiteral("正常"),
|
||||||
emergency ? QStringLiteral("已急停") : QStringLiteral("未急停")));
|
emergency ? QStringLiteral("已急停") : QStringLiteral("未急停")));
|
||||||
const double voltage = state.value(QStringLiteral("voltage")).toDouble();
|
m_agvPowerValue->setText(QStringLiteral("%1 V / %2 A / %3 °C")
|
||||||
const double current = state.value(QStringLiteral("current")).toDouble();
|
.arg(state.value(QStringLiteral("voltage")).toDouble(), 0, 'f', 2)
|
||||||
m_agvPowerValue->setText(QStringLiteral("%1 V / %2 A / %3 W / %4 °C")
|
.arg(state.value(QStringLiteral("current")).toDouble(), 0, 'f', 2)
|
||||||
.arg(voltage, 0, 'f', 2)
|
|
||||||
.arg(current, 0, 'f', 2)
|
|
||||||
.arg(qAbs(voltage * current), 0, 'f', 1)
|
|
||||||
.arg(state.value(QStringLiteral("temperature")).toDouble(), 0, 'f', 1));
|
.arg(state.value(QStringLiteral("temperature")).toDouble(), 0, 'f', 1));
|
||||||
const double timestamp = state.value(QStringLiteral("timestamp")).toDouble();
|
const double timestamp = state.value(QStringLiteral("timestamp")).toDouble();
|
||||||
m_agvTimestampValue->setText(timestamp > 0.0
|
m_agvTimestampValue->setText(timestamp > 0.0
|
||||||
@ -1642,19 +1725,11 @@ void MainWindow::updateAgvState(const QVariantMap &state, const QVariantMap &nav
|
|||||||
.toString(QStringLiteral("yyyy-MM-dd HH:mm:ss.zzz"))
|
.toString(QStringLiteral("yyyy-MM-dd HH:mm:ss.zzz"))
|
||||||
: QStringLiteral("--"));
|
: QStringLiteral("--"));
|
||||||
m_agvProgress->setValue(qBound(0, qRound(navigation.value(QStringLiteral("progress")).toDouble() * 100.0), 100));
|
m_agvProgress->setValue(qBound(0, qRound(navigation.value(QStringLiteral("progress")).toDouble() * 100.0), 100));
|
||||||
if (m_agvMapView) {
|
|
||||||
m_agvMapView->updateRobotPose(
|
|
||||||
state.value(QStringLiteral("x")).toDouble(),
|
|
||||||
state.value(QStringLiteral("y")).toDouble(),
|
|
||||||
state.value(QStringLiteral("theta")).toDouble(), localized);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::updateAgvInventory(const QStringList &maps, const QVariantList &stations)
|
void MainWindow::updateAgvInventory(const QStringList &maps, const QVariantList &stations)
|
||||||
{
|
{
|
||||||
QString selectedMap = m_agvMapCombo->currentText();
|
const QString selectedMap = m_agvMapCombo->currentText();
|
||||||
if (selectedMap.trimmed().isEmpty())
|
|
||||||
selectedMap = m_latestAgvState.value(QStringLiteral("map")).toString();
|
|
||||||
m_agvMapCombo->clear();
|
m_agvMapCombo->clear();
|
||||||
m_agvMapCombo->addItems(maps);
|
m_agvMapCombo->addItems(maps);
|
||||||
const int mapIndex = m_agvMapCombo->findText(selectedMap);
|
const int mapIndex = m_agvMapCombo->findText(selectedMap);
|
||||||
@ -1830,15 +1905,12 @@ void MainWindow::handleCommand(const QString &command, bool success, const QStri
|
|||||||
|| command == QStringLiteral("Camera Stop Recording"))) {
|
|| command == QStringLiteral("Camera Stop Recording"))) {
|
||||||
updateCameraRecordingState(m_cameraRecording, detail);
|
updateCameraRecordingState(m_cameraRecording, detail);
|
||||||
}
|
}
|
||||||
if (success && command == QStringLiteral("AGV SwitchMap")) {
|
if (success && m_agvStatusSwitch
|
||||||
m_client->requestAgvInventory(m_agvIdEdit->text().trimmed());
|
&& (command == QStringLiteral("AGV NavigateToPose")
|
||||||
restartAgvMapStream(m_agvMapCombo->currentText());
|
|| command == QStringLiteral("AGV NavigateToStation")
|
||||||
|
|| command == QStringLiteral("AGV FollowPath"))) {
|
||||||
|
m_agvStatusSwitch->setChecked(true);
|
||||||
}
|
}
|
||||||
if (success && command == QStringLiteral("AGV StopMapping")) {
|
|
||||||
m_client->requestAgvInventory(m_agvIdEdit->text().trimmed());
|
|
||||||
restartAgvMapStream();
|
|
||||||
}
|
|
||||||
|
|
||||||
appendLog(success ? QStringLiteral("OK") : QStringLiteral("ERROR"),
|
appendLog(success ? QStringLiteral("OK") : QStringLiteral("ERROR"),
|
||||||
QStringLiteral("%1 · %2").arg(command, detail));
|
QStringLiteral("%1 · %2").arg(command, detail));
|
||||||
if (!success)
|
if (!success)
|
||||||
@ -2073,8 +2145,6 @@ void MainWindow::setControlsEnabled(bool enabled)
|
|||||||
m_microphoneStreamStartButton->setEnabled(enabled);
|
m_microphoneStreamStartButton->setEnabled(enabled);
|
||||||
if (m_microphoneStreamStopButton)
|
if (m_microphoneStreamStopButton)
|
||||||
m_microphoneStreamStopButton->setEnabled(false);
|
m_microphoneStreamStopButton->setEnabled(false);
|
||||||
if (m_agvDeleteMapButton)
|
|
||||||
m_agvDeleteMapButton->setEnabled(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MainWindow::endpoint() const
|
QString MainWindow::endpoint() const
|
||||||
|
|||||||
@ -39,7 +39,11 @@ class QuicTestServer;
|
|||||||
class UrdfViewerWidget;
|
class UrdfViewerWidget;
|
||||||
class AudioStreamManager;
|
class AudioStreamManager;
|
||||||
class VideoRenderWidget;
|
class VideoRenderWidget;
|
||||||
class AgvMapViewWidget;
|
class TcpCalibrationWidget;
|
||||||
|
class TouchOperationWidget;
|
||||||
|
class TcpJogController;
|
||||||
|
class HandEyeCalibrationWidget;
|
||||||
|
class HandEyeMotionWidget;
|
||||||
|
|
||||||
class MainWindow : public QMainWindow
|
class MainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
@ -51,7 +55,6 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
|
bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
|
||||||
bool eventFilter(QObject *watched, QEvent *event) override;
|
|
||||||
void changeEvent(QEvent *event) override;
|
void changeEvent(QEvent *event) override;
|
||||||
void resizeEvent(QResizeEvent *event) override;
|
void resizeEvent(QResizeEvent *event) override;
|
||||||
|
|
||||||
@ -103,19 +106,31 @@ private:
|
|||||||
void ensureArmModelLoaded();
|
void ensureArmModelLoaded();
|
||||||
void rebuildArmJointTables(const QStringList &jointNames);
|
void rebuildArmJointTables(const QStringList &jointNames);
|
||||||
void rebuildArmJogControls();
|
void rebuildArmJogControls();
|
||||||
void setArmTelemetryEnabled(bool enabled);
|
|
||||||
void startJointJog(int jointIndex, int direction);
|
void startJointJog(int jointIndex, int direction);
|
||||||
void startCartesianJog(int axisIndex, int direction);
|
void startCartesianJog(int axisIndex, int direction);
|
||||||
void stopArmJog();
|
void stopArmJog();
|
||||||
void startAgvManualMotion(double vx, double vy, double wz);
|
void refreshTcpChoices(const QString &savedName = QString());
|
||||||
void stopAgvManualMotion(bool sendStop = true);
|
void updateArmPoseFrames();
|
||||||
void restartAgvMapStream(const QString &mapName = QString());
|
bool selectedLocalTcp() const;
|
||||||
|
void setupHandEye();
|
||||||
|
void setupTouchOperation();
|
||||||
|
void syncHandEyeContext();
|
||||||
void updateArmAlert(const QString &deviceId, const QString &alertKey,
|
void updateArmAlert(const QString &deviceId, const QString &alertKey,
|
||||||
const QString &level, const QString &summary,
|
const QString &level, const QString &summary,
|
||||||
const QString &detail = QString());
|
const QString &detail = QString());
|
||||||
QString endpoint() const;
|
QString endpoint() const;
|
||||||
|
|
||||||
RobotClient *m_client = nullptr;
|
RobotClient *m_client = nullptr;
|
||||||
|
TcpCalibrationWidget *m_tcpCalibration = nullptr;
|
||||||
|
TcpJogController *m_tcpJog = nullptr;
|
||||||
|
HandEyeCalibrationWidget *m_handEye = nullptr;
|
||||||
|
HandEyeMotionWidget *m_handEyeMotion = nullptr;
|
||||||
|
QString m_handEyeOwnedCamera;
|
||||||
|
TouchOperationWidget *m_touchOperation = nullptr;
|
||||||
|
QString m_touchOwnedCamera;
|
||||||
|
QString m_tcpChoiceEndpoint, m_tcpChoiceDevice;
|
||||||
|
QStringList m_controllerTcpFrames;
|
||||||
|
QLabel *m_armPoseSubtitle = nullptr;
|
||||||
AudioStreamManager *m_audioManager = nullptr;
|
AudioStreamManager *m_audioManager = nullptr;
|
||||||
QuicTestServer *m_quicServer = nullptr;
|
QuicTestServer *m_quicServer = nullptr;
|
||||||
QStackedWidget *m_pages = nullptr;
|
QStackedWidget *m_pages = nullptr;
|
||||||
@ -250,8 +265,8 @@ private:
|
|||||||
|
|
||||||
QLineEdit *m_agvIdEdit = nullptr;
|
QLineEdit *m_agvIdEdit = nullptr;
|
||||||
QDialog *m_agvStatusDialog = nullptr;
|
QDialog *m_agvStatusDialog = nullptr;
|
||||||
|
QCheckBox *m_agvStatusSwitch = nullptr;
|
||||||
QTimer *m_agvStatusRefreshTimer = nullptr;
|
QTimer *m_agvStatusRefreshTimer = nullptr;
|
||||||
QTimer *m_agvManualVelocityTimer = nullptr;
|
|
||||||
QLabel *m_agvConnectionValue = nullptr;
|
QLabel *m_agvConnectionValue = nullptr;
|
||||||
QLabel *m_agvPoseValue = nullptr;
|
QLabel *m_agvPoseValue = nullptr;
|
||||||
QLabel *m_agvMotionValue = nullptr;
|
QLabel *m_agvMotionValue = nullptr;
|
||||||
@ -267,9 +282,6 @@ private:
|
|||||||
QLabel *m_agvMapOverview = nullptr;
|
QLabel *m_agvMapOverview = nullptr;
|
||||||
QLabel *m_agvMappingPreview = nullptr;
|
QLabel *m_agvMappingPreview = nullptr;
|
||||||
QLabel *m_agvMappingStateLabel = nullptr;
|
QLabel *m_agvMappingStateLabel = nullptr;
|
||||||
AgvMapViewWidget *m_agvMapView = nullptr;
|
|
||||||
QWidget *m_agvControlWorkspace = nullptr;
|
|
||||||
QPushButton *m_agvDeleteMapButton = nullptr;
|
|
||||||
QProgressBar *m_agvProgress = nullptr;
|
QProgressBar *m_agvProgress = nullptr;
|
||||||
QDoubleSpinBox *m_agvXSpin = nullptr;
|
QDoubleSpinBox *m_agvXSpin = nullptr;
|
||||||
QDoubleSpinBox *m_agvYSpin = nullptr;
|
QDoubleSpinBox *m_agvYSpin = nullptr;
|
||||||
@ -282,12 +294,6 @@ private:
|
|||||||
QComboBox *m_agvStationCombo = nullptr;
|
QComboBox *m_agvStationCombo = nullptr;
|
||||||
QTableWidget *m_agvStationTable = nullptr;
|
QTableWidget *m_agvStationTable = nullptr;
|
||||||
QString m_agvDownloadPath;
|
QString m_agvDownloadPath;
|
||||||
QVariantMap m_latestAgvState;
|
|
||||||
double m_agvManualVx = 0.0;
|
|
||||||
double m_agvManualVy = 0.0;
|
|
||||||
double m_agvManualWz = 0.0;
|
|
||||||
bool m_agvManualMotionActive = false;
|
|
||||||
bool m_agvMapStreamActive = false;
|
|
||||||
QList<QPushButton *> m_serviceButtons;
|
QList<QPushButton *> m_serviceButtons;
|
||||||
QPushButton *m_speakerStreamStartButton = nullptr;
|
QPushButton *m_speakerStreamStartButton = nullptr;
|
||||||
QPushButton *m_speakerStreamStopButton = nullptr;
|
QPushButton *m_speakerStreamStopButton = nullptr;
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
|
||||||
#include "agvmapviewwidget.h"
|
|
||||||
#include "audiostreammanager.h"
|
#include "audiostreammanager.h"
|
||||||
#include "robotclient.h"
|
#include "robotclient.h"
|
||||||
|
#include "tcptoolstore.h"
|
||||||
|
#include "handeyemotionwidget.h"
|
||||||
#include "rpcservicewidget.h"
|
#include "rpcservicewidget.h"
|
||||||
#include "uiicons.h"
|
#include "uiicons.h"
|
||||||
#include "urdfviewerwidget.h"
|
#include "urdfviewerwidget.h"
|
||||||
@ -15,7 +16,6 @@
|
|||||||
#include "ui_quicserverpage.h"
|
#include "ui_quicserverpage.h"
|
||||||
#include "ui_systemservicepage.h"
|
#include "ui_systemservicepage.h"
|
||||||
|
|
||||||
#include <QDialogButtonBox>
|
|
||||||
#include <QAbstractItemView>
|
#include <QAbstractItemView>
|
||||||
#include <QAbstractButton>
|
#include <QAbstractButton>
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
@ -33,7 +33,6 @@
|
|||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QInputDialog>
|
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
@ -45,9 +44,9 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QSignalBlocker>
|
#include <QSignalBlocker>
|
||||||
|
#include <QSettings>
|
||||||
#include <QSlider>
|
#include <QSlider>
|
||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
#include <QStackedWidget>
|
|
||||||
#include <QSplitter>
|
#include <QSplitter>
|
||||||
#include <QStyledItemDelegate>
|
#include <QStyledItemDelegate>
|
||||||
#include <QTabBar>
|
#include <QTabBar>
|
||||||
@ -432,6 +431,8 @@ QWidget *MainWindow::createArmPage()
|
|||||||
QLabel *tcpFrameLabel = new QLabel(QStringLiteral("工具坐标"), cartesianJogPage);
|
QLabel *tcpFrameLabel = new QLabel(QStringLiteral("工具坐标"), cartesianJogPage);
|
||||||
m_baseFrameCombo = new QComboBox(cartesianJogPage);
|
m_baseFrameCombo = new QComboBox(cartesianJogPage);
|
||||||
m_tcpFrameCombo = new QComboBox(cartesianJogPage);
|
m_tcpFrameCombo = new QComboBox(cartesianJogPage);
|
||||||
|
m_tcpFrameCombo->setObjectName(QStringLiteral("armTcpFrameCombo"));
|
||||||
|
m_armPoseSubtitle = ui.poseSubtitle;
|
||||||
m_baseFrameCombo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
m_baseFrameCombo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||||
m_tcpFrameCombo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
m_tcpFrameCombo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||||
frameGrid->addWidget(baseFrameLabel, 0, 0);
|
frameGrid->addWidget(baseFrameLabel, 0, 0);
|
||||||
@ -482,94 +483,29 @@ QWidget *MainWindow::createArmPage()
|
|||||||
}
|
}
|
||||||
return strip;
|
return strip;
|
||||||
};
|
};
|
||||||
const auto createDirectionPad = [&createJogButton](
|
const auto createAxisControls = [&createJogButton](QWidget *parent, int firstAxis,
|
||||||
QWidget *parent,
|
const QStringList &names) {
|
||||||
int verticalAxis,
|
auto *layout = new QHBoxLayout;
|
||||||
const QString &verticalName,
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
const QString &verticalTone,
|
layout->setSpacing(6);
|
||||||
int horizontalAxis,
|
const QStringList tones = {QStringLiteral("x"), QStringLiteral("y"), QStringLiteral("z")};
|
||||||
const QString &horizontalName,
|
for (int i = 0; i < names.size(); ++i) {
|
||||||
const QString &horizontalTone,
|
auto *pair = new QHBoxLayout;
|
||||||
const QString ¢erText) {
|
pair->setSpacing(4);
|
||||||
QFrame *pad = new QFrame(parent);
|
for (int direction : {-1, 1}) {
|
||||||
pad->setObjectName(QStringLiteral("cartesianDirectionPad"));
|
auto *button = createJogButton(parent,
|
||||||
pad->setFixedSize(250, 180);
|
QStringLiteral("%1 %2").arg(direction < 0 ? QStringLiteral("−") : QStringLiteral("+"), names.at(i)),
|
||||||
QGridLayout *layout = new QGridLayout(pad);
|
firstAxis + i, direction, tones.at(i), QStringLiteral("compact"), 48, 42);
|
||||||
layout->setContentsMargins(8, 8, 8, 8);
|
button->setMinimumWidth(42);
|
||||||
layout->setHorizontalSpacing(2);
|
button->setMaximumWidth(QWIDGETSIZE_MAX);
|
||||||
layout->setVerticalSpacing(2);
|
button->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||||
QLabel *center = new QLabel(centerText, pad);
|
button->setToolTip(QStringLiteral("按住沿 %1 %2 运动,松开停止")
|
||||||
center->setObjectName(QStringLiteral("cartesianPadCenter"));
|
.arg(names.at(i), direction < 0 ? QStringLiteral("负向") : QStringLiteral("正向")));
|
||||||
center->setAlignment(Qt::AlignCenter);
|
pair->addWidget(button, 1);
|
||||||
center->setFixedSize(52, 52);
|
}
|
||||||
layout->addWidget(createJogButton(
|
layout->addLayout(pair, 1);
|
||||||
pad, QStringLiteral("▲\n+%1").arg(verticalName),
|
}
|
||||||
verticalAxis, 1, verticalTone, QStringLiteral("north"), 86, 48),
|
return layout;
|
||||||
0, 1, Qt::AlignHCenter);
|
|
||||||
layout->addWidget(createJogButton(
|
|
||||||
pad, QStringLiteral("◀ −%1").arg(horizontalName),
|
|
||||||
horizontalAxis, -1, horizontalTone, QStringLiteral("eastTall"), 72, 150),
|
|
||||||
0, 0, 3, 1, Qt::AlignVCenter);
|
|
||||||
layout->addWidget(center, 1, 1, Qt::AlignCenter);
|
|
||||||
layout->addWidget(createJogButton(
|
|
||||||
pad, QStringLiteral("+%1 ▶").arg(horizontalName),
|
|
||||||
horizontalAxis, 1, horizontalTone, QStringLiteral("westTall"), 72, 150),
|
|
||||||
0, 2, 3, 1, Qt::AlignVCenter);
|
|
||||||
layout->addWidget(createJogButton(
|
|
||||||
pad, QStringLiteral("−%1\n▼").arg(verticalName),
|
|
||||||
verticalAxis, -1, verticalTone, QStringLiteral("south"), 86, 48),
|
|
||||||
2, 1, Qt::AlignHCenter);
|
|
||||||
return pad;
|
|
||||||
};
|
|
||||||
const auto createVerticalRocker = [&createJogButton](
|
|
||||||
QWidget *parent, int axis,
|
|
||||||
const QString &axisName,
|
|
||||||
const QString &tone) {
|
|
||||||
QFrame *rocker = new QFrame(parent);
|
|
||||||
rocker->setObjectName(QStringLiteral("cartesianAxisRocker"));
|
|
||||||
rocker->setProperty("orientation", QStringLiteral("vertical"));
|
|
||||||
rocker->setFixedSize(76, 168);
|
|
||||||
QVBoxLayout *layout = new QVBoxLayout(rocker);
|
|
||||||
layout->setContentsMargins(8, 8, 8, 8);
|
|
||||||
layout->setSpacing(0);
|
|
||||||
QLabel *center = new QLabel(axisName, rocker);
|
|
||||||
center->setObjectName(QStringLiteral("cartesianPadCenter"));
|
|
||||||
center->setAlignment(Qt::AlignCenter);
|
|
||||||
center->setFixedSize(52, 52);
|
|
||||||
layout->addWidget(createJogButton(
|
|
||||||
rocker, QStringLiteral("▲\n+%1").arg(axisName), axis, 1, tone,
|
|
||||||
QStringLiteral("north"), 60, 50),
|
|
||||||
0, Qt::AlignHCenter);
|
|
||||||
layout->addWidget(center, 0, Qt::AlignHCenter);
|
|
||||||
layout->addWidget(createJogButton(
|
|
||||||
rocker, QStringLiteral("−%1\n▼").arg(axisName), axis, -1, tone,
|
|
||||||
QStringLiteral("south"), 60, 50),
|
|
||||||
0, Qt::AlignHCenter);
|
|
||||||
return rocker;
|
|
||||||
};
|
|
||||||
const auto createHorizontalRocker = [&createJogButton](
|
|
||||||
QWidget *parent, int axis,
|
|
||||||
const QString &axisName,
|
|
||||||
const QString &tone) {
|
|
||||||
QFrame *rocker = new QFrame(parent);
|
|
||||||
rocker->setObjectName(QStringLiteral("cartesianAxisRocker"));
|
|
||||||
rocker->setProperty("orientation", QStringLiteral("horizontal"));
|
|
||||||
rocker->setFixedSize(208, 68);
|
|
||||||
QHBoxLayout *layout = new QHBoxLayout(rocker);
|
|
||||||
layout->setContentsMargins(8, 8, 8, 8);
|
|
||||||
layout->setSpacing(0);
|
|
||||||
QLabel *center = new QLabel(axisName, rocker);
|
|
||||||
center->setObjectName(QStringLiteral("cartesianPadCenter"));
|
|
||||||
center->setAlignment(Qt::AlignCenter);
|
|
||||||
center->setFixedSize(52, 52);
|
|
||||||
layout->addWidget(createJogButton(
|
|
||||||
rocker, QStringLiteral("◀ −%1").arg(axisName), axis, -1, tone,
|
|
||||||
QStringLiteral("west"), 70, 52));
|
|
||||||
layout->addWidget(center);
|
|
||||||
layout->addWidget(createJogButton(
|
|
||||||
rocker, QStringLiteral("+%1 ▶").arg(axisName), axis, 1, tone,
|
|
||||||
QStringLiteral("east"), 70, 52));
|
|
||||||
return rocker;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
QVBoxLayout *cartesianControls = new QVBoxLayout;
|
QVBoxLayout *cartesianControls = new QVBoxLayout;
|
||||||
@ -587,19 +523,9 @@ QWidget *MainWindow::createArmPage()
|
|||||||
translationGroup,
|
translationGroup,
|
||||||
{QStringLiteral("X"), QStringLiteral("Y"), QStringLiteral("Z")},
|
{QStringLiteral("X"), QStringLiteral("Y"), QStringLiteral("Z")},
|
||||||
{QStringLiteral("m"), QStringLiteral("m"), QStringLiteral("m")}));
|
{QStringLiteral("m"), QStringLiteral("m"), QStringLiteral("m")}));
|
||||||
QHBoxLayout *translationPads = new QHBoxLayout;
|
translationLayout->addLayout(createAxisControls(translationGroup, 0,
|
||||||
translationPads->setContentsMargins(0, 0, 0, 0);
|
{QStringLiteral("X"), QStringLiteral("Y"), QStringLiteral("Z")}));
|
||||||
translationPads->setSpacing(12);
|
cartesianControls->addWidget(translationGroup);
|
||||||
translationPads->addStretch(1);
|
|
||||||
translationPads->addWidget(createDirectionPad(
|
|
||||||
translationGroup, 0, QStringLiteral("X"), QStringLiteral("x"),
|
|
||||||
1, QStringLiteral("Y"), QStringLiteral("y"), QStringLiteral("XY")));
|
|
||||||
translationPads->addWidget(createVerticalRocker(
|
|
||||||
translationGroup, 2, QStringLiteral("Z"), QStringLiteral("z")),
|
|
||||||
0, Qt::AlignVCenter);
|
|
||||||
translationPads->addStretch(1);
|
|
||||||
translationLayout->addLayout(translationPads);
|
|
||||||
cartesianControls->addWidget(translationGroup, 1);
|
|
||||||
|
|
||||||
QFrame *rotationGroup = new QFrame(cartesianJogPage);
|
QFrame *rotationGroup = new QFrame(cartesianJogPage);
|
||||||
rotationGroup->setObjectName(QStringLiteral("cartesianControlGroup"));
|
rotationGroup->setObjectName(QStringLiteral("cartesianControlGroup"));
|
||||||
@ -613,21 +539,11 @@ QWidget *MainWindow::createArmPage()
|
|||||||
rotationGroup,
|
rotationGroup,
|
||||||
{QStringLiteral("RX"), QStringLiteral("RY"), QStringLiteral("RZ")},
|
{QStringLiteral("RX"), QStringLiteral("RY"), QStringLiteral("RZ")},
|
||||||
{QStringLiteral("rad"), QStringLiteral("rad"), QStringLiteral("rad")}));
|
{QStringLiteral("rad"), QStringLiteral("rad"), QStringLiteral("rad")}));
|
||||||
QHBoxLayout *rotationPads = new QHBoxLayout;
|
rotationLayout->addLayout(createAxisControls(rotationGroup, 3,
|
||||||
rotationPads->setContentsMargins(0, 0, 0, 0);
|
{QStringLiteral("RX"), QStringLiteral("RY"), QStringLiteral("RZ")}));
|
||||||
rotationPads->setSpacing(8);
|
cartesianControls->addWidget(rotationGroup);
|
||||||
rotationPads->addStretch(1);
|
|
||||||
rotationPads->addWidget(createDirectionPad(
|
|
||||||
rotationGroup, 3, QStringLiteral("RX"), QStringLiteral("x"),
|
|
||||||
4, QStringLiteral("RY"), QStringLiteral("y"), QStringLiteral("RXY")));
|
|
||||||
rotationPads->addWidget(createHorizontalRocker(
|
|
||||||
rotationGroup, 5, QStringLiteral("RZ"), QStringLiteral("z")),
|
|
||||||
0, Qt::AlignVCenter);
|
|
||||||
rotationPads->addStretch(1);
|
|
||||||
rotationLayout->addLayout(rotationPads);
|
|
||||||
cartesianControls->addWidget(rotationGroup, 1);
|
|
||||||
|
|
||||||
cartesianLayout->addLayout(cartesianControls, 1);
|
cartesianLayout->addLayout(cartesianControls);
|
||||||
cartesianLayout->addStretch(1);
|
cartesianLayout->addStretch(1);
|
||||||
if (QTabBar *jogTabBar = m_jogModeTabs->findChild<QTabBar *>()) {
|
if (QTabBar *jogTabBar = m_jogModeTabs->findChild<QTabBar *>()) {
|
||||||
jogTabBar->setExpanding(true);
|
jogTabBar->setExpanding(true);
|
||||||
@ -635,6 +551,8 @@ QWidget *MainWindow::createArmPage()
|
|||||||
jogTabBar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
jogTabBar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||||
}
|
}
|
||||||
m_jogModeTabs->addTab(cartesianJogPage, QStringLiteral("笛卡尔速度"));
|
m_jogModeTabs->addTab(cartesianJogPage, QStringLiteral("笛卡尔速度"));
|
||||||
|
m_handEyeMotion = new HandEyeMotionWidget(m_jogModeTabs);
|
||||||
|
m_jogModeTabs->addTab(m_handEyeMotion, QStringLiteral("视觉坐标"));
|
||||||
jogLayout->addWidget(m_jogModeTabs, 1);
|
jogLayout->addWidget(m_jogModeTabs, 1);
|
||||||
|
|
||||||
QHBoxLayout *speedLayout = new QHBoxLayout;
|
QHBoxLayout *speedLayout = new QHBoxLayout;
|
||||||
@ -696,13 +614,26 @@ QWidget *MainWindow::createArmPage()
|
|||||||
m_client->requestSystemStopAll(target.isEmpty() ? QStringLiteral("*") : target);
|
m_client->requestSystemStopAll(target.isEmpty() ? QStringLiteral("*") : target);
|
||||||
});
|
});
|
||||||
connect(m_armTelemetryButton, &QPushButton::clicked, this, [this](bool enabled) {
|
connect(m_armTelemetryButton, &QPushButton::clicked, this, [this](bool enabled) {
|
||||||
if (enabled && m_armIdEdit->text().trimmed().isEmpty()) {
|
const QString deviceId = m_armIdEdit->text().trimmed();
|
||||||
|
if (enabled && deviceId.isEmpty()) {
|
||||||
QMessageBox::warning(this, QStringLiteral("ArmService"),
|
QMessageBox::warning(this, QStringLiteral("ArmService"),
|
||||||
QStringLiteral("请先选择机械臂设备。"));
|
QStringLiteral("请先填写机械臂设备 ID。"));
|
||||||
setArmTelemetryEnabled(false);
|
m_armTelemetryButton->setChecked(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setArmTelemetryEnabled(enabled);
|
m_armTelemetryButton->setText(enabled ? QStringLiteral("遥测 10 Hz")
|
||||||
|
: QStringLiteral("遥测 未启动"));
|
||||||
|
m_armTelemetryButton->setProperty("active", enabled);
|
||||||
|
m_armTelemetryButton->style()->unpolish(m_armTelemetryButton);
|
||||||
|
m_armTelemetryButton->style()->polish(m_armTelemetryButton);
|
||||||
|
// Keep device selection available while telemetry is running. The
|
||||||
|
// selection handler transfers polling to the newly selected arm.
|
||||||
|
m_armSideCombo->setEnabled(true);
|
||||||
|
if (enabled) {
|
||||||
|
m_client->requestArmInfo(deviceId);
|
||||||
|
m_client->requestArmFrames(deviceId);
|
||||||
|
}
|
||||||
|
m_client->setArmTelemetry(deviceId, enabled);
|
||||||
});
|
});
|
||||||
connect(m_torqueOnButton, &QPushButton::clicked, this, [this]() {
|
connect(m_torqueOnButton, &QPushButton::clicked, this, [this]() {
|
||||||
m_client->requestTorque(m_armIdEdit->text().trimmed(), true);
|
m_client->requestTorque(m_armIdEdit->text().trimmed(), true);
|
||||||
@ -750,10 +681,10 @@ QWidget *MainWindow::createArmPage()
|
|||||||
m_client->requestArmFrames(m_armIdEdit->text().trimmed());
|
m_client->requestArmFrames(m_armIdEdit->text().trimmed());
|
||||||
});
|
});
|
||||||
connect(m_client, &RobotClient::armFramesReceived, this,
|
connect(m_client, &RobotClient::armFramesReceived, this,
|
||||||
[this, poseSubtitle = ui.poseSubtitle](const QString &deviceId,
|
[this](const QString &deviceId,
|
||||||
const QStringList &baseFrames,
|
const QStringList &baseFrames,
|
||||||
const QStringList &tcpFrames) {
|
const QStringList &tcpFrames) {
|
||||||
if (!m_armIdEdit || deviceId != m_armIdEdit->text().trimmed())
|
if (!m_connected || !m_armIdEdit || deviceId != m_armIdEdit->text().trimmed())
|
||||||
return;
|
return;
|
||||||
const auto fillFrames = [](QComboBox *combo, const QStringList &frames,
|
const auto fillFrames = [](QComboBox *combo, const QStringList &frames,
|
||||||
const QString &preferred, const QString &fallback) {
|
const QString &preferred, const QString &fallback) {
|
||||||
@ -771,24 +702,20 @@ QWidget *MainWindow::createArmPage()
|
|||||||
};
|
};
|
||||||
fillFrames(m_baseFrameCombo, baseFrames, m_armDefaultBaseFrame,
|
fillFrames(m_baseFrameCombo, baseFrames, m_armDefaultBaseFrame,
|
||||||
QStringLiteral("base"));
|
QStringLiteral("base"));
|
||||||
fillFrames(m_tcpFrameCombo, tcpFrames, m_armDefaultTcpFrame,
|
m_controllerTcpFrames = tcpFrames;
|
||||||
QStringLiteral("tool0"));
|
refreshTcpChoices();
|
||||||
poseSubtitle->setText(QStringLiteral("%1 → %2")
|
|
||||||
.arg(m_baseFrameCombo->currentText(), m_tcpFrameCombo->currentText()));
|
|
||||||
m_client->setArmTelemetryFrames(deviceId, m_baseFrameCombo->currentText(),
|
|
||||||
m_tcpFrameCombo->currentText());
|
|
||||||
});
|
});
|
||||||
const auto updatePoseFrameText = [this, poseSubtitle = ui.poseSubtitle]() {
|
|
||||||
poseSubtitle->setText(QStringLiteral("%1 → %2")
|
|
||||||
.arg(m_baseFrameCombo->currentText(), m_tcpFrameCombo->currentText()));
|
|
||||||
m_client->setArmTelemetryFrames(m_armIdEdit->text().trimmed(),
|
|
||||||
m_baseFrameCombo->currentText(),
|
|
||||||
m_tcpFrameCombo->currentText());
|
|
||||||
};
|
|
||||||
connect(m_baseFrameCombo, &QComboBox::currentTextChanged, this,
|
connect(m_baseFrameCombo, &QComboBox::currentTextChanged, this,
|
||||||
[updatePoseFrameText](const QString &) { updatePoseFrameText(); });
|
[this](const QString &) { updateArmPoseFrames(); });
|
||||||
connect(m_tcpFrameCombo, &QComboBox::currentTextChanged, this,
|
connect(m_tcpFrameCombo, &QComboBox::currentTextChanged, this,
|
||||||
[updatePoseFrameText](const QString &) { updatePoseFrameText(); });
|
[this](const QString &) {
|
||||||
|
updateArmPoseFrames();
|
||||||
|
QSettings settings; QString error;
|
||||||
|
const QString name = selectedLocalTcp() ? m_tcpFrameCombo->currentData().toString().mid(6) : QString();
|
||||||
|
if (!m_armIdEdit->text().trimmed().isEmpty()
|
||||||
|
&& !TcpToolStore::select(settings,endpoint(),m_armIdEdit->text().trimmed(),name,error))
|
||||||
|
appendLog(QStringLiteral("ERROR"),error);
|
||||||
|
});
|
||||||
connect(m_urdfViewer, &UrdfViewerWidget::logMessage,
|
connect(m_urdfViewer, &UrdfViewerWidget::logMessage,
|
||||||
this, &MainWindow::appendLog);
|
this, &MainWindow::appendLog);
|
||||||
|
|
||||||
@ -1085,6 +1012,7 @@ QWidget *MainWindow::createAgvPage()
|
|||||||
statusUi.statusLayout->setColumnStretch(3, 1);
|
statusUi.statusLayout->setColumnStretch(3, 1);
|
||||||
|
|
||||||
m_agvIdEdit = ui.agvIdEdit;
|
m_agvIdEdit = ui.agvIdEdit;
|
||||||
|
m_agvStatusSwitch = ui.agvStatusSwitch;
|
||||||
m_agvStatusRefreshTimer = new QTimer(page);
|
m_agvStatusRefreshTimer = new QTimer(page);
|
||||||
m_agvStatusRefreshTimer->setInterval(1000);
|
m_agvStatusRefreshTimer->setInterval(1000);
|
||||||
m_agvConnectionValue = statusUi.agvConnectionValue;
|
m_agvConnectionValue = statusUi.agvConnectionValue;
|
||||||
@ -1126,251 +1054,41 @@ QWidget *MainWindow::createAgvPage()
|
|||||||
m_agvStationTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
m_agvStationTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||||
m_agvStationTable->verticalHeader()->setVisible(false);
|
m_agvStationTable->verticalHeader()->setVisible(false);
|
||||||
m_agvStationTable->horizontalHeader()->setStretchLastSection(true);
|
m_agvStationTable->horizontalHeader()->setStretchLastSection(true);
|
||||||
m_agvStatusRefreshTimer->setInterval(500);
|
|
||||||
m_agvManualVelocityTimer = new QTimer(page);
|
|
||||||
m_agvManualVelocityTimer->setInterval(150);
|
|
||||||
connect(m_agvManualVelocityTimer, &QTimer::timeout, this, [this]() {
|
|
||||||
if (!m_agvManualMotionActive || !m_connected)
|
|
||||||
return;
|
|
||||||
m_client->requestAgvVelocity(m_agvIdEdit->text().trimmed(),
|
|
||||||
m_agvManualVx, m_agvManualVy,
|
|
||||||
m_agvManualWz);
|
|
||||||
});
|
|
||||||
|
|
||||||
m_agvControlWorkspace = new QWidget(ui.agvTabs);
|
|
||||||
m_agvControlWorkspace->setObjectName(QStringLiteral("agvControlWorkspace"));
|
|
||||||
QHBoxLayout *workspaceLayout = new QHBoxLayout(m_agvControlWorkspace);
|
|
||||||
workspaceLayout->setContentsMargins(0, 0, 0, 0);
|
|
||||||
workspaceLayout->setSpacing(12);
|
|
||||||
|
|
||||||
QWidget *leftColumn = new QWidget(m_agvControlWorkspace);
|
|
||||||
QVBoxLayout *leftLayout = new QVBoxLayout(leftColumn);
|
|
||||||
leftLayout->setContentsMargins(0, 0, 0, 0);
|
|
||||||
leftLayout->setSpacing(12);
|
|
||||||
QWidget *rightColumn = new QWidget(m_agvControlWorkspace);
|
|
||||||
QVBoxLayout *rightLayout = new QVBoxLayout(rightColumn);
|
|
||||||
rightLayout->setContentsMargins(0, 0, 0, 0);
|
|
||||||
rightLayout->setSpacing(12);
|
|
||||||
workspaceLayout->addWidget(leftColumn, 7);
|
|
||||||
workspaceLayout->addWidget(rightColumn, 4);
|
|
||||||
|
|
||||||
ui.mappingPreviewPanel->setParent(leftColumn);
|
|
||||||
ui.mappingPreviewPanel->setMinimumSize(0, 0);
|
|
||||||
ui.mappingPreviewTitle->setText(QStringLiteral("实时地图"));
|
|
||||||
ui.mappingPreviewLayout->removeWidget(ui.mappingPreview);
|
|
||||||
ui.mappingPreview->hide();
|
|
||||||
m_agvMappingPreview = nullptr;
|
|
||||||
|
|
||||||
QHBoxLayout *mapToolbar = new QHBoxLayout;
|
|
||||||
QLabel *mapLegend = new QLabel(
|
|
||||||
QStringLiteral("蓝色箭头:AGV 当前位姿 · 虚线:运动轨迹"),
|
|
||||||
ui.mappingPreviewPanel);
|
|
||||||
mapLegend->setObjectName(QStringLiteral("panelSubtitle"));
|
|
||||||
QPushButton *zoomOutButton = new QPushButton(QStringLiteral("−"),
|
|
||||||
ui.mappingPreviewPanel);
|
|
||||||
QPushButton *zoomInButton = new QPushButton(QStringLiteral("+"),
|
|
||||||
ui.mappingPreviewPanel);
|
|
||||||
QPushButton *resetViewButton = new QPushButton(QStringLiteral("适应窗口"),
|
|
||||||
ui.mappingPreviewPanel);
|
|
||||||
QPushButton *clearTrackButton = new QPushButton(QStringLiteral("清除轨迹"),
|
|
||||||
ui.mappingPreviewPanel);
|
|
||||||
for (QPushButton *button : {zoomOutButton, zoomInButton,
|
|
||||||
resetViewButton, clearTrackButton}) {
|
|
||||||
button->setObjectName(QStringLiteral("agvMapToolButton"));
|
|
||||||
button->setMinimumHeight(30);
|
|
||||||
}
|
|
||||||
zoomOutButton->setMaximumWidth(42);
|
|
||||||
zoomInButton->setMaximumWidth(42);
|
|
||||||
mapToolbar->addWidget(mapLegend);
|
|
||||||
mapToolbar->addStretch();
|
|
||||||
mapToolbar->addWidget(zoomOutButton);
|
|
||||||
mapToolbar->addWidget(zoomInButton);
|
|
||||||
mapToolbar->addWidget(resetViewButton);
|
|
||||||
mapToolbar->addWidget(clearTrackButton);
|
|
||||||
ui.mappingPreviewLayout->insertLayout(1, mapToolbar);
|
|
||||||
|
|
||||||
m_agvMapView = new AgvMapViewWidget(ui.mappingPreviewPanel);
|
|
||||||
m_agvMapView->setObjectName(QStringLiteral("agvLiveMap"));
|
|
||||||
m_agvMapView->setStreamMessage(QStringLiteral("连接设备后自动加载实时地图"));
|
|
||||||
ui.mappingPreviewLayout->insertWidget(2, m_agvMapView, 1);
|
|
||||||
leftLayout->addWidget(ui.mappingPreviewPanel, 1);
|
|
||||||
|
|
||||||
QFrame *mapActionsPanel = new QFrame(leftColumn);
|
|
||||||
mapActionsPanel->setObjectName(QStringLiteral("panel"));
|
|
||||||
QVBoxLayout *mapActionsLayout = new QVBoxLayout(mapActionsPanel);
|
|
||||||
mapActionsLayout->setContentsMargins(18, 14, 18, 14);
|
|
||||||
mapActionsLayout->setSpacing(9);
|
|
||||||
QLabel *mapActionsTitle = new QLabel(QStringLiteral("地图与建图"),
|
|
||||||
mapActionsPanel);
|
|
||||||
mapActionsTitle->setObjectName(QStringLiteral("sectionTitle"));
|
|
||||||
QLabel *mapActionsSubtitle = new QLabel(
|
|
||||||
QStringLiteral("加载已有地图、重新定位,或创建新的建图会话"),
|
|
||||||
mapActionsPanel);
|
|
||||||
mapActionsSubtitle->setObjectName(QStringLiteral("panelSubtitle"));
|
|
||||||
mapActionsLayout->addWidget(mapActionsTitle);
|
|
||||||
mapActionsLayout->addWidget(mapActionsSubtitle);
|
|
||||||
|
|
||||||
QHBoxLayout *mapSelectionRow = new QHBoxLayout;
|
|
||||||
ui.agvMapCombo->setParent(mapActionsPanel);
|
|
||||||
ui.inventoryButton->setParent(mapActionsPanel);
|
|
||||||
ui.switchMapButton->setParent(mapActionsPanel);
|
|
||||||
ui.inventoryButton->setText(QStringLiteral("刷新列表"));
|
|
||||||
ui.switchMapButton->setText(QStringLiteral("加载地图"));
|
|
||||||
mapSelectionRow->addWidget(ui.agvMapCombo, 1);
|
|
||||||
mapSelectionRow->addWidget(ui.inventoryButton);
|
|
||||||
mapSelectionRow->addWidget(ui.switchMapButton);
|
|
||||||
mapActionsLayout->addLayout(mapSelectionRow);
|
|
||||||
|
|
||||||
QPushButton *addMapButton = new QPushButton(QStringLiteral("新增地图"),
|
|
||||||
mapActionsPanel);
|
|
||||||
QPushButton *relocalizeButton = new QPushButton(QStringLiteral("重新定位"),
|
|
||||||
mapActionsPanel);
|
|
||||||
m_agvDeleteMapButton = new QPushButton(QStringLiteral("删除地图"),
|
|
||||||
mapActionsPanel);
|
|
||||||
m_agvDeleteMapButton->setObjectName(QStringLiteral("dangerOutlineButton"));
|
|
||||||
m_agvDeleteMapButton->setEnabled(false);
|
|
||||||
m_agvDeleteMapButton->setToolTip(
|
|
||||||
QStringLiteral("当前边缘系统未提供删除地图接口"));
|
|
||||||
QHBoxLayout *mapOperationRow = new QHBoxLayout;
|
|
||||||
mapOperationRow->addWidget(addMapButton);
|
|
||||||
mapOperationRow->addWidget(relocalizeButton);
|
|
||||||
mapOperationRow->addWidget(m_agvDeleteMapButton);
|
|
||||||
mapActionsLayout->addLayout(mapOperationRow);
|
|
||||||
|
|
||||||
QGridLayout *mappingForm = new QGridLayout;
|
|
||||||
QLabel *mappingNameLabel = new QLabel(QStringLiteral("新地图"),
|
|
||||||
mapActionsPanel);
|
|
||||||
QLabel *mappingDimensionLabel = new QLabel(QStringLiteral("类型"),
|
|
||||||
mapActionsPanel);
|
|
||||||
ui.mappingNameEdit->setParent(mapActionsPanel);
|
|
||||||
ui.mappingDimensionCombo->setParent(mapActionsPanel);
|
|
||||||
ui.mappingRealtimeCheck->setParent(mapActionsPanel);
|
|
||||||
mappingForm->addWidget(mappingNameLabel, 0, 0);
|
|
||||||
mappingForm->addWidget(ui.mappingNameEdit, 0, 1);
|
|
||||||
mappingForm->addWidget(mappingDimensionLabel, 0, 2);
|
|
||||||
mappingForm->addWidget(ui.mappingDimensionCombo, 0, 3);
|
|
||||||
mappingForm->addWidget(ui.mappingRealtimeCheck, 1, 1, 1, 3);
|
|
||||||
mappingForm->setColumnStretch(1, 1);
|
|
||||||
mappingForm->setColumnStretch(3, 1);
|
|
||||||
mapActionsLayout->addLayout(mappingForm);
|
|
||||||
|
|
||||||
ui.startMappingButton->setParent(mapActionsPanel);
|
|
||||||
ui.stopMappingButton->setParent(mapActionsPanel);
|
|
||||||
QHBoxLayout *mappingButtonRow = new QHBoxLayout;
|
|
||||||
mappingButtonRow->addWidget(ui.startMappingButton);
|
|
||||||
mappingButtonRow->addWidget(ui.stopMappingButton);
|
|
||||||
mapActionsLayout->addLayout(mappingButtonRow);
|
|
||||||
|
|
||||||
ui.uploadMapButton->setParent(mapActionsPanel);
|
|
||||||
ui.downloadMapButton->setParent(mapActionsPanel);
|
|
||||||
QHBoxLayout *transferRow = new QHBoxLayout;
|
|
||||||
transferRow->addWidget(ui.uploadMapButton);
|
|
||||||
transferRow->addWidget(ui.downloadMapButton);
|
|
||||||
mapActionsLayout->addLayout(transferRow);
|
|
||||||
leftLayout->addWidget(mapActionsPanel);
|
|
||||||
|
|
||||||
statusUi.agvDialogSurface->setGraphicsEffect(nullptr);
|
|
||||||
statusUi.agvDialogSurface->setParent(rightColumn);
|
|
||||||
statusUi.agvDialogSurface->setMinimumSize(0, 0);
|
|
||||||
statusUi.agvDialogTitleBar->hide();
|
|
||||||
statusUi.agvDialogContentLayout->setContentsMargins(0, 0, 0, 0);
|
|
||||||
statusUi.navigationStatusPanel->setMaximumHeight(150);
|
|
||||||
rightLayout->addWidget(statusUi.agvDialogSurface, 3);
|
|
||||||
|
|
||||||
ui.velocityPanel->setParent(rightColumn);
|
|
||||||
ui.velocityPanel->setMinimumSize(0, 0);
|
|
||||||
ui.velocityTitle->setText(QStringLiteral("手动速度控制"));
|
|
||||||
ui.velocitySubtitle->setText(
|
|
||||||
QStringLiteral("按住方向按钮或 Q/W/E/A/S/D 键运动,松开即停止"));
|
|
||||||
m_agvVxSpin->setMinimum(0.0);
|
|
||||||
m_agvVySpin->setMinimum(0.0);
|
|
||||||
m_agvWzSpin->setMinimum(0.0);
|
|
||||||
if (qFuzzyIsNull(m_agvVySpin->value()))
|
|
||||||
m_agvVySpin->setValue(0.2);
|
|
||||||
ui.rotateLeftButton->setText(QStringLiteral("左旋 (Q)"));
|
|
||||||
ui.forwardButton->setText(QStringLiteral("前进 (W)"));
|
|
||||||
ui.rotateRightButton->setText(QStringLiteral("右旋 (E)"));
|
|
||||||
ui.leftButton->setText(QStringLiteral("左移 (A)"));
|
|
||||||
ui.rightButton->setText(QStringLiteral("右移 (D)"));
|
|
||||||
ui.backwardButton->setText(QStringLiteral("后退 (S)"));
|
|
||||||
ui.velocityButton->hide();
|
|
||||||
rightLayout->addWidget(ui.velocityPanel, 4);
|
|
||||||
|
|
||||||
const auto removeOriginalTab = [tabs = ui.agvTabs](QWidget *tab) {
|
|
||||||
const int index = tabs->indexOf(tab);
|
|
||||||
if (index >= 0)
|
|
||||||
tabs->removeTab(index);
|
|
||||||
};
|
|
||||||
removeOriginalTab(ui.manualTab);
|
|
||||||
removeOriginalTab(ui.mapTab);
|
|
||||||
removeOriginalTab(ui.mappingTab);
|
|
||||||
ui.agvTabs->insertTab(0, m_agvControlWorkspace,
|
|
||||||
QStringLiteral("控制与建图"));
|
|
||||||
ui.agvTabs->setCurrentWidget(m_agvControlWorkspace);
|
|
||||||
|
|
||||||
connect(zoomOutButton, &QPushButton::clicked,
|
|
||||||
m_agvMapView, &AgvMapViewWidget::zoomOut);
|
|
||||||
connect(zoomInButton, &QPushButton::clicked,
|
|
||||||
m_agvMapView, &AgvMapViewWidget::zoomIn);
|
|
||||||
connect(resetViewButton, &QPushButton::clicked,
|
|
||||||
m_agvMapView, &AgvMapViewWidget::resetView);
|
|
||||||
connect(clearTrackButton, &QPushButton::clicked,
|
|
||||||
m_agvMapView, &AgvMapViewWidget::clearTrajectory);
|
|
||||||
connect(addMapButton, &QPushButton::clicked, this,
|
|
||||||
[this, nameEdit = ui.mappingNameEdit]() {
|
|
||||||
bool accepted = false;
|
|
||||||
const QString name = QInputDialog::getText(
|
|
||||||
this, QStringLiteral("新增地图"), QStringLiteral("地图名称"),
|
|
||||||
QLineEdit::Normal, nameEdit->text(), &accepted).trimmed();
|
|
||||||
if (!accepted || name.isEmpty())
|
|
||||||
return;
|
|
||||||
nameEdit->setText(name);
|
|
||||||
nameEdit->setFocus();
|
|
||||||
});
|
|
||||||
connect(relocalizeButton, &QPushButton::clicked, this, [this]() {
|
|
||||||
QDialog dialog(this);
|
|
||||||
dialog.setWindowTitle(QStringLiteral("AGV 重新定位"));
|
|
||||||
QFormLayout *form = new QFormLayout(&dialog);
|
|
||||||
QDoubleSpinBox *xSpin = new QDoubleSpinBox(&dialog);
|
|
||||||
QDoubleSpinBox *ySpin = new QDoubleSpinBox(&dialog);
|
|
||||||
QDoubleSpinBox *thetaSpin = new QDoubleSpinBox(&dialog);
|
|
||||||
for (QDoubleSpinBox *spin : {xSpin, ySpin}) {
|
|
||||||
spin->setRange(-10000.0, 10000.0);
|
|
||||||
spin->setDecimals(3);
|
|
||||||
spin->setSuffix(QStringLiteral(" m"));
|
|
||||||
}
|
|
||||||
thetaSpin->setRange(-6.283, 6.283);
|
|
||||||
thetaSpin->setDecimals(3);
|
|
||||||
thetaSpin->setSuffix(QStringLiteral(" rad"));
|
|
||||||
xSpin->setValue(m_latestAgvState.value(QStringLiteral("x")).toDouble());
|
|
||||||
ySpin->setValue(m_latestAgvState.value(QStringLiteral("y")).toDouble());
|
|
||||||
thetaSpin->setValue(
|
|
||||||
m_latestAgvState.value(QStringLiteral("theta")).toDouble());
|
|
||||||
form->addRow(QStringLiteral("X"), xSpin);
|
|
||||||
form->addRow(QStringLiteral("Y"), ySpin);
|
|
||||||
form->addRow(QStringLiteral("航向"), thetaSpin);
|
|
||||||
QDialogButtonBox *buttons = new QDialogButtonBox(
|
|
||||||
QDialogButtonBox::Ok | QDialogButtonBox::Cancel, &dialog);
|
|
||||||
connect(buttons, &QDialogButtonBox::accepted,
|
|
||||||
&dialog, &QDialog::accept);
|
|
||||||
connect(buttons, &QDialogButtonBox::rejected,
|
|
||||||
&dialog, &QDialog::reject);
|
|
||||||
form->addRow(buttons);
|
|
||||||
if (dialog.exec() == QDialog::Accepted) {
|
|
||||||
m_client->requestAgvRelocalize(
|
|
||||||
m_agvIdEdit->text().trimmed(), xSpin->value(),
|
|
||||||
ySpin->value(), thetaSpin->value());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
connect(ui.refreshButton, &QPushButton::clicked, this, [this]() {
|
connect(ui.refreshButton, &QPushButton::clicked, this, [this]() {
|
||||||
m_client->requestAgvRefresh(m_agvIdEdit->text().trimmed());
|
m_client->requestAgvRefresh(m_agvIdEdit->text().trimmed());
|
||||||
});
|
});
|
||||||
|
connect(statusUi.refreshDialogButton, &QPushButton::clicked, this, [this]() {
|
||||||
|
m_client->requestAgvRefresh(m_agvIdEdit->text().trimmed());
|
||||||
|
});
|
||||||
connect(m_agvStatusRefreshTimer, &QTimer::timeout, this, [this]() {
|
connect(m_agvStatusRefreshTimer, &QTimer::timeout, this, [this]() {
|
||||||
if (m_connected && m_pages && m_pages->currentIndex() == 3)
|
if (m_connected && m_agvStatusSwitch && m_agvStatusSwitch->isChecked())
|
||||||
m_client->requestAgvRefresh(m_agvIdEdit->text().trimmed());
|
m_client->requestAgvRefresh(m_agvIdEdit->text().trimmed());
|
||||||
});
|
});
|
||||||
|
connect(m_agvStatusSwitch, &QCheckBox::toggled, this, [this](bool checked) {
|
||||||
|
if (!m_agvStatusDialog)
|
||||||
|
return;
|
||||||
|
if (!checked) {
|
||||||
|
m_agvStatusRefreshTimer->stop();
|
||||||
|
m_agvStatusDialog->hide();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const QRect owner = frameGeometry();
|
||||||
|
const int x = qMax(owner.left() + 24,
|
||||||
|
owner.right() - m_agvStatusDialog->width() - 24);
|
||||||
|
m_agvStatusDialog->move(x, owner.top() + 88);
|
||||||
|
m_agvStatusDialog->show();
|
||||||
|
m_agvStatusDialog->raise();
|
||||||
|
m_agvStatusDialog->activateWindow();
|
||||||
|
if (m_connected) {
|
||||||
|
m_client->requestAgvRefresh(m_agvIdEdit->text().trimmed());
|
||||||
|
m_agvStatusRefreshTimer->start();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
connect(m_agvStatusDialog, &QDialog::finished, this, [this](int) {
|
||||||
|
if (m_agvStatusSwitch)
|
||||||
|
m_agvStatusSwitch->setChecked(false);
|
||||||
|
});
|
||||||
connect(ui.navigatePoseButton, &QPushButton::clicked, this, [this]() {
|
connect(ui.navigatePoseButton, &QPushButton::clicked, this, [this]() {
|
||||||
m_client->requestAgvNavigatePose(m_agvIdEdit->text().trimmed(), m_agvXSpin->value(),
|
m_client->requestAgvNavigatePose(m_agvIdEdit->text().trimmed(), m_agvXSpin->value(),
|
||||||
m_agvYSpin->value(), m_agvThetaSpin->value(),
|
m_agvYSpin->value(), m_agvThetaSpin->value(),
|
||||||
@ -1390,34 +1108,36 @@ QWidget *MainWindow::createAgvPage()
|
|||||||
connect(ui.cancelButton, &QPushButton::clicked, this, [this]() {
|
connect(ui.cancelButton, &QPushButton::clicked, this, [this]() {
|
||||||
m_client->requestAgvAction(m_agvIdEdit->text().trimmed(), QStringLiteral("Cancel"));
|
m_client->requestAgvAction(m_agvIdEdit->text().trimmed(), QStringLiteral("Cancel"));
|
||||||
});
|
});
|
||||||
connect(ui.forwardButton, &QPushButton::pressed, this, [this]() {
|
connect(ui.velocityButton, &QPushButton::clicked, this, [this]() {
|
||||||
startAgvManualMotion(qAbs(m_agvVxSpin->value()), 0.0, 0.0);
|
m_client->requestAgvVelocity(m_agvIdEdit->text().trimmed(), m_agvVxSpin->value(),
|
||||||
|
m_agvVySpin->value(), m_agvWzSpin->value());
|
||||||
});
|
});
|
||||||
connect(ui.backwardButton, &QPushButton::pressed, this, [this]() {
|
const auto sendManualVelocity = [this](double vx, double vy, double wz) {
|
||||||
startAgvManualMotion(-qAbs(m_agvVxSpin->value()), 0.0, 0.0);
|
m_client->requestAgvVelocity(m_agvIdEdit->text().trimmed(), vx, vy, wz);
|
||||||
|
};
|
||||||
|
connect(ui.forwardButton, &QPushButton::clicked, this, [this, sendManualVelocity]() {
|
||||||
|
sendManualVelocity(qAbs(m_agvVxSpin->value()), 0.0, 0.0);
|
||||||
});
|
});
|
||||||
connect(ui.leftButton, &QPushButton::pressed, this, [this]() {
|
connect(ui.backwardButton, &QPushButton::clicked, this, [this, sendManualVelocity]() {
|
||||||
startAgvManualMotion(0.0, qAbs(m_agvVySpin->value()), 0.0);
|
sendManualVelocity(-qAbs(m_agvVxSpin->value()), 0.0, 0.0);
|
||||||
});
|
});
|
||||||
connect(ui.rightButton, &QPushButton::pressed, this, [this]() {
|
connect(ui.leftButton, &QPushButton::clicked, this, [this, sendManualVelocity]() {
|
||||||
startAgvManualMotion(0.0, -qAbs(m_agvVySpin->value()), 0.0);
|
sendManualVelocity(0.0, qAbs(m_agvVySpin->value()), 0.0);
|
||||||
});
|
});
|
||||||
connect(ui.rotateLeftButton, &QPushButton::pressed, this, [this]() {
|
connect(ui.rightButton, &QPushButton::clicked, this, [this, sendManualVelocity]() {
|
||||||
startAgvManualMotion(0.0, 0.0, qAbs(m_agvWzSpin->value()));
|
sendManualVelocity(0.0, -qAbs(m_agvVySpin->value()), 0.0);
|
||||||
});
|
});
|
||||||
connect(ui.rotateRightButton, &QPushButton::pressed, this, [this]() {
|
connect(ui.rotateLeftButton, &QPushButton::clicked, this, [this, sendManualVelocity]() {
|
||||||
startAgvManualMotion(0.0, 0.0, -qAbs(m_agvWzSpin->value()));
|
sendManualVelocity(0.0, 0.0, qAbs(m_agvWzSpin->value()));
|
||||||
|
});
|
||||||
|
connect(ui.rotateRightButton, &QPushButton::clicked, this, [this, sendManualVelocity]() {
|
||||||
|
sendManualVelocity(0.0, 0.0, -qAbs(m_agvWzSpin->value()));
|
||||||
|
});
|
||||||
|
connect(ui.manualStopButton, &QPushButton::clicked, this, [this]() {
|
||||||
|
m_client->requestAgvAction(m_agvIdEdit->text().trimmed(),
|
||||||
|
QStringLiteral("StopVelocity"));
|
||||||
});
|
});
|
||||||
for (QPushButton *button : {
|
|
||||||
ui.forwardButton, ui.backwardButton, ui.leftButton,
|
|
||||||
ui.rightButton, ui.rotateLeftButton, ui.rotateRightButton}) {
|
|
||||||
connect(button, &QPushButton::released, this,
|
|
||||||
[this]() { stopAgvManualMotion(); });
|
|
||||||
}
|
|
||||||
connect(ui.manualStopButton, &QPushButton::clicked, this,
|
|
||||||
[this]() { stopAgvManualMotion(); });
|
|
||||||
connect(ui.zeroVelocityButton, &QPushButton::clicked, this, [this]() {
|
connect(ui.zeroVelocityButton, &QPushButton::clicked, this, [this]() {
|
||||||
stopAgvManualMotion();
|
|
||||||
m_agvVxSpin->setValue(0.0);
|
m_agvVxSpin->setValue(0.0);
|
||||||
m_agvVySpin->setValue(0.0);
|
m_agvVySpin->setValue(0.0);
|
||||||
m_agvWzSpin->setValue(0.0);
|
m_agvWzSpin->setValue(0.0);
|
||||||
@ -1574,7 +1294,7 @@ QWidget *MainWindow::createAgvPage()
|
|||||||
<< ui.pauseButton << ui.resumeButton << ui.cancelButton
|
<< ui.pauseButton << ui.resumeButton << ui.cancelButton
|
||||||
<< ui.velocityButton << statusUi.stopVelocityButton
|
<< ui.velocityButton << statusUi.stopVelocityButton
|
||||||
<< statusUi.clearFaultButton
|
<< statusUi.clearFaultButton
|
||||||
<< ui.emergencyButton << ui.inventoryButton << ui.switchMapButton << relocalizeButton
|
<< ui.emergencyButton << ui.inventoryButton << ui.switchMapButton
|
||||||
<< ui.forwardButton << ui.backwardButton << ui.leftButton << ui.rightButton
|
<< ui.forwardButton << ui.backwardButton << ui.leftButton << ui.rightButton
|
||||||
<< ui.rotateLeftButton << ui.rotateRightButton << ui.manualStopButton
|
<< ui.rotateLeftButton << ui.rotateRightButton << ui.manualStopButton
|
||||||
<< ui.followPathButton << ui.startMappingButton << ui.stopMappingButton
|
<< ui.followPathButton << ui.startMappingButton << ui.stopMappingButton
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
#include "robotclient.h"
|
#include "robotclient.h"
|
||||||
#include "videodecoder.h"
|
#include "videodecoder.h"
|
||||||
|
#include "tcpjogcontroller.h"
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QElapsedTimer>
|
#include <QElapsedTimer>
|
||||||
@ -15,6 +16,7 @@
|
|||||||
#include <QtMath>
|
#include <QtMath>
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <cmath>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
@ -529,6 +531,146 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void getTcpCalibrationPose(const QString &deviceId, quint64 requestId)
|
||||||
|
{
|
||||||
|
const QString selectedDevice = deviceId.trimmed();
|
||||||
|
const auto reject = [this, requestId, selectedDevice](const QString &detail) {
|
||||||
|
emit tcpCalibrationPoseReceived(requestId, selectedDevice, {}, {}, false, detail);
|
||||||
|
};
|
||||||
|
if (m_demoMode) {
|
||||||
|
reject(QStringLiteral("TCP 标定不接受演示数据,请连接真实机械臂"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!m_connected || selectedDevice.isEmpty()) {
|
||||||
|
reject(QStringLiteral("TCP 标定采样失败:服务未连接或设备 ID 为空"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#ifdef CMVR_WITH_GRPC
|
||||||
|
if (!m_arm) {
|
||||||
|
reject(QStringLiteral("TCP 标定采样失败:机械臂服务不可用"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cmvr::api::GetArmInfo::Request infoRequest;
|
||||||
|
fillHeader(infoRequest.mutable_header(), selectedDevice);
|
||||||
|
cmvr::api::GetArmInfo::Response info;
|
||||||
|
grpc::ClientContext infoContext;
|
||||||
|
setDeadline(infoContext, 1500);
|
||||||
|
const grpc::Status infoStatus = m_arm->GetArmInfo(&infoContext, infoRequest, &info);
|
||||||
|
if (!infoStatus.ok() || !info.header().success()
|
||||||
|
|| QString::fromStdString(info.device_id()).trimmed() != selectedDevice) {
|
||||||
|
reject(QStringLiteral("TCP 标定采样失败:无法确认机械臂驱动身份"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const QString driver = QString::fromStdString(info.driver_type()).trimmed().toLower();
|
||||||
|
const QString manufacturer = QString::fromStdString(info.manufacturer()).trimmed().toLower();
|
||||||
|
const bool auboDriver = driver == QStringLiteral("auboarm")
|
||||||
|
|| driver == QStringLiteral("aubo_arm");
|
||||||
|
const bool auboManufacturer = manufacturer == QStringLiteral("aubo")
|
||||||
|
|| manufacturer == QStringLiteral("auboarm");
|
||||||
|
if (!auboDriver && !(driver.isEmpty() && auboManufacturer)) {
|
||||||
|
reject(QStringLiteral("当前驱动尚未适配 TCP 标定所需的姿态及运动约定:%1")
|
||||||
|
.arg(QString::fromStdString(info.driver_type())));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// A fresh state request deliberately bypasses display telemetry and named
|
||||||
|
// getPose: some drivers silently ignore its requested base/flange names.
|
||||||
|
cmvr::api::GetRobotState::Request request;
|
||||||
|
fillHeader(request.mutable_header(), selectedDevice);
|
||||||
|
cmvr::api::GetRobotState::Response response;
|
||||||
|
grpc::ClientContext context;
|
||||||
|
setDeadline(context, 1500);
|
||||||
|
const qint64 requestedAtMs = QDateTime::currentMSecsSinceEpoch();
|
||||||
|
const grpc::Status status = m_arm->getRobotState(&context, request, &response);
|
||||||
|
const qint64 receivedAtMs = QDateTime::currentMSecsSinceEpoch();
|
||||||
|
if (!status.ok() || !response.header().success()) {
|
||||||
|
const QString error = status.ok()
|
||||||
|
? QString::fromStdString(response.header().error_message())
|
||||||
|
: QString::fromStdString(status.error_message());
|
||||||
|
reject(QStringLiteral("TCP 标定实时采样失败:%1").arg(error));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!response.has_state()) {
|
||||||
|
reject(QStringLiteral("TCP 标定采样失败:服务未返回机械臂状态"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto &robotState = response.state();
|
||||||
|
if (!robotState.connected() || robotState.moving() || robotState.fault()
|
||||||
|
|| robotState.protective_stopped() || robotState.emergency_stopped()) {
|
||||||
|
reject(QStringLiteral("TCP 标定采样失败:机械臂未连接、正在运动或存在故障/停止状态"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ((robotState.safety_mode() != cmvr::api::ARM_SAFETY_MODE_NORMAL
|
||||||
|
&& robotState.safety_mode() != cmvr::api::ARM_SAFETY_MODE_REDUCED)
|
||||||
|
|| (robotState.robot_mode() != cmvr::api::ARM_ROBOT_MODE_IDLE
|
||||||
|
&& robotState.robot_mode() != cmvr::api::ARM_ROBOT_MODE_PAUSED)) {
|
||||||
|
reject(QStringLiteral("TCP 标定采样失败:机械臂未处于可确认的静止安全状态"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!robotState.has_actual_tcp_pose() || !robotState.has_actual_joint_state()
|
||||||
|
|| !std::isfinite(robotState.timestamp()) || robotState.timestamp() < 0.0) {
|
||||||
|
reject(QStringLiteral("TCP 标定采样失败:缺少有效 TCP 位姿、关节状态或时间戳"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto &joints = robotState.actual_joint_state();
|
||||||
|
if (info.dof() == 0 || joints.position_size() != static_cast<int>(info.dof())
|
||||||
|
|| joints.velocity_size() != joints.position_size()
|
||||||
|
|| (joints.name_size() != 0 && joints.name_size() != joints.position_size())) {
|
||||||
|
reject(QStringLiteral("TCP 标定采样失败:关节速度缺失或维度不一致"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bool allJointsZero = true;
|
||||||
|
for (int i = 0; i < joints.position_size(); ++i) {
|
||||||
|
if (!std::isfinite(joints.position(i)) || !std::isfinite(joints.velocity(i))
|
||||||
|
|| std::abs(joints.velocity(i)) > 0.01) {
|
||||||
|
reject(QStringLiteral("TCP 标定采样失败:关节数据无效或机械臂尚未静止"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
allJointsZero = allJointsZero && joints.position(i) == 0.0 && joints.velocity(i) == 0.0;
|
||||||
|
}
|
||||||
|
// This backend also zero-fills joint arrays when an SDK read fails.
|
||||||
|
if (allJointsZero) {
|
||||||
|
reject(QStringLiteral("TCP 标定采样失败:关节反馈全零,无法排除 SDK 读取失败,请更换姿态后重试"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto &tcp = robotState.actual_tcp_pose();
|
||||||
|
const double values[] = {tcp.x(), tcp.y(), tcp.z(), tcp.rx(), tcp.ry(), tcp.rz()};
|
||||||
|
bool allZero = true;
|
||||||
|
for (double value : values) {
|
||||||
|
if (!std::isfinite(value)) {
|
||||||
|
reject(QStringLiteral("TCP 标定采样失败:TCP 位姿包含非有限数值"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
allZero = allZero && value == 0.0;
|
||||||
|
}
|
||||||
|
// Existing AUBO backend returns a zero pose on SDK read failure.
|
||||||
|
if (allZero) {
|
||||||
|
reject(QStringLiteral("TCP 标定采样失败:服务返回全零位姿,无法排除 SDK 读取失败"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const QVariantMap pose = {
|
||||||
|
{QStringLiteral("x"), tcp.x()}, {QStringLiteral("y"), tcp.y()},
|
||||||
|
{QStringLiteral("z"), tcp.z()}, {QStringLiteral("rx"), tcp.rx()},
|
||||||
|
{QStringLiteral("ry"), tcp.ry()}, {QStringLiteral("rz"), tcp.rz()}};
|
||||||
|
const QVariantMap state = {
|
||||||
|
{QStringLiteral("connected"), robotState.connected()},
|
||||||
|
{QStringLiteral("moving"), robotState.moving()},
|
||||||
|
{QStringLiteral("fault"), robotState.fault()},
|
||||||
|
{QStringLiteral("protectiveStopped"), robotState.protective_stopped()},
|
||||||
|
{QStringLiteral("emergencyStopped"), robotState.emergency_stopped()},
|
||||||
|
{QStringLiteral("timestamp"), robotState.timestamp()},
|
||||||
|
{QStringLiteral("serverTimestampAvailable"), robotState.timestamp() > 0.0},
|
||||||
|
{QStringLiteral("requestedAtMs"), requestedAtMs},
|
||||||
|
{QStringLiteral("receivedAtMs"), receivedAtMs},
|
||||||
|
{QStringLiteral("driverType"), QString::fromStdString(info.driver_type())},
|
||||||
|
{QStringLiteral("manufacturer"), QString::fromStdString(info.manufacturer())},
|
||||||
|
{QStringLiteral("source"), QStringLiteral("getRobotState.actual_tcp_pose")}};
|
||||||
|
emit tcpCalibrationPoseReceived(requestId, selectedDevice, pose, state, true,
|
||||||
|
QStringLiteral("已实时读取当前 TCP 位姿;需用已确认的当前 TCP 偏置换算为法兰位姿"));
|
||||||
|
#else
|
||||||
|
reject(QStringLiteral("当前构建未启用 gRPC,无法采集真实 TCP 位姿"));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void getArmFrames(const QString &deviceId)
|
void getArmFrames(const QString &deviceId)
|
||||||
{
|
{
|
||||||
if (!ensureConnected(QStringLiteral("List Arm Frames"))
|
if (!ensureConnected(QStringLiteral("List Arm Frames"))
|
||||||
@ -696,12 +838,28 @@ public:
|
|||||||
const QString &baseLink, const QString &eeLink,
|
const QString &baseLink, const QString &eeLink,
|
||||||
double velocity, double acceleration)
|
double velocity, double acceleration)
|
||||||
{
|
{
|
||||||
if (!ensureConnected(QStringLiteral("MoveL")))
|
movePoseImpl(deviceId, pose, baseLink, eeLink, velocity, acceleration, QStringLiteral("MoveL"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void tcpJogMove(const QString &deviceId, const QVariantMap &pose,
|
||||||
|
double velocity, double acceleration, quint64 token)
|
||||||
|
{
|
||||||
|
// The verified driver resolves "tcp" to its current active offset.
|
||||||
|
// Never pass a local profile name as a controller frame identifier.
|
||||||
|
movePoseImpl(deviceId, pose, QStringLiteral("base"), QStringLiteral("tcp"),
|
||||||
|
velocity, acceleration, TcpJogController::commandName(token));
|
||||||
|
}
|
||||||
|
|
||||||
|
void movePoseImpl(const QString &deviceId, const QVariantMap &pose,
|
||||||
|
const QString &baseLink, const QString &eeLink,
|
||||||
|
double velocity, double acceleration, const QString &command)
|
||||||
|
{
|
||||||
|
if (!ensureConnected(command))
|
||||||
return;
|
return;
|
||||||
if (!ensureDeviceId(QStringLiteral("MoveL"), deviceId))
|
if (!ensureDeviceId(command, deviceId))
|
||||||
return;
|
return;
|
||||||
if (m_demoMode) {
|
if (m_demoMode) {
|
||||||
emit commandFinished(QStringLiteral("MoveL"), true,
|
emit commandFinished(command, true,
|
||||||
QStringLiteral("已发送末端位姿 MoveL,%1 → %2,v=%3,a=%4")
|
QStringLiteral("已发送末端位姿 MoveL,%1 → %2,v=%3,a=%4")
|
||||||
.arg(baseLink, eeLink)
|
.arg(baseLink, eeLink)
|
||||||
.arg(velocity, 0, 'f', 2)
|
.arg(velocity, 0, 'f', 2)
|
||||||
@ -726,7 +884,7 @@ public:
|
|||||||
if (!eeLink.trimmed().isEmpty())
|
if (!eeLink.trimmed().isEmpty())
|
||||||
request.set_tcp_frame(eeLink.trimmed().toStdString());
|
request.set_tcp_frame(eeLink.trimmed().toStdString());
|
||||||
startArmMotion<cmvr::api::MoveL::Request, cmvr::api::MoveL::Response>(
|
startArmMotion<cmvr::api::MoveL::Request, cmvr::api::MoveL::Response>(
|
||||||
QStringLiteral("MoveL"), std::move(request),
|
command, std::move(request),
|
||||||
[](cmvr::api::ArmService::Stub &stub, grpc::ClientContext *context,
|
[](cmvr::api::ArmService::Stub &stub, grpc::ClientContext *context,
|
||||||
const cmvr::api::MoveL::Request &motionRequest,
|
const cmvr::api::MoveL::Request &motionRequest,
|
||||||
cmvr::api::MoveL::Response *response) {
|
cmvr::api::MoveL::Response *response) {
|
||||||
@ -761,6 +919,7 @@ public:
|
|||||||
|
|
||||||
void armStop(const QString &deviceId)
|
void armStop(const QString &deviceId)
|
||||||
{
|
{
|
||||||
|
stopArmMotionInternal();
|
||||||
if (!ensureConnected(QStringLiteral("Stop Motion")))
|
if (!ensureConnected(QStringLiteral("Stop Motion")))
|
||||||
return;
|
return;
|
||||||
if (!ensureDeviceId(QStringLiteral("Stop Motion"), deviceId))
|
if (!ensureDeviceId(QStringLiteral("Stop Motion"), deviceId))
|
||||||
@ -897,6 +1056,161 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void getHandEyeImage(const QString &cameraId, quint64 token)
|
||||||
|
{
|
||||||
|
const QString selectedCamera = cameraId.trimmed();
|
||||||
|
const auto reject = [this, token, selectedCamera](const QString &detail) {
|
||||||
|
emit handEyeImageReceived(token, selectedCamera, {}, {}, {}, false, detail);
|
||||||
|
};
|
||||||
|
if (m_demoMode) {
|
||||||
|
reject(QStringLiteral("手眼标定不接受演示图像,请连接真实相机"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!m_connected || selectedCamera.isEmpty()) {
|
||||||
|
reject(QStringLiteral("手眼图像采集失败:服务未连接或相机 ID 为空"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#ifdef CMVR_WITH_GRPC
|
||||||
|
if (!m_camera) {
|
||||||
|
reject(QStringLiteral("手眼图像采集失败:相机服务不可用"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cmvr::api::GetRGBImageCommand::Request request;
|
||||||
|
fillHeader(request.mutable_header(), selectedCamera);
|
||||||
|
cmvr::api::GetRGBImageCommand::Feedback response;
|
||||||
|
grpc::ClientContext context;
|
||||||
|
setDeadline(context, 3000);
|
||||||
|
const qint64 requestedAtMs = QDateTime::currentMSecsSinceEpoch();
|
||||||
|
const grpc::Status status = m_camera->GetRGBImage(&context, request, &response);
|
||||||
|
const qint64 receivedAtMs = QDateTime::currentMSecsSinceEpoch();
|
||||||
|
if (!status.ok() || !response.header().success()) {
|
||||||
|
reject(QStringLiteral("手眼图像采集失败:%1").arg(status.ok()
|
||||||
|
? QString::fromStdString(response.header().error_message())
|
||||||
|
: QString::fromStdString(status.error_message())));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!response.has_color_frame() || !response.has_intrinsics()) {
|
||||||
|
reject(QStringLiteral("相机未返回完整的彩色图像和对应内参"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto &frame = response.color_frame();
|
||||||
|
const QString codec = QString::fromStdString(frame.codec()).trimmed().toLower();
|
||||||
|
const int channels = frame.type() == cmvr::api::FrameData::U8C3 ? 3
|
||||||
|
: frame.type() == cmvr::api::FrameData::U8C1 ? 1 : 0;
|
||||||
|
// Unary GetRGBImage serializes tightly packed OpenCV BGR/gray bytes.
|
||||||
|
// Bound the multiplication before allocating or constructing a QImage.
|
||||||
|
const qint64 pixels = static_cast<qint64>(frame.width()) * frame.height();
|
||||||
|
if (frame.width() <= 0 || frame.height() <= 0 || channels == 0
|
||||||
|
|| (!codec.isEmpty() && codec != QStringLiteral("none"))
|
||||||
|
|| pixels > kGrpcMaxMessageBytes / channels
|
||||||
|
|| static_cast<quint64>(pixels * channels) != frame.data().size()) {
|
||||||
|
reject(QStringLiteral("相机图像格式、尺寸或数据长度无效;需要原始 BGR8/灰度图像"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto &camera = response.intrinsics();
|
||||||
|
bool validIntrinsics = std::isfinite(camera.fx()) && camera.fx() > 0.0f
|
||||||
|
&& std::isfinite(camera.fy()) && camera.fy() > 0.0f
|
||||||
|
&& std::isfinite(camera.cx()) && std::isfinite(camera.cy())
|
||||||
|
&& camera.coeffs_size() == 5;
|
||||||
|
QVariantList coefficients;
|
||||||
|
for (const float coefficient : camera.coeffs()) {
|
||||||
|
validIntrinsics = validIntrinsics && std::isfinite(coefficient);
|
||||||
|
coefficients.append(static_cast<double>(coefficient));
|
||||||
|
}
|
||||||
|
if (!validIntrinsics) {
|
||||||
|
reject(QStringLiteral("相机彩色内参无效:需要正焦距、有限主点和 5 个有限畸变系数"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto *data = reinterpret_cast<const uchar *>(frame.data().data());
|
||||||
|
const QImage borrowed(data, frame.width(), frame.height(), frame.width() * channels,
|
||||||
|
channels == 3 ? QImage::Format_RGB888 : QImage::Format_Grayscale8);
|
||||||
|
const QImage image = channels == 3 ? borrowed.rgbSwapped() : borrowed.copy();
|
||||||
|
if (image.isNull()) {
|
||||||
|
reject(QStringLiteral("手眼图像解码失败"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const QVariantMap intrinsics = {
|
||||||
|
{QStringLiteral("fx"), camera.fx()}, {QStringLiteral("fy"), camera.fy()},
|
||||||
|
{QStringLiteral("cx"), camera.cx()}, {QStringLiteral("cy"), camera.cy()},
|
||||||
|
{QStringLiteral("coeffs"), coefficients},
|
||||||
|
{QStringLiteral("width"), image.width()}, {QStringLiteral("height"), image.height()},
|
||||||
|
{QStringLiteral("distortionModelAvailable"), false},
|
||||||
|
{QStringLiteral("source"), QStringLiteral("CameraService.GetRGBImage.intrinsics")}};
|
||||||
|
// Older/current unary servers omit these fields. Preserve zero and
|
||||||
|
// advertise the absence; receipt time is not a camera capture time.
|
||||||
|
const bool captureTimestampAvailable = frame.capture_utc_ns() > 0;
|
||||||
|
const QVariantMap metadata = {
|
||||||
|
{QStringLiteral("captureUtcNs"), static_cast<qint64>(frame.capture_utc_ns())},
|
||||||
|
{QStringLiteral("sourceSequence"), static_cast<quint64>(frame.source_sequence())},
|
||||||
|
{QStringLiteral("sourceFrameNumber"), static_cast<quint64>(frame.source_frame_number())},
|
||||||
|
{QStringLiteral("sourceTimestamp"), static_cast<quint64>(frame.source_timestamp())},
|
||||||
|
{QStringLiteral("pts"), static_cast<qint64>(frame.pts())},
|
||||||
|
{QStringLiteral("dts"), static_cast<qint64>(frame.dts())},
|
||||||
|
{QStringLiteral("sourceFps"), frame.source_fps()},
|
||||||
|
{QStringLiteral("requestedAtMs"), requestedAtMs},
|
||||||
|
{QStringLiteral("receivedAtMs"), receivedAtMs},
|
||||||
|
{QStringLiteral("captureTimestampAvailable"), captureTimestampAvailable},
|
||||||
|
{QStringLiteral("source"), QStringLiteral("CameraService.GetRGBImage.color_frame")}};
|
||||||
|
emit handEyeImageReceived(token, selectedCamera, image, intrinsics, metadata, true,
|
||||||
|
captureTimestampAvailable
|
||||||
|
? QStringLiteral("已获取原始图像、对应内参及采集时间戳")
|
||||||
|
: QStringLiteral("已获取图像和内参;服务未提供图像采集时间戳,不能确认与机械臂位姿同步"));
|
||||||
|
#else
|
||||||
|
reject(QStringLiteral("当前构建未启用 gRPC,无法采集真实相机图像"));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void getTouchRgbdImage(const QString &cameraId, quint64 token)
|
||||||
|
{
|
||||||
|
const auto reject=[&](const QString &detail) { touchRgbdImageReceived(token,cameraId,{},{},{},false,detail); };
|
||||||
|
if(m_demoMode||!m_connected||cameraId.trimmed().isEmpty()) { reject(QStringLiteral("请连接真实相机服务")); return; }
|
||||||
|
#ifdef CMVR_WITH_GRPC
|
||||||
|
if(!m_camera) { reject(QStringLiteral("相机服务不可用")); return; }
|
||||||
|
cmvr::api::GetRGBDImagesCommand::Request request;
|
||||||
|
fillHeader(request.mutable_header(),cameraId); request.set_require_metric_depth(true);
|
||||||
|
cmvr::api::GetRGBDImagesCommand::Feedback response;
|
||||||
|
grpc::ClientContext context; setDeadline(context,3000);
|
||||||
|
const auto status=m_camera->GetRGBDImages(&context,request,&response);
|
||||||
|
if(!status.ok()||!response.header().success()) {
|
||||||
|
reject(QStringLiteral("GetRGBDImages:%1").arg(QString::fromStdString(status.ok()?response.header().error_message():status.error_message()))); return;
|
||||||
|
}
|
||||||
|
if(!response.has_depth_geometry()) {
|
||||||
|
reject(QStringLiteral("相机服务尚未提供公制深度元数据,请安装随上位机提供的 RGBD 服务补丁。")); return;
|
||||||
|
}
|
||||||
|
const auto &rgb=response.color_frame(); const auto &d=response.depth_frame();
|
||||||
|
const auto &g=response.depth_geometry(); const auto &k=response.intrinsics();
|
||||||
|
const int bytes=d.type()==cmvr::api::FrameData::U16C1?2:d.type()==cmvr::api::FrameData::F32C1?4:0;
|
||||||
|
const qint64 pixels=qint64(rgb.width())*rgb.height();
|
||||||
|
const auto raw=[](const cmvr::api::FrameData &f) { return f.codec().empty()||f.codec()=="none"; };
|
||||||
|
if(rgb.width()<2||rgb.height()<2||rgb.width()>16384||rgb.height()>16384||pixels>kGrpcMaxMessageBytes/7
|
||||||
|
||rgb.type()!=cmvr::api::FrameData::U8C3||!bytes||!raw(rgb)||!raw(d)
|
||||||
|
||d.width()!=rgb.width()||d.height()!=rgb.height()
|
||||||
|
||rgb.data().size()!=quint64(pixels*3)||d.data().size()!=quint64(pixels*bytes)
|
||||||
|
||!g.aligned_to_color()||!g.color_axial_z()||g.byte_order()!="little"
|
||||||
|
||!std::isfinite(g.metres_per_unit())||g.metres_per_unit()<=0||g.metres_per_unit()>1
|
||||||
|
||rgb.capture_utc_ns()<=0||d.capture_utc_ns()<=0
|
||||||
|
||std::abs(rgb.capture_utc_ns()-d.capture_utc_ns())>33000000
|
||||||
|
||(g.distortion_model()!="none"&&g.distortion_model()!="brown_conrady")) {
|
||||||
|
reject(QStringLiteral("RGBD 格式、配准、时间戳或公制深度信息无效")); return;
|
||||||
|
}
|
||||||
|
QVariantList coeffs;
|
||||||
|
for(float value:k.coeffs()) { if(!std::isfinite(value)) { reject(QStringLiteral("RGB 内参无效")); return; } coeffs<<double(value); }
|
||||||
|
if(!std::isfinite(k.fx())||!std::isfinite(k.fy())||k.fx()<=0||k.fy()<=0
|
||||||
|
||!std::isfinite(k.cx())||!std::isfinite(k.cy())||coeffs.size()!=5) { reject(QStringLiteral("RGB 内参无效")); return; }
|
||||||
|
const QImage borrowed(reinterpret_cast<const uchar*>(rgb.data().data()),rgb.width(),rgb.height(),rgb.width()*3,QImage::Format_RGB888);
|
||||||
|
const QImage image=borrowed.rgbSwapped(); // Owning RGB image; raw transport is OpenCV BGR.
|
||||||
|
const QVariantMap intrinsics{{"fx",double(k.fx())},{"fy",double(k.fy())},{"cx",double(k.cx())},{"cy",double(k.cy())},
|
||||||
|
{"width",rgb.width()},{"height",rgb.height()},{"coeffs",coeffs},{"model",QString::fromStdString(g.distortion_model())}};
|
||||||
|
const QVariantMap metadata{{"captureUtcNs",qint64(rgb.capture_utc_ns())},{"depthCaptureUtcNs",qint64(d.capture_utc_ns())},
|
||||||
|
{"alignedToColor",true},{"colorAxialZ",true},{"byteOrder","little"},{"metresPerUnit",g.metres_per_unit()},
|
||||||
|
{"depthWidth",d.width()},{"depthHeight",d.height()},{"depthFloat32",bytes==4},
|
||||||
|
{"depthData",QByteArray(d.data().data(),int(d.data().size()))}};
|
||||||
|
touchRgbdImageReceived(token,cameraId,image,intrinsics,metadata,true,QStringLiteral("已获取同步公制 RGBD"));
|
||||||
|
#else
|
||||||
|
reject(QStringLiteral("当前构建未启用 gRPC"));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void startCameraStream(const QString &cameraId, const QString &codec,
|
void startCameraStream(const QString &cameraId, const QString &codec,
|
||||||
const QString &mode)
|
const QString &mode)
|
||||||
{
|
{
|
||||||
@ -1337,7 +1651,6 @@ public:
|
|||||||
state.insert(QStringLiteral("voltage"), 49.2);
|
state.insert(QStringLiteral("voltage"), 49.2);
|
||||||
state.insert(QStringLiteral("current"), -2.9);
|
state.insert(QStringLiteral("current"), -2.9);
|
||||||
state.insert(QStringLiteral("temperature"), 28.0);
|
state.insert(QStringLiteral("temperature"), 28.0);
|
||||||
state.insert(QStringLiteral("charging"), false);
|
|
||||||
state.insert(QStringLiteral("x"), 1.24);
|
state.insert(QStringLiteral("x"), 1.24);
|
||||||
state.insert(QStringLiteral("y"), -0.36);
|
state.insert(QStringLiteral("y"), -0.36);
|
||||||
state.insert(QStringLiteral("theta"), 0.12);
|
state.insert(QStringLiteral("theta"), 0.12);
|
||||||
@ -1381,7 +1694,6 @@ public:
|
|||||||
state.insert(QStringLiteral("voltage"), source.battery().voltage());
|
state.insert(QStringLiteral("voltage"), source.battery().voltage());
|
||||||
state.insert(QStringLiteral("current"), source.battery().current());
|
state.insert(QStringLiteral("current"), source.battery().current());
|
||||||
state.insert(QStringLiteral("temperature"), source.battery().temperature());
|
state.insert(QStringLiteral("temperature"), source.battery().temperature());
|
||||||
state.insert(QStringLiteral("charging"), source.battery().charging());
|
|
||||||
state.insert(QStringLiteral("x"), source.pose().x());
|
state.insert(QStringLiteral("x"), source.pose().x());
|
||||||
state.insert(QStringLiteral("y"), source.pose().y());
|
state.insert(QStringLiteral("y"), source.pose().y());
|
||||||
state.insert(QStringLiteral("theta"), source.pose().theta());
|
state.insert(QStringLiteral("theta"), source.pose().theta());
|
||||||
@ -1403,36 +1715,6 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void agvRelocalize(const QString &deviceId, double x, double y, double theta)
|
|
||||||
{
|
|
||||||
const QString command = QStringLiteral("AGV Relocalize");
|
|
||||||
if (!ensureConnected(command) || !ensureDeviceId(command, deviceId))
|
|
||||||
return;
|
|
||||||
if (!qIsFinite(x) || !qIsFinite(y) || !qIsFinite(theta)) {
|
|
||||||
emit commandFinished(command, false,
|
|
||||||
QStringLiteral("重新定位位姿必须是有效数值"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (m_demoMode) {
|
|
||||||
emit commandFinished(command, true,
|
|
||||||
QStringLiteral("重新定位位姿已下发"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#ifdef CMVR_WITH_GRPC
|
|
||||||
cmvr::api::AgvRelocalizeCommand::Request request;
|
|
||||||
fillHeader(request.mutable_header(), deviceId);
|
|
||||||
request.mutable_pose()->set_x(x);
|
|
||||||
request.mutable_pose()->set_y(y);
|
|
||||||
request.mutable_pose()->set_theta(theta);
|
|
||||||
cmvr::api::AgvRelocalizeCommand::Feedback response;
|
|
||||||
grpc::ClientContext context;
|
|
||||||
setDeadline(context, 2500);
|
|
||||||
const grpc::Status status = m_agv->relocalize(&context, request, &response);
|
|
||||||
finish(command, status, response.header().success(),
|
|
||||||
QString::fromStdString(response.header().error_message()));
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void agvNavigatePose(const QString &deviceId, double x, double y, double theta, double maxSpeed)
|
void agvNavigatePose(const QString &deviceId, double x, double y, double theta, double maxSpeed)
|
||||||
{
|
{
|
||||||
if (!ensureConnected(QStringLiteral("AGV NavigateToPose")) ||
|
if (!ensureConnected(QStringLiteral("AGV NavigateToPose")) ||
|
||||||
@ -1719,20 +2001,7 @@ public:
|
|||||||
<< QPointF(260, 302);
|
<< QPointF(260, 302);
|
||||||
painter.drawPolygon(robot);
|
painter.drawPolygon(robot);
|
||||||
painter.end();
|
painter.end();
|
||||||
QVariantMap metadata;
|
emit agvMapFrameReceived(image, QStringLiteral("演示 2D 地图 · 6 个站点"));
|
||||||
metadata.insert(QStringLiteral("mapId"), QStringLiteral("demo_map"));
|
|
||||||
metadata.insert(QStringLiteral("dimension"), 2);
|
|
||||||
metadata.insert(QStringLiteral("originX"), 0.0);
|
|
||||||
metadata.insert(QStringLiteral("originY"), 0.0);
|
|
||||||
metadata.insert(QStringLiteral("originTheta"), 0.0);
|
|
||||||
metadata.insert(QStringLiteral("resolution"), 0.01);
|
|
||||||
metadata.insert(QStringLiteral("sourceWidth"), image.width());
|
|
||||||
metadata.insert(QStringLiteral("sourceHeight"), image.height());
|
|
||||||
metadata.insert(QStringLiteral("renderScale"), 1.0);
|
|
||||||
metadata.insert(QStringLiteral("timestamp"),
|
|
||||||
QDateTime::currentMSecsSinceEpoch() / 1000.0);
|
|
||||||
emit agvMapFrameReceived(image, metadata,
|
|
||||||
QStringLiteral("演示 2D 地图 · 6 个站点"));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1760,7 +2029,6 @@ public:
|
|||||||
continue;
|
continue;
|
||||||
const auto &update = response.update();
|
const auto &update = response.update();
|
||||||
QImage image;
|
QImage image;
|
||||||
QVariantMap metadata;
|
|
||||||
QString detail;
|
QString detail;
|
||||||
if (update.has_map_2d()) {
|
if (update.has_map_2d()) {
|
||||||
const auto &map = update.map_2d();
|
const auto &map = update.map_2d();
|
||||||
@ -1819,21 +2087,6 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
painter.end();
|
painter.end();
|
||||||
metadata.insert(QStringLiteral("mapId"),
|
|
||||||
QString::fromStdString(update.map_id()));
|
|
||||||
metadata.insert(QStringLiteral("dimension"), 2);
|
|
||||||
metadata.insert(QStringLiteral("originX"), map.origin().x());
|
|
||||||
metadata.insert(QStringLiteral("originY"), map.origin().y());
|
|
||||||
metadata.insert(QStringLiteral("originTheta"), map.origin().theta());
|
|
||||||
metadata.insert(QStringLiteral("resolution"), resolution);
|
|
||||||
metadata.insert(QStringLiteral("sourceWidth"), sourceWidth);
|
|
||||||
metadata.insert(QStringLiteral("sourceHeight"), sourceHeight);
|
|
||||||
metadata.insert(QStringLiteral("renderScale"), scale);
|
|
||||||
metadata.insert(QStringLiteral("timestamp"), map.timestamp());
|
|
||||||
metadata.insert(QStringLiteral("sequence"),
|
|
||||||
static_cast<qulonglong>(update.sequence()));
|
|
||||||
metadata.insert(QStringLiteral("updateType"),
|
|
||||||
static_cast<int>(update.update_type()));
|
|
||||||
detail = QStringLiteral("%1 · 2D · %2×%3 · seq %4")
|
detail = QStringLiteral("%1 · 2D · %2×%3 · seq %4")
|
||||||
.arg(QString::fromStdString(update.map_id()))
|
.arg(QString::fromStdString(update.map_id()))
|
||||||
.arg(sourceWidth).arg(sourceHeight)
|
.arg(sourceWidth).arg(sourceHeight)
|
||||||
@ -1864,19 +2117,13 @@ public:
|
|||||||
}
|
}
|
||||||
painter.end();
|
painter.end();
|
||||||
}
|
}
|
||||||
metadata.insert(QStringLiteral("mapId"),
|
|
||||||
QString::fromStdString(update.map_id()));
|
|
||||||
metadata.insert(QStringLiteral("dimension"), 3);
|
|
||||||
metadata.insert(QStringLiteral("timestamp"), map.timestamp());
|
|
||||||
metadata.insert(QStringLiteral("sequence"),
|
|
||||||
static_cast<qulonglong>(update.sequence()));
|
|
||||||
detail = QStringLiteral("%1 · 3D · %2 points · seq %3")
|
detail = QStringLiteral("%1 · 3D · %2 points · seq %3")
|
||||||
.arg(QString::fromStdString(update.map_id()))
|
.arg(QString::fromStdString(update.map_id()))
|
||||||
.arg(map.points_size())
|
.arg(map.points_size())
|
||||||
.arg(static_cast<qulonglong>(update.sequence()));
|
.arg(static_cast<qulonglong>(update.sequence()));
|
||||||
}
|
}
|
||||||
if (!image.isNull())
|
if (!image.isNull())
|
||||||
emit agvMapFrameReceived(image, metadata, detail);
|
emit agvMapFrameReceived(image, detail);
|
||||||
}
|
}
|
||||||
const grpc::Status status = reader->Finish();
|
const grpc::Status status = reader->Finish();
|
||||||
{
|
{
|
||||||
@ -2072,6 +2319,8 @@ public:
|
|||||||
|
|
||||||
std::function<void(bool, int, const QString &)> connectionChanged;
|
std::function<void(bool, int, const QString &)> connectionChanged;
|
||||||
std::function<void(const QString &, const QVariantMap &)> armInfoReceived;
|
std::function<void(const QString &, const QVariantMap &)> armInfoReceived;
|
||||||
|
std::function<void(quint64, const QString &, const QVariantMap &, const QVariantMap &,
|
||||||
|
bool, const QString &)> tcpCalibrationPoseReceived;
|
||||||
std::function<void(const QString &, const QStringList &, const QStringList &)>
|
std::function<void(const QString &, const QStringList &, const QStringList &)>
|
||||||
armFramesReceived;
|
armFramesReceived;
|
||||||
std::function<void(const QString &, const QVariantList &, const QVariantMap &,
|
std::function<void(const QString &, const QVariantList &, const QVariantMap &,
|
||||||
@ -2081,6 +2330,10 @@ public:
|
|||||||
std::function<void(double, double, double, const QVariantList &)> systemStatusReceived;
|
std::function<void(double, double, double, const QVariantList &)> systemStatusReceived;
|
||||||
std::function<void(const QVariantMap &)> systemInfoReceived;
|
std::function<void(const QVariantMap &)> systemInfoReceived;
|
||||||
std::function<void(const QImage &, const QString &)> imageReceived;
|
std::function<void(const QImage &, const QString &)> imageReceived;
|
||||||
|
std::function<void(quint64, const QString &, const QImage &, const QVariantMap &,
|
||||||
|
const QVariantMap &, bool, const QString &)> handEyeImageReceived;
|
||||||
|
std::function<void(quint64, const QString &, const QImage &, const QVariantMap &,
|
||||||
|
const QVariantMap &, bool, const QString &)> touchRgbdImageReceived;
|
||||||
std::function<void(const QString &, const VideoFrame &, const QString &)>
|
std::function<void(const QString &, const VideoFrame &, const QString &)>
|
||||||
videoFrameReceivedForCamera;
|
videoFrameReceivedForCamera;
|
||||||
std::function<void(const QString &, bool, const QString &)>
|
std::function<void(const QString &, bool, const QString &)>
|
||||||
@ -2088,8 +2341,7 @@ public:
|
|||||||
std::function<void(bool, const QString &)> cameraRecordingStateChanged;
|
std::function<void(bool, const QString &)> cameraRecordingStateChanged;
|
||||||
std::function<void(const QVariantMap &, const QVariantMap &)> agvStateReceived;
|
std::function<void(const QVariantMap &, const QVariantMap &)> agvStateReceived;
|
||||||
std::function<void(const QStringList &, const QVariantList &)> agvInventoryReceived;
|
std::function<void(const QStringList &, const QVariantList &)> agvInventoryReceived;
|
||||||
std::function<void(const QImage &, const QVariantMap &, const QString &)>
|
std::function<void(const QImage &, const QString &)> agvMapFrameReceived;
|
||||||
agvMapFrameReceived;
|
|
||||||
std::function<void(bool, const QString &)> agvMapStreamStateChanged;
|
std::function<void(bool, const QString &)> agvMapStreamStateChanged;
|
||||||
std::function<void(const QString &, const QString &, bool, const QString &)> rpcFinished;
|
std::function<void(const QString &, const QString &, bool, const QString &)> rpcFinished;
|
||||||
std::function<void(const QString &, bool, const QString &)> audioStreamStateChanged;
|
std::function<void(const QString &, bool, const QString &)> audioStreamStateChanged;
|
||||||
@ -2774,6 +3026,8 @@ private:
|
|||||||
quint32 sourceFps = 0;
|
quint32 sourceFps = 0;
|
||||||
quint64 generation = 0;
|
quint64 generation = 0;
|
||||||
bool keyFrame = false;
|
bool keyFrame = false;
|
||||||
|
QVariantMap intrinsics;
|
||||||
|
QVariantMap metadata;
|
||||||
};
|
};
|
||||||
// Frame-threaded HEVC needs several packets before its first output.
|
// Frame-threaded HEVC needs several packets before its first output.
|
||||||
// Keep enough startup headroom so the low-latency recovery logic does
|
// Keep enough startup headroom so the low-latency recovery logic does
|
||||||
@ -2816,6 +3070,15 @@ private:
|
|||||||
int decodeErrors = 0;
|
int decodeErrors = 0;
|
||||||
QString activeCodec;
|
QString activeCodec;
|
||||||
quint64 activeGeneration = std::numeric_limits<quint64>::max();
|
quint64 activeGeneration = std::numeric_limits<quint64>::max();
|
||||||
|
struct FrameMetadata {
|
||||||
|
QVariantMap intrinsics;
|
||||||
|
QVariantMap metadata;
|
||||||
|
bool ambiguous = false;
|
||||||
|
bool delivered = false;
|
||||||
|
};
|
||||||
|
QHash<qint64, FrameMetadata> metadataByPts;
|
||||||
|
std::deque<qint64> metadataOrder;
|
||||||
|
constexpr std::size_t kMaxFrameMetadata = 256;
|
||||||
while (!session->stop.load()) {
|
while (!session->stop.load()) {
|
||||||
CompressedVideoFrame packet;
|
CompressedVideoFrame packet;
|
||||||
{
|
{
|
||||||
@ -2837,6 +3100,8 @@ private:
|
|||||||
if (codec != activeCodec ||
|
if (codec != activeCodec ||
|
||||||
packet.generation != activeGeneration) {
|
packet.generation != activeGeneration) {
|
||||||
decoder.reset();
|
decoder.reset();
|
||||||
|
metadataByPts.clear();
|
||||||
|
metadataOrder.clear();
|
||||||
activeCodec = codec;
|
activeCodec = codec;
|
||||||
activeGeneration = packet.generation;
|
activeGeneration = packet.generation;
|
||||||
decodeErrors = 0;
|
decodeErrors = 0;
|
||||||
@ -2845,12 +3110,34 @@ private:
|
|||||||
.arg(codec.toUpper()));
|
.arg(codec.toUpper()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FFmpeg may output an older frame after several input packets.
|
||||||
|
// Match by decoded PTS, never by the most recently read packet.
|
||||||
|
// Zero is also the protobuf missing-field default: omit it from
|
||||||
|
// calibration matching, while leaving video display unaffected.
|
||||||
|
if (packet.pts != 0 && packet.pts != std::numeric_limits<qint64>::min()) {
|
||||||
|
auto existingMetadata = metadataByPts.find(packet.pts);
|
||||||
|
if (existingMetadata != metadataByPts.end()) {
|
||||||
|
existingMetadata->ambiguous = true;
|
||||||
|
} else {
|
||||||
|
FrameMetadata values;
|
||||||
|
values.intrinsics = packet.intrinsics;
|
||||||
|
values.metadata = packet.metadata;
|
||||||
|
metadataByPts.insert(packet.pts, values);
|
||||||
|
metadataOrder.push_back(packet.pts);
|
||||||
|
while (metadataOrder.size() > kMaxFrameMetadata) {
|
||||||
|
metadataByPts.remove(metadataOrder.front());
|
||||||
|
metadataOrder.pop_front();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
QVector<VideoFrame> frames;
|
QVector<VideoFrame> frames;
|
||||||
int decodedCount = 0;
|
int decodedCount = 0;
|
||||||
QElapsedTimer decodeTimer;
|
QElapsedTimer decodeTimer;
|
||||||
decodeTimer.start();
|
decodeTimer.start();
|
||||||
if (!decoder.decode(packet.data, codec, packet.pts, packet.dts,
|
if (!decoder.decode(packet.data, codec, packet.pts, packet.dts,
|
||||||
&frames, true, &decodedCount)) {
|
&frames, true, &decodedCount)) {
|
||||||
|
metadataByPts.clear();
|
||||||
|
metadataOrder.clear();
|
||||||
++decodeErrors;
|
++decodeErrors;
|
||||||
if (decodeErrors == 1 || decodeErrors % 60 == 0) {
|
if (decodeErrors == 1 || decodeErrors % 60 == 0) {
|
||||||
emit logMessage(QStringLiteral("WARN"),
|
emit logMessage(QStringLiteral("WARN"),
|
||||||
@ -2871,7 +3158,18 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const VideoFrame &frame : frames) {
|
for (VideoFrame &frame : frames) {
|
||||||
|
frame.metadata = {{QStringLiteral("kind"), QStringLiteral("rgb")},
|
||||||
|
{QStringLiteral("ptsMatched"), false},
|
||||||
|
{QStringLiteral("captureTimestampAvailable"), false}};
|
||||||
|
auto matched = metadataByPts.find(frame.presentationTimestamp);
|
||||||
|
if (matched != metadataByPts.end() && !matched->ambiguous
|
||||||
|
&& !matched->delivered) {
|
||||||
|
frame.intrinsics = matched->intrinsics;
|
||||||
|
frame.metadata = matched->metadata;
|
||||||
|
frame.metadata.insert(QStringLiteral("ptsMatched"), true);
|
||||||
|
matched->delivered = true;
|
||||||
|
}
|
||||||
displayedFrames.fetch_add(1);
|
displayedFrames.fetch_add(1);
|
||||||
++rateFrames;
|
++rateFrames;
|
||||||
if (rateTimer.elapsed() >= 1000) {
|
if (rateTimer.elapsed() >= 1000) {
|
||||||
@ -2944,6 +3242,32 @@ private:
|
|||||||
packet.seqNo = response.seq_no();
|
packet.seqNo = response.seq_no();
|
||||||
packet.sourceFps = frame.source_fps();
|
packet.sourceFps = frame.source_fps();
|
||||||
packet.keyFrame = frame.is_key_frame();
|
packet.keyFrame = frame.is_key_frame();
|
||||||
|
const auto &intrinsics = response.intrinsics();
|
||||||
|
QVariantList coefficients;
|
||||||
|
for (const float coefficient : intrinsics.coeffs())
|
||||||
|
coefficients.append(static_cast<double>(coefficient));
|
||||||
|
// Preserve the server values. Some drivers resize their encoded
|
||||||
|
// output without scaling K; consumers must confirm native dimensions.
|
||||||
|
packet.intrinsics = {
|
||||||
|
{QStringLiteral("fx"), intrinsics.fx()}, {QStringLiteral("fy"), intrinsics.fy()},
|
||||||
|
{QStringLiteral("cx"), intrinsics.cx()}, {QStringLiteral("cy"), intrinsics.cy()},
|
||||||
|
{QStringLiteral("coeffs"), coefficients},
|
||||||
|
{QStringLiteral("width"), frame.width()},
|
||||||
|
{QStringLiteral("height"), frame.height()},
|
||||||
|
{QStringLiteral("distortionModelAvailable"), false},
|
||||||
|
{QStringLiteral("source"), QStringLiteral("CameraService.GetRGBImageStream.intrinsics")}};
|
||||||
|
packet.metadata = {
|
||||||
|
{QStringLiteral("kind"), QStringLiteral("rgb")},
|
||||||
|
{QStringLiteral("captureUtcNs"), static_cast<qint64>(frame.capture_utc_ns())},
|
||||||
|
{QStringLiteral("sourceSequence"), static_cast<quint64>(frame.source_sequence())},
|
||||||
|
{QStringLiteral("sourceFrameNumber"), static_cast<quint64>(frame.source_frame_number())},
|
||||||
|
{QStringLiteral("sourceTimestamp"), static_cast<quint64>(frame.source_timestamp())},
|
||||||
|
{QStringLiteral("pts"), static_cast<qint64>(frame.pts())},
|
||||||
|
{QStringLiteral("dts"), static_cast<qint64>(frame.dts())},
|
||||||
|
{QStringLiteral("sourceFps"), frame.source_fps()},
|
||||||
|
{QStringLiteral("receivedAtMs"), QDateTime::currentMSecsSinceEpoch()},
|
||||||
|
{QStringLiteral("captureTimestampAvailable"), frame.capture_utc_ns() > 0},
|
||||||
|
{QStringLiteral("source"), QStringLiteral("CameraService.GetRGBImageStream.color_frame")}};
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(compressedFramesMutex);
|
std::lock_guard<std::mutex> lock(compressedFramesMutex);
|
||||||
// Resynchronize only at a keyframe already in hand. Clearing a
|
// Resynchronize only at a keyframe already in hand. Clearing a
|
||||||
@ -3051,6 +3375,7 @@ private:
|
|||||||
pose.insert(QStringLiteral("rx"), tcp.rx());
|
pose.insert(QStringLiteral("rx"), tcp.rx());
|
||||||
pose.insert(QStringLiteral("ry"), tcp.ry());
|
pose.insert(QStringLiteral("ry"), tcp.ry());
|
||||||
pose.insert(QStringLiteral("rz"), tcp.rz());
|
pose.insert(QStringLiteral("rz"), tcp.rz());
|
||||||
|
const QVariantMap activeTcpPose = pose;
|
||||||
if (robotState.connected()
|
if (robotState.connected()
|
||||||
&& !m_armBaseFrame.isEmpty() && !m_armTcpFrame.isEmpty()) {
|
&& !m_armBaseFrame.isEmpty() && !m_armTcpFrame.isEmpty()) {
|
||||||
cmvr::api::GetPose::Request poseRequest;
|
cmvr::api::GetPose::Request poseRequest;
|
||||||
@ -3073,6 +3398,7 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
QVariantMap state;
|
QVariantMap state;
|
||||||
|
state.insert(QStringLiteral("activeTcpPose"), activeTcpPose);
|
||||||
state.insert(QStringLiteral("robotMode"), static_cast<int>(robotState.robot_mode()));
|
state.insert(QStringLiteral("robotMode"), static_cast<int>(robotState.robot_mode()));
|
||||||
state.insert(QStringLiteral("safetyMode"), static_cast<int>(robotState.safety_mode()));
|
state.insert(QStringLiteral("safetyMode"), static_cast<int>(robotState.safety_mode()));
|
||||||
state.insert(QStringLiteral("controlMode"), static_cast<int>(robotState.control_mode()));
|
state.insert(QStringLiteral("controlMode"), static_cast<int>(robotState.control_mode()));
|
||||||
@ -3216,6 +3542,15 @@ RobotClient::RobotClient(QObject *parent)
|
|||||||
emit armFramesReceived(deviceId, baseFrames, tcpFrames);
|
emit armFramesReceived(deviceId, baseFrames, tcpFrames);
|
||||||
}, Qt::QueuedConnection);
|
}, Qt::QueuedConnection);
|
||||||
};
|
};
|
||||||
|
m_worker->tcpCalibrationPoseReceived =
|
||||||
|
[this](quint64 requestId, const QString &deviceId, const QVariantMap &pose,
|
||||||
|
const QVariantMap &state, bool success, const QString &detail) {
|
||||||
|
QMetaObject::invokeMethod(this,
|
||||||
|
[this, requestId, deviceId, pose, state, success, detail]() {
|
||||||
|
emit tcpCalibrationPoseReceived(requestId, deviceId, pose, state,
|
||||||
|
success, detail);
|
||||||
|
}, Qt::QueuedConnection);
|
||||||
|
};
|
||||||
m_worker->telemetryReceived = [this](const QString &deviceId,
|
m_worker->telemetryReceived = [this](const QString &deviceId,
|
||||||
const QVariantList &joints,
|
const QVariantList &joints,
|
||||||
const QVariantMap &pose,
|
const QVariantMap &pose,
|
||||||
@ -3246,6 +3581,23 @@ RobotClient::RobotClient(QObject *parent)
|
|||||||
emit imageReceived(image, detail);
|
emit imageReceived(image, detail);
|
||||||
}, Qt::QueuedConnection);
|
}, Qt::QueuedConnection);
|
||||||
};
|
};
|
||||||
|
m_worker->handEyeImageReceived =
|
||||||
|
[this](quint64 token, const QString &cameraId, const QImage &image,
|
||||||
|
const QVariantMap &intrinsics, const QVariantMap &metadata,
|
||||||
|
bool success, const QString &detail) {
|
||||||
|
QMetaObject::invokeMethod(this,
|
||||||
|
[this, token, cameraId, image, intrinsics, metadata, success, detail]() {
|
||||||
|
emit handEyeImageReceived(token, cameraId, image, intrinsics,
|
||||||
|
metadata, success, detail);
|
||||||
|
}, Qt::QueuedConnection);
|
||||||
|
};
|
||||||
|
m_worker->touchRgbdImageReceived =
|
||||||
|
[this](quint64 token,const QString &camera,const QImage &image,const QVariantMap &intrinsics,
|
||||||
|
const QVariantMap &metadata,bool success,const QString &detail) {
|
||||||
|
QMetaObject::invokeMethod(this,[this,token,camera,image,intrinsics,metadata,success,detail] {
|
||||||
|
emit touchRgbdImageReceived(token,camera,image,intrinsics,metadata,success,detail);
|
||||||
|
},Qt::QueuedConnection);
|
||||||
|
};
|
||||||
const auto queueVideoFrame = [this](const QString &cameraId,
|
const auto queueVideoFrame = [this](const QString &cameraId,
|
||||||
const VideoFrame &frame,
|
const VideoFrame &frame,
|
||||||
const QString &detail) {
|
const QString &detail) {
|
||||||
@ -3291,11 +3643,9 @@ RobotClient::RobotClient(QObject *parent)
|
|||||||
emit agvInventoryReceived(maps, stations);
|
emit agvInventoryReceived(maps, stations);
|
||||||
}, Qt::QueuedConnection);
|
}, Qt::QueuedConnection);
|
||||||
};
|
};
|
||||||
m_worker->agvMapFrameReceived = [this](const QImage &image,
|
m_worker->agvMapFrameReceived = [this](const QImage &image, const QString &detail) {
|
||||||
const QVariantMap &metadata,
|
QMetaObject::invokeMethod(this, [this, image, detail]() {
|
||||||
const QString &detail) {
|
emit agvMapFrameReceived(image, detail);
|
||||||
QMetaObject::invokeMethod(this, [this, image, metadata, detail]() {
|
|
||||||
emit agvMapFrameReceived(image, metadata, detail);
|
|
||||||
}, Qt::QueuedConnection);
|
}, Qt::QueuedConnection);
|
||||||
};
|
};
|
||||||
m_worker->agvMapStreamStateChanged = [this](bool running, const QString &detail) {
|
m_worker->agvMapStreamStateChanged = [this](bool running, const QString &detail) {
|
||||||
@ -3380,6 +3730,9 @@ RobotClient::RobotClient(QObject *parent)
|
|||||||
connect(this, &RobotClient::disconnectRequested, m_worker, &BackendWorker::disconnectFromServer);
|
connect(this, &RobotClient::disconnectRequested, m_worker, &BackendWorker::disconnectFromServer);
|
||||||
connect(this, &RobotClient::armTelemetryRequested, m_worker, &BackendWorker::setArmTelemetry);
|
connect(this, &RobotClient::armTelemetryRequested, m_worker, &BackendWorker::setArmTelemetry);
|
||||||
connect(this, &RobotClient::armInfoRequested, m_worker, &BackendWorker::getArmInfo);
|
connect(this, &RobotClient::armInfoRequested, m_worker, &BackendWorker::getArmInfo);
|
||||||
|
connect(this, &RobotClient::tcpCalibrationPoseRequested,
|
||||||
|
m_worker, &BackendWorker::getTcpCalibrationPose);
|
||||||
|
connect(this, &RobotClient::tcpJogMoveRequested, m_worker, &BackendWorker::tcpJogMove);
|
||||||
connect(this, &RobotClient::armFramesRequested, m_worker, &BackendWorker::getArmFrames);
|
connect(this, &RobotClient::armFramesRequested, m_worker, &BackendWorker::getArmFrames);
|
||||||
connect(this, &RobotClient::armTelemetryFramesRequested,
|
connect(this, &RobotClient::armTelemetryFramesRequested,
|
||||||
m_worker, &BackendWorker::setArmTelemetryFrames);
|
m_worker, &BackendWorker::setArmTelemetryFrames);
|
||||||
@ -3393,6 +3746,8 @@ RobotClient::RobotClient(QObject *parent)
|
|||||||
connect(this, &RobotClient::armCalibrateZeroRequested,
|
connect(this, &RobotClient::armCalibrateZeroRequested,
|
||||||
m_worker, &BackendWorker::armCalibrateZero);
|
m_worker, &BackendWorker::armCalibrateZero);
|
||||||
connect(this, &RobotClient::snapshotRequested, m_worker, &BackendWorker::snapshot);
|
connect(this, &RobotClient::snapshotRequested, m_worker, &BackendWorker::snapshot);
|
||||||
|
connect(this, &RobotClient::handEyeImageRequested, m_worker, &BackendWorker::getHandEyeImage);
|
||||||
|
connect(this, &RobotClient::touchRgbdImageRequested, m_worker, &BackendWorker::getTouchRgbdImage);
|
||||||
connect(this, &RobotClient::cameraStreamStartRequested, m_worker, &BackendWorker::startCameraStream);
|
connect(this, &RobotClient::cameraStreamStartRequested, m_worker, &BackendWorker::startCameraStream);
|
||||||
connect(this, &RobotClient::cameraStreamCodecRequested,
|
connect(this, &RobotClient::cameraStreamCodecRequested,
|
||||||
m_worker, &BackendWorker::setCameraStreamCodec);
|
m_worker, &BackendWorker::setCameraStreamCodec);
|
||||||
@ -3404,8 +3759,6 @@ RobotClient::RobotClient(QObject *parent)
|
|||||||
connect(this, &RobotClient::systemRefreshRequested, m_worker, &BackendWorker::systemRefresh);
|
connect(this, &RobotClient::systemRefreshRequested, m_worker, &BackendWorker::systemRefresh);
|
||||||
connect(this, &RobotClient::systemStopAllRequested, m_worker, &BackendWorker::systemStopAll);
|
connect(this, &RobotClient::systemStopAllRequested, m_worker, &BackendWorker::systemStopAll);
|
||||||
connect(this, &RobotClient::agvRefreshRequested, m_worker, &BackendWorker::agvRefresh);
|
connect(this, &RobotClient::agvRefreshRequested, m_worker, &BackendWorker::agvRefresh);
|
||||||
connect(this, &RobotClient::agvRelocalizeRequested,
|
|
||||||
m_worker, &BackendWorker::agvRelocalize);
|
|
||||||
connect(this, &RobotClient::agvNavigatePoseRequested, m_worker, &BackendWorker::agvNavigatePose);
|
connect(this, &RobotClient::agvNavigatePoseRequested, m_worker, &BackendWorker::agvNavigatePose);
|
||||||
connect(this, &RobotClient::agvNavigateStationRequested, m_worker, &BackendWorker::agvNavigateStation);
|
connect(this, &RobotClient::agvNavigateStationRequested, m_worker, &BackendWorker::agvNavigateStation);
|
||||||
connect(this, &RobotClient::agvFollowPathRequested, m_worker, &BackendWorker::agvFollowPath);
|
connect(this, &RobotClient::agvFollowPathRequested, m_worker, &BackendWorker::agvFollowPath);
|
||||||
@ -3480,6 +3833,15 @@ void RobotClient::requestArmInfo(const QString &deviceId)
|
|||||||
{
|
{
|
||||||
emit armInfoRequested(deviceId);
|
emit armInfoRequested(deviceId);
|
||||||
}
|
}
|
||||||
|
void RobotClient::requestTcpCalibrationPose(const QString &deviceId, quint64 requestId)
|
||||||
|
{
|
||||||
|
emit tcpCalibrationPoseRequested(deviceId, requestId);
|
||||||
|
}
|
||||||
|
void RobotClient::requestTcpJogMove(const QString &deviceId, const QVariantMap &pose,
|
||||||
|
double velocity, double acceleration, quint64 token)
|
||||||
|
{
|
||||||
|
emit tcpJogMoveRequested(deviceId, pose, velocity, acceleration, token);
|
||||||
|
}
|
||||||
void RobotClient::requestArmFrames(const QString &deviceId)
|
void RobotClient::requestArmFrames(const QString &deviceId)
|
||||||
{
|
{
|
||||||
emit armFramesRequested(deviceId);
|
emit armFramesRequested(deviceId);
|
||||||
@ -3492,32 +3854,46 @@ void RobotClient::setArmTelemetryFrames(const QString &deviceId, const QString &
|
|||||||
void RobotClient::requestSpeedJ(const QString &deviceId, const QVariantList &velocities,
|
void RobotClient::requestSpeedJ(const QString &deviceId, const QVariantList &velocities,
|
||||||
double acceleration, double duration)
|
double acceleration, double duration)
|
||||||
{
|
{
|
||||||
|
emit armCommandStarting(deviceId);
|
||||||
emit speedJRequested(deviceId, velocities, acceleration, duration);
|
emit speedJRequested(deviceId, velocities, acceleration, duration);
|
||||||
}
|
}
|
||||||
void RobotClient::requestSpeedL(const QString &deviceId, const QVariantMap &velocity,
|
void RobotClient::requestSpeedL(const QString &deviceId, const QVariantMap &velocity,
|
||||||
double acceleration, double duration, bool toolFrame)
|
double acceleration, double duration, bool toolFrame)
|
||||||
{
|
{
|
||||||
|
emit armCommandStarting(deviceId);
|
||||||
emit speedLRequested(deviceId, velocity, acceleration, duration, toolFrame);
|
emit speedLRequested(deviceId, velocity, acceleration, duration, toolFrame);
|
||||||
}
|
}
|
||||||
void RobotClient::requestMoveJ(const QString &deviceId, const QVariantList &positions,
|
void RobotClient::requestMoveJ(const QString &deviceId, const QVariantList &positions,
|
||||||
double velocity, double acceleration)
|
double velocity, double acceleration)
|
||||||
{
|
{
|
||||||
|
emit armCommandStarting(deviceId);
|
||||||
emit moveJRequested(deviceId, positions, velocity, acceleration);
|
emit moveJRequested(deviceId, positions, velocity, acceleration);
|
||||||
}
|
}
|
||||||
void RobotClient::requestMoveJPose(const QString &deviceId, const QVariantMap &pose,
|
void RobotClient::requestMoveJPose(const QString &deviceId, const QVariantMap &pose,
|
||||||
const QString &baseLink, const QString &eeLink,
|
const QString &baseLink, const QString &eeLink,
|
||||||
double velocity, double acceleration)
|
double velocity, double acceleration)
|
||||||
{
|
{
|
||||||
|
emit tcpReferenceInvalidated(deviceId);
|
||||||
emit moveJPoseRequested(deviceId, pose, baseLink, eeLink, velocity, acceleration);
|
emit moveJPoseRequested(deviceId, pose, baseLink, eeLink, velocity, acceleration);
|
||||||
}
|
}
|
||||||
void RobotClient::requestTorque(const QString &deviceId, bool enabled) { emit torqueRequested(deviceId, enabled); }
|
void RobotClient::requestTorque(const QString &deviceId, bool enabled) { emit armCommandStarting(deviceId); emit torqueRequested(deviceId, enabled); }
|
||||||
void RobotClient::requestArmStop(const QString &deviceId) { emit armStopRequested(deviceId); }
|
void RobotClient::requestArmStop(const QString &deviceId) { emit armStopRequested(deviceId); }
|
||||||
void RobotClient::requestArmClearFault(const QString &deviceId) { emit armClearFaultRequested(deviceId); }
|
void RobotClient::requestArmClearFault(const QString &deviceId) { emit armClearFaultRequested(deviceId); }
|
||||||
void RobotClient::requestArmCalibrateZero(const QString &deviceId, const QString &jointName)
|
void RobotClient::requestArmCalibrateZero(const QString &deviceId, const QString &jointName)
|
||||||
{
|
{
|
||||||
|
emit armCommandStarting(deviceId);
|
||||||
emit armCalibrateZeroRequested(deviceId, jointName);
|
emit armCalibrateZeroRequested(deviceId, jointName);
|
||||||
}
|
}
|
||||||
void RobotClient::requestSnapshot(const QString &cameraId) { emit snapshotRequested(cameraId); }
|
void RobotClient::requestSnapshot(const QString &cameraId) { emit snapshotRequested(cameraId); }
|
||||||
|
void RobotClient::requestTouchRgbdImage(const QString &cameraId, quint64 token)
|
||||||
|
{
|
||||||
|
emit touchRgbdImageRequested(cameraId, token);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RobotClient::requestHandEyeImage(const QString &cameraId, quint64 token)
|
||||||
|
{
|
||||||
|
emit handEyeImageRequested(cameraId, token);
|
||||||
|
}
|
||||||
void RobotClient::startCameraStream(const QString &cameraId, const QString &codec,
|
void RobotClient::startCameraStream(const QString &cameraId, const QString &codec,
|
||||||
const QString &mode)
|
const QString &mode)
|
||||||
{
|
{
|
||||||
@ -3542,11 +3918,6 @@ void RobotClient::stopCameraRecording(const QString &cameraId)
|
|||||||
void RobotClient::requestSystemRefresh() { emit systemRefreshRequested(); }
|
void RobotClient::requestSystemRefresh() { emit systemRefreshRequested(); }
|
||||||
void RobotClient::requestSystemStopAll(const QString &deviceId) { emit systemStopAllRequested(deviceId); }
|
void RobotClient::requestSystemStopAll(const QString &deviceId) { emit systemStopAllRequested(deviceId); }
|
||||||
void RobotClient::requestAgvRefresh(const QString &deviceId) { emit agvRefreshRequested(deviceId); }
|
void RobotClient::requestAgvRefresh(const QString &deviceId) { emit agvRefreshRequested(deviceId); }
|
||||||
void RobotClient::requestAgvRelocalize(const QString &deviceId, double x, double y,
|
|
||||||
double theta)
|
|
||||||
{
|
|
||||||
emit agvRelocalizeRequested(deviceId, x, y, theta);
|
|
||||||
}
|
|
||||||
void RobotClient::requestAgvNavigatePose(const QString &deviceId, double x, double y,
|
void RobotClient::requestAgvNavigatePose(const QString &deviceId, double x, double y,
|
||||||
double theta, double maxSpeed)
|
double theta, double maxSpeed)
|
||||||
{
|
{
|
||||||
@ -3585,8 +3956,12 @@ void RobotClient::stopAgvMapStream()
|
|||||||
emit agvMapStreamStopRequested();
|
emit agvMapStreamStopRequested();
|
||||||
}
|
}
|
||||||
void RobotClient::requestRpc(const QString &serviceName, const QString &methodName,
|
void RobotClient::requestRpc(const QString &serviceName, const QString &methodName,
|
||||||
const QString &requestJson, const QString &deviceId)
|
const QString &requestJson, const QString &deviceId)
|
||||||
{
|
{
|
||||||
|
const QString method = methodName.toLower();
|
||||||
|
if (serviceName.contains(QStringLiteral("ArmService"), Qt::CaseInsensitive)
|
||||||
|
&& !method.startsWith(QStringLiteral("get")) && !method.startsWith(QStringLiteral("list")))
|
||||||
|
emit tcpReferenceInvalidated(deviceId);
|
||||||
emit rpcRequested(serviceName, methodName, requestJson, deviceId);
|
emit rpcRequested(serviceName, methodName, requestJson, deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -30,6 +30,9 @@ public slots:
|
|||||||
void disconnectFromServer();
|
void disconnectFromServer();
|
||||||
void setArmTelemetry(const QString &deviceId, bool enabled);
|
void setArmTelemetry(const QString &deviceId, bool enabled);
|
||||||
void requestArmInfo(const QString &deviceId);
|
void requestArmInfo(const QString &deviceId);
|
||||||
|
void requestTcpCalibrationPose(const QString &deviceId, quint64 requestId);
|
||||||
|
void requestTcpJogMove(const QString &deviceId, const QVariantMap &pose,
|
||||||
|
double velocity, double acceleration, quint64 token);
|
||||||
void requestArmFrames(const QString &deviceId);
|
void requestArmFrames(const QString &deviceId);
|
||||||
void setArmTelemetryFrames(const QString &deviceId, const QString &baseFrame,
|
void setArmTelemetryFrames(const QString &deviceId, const QString &baseFrame,
|
||||||
const QString &tcpFrame);
|
const QString &tcpFrame);
|
||||||
@ -47,6 +50,8 @@ public slots:
|
|||||||
void requestArmClearFault(const QString &deviceId);
|
void requestArmClearFault(const QString &deviceId);
|
||||||
void requestArmCalibrateZero(const QString &deviceId, const QString &jointName);
|
void requestArmCalibrateZero(const QString &deviceId, const QString &jointName);
|
||||||
void requestSnapshot(const QString &cameraId);
|
void requestSnapshot(const QString &cameraId);
|
||||||
|
void requestHandEyeImage(const QString &cameraId, quint64 token);
|
||||||
|
void requestTouchRgbdImage(const QString &cameraId, quint64 token);
|
||||||
void startCameraStream(const QString &cameraId, const QString &codec,
|
void startCameraStream(const QString &cameraId, const QString &codec,
|
||||||
const QString &mode = QStringLiteral("rgb"));
|
const QString &mode = QStringLiteral("rgb"));
|
||||||
void setCameraStreamCodec(const QString &codec);
|
void setCameraStreamCodec(const QString &codec);
|
||||||
@ -56,8 +61,6 @@ public slots:
|
|||||||
void requestSystemRefresh();
|
void requestSystemRefresh();
|
||||||
void requestSystemStopAll(const QString &deviceId);
|
void requestSystemStopAll(const QString &deviceId);
|
||||||
void requestAgvRefresh(const QString &deviceId);
|
void requestAgvRefresh(const QString &deviceId);
|
||||||
void requestAgvRelocalize(const QString &deviceId, double x, double y,
|
|
||||||
double theta);
|
|
||||||
void requestAgvNavigatePose(const QString &deviceId, double x, double y,
|
void requestAgvNavigatePose(const QString &deviceId, double x, double y,
|
||||||
double theta, double maxSpeed);
|
double theta, double maxSpeed);
|
||||||
void requestAgvNavigateStation(const QString &deviceId, const QString &stationId,
|
void requestAgvNavigateStation(const QString &deviceId, const QString &stationId,
|
||||||
@ -88,10 +91,17 @@ public slots:
|
|||||||
const QString &expectedRevision);
|
const QString &expectedRevision);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
// Synchronous arbitration before manual arm commands enter the worker queue.
|
||||||
|
void armCommandStarting(const QString &deviceId);
|
||||||
|
// Emitted synchronously before a command that may select another active TCP.
|
||||||
|
void tcpReferenceInvalidated(const QString &deviceId);
|
||||||
void connectRequested(const QString &host, int port, bool demoMode);
|
void connectRequested(const QString &host, int port, bool demoMode);
|
||||||
void disconnectRequested();
|
void disconnectRequested();
|
||||||
void armTelemetryRequested(const QString &deviceId, bool enabled);
|
void armTelemetryRequested(const QString &deviceId, bool enabled);
|
||||||
void armInfoRequested(const QString &deviceId);
|
void armInfoRequested(const QString &deviceId);
|
||||||
|
void tcpCalibrationPoseRequested(const QString &deviceId, quint64 requestId);
|
||||||
|
void tcpJogMoveRequested(const QString &deviceId, const QVariantMap &pose,
|
||||||
|
double velocity, double acceleration, quint64 token);
|
||||||
void armFramesRequested(const QString &deviceId);
|
void armFramesRequested(const QString &deviceId);
|
||||||
void armTelemetryFramesRequested(const QString &deviceId, const QString &baseFrame,
|
void armTelemetryFramesRequested(const QString &deviceId, const QString &baseFrame,
|
||||||
const QString &tcpFrame);
|
const QString &tcpFrame);
|
||||||
@ -109,6 +119,8 @@ signals:
|
|||||||
void armClearFaultRequested(const QString &deviceId);
|
void armClearFaultRequested(const QString &deviceId);
|
||||||
void armCalibrateZeroRequested(const QString &deviceId, const QString &jointName);
|
void armCalibrateZeroRequested(const QString &deviceId, const QString &jointName);
|
||||||
void snapshotRequested(const QString &cameraId);
|
void snapshotRequested(const QString &cameraId);
|
||||||
|
void handEyeImageRequested(const QString &cameraId, quint64 token);
|
||||||
|
void touchRgbdImageRequested(const QString &cameraId, quint64 token);
|
||||||
void cameraStreamStartRequested(const QString &cameraId, const QString &codec,
|
void cameraStreamStartRequested(const QString &cameraId, const QString &codec,
|
||||||
const QString &mode);
|
const QString &mode);
|
||||||
void cameraStreamCodecRequested(const QString &codec);
|
void cameraStreamCodecRequested(const QString &codec);
|
||||||
@ -118,8 +130,6 @@ signals:
|
|||||||
void systemRefreshRequested();
|
void systemRefreshRequested();
|
||||||
void systemStopAllRequested(const QString &deviceId);
|
void systemStopAllRequested(const QString &deviceId);
|
||||||
void agvRefreshRequested(const QString &deviceId);
|
void agvRefreshRequested(const QString &deviceId);
|
||||||
void agvRelocalizeRequested(const QString &deviceId, double x, double y,
|
|
||||||
double theta);
|
|
||||||
void agvNavigatePoseRequested(const QString &deviceId, double x, double y,
|
void agvNavigatePoseRequested(const QString &deviceId, double x, double y,
|
||||||
double theta, double maxSpeed);
|
double theta, double maxSpeed);
|
||||||
void agvNavigateStationRequested(const QString &deviceId, const QString &stationId,
|
void agvNavigateStationRequested(const QString &deviceId, const QString &stationId,
|
||||||
@ -152,6 +162,10 @@ signals:
|
|||||||
|
|
||||||
void connectionChanged(bool connected, int latencyMs, const QString &detail);
|
void connectionChanged(bool connected, int latencyMs, const QString &detail);
|
||||||
void armInfoReceived(const QString &deviceId, const QVariantMap &info);
|
void armInfoReceived(const QString &deviceId, const QVariantMap &info);
|
||||||
|
// Raw active TCP in the driver's base frame; this is not a flange pose.
|
||||||
|
void tcpCalibrationPoseReceived(quint64 requestId, const QString &deviceId,
|
||||||
|
const QVariantMap &pose, const QVariantMap &state,
|
||||||
|
bool success, const QString &detail);
|
||||||
void armFramesReceived(const QString &deviceId, const QStringList &baseFrames,
|
void armFramesReceived(const QString &deviceId, const QStringList &baseFrames,
|
||||||
const QStringList &tcpFrames);
|
const QStringList &tcpFrames);
|
||||||
void telemetryReceived(const QString &deviceId, const QVariantList &joints,
|
void telemetryReceived(const QString &deviceId, const QVariantList &joints,
|
||||||
@ -162,6 +176,15 @@ signals:
|
|||||||
const QVariantList &devices);
|
const QVariantList &devices);
|
||||||
void systemInfoReceived(const QVariantMap &info);
|
void systemInfoReceived(const QVariantMap &info);
|
||||||
void imageReceived(const QImage &image, const QString &detail);
|
void imageReceived(const QImage &image, const QString &detail);
|
||||||
|
// success validates image/intrinsics only. Pairing must additionally check
|
||||||
|
// metadata.captureTimestampAvailable and its captureUtcNs against robot poses.
|
||||||
|
void handEyeImageReceived(quint64 token, const QString &cameraId,
|
||||||
|
const QImage &image, const QVariantMap &intrinsics,
|
||||||
|
const QVariantMap &metadata, bool success,
|
||||||
|
const QString &detail);
|
||||||
|
void touchRgbdImageReceived(quint64 token, const QString &cameraId,
|
||||||
|
const QImage &image, const QVariantMap &intrinsics,
|
||||||
|
const QVariantMap &metadata, bool success, const QString &detail);
|
||||||
void videoFrameReceived(const QString &cameraId, const VideoFrame &frame,
|
void videoFrameReceived(const QString &cameraId, const VideoFrame &frame,
|
||||||
const QString &detail);
|
const QString &detail);
|
||||||
void cameraStreamStateChanged(const QString &cameraId, bool running,
|
void cameraStreamStateChanged(const QString &cameraId, bool running,
|
||||||
@ -169,8 +192,7 @@ signals:
|
|||||||
void cameraRecordingStateChanged(bool recording, const QString &detail);
|
void cameraRecordingStateChanged(bool recording, const QString &detail);
|
||||||
void agvStateReceived(const QVariantMap &state, const QVariantMap &navigation);
|
void agvStateReceived(const QVariantMap &state, const QVariantMap &navigation);
|
||||||
void agvInventoryReceived(const QStringList &maps, const QVariantList &stations);
|
void agvInventoryReceived(const QStringList &maps, const QVariantList &stations);
|
||||||
void agvMapFrameReceived(const QImage &image, const QVariantMap &metadata,
|
void agvMapFrameReceived(const QImage &image, const QString &detail);
|
||||||
const QString &detail);
|
|
||||||
void agvMapStreamStateChanged(bool running, const QString &detail);
|
void agvMapStreamStateChanged(bool running, const QString &detail);
|
||||||
void rpcFinished(const QString &serviceName, const QString &methodName,
|
void rpcFinished(const QString &serviceName, const QString &methodName,
|
||||||
bool success, const QString &responseJson);
|
bool success, const QString &responseJson);
|
||||||
|
|||||||
599
src/tcpcalibrationwidget.cpp
Normal file
599
src/tcpcalibrationwidget.cpp
Normal file
@ -0,0 +1,599 @@
|
|||||||
|
#include "tcpcalibrationwidget.h"
|
||||||
|
|
||||||
|
#include <QCheckBox>
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QDoubleSpinBox>
|
||||||
|
#include <QFrame>
|
||||||
|
#include <QGridLayout>
|
||||||
|
#include <QHeaderView>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QScrollArea>
|
||||||
|
#include <QSettings>
|
||||||
|
#include <QSignalBlocker>
|
||||||
|
#include <QTableWidget>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QtMath>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
QVBoxLayout *panel(QBoxLayout *parent, const QString &title)
|
||||||
|
{
|
||||||
|
auto *frame = new QFrame;
|
||||||
|
frame->setObjectName(QStringLiteral("panel"));
|
||||||
|
auto *layout = new QVBoxLayout(frame);
|
||||||
|
layout->setContentsMargins(14, 12, 14, 12);
|
||||||
|
layout->setSpacing(8);
|
||||||
|
auto *label = new QLabel(title);
|
||||||
|
label->setObjectName(QStringLiteral("sectionTitle"));
|
||||||
|
layout->addWidget(label);
|
||||||
|
parent->addWidget(frame);
|
||||||
|
return layout;
|
||||||
|
}
|
||||||
|
QLabel *hint(const QString &text)
|
||||||
|
{
|
||||||
|
auto *label = new QLabel(text);
|
||||||
|
label->setObjectName(QStringLiteral("mutedLabel"));
|
||||||
|
label->setWordWrap(true);
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
const char *keys[] = {"x", "y", "z", "rx", "ry", "rz"};
|
||||||
|
QString axis(int i) { return QString::fromLatin1(keys[i]).toUpper(); }
|
||||||
|
double fromDisplay(double value, int axisIndex)
|
||||||
|
{
|
||||||
|
return axisIndex < 3 ? value / 1000.0 : qDegreesToRadians(value);
|
||||||
|
}
|
||||||
|
double toDisplay(double value, int axisIndex)
|
||||||
|
{
|
||||||
|
return axisIndex < 3 ? value * 1000.0 : qRadiansToDegrees(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TcpCalibrationWidget::TcpCalibrationWidget(QWidget *parent) : QWidget(parent)
|
||||||
|
{
|
||||||
|
setObjectName(QStringLiteral("tcpCalibrationPage"));
|
||||||
|
buildUi();
|
||||||
|
m_captureTimer = new QTimer(this);
|
||||||
|
m_captureTimer->setSingleShot(true);
|
||||||
|
m_captureTimer->setInterval(6000);
|
||||||
|
connect(m_captureTimer, &QTimer::timeout, this, [this] {
|
||||||
|
if (m_pendingRow < 0) return;
|
||||||
|
++m_serial;
|
||||||
|
m_pendingRow = -1;
|
||||||
|
refresh();
|
||||||
|
reportError(QStringLiteral("读取实时位姿超时,请检查机械臂连接后重试"));
|
||||||
|
});
|
||||||
|
resizeSamples(4);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpCalibrationWidget::buildUi()
|
||||||
|
{
|
||||||
|
auto *outer = new QVBoxLayout(this);
|
||||||
|
outer->setContentsMargins(12, 10, 12, 10);
|
||||||
|
auto *scroll = new QScrollArea(this);
|
||||||
|
scroll->setWidgetResizable(true);
|
||||||
|
scroll->setFrameShape(QFrame::NoFrame);
|
||||||
|
auto *content = new QWidget;
|
||||||
|
auto *layout = new QVBoxLayout(content);
|
||||||
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
layout->setSpacing(10);
|
||||||
|
scroll->setWidget(content);
|
||||||
|
outer->addWidget(scroll);
|
||||||
|
|
||||||
|
auto *configuration = new QHBoxLayout;
|
||||||
|
configuration->setSpacing(10);
|
||||||
|
layout->addLayout(configuration);
|
||||||
|
auto *toolPanel = panel(configuration, QStringLiteral("工具信息"));
|
||||||
|
auto *toolGrid = new QGridLayout;
|
||||||
|
toolGrid->setHorizontalSpacing(12);
|
||||||
|
m_toolCombo = new QComboBox;
|
||||||
|
m_toolCombo->setObjectName(QStringLiteral("tcpLocalTools"));
|
||||||
|
m_toolCombo->addItem(QStringLiteral("新建工具"));
|
||||||
|
m_name = new QLineEdit;
|
||||||
|
m_name->setObjectName(QStringLiteral("tcpToolName"));
|
||||||
|
m_name->setMaxLength(80);
|
||||||
|
m_name->setPlaceholderText(QStringLiteral("输入工具名称"));
|
||||||
|
m_name->setToolTip(QStringLiteral("保存至当前机械臂,并同步至工具坐标列表。"));
|
||||||
|
m_reload = new QPushButton(QStringLiteral("刷新"));
|
||||||
|
m_delete = new QPushButton(QStringLiteral("删除"));
|
||||||
|
m_delete->setObjectName(QStringLiteral("tcpDelete"));
|
||||||
|
toolGrid->addWidget(new QLabel(QStringLiteral("工具")), 0, 0);
|
||||||
|
toolGrid->addWidget(m_toolCombo, 0, 1);
|
||||||
|
toolGrid->addWidget(new QLabel(QStringLiteral("名称")), 1, 0);
|
||||||
|
toolGrid->addWidget(m_name, 1, 1, 1, 3);
|
||||||
|
toolGrid->addWidget(m_reload, 0, 2);
|
||||||
|
toolGrid->addWidget(m_delete, 0, 3);
|
||||||
|
toolGrid->setColumnStretch(1, 1);
|
||||||
|
toolPanel->addLayout(toolGrid);
|
||||||
|
m_currentTool = hint(QStringLiteral("正在标定:新工具"));
|
||||||
|
toolPanel->addWidget(m_currentTool);
|
||||||
|
toolPanel->addStretch();
|
||||||
|
auto *sourcePanel = panel(configuration, QStringLiteral("控制器 TCP 偏移"));
|
||||||
|
sourcePanel->parentWidget()->setToolTip(QStringLiteral("与示教器当前活动 TCP 一致,用于还原法兰位姿。仅零偏移工具可填全零;采样期间不得切换。"));
|
||||||
|
configuration->setStretch(0,1); configuration->setStretch(1,1);
|
||||||
|
auto *sourceGrid = new QGridLayout;
|
||||||
|
for (int i = 0; i < 6; ++i) {
|
||||||
|
auto *spin = new QDoubleSpinBox;
|
||||||
|
spin->setObjectName(QStringLiteral("tcpSource%1").arg(i));
|
||||||
|
spin->setRange(i < 3 ? -10000 : -360, i < 3 ? 10000 : 360);
|
||||||
|
spin->setDecimals(4);
|
||||||
|
spin->setSuffix(i < 3 ? QStringLiteral(" mm") : QStringLiteral(" °"));
|
||||||
|
m_source.append(spin);
|
||||||
|
sourceGrid->addWidget(new QLabel(axis(i)), i/3, (i%3)*2);
|
||||||
|
sourceGrid->addWidget(spin, i/3, (i%3)*2+1);
|
||||||
|
sourceGrid->setColumnStretch((i%3)*2+1,1);
|
||||||
|
connect(spin, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
|
||||||
|
[this](double) { updateSource(); });
|
||||||
|
}
|
||||||
|
sourcePanel->addLayout(sourceGrid);
|
||||||
|
m_sourceConfirmed = new QCheckBox(QStringLiteral(
|
||||||
|
"已确认控制器 TCP 偏移"));
|
||||||
|
m_sourceConfirmed->setToolTip(QStringLiteral("RX/RY/RZ 为 ZYX 欧拉角,非旋转向量。偏移必须与控制器当前活动工具一致。"));
|
||||||
|
m_sourceConfirmed->setObjectName(QStringLiteral("tcpSourceConfirmed"));
|
||||||
|
sourcePanel->addWidget(m_sourceConfirmed);
|
||||||
|
connect(m_sourceConfirmed, &QCheckBox::toggled, this, [this](bool) {
|
||||||
|
resetCalibration();
|
||||||
|
refresh();
|
||||||
|
emit referenceChanged();
|
||||||
|
});
|
||||||
|
|
||||||
|
auto *pointsPanel = panel(layout, QStringLiteral("TCP 采样"));
|
||||||
|
m_instructions = hint(QString());
|
||||||
|
pointsPanel->addWidget(m_instructions);
|
||||||
|
auto *pointActions = new QHBoxLayout;
|
||||||
|
m_method = new QComboBox;
|
||||||
|
m_method->setObjectName(QStringLiteral("tcpCalibrationMethod"));
|
||||||
|
m_method->addItem(QStringLiteral("四点法"),QStringLiteral("four_point"));
|
||||||
|
m_method->addItem(QStringLiteral("六点法 · XZ"),QStringLiteral("six_point_xz"));
|
||||||
|
m_method->addItem(QStringLiteral("六点法 · XY"),QStringLiteral("six_point_xy"));
|
||||||
|
pointActions->addWidget(new QLabel(QStringLiteral("标定方式")));
|
||||||
|
pointActions->addWidget(m_method);
|
||||||
|
pointActions->addStretch();
|
||||||
|
auto *restart = new QPushButton(QStringLiteral("重新标定"));
|
||||||
|
restart->setObjectName(QStringLiteral("tcpClear"));
|
||||||
|
pointActions->addWidget(restart);
|
||||||
|
pointsPanel->addLayout(pointActions);
|
||||||
|
m_table = new QTableWidget(0, 10);
|
||||||
|
m_table->setObjectName(QStringLiteral("tcpSamples"));
|
||||||
|
m_table->setHorizontalHeaderLabels({QStringLiteral("点位"), QStringLiteral("状态"),
|
||||||
|
QStringLiteral("X mm"), QStringLiteral("Y mm"), QStringLiteral("Z mm"),
|
||||||
|
QStringLiteral("RX °"), QStringLiteral("RY °"), QStringLiteral("RZ °"),
|
||||||
|
QStringLiteral("残差 mm"), QStringLiteral("操作")});
|
||||||
|
m_table->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||||
|
m_table->setSelectionMode(QAbstractItemView::NoSelection);
|
||||||
|
m_table->setAlternatingRowColors(true);
|
||||||
|
m_table->verticalHeader()->hide();
|
||||||
|
m_table->verticalHeader()->setDefaultSectionSize(36);
|
||||||
|
m_table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
||||||
|
m_table->setMinimumHeight(180);
|
||||||
|
pointsPanel->addWidget(m_table);
|
||||||
|
connect(m_method, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this] {
|
||||||
|
resizeSamples(m_method->currentIndex()==0 ? 4 : 6);
|
||||||
|
for (auto *spin : m_orientation) spin->setValue(0);
|
||||||
|
});
|
||||||
|
connect(restart, &QPushButton::clicked, this, &TcpCalibrationWidget::resetCalibration);
|
||||||
|
|
||||||
|
auto *resultPanel = panel(layout, QStringLiteral("TCP 参数(相对法兰)"));
|
||||||
|
auto *resultGrid = new QGridLayout;
|
||||||
|
for (int i = 0; i < 6; ++i) {
|
||||||
|
auto *axisLabel = new QLabel(axis(i) + (i < 3 ? QStringLiteral(" mm") : QStringLiteral(" °(手动)")));
|
||||||
|
resultGrid->addWidget(axisLabel, 0, i);
|
||||||
|
if (i>=3) m_orientationLabels.append(axisLabel);
|
||||||
|
if (i < 3) {
|
||||||
|
auto *value = new QLabel(QStringLiteral("--"));
|
||||||
|
value->setObjectName(QStringLiteral("tcpResult%1").arg(i));
|
||||||
|
value->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
||||||
|
m_results.append(value);
|
||||||
|
resultGrid->addWidget(value, 1, i);
|
||||||
|
} else {
|
||||||
|
auto *spin = new QDoubleSpinBox;
|
||||||
|
spin->setObjectName(QStringLiteral("tcpOrientation%1").arg(i));
|
||||||
|
spin->setRange(-360, 360);
|
||||||
|
spin->setDecimals(4);
|
||||||
|
spin->setSuffix(QStringLiteral(" °"));
|
||||||
|
m_orientation.append(spin);
|
||||||
|
resultGrid->addWidget(spin, 1, i);
|
||||||
|
connect(spin, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
|
||||||
|
[this](double) { refresh(); });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resultPanel->addLayout(resultGrid);
|
||||||
|
for (auto *spin : m_orientation) spin->setToolTip(QStringLiteral("固定点法仅求解平移;工具姿态需手动设置,采用 ZYX 欧拉角。"));
|
||||||
|
m_rms = new QLabel(QStringLiteral("固定点 RMS:--(合格上限 2.000 mm)"));
|
||||||
|
m_rms->setObjectName(QStringLiteral("tcpRms"));
|
||||||
|
resultPanel->addWidget(m_rms);
|
||||||
|
m_preview = hint(QStringLiteral("基座下工具位姿:--"));
|
||||||
|
m_preview->setObjectName(QStringLiteral("tcpToolPreview"));
|
||||||
|
resultPanel->addWidget(m_preview);
|
||||||
|
auto *actions = new QHBoxLayout;
|
||||||
|
m_status = hint(QStringLiteral("等待采样"));
|
||||||
|
m_status->setObjectName(QStringLiteral("tcpStatus"));
|
||||||
|
actions->addWidget(m_status, 1);
|
||||||
|
m_calculate = new QPushButton(QStringLiteral("TCP 标定"));
|
||||||
|
m_calculate->setObjectName(QStringLiteral("primaryButton"));
|
||||||
|
m_calculate->setProperty("tcpAction", QStringLiteral("calculate"));
|
||||||
|
m_save = new QPushButton(QStringLiteral("保存工具"));
|
||||||
|
m_save->setObjectName(QStringLiteral("tcpSave"));
|
||||||
|
actions->addWidget(m_calculate);
|
||||||
|
actions->addWidget(m_save);
|
||||||
|
outer->addLayout(actions);
|
||||||
|
layout->addStretch();
|
||||||
|
connect(m_calculate, &QPushButton::clicked, this, &TcpCalibrationWidget::calculate);
|
||||||
|
connect(m_save, &QPushButton::clicked, this, &TcpCalibrationWidget::saveTool);
|
||||||
|
connect(m_name, &QLineEdit::textChanged, this, [this](const QString &) { refresh(); });
|
||||||
|
connect(m_toolCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &TcpCalibrationWidget::selectTool);
|
||||||
|
connect(m_reload, &QPushButton::clicked, this, [this] { reloadTools(); });
|
||||||
|
connect(m_delete, &QPushButton::clicked, this, &TcpCalibrationWidget::deleteTool);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpCalibrationWidget::setContext(const QString &endpoint, const QString &deviceId,
|
||||||
|
bool connected, bool demoMode)
|
||||||
|
{
|
||||||
|
const bool identityChanged = endpoint != m_endpoint || deviceId != m_device;
|
||||||
|
const bool sessionChanged = connected != m_connected || demoMode != m_demo;
|
||||||
|
m_endpoint = endpoint;
|
||||||
|
m_device = deviceId;
|
||||||
|
m_connected = connected;
|
||||||
|
m_demo = demoMode;
|
||||||
|
if (identityChanged || sessionChanged) {
|
||||||
|
const QSignalBlocker blocker(m_sourceConfirmed);
|
||||||
|
m_sourceConfirmed->setChecked(false);
|
||||||
|
resetCalibration();
|
||||||
|
if (identityChanged) {
|
||||||
|
m_loading = true;
|
||||||
|
for (auto *spin : m_source) spin->setValue(0);
|
||||||
|
m_loading = false;
|
||||||
|
}
|
||||||
|
reloadTools();
|
||||||
|
}
|
||||||
|
refresh();
|
||||||
|
emit referenceChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TcpCalibrationWidget::referenceConfirmed() const
|
||||||
|
{
|
||||||
|
return m_connected && !m_demo && !m_device.trimmed().isEmpty() && m_sourceConfirmed->isChecked();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpCalibrationWidget::invalidateReference()
|
||||||
|
{
|
||||||
|
const QSignalBlocker blocker(m_sourceConfirmed);
|
||||||
|
m_sourceConfirmed->setChecked(false);
|
||||||
|
resetCalibration();
|
||||||
|
emit referenceChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TcpCalibrationWidget::hasSamples() const
|
||||||
|
{
|
||||||
|
for (const auto &sample : m_samples) if (sample.captured) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
void TcpCalibrationWidget::invalidateResult()
|
||||||
|
{
|
||||||
|
m_resultValid = false;
|
||||||
|
m_loadedResult = false;
|
||||||
|
m_result = TcpCalibration::Result{};
|
||||||
|
for (auto *label : m_results) label->setText(QStringLiteral("--"));
|
||||||
|
m_rms->setText(QStringLiteral("固定点 RMS:--(合格上限 2.000 mm)"));
|
||||||
|
m_preview->setText(QStringLiteral("基座下工具位姿:--"));
|
||||||
|
}
|
||||||
|
void TcpCalibrationWidget::resetCalibration()
|
||||||
|
{
|
||||||
|
++m_serial;
|
||||||
|
m_pendingRow = -1;
|
||||||
|
if (m_captureTimer) m_captureTimer->stop();
|
||||||
|
for (auto &sample : m_samples) sample = Sample{};
|
||||||
|
invalidateResult();
|
||||||
|
refresh();
|
||||||
|
emit logMessage(QStringLiteral("INFO"), QStringLiteral("TCP 标定临时采样已重置,已保存工具保持不变"));
|
||||||
|
}
|
||||||
|
void TcpCalibrationWidget::resizeSamples(int count)
|
||||||
|
{
|
||||||
|
++m_serial;
|
||||||
|
m_pendingRow = -1;
|
||||||
|
if (m_captureTimer) m_captureTimer->stop();
|
||||||
|
m_samples.assign(size_t(count),Sample{});
|
||||||
|
invalidateResult();
|
||||||
|
m_table->setRowCount(count);
|
||||||
|
m_table->setMinimumHeight(count*36+40);
|
||||||
|
for (int row = 0; row < count; ++row) {
|
||||||
|
for (int col = 0; col < 9; ++col)
|
||||||
|
if (!m_table->item(row, col)) m_table->setItem(row, col, new QTableWidgetItem);
|
||||||
|
if (!m_table->cellWidget(row, 9)) {
|
||||||
|
auto *button = new QPushButton(QStringLiteral("采集"));
|
||||||
|
button->setObjectName(QStringLiteral("tcpCapture%1").arg(row));
|
||||||
|
m_table->setCellWidget(row, 9, button);
|
||||||
|
connect(button, &QPushButton::clicked, this, [this, row] { capture(row); });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
TcpCalibration::Pose TcpCalibrationWidget::serverOffset() const
|
||||||
|
{
|
||||||
|
TcpCalibration::Pose pose{};
|
||||||
|
for (int i = 0; i < 6; ++i) pose[size_t(i)] = fromDisplay(m_source.at(i)->value(), i);
|
||||||
|
return pose;
|
||||||
|
}
|
||||||
|
void TcpCalibrationWidget::updateSource()
|
||||||
|
{
|
||||||
|
if (m_loading) return;
|
||||||
|
const QSignalBlocker blocker(m_sourceConfirmed);
|
||||||
|
m_sourceConfirmed->setChecked(false);
|
||||||
|
resetCalibration();
|
||||||
|
emit referenceChanged();
|
||||||
|
}
|
||||||
|
void TcpCalibrationWidget::refresh()
|
||||||
|
{
|
||||||
|
if (!m_table) return;
|
||||||
|
int captured = 0;
|
||||||
|
const bool busy = m_pendingRow >= 0;
|
||||||
|
const bool six = m_method->currentIndex()>0;
|
||||||
|
const bool xz = m_method->currentData().toString()=="six_point_xz";
|
||||||
|
m_instructions->setText(six
|
||||||
|
? QStringLiteral("1–3:固定尖端位置并改变姿态;4:方向原点;5:+X;6:+%1。后三点保持相同姿态。").arg(xz?"Z":"Y")
|
||||||
|
: QStringLiteral("保持尖端位置不变,以四个不同姿态采样;工具方向手动设置。"));
|
||||||
|
m_instructions->setToolTip(six ? QStringLiteral("方向点从原点沿所需工具正轴平移,返回原点姿态后采下一轴。程序不会自动移动机器人。最小方向基线 10 mm;建议在安全行程内增加基线。") : QString());
|
||||||
|
const bool ready = m_connected && !m_demo && !m_device.trimmed().isEmpty()
|
||||||
|
&& m_sourceConfirmed->isChecked() && !busy;
|
||||||
|
for (int row = 0; row < int(m_samples.size()); ++row) {
|
||||||
|
const auto &sample = m_samples[size_t(row)];
|
||||||
|
captured += sample.captured;
|
||||||
|
const QString purpose=!six ? QStringLiteral("固定点") : row<3 ? QStringLiteral("接近点")
|
||||||
|
: row==3 ? QStringLiteral("方向原点") : row==4 ? QStringLiteral("+X") : xz?QStringLiteral("+Z"):QStringLiteral("+Y");
|
||||||
|
m_table->item(row, 0)->setText(QStringLiteral("%1 · %2").arg(row+1).arg(purpose));
|
||||||
|
m_table->item(row, 1)->setText(row == m_pendingRow ? QStringLiteral("读取中")
|
||||||
|
: sample.captured ? QStringLiteral("已采集") : QStringLiteral("未采集"));
|
||||||
|
for (int i = 0; i < 6; ++i) m_table->item(row, 2 + i)->setText(sample.captured
|
||||||
|
? QString::number(toDisplay(sample.flange[size_t(i)], i), 'f', 3) : QStringLiteral("--"));
|
||||||
|
m_table->item(row, 8)->setText(m_resultValid && !m_loadedResult
|
||||||
|
&& row < int(m_result.residualsMm.size())
|
||||||
|
? QString::number(m_result.residualsMm[size_t(row)], 'f', 3) : QStringLiteral("--"));
|
||||||
|
auto *button = qobject_cast<QPushButton *>(m_table->cellWidget(row, 9));
|
||||||
|
button->setText(sample.captured ? QStringLiteral("重新采集") : QStringLiteral("采集"));
|
||||||
|
button->setEnabled(ready);
|
||||||
|
}
|
||||||
|
m_method->setEnabled(!busy);
|
||||||
|
for (int i=0;i<m_orientation.size();++i) {
|
||||||
|
m_orientation[i]->setReadOnly(six); m_orientation[i]->setButtonSymbols(six?QAbstractSpinBox::NoButtons:QAbstractSpinBox::UpDownArrows);
|
||||||
|
m_orientationLabels[i]->setText(axis(i+3)+(six?QStringLiteral(" °(计算)"):QStringLiteral(" °(手动)")));
|
||||||
|
m_orientation[i]->setToolTip(six?QStringLiteral("由方向原点、+X 与第二方向点计算,ZYX 欧拉角。"):QStringLiteral("四点法仅求平移;工具方向手动设置,ZYX 欧拉角。"));
|
||||||
|
}
|
||||||
|
m_toolCombo->setEnabled(!busy);
|
||||||
|
m_name->setEnabled(!busy);
|
||||||
|
m_reload->setEnabled(!busy && !m_device.isEmpty());
|
||||||
|
m_delete->setEnabled(!busy && m_toolCombo->currentIndex() > 0);
|
||||||
|
for (auto *spin : m_source) spin->setEnabled(!busy);
|
||||||
|
m_sourceConfirmed->setEnabled(!busy && m_connected && !m_demo);
|
||||||
|
m_calculate->setEnabled(!busy && captured >= 4 && captured == int(m_samples.size()));
|
||||||
|
m_save->setEnabled(!busy && m_resultValid && m_result.rmsMm <= 2.0
|
||||||
|
&& !m_name->text().trimmed().isEmpty());
|
||||||
|
m_status->setText(busy ? QStringLiteral("正在读取真实位姿…") : m_resultValid
|
||||||
|
? (m_result.rmsMm > 2.0 ? QStringLiteral("误差超限,禁止保存,请重新采样")
|
||||||
|
: m_loadedResult ? (six ? QStringLiteral("已加载六点标定结果") : QStringLiteral("已加载标定结果,可修改名称或手动方向"))
|
||||||
|
: QStringLiteral("已计算,尚未保存"))
|
||||||
|
: QStringLiteral("已采集 %1 / %2 点%3").arg(captured).arg(m_samples.size())
|
||||||
|
.arg(!m_sourceConfirmed->isChecked() ? QStringLiteral(" · 请先核对活动 TCP 偏移") : QString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpCalibrationWidget::capture(int index)
|
||||||
|
{
|
||||||
|
if (index < 0 || index >= int(m_samples.size()) || m_pendingRow >= 0) return;
|
||||||
|
if (!m_connected || m_demo || !m_sourceConfirmed->isChecked() || m_device.isEmpty()) {
|
||||||
|
reportError(QStringLiteral("请连接真实机械臂并核对服务端活动 TCP 偏移"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
invalidateResult();
|
||||||
|
// A failed replacement must not silently reuse the previous observation.
|
||||||
|
m_samples[size_t(index)] = Sample{};
|
||||||
|
m_pendingRow = index;
|
||||||
|
++m_serial;
|
||||||
|
m_captureTimer->start();
|
||||||
|
refresh();
|
||||||
|
emit captureRequested(m_device, m_serial);
|
||||||
|
}
|
||||||
|
bool TcpCalibrationWidget::readPose(const QVariantMap &map, TcpCalibration::Pose &pose) const
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 6; ++i) {
|
||||||
|
const QString name = QString::fromLatin1(keys[i]);
|
||||||
|
bool ok = false;
|
||||||
|
pose[size_t(i)] = map.value(name).toDouble(&ok);
|
||||||
|
if (!map.contains(name) || !ok || !std::isfinite(pose[size_t(i)])) return false;
|
||||||
|
}
|
||||||
|
return TcpCalibration::validPose(pose);
|
||||||
|
}
|
||||||
|
void TcpCalibrationWidget::acceptPose(quint64 requestId, const QString &deviceId,
|
||||||
|
const QVariantMap &pose, const QVariantMap &state,
|
||||||
|
bool success, const QString &detail)
|
||||||
|
{
|
||||||
|
if (requestId != m_serial || deviceId != m_device || m_pendingRow < 0) return;
|
||||||
|
const int row = m_pendingRow;
|
||||||
|
m_pendingRow = -1;
|
||||||
|
m_captureTimer->stop();
|
||||||
|
if (!success) { refresh(); reportError(detail); return; }
|
||||||
|
if (!m_connected || m_demo || !m_sourceConfirmed->isChecked()
|
||||||
|
|| !state.value(QStringLiteral("connected")).toBool()
|
||||||
|
|| state.value(QStringLiteral("moving"), true).toBool()
|
||||||
|
|| state.value(QStringLiteral("fault"), true).toBool()) {
|
||||||
|
refresh(); reportError(QStringLiteral("机械臂状态不可用于采点,请停稳并重新核对")); return;
|
||||||
|
}
|
||||||
|
TcpCalibration::Pose tcp{}, flange{};
|
||||||
|
QString error;
|
||||||
|
if (!readPose(pose, tcp) || !TcpCalibration::flangePose(tcp, serverOffset(), flange, &error)) {
|
||||||
|
refresh(); reportError(QStringLiteral("位姿数据无效:%1").arg(error)); return;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < int(m_samples.size()); ++i) {
|
||||||
|
// Direction origin may legitimately repeat one of the position poses.
|
||||||
|
if (m_method->currentIndex()>0 && ((i<3)!=(row<3))) continue;
|
||||||
|
if (i != row && m_samples[size_t(i)].captured
|
||||||
|
&& TcpCalibration::tooSimilar(m_samples[size_t(i)].flange, flange)) {
|
||||||
|
refresh(); reportError(QStringLiteral("与点位 %1 姿态过于接近,请改变腕部姿态后采集").arg(i + 1)); return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_samples[size_t(row)].flange = flange;
|
||||||
|
m_samples[size_t(row)].captured = true;
|
||||||
|
if (m_toolCombo->currentIndex() > 0 && m_toolCombo->currentIndex() <= m_tools.tools.size()) {
|
||||||
|
TcpCalibration::Pose preview{};
|
||||||
|
if (TcpCalibration::toolPose(flange, m_tools.tools.at(m_toolCombo->currentIndex() - 1).offset, preview)) {
|
||||||
|
QStringList values;
|
||||||
|
for (int i = 0; i < 6; ++i) values << QString::number(toDisplay(preview[size_t(i)], i), 'f', 3);
|
||||||
|
m_preview->setText(QStringLiteral("基座下工具位姿(mm / °):%1").arg(values.join(QStringLiteral(", "))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
refresh();
|
||||||
|
emit logMessage(QStringLiteral("OK"), QStringLiteral("TCP 点位 %1 已采集 · %2 · 法兰位姿 m/rad,活动 TCP 偏移已换算")
|
||||||
|
.arg(row + 1).arg(m_device));
|
||||||
|
}
|
||||||
|
void TcpCalibrationWidget::calculate()
|
||||||
|
{
|
||||||
|
std::vector<TcpCalibration::Pose> poses;
|
||||||
|
for (const auto &sample : m_samples) {
|
||||||
|
if (!sample.captured) { reportError(QStringLiteral("请先完成所有点位采集")); return; }
|
||||||
|
poses.push_back(sample.flange);
|
||||||
|
}
|
||||||
|
invalidateResult();
|
||||||
|
QString error;
|
||||||
|
const bool solved=m_method->currentIndex()==0 ? TcpCalibration::solve(poses,m_result,&error)
|
||||||
|
: TcpCalibration::solveSixPoint(poses,m_method->currentData().toString()=="six_point_xz"
|
||||||
|
? TcpCalibration::DirectionMethod::XZ : TcpCalibration::DirectionMethod::XY,m_result,&error);
|
||||||
|
if (!solved) {
|
||||||
|
refresh(); reportError(error); return;
|
||||||
|
}
|
||||||
|
m_resultValid = true;
|
||||||
|
showResult(m_result.offset, m_result.rmsMm, false);
|
||||||
|
refresh();
|
||||||
|
emit logMessage(m_result.rmsMm <= 2.0 ? QStringLiteral("OK") : QStringLiteral("WARN"),
|
||||||
|
QStringLiteral("TCP 计算完成,%1 点,RMS %2 mm%3").arg(poses.size())
|
||||||
|
.arg(m_result.rmsMm, 0, 'f', 3)
|
||||||
|
.arg(m_result.rmsMm > 2.0 ? QStringLiteral(",超过 2 mm,禁止保存") : QString()));
|
||||||
|
}
|
||||||
|
void TcpCalibrationWidget::showResult(const TcpCalibration::Pose &offset, double rmsMm, bool loaded)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 3; ++i) m_results.at(i)->setText(QString::number(offset[size_t(i)] * 1000, 'f', 3));
|
||||||
|
if (m_method->currentIndex()>0)
|
||||||
|
for (int i=0;i<3;++i) m_orientation[i]->setValue(qRadiansToDegrees(offset[size_t(i+3)]));
|
||||||
|
m_rms->setText(QStringLiteral("固定点 RMS:%1 mm · %2%3").arg(rmsMm, 0, 'f', 3)
|
||||||
|
.arg(rmsMm <= 2.0 ? QStringLiteral("合格(≤ 2.000 mm)") : QStringLiteral("超限,禁止保存"))
|
||||||
|
.arg(loaded ? QStringLiteral(" · 已保存结果") : QString()));
|
||||||
|
}
|
||||||
|
void TcpCalibrationWidget::reportError(const QString &message)
|
||||||
|
{
|
||||||
|
emit logMessage(QStringLiteral("ERROR"), QStringLiteral("TCP 标定:%1").arg(message));
|
||||||
|
QMessageBox::warning(this, QStringLiteral("工具坐标标定"), message);
|
||||||
|
}
|
||||||
|
void TcpCalibrationWidget::saveTool()
|
||||||
|
{
|
||||||
|
if (!m_resultValid || !std::isfinite(m_result.rmsMm) || m_result.rmsMm > 2.0) {
|
||||||
|
reportError(QStringLiteral("请先得到 RMS 不超过 2 mm 的有效标定结果")); return;
|
||||||
|
}
|
||||||
|
TcpToolStore::Tool tool;
|
||||||
|
tool.name = m_name->text().trimmed();
|
||||||
|
tool.offset = m_result.offset;
|
||||||
|
if (m_method->currentIndex()==0)
|
||||||
|
for (int i = 0; i < 3; ++i) tool.offset[size_t(i + 3)] = qDegreesToRadians(m_orientation.at(i)->value());
|
||||||
|
tool.rmsMm = m_result.rmsMm;
|
||||||
|
tool.sampleCount = m_loadedResult ? m_loadedSampleCount : int(m_samples.size());
|
||||||
|
tool.method = m_loadedResult ? m_loadedMethod : m_method->currentData().toString();
|
||||||
|
bool replace = false;
|
||||||
|
for (const auto &saved : m_tools.tools) if (saved.name == tool.name) replace = true;
|
||||||
|
if (replace && QMessageBox::question(this, QStringLiteral("覆盖工具"),
|
||||||
|
QStringLiteral("当前机械臂的工具“%1”已存在,是否覆盖?").arg(tool.name),
|
||||||
|
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes) return;
|
||||||
|
QSettings settings;
|
||||||
|
QString error;
|
||||||
|
// TODO(controller TCP): ArmService currently has only ListTCPFrame;
|
||||||
|
// there is no Get/Set/Create/Delete TCP-offset RPC to call or verify.
|
||||||
|
// Keep local records distinct until actual persistent controller APIs exist.
|
||||||
|
if (!TcpToolStore::save(settings, m_endpoint, m_device, tool, replace, error)) {
|
||||||
|
reportError(error); return;
|
||||||
|
}
|
||||||
|
reloadTools(tool.name);
|
||||||
|
emit toolsChanged(m_endpoint, m_device, tool.name);
|
||||||
|
emit logMessage(QStringLiteral("OK"), QStringLiteral("TCP 本机工具“%1”已保存 · %2 / %3")
|
||||||
|
.arg(tool.name, m_endpoint, m_device));
|
||||||
|
QMessageBox::information(this, QStringLiteral("保存成功"),
|
||||||
|
QStringLiteral("已保存到当前机器人的工具配置,并同步到机械臂的工具坐标列表。选择该工具后可进行 TCP 点动。"));
|
||||||
|
}
|
||||||
|
void TcpCalibrationWidget::reloadTools(const QString &preferred)
|
||||||
|
{
|
||||||
|
if (m_device.trimmed().isEmpty() || m_endpoint.trimmed().isEmpty()) {
|
||||||
|
m_tools = TcpToolStore::Snapshot{};
|
||||||
|
const QSignalBlocker blocker(m_toolCombo);
|
||||||
|
m_toolCombo->clear();
|
||||||
|
m_toolCombo->addItem(QStringLiteral("新建工具"));
|
||||||
|
selectTool(0);
|
||||||
|
m_currentTool->setText(QStringLiteral("请先选择机械臂"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QSettings settings;
|
||||||
|
QString error;
|
||||||
|
TcpToolStore::Snapshot snapshot;
|
||||||
|
if (!TcpToolStore::load(settings, m_endpoint, m_device, snapshot, error)) {
|
||||||
|
emit logMessage(QStringLiteral("ERROR"), error);
|
||||||
|
m_currentTool->setText(error);
|
||||||
|
m_tools = TcpToolStore::Snapshot{};
|
||||||
|
const QSignalBlocker blocker(m_toolCombo);
|
||||||
|
m_toolCombo->clear(); m_toolCombo->addItem(QStringLiteral("配置读取失败"));
|
||||||
|
resetCalibration();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_tools = snapshot;
|
||||||
|
const QString wanted = preferred.isEmpty() ? snapshot.current : preferred;
|
||||||
|
int selected = 0;
|
||||||
|
{
|
||||||
|
const QSignalBlocker blocker(m_toolCombo);
|
||||||
|
m_toolCombo->clear();
|
||||||
|
m_toolCombo->addItem(QStringLiteral("新建工具"));
|
||||||
|
for (const auto &tool : snapshot.tools) {
|
||||||
|
m_toolCombo->addItem(tool.name);
|
||||||
|
if (tool.name == wanted) selected = m_toolCombo->count() - 1;
|
||||||
|
}
|
||||||
|
m_toolCombo->setCurrentIndex(selected);
|
||||||
|
}
|
||||||
|
selectTool(selected);
|
||||||
|
}
|
||||||
|
void TcpCalibrationWidget::selectTool(int index)
|
||||||
|
{
|
||||||
|
resetCalibration();
|
||||||
|
m_loading = true;
|
||||||
|
if (index <= 0 || index > m_tools.tools.size()) {
|
||||||
|
m_name->clear();
|
||||||
|
for (auto *spin : m_orientation) spin->setValue(0);
|
||||||
|
m_currentTool->setText(QStringLiteral("新工具 · 未保存"));
|
||||||
|
} else {
|
||||||
|
const auto &tool = m_tools.tools.at(index - 1);
|
||||||
|
{ const QSignalBlocker blocker(m_method);
|
||||||
|
m_method->setCurrentIndex(qMax(0,m_method->findData(tool.method))); }
|
||||||
|
resizeSamples(m_method->currentIndex()==0 ? 4 : 6);
|
||||||
|
m_name->setText(tool.name);
|
||||||
|
m_result.offset = tool.offset;
|
||||||
|
m_result.rmsMm = tool.rmsMm;
|
||||||
|
m_loadedSampleCount = tool.sampleCount;
|
||||||
|
m_loadedMethod = tool.method;
|
||||||
|
m_resultValid = true;
|
||||||
|
m_loadedResult = true;
|
||||||
|
for (int i = 0; i < 3; ++i) m_orientation.at(i)->setValue(qRadiansToDegrees(tool.offset[size_t(i + 3)]));
|
||||||
|
showResult(tool.offset, tool.rmsMm, true);
|
||||||
|
m_currentTool->setText(QStringLiteral("%1 · %2 点标定").arg(tool.name).arg(tool.sampleCount));
|
||||||
|
emit logMessage(QStringLiteral("INFO"), QStringLiteral("已加载工具标定结果:%1").arg(tool.name));
|
||||||
|
}
|
||||||
|
m_loading = false;
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
void TcpCalibrationWidget::deleteTool()
|
||||||
|
{
|
||||||
|
const int index = m_toolCombo->currentIndex() - 1;
|
||||||
|
if (index < 0 || index >= m_tools.tools.size()) return;
|
||||||
|
const QString name = m_tools.tools.at(index).name;
|
||||||
|
if (QMessageBox::question(this, QStringLiteral("删除工具"),
|
||||||
|
QStringLiteral("删除当前机械臂的工具“%1”?对应的工具坐标选项也将移除。").arg(name),
|
||||||
|
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes) return;
|
||||||
|
QSettings settings;
|
||||||
|
QString error;
|
||||||
|
if (!TcpToolStore::remove(settings, m_endpoint, m_device, name, error)) { reportError(error); return; }
|
||||||
|
reloadTools();
|
||||||
|
emit toolsChanged(m_endpoint, m_device, QString());
|
||||||
|
emit logMessage(QStringLiteral("INFO"), QStringLiteral("已删除本机 TCP 工具:%1").arg(name));
|
||||||
|
}
|
||||||
446
src/touchoperationwidget.cpp
Normal file
446
src/touchoperationwidget.cpp
Normal file
@ -0,0 +1,446 @@
|
|||||||
|
#include "touchoperationwidget.h"
|
||||||
|
#include "touchvideowidget.h"
|
||||||
|
#include <QCheckBox>
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QCryptographicHash>
|
||||||
|
#include <QDateTime>
|
||||||
|
#include <QDoubleSpinBox>
|
||||||
|
#include <QFrame>
|
||||||
|
#include <QGridLayout>
|
||||||
|
#include <QHeaderView>
|
||||||
|
#include <QHideEvent>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QScrollArea>
|
||||||
|
#include <QSettings>
|
||||||
|
#include <QSignalBlocker>
|
||||||
|
#include <QSpinBox>
|
||||||
|
#include <QTableWidget>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
using Pose=TcpCalibration::Pose;
|
||||||
|
constexpr quint64 kPosePrefix=quint64(1)<<58;
|
||||||
|
constexpr quint64 kImagePrefix=quint64(1)<<57;
|
||||||
|
QVariantList values(const Pose &pose) { QVariantList result; for(double v:pose) result<<v; return result; }
|
||||||
|
bool poseFrom(const QVariant &value,Pose &pose) {
|
||||||
|
auto list=value.toList(); if(list.size()!=6) return false;
|
||||||
|
for(int i=0;i<6;++i) { bool ok=false; pose[i]=list[i].toDouble(&ok); if(!ok) return false; }
|
||||||
|
return TcpCalibration::validPose(pose);
|
||||||
|
}
|
||||||
|
bool decodePose(const QVariantMap &map,Pose &pose) {
|
||||||
|
QVariantList list; for(const auto &key:QStringList{"x","y","z","rx","ry","rz"}) list<<map.value(key);
|
||||||
|
return poseFrom(list,pose);
|
||||||
|
}
|
||||||
|
bool nearPose(const Pose &a,const Pose &b) {
|
||||||
|
TcpCalibration::Matrix x{},y{};
|
||||||
|
if(!TcpCalibration::poseMatrix(a,x)||!TcpCalibration::poseMatrix(b,y)) return false;
|
||||||
|
double distance=0,trace=0;
|
||||||
|
for(int i=0;i<3;++i) { distance+=std::pow(a[i]-b[i],2); for(int j=0;j<3;++j) trace+=x[i*4+j]*y[i*4+j]; }
|
||||||
|
return distance<=.0005*.0005 && std::acos(qBound(-1.0,(trace-1)/2,1.0))<=.2*3.141592653589793/180;
|
||||||
|
}
|
||||||
|
QString poseText(const Pose &pose) {
|
||||||
|
QStringList result; for(int i=0;i<6;++i) result<<QString::number(pose[i]*(i<3?1000:180/3.141592653589793),'f',2);
|
||||||
|
return result.join(" / ");
|
||||||
|
}
|
||||||
|
QVBoxLayout *panel(QBoxLayout *parent,const QString &title) {
|
||||||
|
auto *frame=new QFrame; frame->setObjectName("panel"); parent->addWidget(frame);
|
||||||
|
auto *layout=new QVBoxLayout(frame); layout->setContentsMargins(12,12,12,12); layout->setSpacing(8);
|
||||||
|
auto *label=new QLabel(title); label->setObjectName("sectionTitle"); layout->addWidget(label); return layout;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TouchOperationWidget::TouchOperationWidget(QWidget *parent):QWidget(parent),
|
||||||
|
m_sequence(new TouchSequenceController(this)),m_video(new TouchVideoWidget(this))
|
||||||
|
{
|
||||||
|
setObjectName("touchOperationPage");
|
||||||
|
m_video->setMaxPoints(2);
|
||||||
|
auto *outer=new QVBoxLayout(this); outer->setContentsMargins(12,10,12,10); outer->setSpacing(8);
|
||||||
|
auto *scroll=new QScrollArea; scroll->setWidgetResizable(true); scroll->setFrameShape(QFrame::NoFrame);
|
||||||
|
auto *content=new QWidget; scroll->setWidget(content); outer->addWidget(scroll);
|
||||||
|
auto *root=new QVBoxLayout(content); root->setContentsMargins(0,0,0,0); root->setSpacing(10);
|
||||||
|
auto *top=new QHBoxLayout; top->setSpacing(10); root->addLayout(top);
|
||||||
|
auto *vision=panel(top,QStringLiteral("视觉取点"));
|
||||||
|
m_video->setMinimumWidth(320); m_video->setMaximumWidth(640); m_video->setFrameAspectLayoutEnabled(true);
|
||||||
|
vision->setAlignment(Qt::AlignTop);
|
||||||
|
vision->addWidget(m_video,0,Qt::AlignTop|Qt::AlignHCenter);
|
||||||
|
auto *videoActions=new QHBoxLayout;
|
||||||
|
m_previewButton=new QPushButton(QStringLiteral("开始视频")); m_stopPreviewButton=new QPushButton(QStringLiteral("停止视频"));
|
||||||
|
m_lockButton=new QPushButton(QStringLiteral("锁定观察画面")); m_liveButton=new QPushButton(QStringLiteral("恢复实时"));
|
||||||
|
for(auto *b:{m_previewButton,m_stopPreviewButton,m_lockButton,m_liveButton}) videoActions->addWidget(b);
|
||||||
|
vision->addLayout(videoActions);
|
||||||
|
auto *hint=new QLabel(QStringLiteral("在锁定画面中选择 A / B 点;滑动按 A → B 执行。")); hint->setObjectName("mutedLabel"); vision->addWidget(hint);
|
||||||
|
auto *config=panel(top,QStringLiteral("任务配置")); top->setStretch(0,1); top->setStretch(1,1);
|
||||||
|
auto *grid=new QGridLayout; config->addLayout(grid);
|
||||||
|
m_handEyeChoice=new QComboBox; m_handEyeChoice->setObjectName("touchHandEye");
|
||||||
|
m_toolChoice=new QComboBox; m_toolChoice->setObjectName("touchTcp");
|
||||||
|
for(auto *c:{m_handEyeChoice,m_toolChoice}) { c->setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Fixed); c->setMinimumWidth(130); }
|
||||||
|
m_cameraName=new QLabel; m_cameraName->setWordWrap(true);
|
||||||
|
grid->setColumnStretch(1,1);
|
||||||
|
grid->addWidget(new QLabel(QStringLiteral("手眼标定")),0,0); grid->addWidget(m_handEyeChoice,0,1,1,2);
|
||||||
|
grid->addWidget(new QLabel(QStringLiteral("工具 TCP")),1,0); grid->addWidget(m_toolChoice,1,1,1,2);
|
||||||
|
grid->addWidget(new QLabel(QStringLiteral("相机")),2,0); grid->addWidget(m_cameraName,2,1);
|
||||||
|
m_reloadButton=new QPushButton(QStringLiteral("刷新标定")); grid->addWidget(m_reloadButton,2,2);
|
||||||
|
m_cameraConfirmed=new QCheckBox(QStringLiteral("已核对相机内参与时钟"));
|
||||||
|
m_cameraConfirmed->setToolTip(QStringLiteral("使用该相机 RGB 光学坐标系及标准 Brown 畸变模型;服务与上位机时钟同步,目标保持静止;深度单位及配准由服务提供。")); config->addWidget(m_cameraConfirmed);
|
||||||
|
m_teachObservation=new QPushButton(QStringLiteral("录入当前观察位")); m_teachObservation->setObjectName("touchTeachObservation");
|
||||||
|
m_returnButton=new QPushButton(QStringLiteral("回观察位"));
|
||||||
|
auto *teachRow=new QHBoxLayout; teachRow->addWidget(m_teachObservation,1); teachRow->addWidget(m_returnButton); config->addLayout(teachRow);
|
||||||
|
m_observationText=new QLabel; m_observationText->setWordWrap(true); m_observationText->setObjectName("mutedLabel"); config->addWidget(m_observationText);
|
||||||
|
config->addSpacing(8);
|
||||||
|
auto *actionTitle=new QLabel(QStringLiteral("动作参数")); actionTitle->setObjectName("sectionTitle"); config->addWidget(actionTitle);
|
||||||
|
auto *params=new QGridLayout; params->setHorizontalSpacing(8); params->setVerticalSpacing(8);
|
||||||
|
params->setColumnStretch(1,1); params->setColumnStretch(3,1); config->addLayout(params);
|
||||||
|
m_action=new QComboBox; m_action->setObjectName("touchAction"); m_action->addItems({QStringLiteral("单击"),QStringLiteral("双击"),QStringLiteral("滑动")});
|
||||||
|
params->addWidget(new QLabel(QStringLiteral("动作")),0,0); params->addWidget(m_action,0,1,1,3);
|
||||||
|
auto addSpin=[params](const QString &label,int row,int col,double value,double min,double max,const QString &suffix) {
|
||||||
|
auto *spin=new QDoubleSpinBox; spin->setRange(min,max); spin->setDecimals(2); spin->setValue(value); spin->setSuffix(suffix); spin->setKeyboardTracking(false);
|
||||||
|
params->addWidget(new QLabel(label),row,col); params->addWidget(spin,row,col+1); return spin;
|
||||||
|
};
|
||||||
|
m_approach=addSpin(QStringLiteral("接近高度"),1,0,10,1,50," mm");
|
||||||
|
m_press=addSpin(QStringLiteral("接触偏移"),1,2,0,0,2," mm");
|
||||||
|
m_lift=addSpin(QStringLiteral("双击抬笔"),4,0,1,1,20," mm");
|
||||||
|
m_speed=addSpin(QStringLiteral("移动速度"),2,0,30,5,50," mm/s");
|
||||||
|
m_contactSpeed=addSpin(QStringLiteral("接触速度"),2,2,10,5,30," mm/s");
|
||||||
|
m_travel=addSpin(QStringLiteral("运动范围"),3,0,300,10,1000," mm");
|
||||||
|
m_dwell=new QSpinBox; m_dwell->setRange(0,2000); m_dwell->setValue(50); m_dwell->setSuffix(" ms");
|
||||||
|
params->addWidget(new QLabel(QStringLiteral("接触停留")),3,2); params->addWidget(m_dwell,3,3);
|
||||||
|
m_gap=new QSpinBox; m_gap->setRange(20,500); m_gap->setValue(50); m_gap->setSuffix(" ms");
|
||||||
|
params->addWidget(new QLabel(QStringLiteral("双击间隔")),4,2); params->addWidget(m_gap,4,3);
|
||||||
|
config->addStretch();
|
||||||
|
m_press->setToolTip(QStringLiteral("沿相机 +Z 方向的几何位移,不是力控。首次验证建议为 0。"));
|
||||||
|
m_travel->setToolTip(QStringLiteral("相对观察位的最大位移与每段最大行程;不代替碰撞检查。"));
|
||||||
|
m_gap->setToolTip(QStringLiteral("抬笔到位后的停留;实际两次触点间隔还包含机械臂运动时间。"));
|
||||||
|
auto *bottom=new QHBoxLayout; root->addLayout(bottom);
|
||||||
|
auto *targetPanel=panel(bottom,QStringLiteral("目标点坐标换算结果"));
|
||||||
|
m_conversionStatus=new QLabel; m_conversionStatus->setObjectName("touchConversionStatus"); m_conversionStatus->setWordWrap(true);
|
||||||
|
m_conversionStatus->setToolTip(QStringLiteral("显示深度测量目标点,尚未叠加接触偏移;控制器 TCP 的实际运动目标见执行路径。"));
|
||||||
|
targetPanel->addWidget(m_conversionStatus);
|
||||||
|
m_targets=new QTableWidget(0,4); m_targets->setObjectName("touchTargets");
|
||||||
|
m_targets->setHorizontalHeaderLabels({QStringLiteral("点"),QStringLiteral("像素 · px"),QStringLiteral("相机 XYZ · mm"),QStringLiteral("基座 XYZ · mm")}); targetPanel->addWidget(m_targets);
|
||||||
|
auto *pathPanel=panel(bottom,QStringLiteral("执行路径"));
|
||||||
|
m_steps=new QTableWidget(0,3); m_steps->setObjectName("touchSteps"); m_steps->setHorizontalHeaderLabels({QStringLiteral("步骤"),QStringLiteral("控制器 TCP · XYZ mm / RxRyRz °"),QStringLiteral("速度 mm/s")}); pathPanel->addWidget(m_steps);
|
||||||
|
for(auto *table:{m_targets,m_steps}) { table->verticalHeader()->hide(); table->setEditTriggers(QAbstractItemView::NoEditTriggers); table->setMinimumHeight(150); table->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); table->horizontalHeader()->setStretchLastSection(true); }
|
||||||
|
m_targets->setMinimumHeight(188); m_targets->setMaximumHeight(230); m_targets->setWordWrap(false);
|
||||||
|
m_steps->setMinimumHeight(188); m_steps->setMaximumHeight(260);
|
||||||
|
for(auto *table:{m_targets,m_steps}) { table->setAlternatingRowColors(true); table->setShowGrid(false); }
|
||||||
|
m_targets->horizontalHeader()->setSectionResizeMode(2,QHeaderView::Stretch);
|
||||||
|
m_targets->horizontalHeader()->setSectionResizeMode(3,QHeaderView::Stretch);
|
||||||
|
bottom->setStretch(0,1); bottom->setStretch(1,1);
|
||||||
|
root->addStretch(1);
|
||||||
|
auto *footer=new QHBoxLayout; outer->addLayout(footer);
|
||||||
|
m_status=new QLabel; m_status->setWordWrap(true); m_status->setObjectName("mutedLabel"); outer->insertWidget(1,m_status);
|
||||||
|
m_pathConfirmed=new QCheckBox(QStringLiteral("已核对目标、笔姿及路径净空")); footer->addWidget(m_pathConfirmed);
|
||||||
|
footer->addStretch(1);
|
||||||
|
m_calculateButton=new QPushButton(QStringLiteral("转换 / 预览")); m_executeButton=new QPushButton(QStringLiteral("执行动作")); m_executeButton->setObjectName("primaryButton");
|
||||||
|
auto *stopButton=new QPushButton(QStringLiteral("停止")); stopButton->setObjectName("dangerOutlineButton");
|
||||||
|
footer->addWidget(m_calculateButton); footer->addWidget(m_executeButton); footer->addWidget(stopButton);
|
||||||
|
m_timeout.setSingleShot(true); m_timeout.setInterval(12000);
|
||||||
|
connect(&m_timeout,&QTimer::timeout,this,[this] { fail(QStringLiteral("读取超时,请检查连接后重试。")); });
|
||||||
|
connect(m_previewButton,&QPushButton::clicked,this,&TouchOperationWidget::startPreview);
|
||||||
|
connect(m_stopPreviewButton,&QPushButton::clicked,this,&TouchOperationWidget::stopPreview);
|
||||||
|
connect(m_lockButton,&QPushButton::clicked,this,&TouchOperationWidget::lockFrame);
|
||||||
|
connect(m_liveButton,&QPushButton::clicked,this,[this] { invalidateFrame(); refresh(); });
|
||||||
|
connect(m_teachObservation,&QPushButton::clicked,this,[this] { teach(Phase::Observation); });
|
||||||
|
connect(m_returnButton,&QPushButton::clicked,this,[this] { teach(Phase::Return); });
|
||||||
|
connect(m_calculateButton,&QPushButton::clicked,this,&TouchOperationWidget::calculate);
|
||||||
|
connect(m_executeButton,&QPushButton::clicked,this,&TouchOperationWidget::execute);
|
||||||
|
connect(stopButton,&QPushButton::clicked,this,[this] {
|
||||||
|
const bool active=running(); stop();
|
||||||
|
if(!active&&!m_device.isEmpty()) emit stopRequested(m_device);
|
||||||
|
});
|
||||||
|
connect(m_reloadButton,&QPushButton::clicked,this,&TouchOperationWidget::reloadCalibrations);
|
||||||
|
connect(m_video,&TouchVideoWidget::pointsChanged,this,[this] { invalidatePlan(); refresh(); });
|
||||||
|
connect(m_cameraConfirmed,&QCheckBox::toggled,this,[this] { invalidateFrame(); refresh(); });
|
||||||
|
connect(m_pathConfirmed,&QCheckBox::toggled,this,[this] { refresh(); });
|
||||||
|
connect(m_handEyeChoice,QOverload<int>::of(&QComboBox::currentIndexChanged),this,[this] { if(m_loading) return; stopPreview(); invalidateFrame(); m_cameraConfirmed->setChecked(false); saveTeaching(); refresh(); });
|
||||||
|
connect(m_toolChoice,QOverload<int>::of(&QComboBox::currentIndexChanged),this,[this] { if(m_loading) return; stop(); saveTeaching(); refresh(); });
|
||||||
|
connect(m_action,QOverload<int>::of(&QComboBox::currentIndexChanged),this,[this] { invalidatePlan(); refresh(); });
|
||||||
|
for(auto *spin:{m_approach,m_press,m_lift,m_speed,m_contactSpeed,m_travel}) connect(spin,QOverload<double>::of(&QDoubleSpinBox::valueChanged),this,[this] { invalidatePlan(); refresh(); });
|
||||||
|
for(auto *spin:{m_dwell,m_gap}) connect(spin,QOverload<int>::of(&QSpinBox::valueChanged),this,[this] { invalidatePlan(); refresh(); });
|
||||||
|
connect(m_sequence,&TouchSequenceController::captureRequested,this,&TouchOperationWidget::captureRequested);
|
||||||
|
connect(m_sequence,&TouchSequenceController::moveRequested,this,&TouchOperationWidget::moveRequested);
|
||||||
|
connect(m_sequence,&TouchSequenceController::stopRequested,this,&TouchOperationWidget::stopRequested);
|
||||||
|
connect(m_sequence,&TouchSequenceController::progressChanged,this,[this](int step,int count,const QString &label) { m_status->setText(QStringLiteral("执行 %1 / %2 · %3").arg(step).arg(count).arg(label)); refresh(); });
|
||||||
|
connect(m_sequence,&TouchSequenceController::errorOccurred,this,[this](const QString &error) { emit logMessage("ERROR",error); });
|
||||||
|
connect(m_sequence,&TouchSequenceController::finished,this,[this](bool success,const QString &detail) { invalidateFrame(); refresh(); m_status->setText(detail); emit logMessage(success?"OK":"WARN",QStringLiteral("末端操作:%1").arg(detail)); });
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TouchOperationWidget::running() const { return m_sequence->running(); }
|
||||||
|
bool TouchOperationWidget::ready() const { return m_connected&&!m_demo&&m_reference&&!m_device.isEmpty()&&TcpCalibration::validPose(m_activeOffset); }
|
||||||
|
const HandEyeStore::Record *TouchOperationWidget::handEye() const {
|
||||||
|
int i=m_handEyeChoice->currentIndex(); return i>=0&&i<m_handEyes.records.size()?&m_handEyes.records[i]:nullptr;
|
||||||
|
}
|
||||||
|
QString TouchOperationWidget::cameraId() const { auto *r=handEye(); return r?r->cameraId:QString(); }
|
||||||
|
bool TouchOperationWidget::selectedTool(Pose &offset) const {
|
||||||
|
int i=m_toolChoice->currentIndex(); if(i<0||i>=m_tools.tools.size()) return false;
|
||||||
|
offset=m_tools.tools[i].offset; return true;
|
||||||
|
}
|
||||||
|
void TouchOperationWidget::setContext(const QString &endpoint,const QString &device,bool connected,bool demo,bool reference,const Pose &offset) {
|
||||||
|
bool scope=endpoint!=m_endpoint||device!=m_device;
|
||||||
|
if(!scope&&offset!=m_activeOffset) { m_observed=false; }
|
||||||
|
if(scope||connected!=m_connected||demo!=m_demo||reference!=m_reference||offset!=m_activeOffset) {
|
||||||
|
stopPreview(); stop(); m_cameraConfirmed->setChecked(false);
|
||||||
|
}
|
||||||
|
m_endpoint=endpoint; m_device=device; m_connected=connected; m_demo=demo; m_reference=reference; m_activeOffset=offset;
|
||||||
|
if(scope) { m_observed=false; reloadCalibrations(); loadTeaching(); }
|
||||||
|
if(m_observed&&m_reference&&m_teachingOffset!=m_activeOffset) { m_observed=false; }
|
||||||
|
m_sequence->setContext(endpoint,device,ready(),offset); refresh();
|
||||||
|
}
|
||||||
|
void TouchOperationWidget::reloadCalibrations() {
|
||||||
|
stopPreview(); stop();
|
||||||
|
const QString oldHand=m_handEyeChoice->currentText(),oldTool=m_toolChoice->currentText();
|
||||||
|
m_loading=true; m_handEyeChoice->clear(); m_toolChoice->clear(); m_handEyes={}; m_tools={};
|
||||||
|
QSettings settings; QString error;
|
||||||
|
bool ok=m_endpoint.isEmpty()||m_device.isEmpty()||
|
||||||
|
(HandEyeStore::load(settings,m_endpoint,m_device,m_handEyes,error)&&TcpToolStore::load(settings,m_endpoint,m_device,m_tools,error));
|
||||||
|
if(ok) {
|
||||||
|
for(const auto &r:m_handEyes.records) m_handEyeChoice->addItem(r.name);
|
||||||
|
for(const auto &t:m_tools.tools) m_toolChoice->addItem(t.name);
|
||||||
|
int h=m_handEyeChoice->findText(oldHand),t=m_toolChoice->findText(oldTool);
|
||||||
|
if(h>=0) m_handEyeChoice->setCurrentIndex(h);
|
||||||
|
if(t>=0) m_toolChoice->setCurrentIndex(t);
|
||||||
|
}
|
||||||
|
m_loading=false;
|
||||||
|
m_cameraConfirmed->setChecked(false); refresh(); if(!ok) fail(error);
|
||||||
|
}
|
||||||
|
void TouchOperationWidget::invalidatePlan() { m_planValid=false; m_plan={}; m_pathConfirmed->setChecked(false); m_steps->setRowCount(0); }
|
||||||
|
void TouchOperationWidget::invalidateFrame() {
|
||||||
|
invalidatePlan(); m_lockedAt=0; m_pendingImage={}; m_depth={}; m_video->unlock(); m_video->clearSelection();
|
||||||
|
}
|
||||||
|
void TouchOperationWidget::stop() {
|
||||||
|
m_sequence->stop(); ++m_serial; m_poseToken=0; m_imageToken=0; m_phase=Phase::Idle; m_timeout.stop(); invalidateFrame(); refresh();
|
||||||
|
}
|
||||||
|
void TouchOperationWidget::fail(const QString &message) {
|
||||||
|
stop(); m_status->setText(message); emit logMessage("ERROR",QStringLiteral("末端操作:%1").arg(message));
|
||||||
|
QMessageBox::warning(this,QStringLiteral("末端操作"),message);
|
||||||
|
}
|
||||||
|
void TouchOperationWidget::hideEvent(QHideEvent *event) { stopPreview(); stop(); QWidget::hideEvent(event); }
|
||||||
|
void TouchOperationWidget::startPreview() {
|
||||||
|
if(!m_connected||m_demo||!handEye()) { fail(QStringLiteral("请连接机器人服务并选择手眼标定。")); return; }
|
||||||
|
stopPreview(); m_previewCamera=cameraId(); m_preview=true; emit previewRequested(m_previewCamera,true); refresh();
|
||||||
|
}
|
||||||
|
void TouchOperationWidget::stopPreview() {
|
||||||
|
const QString camera=m_previewCamera; bool active=m_preview; m_preview=false; m_previewCamera.clear();
|
||||||
|
if(active) emit previewRequested(camera,false);
|
||||||
|
stop(); m_video->clearFrame();
|
||||||
|
}
|
||||||
|
void TouchOperationWidget::acceptFrame(const QString &camera,const VideoFrame &frame,const QString &) {
|
||||||
|
if(!m_preview||camera!=m_previewCamera||!frame.isValid()) return;
|
||||||
|
if(frame.metadata.value("kind").toString()!="rgb") { m_status->setText(QStringLiteral("当前流不是 RGB,请在相机页面切换为彩色视频。")); return; }
|
||||||
|
m_video->present(frame);
|
||||||
|
|
||||||
|
}
|
||||||
|
void TouchOperationWidget::acceptStreamState(const QString &camera,bool active,const QString &detail) {
|
||||||
|
if(m_preview&&camera==m_previewCamera&&!active) { stopPreview(); m_status->setText(QStringLiteral("视频已停止:%1").arg(detail)); }
|
||||||
|
}
|
||||||
|
void TouchOperationWidget::teach(Phase phase) {
|
||||||
|
Pose offset{};
|
||||||
|
if(!ready()||running()||m_phase!=Phase::Idle||(phase!=Phase::Observation&&!selectedTool(offset))) { fail(QStringLiteral("请先连接机械臂、选择 TCP 标定并核对控制器偏移。")); return; }
|
||||||
|
if(phase==Phase::Return&&!m_observed) return;
|
||||||
|
invalidateFrame(); m_phase=phase; readPose();
|
||||||
|
}
|
||||||
|
void TouchOperationWidget::readPose() {
|
||||||
|
m_poseToken=kPosePrefix|++m_serial; m_requestAt=QDateTime::currentMSecsSinceEpoch(); m_timeout.start();
|
||||||
|
emit captureRequested(m_device,m_poseToken); refresh();
|
||||||
|
}
|
||||||
|
void TouchOperationWidget::lockFrame() {
|
||||||
|
if(!ready()||!m_preview||!m_observed||!m_cameraConfirmed->isChecked()||running()||m_phase!=Phase::Idle) return;
|
||||||
|
invalidateFrame(); m_phase=Phase::LockBefore; readPose();
|
||||||
|
}
|
||||||
|
void TouchOperationWidget::acceptPose(quint64 token,const QString &device,const QVariantMap &map,const QVariantMap &state,bool success,const QString &detail) {
|
||||||
|
m_sequence->acceptPose(token,device,map,state,success,detail);
|
||||||
|
if(!m_poseToken||token!=m_poseToken||device!=m_device) return;
|
||||||
|
m_poseToken=0; Pose pose{},tool{},flange{},selected{};
|
||||||
|
const qint64 requested=state.value("requestedAtMs").toLongLong(),received=state.value("receivedAtMs").toLongLong();
|
||||||
|
const qint64 now=QDateTime::currentMSecsSinceEpoch();
|
||||||
|
if(!success||!ready()||!decodePose(map,pose)||(m_phase!=Phase::Observation&&!selectedTool(tool))||requested<m_requestAt||received<requested||received>now||now-received>1500
|
||||||
|
||!state.value("connected").toBool()||state.value("moving",true).toBool()||state.value("fault",true).toBool()
|
||||||
|
||state.value("protectiveStopped",true).toBool()||state.value("emergencyStopped",true).toBool()
|
||||||
|
||state.value("source").toString()!=QStringLiteral("getRobotState.actual_tcp_pose")) { fail(QStringLiteral("实时位姿不可用:%1").arg(detail)); return; }
|
||||||
|
if(!TcpCalibration::flangePose(pose,m_activeOffset,flange)||!TcpCalibration::toolPose(flange,tool,selected)) { fail(QStringLiteral("TCP 位姿转换失败。")); return; }
|
||||||
|
const auto phase=m_phase;
|
||||||
|
if(phase==Phase::LockBefore) {
|
||||||
|
if(!nearPose(pose,m_observation)) { fail(QStringLiteral("机械臂不在观察位,请先回观察位并停稳。")); return; }
|
||||||
|
m_before=pose; m_beforeAt=received; m_phase=Phase::LockImage; m_imageToken=kImagePrefix|++m_serial;
|
||||||
|
emit imageRequested(cameraId(),m_imageToken); refresh(); return;
|
||||||
|
}
|
||||||
|
if(phase==Phase::LockAfter) {
|
||||||
|
if(requested<m_captureAt||!nearPose(m_before,pose)||!nearPose(pose,m_observation)||received-m_beforeAt>10000) { fail(QStringLiteral("取图期间位姿变化或时间窗无效,请停稳后重试。")); return; }
|
||||||
|
TcpCalibration::flangePose(m_before,m_activeOffset,m_lockedFlange);
|
||||||
|
if(!(m_video->lockImage(m_pendingImage))) { fail(QStringLiteral("观察图像无效。")); return; }
|
||||||
|
m_pendingImage={}; m_lockedAt=QDateTime::currentMSecsSinceEpoch();
|
||||||
|
} else if(phase==Phase::Observation) {
|
||||||
|
m_observation=pose; m_observed=true; m_teachingOffset=m_activeOffset; saveTeaching();
|
||||||
|
} else if(phase==Phase::Return) {
|
||||||
|
m_phase=Phase::Idle; m_timeout.stop(); returnObservation(pose); return;
|
||||||
|
}
|
||||||
|
m_phase=Phase::Idle; m_timeout.stop(); refresh(); emit logMessage("OK",QStringLiteral("末端操作:已录入位姿 / 锁定观察图像"));
|
||||||
|
}
|
||||||
|
void TouchOperationWidget::acceptImage(quint64 token,const QString &camera,const QImage &image,const QVariantMap &intrinsics,const QVariantMap &metadata,bool success,const QString &detail) {
|
||||||
|
if(!m_imageToken||token!=m_imageToken||camera!=cameraId()||m_phase!=Phase::LockImage) return;
|
||||||
|
m_imageToken=0; QString error;
|
||||||
|
if(!success) { fail(QStringLiteral("读取 RGBD 失败:%1").arg(detail)); return; }
|
||||||
|
const qint64 colorAt=metadata.value("captureUtcNs").toLongLong()/1000000;
|
||||||
|
const qint64 depthAt=metadata.value("depthCaptureUtcNs").toLongLong()/1000000;
|
||||||
|
const qint64 now=QDateTime::currentMSecsSinceEpoch();
|
||||||
|
if(!metadata.value("alignedToColor").toBool()||!metadata.value("colorAxialZ").toBool()
|
||||||
|
||metadata.value("byteOrder").toString()!="little"||colorAt<=0||depthAt<=0
|
||||||
|
||std::abs(colorAt-depthAt)>33||colorAt>now||depthAt>now) {
|
||||||
|
fail(QStringLiteral("RGBD 缺少有效配准、深度单位或同步时间戳,请更新相机服务。")); return;
|
||||||
|
}
|
||||||
|
if(colorAt<m_beforeAt||depthAt<m_beforeAt||now-qMin(colorAt,depthAt)>1500) {
|
||||||
|
// The server snapshots its acquisition thread. Wait for a new pair;
|
||||||
|
// never combine a live color frame with an older depth image.
|
||||||
|
const quint64 generation=m_serial;
|
||||||
|
QTimer::singleShot(80,this,[this,generation] {
|
||||||
|
if(m_serial!=generation||m_phase!=Phase::LockImage||m_imageToken) return;
|
||||||
|
m_imageToken=kImagePrefix|++m_serial; emit imageRequested(cameraId(),m_imageToken);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
TouchPlanner::DepthImage depth;
|
||||||
|
depth.width=metadata.value("depthWidth").toInt(); depth.height=metadata.value("depthHeight").toInt();
|
||||||
|
depth.data=metadata.value("depthData").toByteArray(); depth.float32=metadata.value("depthFloat32").toBool();
|
||||||
|
depth.metresPerUnit=metadata.value("metresPerUnit").toDouble();
|
||||||
|
if(image.isNull()||!TouchPlanner::cameraModel(intrinsics,image.width(),image.height(),m_cameraModel,&error)
|
||||||
|
||depth.width!=image.width()||depth.height!=image.height()
|
||||||
|
||!std::isfinite(depth.metresPerUnit)||depth.metresPerUnit<=0||depth.metresPerUnit>1
|
||||||
|
||qint64(depth.width)*depth.height*(depth.float32?4:2)!=depth.data.size()) {
|
||||||
|
fail(QStringLiteral("RGBD 尺寸、单位或内参无效:%1").arg(error)); return;
|
||||||
|
}
|
||||||
|
m_depth=depth; m_pendingImage=image; m_captureAt=qMax(colorAt,depthAt); m_phase=Phase::LockAfter; readPose();
|
||||||
|
}
|
||||||
|
void TouchOperationWidget::acceptCommand(const QString &command,bool success,const QString &detail) { m_sequence->acceptCommand(command,success,detail); }
|
||||||
|
TouchPlanner::Parameters TouchOperationWidget::parameters() const {
|
||||||
|
TouchPlanner::Parameters p; p.approachM=m_approach->value()/1000; p.contactOffsetM=m_press->value()/1000;
|
||||||
|
p.doubleLiftM=m_lift->value()/1000; p.travelVelocityMps=m_speed->value()/1000; p.contactVelocityMps=m_contactSpeed->value()/1000;
|
||||||
|
p.maxTravelM=m_travel->value()/1000; p.contactDwellMs=m_dwell->value(); p.doubleIntervalMs=m_gap->value(); return p;
|
||||||
|
}
|
||||||
|
bool TouchOperationWidget::buildPlane(TouchPlanner::Plane &plane,QString &error) const {
|
||||||
|
QVector<TouchPlanner::Point> points,cameraPoints;
|
||||||
|
TouchPlanner::Matrix baseCamera{}; Pose offset{},tip{};
|
||||||
|
if(!resolveTargets(points,cameraPoints,error)||!selectedTool(offset)
|
||||||
|
||!TcpCalibration::toolPose(m_lockedFlange,offset,tip,&error)
|
||||||
|
||!TouchPlanner::cameraTransform(*handEye(),m_lockedFlange,baseCamera,&error)) return false;
|
||||||
|
plane.origin=points.first();
|
||||||
|
// Same free-pixel approach direction as phone: negative camera Z.
|
||||||
|
// Preserve the selected stylus orientation taught at the observation pose.
|
||||||
|
for(int i=0;i<3;++i) { plane.normal[i]=-baseCamera[i*4+2]; plane.orientationRad[i]=tip[i+3]; }
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
void TouchOperationWidget::calculate() {
|
||||||
|
invalidatePlan(); QString error; Pose tool{}; TouchPlanner::Plane plane; QVector<TouchPlanner::Point> points,cameraPoints;
|
||||||
|
TouchPlanner::Matrix baseCamera{};
|
||||||
|
if(!ready()||!handEye()||!selectedTool(tool)||!m_video->locked()||!m_lockedAt||QDateTime::currentMSecsSinceEpoch()-m_lockedAt>60000) { fail(QStringLiteral("请在观察位重新锁定画面后取点。")); return; }
|
||||||
|
if(!buildPlane(plane,error)||!resolveTargets(points,cameraPoints,error)
|
||||||
|
||!TouchPlanner::cameraTransform(*handEye(),m_lockedFlange,baseCamera,&error)
|
||||||
|
||(m_action->currentIndex()==2&&!TouchPlanner::validateDepthSwipe(m_video->selectedPoints(),m_cameraModel,m_depth,baseCamera,parameters(),&error))
|
||||||
|
||!TouchPlanner::buildPlan(static_cast<TouchPlanner::Action>(m_action->currentIndex()),points,plane,m_observation,m_activeOffset,tool,parameters(),m_plan,&error,true)) { fail(error); return; }
|
||||||
|
m_planValid=true; m_steps->setRowCount(m_plan.steps.size());
|
||||||
|
for(int i=0;i<m_plan.steps.size();++i) { const auto &step=m_plan.steps[i]; m_steps->setItem(i,0,new QTableWidgetItem(QString::number(i+1)+" · "+step.label));
|
||||||
|
m_steps->setItem(i,1,new QTableWidgetItem(poseText(step.target))); m_steps->setItem(i,2,new QTableWidgetItem(QString::number(step.velocityMps*1000,'f',1))); }
|
||||||
|
refresh(); emit logMessage("INFO",QStringLiteral("末端操作:已转换 %1 个目标,规划 %2 个动作步骤").arg(points.size()).arg(m_plan.steps.size()));
|
||||||
|
}
|
||||||
|
void TouchOperationWidget::execute() {
|
||||||
|
if(!m_planValid||!m_pathConfirmed->isChecked()||running()||!ready()||QDateTime::currentMSecsSinceEpoch()-m_lockedAt>60000) { fail(QStringLiteral("请重新预览路径并确认后执行。")); return; }
|
||||||
|
QVector<TouchSequenceController::Step> steps;
|
||||||
|
for(const auto &s:m_plan.steps) steps.append({s.target,s.velocityMps,s.accelerationMps2,s.pauseMs,s.label});
|
||||||
|
m_sequence->setContext(m_endpoint,m_device,ready(),m_activeOffset);
|
||||||
|
m_sequence->start(steps,m_observation); refresh();
|
||||||
|
}
|
||||||
|
void TouchOperationWidget::returnObservation(const Pose ¤t) {
|
||||||
|
// Explicit straight return; automatic touch sequences retract before return.
|
||||||
|
auto p=parameters(); double distance=0; for(int i=0;i<3;++i) distance+=std::pow(current[i]-m_observation[i],2);
|
||||||
|
if(std::sqrt(distance)>p.maxTravelM) { fail(QStringLiteral("当前位置超出所设回程范围,请手动接近观察位。")); return; }
|
||||||
|
QVector<TouchSequenceController::Step> steps; Pose tool{};
|
||||||
|
steps.append({m_observation,p.travelVelocityMps,p.accelerationMps2,0,QStringLiteral("返回观察位")});
|
||||||
|
if(!selectedTool(tool)) { fail(QStringLiteral("请选择有效 TCP。")); return; }
|
||||||
|
Pose previous=current,previousFlange{},previousTip{},obsFlange{},obsTip{};
|
||||||
|
if(!TcpCalibration::flangePose(current,m_activeOffset,previousFlange)||!TcpCalibration::toolPose(previousFlange,tool,previousTip)
|
||||||
|
||!TcpCalibration::flangePose(m_observation,m_activeOffset,obsFlange)||!TcpCalibration::toolPose(obsFlange,tool,obsTip)) { fail(QStringLiteral("回程位姿转换失败。")); return; }
|
||||||
|
for(const auto &step:steps) {
|
||||||
|
Pose nextFlange{},nextTip{};
|
||||||
|
if(!TcpCalibration::flangePose(step.target,m_activeOffset,nextFlange)||!TcpCalibration::toolPose(nextFlange,tool,nextTip)) { fail(QStringLiteral("回程位姿转换失败。")); return; }
|
||||||
|
auto norm=[](const Pose &a,const Pose &b) { double sum=0; for(int i=0;i<3;++i) sum+=std::pow(a[i]-b[i],2); return std::sqrt(sum); };
|
||||||
|
const Pose origin{};
|
||||||
|
if(norm(step.target,previous)>p.maxTravelM||norm(nextTip,previousTip)>p.maxTravelM||norm(nextFlange,previousFlange)>p.maxTravelM
|
||||||
|
||norm(step.target,m_observation)>p.maxTravelM||norm(nextTip,obsTip)>p.maxTravelM||norm(nextFlange,obsFlange)>p.maxTravelM
|
||||||
|
||norm(step.target,origin)>p.maxReachM||norm(nextTip,origin)>p.maxReachM||norm(nextFlange,origin)>p.maxReachM) { fail(QStringLiteral("回程路径超出所设运动范围。")); return; }
|
||||||
|
previous=step.target; previousTip=nextTip; previousFlange=nextFlange;
|
||||||
|
}
|
||||||
|
m_sequence->setContext(m_endpoint,m_device,ready(),m_activeOffset); m_sequence->start(steps,current); refresh();
|
||||||
|
}
|
||||||
|
QString TouchOperationWidget::settingsKey() const {
|
||||||
|
QByteArray identity=m_endpoint.toUtf8(); identity.append('\0'); identity.append(m_device.toUtf8());
|
||||||
|
return QStringLiteral("touchOperation/v1/")+QString::fromLatin1(QCryptographicHash::hash(identity,QCryptographicHash::Sha256).toHex());
|
||||||
|
}
|
||||||
|
void TouchOperationWidget::saveTeaching() {
|
||||||
|
if(m_loading||m_endpoint.isEmpty()||m_device.isEmpty()) return;
|
||||||
|
Pose tool{}; QVariantMap data{{"endpoint",m_endpoint},{"device",m_device},{"handEye",m_handEyeChoice->currentText()},{"tool",m_toolChoice->currentText()},
|
||||||
|
{"observed",m_observed},{"observation",values(m_observation)},{"activeOffset",values(m_teachingOffset)}};
|
||||||
|
if(selectedTool(tool)) data.insert("toolOffset",values(tool));
|
||||||
|
QSettings settings; settings.setValue(settingsKey(),QJsonDocument::fromVariant(data).toJson(QJsonDocument::Compact)); settings.sync();
|
||||||
|
if(settings.status()!=QSettings::NoError) { m_status->setText(QStringLiteral("示教配置写入失败")); emit logMessage("ERROR",m_status->text()); }
|
||||||
|
}
|
||||||
|
void TouchOperationWidget::loadTeaching() {
|
||||||
|
QSettings settings; auto bytes=settings.value(settingsKey()).toByteArray(); if(bytes.isEmpty()) return;
|
||||||
|
const auto data=QJsonDocument::fromJson(bytes).toVariant().toMap();
|
||||||
|
if(data.value("endpoint").toString()!=m_endpoint||data.value("device").toString()!=m_device) return;
|
||||||
|
m_loading=true; const int h=m_handEyeChoice->findText(data.value("handEye").toString()),t=m_toolChoice->findText(data.value("tool").toString());
|
||||||
|
if(h>=0) m_handEyeChoice->setCurrentIndex(h);
|
||||||
|
if(t>=0) m_toolChoice->setCurrentIndex(t);
|
||||||
|
m_loading=false;
|
||||||
|
m_observed=data.value("observed").toBool()&&poseFrom(data.value("observation"),m_observation)&&poseFrom(data.value("activeOffset"),m_teachingOffset);
|
||||||
|
|
||||||
|
}
|
||||||
|
void TouchOperationWidget::refresh() {
|
||||||
|
bool busy=running()||m_phase!=Phase::Idle; Pose offset{}; bool selected=selectedTool(offset);
|
||||||
|
m_cameraName->setText(cameraId().isEmpty()?QStringLiteral("请先选择手眼标定"):cameraId());
|
||||||
|
for(auto *w:QList<QWidget*>{m_handEyeChoice,m_toolChoice,m_action,m_reloadButton,m_cameraConfirmed,m_approach,m_press,m_lift,m_speed,m_contactSpeed,m_travel,m_dwell,m_gap}) w->setEnabled(!busy);
|
||||||
|
m_teachObservation->setEnabled(ready()&&!busy); m_returnButton->setEnabled(ready()&&selected&&m_observed&&!busy);
|
||||||
|
|
||||||
|
m_previewButton->setEnabled(m_connected&&!m_demo&&handEye()&&!m_preview&&!busy); m_stopPreviewButton->setEnabled(m_preview);
|
||||||
|
m_lockButton->setEnabled(ready()&&m_observed&&m_preview&&m_cameraConfirmed->isChecked()&&!busy);
|
||||||
|
m_liveButton->setEnabled(m_video->locked()&&!busy); m_video->setEnabled(!busy);
|
||||||
|
m_calculateButton->setEnabled(ready()&&m_video->locked()&&!m_video->selectedPoints().isEmpty()&&!busy);
|
||||||
|
m_executeButton->setEnabled(ready()&&m_planValid&&m_pathConfirmed->isChecked()&&!busy);
|
||||||
|
m_pathConfirmed->setEnabled(m_planValid&&!busy);
|
||||||
|
m_observationText->setText(m_observed?QStringLiteral("观察位 · %1").arg(poseText(m_observation)):QStringLiteral("尚未录入观察位"));
|
||||||
|
refreshTargetResults();
|
||||||
|
if(!running()) m_status->setText(!ready()?QStringLiteral("请连接机械臂并在 TCP 标定页核对控制器工具偏移"):
|
||||||
|
busy?QStringLiteral("正在读取真实位姿 / 图像…"):m_planValid?QStringLiteral("路径已就绪,核对后执行"):m_video->locked()?QStringLiteral("画面已锁定,请选择 1–2 个目标点"):QStringLiteral("录入示教位、选择标定后,在观察位锁定画面"));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TouchOperationWidget::resolveTargets(QVector<TouchPlanner::Point> &basePoints,
|
||||||
|
QVector<TouchPlanner::Point> &cameraPoints,QString &error) const {
|
||||||
|
if(!m_video->locked()||!m_lockedAt) { error=QStringLiteral("请锁定观察画面后选择目标点"); return false; }
|
||||||
|
if(m_video->selectedPoints().isEmpty()) { error=QStringLiteral("请选择 A / B 目标点"); return false; }
|
||||||
|
if(QDateTime::currentMSecsSinceEpoch()-m_lockedAt>60000) { error=QStringLiteral("观察画面已过期,请重新锁定"); return false; }
|
||||||
|
if(!ready()||!handEye()) { error=QStringLiteral("请核对连接、手眼标定与 TCP 偏移"); return false; }
|
||||||
|
TouchPlanner::Matrix baseCamera{};
|
||||||
|
if(!TouchPlanner::cameraTransform(*handEye(),m_lockedFlange,baseCamera,&error)) return false;
|
||||||
|
return TouchPlanner::resolveDepthPixels(m_video->selectedPoints(),m_cameraModel,m_depth,baseCamera,
|
||||||
|
parameters(),basePoints,cameraPoints,&error);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void TouchOperationWidget::refreshTargetResults() {
|
||||||
|
const auto pixels=m_video->selectedPoints(); QVector<TouchPlanner::Point> base,camera; QString error;
|
||||||
|
const bool valid=resolveTargets(base,camera,error);
|
||||||
|
m_conversionStatus->setText(valid?QStringLiteral("%1 个深度目标点 · 换算完成").arg(base.size()):error);
|
||||||
|
m_targets->setRowCount(pixels.size());
|
||||||
|
auto xyz=[](const TouchPlanner::Point &point) {
|
||||||
|
return QStringLiteral("X %1\nY %2\nZ %3").arg(point[0]*1000,0,'f',3).arg(point[1]*1000,0,'f',3).arg(point[2]*1000,0,'f',3);
|
||||||
|
};
|
||||||
|
for(int i=0;i<pixels.size();++i) {
|
||||||
|
const QStringList row={i==0?"A":"B",QStringLiteral("u %1\nv %2").arg(pixels[i].x(),0,'f',1).arg(pixels[i].y(),0,'f',1),
|
||||||
|
valid?xyz(camera[i]):QStringLiteral("待换算"),valid?xyz(base[i]):QStringLiteral("待换算")};
|
||||||
|
for(int col=0;col<row.size();++col) { auto *item=new QTableWidgetItem(row[col]); item->setTextAlignment(Qt::AlignLeft|Qt::AlignVCenter); m_targets->setItem(i,col,item); }
|
||||||
|
m_targets->setRowHeight(i,74);
|
||||||
|
}
|
||||||
|
}
|
||||||
99
src/touchoperationwidget.h
Normal file
99
src/touchoperationwidget.h
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "touchplanner.h"
|
||||||
|
#include "touchsequencecontroller.h"
|
||||||
|
#include "tcptoolstore.h"
|
||||||
|
#include "videoframe.h"
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QImage>
|
||||||
|
|
||||||
|
class QComboBox;
|
||||||
|
class QDoubleSpinBox;
|
||||||
|
class QSpinBox;
|
||||||
|
class QCheckBox;
|
||||||
|
class QLabel;
|
||||||
|
class QPushButton;
|
||||||
|
class QTableWidget;
|
||||||
|
class TouchVideoWidget;
|
||||||
|
|
||||||
|
// Page-level workflow. Geometry and motion sequencing live in separate helpers;
|
||||||
|
// all camera/arm I/O is routed through the existing MainWindow / RobotClient.
|
||||||
|
class TouchOperationWidget : public QWidget {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit TouchOperationWidget(QWidget *parent=nullptr);
|
||||||
|
void setContext(const QString &endpoint,const QString &device,bool connected,bool demo,
|
||||||
|
bool reference,const TcpCalibration::Pose &activeOffset);
|
||||||
|
bool running() const;
|
||||||
|
public slots:
|
||||||
|
void reloadCalibrations();
|
||||||
|
void stop();
|
||||||
|
void acceptPose(quint64 token,const QString &device,const QVariantMap &pose,
|
||||||
|
const QVariantMap &state,bool success,const QString &detail);
|
||||||
|
void acceptImage(quint64 token,const QString &camera,const QImage &image,
|
||||||
|
const QVariantMap &intrinsics,const QVariantMap &metadata,bool success,const QString &detail);
|
||||||
|
void acceptFrame(const QString &camera,const VideoFrame &frame,const QString &detail);
|
||||||
|
void acceptStreamState(const QString &camera,bool running,const QString &detail);
|
||||||
|
void acceptCommand(const QString &command,bool success,const QString &detail);
|
||||||
|
signals:
|
||||||
|
void captureRequested(const QString &device,quint64 token);
|
||||||
|
void imageRequested(const QString &camera,quint64 token);
|
||||||
|
void previewRequested(const QString &camera,bool start);
|
||||||
|
void moveRequested(const QString &device,const QVariantMap &target,double speed,double acceleration,quint64 token);
|
||||||
|
void stopRequested(const QString &device);
|
||||||
|
void logMessage(const QString &level,const QString &message);
|
||||||
|
protected:
|
||||||
|
void hideEvent(QHideEvent *event) override;
|
||||||
|
private:
|
||||||
|
enum class Phase { Idle, Observation, LockBefore, LockImage, LockAfter, Return };
|
||||||
|
using Pose=TcpCalibration::Pose;
|
||||||
|
void refresh();
|
||||||
|
void invalidateFrame();
|
||||||
|
void invalidatePlan();
|
||||||
|
void teach(Phase phase);
|
||||||
|
void readPose();
|
||||||
|
void lockFrame();
|
||||||
|
void startPreview();
|
||||||
|
void stopPreview();
|
||||||
|
void calculate();
|
||||||
|
void execute();
|
||||||
|
void returnObservation(const Pose ¤t);
|
||||||
|
void fail(const QString &message);
|
||||||
|
bool ready() const;
|
||||||
|
bool selectedTool(Pose &offset) const;
|
||||||
|
const HandEyeStore::Record *handEye() const;
|
||||||
|
QString cameraId() const;
|
||||||
|
QString settingsKey() const;
|
||||||
|
void loadTeaching();
|
||||||
|
void saveTeaching();
|
||||||
|
TouchPlanner::Parameters parameters() const;
|
||||||
|
bool buildPlane(TouchPlanner::Plane &plane,QString &error) const;
|
||||||
|
bool resolveTargets(QVector<TouchPlanner::Point> &basePoints,
|
||||||
|
QVector<TouchPlanner::Point> &cameraPoints,QString &error) const;
|
||||||
|
void refreshTargetResults();
|
||||||
|
|
||||||
|
QString m_endpoint,m_device,m_previewCamera;
|
||||||
|
bool m_connected=false,m_demo=false,m_reference=false,m_loading=false,m_preview=false;
|
||||||
|
bool m_observed=false,m_planValid=false;
|
||||||
|
Pose m_activeOffset{},m_observation{},m_before{},m_lockedFlange{},m_teachingOffset{};
|
||||||
|
HandEyeStore::Snapshot m_handEyes;
|
||||||
|
TcpToolStore::Snapshot m_tools;
|
||||||
|
TouchPlanner::Plan m_plan;
|
||||||
|
TouchPlanner::CameraModel m_cameraModel;
|
||||||
|
TouchPlanner::DepthImage m_depth;
|
||||||
|
QImage m_pendingImage;
|
||||||
|
qint64 m_beforeAt=0,m_captureAt=0,m_lockedAt=0,m_requestAt=0;
|
||||||
|
quint64 m_serial=0,m_poseToken=0,m_imageToken=0;
|
||||||
|
Phase m_phase=Phase::Idle;
|
||||||
|
QTimer m_timeout;
|
||||||
|
TouchSequenceController *m_sequence;
|
||||||
|
TouchVideoWidget *m_video;
|
||||||
|
QComboBox *m_handEyeChoice,*m_toolChoice,*m_action;
|
||||||
|
QLabel *m_cameraName,*m_status,*m_observationText;
|
||||||
|
QLabel *m_conversionStatus;
|
||||||
|
QCheckBox *m_cameraConfirmed,*m_pathConfirmed;
|
||||||
|
QPushButton *m_previewButton,*m_stopPreviewButton,*m_lockButton,*m_liveButton,*m_teachObservation;
|
||||||
|
QPushButton *m_returnButton,*m_calculateButton,*m_executeButton,*m_reloadButton;
|
||||||
|
QDoubleSpinBox *m_approach,*m_press,*m_lift,*m_speed,*m_contactSpeed,*m_travel;
|
||||||
|
QSpinBox *m_dwell,*m_gap;
|
||||||
|
QTableWidget *m_targets,*m_steps;
|
||||||
|
};
|
||||||
369
src/touchplanner.cpp
Normal file
369
src/touchplanner.cpp
Normal file
@ -0,0 +1,369 @@
|
|||||||
|
#include "touchplanner.h"
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cmath>
|
||||||
|
#include <cstring>
|
||||||
|
#include <QtEndian>
|
||||||
|
|
||||||
|
namespace TouchPlanner {
|
||||||
|
namespace {
|
||||||
|
bool fail(QString *error, const char *message) {
|
||||||
|
if (error) *error=QString::fromUtf8(message);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
void clear(QString *error) { if (error) error->clear(); }
|
||||||
|
bool finite(const Point &p) { return std::all_of(p.begin(),p.end(),[](double v){return std::isfinite(v);}); }
|
||||||
|
double norm(const Point &p) { return std::hypot(std::hypot(p[0],p[1]),p[2]); }
|
||||||
|
Point subtract(const Point &a,const Point &b) { return {{a[0]-b[0],a[1]-b[1],a[2]-b[2]}}; }
|
||||||
|
double dot(const Point &a,const Point &b) { return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]; }
|
||||||
|
Point position(const Pose &p) { return {{p[0],p[1],p[2]}}; }
|
||||||
|
Point shifted(const Point &p,const Point &n,double distance) {
|
||||||
|
return {{p[0]+n[0]*distance,p[1]+n[1]*distance,p[2]+n[2]*distance}};
|
||||||
|
}
|
||||||
|
bool within(double value,double minimum,double maximum) {
|
||||||
|
return std::isfinite(value) && value>=minimum && value<=maximum;
|
||||||
|
}
|
||||||
|
bool validParameters(const Parameters &p,QString *error) {
|
||||||
|
if (!within(p.approachM,.001,.05) || !within(p.contactOffsetM,0,.002)
|
||||||
|
|| !within(p.doubleLiftM,.0005,.05)
|
||||||
|
|| !within(p.contactVelocityMps,.005,.03) || !within(p.travelVelocityMps,.005,.1)
|
||||||
|
|| !within(p.accelerationMps2,.01,.5) || p.contactDwellMs<0 || p.contactDwellMs>5000
|
||||||
|
|| p.doubleIntervalMs<0 || p.doubleIntervalMs>500
|
||||||
|
|| !within(p.maxTravelM,.01,1) || !within(p.maxReachM,.05,3)
|
||||||
|
|| !within(p.maxCameraRangeM,.05,5))
|
||||||
|
return fail(error,"触控参数超出允许范围,检查距离、速度、加速度和停留时间。");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool validPlane(const Plane &p,QString *error) {
|
||||||
|
if (!finite(p.origin) || !finite(p.normal) || !finite(p.orientationRad)
|
||||||
|
|| norm(p.origin)>3 || std::abs(norm(p.normal)-1)>1e-6)
|
||||||
|
return fail(error,"目标位置、触控姿态或接近方向无效,请重新取点。");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool validCamera(const CameraModel &c,QString *error) {
|
||||||
|
if (c.width<2 || c.width>16384 || c.height<2 || c.height>16384
|
||||||
|
|| !within(c.fx,1,1e6) || !within(c.fy,1,1e6)
|
||||||
|
|| !within(c.cx,-c.width,2.0*c.width) || !within(c.cy,-c.height,2.0*c.height))
|
||||||
|
return fail(error,"RGB 图像尺寸、焦距或主点无效。");
|
||||||
|
const auto size=c.distortion.size();
|
||||||
|
if (size!=0 && size!=4 && size!=5 && size!=8)
|
||||||
|
return fail(error,"仅支持无畸变或 4、5、8 项标准 Brown 畸变系数。");
|
||||||
|
for (double v:c.distortion) if (!within(v,-100,100))
|
||||||
|
return fail(error,"RGB 畸变系数不是有效的有限数值。");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool number(const QVariant &v,double &out) {
|
||||||
|
if (v.type()!=QVariant::Double && v.type()!=QVariant::Int && v.type()!=QVariant::UInt
|
||||||
|
&& v.type()!=QVariant::LongLong && v.type()!=QVariant::ULongLong) return false;
|
||||||
|
out=v.toDouble(); return std::isfinite(out);
|
||||||
|
}
|
||||||
|
// Brown forward projection and analytic Jacobian. A positive, non-singular
|
||||||
|
// Jacobian is required so an inverse on a folded distortion branch is rejected.
|
||||||
|
bool distort(double x,double y,const std::array<double,8> &k,
|
||||||
|
double &dx,double &dy,std::array<double,4> &j) {
|
||||||
|
if (!within(x,-5,5) || !within(y,-5,5)) return false;
|
||||||
|
const double r2=x*x+y*y,r4=r2*r2,r6=r4*r2;
|
||||||
|
const double a=1+k[0]*r2+k[1]*r4+k[4]*r6;
|
||||||
|
const double b=1+k[5]*r2+k[6]*r4+k[7]*r6;
|
||||||
|
if (!std::isfinite(a) || !std::isfinite(b) || a<=1e-9 || b<=1e-9) return false;
|
||||||
|
const double radial=a/b;
|
||||||
|
const double derivative=((k[0]+2*k[1]*r2+3*k[4]*r4)*b
|
||||||
|
-a*(k[5]+2*k[6]*r2+3*k[7]*r4))/(b*b);
|
||||||
|
dx=x*radial+2*k[2]*x*y+k[3]*(r2+2*x*x);
|
||||||
|
dy=y*radial+k[2]*(r2+2*y*y)+2*k[3]*x*y;
|
||||||
|
j={{radial+2*x*x*derivative+2*k[2]*y+6*k[3]*x,
|
||||||
|
2*x*y*derivative+2*k[2]*x+2*k[3]*y,
|
||||||
|
2*x*y*derivative+2*k[2]*x+2*k[3]*y,
|
||||||
|
radial+2*y*y*derivative+6*k[2]*y+2*k[3]*x}};
|
||||||
|
const double det=j[0]*j[3]-j[1]*j[2];
|
||||||
|
return std::isfinite(dx) && std::isfinite(dy) && std::isfinite(det) && det>1e-10;
|
||||||
|
}
|
||||||
|
bool ray(const QPointF &pixel,const CameraModel &c,Point &direction,QString *error) {
|
||||||
|
if (!within(pixel.x(),0,c.width-1.0) || !within(pixel.y(),0,c.height-1.0))
|
||||||
|
return fail(error,"触控像素必须位于所锁定的 RGB 图像内。");
|
||||||
|
const double wantedX=(pixel.x()-c.cx)/c.fx,wantedY=(pixel.y()-c.cy)/c.fy;
|
||||||
|
double x=wantedX,y=wantedY;
|
||||||
|
std::array<double,8> k{};
|
||||||
|
std::copy(c.distortion.begin(),c.distortion.end(),k.begin());
|
||||||
|
bool converged=false;
|
||||||
|
for (int iteration=0;iteration<30;++iteration) {
|
||||||
|
double actualX=0,actualY=0; std::array<double,4> j{};
|
||||||
|
if (!distort(x,y,k,actualX,actualY,j))
|
||||||
|
return fail(error,"畸变反解不稳定,不能生成触控射线。");
|
||||||
|
const double ex=actualX-wantedX,ey=actualY-wantedY;
|
||||||
|
if (std::hypot(ex,ey)<1e-12) { converged=true; break; }
|
||||||
|
const double det=j[0]*j[3]-j[1]*j[2];
|
||||||
|
const double sx=(j[3]*ex-j[1]*ey)/det,sy=(-j[2]*ex+j[0]*ey)/det;
|
||||||
|
bool improved=false;
|
||||||
|
for (int search=0;search<12;++search) {
|
||||||
|
const double scale=std::ldexp(1.0,-search);
|
||||||
|
const double tx=x-scale*sx,ty=y-scale*sy;
|
||||||
|
double px=0,py=0; std::array<double,4> unused{};
|
||||||
|
if (distort(tx,ty,k,px,py,unused) && std::hypot(px-wantedX,py-wantedY)<std::hypot(ex,ey)) {
|
||||||
|
x=tx; y=ty; improved=true; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!improved) break;
|
||||||
|
}
|
||||||
|
if (!converged) return fail(error,"RGB 像素畸变反解未收敛,请核对相机内参与模型。");
|
||||||
|
const double length=std::hypot(std::hypot(x,y),1.0);
|
||||||
|
direction={{x/length,y/length,1.0/length}};
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool teachPlane(const std::array<Pose,3> &contacts,const Pose &observation,Plane &plane,QString *error) {
|
||||||
|
if (!TcpCalibration::validPose(observation) || norm(position(observation))>3)
|
||||||
|
return fail(error,"观察位必须是有限的米制 TCP 位姿。");
|
||||||
|
for (const Pose &p:contacts) if (!TcpCalibration::validPose(p) || norm(position(p))>3)
|
||||||
|
return fail(error,"平面示教点必须是有限的米制 TCP 位姿。");
|
||||||
|
const Point a=subtract(position(contacts[1]),position(contacts[0]));
|
||||||
|
const Point b=subtract(position(contacts[2]),position(contacts[0]));
|
||||||
|
const double la=norm(a),lb=norm(b);
|
||||||
|
if (!within(la,.01,1) || !within(lb,.01,1)
|
||||||
|
|| !within(norm(subtract(position(contacts[2]),position(contacts[1]))),.01,1))
|
||||||
|
return fail(error,"三个平面示教点之间至少间隔 10 mm,最大基线不超过 1 m。");
|
||||||
|
Point n{{a[1]*b[2]-a[2]*b[1],a[2]*b[0]-a[0]*b[2],a[0]*b[1]-a[1]*b[0]}};
|
||||||
|
const double length=norm(n);
|
||||||
|
if (length/(la*lb)<.08715574274765817)
|
||||||
|
return fail(error,"平面示教点共线或接近共线,请扩大点位三角形(夹角至少 5 度)。");
|
||||||
|
for (double &v:n) v/=length;
|
||||||
|
const double side=dot(subtract(position(observation),position(contacts[0])),n);
|
||||||
|
if (std::abs(side)<.001)
|
||||||
|
return fail(error,"观察位必须离开触控平面至少 1 mm,以确定安全回撤方向。");
|
||||||
|
if (side<0) for (double &v:n) v=-v;
|
||||||
|
Plane result; result.origin=position(contacts[0]); result.normal=n;
|
||||||
|
result.orientationRad={{contacts[0][3],contacts[0][4],contacts[0][5]}};
|
||||||
|
plane=result; clear(error); return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool cameraTransform(const HandEyeStore::Record &record,const Pose &flange,Matrix &baseCamera,QString *error) {
|
||||||
|
QString detail;
|
||||||
|
if (!HandEyeStore::validateRecord(record,detail)) { if (error) *error=detail; return false; }
|
||||||
|
Matrix result=record.transform;
|
||||||
|
if (record.mode==QStringLiteral("eye_in_hand")) {
|
||||||
|
Matrix baseFlange{};
|
||||||
|
if (!TcpCalibration::poseMatrix(flange,baseFlange,error)) return false;
|
||||||
|
result.fill(0);
|
||||||
|
for (int r=0;r<4;++r) for (int c=0;c<4;++c) for (int k=0;k<4;++k)
|
||||||
|
result[size_t(4*r+c)]+=baseFlange[size_t(4*r+k)]*record.transform[size_t(4*k+c)];
|
||||||
|
}
|
||||||
|
Pose checked{};
|
||||||
|
if (!TcpCalibration::matrixPose(result,checked,error)) return false;
|
||||||
|
baseCamera=result; clear(error); return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool cameraModel(const QVariantMap &data,int width,int height,CameraModel &camera,QString *error) {
|
||||||
|
CameraModel result; result.width=width; result.height=height;
|
||||||
|
for (const QString &key:{QStringLiteral("width"),QStringLiteral("height")}) if (data.contains(key)) {
|
||||||
|
double value=0;
|
||||||
|
if (!number(data.value(key),value) || value!=(key=="width"?width:height))
|
||||||
|
return fail(error,"RGB 内参尺寸与图像不一致,禁止自动缩放或使用裁剪图。");
|
||||||
|
}
|
||||||
|
for (const QString &key:{QStringLiteral("model"),QStringLiteral("distortion_model")}) if (data.contains(key)) {
|
||||||
|
const QString model=data.value(key).toString().trimmed().toLower();
|
||||||
|
if (model!="none" && model!="0" && model!="4" && model!="brown_conrady"
|
||||||
|
&& model!="brown-conrady" && model!="opencv" && model!="plumb_bob"
|
||||||
|
&& model!="rational_polynomial")
|
||||||
|
return fail(error,"当前 RGB 畸变模型不是受支持的标准 Brown 模型。");
|
||||||
|
}
|
||||||
|
if (data.contains("camera_matrix")) {
|
||||||
|
const auto values=data.value("camera_matrix").toList();
|
||||||
|
std::array<double,9> k{};
|
||||||
|
if (values.size()!=9) return fail(error,"相机内参矩阵需要 9 个有限数值。");
|
||||||
|
for (int i=0;i<9;++i) if (!number(values[i],k[size_t(i)]))
|
||||||
|
return fail(error,"相机内参矩阵需要 9 个有限数值。");
|
||||||
|
if (std::abs(k[1])+std::abs(k[3])+std::abs(k[6])+std::abs(k[7])+std::abs(k[8]-1)>1e-9)
|
||||||
|
return fail(error,"相机内参必须为无斜切的标准针孔矩阵。");
|
||||||
|
result.fx=k[0]; result.fy=k[4]; result.cx=k[2]; result.cy=k[5];
|
||||||
|
} else if (!number(data.value("fx"),result.fx) || !number(data.value("fy"),result.fy)
|
||||||
|
|| !number(data.value("cx"),result.cx) || !number(data.value("cy"),result.cy)) {
|
||||||
|
return fail(error,"缺少有效的 RGB 焦距与主点参数。");
|
||||||
|
}
|
||||||
|
const QVariant coefficients=data.value(data.contains("coeffs")?"coeffs":"distortion");
|
||||||
|
if (coefficients.type()!=QVariant::List)
|
||||||
|
return fail(error,"RGB 内参必须明确提供畸变系数列表(无畸变时为空列表)。");
|
||||||
|
for (const QVariant &v:coefficients.toList()) {
|
||||||
|
double value=0;
|
||||||
|
if (!number(v,value)) return fail(error,"畸变系数必须为有限数值。");
|
||||||
|
result.distortion.push_back(value);
|
||||||
|
}
|
||||||
|
if (!validCamera(result,error)) return false;
|
||||||
|
camera=result; clear(error); return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool resolvePixels(const QVector<QPointF> &pixels,const CameraModel &camera,const Matrix &baseCamera,
|
||||||
|
const Plane &plane,const Parameters ¶meters,QVector<Point> &points,QString *error) {
|
||||||
|
if (pixels.isEmpty() || pixels.size()>2) return fail(error,"请选择 1 至 2 个 RGB 图像点。");
|
||||||
|
if (!validCamera(camera,error) || !validPlane(plane,error) || !validParameters(parameters,error)) return false;
|
||||||
|
Pose cameraPose{};
|
||||||
|
if (!TcpCalibration::matrixPose(baseCamera,cameraPose,error)) return false;
|
||||||
|
const Point origin=position(cameraPose);
|
||||||
|
if (norm(origin)>parameters.maxReachM) return fail(error,"相机基座坐标超出配置的工作空间范围。");
|
||||||
|
QVector<Point> result;
|
||||||
|
for (const QPointF &pixel:pixels) {
|
||||||
|
Point cameraRay{},baseRay{};
|
||||||
|
if (!ray(pixel,camera,cameraRay,error)) return false;
|
||||||
|
for (int r=0;r<3;++r) for (int c=0;c<3;++c)
|
||||||
|
baseRay[size_t(r)]+=baseCamera[size_t(r*4+c)]*cameraRay[size_t(c)];
|
||||||
|
const double cosine=dot(plane.normal,baseRay);
|
||||||
|
if (std::abs(cosine)<.02) return fail(error,"像素射线与示教平面接近平行,无法可靠求交。");
|
||||||
|
const double distance=dot(plane.normal,subtract(plane.origin,origin))/cosine;
|
||||||
|
if (!within(distance,.005,parameters.maxCameraRangeM))
|
||||||
|
return fail(error,"触控交点位于相机后方、过近或超出相机距离限制。");
|
||||||
|
const Point point=shifted(origin,baseRay,distance);
|
||||||
|
if (!finite(point) || norm(point)>parameters.maxReachM)
|
||||||
|
return fail(error,"触控交点超出配置的基座工作空间范围。");
|
||||||
|
if (norm(subtract(point,plane.origin))>parameters.maxTravelM)
|
||||||
|
return fail(error,"触控交点离平面示教原点过远,超过最大行程。");
|
||||||
|
result.append(point);
|
||||||
|
}
|
||||||
|
points=result; clear(error); return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool resolveDepthPixels(const QVector<QPointF> &pixels,const CameraModel &camera,
|
||||||
|
const DepthImage &depth,const Matrix &baseCamera,const Parameters &p,
|
||||||
|
QVector<Point> &basePoints,QVector<Point> &cameraPoints,QString *error) {
|
||||||
|
if (pixels.isEmpty() || pixels.size()>2 || !validCamera(camera,error) || !validParameters(p,error))
|
||||||
|
return fail(error,"请选择 1 至 2 个有效 RGB 点并核对相机参数。");
|
||||||
|
Pose pose{};
|
||||||
|
if (!TcpCalibration::matrixPose(baseCamera,pose,error)) return false;
|
||||||
|
const int bytes=depth.float32?4:2;
|
||||||
|
if (depth.width!=camera.width || depth.height!=camera.height
|
||||||
|
|| !within(depth.metresPerUnit,1e-9,1)
|
||||||
|
|| qint64(depth.width)*depth.height*bytes!=depth.data.size())
|
||||||
|
return fail(error,"缺少与锁定 RGB 对齐的原始深度或有效深度单位。");
|
||||||
|
if (norm(position(pose))>p.maxReachM) return fail(error,"相机位置超出工作空间。");
|
||||||
|
QVector<Point> base,cameraResult;
|
||||||
|
for (const auto &pixel:pixels) {
|
||||||
|
Point direction{}; if (!ray(pixel,camera,direction,error)) return false;
|
||||||
|
const int x=qRound(pixel.x()),y=qRound(pixel.y());
|
||||||
|
std::vector<double> samples;
|
||||||
|
// Phone _depth_mm: local valid-depth median. Keep a small 5x5 patch;
|
||||||
|
// reject depth edges instead of expanding onto an unrelated surface.
|
||||||
|
for (int v=qMax(0,y-2);v<=qMin(depth.height-1,y+2);++v)
|
||||||
|
for (int u=qMax(0,x-2);u<=qMin(depth.width-1,x+2);++u) {
|
||||||
|
const auto *raw=reinterpret_cast<const uchar*>(depth.data.constData())+(v*depth.width+u)*bytes;
|
||||||
|
double value=0;
|
||||||
|
if (depth.float32) {
|
||||||
|
const quint32 bits=qFromLittleEndian<quint32>(raw); float f=0;
|
||||||
|
std::memcpy(&f,&bits,sizeof(f)); value=f;
|
||||||
|
} else value=qFromLittleEndian<quint16>(raw);
|
||||||
|
value*=depth.metresPerUnit;
|
||||||
|
if (within(value,.05,p.maxCameraRangeM)) samples.push_back(value);
|
||||||
|
}
|
||||||
|
if (samples.size()<5) return fail(error,"目标点附近有效深度不足,请重新取图或选择可测量位置。");
|
||||||
|
std::sort(samples.begin(),samples.end());
|
||||||
|
const double z=samples[samples.size()/2];
|
||||||
|
if (samples.back()-samples.front()>.005)
|
||||||
|
return fail(error,"目标点处深度跳变超过 5 mm,请避开遮挡边缘或重新取图。");
|
||||||
|
Point cp{},bp{};
|
||||||
|
for (int i=0;i<3;++i) cp[i]=direction[i]*z/direction[2]; // Z, not Euclidean range.
|
||||||
|
if (norm(cp)>p.maxCameraRangeM) return fail(error,"目标超出相机测量范围。");
|
||||||
|
for (int r=0;r<3;++r) {
|
||||||
|
bp[r]=baseCamera[r*4+3];
|
||||||
|
for (int c=0;c<3;++c) bp[r]+=baseCamera[r*4+c]*cp[c];
|
||||||
|
}
|
||||||
|
if (!finite(bp) || norm(bp)>p.maxReachM) return fail(error,"深度目标超出基座工作空间。");
|
||||||
|
base.append(bp); cameraResult.append(cp);
|
||||||
|
}
|
||||||
|
basePoints=base; cameraPoints=cameraResult; clear(error); return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool validateDepthSwipe(const QVector<QPointF> &pixels,const CameraModel &camera,
|
||||||
|
const DepthImage &depth,const Matrix &baseCamera,const Parameters &p,QString *error) {
|
||||||
|
if (pixels.size()!=2) return fail(error,"滑动需要 A/B 两点。");
|
||||||
|
QVector<Point> ends,unused;
|
||||||
|
if (!resolveDepthPixels(pixels,camera,depth,baseCamera,p,ends,unused,error)) return false;
|
||||||
|
const Point segment=subtract(ends[1],ends[0]); const double length=norm(segment);
|
||||||
|
if (length<.0001) return fail(error,"滑动端点间距不足 0.1 mm。");
|
||||||
|
const int count=qMax(2,int(std::ceil(std::hypot(pixels[1].x()-pixels[0].x(),pixels[1].y()-pixels[0].y())/2)));
|
||||||
|
for (int i=1;i<count;++i) {
|
||||||
|
const double t=double(i)/count;
|
||||||
|
QVector<Point> current;
|
||||||
|
if (!resolveDepthPixels({pixels[0]*(1-t)+pixels[1]*t},camera,depth,baseCamera,p,current,unused,error)) return false;
|
||||||
|
const Point delta=subtract(current[0],ends[0]);
|
||||||
|
const double along=dot(delta,segment)/(length*length);
|
||||||
|
if (along<-.01 || along>1.01 || norm(subtract(delta,shifted(Point{},segment,along)))>.003)
|
||||||
|
return fail(error,"滑动路径深度偏离直线超过 3 mm,不能执行直线触控。");
|
||||||
|
}
|
||||||
|
clear(error); return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool buildPlan(Action action,const QVector<Point> &points,const Plane &plane,const Pose &observationActive,
|
||||||
|
const Pose &flangeActive,const Pose &flangeSelected,const Parameters &p,Plan &plan,QString *error,bool depthTargets) {
|
||||||
|
if (action!=Action::SingleTap && action!=Action::DoubleTap && action!=Action::Swipe)
|
||||||
|
return fail(error,"未知触控动作。");
|
||||||
|
if (points.isEmpty() || points.size()>2 || (action==Action::Swipe && points.size()!=2))
|
||||||
|
return fail(error,"单击或双击需要 1 至 2 点,滑动必须恰好选择 2 点。");
|
||||||
|
if (!validPlane(plane,error) || !validParameters(p,error)) return false;
|
||||||
|
if (action==Action::DoubleTap && (p.doubleLiftM<p.contactOffsetM+.0005 || p.doubleLiftM>p.approachM+p.contactOffsetM))
|
||||||
|
return fail(error,"双击短抬必须越过接触偏移至少 0.5 mm,且不超过接近点。");
|
||||||
|
Pose observationFlange{},observationSelected{};
|
||||||
|
if (!TcpCalibration::flangePose(observationActive,flangeActive,observationFlange,error)
|
||||||
|
|| !TcpCalibration::toolPose(observationFlange,flangeSelected,observationSelected,error)) return false;
|
||||||
|
if (dot(subtract(position(observationSelected),plane.origin),plane.normal)<p.approachM-1e-9)
|
||||||
|
return fail(error,"观察 TCP 必须位于平面外侧,且离面距离不少于接近距离。");
|
||||||
|
for (const Point &point:points) {
|
||||||
|
if (!finite(point) || (!depthTargets && std::abs(dot(subtract(point,plane.origin),plane.normal))>1e-5))
|
||||||
|
return fail(error,"触控目标不在已示教平面上。");
|
||||||
|
if (depthTargets && dot(subtract(position(observationSelected),point),plane.normal)<p.approachM)
|
||||||
|
return fail(error,"观察位必须位于每个深度目标的接近方向外侧。");
|
||||||
|
if (norm(subtract(point,plane.origin))>p.maxTravelM)
|
||||||
|
return fail(error,"触控目标之间的距离超过最大行程。");
|
||||||
|
}
|
||||||
|
if (action==Action::Swipe && norm(subtract(points[0],points[1]))<.0001)
|
||||||
|
return fail(error,"滑动起点和终点至少间隔 0.1 mm。");
|
||||||
|
Plan result; result.contacts=points;
|
||||||
|
Pose previousActive=observationActive,previousSelected=observationSelected;
|
||||||
|
double totalTravel=0;
|
||||||
|
const auto append=[&](const QString &label,const Pose &active,const Pose &selected,
|
||||||
|
double speed,int pause)->bool {
|
||||||
|
Pose flange{};
|
||||||
|
if (!TcpCalibration::flangePose(active,flangeActive,flange,error)) return false;
|
||||||
|
if (!TcpCalibration::validPose(active) || !TcpCalibration::validPose(selected)
|
||||||
|
|| norm(position(active))>p.maxReachM || norm(position(selected))>p.maxReachM
|
||||||
|
|| norm(position(flange))>p.maxReachM)
|
||||||
|
return fail(error,"规划路径超出配置的 TCP / 法兰工作空间半径。");
|
||||||
|
const double activeTravel=norm(subtract(position(active),position(previousActive)));
|
||||||
|
const double tipTravel=norm(subtract(position(selected),position(previousSelected)));
|
||||||
|
if (activeTravel>p.maxTravelM || tipTravel>p.maxTravelM
|
||||||
|
|| norm(subtract(position(active),position(observationActive)))>p.maxTravelM
|
||||||
|
|| norm(subtract(position(selected),position(observationSelected)))>p.maxTravelM)
|
||||||
|
return fail(error,"规划路径超出单段行程或观察位距离限制。");
|
||||||
|
totalTravel+=std::max(activeTravel,tipTravel);
|
||||||
|
if (totalTravel>12*p.maxTravelM || result.steps.size()>=12)
|
||||||
|
return fail(error,"触控路径总行程或步骤数量超出限制。");
|
||||||
|
result.steps.append(Step{label,active,speed,p.accelerationMps2,pause});
|
||||||
|
previousActive=active; previousSelected=selected; return true;
|
||||||
|
};
|
||||||
|
// Check the starting poses too, including a potentially long saved tool offset.
|
||||||
|
if (norm(position(observationActive))>p.maxReachM || norm(position(observationSelected))>p.maxReachM
|
||||||
|
|| norm(position(observationFlange))>p.maxReachM)
|
||||||
|
return fail(error,"观察位超出配置的 TCP / 法兰工作空间半径。");
|
||||||
|
const auto target=[&](const QString &label,const Point &surface,double normalOffset,double speed,int pause)->bool {
|
||||||
|
const Point xyz=shifted(surface,plane.normal,normalOffset);
|
||||||
|
const Pose selected{{xyz[0],xyz[1],xyz[2],plane.orientationRad[0],plane.orientationRad[1],plane.orientationRad[2]}};
|
||||||
|
Pose flange{},active{};
|
||||||
|
if (!TcpCalibration::flangePose(selected,flangeSelected,flange,error)
|
||||||
|
|| !TcpCalibration::toolPose(flange,flangeActive,active,error)) return false;
|
||||||
|
return append(label,active,selected,speed,pause);
|
||||||
|
};
|
||||||
|
const int visits=action==Action::Swipe?1:points.size();
|
||||||
|
for (int visit=0;visit<visits;++visit) {
|
||||||
|
const Point &start=points[visit];
|
||||||
|
const QString index=QString::number(visit+1);
|
||||||
|
if (!target(QStringLiteral("接近点 ")+index,start,p.approachM,p.travelVelocityMps,0)
|
||||||
|
|| !target(QStringLiteral("接触点 ")+index,start,-p.contactOffsetM,p.contactVelocityMps,
|
||||||
|
action==Action::Swipe?0:p.contactDwellMs)) return false;
|
||||||
|
if (action==Action::DoubleTap) {
|
||||||
|
if (!target(QStringLiteral("双击短抬 ")+index,start,p.doubleLiftM-p.contactOffsetM,p.contactVelocityMps,p.doubleIntervalMs)
|
||||||
|
|| !target(QStringLiteral("第二次接触 ")+index,start,-p.contactOffsetM,p.contactVelocityMps,p.contactDwellMs)) return false;
|
||||||
|
}
|
||||||
|
if (action==Action::Swipe && !target(QStringLiteral("滑动到终点"),points[1],-p.contactOffsetM,p.contactVelocityMps,p.contactDwellMs)) return false;
|
||||||
|
const Point &end=action==Action::Swipe?points[1]:start;
|
||||||
|
if (!target(QStringLiteral("回撤"),end,p.approachM,p.contactVelocityMps,0)
|
||||||
|
|| !append(QStringLiteral("返回观察位"),observationActive,observationSelected,p.travelVelocityMps,0)) return false;
|
||||||
|
}
|
||||||
|
plan=result; clear(error); return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
83
src/touchplanner.h
Normal file
83
src/touchplanner.h
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "handeyestore.h"
|
||||||
|
#include <QPointF>
|
||||||
|
#include <QVector>
|
||||||
|
#include <QByteArray>
|
||||||
|
|
||||||
|
// Offline geometry only. All distances are metres and all angles are ZYX radians.
|
||||||
|
// The caller owns frame provenance, observation matching, controller reach/IK
|
||||||
|
// checks, collision clearance, and execution; no hardware is accessed here.
|
||||||
|
namespace TouchPlanner {
|
||||||
|
using Pose = TcpCalibration::Pose;
|
||||||
|
using Matrix = TcpCalibration::Matrix;
|
||||||
|
using Point = std::array<double, 3>;
|
||||||
|
|
||||||
|
struct CameraModel {
|
||||||
|
int width = 0, height = 0;
|
||||||
|
double fx = 0, fy = 0, cx = 0, cy = 0;
|
||||||
|
std::vector<double> distortion; // OpenCV Brown order: k1,k2,p1,p2[,k3[,k4,k5,k6]].
|
||||||
|
};
|
||||||
|
struct Plane {
|
||||||
|
Point origin{};
|
||||||
|
Point normal{}; // Unit outward normal, toward the taught observation tip.
|
||||||
|
Point orientationRad{}; // Selected-tip orientation from the first contact teach.
|
||||||
|
};
|
||||||
|
struct DepthImage {
|
||||||
|
int width = 0, height = 0;
|
||||||
|
QByteArray data; // Owning raw little-endian samples, aligned to native RGB.
|
||||||
|
bool float32 = false;
|
||||||
|
double metresPerUnit = 0; // Explicit transport contract, never inferred from type.
|
||||||
|
};
|
||||||
|
struct Parameters {
|
||||||
|
double approachM = .01;
|
||||||
|
double contactOffsetM = 0; // Positive presses inward, opposite the outward normal.
|
||||||
|
double doubleLiftM = .003;
|
||||||
|
double contactVelocityMps = .01;
|
||||||
|
double travelVelocityMps = .03;
|
||||||
|
double accelerationMps2 = .1;
|
||||||
|
int contactDwellMs = 80;
|
||||||
|
int doubleIntervalMs = 100;
|
||||||
|
double maxTravelM = .3; // Radius from observation AND maximum movement per segment.
|
||||||
|
double maxReachM = 2; // Conservative base-origin sphere, not a substitute for IK.
|
||||||
|
double maxCameraRangeM = 3;
|
||||||
|
};
|
||||||
|
enum class Action { SingleTap, DoubleTap, Swipe };
|
||||||
|
struct Step {
|
||||||
|
QString label;
|
||||||
|
Pose target{}; // Target of the controller's existing active TCP.
|
||||||
|
double velocityMps = 0;
|
||||||
|
double accelerationMps2 = 0;
|
||||||
|
int pauseMs = 0; // Applied after the target has been reached.
|
||||||
|
};
|
||||||
|
struct Plan {
|
||||||
|
QVector<Step> steps;
|
||||||
|
QVector<Point> contacts; // Unpressed surface points in base coordinates.
|
||||||
|
};
|
||||||
|
|
||||||
|
// All functions leave output unchanged on failure and clear error on success.
|
||||||
|
bool teachPlane(const std::array<Pose, 3> &selectedContacts,
|
||||||
|
const Pose &observationSelected, Plane &plane, QString *error = nullptr);
|
||||||
|
bool cameraTransform(const HandEyeStore::Record &record, const Pose &lockedBaseFlange,
|
||||||
|
Matrix &baseCamera, QString *error = nullptr);
|
||||||
|
// Exact-size intrinsics only; callers must establish the RGB distortion model.
|
||||||
|
// Supports fx/fy/cx/cy + coeffs, or camera_matrix + distortion. Does not rescale.
|
||||||
|
bool cameraModel(const QVariantMap &intrinsics, int imageWidth, int imageHeight,
|
||||||
|
CameraModel &camera, QString *error = nullptr);
|
||||||
|
bool resolvePixels(const QVector<QPointF> &pixels, const CameraModel &camera,
|
||||||
|
const Matrix &baseCamera, const Plane &plane, const Parameters ¶meters,
|
||||||
|
QVector<Point> &points, QString *error = nullptr);
|
||||||
|
bool resolveDepthPixels(const QVector<QPointF> &pixels, const CameraModel &camera,
|
||||||
|
const DepthImage &depth, const Matrix &baseCamera,
|
||||||
|
const Parameters ¶meters, QVector<Point> &basePoints,
|
||||||
|
QVector<Point> &cameraPoints, QString *error = nullptr);
|
||||||
|
bool validateDepthSwipe(const QVector<QPointF> &pixels, const CameraModel &camera,
|
||||||
|
const DepthImage &depth, const Matrix &baseCamera,
|
||||||
|
const Parameters ¶meters, QString *error = nullptr);
|
||||||
|
// Single/double tap visit 1-2 contacts sequentially, returning to observation after
|
||||||
|
// each. Swipe requires two distinct contacts. All use approach/contact/retract.
|
||||||
|
bool buildPlan(Action action, const QVector<Point> &points, const Plane &plane,
|
||||||
|
const Pose &observationActive, const Pose &flangeActive,
|
||||||
|
const Pose &flangeSelected, const Parameters ¶meters,
|
||||||
|
Plan &plan, QString *error = nullptr, bool depthTargets = false);
|
||||||
|
}
|
||||||
228
src/touchsequencecontroller.cpp
Normal file
228
src/touchsequencecontroller.cpp
Normal file
@ -0,0 +1,228 @@
|
|||||||
|
#include "touchsequencecontroller.h"
|
||||||
|
#include <QDateTime>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
constexpr int kReadTimeoutMs = 6000;
|
||||||
|
constexpr int kMoveTimeoutMs = 30000;
|
||||||
|
constexpr int kSequenceTimeoutMs = 180000;
|
||||||
|
constexpr double kPositionToleranceM = .0005;
|
||||||
|
constexpr double kRotationToleranceRad = .2 * 3.14159265358979323846 / 180;
|
||||||
|
|
||||||
|
bool poseMatches(const TcpCalibration::Pose &actual, const TcpCalibration::Pose &expected)
|
||||||
|
{
|
||||||
|
double squaredDistance = 0;
|
||||||
|
for (int i = 0; i < 3; ++i)
|
||||||
|
squaredDistance += std::pow(actual[size_t(i)] - expected[size_t(i)], 2);
|
||||||
|
if (squaredDistance > kPositionToleranceM * kPositionToleranceM)
|
||||||
|
return false;
|
||||||
|
TcpCalibration::Matrix a{}, b{};
|
||||||
|
if (!TcpCalibration::poseMatrix(actual, a) || !TcpCalibration::poseMatrix(expected, b))
|
||||||
|
return false;
|
||||||
|
// Relative rotation, including equivalent Euler representations at +/-pi.
|
||||||
|
double trace = 0;
|
||||||
|
for (int row = 0; row < 3; ++row)
|
||||||
|
for (int col = 0; col < 3; ++col)
|
||||||
|
trace += a[size_t(row * 4 + col)] * b[size_t(row * 4 + col)];
|
||||||
|
const double angle = std::acos(std::max(-1.0, std::min(1.0, (trace - 1) / 2)));
|
||||||
|
return angle <= kRotationToleranceRad;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool stoppedHealthy(const QVariantMap &state)
|
||||||
|
{
|
||||||
|
return state.value("connected").toBool()
|
||||||
|
&& !state.value("moving", true).toBool()
|
||||||
|
&& !state.value("fault", true).toBool()
|
||||||
|
&& !state.value("protectiveStopped", true).toBool()
|
||||||
|
&& !state.value("emergencyStopped", true).toBool();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TouchSequenceController::TouchSequenceController(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
m_timeout.setSingleShot(true);
|
||||||
|
m_deadline.setSingleShot(true);
|
||||||
|
m_dwell.setSingleShot(true);
|
||||||
|
m_dwell.setTimerType(Qt::PreciseTimer);
|
||||||
|
connect(&m_timeout, &QTimer::timeout, this, [this] {
|
||||||
|
fail(QStringLiteral("触控动作反馈超时,已请求停止;不会自动回程"));
|
||||||
|
});
|
||||||
|
connect(&m_deadline, &QTimer::timeout, this, [this] {
|
||||||
|
fail(QStringLiteral("触控任务超出总时限,已请求停止;不会自动回程"));
|
||||||
|
});
|
||||||
|
connect(&m_dwell, &QTimer::timeout, this, [this] {
|
||||||
|
if (m_phase == Phase::Dwelling) readPose(Phase::AfterDwellRead);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
QString TouchSequenceController::commandName(quint64 token)
|
||||||
|
{
|
||||||
|
// RobotClient::requestTcpJogMove uses this existing command namespace.
|
||||||
|
return QStringLiteral("TCPJog/%1").arg(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TouchSequenceController::setContext(const QString &endpoint, const QString &device,
|
||||||
|
bool ready, const TcpCalibration::Pose &activeOffset,
|
||||||
|
const QString &contextRevision)
|
||||||
|
{
|
||||||
|
if (m_endpoint != endpoint || m_device != device || m_ready != ready
|
||||||
|
|| m_activeOffset != activeOffset || m_contextRevision != contextRevision)
|
||||||
|
stop(); // Stop the old device before replacing its identity.
|
||||||
|
m_endpoint = endpoint;
|
||||||
|
m_device = device;
|
||||||
|
m_ready = ready;
|
||||||
|
m_activeOffset = activeOffset;
|
||||||
|
m_contextRevision = contextRevision;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TouchSequenceController::start(const QVector<Step> &steps,
|
||||||
|
const TcpCalibration::Pose &expectedInitialPose)
|
||||||
|
{
|
||||||
|
if (running()) return false;
|
||||||
|
bool valid = m_ready && !m_endpoint.trimmed().isEmpty() && !m_device.trimmed().isEmpty()
|
||||||
|
&& TcpCalibration::validPose(m_activeOffset)
|
||||||
|
&& TcpCalibration::validPose(expectedInitialPose)
|
||||||
|
&& !steps.isEmpty() && steps.size() <= 128;
|
||||||
|
for (const auto &step : steps) {
|
||||||
|
valid = valid && TcpCalibration::validPose(step.target)
|
||||||
|
&& std::isfinite(step.speed) && step.speed > 0 && step.speed <= .05
|
||||||
|
&& std::isfinite(step.acceleration) && step.acceleration > 0 && step.acceleration <= .5
|
||||||
|
&& step.dwellMs >= 0 && step.dwellMs <= 5000;
|
||||||
|
}
|
||||||
|
if (!valid) {
|
||||||
|
emit errorOccurred(QStringLiteral("触控路径或机械臂上下文无效,请核对连接、活动 TCP 和运动参数"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
m_steps = steps;
|
||||||
|
m_expected = expectedInitialPose;
|
||||||
|
m_index = 0;
|
||||||
|
m_deadline.start(kSequenceTimeoutMs);
|
||||||
|
readPose(Phase::InitialRead);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TouchSequenceController::readPose(Phase phase)
|
||||||
|
{
|
||||||
|
m_phase = phase;
|
||||||
|
++m_token;
|
||||||
|
m_captureIssuedAtMs = QDateTime::currentMSecsSinceEpoch();
|
||||||
|
m_timeout.start(kReadTimeoutMs);
|
||||||
|
emit captureRequested(m_device, m_token);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TouchSequenceController::moveNext()
|
||||||
|
{
|
||||||
|
if (!running()) return;
|
||||||
|
const Step step = m_steps.at(m_index);
|
||||||
|
m_phase = Phase::Moving;
|
||||||
|
const quint64 token = ++m_token;
|
||||||
|
m_timeout.start(kMoveTimeoutMs);
|
||||||
|
emit progressChanged(m_index + 1, m_steps.size(), step.label);
|
||||||
|
// A direct progress listener may cancel or change context synchronously.
|
||||||
|
if (m_phase != Phase::Moving || m_token != token) return;
|
||||||
|
QVariantMap target;
|
||||||
|
const char *keys[] = {"x", "y", "z", "rx", "ry", "rz"};
|
||||||
|
for (int i = 0; i < 6; ++i) target[keys[i]] = step.target[size_t(i)];
|
||||||
|
emit moveRequested(m_device, target, step.speed, step.acceleration, token);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TouchSequenceController::acceptPose(quint64 token, const QString &device,
|
||||||
|
const QVariantMap &pose, const QVariantMap &state,
|
||||||
|
bool success, const QString &detail)
|
||||||
|
{
|
||||||
|
if ((m_phase != Phase::InitialRead && m_phase != Phase::VerifyRead
|
||||||
|
&& m_phase != Phase::AfterDwellRead) || token != m_token || device != m_device)
|
||||||
|
return;
|
||||||
|
if (!success) {
|
||||||
|
fail(detail.isEmpty() ? QStringLiteral("触控任务读取实时位姿失败") : detail);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!stoppedHealthy(state)) {
|
||||||
|
fail(QStringLiteral("机械臂未停稳、未连接或处于故障/停止状态,已取消触控任务"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bool requestedOk = false, receivedOk = false;
|
||||||
|
const qint64 requested = state.value("requestedAtMs").toLongLong(&requestedOk);
|
||||||
|
const qint64 received = state.value("receivedAtMs").toLongLong(&receivedOk);
|
||||||
|
const qint64 now = QDateTime::currentMSecsSinceEpoch();
|
||||||
|
if (!requestedOk || !receivedOk || requested < m_captureIssuedAtMs
|
||||||
|
|| received < requested || received > now + 50 || now - received > 1500
|
||||||
|
|| state.value("source").toString() != QStringLiteral("getRobotState.actual_tcp_pose")) {
|
||||||
|
fail(QStringLiteral("触控任务收到过期或来源不明的位姿,已请求停止"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
TcpCalibration::Pose actual{};
|
||||||
|
const char *keys[] = {"x", "y", "z", "rx", "ry", "rz"};
|
||||||
|
for (int i = 0; i < 6; ++i) {
|
||||||
|
bool ok = false;
|
||||||
|
actual[size_t(i)] = pose.value(keys[i]).toDouble(&ok);
|
||||||
|
if (!ok || !std::isfinite(actual[size_t(i)])) {
|
||||||
|
fail(QStringLiteral("触控任务收到无效的 TCP 位姿"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!poseMatches(actual, m_expected)) {
|
||||||
|
fail(m_phase == Phase::InitialRead
|
||||||
|
? QStringLiteral("当前位姿已偏离观察位(允许 0.5 mm / 0.2°),请重新定位并确认画面")
|
||||||
|
: QStringLiteral("实际 TCP 未到达触控路径目标(允许 0.5 mm / 0.2°),已停止且不会自动回程"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_timeout.stop();
|
||||||
|
if (m_phase == Phase::InitialRead) {
|
||||||
|
moveNext();
|
||||||
|
} else if (m_phase == Phase::VerifyRead && m_steps.at(m_index).dwellMs > 0) {
|
||||||
|
m_phase = Phase::Dwelling;
|
||||||
|
++m_token;
|
||||||
|
m_dwell.start(m_steps.at(m_index).dwellMs);
|
||||||
|
} else {
|
||||||
|
completeStep();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TouchSequenceController::acceptCommand(const QString &command, bool success,
|
||||||
|
const QString &detail)
|
||||||
|
{
|
||||||
|
if (m_phase != Phase::Moving || command != commandName(m_token)) return;
|
||||||
|
if (!success) {
|
||||||
|
fail(detail.isEmpty() ? QStringLiteral("触控运动命令失败") : detail);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_expected = m_steps.at(m_index).target;
|
||||||
|
readPose(Phase::VerifyRead);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TouchSequenceController::completeStep()
|
||||||
|
{
|
||||||
|
++m_index;
|
||||||
|
if (m_index == m_steps.size())
|
||||||
|
finish(true, QStringLiteral("触控路径已完成,实际 TCP 已到达最终目标"), false);
|
||||||
|
else
|
||||||
|
moveNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TouchSequenceController::finish(bool success, const QString &detail, bool requestStop)
|
||||||
|
{
|
||||||
|
if (!running()) return;
|
||||||
|
const QString device = m_device;
|
||||||
|
m_phase = Phase::Idle;
|
||||||
|
++m_token;
|
||||||
|
m_timeout.stop();
|
||||||
|
m_deadline.stop();
|
||||||
|
m_dwell.stop();
|
||||||
|
m_steps.clear();
|
||||||
|
if (requestStop) emit stopRequested(device);
|
||||||
|
emit finished(success, detail);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TouchSequenceController::stop()
|
||||||
|
{
|
||||||
|
finish(false, QStringLiteral("触控任务已取消并请求停止;不会自动回程"), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TouchSequenceController::fail(const QString &message)
|
||||||
|
{
|
||||||
|
if (!running()) return;
|
||||||
|
finish(false, message, true);
|
||||||
|
emit errorOccurred(message);
|
||||||
|
}
|
||||||
65
src/touchsequencecontroller.h
Normal file
65
src/touchsequencecontroller.h
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "tcpcalibration.h"
|
||||||
|
#include <QObject>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QVariantMap>
|
||||||
|
#include <QVector>
|
||||||
|
|
||||||
|
// Runs an already reviewed path of targets for the driver's ACTIVE TCP.
|
||||||
|
// Connect its requests to the existing RobotClient; it owns no transport.
|
||||||
|
class TouchSequenceController : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
struct Step {
|
||||||
|
TcpCalibration::Pose target{};
|
||||||
|
double speed = .01;
|
||||||
|
double acceleration = .1;
|
||||||
|
int dwellMs = 0;
|
||||||
|
QString label;
|
||||||
|
};
|
||||||
|
|
||||||
|
explicit TouchSequenceController(QObject *parent = nullptr);
|
||||||
|
void setContext(const QString &endpoint, const QString &device, bool ready,
|
||||||
|
const TcpCalibration::Pose &activeOffset,
|
||||||
|
const QString &contextRevision = QString());
|
||||||
|
// expectedInitialPose is the taught observation pose, or a separately
|
||||||
|
// verified current pose for an explicitly requested return movement.
|
||||||
|
bool start(const QVector<Step> &steps, const TcpCalibration::Pose &expectedInitialPose);
|
||||||
|
bool running() const { return m_phase != Phase::Idle; }
|
||||||
|
static QString commandName(quint64 token);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void stop();
|
||||||
|
void acceptPose(quint64 token, const QString &device, const QVariantMap &pose,
|
||||||
|
const QVariantMap &state, bool success, const QString &detail);
|
||||||
|
void acceptCommand(const QString &command, bool success, const QString &detail);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void captureRequested(const QString &device, quint64 token);
|
||||||
|
void moveRequested(const QString &device, const QVariantMap &target,
|
||||||
|
double speed, double acceleration, quint64 token);
|
||||||
|
void stopRequested(const QString &device);
|
||||||
|
void progressChanged(int step, int total, const QString &label);
|
||||||
|
void errorOccurred(const QString &message);
|
||||||
|
void finished(bool success, const QString &detail);
|
||||||
|
|
||||||
|
private:
|
||||||
|
enum class Phase { Idle, InitialRead, Moving, VerifyRead, Dwelling, AfterDwellRead };
|
||||||
|
void readPose(Phase phase);
|
||||||
|
void moveNext();
|
||||||
|
void completeStep();
|
||||||
|
void fail(const QString &message);
|
||||||
|
void finish(bool success, const QString &detail, bool requestStop);
|
||||||
|
|
||||||
|
QString m_endpoint, m_device, m_contextRevision;
|
||||||
|
TcpCalibration::Pose m_activeOffset{}, m_expected{};
|
||||||
|
bool m_ready = false;
|
||||||
|
Phase m_phase = Phase::Idle;
|
||||||
|
QVector<Step> m_steps;
|
||||||
|
int m_index = 0;
|
||||||
|
quint64 m_token = quint64(1) << 59;
|
||||||
|
qint64 m_captureIssuedAtMs = 0;
|
||||||
|
QTimer m_timeout, m_deadline, m_dwell;
|
||||||
|
};
|
||||||
186
src/touchvideowidget.cpp
Normal file
186
src/touchvideowidget.cpp
Normal file
@ -0,0 +1,186 @@
|
|||||||
|
#include "touchvideowidget.h"
|
||||||
|
|
||||||
|
#include <QMouseEvent>
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
QRect imageRectangle(const QSize &widgetSize, const QSize &imageSize)
|
||||||
|
{
|
||||||
|
if (widgetSize.isEmpty() || imageSize.isEmpty()) return {};
|
||||||
|
QSize target = imageSize;
|
||||||
|
target.scale(widgetSize, Qt::KeepAspectRatio);
|
||||||
|
return QRect((widgetSize.width() - target.width()) / 2,
|
||||||
|
(widgetSize.height() - target.height()) / 2,
|
||||||
|
target.width(), target.height());
|
||||||
|
}
|
||||||
|
|
||||||
|
QRectF frameRectangle(const QSize &widgetSize, const QSize &imageSize, VideoPixelFormat format)
|
||||||
|
{
|
||||||
|
if (format == VideoPixelFormat::RGBA) return imageRectangle(widgetSize, imageSize);
|
||||||
|
if (widgetSize.isEmpty() || imageSize.isEmpty()) return {};
|
||||||
|
// The GL video renderer preserves fractional dimensions and centres the
|
||||||
|
// quad exactly; its geometry differs from the integer RGBA image path.
|
||||||
|
const double scale = qMin(double(widgetSize.width()) / imageSize.width(),
|
||||||
|
double(widgetSize.height()) / imageSize.height());
|
||||||
|
const QSizeF target(imageSize.width() * scale, imageSize.height() * scale);
|
||||||
|
return QRectF((widgetSize.width() - target.width()) / 2,
|
||||||
|
(widgetSize.height() - target.height()) / 2,
|
||||||
|
target.width(), target.height());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool mapPoint(const QPointF &position, const QRectF &area, const QSize &imageSize, QPointF *pixel)
|
||||||
|
{
|
||||||
|
if (!pixel || !std::isfinite(position.x()) || !std::isfinite(position.y())
|
||||||
|
|| imageSize.isEmpty() || area.isEmpty()
|
||||||
|
|| position.x() < area.x() || position.y() < area.y()
|
||||||
|
|| position.x() >= area.x() + area.width()
|
||||||
|
|| position.y() >= area.y() + area.height()) return false;
|
||||||
|
const double x = (position.x() - area.x()) * imageSize.width() / area.width() - .5;
|
||||||
|
const double y = (position.y() - area.y()) * imageSize.height() / area.height() - .5;
|
||||||
|
*pixel = QPointF(qBound(0.0, x, double(imageSize.width() - 1)),
|
||||||
|
qBound(0.0, y, double(imageSize.height() - 1)));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TouchVideoWidget::TouchVideoWidget(QWidget *parent) : VideoRenderWidget(parent)
|
||||||
|
{
|
||||||
|
setMinimumSize(320, 240);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TouchVideoWidget::present(const VideoFrame &frame)
|
||||||
|
{
|
||||||
|
if (!frame.isValid()) return;
|
||||||
|
m_latestFrame = frame;
|
||||||
|
if (m_locked) return;
|
||||||
|
m_imageSize = QSize(frame.width, frame.height);
|
||||||
|
setFrame(frame);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TouchVideoWidget::lockImage(const QImage &image)
|
||||||
|
{
|
||||||
|
if (image.isNull()) return false;
|
||||||
|
m_locked = true;
|
||||||
|
m_imageSize = image.size();
|
||||||
|
m_lockedFormat = VideoPixelFormat::RGBA;
|
||||||
|
setImage(image);
|
||||||
|
clearSelection();
|
||||||
|
setCursor(Qt::CrossCursor);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TouchVideoWidget::lockFrame(const VideoFrame &frame)
|
||||||
|
{
|
||||||
|
if (!frame.isValid()) return false;
|
||||||
|
m_locked = true;
|
||||||
|
m_imageSize = QSize(frame.width, frame.height);
|
||||||
|
m_lockedFormat = frame.format;
|
||||||
|
// VideoFrame keeps its backing AVFrame alive through its shared owner.
|
||||||
|
// Keep the exact frame, including timestamps and matching intrinsics.
|
||||||
|
setFrame(frame);
|
||||||
|
clearSelection();
|
||||||
|
setCursor(Qt::CrossCursor);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TouchVideoWidget::unlock()
|
||||||
|
{
|
||||||
|
m_locked = false;
|
||||||
|
m_lockedFormat = VideoPixelFormat::Invalid;
|
||||||
|
clearSelection();
|
||||||
|
unsetCursor();
|
||||||
|
if (m_latestFrame.isValid()) {
|
||||||
|
m_imageSize = QSize(m_latestFrame.width, m_latestFrame.height);
|
||||||
|
setFrame(m_latestFrame);
|
||||||
|
} else {
|
||||||
|
m_imageSize = {};
|
||||||
|
VideoRenderWidget::clearFrame();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TouchVideoWidget::clearFrame(const QString &message)
|
||||||
|
{
|
||||||
|
m_latestFrame = {};
|
||||||
|
m_imageSize = {};
|
||||||
|
m_locked = false;
|
||||||
|
m_lockedFormat = VideoPixelFormat::Invalid;
|
||||||
|
clearSelection();
|
||||||
|
unsetCursor();
|
||||||
|
VideoRenderWidget::clearFrame(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TouchVideoWidget::clearSelection()
|
||||||
|
{
|
||||||
|
if (m_points.isEmpty()) return;
|
||||||
|
m_points.clear();
|
||||||
|
update();
|
||||||
|
emit pointsChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TouchVideoWidget::setMaxPoints(int count)
|
||||||
|
{
|
||||||
|
count = qBound(1, count, 2);
|
||||||
|
if (count == m_maxPoints) return;
|
||||||
|
m_maxPoints = count;
|
||||||
|
clearSelection();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TouchVideoWidget::mapToImage(const QPointF &position, const QSizeF &widgetSize,
|
||||||
|
const QSize &imageSize, QPointF *pixel)
|
||||||
|
{
|
||||||
|
if (!std::isfinite(widgetSize.width()) || !std::isfinite(widgetSize.height())
|
||||||
|
|| widgetSize.isEmpty() || imageSize.isEmpty()) return false;
|
||||||
|
return mapPoint(position, imageRectangle(widgetSize.toSize(), imageSize), imageSize, pixel);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TouchVideoWidget::mousePressEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
|
QPointF pixel;
|
||||||
|
if (event->button() != Qt::LeftButton || !m_locked
|
||||||
|
|| !mapPoint(event->localPos(), frameRectangle(size(), m_imageSize, m_lockedFormat), m_imageSize, &pixel)) {
|
||||||
|
VideoRenderWidget::mousePressEvent(event);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (m_points.size() >= m_maxPoints) m_points.clear();
|
||||||
|
m_points.append(pixel);
|
||||||
|
update();
|
||||||
|
emit pointsChanged();
|
||||||
|
event->accept();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TouchVideoWidget::paintGL()
|
||||||
|
{
|
||||||
|
VideoRenderWidget::paintGL();
|
||||||
|
if (!m_locked || m_points.isEmpty() || m_imageSize.isEmpty()) return;
|
||||||
|
const QRectF area = frameRectangle(size(), m_imageSize, m_lockedFormat);
|
||||||
|
if (area.isEmpty()) return;
|
||||||
|
QVector<QPointF> screenPoints;
|
||||||
|
for (const QPointF &point : m_points) {
|
||||||
|
screenPoints.append(QPointF(area.x() + (point.x() + .5) * area.width() / m_imageSize.width(),
|
||||||
|
area.y() + (point.y() + .5) * area.height() / m_imageSize.height()));
|
||||||
|
}
|
||||||
|
QPainter painter(this);
|
||||||
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
|
painter.setClipRect(area);
|
||||||
|
painter.setPen(QPen(QColor(QStringLiteral("#f4d26c")), 2));
|
||||||
|
if (screenPoints.size() == 2) painter.drawLine(screenPoints[0], screenPoints[1]);
|
||||||
|
for (int i = 0; i < screenPoints.size(); ++i) {
|
||||||
|
const QPointF center = screenPoints[i];
|
||||||
|
painter.setPen(QPen(i == 0 ? QColor(QStringLiteral("#4cdd9b"))
|
||||||
|
: QColor(QStringLiteral("#ffac60")), 2));
|
||||||
|
painter.setBrush(QColor(14, 17, 21, 180));
|
||||||
|
painter.drawEllipse(center, 7, 7);
|
||||||
|
const QString label = i == 0 ? QStringLiteral("A") : QStringLiteral("B");
|
||||||
|
const qreal labelWidth = painter.fontMetrics().horizontalAdvance(label) + 8;
|
||||||
|
const qreal labelHeight = painter.fontMetrics().height() + 4;
|
||||||
|
const qreal left = qBound(qreal(area.left()), center.x() + 11,
|
||||||
|
qMax(qreal(area.left()), area.x() + area.width() - labelWidth));
|
||||||
|
const qreal top = qBound(qreal(area.top()), center.y() - labelHeight - 3,
|
||||||
|
qMax(qreal(area.top()), area.y() + area.height() - labelHeight));
|
||||||
|
const QRectF labelRect(left, top, labelWidth, labelHeight);
|
||||||
|
painter.fillRect(labelRect, QColor(14, 17, 21, 210));
|
||||||
|
painter.drawText(labelRect, Qt::AlignCenter, label);
|
||||||
|
}
|
||||||
|
}
|
||||||
49
src/touchvideowidget.h
Normal file
49
src/touchvideowidget.h
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "videorenderwidget.h"
|
||||||
|
|
||||||
|
#include <QPointF>
|
||||||
|
#include <QSizeF>
|
||||||
|
#include <QVector>
|
||||||
|
|
||||||
|
class QMouseEvent;
|
||||||
|
|
||||||
|
// Presents an existing camera session. Selection belongs to a frozen native
|
||||||
|
// image, whose matching intrinsics and robot pose are owned by the caller.
|
||||||
|
class TouchVideoWidget : public VideoRenderWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit TouchVideoWidget(QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
void present(const VideoFrame &frame);
|
||||||
|
bool lockImage(const QImage &image);
|
||||||
|
bool lockFrame(const VideoFrame &frame);
|
||||||
|
void unlock();
|
||||||
|
void clearFrame(const QString &message = QStringLiteral("暂无画面"));
|
||||||
|
void clearSelection();
|
||||||
|
void setMaxPoints(int count);
|
||||||
|
QVector<QPointF> selectedPoints() const { return m_points; }
|
||||||
|
bool locked() const { return m_locked; }
|
||||||
|
QSize imageSize() const { return m_imageSize; }
|
||||||
|
|
||||||
|
// OpenCV coordinates: the centre of the first pixel is (0, 0).
|
||||||
|
// Uses the same integer letterbox rectangle as the base RGBA renderer.
|
||||||
|
static bool mapToImage(const QPointF &position, const QSizeF &widgetSize,
|
||||||
|
const QSize &imageSize, QPointF *pixel);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void pointsChanged();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void mousePressEvent(QMouseEvent *event) override;
|
||||||
|
void paintGL() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
VideoFrame m_latestFrame;
|
||||||
|
QSize m_imageSize;
|
||||||
|
VideoPixelFormat m_lockedFormat = VideoPixelFormat::Invalid;
|
||||||
|
QVector<QPointF> m_points;
|
||||||
|
int m_maxPoints = 1;
|
||||||
|
bool m_locked = false;
|
||||||
|
};
|
||||||
@ -77,11 +77,51 @@ VideoRenderWidget::~VideoRenderWidget()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VideoRenderWidget::setFrameAspectLayoutEnabled(bool enabled)
|
||||||
|
{
|
||||||
|
m_frameAspectLayout = enabled;
|
||||||
|
QSizePolicy policy(QSizePolicy::Expanding, enabled ? QSizePolicy::Fixed : QSizePolicy::Expanding);
|
||||||
|
policy.setHeightForWidth(enabled);
|
||||||
|
setSizePolicy(policy);
|
||||||
|
if (enabled) updateAspectHeight();
|
||||||
|
else { setMinimumHeight(0); setMaximumHeight(QWIDGETSIZE_MAX); }
|
||||||
|
updateGeometry();
|
||||||
|
}
|
||||||
|
|
||||||
|
int VideoRenderWidget::heightForWidth(int width) const
|
||||||
|
{
|
||||||
|
return m_frameAspectLayout ? qMax(1, qRound(double(width) * m_layoutFrameSize.height()
|
||||||
|
/ m_layoutFrameSize.width())) : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
QSize VideoRenderWidget::sizeHint() const
|
||||||
|
{
|
||||||
|
return m_frameAspectLayout ? QSize(640,heightForWidth(640)) : QOpenGLWidget::sizeHint();
|
||||||
|
}
|
||||||
|
|
||||||
|
void VideoRenderWidget::updateAspectHeight()
|
||||||
|
{
|
||||||
|
if (!m_frameAspectLayout) return;
|
||||||
|
const int wanted = heightForWidth(width());
|
||||||
|
if (minimumHeight() != wanted || maximumHeight() != wanted) setFixedHeight(wanted);
|
||||||
|
}
|
||||||
|
|
||||||
|
void VideoRenderWidget::resizeEvent(QResizeEvent *event)
|
||||||
|
{
|
||||||
|
QOpenGLWidget::resizeEvent(event);
|
||||||
|
updateAspectHeight();
|
||||||
|
}
|
||||||
|
|
||||||
void VideoRenderWidget::setFrame(const VideoFrame &frame)
|
void VideoRenderWidget::setFrame(const VideoFrame &frame)
|
||||||
{
|
{
|
||||||
if (!frame.isValid())
|
if (!frame.isValid())
|
||||||
return;
|
return;
|
||||||
m_frame = frame;
|
m_frame = frame;
|
||||||
|
if (m_layoutFrameSize != QSize(frame.width, frame.height)) {
|
||||||
|
m_layoutFrameSize = QSize(frame.width, frame.height);
|
||||||
|
updateAspectHeight();
|
||||||
|
if (m_frameAspectLayout) updateGeometry();
|
||||||
|
}
|
||||||
m_message.clear();
|
m_message.clear();
|
||||||
m_frameDirty = true;
|
m_frameDirty = true;
|
||||||
update();
|
update();
|
||||||
|
|||||||
@ -23,10 +23,15 @@ public:
|
|||||||
void setImage(const QImage &image);
|
void setImage(const QImage &image);
|
||||||
void clearFrame(const QString &message = QStringLiteral("暂无画面"));
|
void clearFrame(const QString &message = QStringLiteral("暂无画面"));
|
||||||
bool hasFrame() const { return m_frame.isValid(); }
|
bool hasFrame() const { return m_frame.isValid(); }
|
||||||
|
// Opt-in for calibration panels; other video pages keep their layout.
|
||||||
|
void setFrameAspectLayoutEnabled(bool enabled);
|
||||||
|
int heightForWidth(int width) const override;
|
||||||
|
QSize sizeHint() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void initializeGL() override;
|
void initializeGL() override;
|
||||||
void paintGL() override;
|
void paintGL() override;
|
||||||
|
void resizeEvent(QResizeEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void releaseTextures();
|
void releaseTextures();
|
||||||
@ -34,6 +39,9 @@ private:
|
|||||||
unsigned int format, const QByteArray &data,
|
unsigned int format, const QByteArray &data,
|
||||||
int textureIndex);
|
int textureIndex);
|
||||||
void drawMessage(const QString &message);
|
void drawMessage(const QString &message);
|
||||||
|
void updateAspectHeight();
|
||||||
|
bool m_frameAspectLayout = false;
|
||||||
|
QSize m_layoutFrameSize{640, 480}; // Placeholder until the first camera frame.
|
||||||
|
|
||||||
std::unique_ptr<QOpenGLShaderProgram> m_program;
|
std::unique_ptr<QOpenGLShaderProgram> m_program;
|
||||||
VideoFrame m_frame;
|
VideoFrame m_frame;
|
||||||
|
|||||||
13
styles.qss
13
styles.qss
@ -1357,9 +1357,9 @@ QTabWidget#armJogModeTabs::pane {
|
|||||||
background: #ffffff;
|
background: #ffffff;
|
||||||
}
|
}
|
||||||
QTabWidget#armJogModeTabs QTabBar::tab {
|
QTabWidget#armJogModeTabs QTabBar::tab {
|
||||||
min-width: 150px;
|
min-width: 80px;
|
||||||
min-height: 32px;
|
min-height: 32px;
|
||||||
padding: 0 18px;
|
padding: 0 8px;
|
||||||
color: #64717d;
|
color: #64717d;
|
||||||
background: #f2f5f8;
|
background: #f2f5f8;
|
||||||
border: 1px solid #dbe2e8;
|
border: 1px solid #dbe2e8;
|
||||||
@ -1370,6 +1370,9 @@ QTabWidget#armJogModeTabs QTabBar::tab:selected {
|
|||||||
border-color: #8db9f3;
|
border-color: #8db9f3;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
|
QWidget#handEyeMotionPanel QDoubleSpinBox {
|
||||||
|
padding: 6px 8px;
|
||||||
|
}
|
||||||
QFrame#jogAxisRow {
|
QFrame#jogAxisRow {
|
||||||
background: transparent;
|
background: transparent;
|
||||||
border: none;
|
border: none;
|
||||||
@ -1463,6 +1466,12 @@ QPushButton#cartesianPadButton[padRole="north"] {
|
|||||||
border-bottom-left-radius: 9px;
|
border-bottom-left-radius: 9px;
|
||||||
border-bottom-right-radius: 9px;
|
border-bottom-right-radius: 9px;
|
||||||
}
|
}
|
||||||
|
QPushButton#cartesianPadButton[padRole="compact"] {
|
||||||
|
min-height: 36px;
|
||||||
|
max-height: 36px;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
QPushButton#cartesianPadButton[padRole="south"] {
|
QPushButton#cartesianPadButton[padRole="south"] {
|
||||||
border-top-left-radius: 9px;
|
border-top-left-radius: 9px;
|
||||||
border-top-right-radius: 9px;
|
border-top-right-radius: 9px;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user