rcb4 0.0.2__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.
- rcb4-0.0.2/LICENSE +19 -0
- rcb4-0.0.2/MANIFEST.in +2 -0
- rcb4-0.0.2/PKG-INFO +133 -0
- rcb4-0.0.2/README.md +103 -0
- rcb4-0.0.2/pyproject.toml +45 -0
- rcb4-0.0.2/rcb4/__init__.py +11 -0
- rcb4-0.0.2/rcb4/apps/__init__.py +0 -0
- rcb4-0.0.2/rcb4/apps/armh7_tool.py +175 -0
- rcb4-0.0.2/rcb4/apps/write_firmware.py +48 -0
- rcb4-0.0.2/rcb4/armh7interface.py +1528 -0
- rcb4-0.0.2/rcb4/asm.py +208 -0
- rcb4-0.0.2/rcb4/ctype_utils.py +28 -0
- rcb4-0.0.2/rcb4/data/__init__.py +111 -0
- rcb4-0.0.2/rcb4/rcb4interface.py +1054 -0
- rcb4-0.0.2/rcb4/struct_header.py +261 -0
- rcb4-0.0.2/rcb4/units.py +33 -0
- rcb4-0.0.2/rcb4/usb_utils.py +78 -0
- rcb4-0.0.2/rcb4.egg-info/PKG-INFO +133 -0
- rcb4-0.0.2/rcb4.egg-info/SOURCES.txt +25 -0
- rcb4-0.0.2/rcb4.egg-info/dependency_links.txt +1 -0
- rcb4-0.0.2/rcb4.egg-info/entry_points.txt +3 -0
- rcb4-0.0.2/rcb4.egg-info/not-zip-safe +1 -0
- rcb4-0.0.2/rcb4.egg-info/requires.txt +9 -0
- rcb4-0.0.2/rcb4.egg-info/top_level.txt +1 -0
- rcb4-0.0.2/requirements.txt +9 -0
- rcb4-0.0.2/setup.cfg +4 -0
- rcb4-0.0.2/setup.py +64 -0
rcb4-0.0.2/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2023 Iori Yanokura.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
rcb4-0.0.2/MANIFEST.in
ADDED
rcb4-0.0.2/PKG-INFO
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: rcb4
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: A python library for RCB4
|
|
5
|
+
Home-page: https://github.com/iory/rcb4
|
|
6
|
+
Author: Iori Yanokura
|
|
7
|
+
Author-email: yanokura@jsk.imi.i.u-tokyo.ac.jp
|
|
8
|
+
License: MIT
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Natural Language :: English
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python
|
|
14
|
+
Classifier: Programming Language :: Python :: 2.7
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.5
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.6
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
18
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: colorama
|
|
22
|
+
Requires-Dist: cstruct
|
|
23
|
+
Requires-Dist: gdown
|
|
24
|
+
Requires-Dist: libusb1
|
|
25
|
+
Requires-Dist: numpy
|
|
26
|
+
Requires-Dist: pandas
|
|
27
|
+
Requires-Dist: pyelftools
|
|
28
|
+
Requires-Dist: pyserial
|
|
29
|
+
Requires-Dist: tabulate
|
|
30
|
+
|
|
31
|
+
# rcb4
|
|
32
|
+
|
|
33
|
+
## Contributing
|
|
34
|
+
|
|
35
|
+
### Automatic Formatting
|
|
36
|
+
This repository uses `ruff` for both linting and formatting which is configured in `pyproject.toml`, you can run with:
|
|
37
|
+
```
|
|
38
|
+
pip install ruff
|
|
39
|
+
ruff format
|
|
40
|
+
ruff check --fix .
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## For JSK Users
|
|
44
|
+
|
|
45
|
+
### Worm Gear Module Calibration Tool
|
|
46
|
+
|
|
47
|
+
`armh7-tools` provides a comprehensive solution for calibrating and managing worm gear modules connected via the `ARMH7Interface`.
|
|
48
|
+
It facilitates the calibration of worm gears, reading of calibrated sensor data, and real-time display of sensor and worm gear values.
|
|
49
|
+
Designed for flexibility, it supports operations like calibration data update and in-place modification of YAML configuration files.
|
|
50
|
+
|
|
51
|
+
#### YAML Configuration Format
|
|
52
|
+
|
|
53
|
+
The calibration tool requires an input YAML file for worm gear modules configuration.
|
|
54
|
+
This file contains a list of worm gears with their associated parameters: `worm_id`, `servo_id`, `sensor_id`,
|
|
55
|
+
and initial magnetic encoder value `magenc_init`.
|
|
56
|
+
Each worm gear is represented by a line in the YAML file with its parameters encapsulated in curly braces and prefixed by a dash, indicating a list item in YAML syntax.
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
- {worm_id: 0, servo_id: 0, sensor_id: 38, magenc_init: 6502}
|
|
60
|
+
- {worm_id: 1, servo_id: 2, sensor_id: 40, magenc_init: 3039}
|
|
61
|
+
- {worm_id: 3, servo_id: 6, sensor_id: 44, magenc_init: 9502}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
#### Reading Worm Gear Modules's calibration data
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
armh7-tools read-calib [--device DEVICE] output_file_path
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
`--device`, `-d`: Specify the device port. (Default: None)
|
|
71
|
+
`output_file_path`: Path to output the YAML file with calibration data.
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
##### Example
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
armh7-tools read-calib ./worm_calib.yaml
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
#### Calibrate Worm Gear Modules
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
armh7-tools calibrate [--device DEVICE] file_path [--inplace] [--update] [--output OUTPUT]
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
`--device`, `-d`: Specify the device port. (Default: None)
|
|
87
|
+
`file_path`: Path to the input YAML file containing worm gear configurations.
|
|
88
|
+
`--inplace`, `-i`: Overwrite the input YAML file with calibration results. (Optional)
|
|
89
|
+
`--update`, `-u`: Ignore and overwrite the current magenc_init values in the input YAML. (Optional)
|
|
90
|
+
`--output`, `-o`: Specify a path to save the calibrated data if not overwriting in-place. (Optional)
|
|
91
|
+
|
|
92
|
+
##### Example
|
|
93
|
+
|
|
94
|
+
When the `update` option is specified, the current posture of the robot will be modified,
|
|
95
|
+
and upon pressing the Enter key, the angle at that moment will be set as the zero point.
|
|
96
|
+
Consequently, the `magenc_init` value will be updated and written to the board,
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
armh7-tools calibrate ./worm_calib.yaml --update
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
#### Print Sensor Values
|
|
103
|
+
|
|
104
|
+
This command displays real-time sensor values in a table format.
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
armh7-tools print-sensor
|
|
108
|
+
+------|----------|--------------|--------------|--------------|--------------|----------|----------|----------|----------+
|
|
109
|
+
| ID | Magenc | Proximity1 | Proximity2 | Proximity3 | Proximity4 | Force1 | Force2 | Force3 | Force4 |
|
|
110
|
+
|------|----------|--------------|--------------|--------------|--------------|----------|----------|----------|----------|
|
|
111
|
+
| 19 | 7365 | 0 | 0 | 0 | 0 | 1240 | 1167 | 1083 | 1037 |
|
|
112
|
+
| 20 | 3042 | 0 | 0 | 0 | 0 | 1209 | 1106 | 1075 | 1025 |
|
|
113
|
+
| 21 | 13800 | 0 | 0 | 0 | 0 | 1230 | 1106 | 1064 | 1003 |
|
|
114
|
+
| 22 | 9512 | 0 | 0 | 0 | 0 | 1222 | 1144 | 1123 | 1085 |
|
|
115
|
+
| 23 | 14182 | 0 | 0 | 0 | 0 | 1238 | 1179 | 1083 | 1040 |
|
|
116
|
+
+------|----------|--------------|--------------|--------------|--------------|----------|----------|----------|----------+
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
#### Print Worm Values
|
|
120
|
+
|
|
121
|
+
Displays real-time worm gear values in a table format.
|
|
122
|
+
|
|
123
|
+
```
|
|
124
|
+
armh7-tools print-worm
|
|
125
|
+
+------------|-------------|---------------|------------------|-----------------+
|
|
126
|
+
| servo_id | sensor_id | magenc_init | magenc_present | present_angle |
|
|
127
|
+
|------------|-------------|---------------|------------------|-----------------|
|
|
128
|
+
| 0 | 38 | 6502 | 7368 | -19.0283 |
|
|
129
|
+
| 2 | 40 | 3039 | 3039 | -0 |
|
|
130
|
+
| 6 | 44 | 9502 | 9513 | -0.241699 |
|
|
131
|
+
| 8 | 46 | 9783 | 14170 | -96.394 |
|
|
132
|
+
+------------|-------------|---------------|------------------|-----------------+
|
|
133
|
+
```
|
rcb4-0.0.2/README.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# rcb4
|
|
2
|
+
|
|
3
|
+
## Contributing
|
|
4
|
+
|
|
5
|
+
### Automatic Formatting
|
|
6
|
+
This repository uses `ruff` for both linting and formatting which is configured in `pyproject.toml`, you can run with:
|
|
7
|
+
```
|
|
8
|
+
pip install ruff
|
|
9
|
+
ruff format
|
|
10
|
+
ruff check --fix .
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## For JSK Users
|
|
14
|
+
|
|
15
|
+
### Worm Gear Module Calibration Tool
|
|
16
|
+
|
|
17
|
+
`armh7-tools` provides a comprehensive solution for calibrating and managing worm gear modules connected via the `ARMH7Interface`.
|
|
18
|
+
It facilitates the calibration of worm gears, reading of calibrated sensor data, and real-time display of sensor and worm gear values.
|
|
19
|
+
Designed for flexibility, it supports operations like calibration data update and in-place modification of YAML configuration files.
|
|
20
|
+
|
|
21
|
+
#### YAML Configuration Format
|
|
22
|
+
|
|
23
|
+
The calibration tool requires an input YAML file for worm gear modules configuration.
|
|
24
|
+
This file contains a list of worm gears with their associated parameters: `worm_id`, `servo_id`, `sensor_id`,
|
|
25
|
+
and initial magnetic encoder value `magenc_init`.
|
|
26
|
+
Each worm gear is represented by a line in the YAML file with its parameters encapsulated in curly braces and prefixed by a dash, indicating a list item in YAML syntax.
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
- {worm_id: 0, servo_id: 0, sensor_id: 38, magenc_init: 6502}
|
|
30
|
+
- {worm_id: 1, servo_id: 2, sensor_id: 40, magenc_init: 3039}
|
|
31
|
+
- {worm_id: 3, servo_id: 6, sensor_id: 44, magenc_init: 9502}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
#### Reading Worm Gear Modules's calibration data
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
armh7-tools read-calib [--device DEVICE] output_file_path
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`--device`, `-d`: Specify the device port. (Default: None)
|
|
41
|
+
`output_file_path`: Path to output the YAML file with calibration data.
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
##### Example
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
armh7-tools read-calib ./worm_calib.yaml
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
#### Calibrate Worm Gear Modules
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
armh7-tools calibrate [--device DEVICE] file_path [--inplace] [--update] [--output OUTPUT]
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
`--device`, `-d`: Specify the device port. (Default: None)
|
|
57
|
+
`file_path`: Path to the input YAML file containing worm gear configurations.
|
|
58
|
+
`--inplace`, `-i`: Overwrite the input YAML file with calibration results. (Optional)
|
|
59
|
+
`--update`, `-u`: Ignore and overwrite the current magenc_init values in the input YAML. (Optional)
|
|
60
|
+
`--output`, `-o`: Specify a path to save the calibrated data if not overwriting in-place. (Optional)
|
|
61
|
+
|
|
62
|
+
##### Example
|
|
63
|
+
|
|
64
|
+
When the `update` option is specified, the current posture of the robot will be modified,
|
|
65
|
+
and upon pressing the Enter key, the angle at that moment will be set as the zero point.
|
|
66
|
+
Consequently, the `magenc_init` value will be updated and written to the board,
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
armh7-tools calibrate ./worm_calib.yaml --update
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
#### Print Sensor Values
|
|
73
|
+
|
|
74
|
+
This command displays real-time sensor values in a table format.
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
armh7-tools print-sensor
|
|
78
|
+
+------|----------|--------------|--------------|--------------|--------------|----------|----------|----------|----------+
|
|
79
|
+
| ID | Magenc | Proximity1 | Proximity2 | Proximity3 | Proximity4 | Force1 | Force2 | Force3 | Force4 |
|
|
80
|
+
|------|----------|--------------|--------------|--------------|--------------|----------|----------|----------|----------|
|
|
81
|
+
| 19 | 7365 | 0 | 0 | 0 | 0 | 1240 | 1167 | 1083 | 1037 |
|
|
82
|
+
| 20 | 3042 | 0 | 0 | 0 | 0 | 1209 | 1106 | 1075 | 1025 |
|
|
83
|
+
| 21 | 13800 | 0 | 0 | 0 | 0 | 1230 | 1106 | 1064 | 1003 |
|
|
84
|
+
| 22 | 9512 | 0 | 0 | 0 | 0 | 1222 | 1144 | 1123 | 1085 |
|
|
85
|
+
| 23 | 14182 | 0 | 0 | 0 | 0 | 1238 | 1179 | 1083 | 1040 |
|
|
86
|
+
+------|----------|--------------|--------------|--------------|--------------|----------|----------|----------|----------+
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
#### Print Worm Values
|
|
90
|
+
|
|
91
|
+
Displays real-time worm gear values in a table format.
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
armh7-tools print-worm
|
|
95
|
+
+------------|-------------|---------------|------------------|-----------------+
|
|
96
|
+
| servo_id | sensor_id | magenc_init | magenc_present | present_angle |
|
|
97
|
+
|------------|-------------|---------------|------------------|-----------------|
|
|
98
|
+
| 0 | 38 | 6502 | 7368 | -19.0283 |
|
|
99
|
+
| 2 | 40 | 3039 | 3039 | -0 |
|
|
100
|
+
| 6 | 44 | 9502 | 9513 | -0.241699 |
|
|
101
|
+
| 8 | 46 | 9783 | 14170 | -96.394 |
|
|
102
|
+
+------------|-------------|---------------|------------------|-----------------+
|
|
103
|
+
```
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[tool.ruff]
|
|
2
|
+
target-version = "py38"
|
|
3
|
+
line-length = 90
|
|
4
|
+
|
|
5
|
+
# See https://github.com/charliermarsh/ruff#rules for error code definitions.
|
|
6
|
+
|
|
7
|
+
[tool.ruff.lint]
|
|
8
|
+
select = [
|
|
9
|
+
# "ANN", # annotations
|
|
10
|
+
"B", # bugbear
|
|
11
|
+
"C", # comprehensions
|
|
12
|
+
"E", # style errors
|
|
13
|
+
"F", # flakes
|
|
14
|
+
"I", # import sorting
|
|
15
|
+
"RUF", # ruff specific rules
|
|
16
|
+
"UP", # upgrade
|
|
17
|
+
"W", # style warnings
|
|
18
|
+
"YTT", # sys.version
|
|
19
|
+
"ISC002",
|
|
20
|
+
"NPY201",
|
|
21
|
+
"TID251"
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
ignore = [
|
|
25
|
+
"C901", # Comprehension is too complex (11 > 10)
|
|
26
|
+
"N802", # Function name should be lowercase
|
|
27
|
+
"N806", # Variable in function should be lowercase
|
|
28
|
+
"E501", # Line too long ({width} > {limit} characters)
|
|
29
|
+
"B904", # raise ... from err
|
|
30
|
+
"B905", # zip() without an explicit strict= parameter
|
|
31
|
+
"RUF005", # recommends non-type-aware expansion
|
|
32
|
+
"UP008",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
# don't allow implicit string concatenation
|
|
36
|
+
flake8-implicit-str-concat = {"allow-multiline" = false}
|
|
37
|
+
|
|
38
|
+
[tool.ruff.lint.isort]
|
|
39
|
+
force-single-line = true
|
|
40
|
+
force-sort-within-sections = true
|
|
41
|
+
order-by-type = false
|
|
42
|
+
|
|
43
|
+
[tool.ruff.lint.flake8-tidy-imports.banned-api]
|
|
44
|
+
"IPython.embed".msg = "you forgot to remove a debug embed ;)"
|
|
45
|
+
"numpy.empty".msg = "uninitialized arrays are haunted try numpy.zeros"
|
|
File without changes
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
|
|
5
|
+
import pandas as pd
|
|
6
|
+
from tabulate import tabulate
|
|
7
|
+
import yaml
|
|
8
|
+
|
|
9
|
+
from rcb4.armh7interface import ARMH7Interface
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def calibrate_worms(interface, file_path, output_path, update=False, inplace=False):
|
|
13
|
+
with open(file_path) as file:
|
|
14
|
+
data = yaml.safe_load(file)
|
|
15
|
+
|
|
16
|
+
output_str = ""
|
|
17
|
+
for entry in data:
|
|
18
|
+
print(entry)
|
|
19
|
+
worm_id = entry["worm_id"]
|
|
20
|
+
servo_id = entry["servo_id"]
|
|
21
|
+
sensor_id = entry["sensor_id"]
|
|
22
|
+
magenc_present = entry.get("magenc_init", None)
|
|
23
|
+
if update is True:
|
|
24
|
+
magenc_present = None
|
|
25
|
+
calibrated_value = interface.calibrate_worm(
|
|
26
|
+
worm_id, servo_id, sensor_id, magenc_present
|
|
27
|
+
)
|
|
28
|
+
entry["magenc_init"] = calibrated_value
|
|
29
|
+
output_str += f" - {{worm_id: {worm_id}, servo_id: {servo_id}, sensor_id: {sensor_id}, magenc_init: {calibrated_value}}}\n"
|
|
30
|
+
interface.databssram_to_dataflash()
|
|
31
|
+
if inplace:
|
|
32
|
+
output_path = file_path
|
|
33
|
+
print(output_str, end="")
|
|
34
|
+
if output_path:
|
|
35
|
+
with open(output_path, "w") as file:
|
|
36
|
+
file.write(output_str)
|
|
37
|
+
print(f"Worm calibration file is saved to {output_path}")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def read_calib_sensors(interface, output_path):
|
|
41
|
+
output_str = ""
|
|
42
|
+
for worm_id in interface.search_worm_ids():
|
|
43
|
+
worm = interface.read_worm_calib_data(worm_id)
|
|
44
|
+
output_str += f" - {{worm_id: {worm_id}, servo_id: {worm.servo_id}, sensor_id: {worm.sensor_id}, magenc_init: {worm.magenc_init}}}\n"
|
|
45
|
+
print(output_str, end="")
|
|
46
|
+
with open(output_path, "w") as file:
|
|
47
|
+
file.write(output_str)
|
|
48
|
+
print(f"Worm calibration file is saved to {output_path}")
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def print_sensor_values(interface):
|
|
52
|
+
try:
|
|
53
|
+
while True:
|
|
54
|
+
sensors = interface.all_jointbase_sensors()
|
|
55
|
+
data = {
|
|
56
|
+
"ID": [sensor.id for sensor in sensors],
|
|
57
|
+
"Magenc": [sensor.magenc for sensor in sensors],
|
|
58
|
+
"Proximity1": [sensor.ps[0] for sensor in sensors],
|
|
59
|
+
"Proximity2": [sensor.ps[1] for sensor in sensors],
|
|
60
|
+
"Proximity3": [sensor.ps[2] for sensor in sensors],
|
|
61
|
+
"Proximity4": [sensor.ps[3] for sensor in sensors],
|
|
62
|
+
"Force1": [sensor.adc[0] for sensor in sensors],
|
|
63
|
+
"Force2": [sensor.adc[1] for sensor in sensors],
|
|
64
|
+
"Force3": [sensor.adc[2] for sensor in sensors],
|
|
65
|
+
"Force4": [sensor.adc[3] for sensor in sensors],
|
|
66
|
+
}
|
|
67
|
+
df = pd.DataFrame(data)
|
|
68
|
+
|
|
69
|
+
print(tabulate(df, headers="keys", tablefmt="psql", showindex=False))
|
|
70
|
+
print("\033[H\033[J", end="")
|
|
71
|
+
except KeyboardInterrupt:
|
|
72
|
+
pass
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def print_worm_values(interface):
|
|
76
|
+
attributes = [
|
|
77
|
+
"servo_id",
|
|
78
|
+
"sensor_id",
|
|
79
|
+
"magenc_init",
|
|
80
|
+
"magenc_present",
|
|
81
|
+
"present_angle",
|
|
82
|
+
]
|
|
83
|
+
try:
|
|
84
|
+
while True:
|
|
85
|
+
sensors = [
|
|
86
|
+
interface.read_worm_calib_data(worm_idx)
|
|
87
|
+
for worm_idx in interface.search_worm_ids()
|
|
88
|
+
]
|
|
89
|
+
data = {attr: [] for attr in attributes}
|
|
90
|
+
for sensor in sensors:
|
|
91
|
+
for attr in attributes:
|
|
92
|
+
data[attr].append(getattr(sensor, attr, "N/A"))
|
|
93
|
+
df = pd.DataFrame(data)
|
|
94
|
+
print(tabulate(df, headers="keys", tablefmt="psql", showindex=False))
|
|
95
|
+
print("\033[H\033[J", end="")
|
|
96
|
+
except KeyboardInterrupt:
|
|
97
|
+
pass
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def main():
|
|
101
|
+
parser = argparse.ArgumentParser()
|
|
102
|
+
subparsers = parser.add_subparsers()
|
|
103
|
+
|
|
104
|
+
parser_calibrate = subparsers.add_parser(
|
|
105
|
+
"calibrate", help="Calibrate worm gear module."
|
|
106
|
+
)
|
|
107
|
+
parser_calibrate.add_argument(
|
|
108
|
+
"--device", "-d", default=None, help="Input device port."
|
|
109
|
+
)
|
|
110
|
+
parser_calibrate.add_argument("file_path", type=str, help="Path to yaml file.")
|
|
111
|
+
parser_calibrate.add_argument(
|
|
112
|
+
"--inplace", "-i", action="store_true", help="Overwrite file_path."
|
|
113
|
+
)
|
|
114
|
+
parser_calibrate.add_argument(
|
|
115
|
+
"--update",
|
|
116
|
+
"-u",
|
|
117
|
+
action="store_true",
|
|
118
|
+
help="Overwrite input yaml's current magenc_init.",
|
|
119
|
+
)
|
|
120
|
+
parser_calibrate.add_argument(
|
|
121
|
+
"--output", "-o", type=str, help="Output file path for calibrated data."
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
parser_calibrate.set_defaults(
|
|
125
|
+
func=lambda args: calibrate_worms(
|
|
126
|
+
ARMH7Interface.from_port(args.device),
|
|
127
|
+
args.file_path,
|
|
128
|
+
output_path=args.output,
|
|
129
|
+
update=args.update,
|
|
130
|
+
inplace=args.inplace,
|
|
131
|
+
)
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
parser_read_calib = subparsers.add_parser(
|
|
135
|
+
"read-calib", help="Read worm gear module calib data from armh7"
|
|
136
|
+
)
|
|
137
|
+
parser_read_calib.add_argument(
|
|
138
|
+
"--device", "-d", default=None, help="Input device port."
|
|
139
|
+
)
|
|
140
|
+
parser_read_calib.add_argument(
|
|
141
|
+
"output_file_path", type=str, help="Output path to yaml file."
|
|
142
|
+
)
|
|
143
|
+
parser_read_calib.set_defaults(
|
|
144
|
+
func=lambda args: read_calib_sensors(
|
|
145
|
+
ARMH7Interface.from_port(args.device), args.output_file_path
|
|
146
|
+
)
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
parser_print_sensor = subparsers.add_parser(
|
|
150
|
+
"print-sensor", help="Print sensor values."
|
|
151
|
+
)
|
|
152
|
+
parser_print_sensor.add_argument(
|
|
153
|
+
"--device", "-d", default=None, help="Input device port."
|
|
154
|
+
)
|
|
155
|
+
parser_print_sensor.set_defaults(
|
|
156
|
+
func=lambda args: print_sensor_values(ARMH7Interface.from_port(args.device))
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
parser_print_worm = subparsers.add_parser("print-worm", help="Print worm values.")
|
|
160
|
+
parser_print_worm.add_argument(
|
|
161
|
+
"--device", "-d", default=None, help="Input device port."
|
|
162
|
+
)
|
|
163
|
+
parser_print_worm.set_defaults(
|
|
164
|
+
func=lambda args: print_worm_values(ARMH7Interface.from_port(args.device))
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
args = parser.parse_args()
|
|
168
|
+
if hasattr(args, "func"):
|
|
169
|
+
args.func(args)
|
|
170
|
+
else:
|
|
171
|
+
parser.print_help()
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
if __name__ == "__main__":
|
|
175
|
+
main()
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
import shutil
|
|
5
|
+
import subprocess
|
|
6
|
+
import sys
|
|
7
|
+
|
|
8
|
+
from rcb4.data import kondoh7_elf
|
|
9
|
+
from rcb4.data import stlink
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def check_dependencies():
|
|
13
|
+
objcopy = shutil.which("arm-none-eabi-objcopy")
|
|
14
|
+
if objcopy is None:
|
|
15
|
+
print("Please install arm-none-eabi-objcopy.")
|
|
16
|
+
print("sudo apt install -y binutils-arm-none-eabi")
|
|
17
|
+
sys.exit(1)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def convert_elf_to_bin(elf_path, bin_path):
|
|
21
|
+
cmd = ["arm-none-eabi-objcopy", "-O", "binary", elf_path, bin_path]
|
|
22
|
+
result = subprocess.run(cmd, capture_output=True, text=True)
|
|
23
|
+
if result.returncode != 0:
|
|
24
|
+
print(f"Error converting ELF to BIN: {result.stderr}")
|
|
25
|
+
sys.exit(2)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def flash_bin_to_device(st_flash_path, bin_path):
|
|
29
|
+
cmd = [st_flash_path, "write", bin_path, "0x08000000"]
|
|
30
|
+
result = subprocess.run(cmd, capture_output=True, text=True)
|
|
31
|
+
if result.returncode != 0:
|
|
32
|
+
print(f"Error flashing BIN to device: {result.stderr}")
|
|
33
|
+
sys.exit(3)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def main():
|
|
37
|
+
check_dependencies()
|
|
38
|
+
|
|
39
|
+
st_flash_path = stlink()
|
|
40
|
+
elf_path = kondoh7_elf()
|
|
41
|
+
bin_path = Path(elf_path).with_suffix(".bin")
|
|
42
|
+
|
|
43
|
+
convert_elf_to_bin(elf_path, bin_path)
|
|
44
|
+
flash_bin_to_device(st_flash_path, bin_path)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
if __name__ == "__main__":
|
|
48
|
+
main()
|