openarm-can 1.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- openarm_can-1.2.0/CMakeLists.txt +117 -0
- openarm_can-1.2.0/LICENSE.txt +202 -0
- openarm_can-1.2.0/PKG-INFO +23 -0
- openarm_can-1.2.0/README.md +9 -0
- openarm_can-1.2.0/build.sh +62 -0
- openarm_can-1.2.0/examples/example.py +56 -0
- openarm_can-1.2.0/examples/test_posvel.py +44 -0
- openarm_can-1.2.0/openarm_can/__init__.py +53 -0
- openarm_can-1.2.0/pyproject.toml +38 -0
- openarm_can-1.2.0/requirements.txt +13 -0
- openarm_can-1.2.0/setup.py +60 -0
- openarm_can-1.2.0/src/openarm_can.cpp +413 -0
- openarm_can-1.2.0/vendor/nanobind-2.10.2.tar.gz +0 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# Copyright 2025 Enactic, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
cmake_minimum_required(VERSION 3.22)
|
|
16
|
+
project(
|
|
17
|
+
openarm_can_python
|
|
18
|
+
VERSION 1.2.0
|
|
19
|
+
LANGUAGES CXX)
|
|
20
|
+
|
|
21
|
+
set(CMAKE_CXX_STANDARD 17)
|
|
22
|
+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
23
|
+
|
|
24
|
+
find_package(
|
|
25
|
+
Python
|
|
26
|
+
COMPONENTS Interpreter Development.Module
|
|
27
|
+
REQUIRED)
|
|
28
|
+
|
|
29
|
+
include(FetchContent)
|
|
30
|
+
set(OCP_FETCH_CONTENT_COMMON_OPTIONS)
|
|
31
|
+
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.28)
|
|
32
|
+
list(APPEND OCP_FETCH_CONTENT_COMMON_OPTIONS EXCLUDE_FROM_ALL TRUE)
|
|
33
|
+
endif()
|
|
34
|
+
macro(ocp_prepare_fetchcontent)
|
|
35
|
+
set(BUILD_SHARED_LIBS OFF)
|
|
36
|
+
set(BUILD_TESTING OFF)
|
|
37
|
+
set(CMAKE_COMPILE_WARNING_AS_ERROR FALSE)
|
|
38
|
+
set(CMAKE_EXPORT_NO_PACKAGE_REGISTRY TRUE)
|
|
39
|
+
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
|
|
40
|
+
endmacro()
|
|
41
|
+
|
|
42
|
+
execute_process(
|
|
43
|
+
COMMAND Python::Interpreter -m nanobind --cmake_dir
|
|
44
|
+
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
45
|
+
OUTPUT_VARIABLE nanobind_ROOT)
|
|
46
|
+
function(ocp_ensure_nanobind)
|
|
47
|
+
# We can use FIND_PACKAGE_ARGS in fetchcontent_declare() instead of
|
|
48
|
+
# explicit find_package() when we require CMake 3.24 or later.
|
|
49
|
+
find_package(nanobind)
|
|
50
|
+
if(nanobind_FOUND)
|
|
51
|
+
return()
|
|
52
|
+
endif()
|
|
53
|
+
|
|
54
|
+
set(NANOBIND_BUNDLED_VERSION "2.10.2")
|
|
55
|
+
set(NANOBIND_SOURCE_BASE_NAME "nanobind-${NANOBIND_BUNDLED_VERSION}.tar.gz")
|
|
56
|
+
set(NANOBIND_SOURCE_LOCAL_PATH
|
|
57
|
+
"${CMAKE_CURRENT_SOURCE_DIR}/vendor/${NANOBIND_SOURCE_BASE_NAME}")
|
|
58
|
+
if(EXISTS ${NANOBIND_SOURCE_LOCAL_PATH})
|
|
59
|
+
set(NANOBIND_SOURCE_ARGS URL ${NANOBIND_SOURCE_LOCAL_PATH})
|
|
60
|
+
else()
|
|
61
|
+
set(NANOBIND_SOURCE_ARGS
|
|
62
|
+
GIT_REPOSITORY "https://github.com/wjakob/nanobind.git" GIT_TAG
|
|
63
|
+
"v${NANOBIND_BUNDLED_VERSION}")
|
|
64
|
+
endif()
|
|
65
|
+
fetchcontent_declare(
|
|
66
|
+
nanobind
|
|
67
|
+
${OCP_FETCH_CONTENT_COMMON_OPTIONS}
|
|
68
|
+
${NANOBIND_SOURCE_ARGS}
|
|
69
|
+
# We can use FIND_PACKAGE_ARGS when we require CMake 3.24 or later.
|
|
70
|
+
#
|
|
71
|
+
# FIND_PACKAGE_ARGS
|
|
72
|
+
)
|
|
73
|
+
ocp_prepare_fetchcontent()
|
|
74
|
+
fetchcontent_makeavailable(nanobind)
|
|
75
|
+
if(nanobind_SOURCE_DIR)
|
|
76
|
+
if(CMAKE_VERSION VERSION_LESS 3.28)
|
|
77
|
+
set_property(DIRECTORY "${nanobind_SOURCE_DIR}" PROPERTY EXCLUDE_FROM_ALL
|
|
78
|
+
TRUE)
|
|
79
|
+
endif()
|
|
80
|
+
endif()
|
|
81
|
+
endfunction()
|
|
82
|
+
ocp_ensure_nanobind()
|
|
83
|
+
|
|
84
|
+
function(ocp_ensure_openarm_can)
|
|
85
|
+
# We can use FIND_PACKAGE_ARGS in fetchcontent_declare() instead of
|
|
86
|
+
# explicit find_package() when we require CMake 3.24 or later.
|
|
87
|
+
find_package(OpenArmCAN)
|
|
88
|
+
if(OpenArmCAN_FOUND)
|
|
89
|
+
return()
|
|
90
|
+
endif()
|
|
91
|
+
|
|
92
|
+
fetchcontent_declare(
|
|
93
|
+
openarm_can
|
|
94
|
+
${OCP_FETCH_CONTENT_COMMON_OPTIONS}
|
|
95
|
+
GIT_REPOSITORY "https://github.com/enactic/openarm_can.git"
|
|
96
|
+
GIT_TAG "${openarm_can_python_VERSION}"
|
|
97
|
+
# We can use FIND_PACKAGE_ARGS when we require CMake 3.24 or later.
|
|
98
|
+
#
|
|
99
|
+
# FIND_PACKAGE_ARGS NAMES OpenArmCAN
|
|
100
|
+
)
|
|
101
|
+
ocp_prepare_fetchcontent()
|
|
102
|
+
fetchcontent_makeavailable(openarm_can)
|
|
103
|
+
if(openarm_can_SOURCE_DIR)
|
|
104
|
+
if(CMAKE_VERSION VERSION_LESS 3.28)
|
|
105
|
+
set_property(DIRECTORY "${openarm_can_SOURCE_DIR}"
|
|
106
|
+
PROPERTY EXCLUDE_FROM_ALL TRUE)
|
|
107
|
+
endif()
|
|
108
|
+
add_library(OpenArmCAN::openarm_can ALIAS openarm_can)
|
|
109
|
+
endif()
|
|
110
|
+
endfunction()
|
|
111
|
+
ocp_ensure_openarm_can()
|
|
112
|
+
|
|
113
|
+
nanobind_add_module(openarm_can_python src/openarm_can.cpp)
|
|
114
|
+
set_target_properties(openarm_can_python PROPERTIES OUTPUT_NAME "openarm_can")
|
|
115
|
+
target_link_libraries(openarm_can_python PRIVATE OpenArmCAN::openarm_can)
|
|
116
|
+
install(TARGETS openarm_can_python LIBRARY DESTINATION "openarm_can")
|
|
117
|
+
install(FILES openarm_can/__init__.py DESTINATION "openarm_can")
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: openarm_can
|
|
3
|
+
Version: 1.2.0
|
|
4
|
+
Author: Enactic, Inc.
|
|
5
|
+
Maintainer: Enactic, Inc.
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: changelog, https://github.com/enactic/openarm_can/releases
|
|
8
|
+
Project-URL: documentation, https://docs.openarm.dev/software/can
|
|
9
|
+
Project-URL: homepage, https://docs.openarm.dev/software/can
|
|
10
|
+
Project-URL: issues, https://github.com/enactic/openarm_can/issues
|
|
11
|
+
Project-URL: repository, https://github.com/enactic/openarm_can.git
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
# OpenArm CAN Python bindings
|
|
16
|
+
|
|
17
|
+
This is the Python bindings of OpenArm CAN library.
|
|
18
|
+
|
|
19
|
+
> [!WARNING]
|
|
20
|
+
>
|
|
21
|
+
> ⚠️ **WARNING: UNSTABLE API** ⚠️
|
|
22
|
+
> Python bindings are currently a direct low level **temporary port**, and will change **DRASTICALLY**.
|
|
23
|
+
> The interface is may break between versions.Use at your own risk! Discussions on the interface are welcomed.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# OpenArm CAN Python bindings
|
|
2
|
+
|
|
3
|
+
This is the Python bindings of OpenArm CAN library.
|
|
4
|
+
|
|
5
|
+
> [!WARNING]
|
|
6
|
+
>
|
|
7
|
+
> ⚠️ **WARNING: UNSTABLE API** ⚠️
|
|
8
|
+
> Python bindings are currently a direct low level **temporary port**, and will change **DRASTICALLY**.
|
|
9
|
+
> The interface is may break between versions.Use at your own risk! Discussions on the interface are welcomed.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
#
|
|
3
|
+
# Copyright 2025 Enactic, Inc.
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
#
|
|
17
|
+
# Build script for OpenArm Python bindings
|
|
18
|
+
|
|
19
|
+
set -eu
|
|
20
|
+
|
|
21
|
+
# Get script directory
|
|
22
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
23
|
+
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
|
|
24
|
+
|
|
25
|
+
echo "Building OpenArm Python bindings..."
|
|
26
|
+
echo "Script directory: $SCRIPT_DIR"
|
|
27
|
+
echo "Project root: $PROJECT_ROOT"
|
|
28
|
+
|
|
29
|
+
# Check if we're in a virtual environment
|
|
30
|
+
if [[ -n "${VIRTUAL_ENV:-}" ]]; then
|
|
31
|
+
echo "Using virtual environment (venv): $VIRTUAL_ENV"
|
|
32
|
+
elif [[ -n "${CONDA_DEFAULT_ENV:-}" ]]; then
|
|
33
|
+
echo "Using conda environment: $CONDA_DEFAULT_ENV"
|
|
34
|
+
else
|
|
35
|
+
echo "Warning: Not in a virtual environment. Consider using:"
|
|
36
|
+
echo " python -m venv venv && source venv/bin/activate"
|
|
37
|
+
echo " # or"
|
|
38
|
+
echo " conda create -n myenv python=3.x && conda activate myenv"
|
|
39
|
+
fi
|
|
40
|
+
|
|
41
|
+
# Build the C++ library first if needed
|
|
42
|
+
if [ ! -d "$PROJECT_ROOT/build" ]; then
|
|
43
|
+
echo "Building C++ library..."
|
|
44
|
+
cmake \
|
|
45
|
+
-S "$PROJECT_ROOT" \
|
|
46
|
+
-B "$PROJECT_ROOT/build" \
|
|
47
|
+
-DCMAKE_BUILD_TYPE=Debug \
|
|
48
|
+
-GNinja
|
|
49
|
+
cmake --build "$PROJECT_ROOT/build"
|
|
50
|
+
cmake --install "$PROJECT_ROOT/build"
|
|
51
|
+
fi
|
|
52
|
+
|
|
53
|
+
# Install in development mode
|
|
54
|
+
echo "Installing in development mode..."
|
|
55
|
+
pip install .
|
|
56
|
+
|
|
57
|
+
echo "Build completed successfully!"
|
|
58
|
+
echo ""
|
|
59
|
+
echo "To test the installation, run:"
|
|
60
|
+
echo " python -c 'import openarm; print(openarm.__version__)'"
|
|
61
|
+
echo ""
|
|
62
|
+
echo "See examples/ directory for usage examples."
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Copyright 2025 Enactic, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import openarm_can as oa
|
|
16
|
+
import time
|
|
17
|
+
# Create OpenArm instance
|
|
18
|
+
|
|
19
|
+
arm = oa.OpenArm("can0", True)
|
|
20
|
+
|
|
21
|
+
# Initialize arm motors
|
|
22
|
+
motor_types = [oa.MotorType.DM4310, oa.MotorType.DM4310]
|
|
23
|
+
send_ids = [0x01, 0x02]
|
|
24
|
+
recv_ids = [0x11, 0x12]
|
|
25
|
+
arm.init_arm_motors(motor_types, send_ids, recv_ids)
|
|
26
|
+
|
|
27
|
+
# Initialize gripper
|
|
28
|
+
arm.init_gripper_motor(oa.MotorType.DM4310, 0x7, 0x17)
|
|
29
|
+
arm.set_callback_mode_all(oa.CallbackMode.IGNORE)
|
|
30
|
+
# Use high-level operations
|
|
31
|
+
arm.enable_all()
|
|
32
|
+
arm.recv_all()
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
# return to zero position
|
|
36
|
+
arm.set_callback_mode_all(oa.CallbackMode.STATE)
|
|
37
|
+
arm.get_arm().mit_control_all([oa.MITParam(2, 0.5, 0, 0, 0),
|
|
38
|
+
oa.MITParam(2, 0.5, 0, 0, 0)])
|
|
39
|
+
|
|
40
|
+
arm.recv_all()
|
|
41
|
+
|
|
42
|
+
# torque control test
|
|
43
|
+
|
|
44
|
+
arm.get_gripper().mit_control_all([oa.MITParam(0, 0, 0, 0, 0.15)])
|
|
45
|
+
arm.get_arm().mit_control_all(
|
|
46
|
+
[oa.MITParam(0, 0, 0, 0, 0.15), oa.MITParam(0, 0, 0, 0, 0.15)])
|
|
47
|
+
arm.recv_all()
|
|
48
|
+
|
|
49
|
+
# read motor position
|
|
50
|
+
while True:
|
|
51
|
+
arm.refresh_all()
|
|
52
|
+
arm.recv_all()
|
|
53
|
+
for motor in arm.get_arm().get_motors():
|
|
54
|
+
print(motor.get_position())
|
|
55
|
+
for motor in arm.get_gripper().get_motors():
|
|
56
|
+
print(motor.get_position())
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Copyright 2025 Enactic, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import openarm_can as oa
|
|
16
|
+
import time
|
|
17
|
+
# Create OpenArm instance
|
|
18
|
+
|
|
19
|
+
arm = oa.OpenArm("can0", True)
|
|
20
|
+
|
|
21
|
+
# Initialize arm motors
|
|
22
|
+
motor_types = [oa.MotorType.DM4310]
|
|
23
|
+
send_ids = [0x0A]
|
|
24
|
+
recv_ids = [0x1A]
|
|
25
|
+
arm.init_arm_motors(motor_types, send_ids, recv_ids)
|
|
26
|
+
|
|
27
|
+
# Use high-level operations
|
|
28
|
+
arm.enable_all()
|
|
29
|
+
arm.recv_all()
|
|
30
|
+
|
|
31
|
+
# return to zero position
|
|
32
|
+
arm.set_callback_mode_all(oa.CallbackMode.STATE)
|
|
33
|
+
arm.get_arm().posvel_control_all([oa.PosVelParam(3.14 * 4, 20)])
|
|
34
|
+
|
|
35
|
+
arm.recv_all()
|
|
36
|
+
|
|
37
|
+
# read motor position
|
|
38
|
+
while True:
|
|
39
|
+
arm.refresh_all()
|
|
40
|
+
arm.recv_all()
|
|
41
|
+
for motor in arm.get_arm().get_motors():
|
|
42
|
+
print(motor.get_position())
|
|
43
|
+
for motor in arm.get_gripper().get_motors():
|
|
44
|
+
print(motor.get_position())
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Copyright 2025 Enactic, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
"""
|
|
17
|
+
OpenArm CAN Python bindings for motor control via SocketCAN.
|
|
18
|
+
|
|
19
|
+
This package provides Python bindings for the OpenArm motor control system,
|
|
20
|
+
allowing you to control DAMIAO motors through SocketCAN.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
from .openarm_can import *
|
|
24
|
+
|
|
25
|
+
__version__ = "1.2.0"
|
|
26
|
+
__author__ = "Enactic, Inc."
|
|
27
|
+
|
|
28
|
+
# Direct export of C++ classes - no wrappers
|
|
29
|
+
__all__ = [
|
|
30
|
+
# Enums
|
|
31
|
+
"MotorType",
|
|
32
|
+
"MotorVariable",
|
|
33
|
+
"CallbackMode",
|
|
34
|
+
|
|
35
|
+
# Data structures
|
|
36
|
+
"LimitParam",
|
|
37
|
+
"ParamResult",
|
|
38
|
+
"MotorStateResult",
|
|
39
|
+
"CanFrame",
|
|
40
|
+
"CanFdFrame",
|
|
41
|
+
"MITParam",
|
|
42
|
+
|
|
43
|
+
# Main C++ classes (1:1 mapping)
|
|
44
|
+
"Motor",
|
|
45
|
+
"MotorControl",
|
|
46
|
+
"CANSocket", # Low-level socket with file descriptor access
|
|
47
|
+
"CANDevice", # Base CAN device class
|
|
48
|
+
"MotorDeviceCan", # Motor device management
|
|
49
|
+
"CANDeviceCollection", # Device collection management
|
|
50
|
+
|
|
51
|
+
# Exceptions
|
|
52
|
+
"CANSocketException",
|
|
53
|
+
]
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Copyright 2025 Enactic, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
[build-system]
|
|
16
|
+
build-backend = "scikit_build_core.build"
|
|
17
|
+
requires = ["scikit-build-core", "nanobind"]
|
|
18
|
+
|
|
19
|
+
[project]
|
|
20
|
+
authors = [{name = "Enactic, Inc."}]
|
|
21
|
+
# pyproject-metadta 0.7.1 on Ubuntu 24.04 doesn't accept PEP 639 yet.
|
|
22
|
+
# license = "Apache-2.0"
|
|
23
|
+
# license-files = ["LICENSE.txt"]
|
|
24
|
+
license = {text = "Apache-2.0"}
|
|
25
|
+
maintainers = [{name = "Enactic, Inc."}]
|
|
26
|
+
name = "openarm_can"
|
|
27
|
+
readme = "README.md"
|
|
28
|
+
requires-python = ">= 3.10"
|
|
29
|
+
version = "1.2.0"
|
|
30
|
+
|
|
31
|
+
[project.urls]
|
|
32
|
+
changelog = "https://github.com/enactic/openarm_can/releases"
|
|
33
|
+
documentation = "https://docs.openarm.dev/software/can"
|
|
34
|
+
homepage = "https://docs.openarm.dev/software/can"
|
|
35
|
+
issues = "https://github.com/enactic/openarm_can/issues"
|
|
36
|
+
repository = "https://github.com/enactic/openarm_can.git"
|
|
37
|
+
|
|
38
|
+
[tool.autopep8]
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Copyright 2025 Enactic, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Copyright 2025 Enactic, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
# If you can use build and mesonpy, you should use pyproject.toml and
|
|
16
|
+
# meson.build intead of setup.py. setup.py is only for old environment
|
|
17
|
+
# such as deb packages for Ubuntu 22.04.
|
|
18
|
+
|
|
19
|
+
import pathlib
|
|
20
|
+
|
|
21
|
+
from setuptools import setup, Extension
|
|
22
|
+
from setuptools.command.build_ext import build_ext
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class cmake_build_ext(build_ext):
|
|
26
|
+
def build_extensions(self):
|
|
27
|
+
self.extensions = [
|
|
28
|
+
ext for ext in self.extensions if ext.name != '__dummy__']
|
|
29
|
+
super().run()
|
|
30
|
+
|
|
31
|
+
def run(self):
|
|
32
|
+
self._run_cmake()
|
|
33
|
+
super().run()
|
|
34
|
+
|
|
35
|
+
def _run_cmake(self):
|
|
36
|
+
source = pathlib.Path().absolute()
|
|
37
|
+
build_lib = pathlib.Path(self.build_lib).absolute()
|
|
38
|
+
build_temp = pathlib.Path(self.build_temp).absolute()
|
|
39
|
+
build_temp.mkdir(parents=True, exist_ok=True)
|
|
40
|
+
self.spawn([
|
|
41
|
+
"cmake",
|
|
42
|
+
"-S", str(source),
|
|
43
|
+
"-B", str(build_temp),
|
|
44
|
+
"-DCMAKE_BUILD_TYPE=Release",
|
|
45
|
+
f"-DCMAKE_INSTALL_PREFIX={build_lib}",
|
|
46
|
+
])
|
|
47
|
+
self.spawn(["cmake", "--build", str(build_temp)])
|
|
48
|
+
self.spawn(["cmake", "--install", str(build_temp)])
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
setup(
|
|
52
|
+
name="openarm_can",
|
|
53
|
+
version="1.2.0",
|
|
54
|
+
license="Apache-2.0",
|
|
55
|
+
license_files=["LICENSE.txt"],
|
|
56
|
+
ext_modules=[Extension('__dummy__', [])],
|
|
57
|
+
cmdclass={
|
|
58
|
+
"build_ext": cmake_build_ext,
|
|
59
|
+
}
|
|
60
|
+
)
|
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
// Copyright 2025 Enactic, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
#include <nanobind/nanobind.h>
|
|
16
|
+
#include <nanobind/stl/string.h>
|
|
17
|
+
#include <nanobind/stl/vector.h>
|
|
18
|
+
|
|
19
|
+
// Include the C++ headers
|
|
20
|
+
#include <linux/can.h>
|
|
21
|
+
#include <linux/can/raw.h>
|
|
22
|
+
|
|
23
|
+
#include <openarm/can/socket/arm_component.hpp>
|
|
24
|
+
#include <openarm/can/socket/gripper_component.hpp>
|
|
25
|
+
#include <openarm/can/socket/openarm.hpp>
|
|
26
|
+
#include <openarm/canbus/can_device.hpp>
|
|
27
|
+
#include <openarm/canbus/can_device_collection.hpp>
|
|
28
|
+
#include <openarm/canbus/can_socket.hpp>
|
|
29
|
+
#include <openarm/damiao_motor/dm_motor.hpp>
|
|
30
|
+
#include <openarm/damiao_motor/dm_motor_constants.hpp>
|
|
31
|
+
#include <openarm/damiao_motor/dm_motor_control.hpp>
|
|
32
|
+
#include <openarm/damiao_motor/dm_motor_device.hpp>
|
|
33
|
+
#include <openarm/damiao_motor/dm_motor_device_collection.hpp>
|
|
34
|
+
|
|
35
|
+
using namespace openarm::canbus;
|
|
36
|
+
using namespace openarm::damiao_motor;
|
|
37
|
+
using namespace openarm::can::socket;
|
|
38
|
+
|
|
39
|
+
namespace nb = nanobind;
|
|
40
|
+
|
|
41
|
+
NB_MODULE(openarm_can, m) {
|
|
42
|
+
m.doc() = "OpenArm CAN Python bindings for motor control via SocketCAN";
|
|
43
|
+
|
|
44
|
+
// ============================================================================
|
|
45
|
+
// DAMIAO MOTOR NAMESPACE - ENUMS AND CONSTANTS
|
|
46
|
+
// ============================================================================
|
|
47
|
+
|
|
48
|
+
// Motor Type enum
|
|
49
|
+
nb::enum_<MotorType>(m, "MotorType")
|
|
50
|
+
.value("DM3507", MotorType::DM3507)
|
|
51
|
+
.value("DM4310", MotorType::DM4310)
|
|
52
|
+
.value("DM4310_48V", MotorType::DM4310_48V)
|
|
53
|
+
.value("DM4340", MotorType::DM4340)
|
|
54
|
+
.value("DM4340_48V", MotorType::DM4340_48V)
|
|
55
|
+
.value("DM6006", MotorType::DM6006)
|
|
56
|
+
.value("DM8006", MotorType::DM8006)
|
|
57
|
+
.value("DM8009", MotorType::DM8009)
|
|
58
|
+
.value("DM10010L", MotorType::DM10010L)
|
|
59
|
+
.value("DM10010", MotorType::DM10010)
|
|
60
|
+
.value("DMH3510", MotorType::DMH3510)
|
|
61
|
+
.value("DMH6215", MotorType::DMH6215)
|
|
62
|
+
.value("DMG6220", MotorType::DMG6220)
|
|
63
|
+
.value("COUNT", MotorType::COUNT)
|
|
64
|
+
.export_values();
|
|
65
|
+
|
|
66
|
+
// Motor Variable enum
|
|
67
|
+
nb::enum_<RID>(m, "MotorVariable")
|
|
68
|
+
.value("UV_Value", RID::UV_Value)
|
|
69
|
+
.value("KT_Value", RID::KT_Value)
|
|
70
|
+
.value("OT_Value", RID::OT_Value)
|
|
71
|
+
.value("OC_Value", RID::OC_Value)
|
|
72
|
+
.value("ACC", RID::ACC)
|
|
73
|
+
.value("DEC", RID::DEC)
|
|
74
|
+
.value("MAX_SPD", RID::MAX_SPD)
|
|
75
|
+
.value("MST_ID", RID::MST_ID)
|
|
76
|
+
.value("ESC_ID", RID::ESC_ID)
|
|
77
|
+
.value("TIMEOUT", RID::TIMEOUT)
|
|
78
|
+
.value("CTRL_MODE", RID::CTRL_MODE)
|
|
79
|
+
.value("Damp", RID::Damp)
|
|
80
|
+
.value("Inertia", RID::Inertia)
|
|
81
|
+
.value("hw_ver", RID::hw_ver)
|
|
82
|
+
.value("sw_ver", RID::sw_ver)
|
|
83
|
+
.value("SN", RID::SN)
|
|
84
|
+
.value("NPP", RID::NPP)
|
|
85
|
+
.value("Rs", RID::Rs)
|
|
86
|
+
.value("LS", RID::LS)
|
|
87
|
+
.value("Flux", RID::Flux)
|
|
88
|
+
.value("Gr", RID::Gr)
|
|
89
|
+
.value("PMAX", RID::PMAX)
|
|
90
|
+
.value("VMAX", RID::VMAX)
|
|
91
|
+
.value("TMAX", RID::TMAX)
|
|
92
|
+
.value("I_BW", RID::I_BW)
|
|
93
|
+
.value("KP_ASR", RID::KP_ASR)
|
|
94
|
+
.value("KI_ASR", RID::KI_ASR)
|
|
95
|
+
.value("KP_APR", RID::KP_APR)
|
|
96
|
+
.value("KI_APR", RID::KI_APR)
|
|
97
|
+
.value("OV_Value", RID::OV_Value)
|
|
98
|
+
.value("GREF", RID::GREF)
|
|
99
|
+
.value("Deta", RID::Deta)
|
|
100
|
+
.value("V_BW", RID::V_BW)
|
|
101
|
+
.value("IQ_c1", RID::IQ_c1)
|
|
102
|
+
.value("VL_c1", RID::VL_c1)
|
|
103
|
+
.value("can_br", RID::can_br)
|
|
104
|
+
.value("sub_ver", RID::sub_ver)
|
|
105
|
+
.value("u_off", RID::u_off)
|
|
106
|
+
.value("v_off", RID::v_off)
|
|
107
|
+
.value("k1", RID::k1)
|
|
108
|
+
.value("k2", RID::k2)
|
|
109
|
+
.value("m_off", RID::m_off)
|
|
110
|
+
.value("dir", RID::dir)
|
|
111
|
+
.value("p_m", RID::p_m)
|
|
112
|
+
.value("xout", RID::xout)
|
|
113
|
+
.value("COUNT", RID::COUNT)
|
|
114
|
+
.export_values();
|
|
115
|
+
|
|
116
|
+
// Callback Mode enum
|
|
117
|
+
nb::enum_<CallbackMode>(m, "CallbackMode")
|
|
118
|
+
.value("STATE", CallbackMode::STATE)
|
|
119
|
+
.value("PARAM", CallbackMode::PARAM)
|
|
120
|
+
.value("IGNORE", CallbackMode::IGNORE)
|
|
121
|
+
.export_values();
|
|
122
|
+
|
|
123
|
+
// ============================================================================
|
|
124
|
+
// DAMIAO MOTOR NAMESPACE - STRUCTS
|
|
125
|
+
// ============================================================================
|
|
126
|
+
|
|
127
|
+
// LimitParam struct
|
|
128
|
+
nb::class_<LimitParam>(m, "LimitParam")
|
|
129
|
+
.def(nb::init<>())
|
|
130
|
+
.def_rw("pMax", &LimitParam::pMax)
|
|
131
|
+
.def_rw("vMax", &LimitParam::vMax)
|
|
132
|
+
.def_rw("tMax", &LimitParam::tMax);
|
|
133
|
+
|
|
134
|
+
// ParamResult struct
|
|
135
|
+
nb::class_<ParamResult>(m, "ParamResult")
|
|
136
|
+
.def(nb::init<>())
|
|
137
|
+
.def_rw("rid", &ParamResult::rid)
|
|
138
|
+
.def_rw("value", &ParamResult::value)
|
|
139
|
+
.def_rw("valid", &ParamResult::valid);
|
|
140
|
+
|
|
141
|
+
// MotorStateResult struct
|
|
142
|
+
nb::class_<StateResult>(m, "MotorStateResult")
|
|
143
|
+
.def(nb::init<>())
|
|
144
|
+
.def_rw("position", &StateResult::position)
|
|
145
|
+
.def_rw("velocity", &StateResult::velocity)
|
|
146
|
+
.def_rw("torque", &StateResult::torque)
|
|
147
|
+
.def_rw("t_mos", &StateResult::t_mos)
|
|
148
|
+
.def_rw("t_rotor", &StateResult::t_rotor)
|
|
149
|
+
.def_rw("valid", &StateResult::valid);
|
|
150
|
+
|
|
151
|
+
// CANPacket struct
|
|
152
|
+
nb::class_<CANPacket>(m, "CANPacket")
|
|
153
|
+
.def(nb::init<>())
|
|
154
|
+
.def_rw("send_can_id", &CANPacket::send_can_id)
|
|
155
|
+
.def_rw("data", &CANPacket::data);
|
|
156
|
+
|
|
157
|
+
// MITParam struct
|
|
158
|
+
nb::class_<MITParam>(m, "MITParam")
|
|
159
|
+
.def(nb::init<>())
|
|
160
|
+
.def(
|
|
161
|
+
"__init__",
|
|
162
|
+
[](MITParam* param, double kp, double kd, double q, double dq, double tau) {
|
|
163
|
+
new (param) MITParam(MITParam{kp, kd, q, dq, tau});
|
|
164
|
+
},
|
|
165
|
+
nb::arg("kp"), nb::arg("kd"), nb::arg("q"), nb::arg("dq"), nb::arg("tau"))
|
|
166
|
+
.def_rw("kp", &MITParam::kp)
|
|
167
|
+
.def_rw("kd", &MITParam::kd)
|
|
168
|
+
.def_rw("q", &MITParam::q)
|
|
169
|
+
.def_rw("dq", &MITParam::dq)
|
|
170
|
+
.def_rw("tau", &MITParam::tau);
|
|
171
|
+
|
|
172
|
+
// PosVelParam struct
|
|
173
|
+
nb::class_<PosVelParam>(m, "PosVelParam")
|
|
174
|
+
.def(nb::init<>())
|
|
175
|
+
.def(
|
|
176
|
+
"__init__",
|
|
177
|
+
[](PosVelParam* param, double q, double dq) {
|
|
178
|
+
new (param) PosVelParam(PosVelParam{q, dq});
|
|
179
|
+
},
|
|
180
|
+
nb::arg("q"), nb::arg("dq"))
|
|
181
|
+
.def_rw("q", &PosVelParam::q)
|
|
182
|
+
.def_rw("dq", &PosVelParam::dq);
|
|
183
|
+
// ============================================================================
|
|
184
|
+
// DAMIAO MOTOR NAMESPACE - MAIN CLASSES
|
|
185
|
+
// ============================================================================
|
|
186
|
+
|
|
187
|
+
// Motor class
|
|
188
|
+
nb::class_<Motor>(m, "Motor")
|
|
189
|
+
.def(nb::init<MotorType, uint32_t, uint32_t>(), nb::arg("motor_type"),
|
|
190
|
+
nb::arg("send_can_id"), nb::arg("recv_can_id"))
|
|
191
|
+
.def("get_position", &Motor::get_position)
|
|
192
|
+
.def("get_velocity", &Motor::get_velocity)
|
|
193
|
+
.def("get_torque", &Motor::get_torque)
|
|
194
|
+
.def("get_state_tmos", &Motor::get_state_tmos)
|
|
195
|
+
.def("get_state_trotor", &Motor::get_state_trotor)
|
|
196
|
+
.def("get_send_can_id", &Motor::get_send_can_id)
|
|
197
|
+
.def("get_recv_can_id", &Motor::get_recv_can_id)
|
|
198
|
+
.def("get_motor_type", &Motor::get_motor_type)
|
|
199
|
+
.def("is_enabled", &Motor::is_enabled)
|
|
200
|
+
.def("get_param", &Motor::get_param, nb::arg("rid"))
|
|
201
|
+
.def_static("get_limit_param", &Motor::get_limit_param, nb::arg("motor_type"));
|
|
202
|
+
|
|
203
|
+
// MotorControl class
|
|
204
|
+
nb::class_<CanPacketEncoder>(m, "CanPacketEncoder")
|
|
205
|
+
.def_static("create_refresh_command", &CanPacketEncoder::create_refresh_command,
|
|
206
|
+
nb::arg("motor"))
|
|
207
|
+
.def_static("create_enable_command", &CanPacketEncoder::create_enable_command,
|
|
208
|
+
nb::arg("motor"))
|
|
209
|
+
.def_static("create_disable_command", &CanPacketEncoder::create_disable_command,
|
|
210
|
+
nb::arg("motor"))
|
|
211
|
+
.def_static("create_set_zero_command", &CanPacketEncoder::create_set_zero_command,
|
|
212
|
+
nb::arg("motor"))
|
|
213
|
+
.def_static("create_mit_control_command", &CanPacketEncoder::create_mit_control_command,
|
|
214
|
+
nb::arg("motor"), nb::arg("mit_param"))
|
|
215
|
+
.def_static("create_posvel_control_command",
|
|
216
|
+
&CanPacketEncoder::create_posvel_control_command, nb::arg("motor"),
|
|
217
|
+
nb::arg("posvel_param"))
|
|
218
|
+
.def_static("create_query_param_command", &CanPacketEncoder::create_query_param_command,
|
|
219
|
+
nb::arg("motor"), nb::arg("rid"));
|
|
220
|
+
|
|
221
|
+
nb::class_<CanPacketDecoder>(m, "CanPacketDecoder")
|
|
222
|
+
.def_static("parse_motor_state_data", &CanPacketDecoder::parse_motor_state_data,
|
|
223
|
+
nb::arg("motor"), nb::arg("data"))
|
|
224
|
+
.def_static("parse_motor_param_data", &CanPacketDecoder::parse_motor_param_data,
|
|
225
|
+
nb::arg("data"));
|
|
226
|
+
|
|
227
|
+
// ============================================================================
|
|
228
|
+
// CANBUS NAMESPACE - EXCEPTIONS AND BASE CLASSES
|
|
229
|
+
// ============================================================================
|
|
230
|
+
|
|
231
|
+
// CAN Socket Exception
|
|
232
|
+
nb::exception<CANSocketException>(m, "CANSocketException");
|
|
233
|
+
|
|
234
|
+
// CANDevice base class (MUST be defined before derived classes)
|
|
235
|
+
nb::class_<CANDevice>(m, "CANDevice")
|
|
236
|
+
.def("get_send_can_id", &CANDevice::get_send_can_id)
|
|
237
|
+
.def("get_recv_can_id", &CANDevice::get_recv_can_id)
|
|
238
|
+
.def("get_recv_can_mask", &CANDevice::get_recv_can_mask)
|
|
239
|
+
.def("is_fd_enabled", &CANDevice::is_fd_enabled);
|
|
240
|
+
|
|
241
|
+
// MotorDeviceCan class (NOW can inherit from CANDevice)
|
|
242
|
+
nb::class_<DMCANDevice, CANDevice>(m, "MotorDeviceCan")
|
|
243
|
+
.def(nb::init<Motor&, canid_t, bool>(), nb::arg("motor"), nb::arg("recv_can_mask"),
|
|
244
|
+
nb::arg("use_fd"))
|
|
245
|
+
.def("get_motor", &DMCANDevice::get_motor, nb::rv_policy::reference)
|
|
246
|
+
.def("callback",
|
|
247
|
+
static_cast<void (DMCANDevice::*)(const can_frame&)>(&DMCANDevice::callback),
|
|
248
|
+
nb::arg("frame"))
|
|
249
|
+
.def("callback",
|
|
250
|
+
static_cast<void (DMCANDevice::*)(const canfd_frame&)>(&DMCANDevice::callback),
|
|
251
|
+
nb::arg("frame"))
|
|
252
|
+
.def("create_can_frame", &DMCANDevice::create_can_frame, nb::arg("send_can_id"),
|
|
253
|
+
nb::arg("data"))
|
|
254
|
+
.def("create_canfd_frame", &DMCANDevice::create_canfd_frame, nb::arg("send_can_id"),
|
|
255
|
+
nb::arg("data"))
|
|
256
|
+
.def("set_callback_mode", &DMCANDevice::set_callback_mode, nb::arg("callback_mode"));
|
|
257
|
+
|
|
258
|
+
// CANDeviceCollection class
|
|
259
|
+
nb::class_<CANDeviceCollection>(m, "CANDeviceCollection")
|
|
260
|
+
.def(nb::init<CANSocket&>(), nb::arg("can_socket"))
|
|
261
|
+
.def(
|
|
262
|
+
"add_device",
|
|
263
|
+
[](CANDeviceCollection& self, std::shared_ptr<CANDevice> device) {
|
|
264
|
+
self.add_device(device);
|
|
265
|
+
},
|
|
266
|
+
nb::arg("device"))
|
|
267
|
+
.def(
|
|
268
|
+
"remove_device",
|
|
269
|
+
[](CANDeviceCollection& self, std::shared_ptr<CANDevice> device) {
|
|
270
|
+
self.remove_device(device);
|
|
271
|
+
},
|
|
272
|
+
nb::arg("device"))
|
|
273
|
+
.def("dispatch_frame_callback",
|
|
274
|
+
static_cast<void (CANDeviceCollection::*)(can_frame&)>(
|
|
275
|
+
&CANDeviceCollection::dispatch_frame_callback),
|
|
276
|
+
nb::arg("frame"))
|
|
277
|
+
.def("dispatch_frame_callback",
|
|
278
|
+
static_cast<void (CANDeviceCollection::*)(canfd_frame&)>(
|
|
279
|
+
&CANDeviceCollection::dispatch_frame_callback),
|
|
280
|
+
nb::arg("frame"))
|
|
281
|
+
.def("get_devices", &CANDeviceCollection::get_devices);
|
|
282
|
+
|
|
283
|
+
// CAN Socket class
|
|
284
|
+
nb::class_<CANSocket>(m, "CANSocket")
|
|
285
|
+
.def(nb::init<const std::string&, bool>(), nb::arg("interface"),
|
|
286
|
+
nb::arg("enable_fd") = false)
|
|
287
|
+
.def("get_socket_fd", &CANSocket::get_socket_fd)
|
|
288
|
+
.def("get_interface", &CANSocket::get_interface)
|
|
289
|
+
.def("is_canfd_enabled", &CANSocket::is_canfd_enabled)
|
|
290
|
+
.def("is_initialized", &CANSocket::is_initialized)
|
|
291
|
+
.def(
|
|
292
|
+
"read_raw_frame",
|
|
293
|
+
[](CANSocket& self, size_t buffer_size) {
|
|
294
|
+
std::vector<uint8_t> buffer(buffer_size);
|
|
295
|
+
ssize_t bytes_read = self.read_raw_frame(buffer.data(), buffer_size);
|
|
296
|
+
if (bytes_read > 0) {
|
|
297
|
+
buffer.resize(bytes_read);
|
|
298
|
+
return nb::bytes(reinterpret_cast<const char*>(buffer.data()), bytes_read);
|
|
299
|
+
}
|
|
300
|
+
return nb::bytes();
|
|
301
|
+
},
|
|
302
|
+
nb::arg("buffer_size"))
|
|
303
|
+
.def(
|
|
304
|
+
"write_raw_frame",
|
|
305
|
+
[](CANSocket& self, nb::bytes data) {
|
|
306
|
+
// nb::bytes::data() is available since nanobind 2.0.0.
|
|
307
|
+
return self.write_raw_frame(data.c_str(), data.size());
|
|
308
|
+
},
|
|
309
|
+
nb::arg("data"))
|
|
310
|
+
.def("write_can_frame", &CANSocket::write_can_frame, nb::arg("frame"))
|
|
311
|
+
.def("read_can_frame", &CANSocket::read_can_frame, nb::arg("frame"))
|
|
312
|
+
.def("write_canfd_frame", &CANSocket::write_canfd_frame, nb::arg("frame"))
|
|
313
|
+
.def("read_canfd_frame", &CANSocket::read_canfd_frame, nb::arg("frame"));
|
|
314
|
+
|
|
315
|
+
// ============================================================================
|
|
316
|
+
// LINUX CAN FRAME STRUCTURES
|
|
317
|
+
// ============================================================================
|
|
318
|
+
|
|
319
|
+
// CAN frame structures
|
|
320
|
+
nb::class_<can_frame>(m, "CanFrame")
|
|
321
|
+
.def(nb::init<>())
|
|
322
|
+
.def_rw("can_id", &can_frame::can_id)
|
|
323
|
+
.def_rw("can_dlc", &can_frame::can_dlc)
|
|
324
|
+
.def_prop_rw(
|
|
325
|
+
"data",
|
|
326
|
+
[](const can_frame& frame) {
|
|
327
|
+
return nb::bytes(reinterpret_cast<const char*>(frame.data), frame.can_dlc);
|
|
328
|
+
},
|
|
329
|
+
[](can_frame& frame, nb::bytes data) {
|
|
330
|
+
size_t len = std::min(data.size(), sizeof(frame.data));
|
|
331
|
+
frame.can_dlc = len;
|
|
332
|
+
// nb::bytes::data() is available since nanobind 2.0.0.
|
|
333
|
+
std::memcpy(frame.data, data.c_str(), len);
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
nb::class_<canfd_frame>(m, "CanFdFrame")
|
|
337
|
+
.def(nb::init<>())
|
|
338
|
+
.def_rw("can_id", &canfd_frame::can_id)
|
|
339
|
+
.def_rw("len", &canfd_frame::len)
|
|
340
|
+
.def_rw("flags", &canfd_frame::flags)
|
|
341
|
+
.def_prop_rw(
|
|
342
|
+
"data",
|
|
343
|
+
[](const canfd_frame& frame) {
|
|
344
|
+
return nb::bytes(reinterpret_cast<const char*>(frame.data), frame.len);
|
|
345
|
+
},
|
|
346
|
+
[](canfd_frame& frame, nb::bytes data) {
|
|
347
|
+
size_t len = std::min(data.size(), sizeof(frame.data));
|
|
348
|
+
frame.len = len;
|
|
349
|
+
// nb::bytes::data() is available since nanobind 2.0.0.
|
|
350
|
+
std::memcpy(frame.data, data.c_str(), len);
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
// ============================================================================
|
|
354
|
+
// TOP-LEVEL COMPONENT CLASSES
|
|
355
|
+
// ============================================================================
|
|
356
|
+
|
|
357
|
+
// DMDeviceCollection class (base class for ArmComponent and
|
|
358
|
+
// GripperComponent)
|
|
359
|
+
nb::class_<DMDeviceCollection>(m, "DMDeviceCollection")
|
|
360
|
+
.def(nb::init<CANSocket&>(), nb::arg("can_socket"))
|
|
361
|
+
.def("enable_all", &DMDeviceCollection::enable_all)
|
|
362
|
+
.def("disable_all", &DMDeviceCollection::disable_all)
|
|
363
|
+
.def("set_zero_all", &DMDeviceCollection::set_zero_all)
|
|
364
|
+
.def("refresh_all", &DMDeviceCollection::refresh_all)
|
|
365
|
+
.def("set_callback_mode_all", &DMDeviceCollection::set_callback_mode_all,
|
|
366
|
+
nb::arg("callback_mode"))
|
|
367
|
+
.def("query_param_all", &DMDeviceCollection::query_param_all, nb::arg("rid"))
|
|
368
|
+
.def("mit_control_one", &DMDeviceCollection::mit_control_one, nb::arg("index"),
|
|
369
|
+
nb::arg("mit_param"))
|
|
370
|
+
.def("mit_control_all", &DMDeviceCollection::mit_control_all, nb::arg("mit_params"))
|
|
371
|
+
.def("posvel_control_one", &DMDeviceCollection::posvel_control_one, nb::arg("index"),
|
|
372
|
+
nb::arg("posvel_param"))
|
|
373
|
+
.def("posvel_control_all", &DMDeviceCollection::posvel_control_all,
|
|
374
|
+
nb::arg("posvel_params"))
|
|
375
|
+
.def("get_motors", &DMDeviceCollection::get_motors)
|
|
376
|
+
.def("get_device_collection", &DMDeviceCollection::get_device_collection,
|
|
377
|
+
nb::rv_policy::reference);
|
|
378
|
+
|
|
379
|
+
// ArmComponent class
|
|
380
|
+
nb::class_<ArmComponent, DMDeviceCollection>(m, "ArmComponent")
|
|
381
|
+
.def(nb::init<CANSocket&>(), nb::arg("can_socket"))
|
|
382
|
+
.def("init_motor_devices", &ArmComponent::init_motor_devices, nb::arg("motor_types"),
|
|
383
|
+
nb::arg("send_can_ids"), nb::arg("recv_can_ids"), nb::arg("use_fd"));
|
|
384
|
+
|
|
385
|
+
// GripperComponent class
|
|
386
|
+
nb::class_<GripperComponent, DMDeviceCollection>(m, "GripperComponent")
|
|
387
|
+
.def(nb::init<CANSocket&>(), nb::arg("can_socket"))
|
|
388
|
+
.def("init_motor_device", &GripperComponent::init_motor_device, nb::arg("motor_type"),
|
|
389
|
+
nb::arg("send_can_id"), nb::arg("recv_can_id"), nb::arg("use_fd"))
|
|
390
|
+
.def("open", &GripperComponent::open, nb::arg("kp") = 50.0, nb::arg("kd") = 1.0)
|
|
391
|
+
.def("close", &GripperComponent::close, nb::arg("kp") = 50.0, nb::arg("kd") = 1.0)
|
|
392
|
+
.def("get_motor", &GripperComponent::get_motor, nb::rv_policy::reference_internal);
|
|
393
|
+
|
|
394
|
+
// OpenArm class (main high-level interface)
|
|
395
|
+
nb::class_<OpenArm>(m, "OpenArm")
|
|
396
|
+
.def(nb::init<const std::string&, bool>(), nb::arg("can_interface"),
|
|
397
|
+
nb::arg("enable_fd") = false)
|
|
398
|
+
.def("init_arm_motors", &OpenArm::init_arm_motors, nb::arg("motor_types"),
|
|
399
|
+
nb::arg("send_can_ids"), nb::arg("recv_can_ids"))
|
|
400
|
+
.def("init_gripper_motor", &OpenArm::init_gripper_motor, nb::arg("motor_type"),
|
|
401
|
+
nb::arg("send_can_id"), nb::arg("recv_can_id"))
|
|
402
|
+
.def("get_arm", &OpenArm::get_arm, nb::rv_policy::reference)
|
|
403
|
+
.def("get_gripper", &OpenArm::get_gripper, nb::rv_policy::reference)
|
|
404
|
+
.def("get_master_can_device_collection", &OpenArm::get_master_can_device_collection,
|
|
405
|
+
nb::rv_policy::reference)
|
|
406
|
+
.def("enable_all", &OpenArm::enable_all)
|
|
407
|
+
.def("disable_all", &OpenArm::disable_all)
|
|
408
|
+
.def("set_zero_all", &OpenArm::set_zero_all)
|
|
409
|
+
.def("refresh_all", &OpenArm::refresh_all)
|
|
410
|
+
.def("recv_all", &OpenArm::recv_all, nb::arg("timeout_us") = 500)
|
|
411
|
+
.def("set_callback_mode_all", &OpenArm::set_callback_mode_all, nb::arg("callback_mode"))
|
|
412
|
+
.def("query_param_all", &OpenArm::query_param_all, nb::arg("rid"));
|
|
413
|
+
}
|
|
Binary file
|