Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions docs/API-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,26 @@ LinkerHandApi(const LINKER_HAND &handModel, const HAND_TYPE &handType, const COM
**返回值**

```cpp
LinkerHandApi(const LINKER_HAND &handModel, const HAND_TYPE &handType,
const std::string canChannel, const int baudrate);
```

**功能描述**
创建并初始化 LinkerHand API 实例。

**参数说明**
- `handModel` (LINKER_HAND): 机械手型号
- 可选值: `LINKER_HAND::O6`, `LINKER_HAND::L6`, `LINKER_HAND::L7`, `LINKER_HAND::L10`, `LINKER_HAND::L20`, `LINKER_HAND::L21`, `LINKER_HAND::L25`
- `handType` (HAND_TYPE): 机械手类型
- `HAND_TYPE::LEFT` - 左手
- `HAND_TYPE::RIGHT` - 右手
- `canChannel` (std::string): can 通道名称
- `baudrate` (int): can 波特率

**返回值**

**使用示例**
```cpp
#include "LinkerHandApi.h"
Expand All @@ -91,6 +111,31 @@ int main() {
}
```

```cpp
#include "LinkerHandApi.h"

int main() {

// 调用API接口
LinkerHandApi hand(LINKER_HAND::O6, HAND_TYPE::LEFT, "can0", 115200);

// 获取版本信息
std::cout << hand.getVersion() << std::endl;

// 四指握拳
std::vector<uint8_t> fist_pose = {255, 255, 0, 0, 0, 0};
hand.fingerMove(fist_pose);
std::this_thread::sleep_for(std::chrono::seconds(1));

// 四指张开
std::vector<uint8_t> open_pose = {255, 255, 255, 255, 255, 255};
hand.fingerMove(open_pose);
std::this_thread::sleep_for(std::chrono::seconds(1));

return 0;
}
```

**注意事项**
- 构造函数会自动初始化通信接口
- 确保在创建实例前,通信接口已正确配置(如 CAN 总线已启动、ModBus 端口已配置、EtherCAT 网络已初始化)
Expand Down
2 changes: 1 addition & 1 deletion docs/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ sudo modprobe can_raw
sudo modprobe vcan # 虚拟 CAN(用于测试)

# 配置 CAN 接口
sudo ip link set can0 type can bitrate 500000
sudo ip link set can0 type can bitrate 1000000
sudo ip link set can0 up

# 查看 CAN 接口状态
Expand Down
13 changes: 9 additions & 4 deletions include/CanBusFactory.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/*
* @Author: liangshaoteng liangshaoteng2012@163.com
* @Date: 2026-01-29 17:01:44
* @LastEditors: liangshaoteng liangshaoteng2012@163.com
* @LastEditTime: 2026-03-09 13:19:16
* @FilePath: /linkerhand/include/CanBusFactory.h
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
#ifndef LINKERHAND_CAN_BUS_FACTORY_H
#define LINKERHAND_CAN_BUS_FACTORY_H

Expand Down Expand Up @@ -34,10 +42,7 @@ namespace communication {
return std::make_unique<linkerhand::communication::PCANBus>(channel, baudrate, linkerHand);

#else
// Linux/Unix 平台
if (interfaceOrChannel == "can0" || interfaceOrChannel == "can1") {
return std::make_unique<linkerhand::communication::CanBus>(interfaceOrChannel, bitrate, linkerHand);
}
return std::make_unique<linkerhand::communication::CanBus>(interfaceOrChannel, bitrate, linkerHand);

#if USE_ETHERCAT
else if (interfaceOrChannel == "ethercat") {
Expand Down
71 changes: 71 additions & 0 deletions include/HandFactory.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#ifndef LINKERHAND_HAND_FACTORY_H
#define LINKERHAND_HAND_FACTORY_H

#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>

#include "IHand.h"
#include "LinkerHandL6.h"
#include "LinkerHandL7.h"
Expand All @@ -10,6 +15,8 @@
#include "ModbusLinkerHandL10.h"
#include "Common.h"



namespace linkerhand {
namespace factory {

Expand Down Expand Up @@ -100,6 +107,70 @@ class HandFactory {

return nullptr;
}


static std::unique_ptr<hand::IHand> createHand(LINKER_HAND type, uint32_t handId, const std::string canChannel, const int baudrate) {

if (handId != static_cast<uint32_t>(LEFT) &&
handId != static_cast<uint32_t>(RIGHT))
{
throw std::invalid_argument("Unsupported hand type");
}

if (containsIgnoreCase(canChannel, "can")) {
switch (type) {
case O6:
return std::unique_ptr<hand::IHand>(std::make_unique<hand::L6Hand>(handId, canChannel, baudrate));
break;
case L6:
return std::unique_ptr<hand::IHand>(std::make_unique<hand::L6Hand>(handId, canChannel, baudrate));
break;
case L7:
return std::unique_ptr<hand::IHand>(std::make_unique<hand::L7Hand>(handId, canChannel, baudrate));
break;
case L10:
return std::unique_ptr<hand::IHand>(std::make_unique<hand::L10Hand>(handId, canChannel, baudrate));
break;
case L20:
return std::unique_ptr<hand::IHand>(std::make_unique<hand::L20Hand>(handId, canChannel, baudrate));
break;
case L21:
return std::unique_ptr<hand::IHand>(std::make_unique<hand::L25Hand>(handId, canChannel, baudrate, 1));
break;
case L25:
return std::unique_ptr<hand::IHand>(std::make_unique<hand::L25Hand>(handId, canChannel, baudrate, 0));
break;
default:
throw std::invalid_argument("Unknown hand type");
}
} else if (canChannel == "modbus") {
#if USE_RMAN
switch (type) {
case L10:
return std::unique_ptr<hand::IHand>(std::make_unique<hand::ModbusL10Hand>(handId));
default:
throw std::invalid_argument("Unknown hand type");
break;
}
#else
throw std::runtime_error("ModBus support is disabled (USE_RMAN=0)");
#endif
}

return nullptr;
}

private:

static std::string toLower(const std::string& str) {
std::string result = str;
std::transform(result.begin(), result.end(), result.begin(), ::tolower);
return result;
}

static bool containsIgnoreCase(const std::string& str, const std::string& target) {
return toLower(str).find(toLower(target)) != std::string::npos;
}
};

} // namespace factory
Expand Down
2 changes: 2 additions & 0 deletions include/LinkerHandApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class LinkerHandApi
*/
LinkerHandApi(const LINKER_HAND &handModel, const HAND_TYPE &handType,
const COMM_TYPE commType = COMM_CAN_0);
LinkerHandApi(const LINKER_HAND &handModel, const HAND_TYPE &handType,
const std::string canChannel, const int baudrate);
~LinkerHandApi();

// 设置关节位置
Expand Down
Binary file modified lib/aarch64/liblinkerhand_cpp_sdk.so.1.5.8
Binary file not shown.
Binary file modified lib/x86_64/liblinkerhand_cpp_sdk.so.1.5.8
Binary file not shown.
6 changes: 3 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
int main() {

// 调用API接口
LinkerHandApi hand(LINKER_HAND::L10, HAND_TYPE::LEFT);
LinkerHandApi hand(LINKER_HAND::O6, HAND_TYPE::LEFT, "can0", 115200);

// 获取版本信息
std::cout << hand.getVersion() << std::endl;

// 握拳
std::vector<uint8_t> fist_pose = {101, 60, 0, 0, 0, 0, 255, 255, 255, 51};
std::vector<uint8_t> fist_pose = {255, 255, 0, 0, 0, 0};
hand.fingerMove(fist_pose);
std::this_thread::sleep_for(std::chrono::seconds(1));

// 张开
std::vector<uint8_t> open_pose = {255, 104, 255, 255, 255, 255, 255, 255, 255, 71};
std::vector<uint8_t> open_pose = {255, 255, 255, 255, 255, 255};
hand.fingerMove(open_pose);
std::this_thread::sleep_for(std::chrono::seconds(1));

Expand Down