moons-motor 0.1.3__py3-none-any.whl → 0.1.4__py3-none-any.whl
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.
- moons_motor/motor.py +56 -5
- {moons_motor-0.1.3.dist-info → moons_motor-0.1.4.dist-info}/METADATA +5 -5
- {moons_motor-0.1.3.dist-info → moons_motor-0.1.4.dist-info}/RECORD +6 -6
- {moons_motor-0.1.3.dist-info → moons_motor-0.1.4.dist-info}/WHEEL +0 -0
- {moons_motor-0.1.3.dist-info → moons_motor-0.1.4.dist-info}/licenses/LICENSE +0 -0
- {moons_motor-0.1.3.dist-info → moons_motor-0.1.4.dist-info}/top_level.txt +0 -0
moons_motor/motor.py
CHANGED
@@ -52,6 +52,7 @@ class StepperCommand:
|
|
52
52
|
SET_RETURN_FORMAT_HEXADECIMAL: str = "IFH" # Set return format to hexadecimal
|
53
53
|
|
54
54
|
SET_TRANSMIT_DELAY: str = "TD" # Set transmit delay
|
55
|
+
REQUEST_STATUS: str = "RS" # Request status
|
55
56
|
|
56
57
|
|
57
58
|
class MoonsStepper(Subject):
|
@@ -357,6 +358,32 @@ class MoonsStepper(Subject):
|
|
357
358
|
# self.set_return_format_dexcimal(motor_address)
|
358
359
|
|
359
360
|
def home(self, motor_address="", speed=0.3, onComplete=None):
|
361
|
+
homing_complete = threading.Event() # Shared event to signal completion
|
362
|
+
|
363
|
+
def check_status(response):
|
364
|
+
result = MoonsStepper.process_response(response)
|
365
|
+
print(f"[bold blue]Status check result:[/bold blue] {result}")
|
366
|
+
if "H" not in result["value"]:
|
367
|
+
print("[bold green]Motor is homed.[/bold green]")
|
368
|
+
if onComplete: # Call the onComplete callback if provided
|
369
|
+
onComplete(result)
|
370
|
+
homing_complete.set() # Signal that homing is complete
|
371
|
+
else:
|
372
|
+
print("[bold yellow]Motor is not homed yet.[/bold yellow]")
|
373
|
+
|
374
|
+
def check_homing_complete():
|
375
|
+
while not homing_complete.is_set(): # Loop until homing is complete
|
376
|
+
self.get_status(
|
377
|
+
motor_address=motor_address,
|
378
|
+
command=StepperCommand.REQUEST_STATUS,
|
379
|
+
callback=check_status,
|
380
|
+
)
|
381
|
+
time.sleep(0.3)
|
382
|
+
|
383
|
+
home_thread = threading.Thread(
|
384
|
+
target=check_homing_complete,
|
385
|
+
daemon=True,
|
386
|
+
)
|
360
387
|
self.send_command(
|
361
388
|
address=motor_address, command=StepperCommand.VELOCITY, value=speed
|
362
389
|
)
|
@@ -364,15 +391,12 @@ class MoonsStepper(Subject):
|
|
364
391
|
address=motor_address, command=StepperCommand.HOME, value="3F"
|
365
392
|
)
|
366
393
|
self.send_command(
|
367
|
-
address=motor_address, command=StepperCommand.ENCODER_POSITION
|
394
|
+
address=motor_address, command=StepperCommand.ENCODER_POSITION, value=0
|
368
395
|
)
|
369
396
|
self.send_command(
|
370
397
|
address=motor_address, command=StepperCommand.SET_POSITION, value=0
|
371
398
|
)
|
372
|
-
|
373
|
-
self.get_status(
|
374
|
-
motor_address, StepperCommand.SET_POSITION, callback=onComplete
|
375
|
-
)
|
399
|
+
home_thread.start()
|
376
400
|
|
377
401
|
# endregion
|
378
402
|
def get_status(self, motor_address, command: StepperCommand, callback=None):
|
@@ -381,6 +405,33 @@ class MoonsStepper(Subject):
|
|
381
405
|
self.pending_callbacks.put_nowait(callback)
|
382
406
|
self.sendQueue.put_nowait(command)
|
383
407
|
|
408
|
+
def decode_status(status_code):
|
409
|
+
"""
|
410
|
+
Decode the status code from the motor.
|
411
|
+
"""
|
412
|
+
status = {
|
413
|
+
"A": "An Alarm code is present (use AL command to see code, AR command to clear code)",
|
414
|
+
"D": "Disabled (the drive is disabled)",
|
415
|
+
"E": "Drive Fault (drive must be reset by AR command to clear this fault)",
|
416
|
+
"F": "Motor moving",
|
417
|
+
"H": "Homing (SH in progress)",
|
418
|
+
"J": "Jogging (CJ in progress)",
|
419
|
+
"M": "Motion in progress (Feed & Jog Commands)",
|
420
|
+
"P": "In position",
|
421
|
+
"R": "Ready (Drive is enabled and ready)",
|
422
|
+
"S": "Stopping a motion (ST or SK command executing)",
|
423
|
+
"T": "Wait Time (WT command executing)",
|
424
|
+
"W": "Wait Input (WI command executing)",
|
425
|
+
}
|
426
|
+
status_string = ""
|
427
|
+
for char in status_code:
|
428
|
+
if char in status:
|
429
|
+
status_string += status[char]
|
430
|
+
status_string += "\n"
|
431
|
+
else:
|
432
|
+
status_string += f"Unknown status code: {char}"
|
433
|
+
return status_string
|
434
|
+
|
384
435
|
# endregion
|
385
436
|
|
386
437
|
# region utility functions
|
@@ -1,10 +1,10 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: moons_motor
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.4
|
4
4
|
Summary: This is a python library for controlling the Moons' motor through the serial port.
|
5
5
|
Author-email: miroc <mike8503111@gmail.com>
|
6
6
|
Project-URL: Repository, https://github.com/miroc99/moons_motor.git
|
7
|
-
Classifier: Development Status ::
|
7
|
+
Classifier: Development Status :: 4 - Beta
|
8
8
|
Classifier: Intended Audience :: Developers
|
9
9
|
Classifier: Topic :: Terminals :: Serial
|
10
10
|
Classifier: License :: OSI Approved :: MIT License
|
@@ -38,7 +38,7 @@ python -m pip install moons_motor
|
|
38
38
|
## Usage
|
39
39
|
|
40
40
|
```python
|
41
|
-
from motor import MoonsStepper, StepperModules
|
41
|
+
from motor import MoonsStepper, StepperModules, StepperCommand
|
42
42
|
import simulate
|
43
43
|
from time import sleep
|
44
44
|
|
@@ -47,9 +47,9 @@ motor = MoonsStepper(StepperModules.STM17S_3RN, "0403", "6001", "TESTA")
|
|
47
47
|
MoonsStepper.list_all_ports()
|
48
48
|
motor.connect()
|
49
49
|
|
50
|
-
motor.
|
50
|
+
motor.send_command(address="@", command=StepperCommand.JOG)
|
51
51
|
sleep(5)
|
52
|
-
motor.
|
52
|
+
motor.send_command(address="@", command=StepperCommand.STOP_JOG)
|
53
53
|
|
54
54
|
```
|
55
55
|
|
@@ -1,11 +1,11 @@
|
|
1
1
|
moons_motor/__init__.py,sha256=qOpsRwizV-DpKSvNzyvj8ju3cs6vwgIICur1Oe6sxOA,27
|
2
|
-
moons_motor/motor.py,sha256=
|
2
|
+
moons_motor/motor.py,sha256=ZXXX6Ie-PL5QN8O-JpMVGh9xgYSsQpJM0BsqiVbtdns,15521
|
3
3
|
moons_motor/observer.py,sha256=PXzuPYKRb2HpjArJcD8HakYIPfFGAs1uBDIL8PSizgA,124
|
4
4
|
moons_motor/simulate.py,sha256=J0y1fZhoOim9i-BAkprxnPern1SAdkDfKPqT2MWyDwU,2561
|
5
5
|
moons_motor/status.py,sha256=jXQZFZTt9ugHktkWKLII8MpEQQaeO-UjlwTrrP4LJNE,2872
|
6
6
|
moons_motor/subject.py,sha256=L_GS6fvJTeX7X23o3T92oiZ4rtLVKA2OEd9GpHn_Dz4,445
|
7
|
-
moons_motor-0.1.
|
8
|
-
moons_motor-0.1.
|
9
|
-
moons_motor-0.1.
|
10
|
-
moons_motor-0.1.
|
11
|
-
moons_motor-0.1.
|
7
|
+
moons_motor-0.1.4.dist-info/licenses/LICENSE,sha256=nsYjO800SjIjI85y2kVHR5mC3tca2vs4kK_BhNe89bM,1074
|
8
|
+
moons_motor-0.1.4.dist-info/METADATA,sha256=OfYNsukji4MOjMxTBk87GHo1Y4GH5eQFkfpLY8czulE,1403
|
9
|
+
moons_motor-0.1.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
10
|
+
moons_motor-0.1.4.dist-info/top_level.txt,sha256=0dE-CR5_NYBw34jHIDGQNWpMllzO6mtUIuKyRv_rJLg,12
|
11
|
+
moons_motor-0.1.4.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|