moons-motor 0.0.8__tar.gz → 0.0.10__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {moons_motor-0.0.8 → moons_motor-0.0.10}/PKG-INFO +8 -1
- {moons_motor-0.0.8 → moons_motor-0.0.10}/README.md +7 -0
- {moons_motor-0.0.8 → moons_motor-0.0.10}/moons_motor/motor.py +130 -55
- {moons_motor-0.0.8 → moons_motor-0.0.10}/moons_motor.egg-info/PKG-INFO +8 -1
- {moons_motor-0.0.8 → moons_motor-0.0.10}/pyproject.toml +1 -1
- {moons_motor-0.0.8 → moons_motor-0.0.10}/LICENSE +0 -0
- {moons_motor-0.0.8 → moons_motor-0.0.10}/moons_motor/__init__.py +0 -0
- {moons_motor-0.0.8 → moons_motor-0.0.10}/moons_motor/observer.py +0 -0
- {moons_motor-0.0.8 → moons_motor-0.0.10}/moons_motor/simulate.py +0 -0
- {moons_motor-0.0.8 → moons_motor-0.0.10}/moons_motor/status.py +0 -0
- {moons_motor-0.0.8 → moons_motor-0.0.10}/moons_motor/subject.py +0 -0
- {moons_motor-0.0.8 → moons_motor-0.0.10}/moons_motor.egg-info/SOURCES.txt +0 -0
- {moons_motor-0.0.8 → moons_motor-0.0.10}/moons_motor.egg-info/dependency_links.txt +0 -0
- {moons_motor-0.0.8 → moons_motor-0.0.10}/moons_motor.egg-info/requires.txt +0 -0
- {moons_motor-0.0.8 → moons_motor-0.0.10}/moons_motor.egg-info/top_level.txt +0 -0
- {moons_motor-0.0.8 → moons_motor-0.0.10}/setup.cfg +0 -0
- {moons_motor-0.0.8 → moons_motor-0.0.10}/setup.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: moons_motor
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.10
|
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
|
@@ -22,15 +22,20 @@ Requires-Dist: requests
|
|
22
22
|
This is a python library for control moons motor through serial port.
|
23
23
|
|
24
24
|
## Compatibility
|
25
|
+
|
25
26
|
Now only support Windows.
|
26
27
|
|
27
28
|
## Installing
|
29
|
+
|
28
30
|
Install through `pip`
|
31
|
+
|
29
32
|
```bash
|
30
33
|
python -m pip install moons_motor
|
31
34
|
|
32
35
|
```
|
36
|
+
|
33
37
|
## Usage
|
38
|
+
|
34
39
|
```python
|
35
40
|
from motor import MoonsStepper, StepperModules
|
36
41
|
import simulate
|
@@ -46,7 +51,9 @@ sleep(5)
|
|
46
51
|
motor.stop_jog()
|
47
52
|
|
48
53
|
```
|
54
|
+
|
49
55
|
## Tested Motor
|
56
|
+
|
50
57
|
1. STM17S-3RN
|
51
58
|
|
52
59
|
## Reference
|
@@ -3,15 +3,20 @@
|
|
3
3
|
This is a python library for control moons motor through serial port.
|
4
4
|
|
5
5
|
## Compatibility
|
6
|
+
|
6
7
|
Now only support Windows.
|
7
8
|
|
8
9
|
## Installing
|
10
|
+
|
9
11
|
Install through `pip`
|
12
|
+
|
10
13
|
```bash
|
11
14
|
python -m pip install moons_motor
|
12
15
|
|
13
16
|
```
|
17
|
+
|
14
18
|
## Usage
|
19
|
+
|
15
20
|
```python
|
16
21
|
from motor import MoonsStepper, StepperModules
|
17
22
|
import simulate
|
@@ -27,7 +32,9 @@ sleep(5)
|
|
27
32
|
motor.stop_jog()
|
28
33
|
|
29
34
|
```
|
35
|
+
|
30
36
|
## Tested Motor
|
37
|
+
|
31
38
|
1. STM17S-3RN
|
32
39
|
|
33
40
|
## Reference
|
@@ -147,25 +147,28 @@ class MoonsStepper(Subject):
|
|
147
147
|
ports = list(list_ports.comports())
|
148
148
|
for p in ports:
|
149
149
|
m = re.match(
|
150
|
-
r"USB\s*VID:PID=(\w+):(\w+)\s*SER=([A-Za-z0-9]
|
150
|
+
r"USB\s*VID:PID=(\w+):(\w+)\s*SER=([A-Za-z0-9]*)", p.usb_info()
|
151
151
|
)
|
152
|
+
print(m, p.usb_info())
|
152
153
|
if (
|
153
154
|
m
|
154
155
|
and m.group(1) == self.VID
|
155
156
|
and m.group(2) == self.PID
|
156
|
-
and m.group(3) == self.SERIAL_NUM
|
157
|
+
# and m.group(3) == self.SERIAL_NUM
|
157
158
|
):
|
158
|
-
print(
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
159
|
+
print("find vid pid match")
|
160
|
+
if m.group(3) == self.SERIAL_NUM or self.SERIAL_NUM == "":
|
161
|
+
print(
|
162
|
+
f"Device: {p.description} | VID: {m.group(1)} | PID: {m.group(2)} | SER: {m.group(3)} connected"
|
163
|
+
)
|
164
|
+
|
165
|
+
self.device = p.description
|
166
|
+
|
167
|
+
attempt_connect(p.device, baudrate)
|
168
|
+
if callback:
|
169
|
+
callback(self.device, self.Opened)
|
170
|
+
break
|
167
171
|
break
|
168
|
-
break
|
169
172
|
|
170
173
|
if self.only_simulate:
|
171
174
|
self.device = "Simulate"
|
@@ -210,6 +213,37 @@ class MoonsStepper(Subject):
|
|
210
213
|
else:
|
211
214
|
print(f"Target device is not opened. Command: {command}")
|
212
215
|
|
216
|
+
def read(self, timeout=1):
|
217
|
+
if self.ser is not None and self.ser.is_open:
|
218
|
+
print("reading...")
|
219
|
+
try:
|
220
|
+
start_time = time.time()
|
221
|
+
while time.time() - start_time < timeout:
|
222
|
+
if self.ser.in_waiting > 0:
|
223
|
+
response = self.ser.read(self.ser.in_waiting)
|
224
|
+
response = response.decode("utf-8").strip()
|
225
|
+
if self.is_log_message:
|
226
|
+
print(
|
227
|
+
f"[bold blue]Recv from {self.device} :[/bold blue] {response}"
|
228
|
+
)
|
229
|
+
return response
|
230
|
+
time.sleep(0.01)
|
231
|
+
print("reading timeout")
|
232
|
+
return None
|
233
|
+
except Exception as e:
|
234
|
+
print(f"Error when reading serial port: {str(e)}")
|
235
|
+
return None
|
236
|
+
elif self.only_simulate:
|
237
|
+
simulated_response = "simulate response"
|
238
|
+
if self.is_log_message:
|
239
|
+
print(
|
240
|
+
f"[bold blue]Recv from simulate device:[/bold blue] {simulated_response}"
|
241
|
+
)
|
242
|
+
return simulated_response
|
243
|
+
else:
|
244
|
+
print("Device not open, read fail.")
|
245
|
+
return None
|
246
|
+
|
213
247
|
# endregion
|
214
248
|
|
215
249
|
# region motor motion functions
|
@@ -278,63 +312,93 @@ class MoonsStepper(Subject):
|
|
278
312
|
# region motor status functions
|
279
313
|
def get_position(self, motor_address):
|
280
314
|
self.send(self.addressed_cmd(motor_address, "IP"))
|
281
|
-
self.
|
282
|
-
|
315
|
+
return self.read()
|
316
|
+
# self.new_value_event.wait(timeout=0.5)
|
317
|
+
# return self.get_value()
|
283
318
|
|
284
319
|
def get_temperature(self, motor_address):
|
285
320
|
self.send(self.addressed_cmd(motor_address, "IT"))
|
286
|
-
self.new_value_event.wait(timeout=0.5)
|
287
|
-
return
|
321
|
+
# self.new_value_event.wait(timeout=0.5)
|
322
|
+
return self.read()
|
323
|
+
# return int(self.get_value()) / 10
|
288
324
|
|
289
325
|
def get_sensor_status(self, motor_address):
|
290
326
|
self.send(self.addressed_cmd(motor_address, "IS"))
|
291
|
-
self.
|
292
|
-
|
327
|
+
return self.read()
|
328
|
+
# self.new_value_event.wait(timeout=0.5)
|
329
|
+
# return self.get_value()
|
293
330
|
|
294
331
|
def get_votalge(self, motor_address):
|
295
332
|
self.send(self.addressed_cmd(motor_address, "IU"))
|
296
|
-
self.
|
297
|
-
|
333
|
+
return self.read()
|
334
|
+
# self.new_value_event.wait(timeout=0.5)
|
335
|
+
# return self.get_value()
|
298
336
|
|
299
337
|
def get_acceleration(self, motor_address):
|
300
338
|
self.send(self.addressed_cmd(motor_address, "AC"))
|
301
|
-
self.
|
302
|
-
|
339
|
+
return self.read()
|
340
|
+
# self.new_value_event.wait(timeout=0.5)
|
341
|
+
# return self.get_value()
|
303
342
|
|
304
343
|
def get_deceleration(self, motor_address):
|
305
344
|
self.send(self.addressed_cmd(motor_address, "DE"))
|
306
|
-
self.
|
307
|
-
|
345
|
+
return self.read()
|
346
|
+
# self.new_value_event.wait(timeout=0.5)
|
347
|
+
# return self.get_value()
|
308
348
|
|
309
349
|
def get_velocity(self, motor_address):
|
310
350
|
self.send(self.addressed_cmd(motor_address, "VE"))
|
311
|
-
self.
|
312
|
-
|
351
|
+
return self.read()
|
352
|
+
# self.new_value_event.wait(timeout=0.5)
|
353
|
+
# return self.get_value()
|
313
354
|
|
314
355
|
def get_distance(self, motor_address):
|
315
356
|
self.send(self.addressed_cmd(motor_address, "DI"))
|
316
|
-
self.
|
317
|
-
|
357
|
+
return self.read()
|
358
|
+
# self.new_value_event.wait(timeout=0.5)
|
359
|
+
# return self.get_value()
|
318
360
|
|
319
361
|
def get_jog_speed(self, motor_address):
|
320
362
|
self.send(self.addressed_cmd(motor_address, "JS"))
|
321
|
-
self.new_value_event.wait(timeout=0.5)
|
322
|
-
return self.get_value()
|
363
|
+
# self.new_value_event.wait(timeout=0.5)
|
364
|
+
# return self.get_value()
|
365
|
+
return self.read()
|
323
366
|
|
324
|
-
def get_info(self, motor_address):
|
367
|
+
def get_info(self, motor_address, progress=None):
|
325
368
|
self.set_return_format_dexcimal(motor_address)
|
326
369
|
self.motor_wait(motor_address, 0.1)
|
370
|
+
totalInfoCount = 7
|
371
|
+
pos = self.extractValueFromResponse(self.get_position(motor_address))
|
372
|
+
if progress:
|
373
|
+
progress(round(1 / totalInfoCount, 1))
|
374
|
+
temp = (
|
375
|
+
int(self.extractValueFromResponse(self.get_temperature(motor_address))) / 10
|
376
|
+
)
|
377
|
+
if progress:
|
378
|
+
progress(round(2 / totalInfoCount, 1))
|
379
|
+
vol = int(self.extractValueFromResponse(self.get_votalge(motor_address))) / 10
|
380
|
+
if progress:
|
381
|
+
progress(round(3 / totalInfoCount, 1))
|
382
|
+
accel = self.extractValueFromResponse(self.get_acceleration(motor_address))
|
383
|
+
if progress:
|
384
|
+
progress(round(4 / totalInfoCount, 1))
|
385
|
+
decel = self.extractValueFromResponse(self.get_deceleration(motor_address))
|
386
|
+
if progress:
|
387
|
+
progress(round(5 / totalInfoCount, 1))
|
388
|
+
jogsp = self.extractValueFromResponse(self.get_jog_speed(motor_address))
|
389
|
+
if progress:
|
390
|
+
progress(round(6 / totalInfoCount, 1))
|
327
391
|
info = {
|
328
|
-
"pos":
|
329
|
-
"temp":
|
330
|
-
"
|
331
|
-
"
|
332
|
-
"
|
333
|
-
"
|
334
|
-
"vel": str(self.get_velocity(motor_address)),
|
335
|
-
"dis": str(self.get_distance(motor_address)),
|
336
|
-
"jogsp": str(self.get_jog_speed(motor_address)),
|
392
|
+
"pos": pos,
|
393
|
+
"temp": temp,
|
394
|
+
"vol": vol,
|
395
|
+
"accel": accel,
|
396
|
+
"decel": decel,
|
397
|
+
"jogsp": jogsp,
|
337
398
|
}
|
399
|
+
if progress:
|
400
|
+
progress(round(7 / totalInfoCount))
|
401
|
+
|
338
402
|
return info
|
339
403
|
|
340
404
|
def get_status(self, motor_address) -> str:
|
@@ -360,26 +424,37 @@ class MoonsStepper(Subject):
|
|
360
424
|
return f"~{command}"
|
361
425
|
return f"{motor_address}{command}"
|
362
426
|
|
427
|
+
def extractValueFromResponse(self, response):
|
428
|
+
pattern = r"=(.*)"
|
429
|
+
if response == None:
|
430
|
+
return None
|
431
|
+
result = re.search(pattern, response)
|
432
|
+
if result:
|
433
|
+
return result.group(1)
|
434
|
+
else:
|
435
|
+
return None
|
436
|
+
|
363
437
|
def get_value(self):
|
364
438
|
print("Waiting for value")
|
365
439
|
self.new_data_event.wait(timeout=0.5)
|
366
440
|
print("Recv:" + self.listeningBufferPre)
|
367
441
|
self.new_data_event.clear()
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
self.listeningBufferPre
|
378
|
-
self.
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
442
|
+
return self.listeningBufferPre
|
443
|
+
# if "%" in self.listeningBufferPre:
|
444
|
+
# return "success_ack"
|
445
|
+
# if "?" in self.listeningBufferPre:
|
446
|
+
# return "fail_ack"
|
447
|
+
# if "*" in self.listeningBufferPre:
|
448
|
+
# return "buffered_ack"
|
449
|
+
# self.new_value_event.set()
|
450
|
+
# pattern = r"=(\w+(?:\.\w+)?|\d+(?:\.\d+)?)"
|
451
|
+
# result = re.search(pattern, self.listeningBufferPre)
|
452
|
+
# self.listeningBufferPre = ""
|
453
|
+
# self.new_value_event.clear()
|
454
|
+
# if result:
|
455
|
+
# return result.group(1)
|
456
|
+
# else:
|
457
|
+
# return "No_value_found"
|
383
458
|
|
384
459
|
|
385
460
|
# endregion
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: moons_motor
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.10
|
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
|
@@ -22,15 +22,20 @@ Requires-Dist: requests
|
|
22
22
|
This is a python library for control moons motor through serial port.
|
23
23
|
|
24
24
|
## Compatibility
|
25
|
+
|
25
26
|
Now only support Windows.
|
26
27
|
|
27
28
|
## Installing
|
29
|
+
|
28
30
|
Install through `pip`
|
31
|
+
|
29
32
|
```bash
|
30
33
|
python -m pip install moons_motor
|
31
34
|
|
32
35
|
```
|
36
|
+
|
33
37
|
## Usage
|
38
|
+
|
34
39
|
```python
|
35
40
|
from motor import MoonsStepper, StepperModules
|
36
41
|
import simulate
|
@@ -46,7 +51,9 @@ sleep(5)
|
|
46
51
|
motor.stop_jog()
|
47
52
|
|
48
53
|
```
|
54
|
+
|
49
55
|
## Tested Motor
|
56
|
+
|
50
57
|
1. STM17S-3RN
|
51
58
|
|
52
59
|
## Reference
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
4
4
|
|
5
5
|
[project]
|
6
6
|
name = "moons_motor"
|
7
|
-
version = "0.0.
|
7
|
+
version = "0.0.10"
|
8
8
|
authors = [{ name = "miroc", email = "mike8503111@gmail.com" }]
|
9
9
|
description = "This is a python library for controlling the Moons' motor through the serial port."
|
10
10
|
readme = "README.md"
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|