diff --git a/docs/en/README.md b/docs/en/README.md index b67a503..1014fe8 100644 --- a/docs/en/README.md +++ b/docs/en/README.md @@ -15,7 +15,7 @@ | Model | Tutorial and support status | | --- | --- | | L6 | [Classic CAN features and native Managers](tutorials/l6.md); for optional HOP CAN FD, see [Protocol details](guides/usage.md#optional-l6-can-fd-protocol) | -| O6 | [Angles, speed, acceleration, and sensors](tutorials/o6.md) | +| O6 | [Angles, speed, acceleration, and sensors](tutorials/o6.md); for optional HOP 0.0.4 (CAN FD / CAN 2.0), see [O6 HOP setup and mode switching](tutorials/o6.md#o6-hop) | | L20 Lite | [Ten-joint control, configuration caches, and tactile data](tutorials/l20lite.md) | | L20 | [Sixteen-joint control and sensors](tutorials/l20.md) | | L30 | [CAN FD, enablement, and seventeen-joint control](tutorials/l30.md) | diff --git a/docs/en/connections/manual.md b/docs/en/connections/manual.md index bee9601..d4ce1c0 100644 --- a/docs/en/connections/manual.md +++ b/docs/en/connections/manual.md @@ -7,7 +7,7 @@ For build instructions, see [Prepare the communication interface](prepare-interf | Model | `Model` | Joint count | Default communication and address | | --- | --- | ---: | --- | | L6 | `kL6` | 6 | Classic CAN, left `0x28`, right `0x27` | -| O6 | `kO6` | 6 | Classic CAN, left `0x28`, right `0x27` | +| O6 | `kO6` | 6 | Classic CAN (left `0x28`, right `0x27`); optional HOP 0.0.4 (default request ID `0x001`) | | L20 Lite | `kL20Lite` | 10 | Classic CAN, left `0x28`, right `0x27` | | L20 | `kL20` | 16 | Classic CAN, left `0x28`, right `0x27` | | L30 | `kL30` | 17 | Extended FD, NodeID defaults to 1, HostID defaults to 0 | @@ -154,9 +154,9 @@ For optional L6 HOP firmware, explicitly set `config.l6_protocol = L6Protocol::k and verify the corresponding address, bitrate, and capabilities. You cannot infer the device protocol from the FD interface configuration. See [Optional HOP connection](../guides/usage.md#optional-l6-can-fd-protocol). -Connect to O6 HOP firmware manually. Set `config.o6_protocol = O6Protocol::kHopV004` for a device currently using CAN FD, -or select `O6Protocol::kHopV004Can` for CAN 2.0 and configure SocketCAN to match the device. The default request ID is `0x001`. -See the connection example and device-side mode switch in [Manual O6 HOP connection](../tutorials/o6.md#o6-hop). +Connect to O6 HOP firmware manually (default request ID `0x001`): set `config.o6_protocol = O6Protocol::kHopV004` when the device is in CAN FD (`fd on`), +or `O6Protocol::kHopV004Can` when the device is in CAN 2.0 (`fd off`). +See [Manual O6 HOP connection](../tutorials/o6.md#o6-hop) for setup examples and [Switching HOP CAN modes](../tutorials/o6.md#hop-can-mode) to change the device mode. diff --git a/docs/en/connections/prepare-interface.md b/docs/en/connections/prepare-interface.md index 102766d..7270fac 100644 --- a/docs/en/connections/prepare-interface.md +++ b/docs/en/connections/prepare-interface.md @@ -22,11 +22,11 @@ if(MSVC) endif() ``` -Place the application files in `demo/` and run the following from the SDK source root, replacing `install` with the actual SDK installation prefix: +Place `CMakeLists.txt` and `main.cpp` in your application directory and build from there (replace `/path/to/linkerbot-hand-cpp` with your extracted SDK package directory or install prefix; omit `-DCMAKE_PREFIX_PATH` if installed into a standard system prefix such as `/usr/local`): ```bash -cmake -S demo -B demo/build -DCMAKE_PREFIX_PATH="$PWD/install" -cmake --build demo/build --config Release +cmake -S . -B build -DCMAKE_PREFIX_PATH="/path/to/linkerbot-hand-cpp" +cmake --build build --config Release ``` `HandDevice` does not directly accept Python transport arguments or model-name strings. In C++, use @@ -40,7 +40,7 @@ Automatic discovery does not run `ip link` or change the interface bitrate for y ### Classic CAN -L6, O6, L20 Lite, and L20 with Classic firmware use 1 Mbit/s: +L6, O6, L20 Lite, and L20 with Classic firmware—as well as O6 HOP running in CAN 2.0 mode (`O6Protocol::kHopV004Can`)—use 1 Mbit/s: ```bash sudo ip link set can0 down @@ -51,7 +51,7 @@ ip -details link show can0 ### CAN FD -L30 and O30 use a nominal bitrate of 1 Mbit/s and a data bitrate of 5 Mbit/s: +L30, O30, and O6 HOP running in CAN FD mode (`O6Protocol::kHopV004`) use a nominal bitrate of 1 Mbit/s and a data bitrate of 5 Mbit/s: ```bash sudo ip link set can0 down @@ -60,9 +60,9 @@ sudo ip link set can0 up ip -details link show can0 ``` -L30 uses extended FD frames; O30 uses standard FD frames without BRS. Each model implementation determines the frame format. -L6 still defaults to Classic CAN. Explicitly select the optional HOP CAN FD protocol only when the device firmware matches; -setting the system interface to FD alone does not switch the L6 protocol. See [Optional protocol](../guides/usage.md#optional-l6-can-fd-protocol). +L30 uses extended FD frames; O30 and O6 HOP use standard FD frames without BRS. The model and protocol configuration determine the frame format. +L6 and O6 still default to Classic CAN. Explicitly select an optional HOP protocol only when the device firmware matches; +setting the system interface to FD alone does not switch the device protocol. See [Optional L6 protocol](../guides/usage.md#optional-l6-can-fd-protocol) and [Manual O6 HOP connection and mode switching](../tutorials/o6.md#o6-hop). ## Windows and standalone adapter backends diff --git a/docs/en/reference/model-capabilities.md b/docs/en/reference/model-capabilities.md index 0530a1e..05793e8 100644 --- a/docs/en/reference/model-capabilities.md +++ b/docs/en/reference/model-capabilities.md @@ -176,7 +176,7 @@ The model-specific entry point is `o6::HopO6`. For the unified API, explicitly s | CAN configuration | `get_can_configuration()` reads the mode, request ID, BRS, and bitrates. `set_can_interface_mode()` writes the mode field | Use raw counts for numeric data. Physical conversions for speed, acceleration, and current remain unverified. -See the [O6 HOP guide](../tutorials/o6.md#o6-hop) for connection setup, mode switching, and adapter limitations. +See [Manual HOP 0.0.4 connection](../tutorials/o6.md#o6-hop) for setup and [Switching HOP CAN modes](../tutorials/o6.md#hop-can-mode) for mode-switching steps. ## L20 Lite diff --git a/docs/en/tutorials/o6.md b/docs/en/tutorials/o6.md index 9dc6f12..daafe1a 100644 --- a/docs/en/tutorials/o6.md +++ b/docs/en/tutorials/o6.md @@ -1,7 +1,8 @@ # O6 Feature Guide -O6 has 6 joints. The SDK defaults to the original O6 Classic CAN protocol. Select HOP explicitly on firmware that supports HOP 0.0.4. -This page uses C++ `HandDevice` for common operations. The examples follow the current C++ SDK API. +O6 has 6 joints. The SDK defaults to the original O6 Classic CAN protocol; for firmware running **HOP 0.0.4**, explicitly set `config.o6_protocol`. + +This page uses the C++ `HandDevice` API for common operations. ## Contents @@ -15,265 +16,277 @@ This page uses C++ `HandDevice` for common operations. The examples follow the c - [Speed control](#speed-control) - [Acceleration settings](#acceleration) - [Reading sensor data](#sensor-reading) +- [Notes and known limitations](#notes) ## Usage -For firmware using the original O6 Classic CAN protocol, configure your environment using [Prepare the communication interface](../connections/prepare-interface.md), then choose [Automatic connection](../connections/automatic.md) -or [Manual connection](../connections/manual.md). The complete read-only Linux SocketCAN program below -provides the `hand` object, chrono literals, and printing/waiting helpers used by the snippets later on this page. -For Windows, replace the device construction code with a verified adapter factory; the feature snippets remain the same. +Before starting, set up your build environment and CAN interface as described in [Prepare the communication interface](../connections/prepare-interface.md). + +### Match the three protocol modes first + +The **device's current mode**, the **host CAN interface**, and **`config.o6_protocol` in code** must all match. Otherwise, `hand.open()` will time out (`device request deadline expired`): + +| Protocol mode | `config.o6_protocol` | Default CAN ID | Linux `can0` setup | +| --- | --- | --- | --- | +| Classic (legacy default) | `O6Protocol::kClassic` (default) | Left `0x28` / Right `0x27` | `bitrate 1000000 fd off` | +| HOP 0.0.4 · CAN FD | `O6Protocol::kHopV004` | Request `0x001` / Response `0x401` | `bitrate 1000000 dbitrate 5000000 fd on` | +| HOP 0.0.4 · CAN 2.0 | `O6Protocol::kHopV004Can` | Request `0x001` / Response `0x401` | `bitrate 1000000 fd off` | + +### Minimal complete program (Linux SocketCAN) + +The example below connects to a Classic O6 and reads all 6 joint angles (for HOP firmware, set `o6_protocol` and `address` as shown in the next section; on Windows, supply an adapter transport factory—the feature calls stay the same): ```cpp -#include #include -#include #include #include -#include -#include -#include #include using namespace linkerbot::hand; using namespace std::chrono_literals; -template -void print_values(const Values &values) { - for (const auto value : values) { - std::cout << +value << ' '; - } - std::cout << '\n'; -} - -void check_sample(const SampleMeta &meta) { - if (!meta.valid) { - throw std::runtime_error("Sample unavailable"); - } - if (meta.stale) { - std::cerr << "Sample is stale; read it again as required by your application\n"; - } -} - -void wait_command(const CommandHandle &command) { - if (!command.wait_for(2s)) { - throw std::runtime_error("Wait timed out; command was not cancelled and is not automatically resent"); - } - if (const auto error = command.error()) { - std::rethrow_exception(error); - } - const auto stage = command.stage(); - if (stage != CommandStage::kAcknowledged && - !(stage == CommandStage::kDispatched && command.ack_expectation() == AckExpectation::kNone)) { - throw std::runtime_error("Command did not complete successfully; it may have been replaced or cancelled"); - } -} +int main() { + try { + HandDeviceConfig config; + config.model = Model::kO6; + config.side = HandSide::kLeft; // Change to kLeft or kRight as needed + config.interface_name = "can0"; -void print_sample(const RawVectorSample &sample) { - check_sample(sample.meta); - print_values(sample.raw); -} + HandDevice hand(config); + hand.open(); -void print_field(const ForceSample &force, const std::string &name) { - const auto *field = force.field(name); - if (!field) { - std::cout << name << ": " << force.status(name) << '\n'; - return; - } - check_sample(field->meta); - for (size_t finger = 0; finger < field->raw.size(); ++finger) { - if (!field->raw[finger]) { - std::cout << "finger " << finger << ": no data\n"; - continue; - } - const auto &values = *field->raw[finger]; - for (size_t point = 0; point < values.size(); ++point) { - if (finger < field->valid_values.size() && field->valid_values[finger] && - point < field->valid_values[finger]->size() && !(*field->valid_values[finger])[point]) { - std::cout << "invalid "; - } else { - std::cout << values[point] << ' '; - } + // Any feature snippet below can be placed here (after open() and before close()) + const auto angles = hand.get_angles(1s); + for (const auto angle : angles.raw) { + std::cout << angle << ' '; } std::cout << '\n'; - } -} -int main() try { - HandDeviceConfig config; - config.model = Model::kO6; - config.side = HandSide::kLeft; // Set the actual hand side. - config.interface_name = "can0"; // This complete program uses Linux SocketCAN. - HandDevice hand(config); - std::exception_ptr failure; - try { - hand.open(); - // Insert the feature snippet you need here; do not run every control example at once. - const auto angles = hand.get_angles(1s); - check_sample(angles.meta); - print_values(angles.raw); - } catch (...) { - failure = std::current_exception(); - } - try { hand.close(); - } catch (const std::exception &error) { - if (!failure) { - throw; - } - std::cerr << "Failed to close connection: " << error.what() << '\n'; - } - if (failure) { - std::rethrow_exception(failure); + } catch (const std::exception &e) { + std::cerr << "Error: " << e.what() << '\n'; + return 1; } return 0; -} catch (const std::exception &error) { - std::cerr << error.what() << '\n'; - return 1; } ``` -Place each ordinary C++ snippet below after `hand.open()` succeeds and before `hand.close()`, -keeping these helper functions. The snippets are not standalone programs, and you should not run all control operations at once. -The sections on native Managers provide separate standalone programs. - -Unified setters and discrete operations such as `enable()` / `disable()` return a `CommandHandle`. -`wait_command()` waits for termination, then checks the error and final stage: only `kAcknowledged`, or `kDispatched` when no ACK is expected, -counts as completed communication under the corresponding protocol. Replacement, cancellation, and failure are not success; a wait timeout neither cancels nor automatically resends the command. -Your application must separately verify mechanical positioning and control effects. - -Check `meta.valid` first, then use `meta.stale` to determine whether a sample has expired; a cached reading is not a live measurement. -If closing fails, a long-running application should retain the same object and schedule cleanup retries rather than immediately opening another connection. +> Tips: +> - `HandDevice`'s destructor automatically attempts to close the connection on scope exit, so a single `try / catch` block is enough to report errors clearly. For production close-retry and recovery patterns, see the [API guide](../guides/usage.md). +> - All `set_*` methods enqueue asynchronously and return a `CommandHandle`. Call `cmd.wait_for(2s)` and check `cmd.error()` when you need to confirm delivery/acknowledgement. +> - In production code, check `sample.meta.valid` and `sample.meta.stale` before using sensor samples. ## Manual HOP 0.0.4 connection -HOP defines device registers and messages. CAN 2.0 and CAN FD carry those messages. Set `HandDeviceConfig::o6_protocol` to match the device's **current** protocol and frame format. -This setting selects how the SDK communicates. To change the device's frame format, use the [HOP mode-switching API](#hop-can-mode). +Connect to HOP firmware manually by specifying the hand side, request ID (default `0x001`; response ID is automatically `request_id | 0x400`), and the `o6_protocol` that matches the device's current frame format. -| Setting | Frame format | Addresses | -| --- | --- | --- | -| `O6Protocol::kClassic` (default) | Original O6 Classic CAN | Left `0x28`, right `0x27` | -| `O6Protocol::kHopV004` | HOP 0.0.4, standard CAN FD frames with BRS off on SDK transmissions | Default request ID `0x001`; response ID is the request ID OR `0x400` | -| `O6Protocol::kHopV004Can` | HOP 0.0.4, standard CAN 2.0 frames | Same ID rules as HOP CAN FD | +> `config.o6_protocol` only selects **which frame format the SDK uses**—it does not change the device's mode. To switch the device-side mode, see [Switching HOP CAN modes](#hop-can-mode). + +### 1. Configure Linux SocketCAN -Connect to HOP devices manually. Specify the actual hand side, request ID, and adapter channel. `open()` reads the device identity and checks the hand side. -Check the CAN_H and CAN_L wiring and bus termination. The tested right hand used `0x001/0x401`, a 1 Mbit/s nominal bitrate, a 5 Mbit/s data bitrate, and BRS off. -For a Linux SocketCAN device with these settings, configure `can0` as follows. +Choose the command matching the device's current CAN mode: ```bash +# Device currently in CAN FD (1 Mbit/s nominal + 5 Mbit/s data; SDK sends with BRS off) sudo ip link set can0 down sudo ip link set can0 up type can bitrate 1000000 dbitrate 5000000 fd on -ip -details link show can0 + +# Device currently in CAN 2.0 (1 Mbit/s, FD disabled) +sudo ip link set can0 down +sudo ip link set can0 up type can bitrate 1000000 fd off ``` -This program reads CAN configuration and angles. For a device already using HOP CAN 2.0, select `kHopV004Can` and configure SocketCAN with the nominal bitrate and `fd off`. +### 2. Read CAN configuration and angles (complete example) ```cpp +#include #include #include #include -int main() try { - using namespace linkerbot::hand; - HandDeviceConfig config; - config.model = Model::kO6; - config.side = HandSide::kRight; - config.interface_name = "can0"; - config.address = 0x001; - config.o6_protocol = O6Protocol::kHopV004; - - HandDevice hand(config); - hand.open(); - const auto can = hand.get_can_configuration(); - std::cout << "request_id=0x" << std::hex << can.request_id - << " response_id=0x" << can.response_id() << std::dec - << " mode=" << (can.interface_mode == HopCanInterfaceMode::kCanFd ? "canfd" : "can") - << " nominal=" << can.nominal_bitrate << " data=" << can.data_bitrate - << " brs=" << can.brs << '\n'; - const auto angles = hand.get_angles(); - for (const auto angle : angles.raw) { - std::cout << angle << ' '; +using namespace linkerbot::hand; +using namespace std::chrono_literals; + +int main() { + try { + HandDeviceConfig config; + config.model = Model::kO6; + config.side = HandSide::kRight; + config.interface_name = "can0"; + config.address = 0x001; + config.o6_protocol = O6Protocol::kHopV004; // Use kHopV004Can if device is in CAN 2.0 + + HandDevice hand(config); + hand.open(); + + const auto can = hand.get_can_configuration(); + std::cout << "request_id=0x" << std::hex << can.request_id + << " response_id=0x" << can.response_id() << std::dec + << " mode=" << (can.interface_mode == HopCanInterfaceMode::kCanFd ? "canfd" : "can") + << " nominal=" << can.nominal_bitrate + << " data=" << can.data_bitrate + << " brs=" << can.brs << '\n'; + + const auto angles = hand.get_angles(1s); + for (const auto angle : angles.raw) { + std::cout << angle << ' '; + } + std::cout << '\n'; + + hand.close(); + } catch (const std::exception &e) { + std::cerr << "Error: " << e.what() << '\n'; + return 1; } - std::cout << '\n'; - hand.close(); - return angles.meta.valid ? 0 : 1; -} catch (const std::exception &error) { - std::cerr << error.what() << '\n'; - return 1; + return 0; } ``` +> **Troubleshooting timeouts**: If you get `device request deadline expired`, the most common cause is a **mismatch between the device's current mode and `config.o6_protocol`** (for example, code uses `kHopV004` while the hand is in CAN 2.0 mode), or swapped CAN_H / CAN_L lines. Temporarily switch `o6_protocol` to `kHopV004Can` (with `can0` set to `fd off`) and rerun to see which mode prints `mode=...` and confirm the device's current state. + ## Switching HOP CAN modes -`get_can_configuration()` reads the device's request ID, interface mode, BRS, nominal bitrate, and data bitrate. -Pass `HopCanInterfaceMode::kCan20` or `HopCanInterfaceMode::kCanFd` to `set_can_interface_mode()` to set the device's HOP frame format. -These modes correspond to values `1` and `2` in MI `0x35` / SI `0x06`. Disable device-side BRS before selecting CAN 2.0. -Connect in the device's current mode before switching. Each call sends at most one mode write. Configure the host interface separately. +The device-side HOP frame format is controlled by register `MI 0x35 / SI 0x06` (`1` = CAN 2.0, `2` = CAN FD), and Flash save is triggered by `MI 0x35 / SI 0x1E = 1`. + +Switching always follows three steps: **1. Check current mode → 2. Switch device-side mode → 3. Update the host interface and `o6_protocol`**. + +### Step 1: Check the device's current mode (read-only) + +Run the complete example in the previous section (which calls `hand.get_can_configuration()`) to print the current `mode=canfd` or `mode=can`, along with `brs` and bitrates. If unsure, try `kHopV004` (`fd on`) and `kHopV004Can` (`fd off`) once each. -The Linux SocketCAN example `hop_can_mode` reads identity and CAN configuration by default. +### Step 2: Switch the device-side mode + +> Note: Device-side `brs` must be `0` before switching to CAN 2.0. With `save_to_flash = false`, the change is volatile and reverts after a power cycle—verify communication before saving to Flash. + +#### Option A: Call `set_can_interface_mode()` in your C++ program (recommended, works with the release package) + +Open the device in its **current** mode, switch, close it, and reopen with the new `o6_protocol`: + +```cpp +#include +#include +#include + +using namespace linkerbot::hand; + +int main() { + try { + HandDeviceConfig config; + config.model = Model::kO6; + config.side = HandSide::kRight; + config.interface_name = "can0"; + config.address = 0x001; + config.o6_protocol = O6Protocol::kHopV004; // Match the device's CURRENT mode: kHopV004 (FD) or kHopV004Can (CAN 2.0) + + HandDevice hand(config); + hand.open(); + + // Target mode: HopCanInterfaceMode::kCan20 or HopCanInterfaceMode::kCanFd + // 2nd argument save_to_flash: false = volatile, true = write to Flash + const auto result = hand.set_can_interface_mode(HopCanInterfaceMode::kCan20, false); + std::cout << "active_wire_is_fd=" << result.active_wire_is_fd << '\n'; + + hand.close(); + } catch (const std::exception &e) { + std::cerr << "Error: " << e.what() << '\n'; + return 1; + } + return 0; +} +``` + +> **Known Linux SocketCAN behavior (CAN 2.0 → CAN FD)**: When connecting with `kHopV004Can` and switching to `kCanFd`, a classic SocketCAN socket cannot receive the immediate FD reply and may throw `CAN FD frame cannot be sent on a classic link`. The switch command has usually already taken effect. Do not resend immediately—reconfigure `can0` with `fd on` and run the read example with `kHopV004` to confirm `mode=canfd`. If you want to persist it to Flash, call `set_can_interface_mode(HopCanInterfaceMode::kCanFd, true)` once from `kHopV004` mode. + +#### Option B: Send raw HOP frames with `cansend` on Linux (no code required) + +If `can-utils` is installed on Linux, you can switch modes directly with `cansend` (especially handy for switching CAN 2.0 back to CAN FD). For default `request_id = 0x001` (`#` sends a CAN 2.0 frame; `##0` sends a CAN FD frame with BRS off): + +```bash +# CAN FD → CAN 2.0 +cansend can0 001##035060101 + +# CAN 2.0 → CAN FD +cansend can0 001#35060102 + +# Optional: save to Flash (match the active format after switching) +cansend can0 001#351E0101 # while in CAN 2.0 +cansend can0 001##0351E0101 # while in CAN FD +``` + +#### Option C (optional, source-tree builds only): `hop_can_mode` CLI example + +> Prebuilt release packages do not include `examples/`. This option applies only if you cloned the `linkerbot-hand-cpp-sdk` source repository, and must be run from the **SDK source root**. ```bash cmake -S . -B build -DLINKERBOT_BUILD_EXAMPLES=ON cmake --build build --target hop_can_mode + +# Read-only query (defaults to CAN FD; append --from-mode can for CAN 2.0) ./build/examples/hop_can_mode can0 o6 right --request-id 0x001 + +# CAN FD → CAN 2.0 (append --save to write to Flash) +./build/examples/hop_can_mode can0 o6 right --from-mode canfd --mode can + +# CAN 2.0 → CAN FD (if it reports a classic-link error, verify with the FD query above) +./build/examples/hop_can_mode can0 o6 right --from-mode can --mode canfd ``` -- `--from-mode canfd|can` selects the connection's frame format and defaults to `canfd`. `can` applies only to O6 HOP. -- `--mode can|canfd` writes the target mode to volatile configuration by default. Add `--save` to send one Flash save command. Power-cycle persistence remains untested. -- Check the actual reply format using the API result's `active_wire_is_fd`. CLI exit code `2` means the register was verified and replies still use the previous format. Recheck after a controlled restart. Once the new format is active, close the original connection, configure the host interface and adapter for the new mode, and open a new connection with the corresponding `o6_protocol`. -- Switching from CAN 2.0 to CAN FD requires a transport that can receive an immediate FD reply. A Classic SocketCAN connection cannot receive it. - The current SDK leaves the Classic frame format implicit on HOP CAN 2.0 requests. FD-enabled SocketCAN and MiniCANFD channels can send those requests as FD frames. - After a timeout, check the device using the target format before attempting another mode write. +If the CLI exits with code `2`, the register was updated but replies still use the old format; verify again after a controlled device restart. + +### Step 3: Update the host interface and code -The candleLightFD run verified common C++ `HandDevice` operations over HOP CAN FD. The MiniCANFD run verified the C++ FD-to-CAN 2.0 switch and used the vendor API for Classic frame reads and writes and the return to FD. -See the [O6 HOP hardware record](../../hardware-acceptance/o6/report.md#o6-hop-2026-11-25). +Once the new device mode is active, align both `can0` and `config.o6_protocol`: + +| Target mode | Host `can0` command | Code setting | +| --- | --- | --- | +| **CAN 2.0** | `sudo ip link set can0 down && sudo ip link set can0 up type can bitrate 1000000 fd off` | `config.o6_protocol = O6Protocol::kHopV004Can;` | +| **CAN FD** | `sudo ip link set can0 down && sudo ip link set can0 up type can bitrate 1000000 dbitrate 5000000 fd on` | `config.o6_protocol = O6Protocol::kHopV004;` | ## Joint order -The SDK reads and sets joint data in the following order. +The SDK reads and sets the 6 joints in this order: -| Number | Joint name | Joint | -| ---: | --- | --- | -| 1 | `thumb_flex` | Thumb flexion | -| 2 | `thumb_abd` | Thumb abduction/adduction | -| 3 | `index` | Index finger | -| 4 | `middle` | Middle finger | -| 5 | `ring` | Ring finger | -| 6 | `pinky` | Little finger | +| Number | Vector index | Joint name | Joint | +| ---: | ---: | --- | --- | +| 1 | `0` | `thumb_flex` | Thumb flexion | +| 2 | `1` | `thumb_abd` | Thumb abduction/adduction | +| 3 | `2` | `index` | Index finger | +| 4 | `3` | `middle` | Middle finger | +| 5 | `4` | `ring` | Ring finger | +| 6 | `5` | `pinky` | Little finger | -Table numbering starts at 1; C++ vector indices are `0..5`. Use `joints[index].name` in the capabilities as the authoritative name. +Use `caps.joints[index].name` from `get_capabilities()` as the authoritative joint name. ## Device identity -`get_device_info(1s)` actively reads and verifies device identity. C++ returns a struct; inspect its fields rather than printing the whole object directly. -`get_identity()` only reads the identity cache for the current connection generation. +`get_device_info(1s)` actively queries and verifies device identity; `get_identity()` returns the cached identity for the current connection. ```cpp const auto info = hand.get_device_info(1s); -std::cout << "Serial number: " << info.serial_number.value_or("Not reported by device") << '\n'; -std::cout << "Product: " << info.product_code.value_or("Not reported by device") << '\n'; +std::cout << "Serial number: " << info.serial_number.value_or("unknown") << '\n'; +std::cout << "Product: " << info.product_code.value_or("unknown") << '\n'; ``` ## Capabilities -`get_capabilities()` sends no control commands. Use the capabilities to confirm whether the current model/protocol supports an operation, -especially across different firmware, protocols, and sensors for the same model. Joint indices start at 0; table numbering starts at 1. +`get_capabilities()` sends no control commands and lets you inspect the supported joint ranges and operations: ```cpp const auto caps = hand.get_capabilities(); -std::cout << caps.serialize() << '\n'; for (const auto &joint : caps.joints) { - std::cout << joint.index << ": " << joint.name << " raw=" - << joint.raw_angle_range.minimum << ".." << joint.raw_angle_range.maximum << '\n'; + std::cout << joint.index << ": " << joint.name + << " raw=" << joint.raw_angle_range.minimum + << ".." << joint.raw_angle_range.maximum << '\n'; } ``` @@ -281,51 +294,72 @@ for (const auto &joint : caps.joints) { ## Angle control -Raw angles range from `0..255`; by default, percentages increase in the same direction as raw values. Determine the mechanical pose from the joint, hand side, and actual angle mapping; -do not simply equate the endpoints of an abduction/adduction or rotation axis with "bent/straight". +Raw angles range from `0..255`, and percentages range from `0..100` (increasing in the same direction by default). Mechanical poses depend on the hand side and joint type—do not equate abduction/rotation endpoints with "bent/straight". ### Reading angles -`AngleSample::raw` is a `vector`; `percent` contains an `optional` for each joint. -Do not replace an unavailable percentage conversion with 0. +```cpp +const auto angles = hand.get_angles(1s); +for (const auto raw : angles.raw) { + std::cout << raw << ' '; +} +std::cout << '\n'; +``` + +`angles.percent` holds a `std::optional` per joint (do not substitute `0` when unavailable): ```cpp -const auto sample = hand.get_angles(1s); -check_sample(sample.meta); -print_values(sample.raw); -for (const auto &percent : sample.percent) { - if (percent) { - std::cout << *percent << ' '; +const auto angles = hand.get_angles(1s); +for (const auto &p : angles.percent) { + if (p) { + std::cout << *p << "% "; } else { - std::cout << "unavailable "; + std::cout << "N/A "; } } std::cout << '\n'; ``` -### Setting raw angles +### Setting raw angles (read → set → read) -`set_angles()` takes 6 `int32_t` values in joint-table order. This example reads the current values and uses them as targets; -in your application, replace them with confirmed targets within the allowed ranges. Control frames are still sent, so the device may move. +`set_angles()` takes 6 `int32_t` values (`0..255`). This example reads the current angles as the starting target (edit `targets[0..5]` as needed), waits for completion, and reads back: ```cpp -const auto sample = hand.get_angles(1s); -check_sample(sample.meta); -std::vector targets(sample.raw.begin(), sample.raw.end()); -wait_command(hand.set_angles(targets)); +const auto before = hand.get_angles(1s); + +std::vector targets(before.raw.begin(), before.raw.end()); +// targets[5] = 200; // Modify a safe target value as needed, e.g. pinky + +const auto cmd = hand.set_angles(targets); +if (!cmd.wait_for(2s)) { + throw std::runtime_error("set_angles timed out"); +} +if (const auto err = cmd.error()) { + std::rethrow_exception(err); +} + +// Optionally sleep briefly for mechanical travel before reading back (#include ) +// std::this_thread::sleep_for(500ms); const auto after = hand.get_angles(1s); -check_sample(after.meta); -print_values(after.raw); +for (const auto raw : after.raw) { + std::cout << raw << ' '; +} +std::cout << '\n'; ``` ### Setting percentage angles -`set_percent_angles()` takes 6 `float` values in the range `0..100`. `50.0F` is only the midpoint of each axis mapping; -it is not a universally validated safe pose. Replace it to suit the actual task. +`set_percent_angles()` takes 6 `float` values (`0..100`). Replace the target values with a safe pose for your task: ```cpp std::vector targets(6, 50.0F); -wait_command(hand.set_percent_angles(targets)); +const auto cmd = hand.set_percent_angles(targets); +if (!cmd.wait_for(2s)) { + throw std::runtime_error("set_percent_angles timed out"); +} +if (const auto err = cmd.error()) { + std::rethrow_exception(err); +} ``` @@ -334,41 +368,58 @@ wait_command(hand.set_percent_angles(targets)); ### Setting speeds -The raw setting range is `0..255`; it is not a confirmed physical rotational speed. +Raw counts in `0..255` (not a confirmed physical rotational speed): ```cpp -wait_command(hand.set_speeds(std::vector(6, 100.0))); +const auto cmd = hand.set_speeds(std::vector(6, 100.0)); +if (!cmd.wait_for(2s)) { + throw std::runtime_error("set_speeds timed out"); +} +if (const auto err = cmd.error()) { + std::rethrow_exception(err); +} ``` ### Reading configured speeds -HOP reads the device register through `get_configured_speeds()`. The original Classic protocol uses the complete speed-write response cached in the current connection, so set the speed first in that connection. -On Classic V1.3.2 firmware, a native `speed.get_blocking()` query may set the device speed to 0. - ```cpp -print_sample(hand.get_configured_speeds(1s)); +const auto speeds = hand.get_configured_speeds(1s); +for (const auto v : speeds.raw) { + std::cout << v << ' '; +} +std::cout << '\n'; ``` +> Note: HOP queries the device register directly. The legacy Classic protocol reads the write-response cache in the current connection, so call `set_speeds()` first. + ## Acceleration settings ### Setting accelerations -`set_accelerations()` takes 6 raw counts. The original Classic protocol accepts `0..254`. HOP accepts `0..255`. +`set_accelerations()` takes 6 raw counts (`0..254` on Classic, where `0` encodes special maximum acceleration; `0..255` on HOP): ```cpp -wait_command(hand.set_accelerations(std::vector(6, 100.0))); +const auto cmd = hand.set_accelerations(std::vector(6, 100.0)); +if (!cmd.wait_for(2s)) { + throw std::runtime_error("set_accelerations timed out"); +} +if (const auto err = cmd.error()) { + std::rethrow_exception(err); +} ``` -The original Classic protocol uses `0` to encode special maximum acceleration. The physical conversion for HOP acceleration remains unverified. - ### Reading configured accelerations -This reads device configuration, not current measured acceleration. +Reads the configured acceleration setting rather than live measured acceleration: ```cpp -print_sample(hand.get_configured_accelerations(1s)); +const auto acc = hand.get_configured_accelerations(1s); +for (const auto v : acc.raw) { + std::cout << v << ' '; +} +std::cout << '\n'; ``` @@ -377,33 +428,61 @@ print_sample(hand.get_configured_accelerations(1s)); ### Reading currents -`get_currents()` reads raw measured-current counts, which differ from current-limit settings. Do not label them as mA without a reliable conversion factor. +`get_currents()` reads raw measured-current counts (distinct from current-limit settings; do not label as mA without a verified scale): ```cpp -print_sample(hand.get_currents(1s)); +const auto currents = hand.get_currents(1s); +for (const auto v : currents.raw) { + std::cout << v << ' '; +} +std::cout << '\n'; ``` ### Reading temperatures -The original Classic protocol declares temperatures in degrees Celsius. HOP capabilities report raw counts. Check the sample validity with either protocol. +Classic protocol reports degrees Celsius; HOP capabilities report raw counts: ```cpp -print_sample(hand.get_temperatures(1s)); +const auto temps = hand.get_temperatures(1s); +for (const auto v : temps.raw) { + std::cout << v << ' '; +} +std::cout << '\n'; ``` ### Reading tactile matrices -Select fields with `get_force(vector{"fn"}, timeout)` and access them through `field("fn")`. -Each optional vector in `raw` corresponds to one finger. `nullopt` means missing data, -and `false` in `valid_values` means an invalid value. The `print_field()` helper above displays this information without filling in zeros or computing sums. +Use `get_force({"fn"}, 1s)` to read five-finger normal-force matrices (Classic defaults to 5 fingers × 10×4; HOP reads shapes from each finger's sensor descriptor). Missing fingers are represented by `std::nullopt`: ```cpp const auto force = hand.get_force(std::vector{"fn"}, 1s); -print_field(force, "fn"); +const auto *fn = force.field("fn"); +if (!fn) { + std::cout << "fn: " << force.status("fn") << '\n'; +} else { + for (size_t finger = 0; finger < fn->raw.size(); ++finger) { + std::cout << "finger " << finger << ": "; + if (!fn->raw[finger]) { + std::cout << "no data\n"; + continue; + } + for (const auto value : *fn->raw[finger]) { + std::cout << value << ' '; + } + std::cout << '\n'; + } +} ``` -The original Classic protocol defaults to 5 fingers with 10×4 points per finger. HOP reads fields and shapes from each finger's sensor descriptor. + + +## Notes and known limitations -For more features, firmware limitations, and physical units, see [Model capabilities](../reference/model-capabilities.md). +- **Command completion semantics**: `cmd.wait_for()` confirms communication dispatch or device acknowledgement only, not physical arrival. A wait timeout neither cancels nor resends the command. For strict `CommandStage` checks (`kAcknowledged`, `kDispatched`, `kSuperseded`, etc.), see the [API guide](../guides/usage.md). +- **Classic V1.3.2 speed query**: Do not call the native `speed.get_blocking()` query on Classic V1.3.2 firmware, as it may reset device speed to `0`; use `HandDevice::get_configured_speeds()` instead. +- **HOP mode switching and adapter boundaries**: + - Current HOP CAN 2.0 requests leave the Classic frame format implicit; if `can0` stays in `fd on`, SocketCAN or MiniCANFD may transmit them as FD frames. Always set `can0` to `fd off` when using `kHopV004Can`. + - Power-cycle persistence after `--save` and full adapter validation coverage are recorded in the [O6 HOP hardware record](../../hardware-acceptance/o6/report.md#o6-hop-2026-11-25). +- **More capabilities and units**: See [Model capabilities](../reference/model-capabilities.md). [Back to the documentation overview](../README.md) diff --git a/docs/zh/README.md b/docs/zh/README.md index 03cb35d..1a1a294 100644 --- a/docs/zh/README.md +++ b/docs/zh/README.md @@ -15,7 +15,7 @@ | 型号 | 教程与支持状态 | | --- | --- | | L6 | [Classic CAN 功能与专有 Manager](tutorials/l6.md);可选 HOP CAN FD 见[协议说明](guides/usage.md#l6-可选-can-fd-协议) | -| O6 | [角度、速度、加速度与传感器](tutorials/o6.md) | +| O6 | [角度、速度、加速度与传感器](tutorials/o6.md);可选 HOP 0.0.4(CAN FD / CAN 2.0)见 [O6 HOP 接入与模式切换](tutorials/o6.md#o6-hop) | | L20 Lite | [十关节控制、配置缓存与触觉](tutorials/l20lite.md) | | L20 | [十六关节控制与传感器](tutorials/l20.md) | | L30 | [CAN FD、使能与十七关节控制](tutorials/l30.md) | diff --git a/docs/zh/connections/manual.md b/docs/zh/connections/manual.md index b93a1ee..1293ba1 100644 --- a/docs/zh/connections/manual.md +++ b/docs/zh/connections/manual.md @@ -7,7 +7,7 @@ | 型号 | `Model` | 关节数 | 默认通信与地址 | | --- | --- | ---: | --- | | L6 | `kL6` | 6 | Classic CAN,左 `0x28`,右 `0x27` | -| O6 | `kO6` | 6 | Classic CAN,左 `0x28`,右 `0x27` | +| O6 | `kO6` | 6 | Classic CAN(左 `0x28`,右 `0x27`);可选 HOP 0.0.4(默认请求 ID `0x001`) | | L20 Lite | `kL20Lite` | 10 | Classic CAN,左 `0x28`,右 `0x27` | | L20 | `kL20` | 16 | Classic CAN,左 `0x28`,右 `0x27` | | L30 | `kL30` | 17 | 扩展 FD,NodeID 默认 1、HostID 默认 0 | @@ -154,9 +154,9 @@ L6 可选 HOP 固件需显式设置 `config.l6_protocol = L6Protocol::kHopV004` 并核对对应地址、速率和能力;不能通过 FD 接口配置推断设备协议。 详见[可选 HOP 接入](../guides/usage.md#l6-可选-can-fd-协议)。 -O6 HOP 固件使用显式手动连接。设备当前使用 CAN FD 时选择 `config.o6_protocol = O6Protocol::kHopV004`, -使用 CAN 2.0 时选择 `O6Protocol::kHopV004Can`,并按实际设置配置 SocketCAN。请求 ID 默认 `0x001`。 -连接示例和设备端模式切换见 [O6 HOP 手动接入](../tutorials/o6.md#o6-hop)。 +O6 HOP 固件使用显式手动连接(默认请求 ID `0x001`):设备当前为 CAN FD 时设置 `config.o6_protocol = O6Protocol::kHopV004`(网卡 `fd on`), +当前为 CAN 2.0 时设置 `O6Protocol::kHopV004Can`(网卡 `fd off`)。 +完整接入示例见 [O6 HOP 手动接入](../tutorials/o6.md#o6-hop),切换设备 CAN 模式见 [切换 HOP 的 CAN 模式](../tutorials/o6.md#hop-can-mode)。 diff --git a/docs/zh/connections/prepare-interface.md b/docs/zh/connections/prepare-interface.md index 2ba2c22..eef19c3 100644 --- a/docs/zh/connections/prepare-interface.md +++ b/docs/zh/connections/prepare-interface.md @@ -22,11 +22,11 @@ if(MSVC) endif() ``` -将应用文件放在 `demo/`,从 SDK 源码根目录执行;`install` 替换为实际 SDK 安装前缀: +将 `CMakeLists.txt` 和 `main.cpp` 放在你的应用目录中,在应用目录下执行构建(将 `/path/to/linkerbot-hand-cpp` 替换为 SDK 安装包解压目录或安装前缀;如已安装到系统目录 `/usr/local`,可省略 `-DCMAKE_PREFIX_PATH`): ```bash -cmake -S demo -B demo/build -DCMAKE_PREFIX_PATH="$PWD/install" -cmake --build demo/build --config Release +cmake -S . -B build -DCMAKE_PREFIX_PATH="/path/to/linkerbot-hand-cpp" +cmake --build build --config Release ``` `HandDevice` 不直接接收 Python 的 transport 参数或字符串型号,C++ 使用 @@ -40,7 +40,7 @@ cmake --build demo/build --config Release ### 经典 CAN -Classic 固件 L6、O6、L20 Lite、L20 使用 1 Mbit/s: +Classic 固件 L6、O6、L20 Lite、L20 以及运行在 CAN 2.0 模式的 O6 HOP(`O6Protocol::kHopV004Can`)使用 1 Mbit/s: ```bash sudo ip link set can0 down @@ -51,7 +51,7 @@ ip -details link show can0 ### CAN FD -L30、O30 使用仲裁速率 1 Mbit/s、数据速率 5 Mbit/s: +L30、O30 以及运行在 CAN FD 模式的 O6 HOP(`O6Protocol::kHopV004`)使用仲裁速率 1 Mbit/s、数据速率 5 Mbit/s: ```bash sudo ip link set can0 down @@ -60,9 +60,8 @@ sudo ip link set can0 up ip -details link show can0 ``` -L30 使用扩展 FD 帧,O30 使用标准 FD 帧、无 BRS;帧格式由型号实现决定。 -L6 默认仍是 Classic CAN。只有设备固件匹配时才显式选择可选 HOP CAN FD 协议; -仅将系统接口设成 FD 不会切换 L6 协议,详见[可选协议](../guides/usage.md#l6-可选-can-fd-协议)。 +L30 使用扩展 FD 帧,O30 和 O6 HOP 使用标准 FD 帧、无 BRS;帧格式由型号与协议配置决定。 +L6 和 O6 默认仍是 Classic CAN。只有设备固件匹配时才显式选择可选 HOP 协议;仅将系统接口设成 FD 不会切换设备协议,详见 [L6 可选协议](../guides/usage.md#l6-可选-can-fd-协议) 和 [O6 HOP 手动接入与模式切换](../tutorials/o6.md#o6-hop)。 ## Windows 与独立适配器后端 diff --git a/docs/zh/reference/model-capabilities.md b/docs/zh/reference/model-capabilities.md index a7d0543..dd94e61 100644 --- a/docs/zh/reference/model-capabilities.md +++ b/docs/zh/reference/model-capabilities.md @@ -175,7 +175,7 @@ Kp 写入为 `0..200`,两个 Kd 为 `0..255`;回复保留设备实际值, | 实时遥测 | 支持角度、电流、温度、故障和五指触觉读取,触觉字段和形状按传感器描述获得 | | CAN 配置 | `get_can_configuration()` 读取接口模式、请求 ID、BRS 和速率。 `set_can_interface_mode()` 写入模式字段 | -数值按原始计数处理,速度、加速度和电流的物理换算尚未确认。接入配置、模式切换和适配器限制见 [O6 HOP 教程](../tutorials/o6.md#o6-hop)。 +数值按原始计数处理,速度、加速度和电流的物理换算尚未确认。接入配置见 [O6 HOP 手动接入](../tutorials/o6.md#o6-hop),模式切换步骤见 [切换 HOP 的 CAN 模式](../tutorials/o6.md#hop-can-mode)。 ## L20 Lite diff --git a/docs/zh/tutorials/o6.md b/docs/zh/tutorials/o6.md index b73aa0b..313b1bd 100644 --- a/docs/zh/tutorials/o6.md +++ b/docs/zh/tutorials/o6.md @@ -1,7 +1,8 @@ # O6 功能文档 -O6 有 6 个关节。SDK 默认使用原有 O6 Classic CAN 协议,支持 HOP 0.0.4 的固件可显式选择 HOP。 -本页以 C++ `HandDevice` 为常用操作入口,示例按当前 C++ SDK 接口编写。 +O6 包含 6 个关节。SDK 默认使用原有 O6 Classic CAN 协议;如果设备刷写的是 **HOP 0.0.4** 固件,需要显式设置 `config.o6_protocol`。 + +本页统一使用 C++ `HandDevice` 演示常用操作。 ## 目录 @@ -15,265 +16,277 @@ O6 有 6 个关节。SDK 默认使用原有 O6 Classic CAN 协议,支持 HOP 0 - [速度控制](#speed-control) - [加速度设置](#acceleration) - [传感器数据读取](#sensor-reading) +- [注意事项与已知限制](#notes) ## 使用方式 -对于使用原有 O6 Classic CAN 协议的固件,先按[准备接口](../connections/prepare-interface.md)配置环境,选择[自动连接](../connections/automatic.md) -或[手动连接](../connections/manual.md)。下面是 Linux SocketCAN 的完整只读程序, -提供本页后续片段使用的 `hand`、chrono 字面量和输出/等待函数。 -Windows 连接时替换设备构造部分,传入已确认的 adapter factory;功能片段保持相同。 +开始前先按 [准备通信接口](../connections/prepare-interface.md) 配置好编译环境和 CAN 接口。 + +### 先对齐三种模式 + +O6 的**设备端当前模式**、**主机网卡配置**和**代码里的 `o6_protocol`** 必须一致,否则 `hand.open()` 会超时报错(`device request deadline expired`): + +| 协议模式 | `config.o6_protocol` | 默认 CAN ID | Linux `can0` 配置 | +| --- | --- | --- | --- | +| Classic(旧固件默认) | `O6Protocol::kClassic`(默认) | 左手 `0x28` / 右手 `0x27` | `bitrate 1000000 fd off` | +| HOP 0.0.4 · CAN FD | `O6Protocol::kHopV004` | 请求 `0x001` / 响应 `0x401` | `bitrate 1000000 dbitrate 5000000 fd on` | +| HOP 0.0.4 · CAN 2.0 | `O6Protocol::kHopV004Can` | 请求 `0x001` / 响应 `0x401` | `bitrate 1000000 fd off` | + +### 最简完整程序(Linux SocketCAN) + +下面的完整示例演示连接 Classic O6 并读取 6 个关节角度(如果是 HOP 固件,按下一节改 `o6_protocol` 和 `address` 即可;Windows 替换 transport factory 即可,功能调用完全相同): ```cpp -#include #include -#include #include #include -#include -#include -#include #include using namespace linkerbot::hand; using namespace std::chrono_literals; -template -void print_values(const Values &values) { - for (const auto value : values) { - std::cout << +value << ' '; - } - std::cout << '\n'; -} - -void check_sample(const SampleMeta &meta) { - if (!meta.valid) { - throw std::runtime_error("样本不可用"); - } - if (meta.stale) { - std::cerr << "样本已超过新鲜度窗口,请按业务要求重新读取\n"; - } -} - -void wait_command(const CommandHandle &command) { - if (!command.wait_for(2s)) { - throw std::runtime_error("等待超时;命令未取消,不自动重发"); - } - if (const auto error = command.error()) { - std::rethrow_exception(error); - } - const auto stage = command.stage(); - if (stage != CommandStage::kAcknowledged && - !(stage == CommandStage::kDispatched && command.ack_expectation() == AckExpectation::kNone)) { - throw std::runtime_error("命令未成功完成,可能已被替换或取消"); - } -} +int main() { + try { + HandDeviceConfig config; + config.model = Model::kO6; + config.side = HandSide::kLeft; // 按实际修改为 kLeft / kRight + config.interface_name = "can0"; -void print_sample(const RawVectorSample &sample) { - check_sample(sample.meta); - print_values(sample.raw); -} + HandDevice hand(config); + hand.open(); -void print_field(const ForceSample &force, const std::string &name) { - const auto *field = force.field(name); - if (!field) { - std::cout << name << ": " << force.status(name) << '\n'; - return; - } - check_sample(field->meta); - for (size_t finger = 0; finger < field->raw.size(); ++finger) { - if (!field->raw[finger]) { - std::cout << "finger " << finger << ": 无数据\n"; - continue; - } - const auto &values = *field->raw[finger]; - for (size_t point = 0; point < values.size(); ++point) { - if (finger < field->valid_values.size() && field->valid_values[finger] && - point < field->valid_values[finger]->size() && !(*field->valid_values[finger])[point]) { - std::cout << "invalid "; - } else { - std::cout << values[point] << ' '; - } + // 下文各功能片段均可直接放在此处(hand.open() 之后、hand.close() 之前) + const auto angles = hand.get_angles(1s); + for (const auto angle : angles.raw) { + std::cout << angle << ' '; } std::cout << '\n'; - } -} -int main() try { - HandDeviceConfig config; - config.model = Model::kO6; - config.side = HandSide::kLeft; // 改为实际侧别 - config.interface_name = "can0"; // 此完整程序使用 Linux SocketCAN - HandDevice hand(config); - std::exception_ptr failure; - try { - hand.open(); - // 将下文所需的功能片段放在这里;不要一次执行整篇所有控制示例。 - const auto angles = hand.get_angles(1s); - check_sample(angles.meta); - print_values(angles.raw); - } catch (...) { - failure = std::current_exception(); - } - try { hand.close(); - } catch (const std::exception &error) { - if (!failure) { - throw; - } - std::cerr << "关闭连接失败:" << error.what() << '\n'; - } - if (failure) { - std::rethrow_exception(failure); + } catch (const std::exception &e) { + std::cerr << "Error: " << e.what() << '\n'; + return 1; } return 0; -} catch (const std::exception &error) { - std::cerr << error.what() << '\n'; - return 1; } ``` -下文普通 C++ 片段分别放到 `hand.open()` 成功之后、`hand.close()` 之前, -并保留这些辅助函数;它们不是独立程序,也不应一次执行全部控制操作。 -专用 Manager 小节另外提供独立程序。 - -统一 setter 和 `enable()` / `disable()` 等离散操作返回 `CommandHandle`。 -`wait_command()` 先等待终结,再检查错误和终态:`kAcknowledged` 或无 ACK 的 `kDispatched` -才按对应协议视为通信完成。被替换、取消或失败都不是成功;等待超时不取消命令,不自动重发。 -机械到位和控制效果需要业务另外验证。 - -样本先检查 `meta.valid`,并按 `meta.stale` 判断是否过期;缓存读数不是实时测量。 -关闭异常时长期应用应保留同一对象安排清理重试,不能直接另开连接。 +> 提示: +> - `HandDevice` 析构函数会自动尝试关闭连接,示例使用单层 `try / catch` 即可打印出错原因。生产环境如需处理关闭失败或重试恢复,见 [API 使用指南](../guides/usage.md)。 +> - 所有 `set_*` 写操作都是异步入队并返回 `CommandHandle`,需要确认发包/应答完成时调用 `cmd.wait_for(2s)` 并检查 `cmd.error()`。 +> - 生产代码读取传感器前建议先检查 `sample.meta.valid`(是否有效)和 `sample.meta.stale`(是否过期)。 ## HOP 0.0.4 手动接入 -HOP 定义设备的寄存器和消息格式,CAN 2.0 与 CAN FD 承载这些消息。根据设备**当前**的协议与帧格式选择 `HandDeviceConfig::o6_protocol`。 -这个配置项只决定 SDK 如何通信。更改设备的帧格式使用[独立的 HOP 模式切换接口](#hop-can-mode)。 +HOP 固件采用手动连接(不走自动扫描),需显式指定左右手、请求 ID(默认 `0x001`,响应 ID 自动为 `request_id | 0x400`)以及与设备当前帧格式匹配的 `o6_protocol`。 -| 配置值 | 帧格式 | 地址 | -| --- | --- | --- | -| `O6Protocol::kClassic`(默认) | 原有 O6 Classic CAN | 左手 `0x28`,右手 `0x27` | -| `O6Protocol::kHopV004` | HOP 0.0.4,CAN FD 标准帧,SDK 发送时关闭 BRS | 请求 ID 默认 `0x001`,响应 ID 为请求 ID 按位或 `0x400` | -| `O6Protocol::kHopV004Can` | HOP 0.0.4,CAN 2.0 标准帧 | 与 HOP CAN FD 使用相同的 ID 规则 | +> `config.o6_protocol` 只决定 **SDK 用哪种帧格式收发**,不会改变灵巧手本身的模式。如需修改设备侧模式,见下一节 [切换 HOP 的 CAN 模式](#hop-can-mode)。 + +### 1. 配置 Linux SocketCAN 网卡 -HOP 使用显式手动连接。根据实际设备指定左右手、请求 ID 和适配器通道,`open()` 会读取设备身份并核对侧别。 -核对 CAN_H 与 CAN_L 的接线及终端匹配。实测右手使用 `0x001/0x401`、标称速率 1 Mbit/s、数据速率 5 Mbit/s、BRS 关闭。 -对于相同设置的 Linux SocketCAN 设备,运行以下命令配置 `can0`。 +按设备当前的 CAN 模式二选一: ```bash +# 设备当前为 CAN FD(1 Mbit/s 仲裁速率 + 5 Mbit/s 数据速率,SDK 发送时关闭 BRS) sudo ip link set can0 down sudo ip link set can0 up type can bitrate 1000000 dbitrate 5000000 fd on -ip -details link show can0 + +# 设备当前为 CAN 2.0(1 Mbit/s,关闭 FD) +sudo ip link set can0 down +sudo ip link set can0 up type can bitrate 1000000 fd off ``` -以下程序只读 CAN 配置与角度。若设备当前运行 HOP CAN 2.0,将协议改为 `kHopV004Can`,并用标称速率和 `fd off` 配置 SocketCAN。 +### 2. 读取 CAN 配置与角度(完整示例) ```cpp +#include #include #include #include -int main() try { - using namespace linkerbot::hand; - HandDeviceConfig config; - config.model = Model::kO6; - config.side = HandSide::kRight; - config.interface_name = "can0"; - config.address = 0x001; - config.o6_protocol = O6Protocol::kHopV004; - - HandDevice hand(config); - hand.open(); - const auto can = hand.get_can_configuration(); - std::cout << "request_id=0x" << std::hex << can.request_id - << " response_id=0x" << can.response_id() << std::dec - << " mode=" << (can.interface_mode == HopCanInterfaceMode::kCanFd ? "canfd" : "can") - << " nominal=" << can.nominal_bitrate << " data=" << can.data_bitrate - << " brs=" << can.brs << '\n'; - const auto angles = hand.get_angles(); - for (const auto angle : angles.raw) { - std::cout << angle << ' '; +using namespace linkerbot::hand; +using namespace std::chrono_literals; + +int main() { + try { + HandDeviceConfig config; + config.model = Model::kO6; + config.side = HandSide::kRight; + config.interface_name = "can0"; + config.address = 0x001; + config.o6_protocol = O6Protocol::kHopV004; // 若设备当前为 CAN 2.0,改为 kHopV004Can + + HandDevice hand(config); + hand.open(); + + const auto can = hand.get_can_configuration(); + std::cout << "request_id=0x" << std::hex << can.request_id + << " response_id=0x" << can.response_id() << std::dec + << " mode=" << (can.interface_mode == HopCanInterfaceMode::kCanFd ? "canfd" : "can") + << " nominal=" << can.nominal_bitrate + << " data=" << can.data_bitrate + << " brs=" << can.brs << '\n'; + + const auto angles = hand.get_angles(1s); + for (const auto angle : angles.raw) { + std::cout << angle << ' '; + } + std::cout << '\n'; + + hand.close(); + } catch (const std::exception &e) { + std::cerr << "Error: " << e.what() << '\n'; + return 1; } - std::cout << '\n'; - hand.close(); - return angles.meta.valid ? 0 : 1; -} catch (const std::exception &error) { - std::cerr << error.what() << '\n'; - return 1; + return 0; } ``` +> **常见超时排查**:如果运行报 `device request deadline expired`,通常是因为**灵巧手当前模式与代码 `o6_protocol` 不一致**(例如代码写了 `kHopV004`,但设备当前在 CAN 2.0 模式),或者 CAN_H / CAN_L 接反。你可以把 `o6_protocol` 临时换成 `kHopV004Can`(并把 `can0` 配成 `fd off`)重跑一次,看哪一种模式能正常打印 `mode=...` 来确认设备当前状态。 + ## 切换 HOP 的 CAN 模式 -`get_can_configuration()` 读取设备的请求 ID、接口模式、BRS、标称速率和数据速率。 -向 `set_can_interface_mode()` 传入 `HopCanInterfaceMode::kCan20` 或 `HopCanInterfaceMode::kCanFd` 可切换设备侧 HOP 接口的帧格式, -对应 MI `0x35` / SI `0x06` 的值 `1` 或 `2`。切到 CAN 2.0 前,设备端 BRS 必须已关闭。 -调用前通过设备的当前模式建立连接。一次调用最多发送一次模式写入。主机接口由操作系统或适配器单独配置。 +HOP 设备侧的 CAN 帧格式由寄存器 `MI 0x35 / SI 0x06` 控制(`1` = CAN 2.0,`2` = CAN FD),保存到 Flash 由 `MI 0x35 / SI 0x1E = 1` 触发。 + +切换完整流程固定为三步:**① 查询当前模式 → ② 切换设备侧模式 → ③ 同步修改主机网卡和代码 `o6_protocol`**。 + +### 第 1 步:查询设备当前模式(只读) + +直接运行上一节的完整示例(调用 `hand.get_can_configuration()`),即可打印出设备当前的 `mode=canfd` 或 `mode=can`,以及 `brs` 和速率。不确定设备当前模式时,分别用 `kHopV004`(`fd on`)和 `kHopV004Can`(`fd off`)各试一次即可。 -Linux SocketCAN 的 `hop_can_mode` 示例可先只读检查身份和当前配置。 +### 第 2 步:切换设备侧模式 + +> 提示:切到 CAN 2.0 前,设备侧 `brs` 必须为 `0`。`save_to_flash = false`(不写 Flash)时仅临时生效,灵巧手断电重启后会恢复 Flash 中的原配置;建议先临时切换并验证通信正常后,再保存到 Flash。 + +#### 方式 A:在你的 C++ 程序中调用 `set_can_interface_mode()`(推荐,安装包即可用) + +先用设备**当前**模式 `open()`,切换完成后 `close()`,再改用新协议重新打开连接: + +```cpp +#include +#include +#include + +using namespace linkerbot::hand; + +int main() { + try { + HandDeviceConfig config; + config.model = Model::kO6; + config.side = HandSide::kRight; + config.interface_name = "can0"; + config.address = 0x001; + config.o6_protocol = O6Protocol::kHopV004; // 按设备「当前」模式填写:FD 用 kHopV004,CAN 2.0 用 kHopV004Can + + HandDevice hand(config); + hand.open(); + + // 目标模式:HopCanInterfaceMode::kCan20 或 HopCanInterfaceMode::kCanFd + // 第 2 个参数 save_to_flash:false = 临时生效,true = 写入 Flash + const auto result = hand.set_can_interface_mode(HopCanInterfaceMode::kCan20, false); + std::cout << "active_wire_is_fd=" << result.active_wire_is_fd << '\n'; + + hand.close(); + } catch (const std::exception &e) { + std::cerr << "Error: " << e.what() << '\n'; + return 1; + } + return 0; +} +``` + +> **Linux SocketCAN 已知现象(CAN 2.0 → CAN FD)**:当以 `kHopV004Can` 连接并切向 `kCanFd` 时,经典 SocketCAN socket 无法接收切换后立即返回的 FD 确认帧,可能抛出 `CAN FD frame cannot be sent on a classic link`,但**切换指令通常已经发出并生效**。此时不要重复切换,直接按 CAN FD 配置(`fd on` + `kHopV004`)运行上一节的读取程序验证即可;确认已为 `mode=canfd` 后,如需写入 Flash,再在 `kHopV004` 下调用一次 `set_can_interface_mode(HopCanInterfaceMode::kCanFd, true)`。 + +#### 方式 B:Linux 下用 `cansend` 直接发原始帧(无需写代码) + +如果你在 Linux 下已安装 `can-utils`,可以直接发原始 HOP 帧切换(尤其适合从 CAN 2.0 快速切回 CAN FD)。以默认 `request_id = 0x001` 为例(`#` 表示 CAN 2.0 帧,`##0` 表示关闭 BRS 的 CAN FD 帧): + +```bash +# 当前 CAN FD → 切到 CAN 2.0 +cansend can0 001##035060101 + +# 当前 CAN 2.0 → 切到 CAN FD +cansend can0 001#35060102 + +# 可选:写入 Flash(按切换后的当前格式二选一) +cansend can0 001#351E0101 # 当前为 CAN 2.0 时 +cansend can0 001##0351E0101 # 当前为 CAN FD 时 +``` + +#### 方式 C(可选,仅源码构建用户):SDK 源码自带的 `hop_can_mode` 工具 + +> 发布安装包不包含 `examples/`,以下仅适用于克隆了 `linkerbot-hand-cpp-sdk` 源码仓库的用户,且必须在 **SDK 源码根目录**执行。 ```bash cmake -S . -B build -DLINKERBOT_BUILD_EXAMPLES=ON cmake --build build --target hop_can_mode + +# 只读查询(默认 CAN FD;查询 CAN 2.0 追加 --from-mode can) ./build/examples/hop_can_mode can0 o6 right --request-id 0x001 + +# CAN FD → CAN 2.0(如需写入 Flash,追加 --save) +./build/examples/hop_can_mode can0 o6 right --from-mode canfd --mode can + +# CAN 2.0 → CAN FD(若报 classic link 提示,直接用上面 FD 只读查询验证) +./build/examples/hop_can_mode can0 o6 right --from-mode can --mode canfd ``` -- `--from-mode canfd|can` 选择连接时的帧格式,默认 `canfd`。`can` 仅适用于 O6 HOP。 -- `--mode can|canfd` 写入目标模式。默认仅改易失配置,`--save` 另发一次 Flash 保存指令。断电保持尚未实测。 -- 以实际回复帧格式为准。API 返回 `active_wire_is_fd`。CLI 返回 `2` 表示寄存器已经核对,回复仍使用旧格式,需在受控重启后复查。新模式生效后,关闭原连接,按新模式配置主机和适配器,再以对应的 `o6_protocol` 新建连接。 -- CAN 2.0→CAN FD 需要适配器能接收切换后立即到达的 FD 回复。经典 SocketCAN 连接无法接收该回复。 - 当前 SDK 的 HOP CAN 2.0 请求缺少显式 Classic 帧标记,配置为 FD 的 SocketCAN 和 MiniCANFD 通道可能把它发成 FD 帧。 - 切换超时时,先按目标模式核对设备的实际状态,再决定是否重试。 +如果退出码为 `2`,表示寄存器已核对但回复仍使用旧帧格式,重启灵巧手后再查询确认。 + +### 第 3 步:切换后同步主机配置 -candleLightFD 已验证 C++ `HandDevice` 的 HOP CAN FD 常用功能。MiniCANFD 已验证 C++ 发起 FD→CAN 2.0 切换, -切换后的经典帧读写及恢复 FD 使用适配器的原生接口。完整组合和验证范围见 [O6 HOP 实机记录](../../hardware-acceptance/o6/report.md#o6-hop-2026-11-25)。 +设备模式生效后,按目标模式同步更新主机 `can0` 和代码中的 `config.o6_protocol`: + +| 目标模式 | 主机 `can0` 命令 | 代码配置 | +| --- | --- | --- | +| **CAN 2.0** | `sudo ip link set can0 down && sudo ip link set can0 up type can bitrate 1000000 fd off` | `config.o6_protocol = O6Protocol::kHopV004Can;` | +| **CAN FD** | `sudo ip link set can0 down && sudo ip link set can0 up type can bitrate 1000000 dbitrate 5000000 fd on` | `config.o6_protocol = O6Protocol::kHopV004;` | ## 关节顺序 -SDK 按以下顺序读取和设置关节数据。 +SDK 按以下顺序读取和设置 6 个关节数据: -| 索引编号 | 关节名称 | 关节 | -| ---: | --- | --- | -| 1 | `thumb_flex` | 拇指弯曲 | -| 2 | `thumb_abd` | 拇指侧摆 | -| 3 | `index` | 食指 | -| 4 | `middle` | 中指 | -| 5 | `ring` | 无名指 | -| 6 | `pinky` | 小指 | +| 序号 | 向量下标 | 关节名称 | 说明 | +| ---: | ---: | --- | --- | +| 1 | `0` | `thumb_flex` | 拇指弯曲 | +| 2 | `1` | `thumb_abd` | 拇指侧摆 | +| 3 | `2` | `index` | 食指 | +| 4 | `3` | `middle` | 中指 | +| 5 | `4` | `ring` | 无名指 | +| 6 | `5` | `pinky` | 小指 | -表格序号从 1 开始;C++ 向量下标为 `0..5`,以能力表 `joints[index].name` 为准。 +以能力表 `caps.joints[index].name` 为准。 ## 身份识别 -`get_device_info(1s)` 主动读取并核验身份;C++ 返回结构体,按字段查看而不是直接打印整个对象。 -`get_identity()` 只读取当前连接代的身份缓存。 +`get_device_info(1s)` 主动向设备读取并核验身份;`get_identity()` 只返回当前连接缓存的身份信息。 ```cpp const auto info = hand.get_device_info(1s); -std::cout << "序列号:" << info.serial_number.value_or("设备未报告") << '\n'; -std::cout << "产品:" << info.product_code.value_or("设备未报告") << '\n'; +std::cout << "序列号: " << info.serial_number.value_or("未知") << '\n'; +std::cout << "产品码: " << info.product_code.value_or("未知") << '\n'; ``` ## 能力查询 -`get_capabilities()` 不发送控制命令。用能力表确认当前型号/协议是否支持操作, -尤其是同一型号的不同固件、协议和传感器。关节下标从 0 开始;下表序号从 1 开始。 +`get_capabilities()` 不发送控制命令,可用于确认当前型号与协议支持的关节范围和功能: ```cpp const auto caps = hand.get_capabilities(); -std::cout << caps.serialize() << '\n'; for (const auto &joint : caps.joints) { - std::cout << joint.index << ": " << joint.name << " raw=" - << joint.raw_angle_range.minimum << ".." << joint.raw_angle_range.maximum << '\n'; + std::cout << joint.index << ": " << joint.name + << " raw=" << joint.raw_angle_range.minimum + << ".." << joint.raw_angle_range.maximum << '\n'; } ``` @@ -281,51 +294,72 @@ for (const auto &joint : caps.joints) { ## 角度控制 -原始角度为 `0..255`,默认百分比与原始值同向。具体机械姿态按关节、侧别及实际角度映射判断, -不能把侧摆或旋转轴的两个端点简单等同于“弯曲/伸直”。 +原始角度范围为 `0..255`,百分比范围为 `0..100`(默认与原始值同向)。具体机械姿态与左右手及关节类型相关,不能把侧摆轴的两个端点简单等同于“弯曲/伸直”。 ### 角度读取 -`AngleSample::raw` 是 `vector`;`percent` 是逐关节的 `optional`, -无法换算的百分比不能补成 0。 +```cpp +const auto angles = hand.get_angles(1s); +for (const auto raw : angles.raw) { + std::cout << raw << ' '; +} +std::cout << '\n'; +``` + +`angles.percent` 为逐关节的 `std::optional`,部分配置下可能为空(不可用时不要自行补 `0`): ```cpp -const auto sample = hand.get_angles(1s); -check_sample(sample.meta); -print_values(sample.raw); -for (const auto &percent : sample.percent) { - if (percent) { - std::cout << *percent << ' '; +const auto angles = hand.get_angles(1s); +for (const auto &p : angles.percent) { + if (p) { + std::cout << *p << "% "; } else { - std::cout << "unavailable "; + std::cout << "N/A "; } } std::cout << '\n'; ``` -### 原始角度设置 +### 原始角度设置(读 → 设 → 读) -`set_angles()` 接收 6 个 `int32_t`,按关节表顺序排列。下面读取当前值作为示例目标, -实际业务中替换为已确认且在范围内的目标;仍会发送控制帧,不保证设备不会运动。 +`set_angles()` 接收 6 个 `int32_t`(范围 `0..255`)。下面示例先读当前角度作为目标值(按需修改 `targets[0..5]`),等待命令完成后再回读: ```cpp -const auto sample = hand.get_angles(1s); -check_sample(sample.meta); -std::vector targets(sample.raw.begin(), sample.raw.end()); -wait_command(hand.set_angles(targets)); +const auto before = hand.get_angles(1s); + +std::vector targets(before.raw.begin(), before.raw.end()); +// targets[5] = 200; // 按需修改安全范围内的目标值,例如小指 + +const auto cmd = hand.set_angles(targets); +if (!cmd.wait_for(2s)) { + throw std::runtime_error("set_angles 等待超时"); +} +if (const auto err = cmd.error()) { + std::rethrow_exception(err); +} + +// 如需等待手指物理到位后再读,可短暂休眠(需 #include ) +// std::this_thread::sleep_for(500ms); const auto after = hand.get_angles(1s); -check_sample(after.meta); -print_values(after.raw); +for (const auto raw : after.raw) { + std::cout << raw << ' '; +} +std::cout << '\n'; ``` ### 百分比角度设置 -`set_percent_angles()` 接收 6 个 `float`,范围 `0..100`。`50.0F` 仅表示各轴映射中点, -不是经过验证的通用安全姿态;应按实际任务替换。 +`set_percent_angles()` 接收 6 个 `float`(范围 `0..100`),请按实际安全姿态设置目标: ```cpp std::vector targets(6, 50.0F); -wait_command(hand.set_percent_angles(targets)); +const auto cmd = hand.set_percent_angles(targets); +if (!cmd.wait_for(2s)) { + throw std::runtime_error("set_percent_angles 等待超时"); +} +if (const auto err = cmd.error()) { + std::rethrow_exception(err); +} ``` @@ -334,41 +368,58 @@ wait_command(hand.set_percent_angles(targets)); ### 速度设置 -原始设置范围为 `0..255`,不是已确认的物理转速。 +原始范围 `0..255`(原始计数,非物理转速): ```cpp -wait_command(hand.set_speeds(std::vector(6, 100.0))); +const auto cmd = hand.set_speeds(std::vector(6, 100.0)); +if (!cmd.wait_for(2s)) { + throw std::runtime_error("set_speeds 等待超时"); +} +if (const auto err = cmd.error()) { + std::rethrow_exception(err); +} ``` ### 速度配置读取 -HOP 的 `get_configured_speeds()` 查询设备寄存器。原有 Classic 协议读取本次连接中完整速度写回复的缓存,须先在同一连接中设置速度。 -Classic V1.3.2 的原生 `speed.get_blocking()` 查询可能将设备速度改为 0。 - ```cpp -print_sample(hand.get_configured_speeds(1s)); +const auto speeds = hand.get_configured_speeds(1s); +for (const auto v : speeds.raw) { + std::cout << v << ' '; +} +std::cout << '\n'; ``` +> 说明:HOP 直接查询设备寄存器;原有 Classic 协议读取本次连接内的写回复缓存(首次读取前需先调用一次 `set_speeds()`)。 + ## 加速度设置 ### 加速度设置 -`set_accelerations()` 接收 6 个原始计数。原有 Classic 协议范围为 `0..254`,HOP 为 `0..255`。 +`set_accelerations()` 接收 6 个原始计数(原有 Classic 为 `0..254`,其中 `0` 表示特殊最大加速度;HOP 为 `0..255`): ```cpp -wait_command(hand.set_accelerations(std::vector(6, 100.0))); +const auto cmd = hand.set_accelerations(std::vector(6, 100.0)); +if (!cmd.wait_for(2s)) { + throw std::runtime_error("set_accelerations 等待超时"); +} +if (const auto err = cmd.error()) { + std::rethrow_exception(err); +} ``` -原有 Classic 协议用 `0` 表示特殊最大加速度。HOP 的物理加速度换算尚未确认。 - ### 加速度配置读取 -此读取为设备配置查询,不是当前实测加速度。 +读取的是设备配置的加速度值,而非实时测量加速度: ```cpp -print_sample(hand.get_configured_accelerations(1s)); +const auto acc = hand.get_configured_accelerations(1s); +for (const auto v : acc.raw) { + std::cout << v << ' '; +} +std::cout << '\n'; ``` @@ -377,33 +428,61 @@ print_sample(hand.get_configured_accelerations(1s)); ### 电流读取 -`get_currents()` 读取实际电流原始计数,和电流上限设置不同;没有可靠比例时不标成 mA。 +`get_currents()` 返回实时电流原始计数(区别于电流上限配置,无可靠比例时不要标成 mA): ```cpp -print_sample(hand.get_currents(1s)); +const auto currents = hand.get_currents(1s); +for (const auto v : currents.raw) { + std::cout << v << ' '; +} +std::cout << '\n'; ``` ### 温度读取 -原有 Classic 协议的温度单位为摄氏度。HOP 能力表提供原始计数。两种协议都应检查样本有效性。 +原有 Classic 协议单位为摄氏度(°C),HOP 能力表返回原始计数: ```cpp -print_sample(hand.get_temperatures(1s)); +const auto temps = hand.get_temperatures(1s); +for (const auto v : temps.raw) { + std::cout << v << ' '; +} +std::cout << '\n'; ``` ### 触觉点阵读取 -用 `get_force(vector{"fn"}, timeout)` 选择字段,并通过 `field("fn")` 读取。 -`raw` 中每个可选向量对应一个手指,`nullopt` 表示缺失, -`valid_values` 中的 `false` 表示该值无效。前置函数 `print_field()` 按这些信息显示,不补零、不自行求和。 +使用 `get_force({"fn"}, 1s)` 读取五指法向触觉点阵(Classic 默认 5 指 × 10×4;HOP 按各指传感器描述读取)。缺失手指以 `std::nullopt` 表示: ```cpp const auto force = hand.get_force(std::vector{"fn"}, 1s); -print_field(force, "fn"); +const auto *fn = force.field("fn"); +if (!fn) { + std::cout << "fn: " << force.status("fn") << '\n'; +} else { + for (size_t finger = 0; finger < fn->raw.size(); ++finger) { + std::cout << "finger " << finger << ": "; + if (!fn->raw[finger]) { + std::cout << "无数据\n"; + continue; + } + for (const auto value : *fn->raw[finger]) { + std::cout << value << ' '; + } + std::cout << '\n'; + } +} ``` -原有 Classic 协议的默认点阵形状为 5 个手指,每指 10×4。HOP 的字段和形状按各指传感器描述读取。 + + +## 注意事项与已知限制 -更多功能、固件限制和物理单位说明见[各型号能力说明](../reference/model-capabilities.md)。 +- **命令完成语义**:`cmd.wait_for()` 仅表示通信发送或收到设备应答,不代表机械手指已运动到位;等待超时不会取消或自动重发命令。如需严格区分 `kAcknowledged` / `kDispatched` / `kSuperseded` 等终态,见 [API 使用指南](../guides/usage.md)。 +- **Classic V1.3.2 速度查询**:不要直接调用底层原生 `speed.get_blocking()`,该请求可能把设备速度改写为 `0`;请使用统一的 `HandDevice::get_configured_speeds()`。 +- **HOP 模式切换与适配器边界**: + - 当前 SDK 的 HOP CAN 2.0 请求未显式标记 Classic 帧,若 `can0` 仍保持 `fd on`,SocketCAN 或 MiniCANFD 可能将其按 FD 帧发送;使用 `kHopV004Can` 时请将 `can0` 设为 `fd off`。 + - `--save` 写入 Flash 后的断电保持效果及更多适配器实测范围见 [O6 HOP 实机记录](../../hardware-acceptance/o6/report.md#o6-hop-2026-11-25)。 +- **更多能力与单位说明**:见 [各型号能力说明](../reference/model-capabilities.md)。 [返回文档总览](../README.md)