Skip to content

Commit 9471a45

Browse files
committed
船新版本
0 parents  commit 9471a45

28 files changed

+1614
-0
lines changed

.clang-format

Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
---
2+
Language: Cpp
3+
BasedOnStyle: LLVM
4+
AccessModifierOffset: -2
5+
AlignAfterOpenBracket: Align
6+
AlignArrayOfStructures: None
7+
AlignConsecutiveAssignments:
8+
Enabled: false
9+
AcrossEmptyLines: false
10+
AcrossComments: false
11+
AlignCompound: false
12+
AlignFunctionPointers: false
13+
PadOperators: true
14+
AlignConsecutiveBitFields:
15+
Enabled: false
16+
AcrossEmptyLines: false
17+
AcrossComments: false
18+
AlignCompound: false
19+
AlignFunctionPointers: false
20+
PadOperators: false
21+
AlignConsecutiveDeclarations:
22+
Enabled: false
23+
AcrossEmptyLines: false
24+
AcrossComments: false
25+
AlignCompound: false
26+
AlignFunctionPointers: false
27+
PadOperators: false
28+
AlignConsecutiveMacros:
29+
Enabled: false
30+
AcrossEmptyLines: false
31+
AcrossComments: false
32+
AlignCompound: false
33+
AlignFunctionPointers: false
34+
PadOperators: false
35+
AlignConsecutiveShortCaseStatements:
36+
Enabled: false
37+
AcrossEmptyLines: false
38+
AcrossComments: false
39+
AlignCaseColons: false
40+
AlignEscapedNewlines: Right
41+
AlignOperands: Align
42+
AlignTrailingComments:
43+
Kind: Always
44+
OverEmptyLines: 0
45+
AllowAllArgumentsOnNextLine: true
46+
AllowAllParametersOfDeclarationOnNextLine: true
47+
AllowBreakBeforeNoexceptSpecifier: Never
48+
AllowShortBlocksOnASingleLine: Never
49+
AllowShortCaseLabelsOnASingleLine: false
50+
AllowShortCompoundRequirementOnASingleLine: true
51+
AllowShortEnumsOnASingleLine: true
52+
AllowShortFunctionsOnASingleLine: All
53+
AllowShortIfStatementsOnASingleLine: Never
54+
AllowShortLambdasOnASingleLine: All
55+
AllowShortLoopsOnASingleLine: false
56+
AlwaysBreakAfterDefinitionReturnType: None
57+
AlwaysBreakAfterReturnType: None
58+
AlwaysBreakBeforeMultilineStrings: false
59+
AlwaysBreakTemplateDeclarations: MultiLine
60+
AttributeMacros:
61+
- __capability
62+
BinPackArguments: true
63+
BinPackParameters: true
64+
BitFieldColonSpacing: Both
65+
BraceWrapping:
66+
AfterCaseLabel: false
67+
AfterClass: false
68+
AfterControlStatement: Never
69+
AfterEnum: false
70+
AfterExternBlock: false
71+
AfterFunction: false
72+
AfterNamespace: false
73+
AfterObjCDeclaration: false
74+
AfterStruct: false
75+
AfterUnion: false
76+
BeforeCatch: false
77+
BeforeElse: false
78+
BeforeLambdaBody: false
79+
BeforeWhile: false
80+
IndentBraces: false
81+
SplitEmptyFunction: true
82+
SplitEmptyRecord: true
83+
SplitEmptyNamespace: true
84+
BreakAdjacentStringLiterals: true
85+
BreakAfterAttributes: Leave
86+
BreakAfterJavaFieldAnnotations: false
87+
BreakArrays: true
88+
BreakBeforeBinaryOperators: None
89+
BreakBeforeConceptDeclarations: Always
90+
BreakBeforeBraces: Attach
91+
BreakBeforeInlineASMColon: OnlyMultiline
92+
BreakBeforeTernaryOperators: true
93+
BreakConstructorInitializers: BeforeColon
94+
BreakInheritanceList: BeforeColon
95+
BreakStringLiterals: true
96+
ColumnLimit: 80
97+
CommentPragmas: '^ IWYU pragma:'
98+
CompactNamespaces: false
99+
ConstructorInitializerIndentWidth: 4
100+
ContinuationIndentWidth: 4
101+
Cpp11BracedListStyle: true
102+
DerivePointerAlignment: false
103+
DisableFormat: false
104+
EmptyLineAfterAccessModifier: Never
105+
EmptyLineBeforeAccessModifier: LogicalBlock
106+
ExperimentalAutoDetectBinPacking: false
107+
FixNamespaceComments: true
108+
ForEachMacros:
109+
- foreach
110+
- Q_FOREACH
111+
- BOOST_FOREACH
112+
IfMacros:
113+
- KJ_IF_MAYBE
114+
IncludeBlocks: Preserve
115+
IncludeCategories:
116+
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
117+
Priority: 2
118+
SortPriority: 0
119+
CaseSensitive: false
120+
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
121+
Priority: 3
122+
SortPriority: 0
123+
CaseSensitive: false
124+
- Regex: '.*'
125+
Priority: 1
126+
SortPriority: 0
127+
CaseSensitive: false
128+
IncludeIsMainRegex: '(Test)?$'
129+
IncludeIsMainSourceRegex: ''
130+
IndentAccessModifiers: false
131+
IndentCaseBlocks: false
132+
IndentCaseLabels: false
133+
IndentExternBlock: AfterExternBlock
134+
IndentGotoLabels: true
135+
IndentPPDirectives: None
136+
IndentRequiresClause: true
137+
IndentWidth: 2
138+
IndentWrappedFunctionNames: false
139+
InsertBraces: false
140+
InsertNewlineAtEOF: false
141+
InsertTrailingCommas: None
142+
IntegerLiteralSeparator:
143+
Binary: 0
144+
BinaryMinDigits: 0
145+
Decimal: 0
146+
DecimalMinDigits: 0
147+
Hex: 0
148+
HexMinDigits: 0
149+
JavaScriptQuotes: Leave
150+
JavaScriptWrapImports: true
151+
KeepEmptyLinesAtTheStartOfBlocks: true
152+
KeepEmptyLinesAtEOF: false
153+
LambdaBodyIndentation: Signature
154+
LineEnding: DeriveLF
155+
MacroBlockBegin: ''
156+
MacroBlockEnd: ''
157+
MaxEmptyLinesToKeep: 1
158+
NamespaceIndentation: None
159+
ObjCBinPackProtocolList: Auto
160+
ObjCBlockIndentWidth: 2
161+
ObjCBreakBeforeNestedBlockParam: true
162+
ObjCSpaceAfterProperty: false
163+
ObjCSpaceBeforeProtocolList: true
164+
PackConstructorInitializers: BinPack
165+
PenaltyBreakAssignment: 2
166+
PenaltyBreakBeforeFirstCallParameter: 19
167+
PenaltyBreakComment: 300
168+
PenaltyBreakFirstLessLess: 120
169+
PenaltyBreakOpenParenthesis: 0
170+
PenaltyBreakScopeResolution: 500
171+
PenaltyBreakString: 1000
172+
PenaltyBreakTemplateDeclaration: 10
173+
PenaltyExcessCharacter: 1000000
174+
PenaltyIndentedWhitespace: 0
175+
PenaltyReturnTypeOnItsOwnLine: 60
176+
PointerAlignment: Right
177+
PPIndentWidth: -1
178+
QualifierAlignment: Leave
179+
ReferenceAlignment: Pointer
180+
ReflowComments: true
181+
RemoveBracesLLVM: false
182+
RemoveParentheses: Leave
183+
RemoveSemicolon: false
184+
RequiresClausePosition: OwnLine
185+
RequiresExpressionIndentation: OuterScope
186+
SeparateDefinitionBlocks: Leave
187+
ShortNamespaceLines: 1
188+
SkipMacroDefinitionBody: false
189+
SortIncludes: CaseSensitive
190+
SortJavaStaticImport: Before
191+
SortUsingDeclarations: LexicographicNumeric
192+
SpaceAfterCStyleCast: false
193+
SpaceAfterLogicalNot: false
194+
SpaceAfterTemplateKeyword: true
195+
SpaceAroundPointerQualifiers: Default
196+
SpaceBeforeAssignmentOperators: true
197+
SpaceBeforeCaseColon: false
198+
SpaceBeforeCpp11BracedList: false
199+
SpaceBeforeCtorInitializerColon: true
200+
SpaceBeforeInheritanceColon: true
201+
SpaceBeforeJsonColon: false
202+
SpaceBeforeParens: ControlStatements
203+
SpaceBeforeParensOptions:
204+
AfterControlStatements: true
205+
AfterForeachMacros: true
206+
AfterFunctionDefinitionName: false
207+
AfterFunctionDeclarationName: false
208+
AfterIfMacros: true
209+
AfterOverloadedOperator: false
210+
AfterPlacementOperator: true
211+
AfterRequiresInClause: false
212+
AfterRequiresInExpression: false
213+
BeforeNonEmptyParentheses: false
214+
SpaceBeforeRangeBasedForLoopColon: true
215+
SpaceBeforeSquareBrackets: false
216+
SpaceInEmptyBlock: false
217+
SpacesBeforeTrailingComments: 1
218+
SpacesInAngles: Never
219+
SpacesInContainerLiterals: true
220+
SpacesInLineCommentPrefix:
221+
Minimum: 1
222+
Maximum: -1
223+
SpacesInParens: Never
224+
SpacesInParensOptions:
225+
InCStyleCasts: false
226+
InConditionalStatements: false
227+
InEmptyParentheses: false
228+
Other: false
229+
SpacesInSquareBrackets: false
230+
Standard: Latest
231+
StatementAttributeLikeMacros:
232+
- Q_EMIT
233+
StatementMacros:
234+
- Q_UNUSED
235+
- QT_REQUIRE_VERSION
236+
TabWidth: 8
237+
UseTab: Never
238+
VerilogBreakBetweenInstancePorts: true
239+
WhitespaceSensitiveMacros:
240+
- BOOST_PP_STRINGIZE
241+
- CF_SWIFT_NAME
242+
- NS_SWIFT_NAME
243+
- PP_STRINGIZE
244+
- STRINGIZE
245+
...
246+

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
**/build
2+
.vscode
3+
4+

