外观
C++
头文件 w6e/hand_client.hpp,命名空间 w6e。示例在 sdk/cpp/examples/,静态库目标名为 w6e。多数接口返回 bool,失败时看 last_error()。
编译
bash
sudo apt-get install -y build-essential cmake qt6-base-dev
cd sdk/cpp
cmake -B build -DW6E_BUILD_UI=ON -DCMAKE_PREFIX_PATH=/usr
cmake --build build -j"$(nproc)"只要命令行、不要界面时,把 -DW6E_BUILD_UI=ON 换成 -DW6E_BUILD_UI=OFF。不要在同一次配置里来回切换,后一次会去掉面板程序。
如果目录里带着另一台电脑的 build,先删掉再在本机重新 cmake。
bash
sdk/cpp/build/w6e_control_panel
sdk/cpp/build/examples/encoder_status --port /dev/ttyACM0
sdk/cpp/build/examples/set_open_pct --port /dev/ttyACM0 0 0 0 0 0 0C++ 面板的端口框可以打字。串口传输选 can_slcan。can0 已经挂上时,传输选 socketcan,端口手输 can0。
bash
sdk/cpp/build/examples/encoder_status --port can0 --transport socketcan
sdk/cpp/build/examples/set_open_pct --port can0 --transport socketcan 0 0 0 0 0 0最短示例
cpp
#include "w6e/hand_client.hpp"
#include <iostream>
int main() {
w6e::HandClient hand(1.0);
if (!hand.connect("/dev/ttyACM0", w6e::TransportKind::CanSlcan)) {
std::cerr << hand.last_error() << std::endl;
return 1;
}
std::cout << hand.get_version_string() << std::endl;
hand.set_open_pct({100, 100, 100, 100, 100, 100});
hand.set_open_pct({0, 0, 0, 0, 0, 0});
hand.play_gesture("ok");
hand.stop_all();
hand.disconnect();
return 0;
}SocketCAN 时使用 w6e::TransportKind::SocketCan,端口填 can0。
常用接口
| 接口 | 作用 |
|---|---|
list_ports() | 串口名列表 |
connect(port, kind, verify) | 默认 CanSlcan。verify 为真时读版本并确认是 W6E |
disconnect() / connected() | 退出前调用 disconnect() |
set_open_pct / get_open_pct / get_positions | 六个开合度。未归零的那一路在 get_positions 里无值 |
open_all / close_all / stop_all | 前两个不含虎口 |
set_finger / stop_finger / set_finger_actions | 单指极限,或六路同时停 / 开 / 合(0 / 1 / 2) |
play_gesture / play_fixed / list_gestures | 预设手势 |
get_version_string / get_serial_number | 例如 1.0.20 |
home / wait_home / get_encoder_status | 归零期间手指会动 |
last_error | 最近一次失败的描述 |
open_all 和 close_all 的超时参数默认 8 秒。任意中间位置用 set_open_pct,不要用 set_finger。
