knexflow 0.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.
- knexflow-0.2.0/LICENSE +176 -0
- knexflow-0.2.0/PKG-INFO +431 -0
- knexflow-0.2.0/README.md +405 -0
- knexflow-0.2.0/knexflow.egg-info/PKG-INFO +431 -0
- knexflow-0.2.0/knexflow.egg-info/SOURCES.txt +67 -0
- knexflow-0.2.0/knexflow.egg-info/dependency_links.txt +1 -0
- knexflow-0.2.0/knexflow.egg-info/entry_points.txt +2 -0
- knexflow-0.2.0/knexflow.egg-info/requires.txt +3 -0
- knexflow-0.2.0/knexflow.egg-info/top_level.txt +2 -0
- knexflow-0.2.0/knexflow.py +17 -0
- knexflow-0.2.0/knexflow_library/__init__.py +603 -0
- knexflow-0.2.0/knexflow_library/__main__.py +1307 -0
- knexflow-0.2.0/knexflow_library/audio.py +437 -0
- knexflow-0.2.0/knexflow_library/audio_compiler.py +294 -0
- knexflow-0.2.0/knexflow_library/audio_pipeline.py +207 -0
- knexflow-0.2.0/knexflow_library/box.py +2012 -0
- knexflow-0.2.0/knexflow_library/builder.py +697 -0
- knexflow-0.2.0/knexflow_library/cad/__init__.py +43 -0
- knexflow-0.2.0/knexflow_library/cad/model.py +255 -0
- knexflow-0.2.0/knexflow_library/cad/parts.py +90 -0
- knexflow-0.2.0/knexflow_library/cad/templates.py +214 -0
- knexflow-0.2.0/knexflow_library/codegen.py +199 -0
- knexflow-0.2.0/knexflow_library/compiler.py +608 -0
- knexflow-0.2.0/knexflow_library/compiler_blocks.py +557 -0
- knexflow-0.2.0/knexflow_library/compiler_charts.py +1113 -0
- knexflow-0.2.0/knexflow_library/compiler_expressions.py +487 -0
- knexflow-0.2.0/knexflow_library/compiler_flow.py +1384 -0
- knexflow-0.2.0/knexflow_library/debugger.py +331 -0
- knexflow-0.2.0/knexflow_library/devices.py +625 -0
- knexflow-0.2.0/knexflow_library/disassembler.py +447 -0
- knexflow-0.2.0/knexflow_library/drive.py +637 -0
- knexflow-0.2.0/knexflow_library/formatter.py +475 -0
- knexflow-0.2.0/knexflow_library/image.py +832 -0
- knexflow-0.2.0/knexflow_library/ir.py +135 -0
- knexflow-0.2.0/knexflow_library/kinematics.py +321 -0
- knexflow-0.2.0/knexflow_library/ld_model.py +990 -0
- knexflow-0.2.0/knexflow_library/ld_transpiler.py +668 -0
- knexflow-0.2.0/knexflow_library/media.py +238 -0
- knexflow-0.2.0/knexflow_library/monitor.py +220 -0
- knexflow-0.2.0/knexflow_library/navigation/__init__.py +86 -0
- knexflow-0.2.0/knexflow_library/navigation/autonomous.py +473 -0
- knexflow-0.2.0/knexflow_library/navigation/navigator.py +222 -0
- knexflow-0.2.0/knexflow_library/navigation/pid.py +107 -0
- knexflow-0.2.0/knexflow_library/packages.py +480 -0
- knexflow-0.2.0/knexflow_library/parser.py +1162 -0
- knexflow-0.2.0/knexflow_library/probe.py +454 -0
- knexflow-0.2.0/knexflow_library/production.py +290 -0
- knexflow-0.2.0/knexflow_library/project.py +247 -0
- knexflow-0.2.0/knexflow_library/ros/__init__.py +100 -0
- knexflow-0.2.0/knexflow_library/ros/bridge.py +241 -0
- knexflow-0.2.0/knexflow_library/ros/kinematics.py +266 -0
- knexflow-0.2.0/knexflow_library/ros/messages.py +193 -0
- knexflow-0.2.0/knexflow_library/ros/node.py +158 -0
- knexflow-0.2.0/knexflow_library/ros/rviz.py +219 -0
- knexflow-0.2.0/knexflow_library/ros/watchdog.py +154 -0
- knexflow-0.2.0/knexflow_library/studio.py +740 -0
- knexflow-0.2.0/knexflow_library/synth.py +560 -0
- knexflow-0.2.0/knexflow_library/transport.py +545 -0
- knexflow-0.2.0/knexflow_library/tui.py +542 -0
- knexflow-0.2.0/knexflow_library/visual/__init__.py +47 -0
- knexflow-0.2.0/knexflow_library/visual/diagnostics.py +444 -0
- knexflow-0.2.0/knexflow_library/visual/html_view.py +124 -0
- knexflow-0.2.0/knexflow_library/visual/state.py +311 -0
- knexflow-0.2.0/knexflow_library/visual/svg_view.py +195 -0
- knexflow-0.2.0/knexflow_library/visual/telemetry_replay.py +320 -0
- knexflow-0.2.0/knexflow_library/visual/text_view.py +98 -0
- knexflow-0.2.0/knexflow_library/visual/timeline.py +782 -0
- knexflow-0.2.0/pyproject.toml +45 -0
- knexflow-0.2.0/setup.cfg +4 -0
knexflow-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
knexflow-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: knexflow
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Portable K'NEX Flow program library, controller compiler, and robotics SDK
|
|
5
|
+
Author-email: siegzeon0079 <davidg0079@gmail.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/siegzeon0079/knexflow-rework
|
|
8
|
+
Project-URL: Repository, https://github.com/siegzeon0079/knexflow-rework
|
|
9
|
+
Project-URL: Issues, https://github.com/siegzeon0079/knexflow-rework/issues
|
|
10
|
+
Keywords: knex,robotics,stem,education,usb-hid,blockly,compiler
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Topic :: Education
|
|
16
|
+
Classifier: Topic :: Software Development :: Compilers
|
|
17
|
+
Classifier: Topic :: System :: Hardware :: Universal Serial Bus (USB) :: Human Interface Device (HID)
|
|
18
|
+
Classifier: Intended Audience :: Education
|
|
19
|
+
Classifier: Intended Audience :: Developers
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Provides-Extra: hid
|
|
24
|
+
Requires-Dist: hidapi>=0.14; extra == "hid"
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
# K'NEX Flow Python library
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
This package is a cross-platform library for editing K'NEX Flow program
|
|
32
|
+
|
|
33
|
+
libraries, validating compiled-package JSON, and uploading compiled packages
|
|
34
|
+
|
|
35
|
+
into stored controller slots. It requires Python 3.10 or later. Library and
|
|
36
|
+
|
|
37
|
+
package validation use only the standard library.
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
## Install
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
From this directory:
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
```powershell
|
|
50
|
+
|
|
51
|
+
python -m pip install .
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
For USB HID uploads, install the optional `hidapi` backend:
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
```powershell
|
|
62
|
+
|
|
63
|
+
python -m pip install ".[hid]"
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
The HID backend depends on the operating system's USB HID permissions and
|
|
70
|
+
|
|
71
|
+
driver configuration. The package does not require the vendor Windows desktop
|
|
72
|
+
|
|
73
|
+
application for package validation or upload.
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
## Command-line interface (`python -m knexflow_library` or `knexflow`)
|
|
78
|
+
|
|
79
|
+
The CLI provides subcommands for bytecode disassembly, sound bundle management, hardware visualization, diagnostic reporting, backup management, and controller slot uploads:
|
|
80
|
+
|
|
81
|
+
```powershell
|
|
82
|
+
# 1. Disassemble controller bytecode (.knexpackage or compiled JSON):
|
|
83
|
+
python -m knexflow_library disasm path\to\program.knexpackage
|
|
84
|
+
python -m knexflow_library disasm path\to\program.json -o program.asm
|
|
85
|
+
|
|
86
|
+
# 2. Inspect sound assets or extract audio payloads from .knexsound bundles / packages:
|
|
87
|
+
python -m knexflow_library sounds path\to\robot_audio.knexsound
|
|
88
|
+
python -m knexflow_library sounds path\to\robot_audio.knexsound -x extracted_sounds\
|
|
89
|
+
|
|
90
|
+
# 3. Render hardware diagrams (terminal Unicode, SVG vector graphic, or HTML5 digital twin):
|
|
91
|
+
python -m knexflow_library visualize path\to\program.json --format terminal
|
|
92
|
+
python -m knexflow_library visualize path\to\program.json --format svg -o hardware.svg
|
|
93
|
+
python -m knexflow_library visualize path\to\program.json --format html --show
|
|
94
|
+
|
|
95
|
+
# 4. Analyze recorded telemetry runs and generate anomaly diagnostic reports:
|
|
96
|
+
python -m knexflow_library diagnostics path\to\telemetry.json --format terminal
|
|
97
|
+
python -m knexflow_library diagnostics path\to\telemetry.json --format markdown -o report.md
|
|
98
|
+
python -m knexflow_library diagnostics path\to\telemetry.json --format html -o report.html
|
|
99
|
+
|
|
100
|
+
# 5. Inspect and verify program library backups (legacy positional syntax also supported):
|
|
101
|
+
python -m knexflow_library backup path\to\library-backup.json
|
|
102
|
+
python -m knexflow_library backup path\to\library-backup.json --verify-only
|
|
103
|
+
|
|
104
|
+
# 6. Upload compiled package to a stored controller slot (0-9):
|
|
105
|
+
python -m knexflow_library upload path\to\compiled-package.json --slot 0 --yes
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Program library
|
|
109
|
+
|
|
110
|
+
The version-1 JSON backup envelope remains compatible with the browser app:
|
|
111
|
+
|
|
112
|
+
```powershell
|
|
113
|
+
python -m knexflow_library path\to\library-backup.json
|
|
114
|
+
python -m knexflow_library --verify-only path\to\library-backup.json
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
The API includes `create_text_program`, `create_blocks_program`,
|
|
120
|
+
|
|
121
|
+
`update_program`, `duplicate_program`, `load_backup`, and `save_backup`.
|
|
122
|
+
|
|
123
|
+
Program XML and source text remain user data; backup operations do not parse or
|
|
124
|
+
|
|
125
|
+
execute either language.
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
## Compiled packages and upload
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
`CompiledProgram.from_manifest` validates the browser-compatible compiler JSON
|
|
134
|
+
|
|
135
|
+
areas (base64 encoding, fixed area sizes, usable lengths, and sound directory
|
|
136
|
+
|
|
137
|
+
checksums). A `ProgramUploader` accepts a validated package and a
|
|
138
|
+
|
|
139
|
+
`ReportTransport`; it sends the HID download protocol to stored slots 0-9 and
|
|
140
|
+
|
|
141
|
+
checks the controller's slot-presence response. A mock transport can be used
|
|
142
|
+
|
|
143
|
+
for tests or alternative cross-platform HID implementations.
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
To upload from the CLI, connect the controller and specify the target slot:
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
```powershell
|
|
152
|
+
|
|
153
|
+
python -m knexflow_library --upload-package path\to\compiled-package.json --slot 0
|
|
154
|
+
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
The command confirms before replacing a stored slot. `--yes` bypasses that
|
|
160
|
+
|
|
161
|
+
prompt. Upload does **not** start or resume a program; starting remains outside
|
|
162
|
+
|
|
163
|
+
the Python uploader API. Do not confuse a stored-slot upload with temporary
|
|
164
|
+
|
|
165
|
+
development-program staging.
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
## Compiler status
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
The experimental pure-Python compiler supports linear Blockly charts and
|
|
174
|
+
|
|
175
|
+
bounded `knex_repeat` blocks, expanded into linear actions, with numeric
|
|
176
|
+
|
|
177
|
+
arithmetic expressions in `knex_wait`, constant-speed `knex_motor_run`, and
|
|
178
|
+
|
|
179
|
+
single-motor `knex_motor_rotations`, plus optional
|
|
180
|
+
|
|
181
|
+
`knex_motor_pair`, `knex_stop_motors` blocks targeting `all`, `knex_output_value` (TriLED channels 0 and 1; off, red, green, yellow, notset), and compile-time sensor configuration blocks `knex_sensor_led` and `knex_sensor_gain` (ports 1-6, LED ON/OFF, gain 0-2). Paired motors
|
|
182
|
+
|
|
183
|
+
support independent ports, directions, and speeds, with continuous or
|
|
184
|
+
|
|
185
|
+
rotation-limited actions. Rotation actions wait for the selected motors to
|
|
186
|
+
|
|
187
|
+
finish. If a motor chart does not end in a stop-all block, a safety stop is
|
|
188
|
+
|
|
189
|
+
appended, matching the official compiler. That compiler's generated safety
|
|
190
|
+
|
|
191
|
+
stop also includes Port A when it was not selected; the Python output preserves
|
|
192
|
+
|
|
193
|
+
that observed behavior.
|
|
194
|
+
|
|
195
|
+
Literal rotation counts are limited to 0.1 to 1000.
|
|
196
|
+
|
|
197
|
+
Supported expression operators are `+`, `-`, `*`, `/`, unary minus, and
|
|
198
|
+
|
|
199
|
+
parentheses over numeric literals. Official wait, motor, arithmetic, rotation,
|
|
200
|
+
|
|
201
|
+
coordinated-motor, bounded-repeat, numeric-variable, distance-conditional, sensor-configuration, display block, bounded while loop, and named procedure fixtures match
|
|
202
|
+
|
|
203
|
+
byte-for-byte, including package header and code area when given each fixture
|
|
204
|
+
|
|
205
|
+
timestamp. Other variable uses, sensor expressions, and chained
|
|
206
|
+
|
|
207
|
+
same-precedence operators outside the vendor grammar are rejected. Repeat counts must be
|
|
208
|
+
|
|
209
|
+
integer literals from 1 to 100, nested repeat depth is limited to 8, and
|
|
210
|
+
|
|
211
|
+
expanded programs are limited to 250 blocks.
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
Official reference fixtures and timestamp/volatile-byte notes are in
|
|
216
|
+
|
|
217
|
+
`../tests/fixtures/compiler/`. Add a fixture and an exact Python comparison
|
|
218
|
+
|
|
219
|
+
before extending the compiler with each new instruction family. Other variable
|
|
220
|
+
|
|
221
|
+
constructs, sensor actions, other conditional forms, loops, procedures, sounds, and
|
|
222
|
+
|
|
223
|
+
images are not implemented. Repeat blocks are statically expanded; they are
|
|
224
|
+
|
|
225
|
+
not runtime loops. Conditional support is limited to one `knex_if_variable`,
|
|
226
|
+
|
|
227
|
+
`knex_if_sensor_distance`, or `knex_if_boolean` (push-button) per chart. Numeric conditions may read assigned
|
|
228
|
+
|
|
229
|
+
variables; distance conditions use a port from 1 to 6 and a numeric or
|
|
230
|
+
|
|
231
|
+
previously assigned variable threshold in millimetres. Branches support waits,
|
|
232
|
+
|
|
233
|
+
constant-speed motor runs, single-motor rotations, coordinated-motor
|
|
234
|
+
|
|
235
|
+
actions, output values, and LCD display commands (clear LCD and print text on lines 0-3). Any chart with a motor branch must end with an explicit stop-all
|
|
236
|
+
|
|
237
|
+
continuation; automatic branch safety stops and unverified motor action types
|
|
238
|
+
|
|
239
|
+
are not implemented. Rotations use fixture-verified motor completion wait
|
|
240
|
+
|
|
241
|
+
masks. Branch addresses are linked to fixture-verified native byte offsets.
|
|
242
|
+
|
|
243
|
+
Unassigned-variable reads, sensor conditions other than distance and button, and
|
|
244
|
+
|
|
245
|
+
nested/multiple conditionals are rejected. Push-button conditions use `button(port)`
|
|
246
|
+
|
|
247
|
+
from ports 1 to 6 compared with 0 or 1 using `==` or `!=`. Distance conditions declare the
|
|
248
|
+
|
|
249
|
+
selected sensor requirement. Current distance fixtures cover ports 1, 2, 3,
|
|
250
|
+
|
|
251
|
+
4, 5, and 6; all six comparison operators; and literal, arithmetic,
|
|
252
|
+
|
|
253
|
+
assigned-variable, and variable-arithmetic thresholds. The compiler supports numeric
|
|
254
|
+
|
|
255
|
+
`knex_variable_set` assignments before the conditional, including reassignments
|
|
256
|
+
|
|
257
|
+
and arithmetic that reads variables assigned earlier in the chart. Variables
|
|
258
|
+
|
|
259
|
+
may also appear in either comparison expression. Reading an unassigned
|
|
260
|
+
|
|
261
|
+
variable, assigning after the conditional, and assignments inside branches
|
|
262
|
+
|
|
263
|
+
remain unsupported.
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
## High-level controller API (`KnexBox`)
|
|
268
|
+
|
|
269
|
+
For interactive or robotic scripting similar to PyTello, `knexflow_library.KnexBox` provides a fluent, object-oriented API for building and compiling controller programs:
|
|
270
|
+
|
|
271
|
+
```python
|
|
272
|
+
from knexflow_library import KnexBox
|
|
273
|
+
|
|
274
|
+
box = KnexBox("Rover")
|
|
275
|
+
box.motor("A", speed=50, direction="forward")
|
|
276
|
+
box.wait(1.5)
|
|
277
|
+
box.display_text(line=0, text="Moving...")
|
|
278
|
+
box.stop_all()
|
|
279
|
+
|
|
280
|
+
# Or with bounded while loops and variable assignments:
|
|
281
|
+
box.assign("count", 3)
|
|
282
|
+
with box.while_loop("count > 0", max_iterations=3):
|
|
283
|
+
box.motor("A", speed=40)
|
|
284
|
+
box.wait(1.0)
|
|
285
|
+
box.assign("count", "count - 1")
|
|
286
|
+
|
|
287
|
+
# Or modular named procedures:
|
|
288
|
+
box.call("step", times=2)
|
|
289
|
+
box.wait(1.0)
|
|
290
|
+
with box.procedure("step"):
|
|
291
|
+
box.motor("A", speed=50)
|
|
292
|
+
box.wait(0.5)
|
|
293
|
+
box.stop_all()
|
|
294
|
+
|
|
295
|
+
# Compile to validated bytecode
|
|
296
|
+
compiled = box.compile()
|
|
297
|
+
|
|
298
|
+
# Upload directly to slot 0 over USB HID (requires knexflow_library[hid])
|
|
299
|
+
# box.upload(slot=0)
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
## Hardware graphical representation (`knexflow_library.visual`)
|
|
303
|
+
|
|
304
|
+
The library includes a zero-dependency hardware visualization submodule that renders the physical K'NEX Control Box, 4 motor ports (A–D with direction/speed), 6 sensor ports (1–6 with distance/button/color states), 2 TriLED channels, and the 4-line LCD screen:
|
|
305
|
+
|
|
306
|
+
```python
|
|
307
|
+
# 1. Console Unicode dashboard (instant view in PyCharm/terminal):
|
|
308
|
+
print(box.hardware_dashboard())
|
|
309
|
+
|
|
310
|
+
# 2. Export vector SVG graphic (previews directly in PyCharm):
|
|
311
|
+
box.hardware_svg("rover_hardware.svg")
|
|
312
|
+
|
|
313
|
+
# 3. Open interactive digital twin in the default web browser:
|
|
314
|
+
box.show_hardware()
|
|
315
|
+
|
|
316
|
+
# 4. Interactive execution timeline & step-by-step scrubber:
|
|
317
|
+
print(box.timeline_dashboard()) # Terminal ASCII/Unicode table
|
|
318
|
+
box.show_timeline() # Browser player with Play/Pause and scrubber
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
## Sound asset management (`knexflow_library.packages`)
|
|
322
|
+
|
|
323
|
+
The package subsystem provides official-compiler parity for inspecting, building, and packing compressed K'NEX sound assets (`131,072`-byte sound area):
|
|
324
|
+
|
|
325
|
+
```python
|
|
326
|
+
from knexflow_library import build_sound_area, parse_sound_area
|
|
327
|
+
|
|
328
|
+
# Build a sound area from raw compressed audio payloads:
|
|
329
|
+
area, length, checksum = build_sound_area([sound1_bytes, sound2_bytes])
|
|
330
|
+
|
|
331
|
+
# Inspect individual sound directory entries and payloads:
|
|
332
|
+
entries = parse_sound_area(area, length, checksum)
|
|
333
|
+
for entry in entries:
|
|
334
|
+
print(f"Sound {entry.index}: {entry.length} bytes at [{entry.start_offset}:{entry.end_offset}]")
|
|
335
|
+
|
|
336
|
+
# Attach sound assets to a KnexBox or compiled package:
|
|
337
|
+
box.set_sounds([sound1_bytes, sound2_bytes])
|
|
338
|
+
compiled = box.compile()
|
|
339
|
+
print(compiled.sounds) # Tuple of SoundDirectoryEntry
|
|
340
|
+
sound_blobs = compiled.extract_sounds()
|
|
341
|
+
|
|
342
|
+
# Export or import portable .knexsound bundles (zip archives with manifest):
|
|
343
|
+
box.export_sound_bundle("robot_audio.knexsound")
|
|
344
|
+
box.load_sound_bundle("robot_audio.knexsound")
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
## Telemetry replay bridge (`knexflow_library.visual`)
|
|
348
|
+
|
|
349
|
+
Decode raw USB HID telemetry reports and replay recorded runs into the interactive digital twin:
|
|
350
|
+
|
|
351
|
+
```python
|
|
352
|
+
from knexflow_library.visual import TelemetryDecoder, replay_telemetry_to_timeline
|
|
353
|
+
|
|
354
|
+
# Replay a recorded sequence of timestamped raw packets or telemetry dictionaries:
|
|
355
|
+
timeline = box.replay_telemetry(recorded_packets, title="Diagnostic Run 5")
|
|
356
|
+
print(timeline.render_dashboard())
|
|
357
|
+
timeline.show()
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
## Offline diagnostic reporting (`knexflow_library.visual.diagnostics`)
|
|
361
|
+
|
|
362
|
+
Analyze recorded controller sessions, detect hardware/interpreter anomalies (low battery, motor stalls, stop codes), and generate structured diagnostic reports in Markdown, HTML, or Terminal formats:
|
|
363
|
+
|
|
364
|
+
```python
|
|
365
|
+
from knexflow_library import analyze_telemetry, generate_diagnostic_report
|
|
366
|
+
|
|
367
|
+
# 1. Quick terminal summary table:
|
|
368
|
+
print(box.diagnostic_summary(telemetry_records))
|
|
369
|
+
|
|
370
|
+
# 2. Export full Markdown or HTML report:
|
|
371
|
+
box.generate_diagnostic_report(telemetry_records, output_path="diagnostic_run.md", format="markdown")
|
|
372
|
+
box.generate_diagnostic_report(telemetry_records, output_path="diagnostic_run.html", format="html")
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
## Tone and melody generator (`knexflow_library.audio`)
|
|
376
|
+
|
|
377
|
+
Compose musical tones and melodies similar to mBot / buzzer APIs with 12-TET note resolution (`C3`–`C6`), standard beat fraction timings (`whole`, `half`, `quarter`, `eighth`, `sixteenth`), and offline WAV generation:
|
|
378
|
+
|
|
379
|
+
> [!NOTE]
|
|
380
|
+
> **Hardware Compatibility**: The K'NEX Control Box firmware does not have a raw tone frequency generator opcode (official audio relies on opcode `0x0A OutputSound` pointing to compressed sound payloads in the ISD2130 chip sound area). Tones preview interactively in the browser timeline player (`box.show_timeline()`) and can be exported to standard WAV files (`generate_tone_wav`). When programs containing tone blocks are compiled to controller packages (`box.compile()`), tone blocks are lowered to equivalent duration pauses (`knex_wait`) to preserve package validity without sending unverified opcodes to the hardware.
|
|
381
|
+
|
|
382
|
+
```python
|
|
383
|
+
from knexflow_library import generate_tone_wav, generate_melody_wav
|
|
384
|
+
|
|
385
|
+
# 1. Fluent box tone and melody programming:
|
|
386
|
+
box.tone("C4", 0.5) # Play 261.63 Hz for 0.5s
|
|
387
|
+
box.play_note("G4", "quarter") # Play note G4 at current BPM (default 120 BPM = 0.5s)
|
|
388
|
+
box.beep(880, 0.1) # Play quick 880 Hz beep
|
|
389
|
+
box.play_melody([ # Play sequenced melody
|
|
390
|
+
("C4", "quarter"),
|
|
391
|
+
("E4", "quarter"),
|
|
392
|
+
("G4", "half"),
|
|
393
|
+
("rest", "quarter"),
|
|
394
|
+
], bpm=120)
|
|
395
|
+
|
|
396
|
+
# 2. Offline audio synthesis to 16-bit PCM WAV (zero external dependencies):
|
|
397
|
+
wav_data = generate_tone_wav("A4", duration_seconds=1.0)
|
|
398
|
+
melody_wav = generate_melody_wav([("C4", "quarter"), ("G4", "half")], bpm=120)
|
|
399
|
+
|
|
400
|
+
# 3. Interactive Web Audio preview:
|
|
401
|
+
# Tones play back automatically via the browser Web Audio API in the timeline player:
|
|
402
|
+
box.show_timeline()
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
## Bytecode disassembly inspection (`knexflow_library.disassembler`)
|
|
406
|
+
|
|
407
|
+
Inspect compiled controller p-code with mnemonics, byte addresses, and parameter decoding:
|
|
408
|
+
|
|
409
|
+
```python
|
|
410
|
+
# 1. Disassemble directly from KnexBox:
|
|
411
|
+
print(box.disassemble())
|
|
412
|
+
|
|
413
|
+
# 2. Disassemble a compiled package or official fixture:
|
|
414
|
+
compiled = box.compile()
|
|
415
|
+
print(compiled.disassemble())
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
## Tests
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
Run the standard-library tests from the repository root:
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
```powershell
|
|
427
|
+
|
|
428
|
+
python -m unittest discover -s tests\python -v
|
|
429
|
+
|
|
430
|
+
```
|
|
431
|
+
|