CMakeLists.txt

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# 指定CMake的最低版本要求
2+
cmake_minimum_required(VERSION 3.10)
3+
4+
# 定义项目名称和使用的编程语言
5+
project(D5RC VERSION 0.2)
6+
7+
# 设置C++标准
8+
set(CMAKE_CXX_STANDARD 11)
9+
set(CMAKE_CXX_STANDARD_REQUIRED True)
10+
11+
add_subdirectory(lib/RMD)
12+
add_subdirectory(lib/Nator)
13+
add_library(D5Robot SHARED src/D5Robot.cpp src/DllApi.cpp)
14+
target_include_directories(D5Robot PUBLIC "${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/include" "${PROJECT_SOURCE_DIR}/lib/RMD" "${PROJECT_SOURCE_DIR}/lib/Nator")
15+
target_link_libraries(D5Robot PUBLIC RMDMotor)
16+
target_link_libraries(D5Robot PUBLIC NatorMotor)
17+
target_compile_definitions(D5Robot PUBLIC "D5R_EXPORTS")
18+
19+
add_executable(test test.cpp)
20+
target_link_libraries(test D5Robot)
21+
22+
23+
24+
# 包含头文件目录
25+
# include_directories(include)
26+
27+
# 将子目录下的CMakeLists.txt文件包括到当前的构建中
28+
29+
# 链接库 SHARED 共享库
30+
# add_library(DOF5RobotControl SHARED DOF5RobotControl.cpp)
31+
32+
# 设置包含目录 确保编译时可以找到头文件
33+
# target_include_directories(DOF5RobotControl PUBLIC "${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/lib/RMDControl" "${PROJECT_SOURCE_DIR}/lib/NatorControl")
34+
35+
# target_link_libraries(DOF5RobotControl PUBLIC RMDControl)
36+
# target_link_libraries(DOF5RobotControl PUBLIC NatorControl)
37+
38+
# 为指定目标添加预处理宏定义
39+
# target_compile_definitions(DOF5RobotControl PRIVATE "D5R_EXPORTS")
40+
41+
# 定义可执行文件及其源文件
42+
# add_executable(D5R_Main main.cpp)
43+
44+
# 链接库到可执行文件
45+
# target_include_directories(D5R_Main PUBLIC "${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/lib/RMDControl" "${PROJECT_SOURCE_DIR}/lib/NatorControl")
46+
47+
# target_link_libraries(D5R_Main PUBLIC RMDControl)
48+
# target_link_libraries(D5R_Main PUBLIC NatorControl)
49+
# target_link_libraries(D5R_Main PUBLIC DOF5RobotControl)
50+
51+
# 启用测试
52+
# enable_testing()
53+
54+
# 定义测试用例
55+
# add_test(NAME MyTest COMMAND MyExecutable)
56+
57+
# 设置安装规则
58+
# install(TARGETS MyExecutable RUNTIME DESTINATION bin)
59+
# install(FILES datafile.txt DESTINATION share/data)
60+
61+
# 设置包信息
62+
# set(CPACK_PACKAGE_NAME "DOF5RobotControl")
63+
# set(CPACK_PACKAGE_VERSION "${MyProject_VERSION}")
64+
# set(CPACK_PACKAGE_CONTACT "Hin <[email protected]>")
65+
# include(CPack)
66+
67+
# enable_testing()

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# DOF5RobotControl
2+
3+
> 该库消极开发中
4+
5+
这是用于控制五自由度机器人的 C/C++ 库代码。
6+
7+
注意!要正常使用请进入 `lib/NatorControl/SDK1.4.12` 按指示操作。
8+
9+
> 为什么?这是厂家的 bug 处理方式。
10+

include/D5Robot.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#pragma once
2+
#include "LogUtil.h"
3+
#include "NatorMotor.h"
4+
#include "RMDMotor.h"
5+
#include "SerialPort.h"
6+
7+
#ifdef D5R_EXPORTS
8+
#define D5R_API __declspec(dllexport)
9+
#else
10+
#define D5R_API __declspec(dllimport)
11+
#endif
12+
13+
namespace D5R {
14+
15+
struct Joints {
16+
int r1;
17+
int x;
18+
int y;
19+
int z;
20+
int r5;
21+
};
22+
23+
class D5R_API D5Robot {
24+
public:
25+
D5Robot(const char *serialPort, std::string natorID, uint8_t topRMDID,
26+
uint8_t botRMDID);
27+
~D5Robot();
28+
bool IsInit();
29+
bool SetZero();
30+
bool Stop();
31+
bool JointsMoveAbsolute(const Joints j);
32+
bool JointsMoveRelative(const Joints j);
33+
34+
private:
35+
SerialPort _port;
36+
NatorMotor _NatorMotor;
37+
RMDMotor _topRMDMotor;
38+
RMDMotor _botRMDMotor;
39+
bool _isInit;
40+
};
41+
} // namespace D5R

include/DllApi.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "D5Robot.h"
2+
3+
#ifdef D5R_EXPORTS
4+
#define D5R_API __declspec(dllexport)
5+
#else
6+
#define D5R_API __declspec(dllimport)
7+
#endif
8+
9+
using namespace D5R;
10+
11+
extern "C" {
12+
D5R_API D5Robot *CreateD5RobotInstance(const char *serialPort,
13+
std::string natorID, uint8_t topRMDID,
14+
uint8_t botRMDID);
15+
D5R_API void DestroyD5RobotInstance(D5Robot *instance);
16+
D5R_API bool CallIsInit(D5Robot *instance);
17+
D5R_API bool CallSetZero(D5Robot *instance);
18+
D5R_API bool CallStop(D5Robot *instance);
19+
D5R_API bool CallJointsMoveAbsolute(D5Robot *instance, const Joints j);
20+
D5R_API bool CallJointsMoveRelative(D5Robot *instance, const Joints j);
21+
}

0 commit comments

Comments
 (0)