moons-motor 0.0.9__py3-none-any.whl → 0.0.11__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- moons_motor/motor.py +116 -44
- {moons_motor-0.0.9.dist-info → moons_motor-0.0.11.dist-info}/METADATA +2 -2
- moons_motor-0.0.11.dist-info/RECORD +11 -0
- {moons_motor-0.0.9.dist-info → moons_motor-0.0.11.dist-info}/WHEEL +1 -1
- moons_motor-0.0.9.dist-info/RECORD +0 -11
- {moons_motor-0.0.9.dist-info → moons_motor-0.0.11.dist-info}/LICENSE +0 -0
- {moons_motor-0.0.9.dist-info → moons_motor-0.0.11.dist-info}/top_level.txt +0 -0
moons_motor/motor.py
CHANGED
@@ -213,6 +213,37 @@ class MoonsStepper(Subject):
|
|
213
213
|
else:
|
214
214
|
print(f"Target device is not opened. Command: {command}")
|
215
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
|
+
|
216
247
|
# endregion
|
217
248
|
|
218
249
|
# region motor motion functions
|
@@ -261,7 +292,7 @@ class MoonsStepper(Subject):
|
|
261
292
|
def calibrate(self, motor_address="", speed=0.3, onStart=None, onComplete=None):
|
262
293
|
self.send(self.addressed_cmd(motor_address, "VE{}".format(speed)))
|
263
294
|
# time.sleep(0.01)
|
264
|
-
self.send(self.addressed_cmd(motor_address, "DI10"))
|
295
|
+
# self.send(self.addressed_cmd(motor_address, "DI10"))
|
265
296
|
# time.sleep(0.01)
|
266
297
|
self.send(self.addressed_cmd(motor_address, "SH3F"))
|
267
298
|
# time.sleep(0.01)
|
@@ -281,63 +312,93 @@ class MoonsStepper(Subject):
|
|
281
312
|
# region motor status functions
|
282
313
|
def get_position(self, motor_address):
|
283
314
|
self.send(self.addressed_cmd(motor_address, "IP"))
|
284
|
-
self.
|
285
|
-
|
315
|
+
return self.read()
|
316
|
+
# self.new_value_event.wait(timeout=0.5)
|
317
|
+
# return self.get_value()
|
286
318
|
|
287
319
|
def get_temperature(self, motor_address):
|
288
320
|
self.send(self.addressed_cmd(motor_address, "IT"))
|
289
|
-
self.new_value_event.wait(timeout=0.5)
|
290
|
-
return
|
321
|
+
# self.new_value_event.wait(timeout=0.5)
|
322
|
+
return self.read()
|
323
|
+
# return int(self.get_value()) / 10
|
291
324
|
|
292
325
|
def get_sensor_status(self, motor_address):
|
293
326
|
self.send(self.addressed_cmd(motor_address, "IS"))
|
294
|
-
self.
|
295
|
-
|
327
|
+
return self.read()
|
328
|
+
# self.new_value_event.wait(timeout=0.5)
|
329
|
+
# return self.get_value()
|
296
330
|
|
297
331
|
def get_votalge(self, motor_address):
|
298
332
|
self.send(self.addressed_cmd(motor_address, "IU"))
|
299
|
-
self.
|
300
|
-
|
333
|
+
return self.read()
|
334
|
+
# self.new_value_event.wait(timeout=0.5)
|
335
|
+
# return self.get_value()
|
301
336
|
|
302
337
|
def get_acceleration(self, motor_address):
|
303
338
|
self.send(self.addressed_cmd(motor_address, "AC"))
|
304
|
-
self.
|
305
|
-
|
339
|
+
return self.read()
|
340
|
+
# self.new_value_event.wait(timeout=0.5)
|
341
|
+
# return self.get_value()
|
306
342
|
|
307
343
|
def get_deceleration(self, motor_address):
|
308
344
|
self.send(self.addressed_cmd(motor_address, "DE"))
|
309
|
-
self.
|
310
|
-
|
345
|
+
return self.read()
|
346
|
+
# self.new_value_event.wait(timeout=0.5)
|
347
|
+
# return self.get_value()
|
311
348
|
|
312
349
|
def get_velocity(self, motor_address):
|
313
350
|
self.send(self.addressed_cmd(motor_address, "VE"))
|
314
|
-
self.
|
315
|
-
|
351
|
+
return self.read()
|
352
|
+
# self.new_value_event.wait(timeout=0.5)
|
353
|
+
# return self.get_value()
|
316
354
|
|
317
355
|
def get_distance(self, motor_address):
|
318
356
|
self.send(self.addressed_cmd(motor_address, "DI"))
|
319
|
-
self.
|
320
|
-
|
357
|
+
return self.read()
|
358
|
+
# self.new_value_event.wait(timeout=0.5)
|
359
|
+
# return self.get_value()
|
321
360
|
|
322
361
|
def get_jog_speed(self, motor_address):
|
323
362
|
self.send(self.addressed_cmd(motor_address, "JS"))
|
324
|
-
self.new_value_event.wait(timeout=0.5)
|
325
|
-
return self.get_value()
|
363
|
+
# self.new_value_event.wait(timeout=0.5)
|
364
|
+
# return self.get_value()
|
365
|
+
return self.read()
|
326
366
|
|
327
|
-
def get_info(self, motor_address):
|
367
|
+
def get_info(self, motor_address, progress=None):
|
328
368
|
self.set_return_format_dexcimal(motor_address)
|
329
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))
|
330
391
|
info = {
|
331
|
-
"pos":
|
332
|
-
"temp":
|
333
|
-
"
|
334
|
-
"
|
335
|
-
"
|
336
|
-
"
|
337
|
-
"vel": str(self.get_velocity(motor_address)),
|
338
|
-
"dis": str(self.get_distance(motor_address)),
|
339
|
-
"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,
|
340
398
|
}
|
399
|
+
if progress:
|
400
|
+
progress(round(7 / totalInfoCount))
|
401
|
+
|
341
402
|
return info
|
342
403
|
|
343
404
|
def get_status(self, motor_address) -> str:
|
@@ -363,26 +424,37 @@ class MoonsStepper(Subject):
|
|
363
424
|
return f"~{command}"
|
364
425
|
return f"{motor_address}{command}"
|
365
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
|
+
|
366
437
|
def get_value(self):
|
367
438
|
print("Waiting for value")
|
368
439
|
self.new_data_event.wait(timeout=0.5)
|
369
440
|
print("Recv:" + self.listeningBufferPre)
|
370
441
|
self.new_data_event.clear()
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
self.listeningBufferPre
|
381
|
-
self.
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
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"
|
386
458
|
|
387
459
|
|
388
460
|
# endregion
|
@@ -1,6 +1,6 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.2
|
2
2
|
Name: moons_motor
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.11
|
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
|
@@ -0,0 +1,11 @@
|
|
1
|
+
moons_motor/__init__.py,sha256=qOpsRwizV-DpKSvNzyvj8ju3cs6vwgIICur1Oe6sxOA,27
|
2
|
+
moons_motor/motor.py,sha256=Fbp08XMgAjLiyGqFD-WXsGXBNrgCiclsopYxT0tq9Xk,16077
|
3
|
+
moons_motor/observer.py,sha256=PXzuPYKRb2HpjArJcD8HakYIPfFGAs1uBDIL8PSizgA,124
|
4
|
+
moons_motor/simulate.py,sha256=J0y1fZhoOim9i-BAkprxnPern1SAdkDfKPqT2MWyDwU,2561
|
5
|
+
moons_motor/status.py,sha256=jXQZFZTt9ugHktkWKLII8MpEQQaeO-UjlwTrrP4LJNE,2872
|
6
|
+
moons_motor/subject.py,sha256=L_GS6fvJTeX7X23o3T92oiZ4rtLVKA2OEd9GpHn_Dz4,445
|
7
|
+
moons_motor-0.0.11.dist-info/LICENSE,sha256=nsYjO800SjIjI85y2kVHR5mC3tca2vs4kK_BhNe89bM,1074
|
8
|
+
moons_motor-0.0.11.dist-info/METADATA,sha256=Pde70Xqjwl4hZmQZMig8ik6_T1XqutMWs5wkkAkTVdg,1282
|
9
|
+
moons_motor-0.0.11.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
10
|
+
moons_motor-0.0.11.dist-info/top_level.txt,sha256=0dE-CR5_NYBw34jHIDGQNWpMllzO6mtUIuKyRv_rJLg,12
|
11
|
+
moons_motor-0.0.11.dist-info/RECORD,,
|
@@ -1,11 +0,0 @@
|
|
1
|
-
moons_motor/__init__.py,sha256=qOpsRwizV-DpKSvNzyvj8ju3cs6vwgIICur1Oe6sxOA,27
|
2
|
-
moons_motor/motor.py,sha256=ruvSUhKlVk6v8Jxl7lDZ4tu4t953_jr6OWjgenIms0E,13416
|
3
|
-
moons_motor/observer.py,sha256=PXzuPYKRb2HpjArJcD8HakYIPfFGAs1uBDIL8PSizgA,124
|
4
|
-
moons_motor/simulate.py,sha256=J0y1fZhoOim9i-BAkprxnPern1SAdkDfKPqT2MWyDwU,2561
|
5
|
-
moons_motor/status.py,sha256=jXQZFZTt9ugHktkWKLII8MpEQQaeO-UjlwTrrP4LJNE,2872
|
6
|
-
moons_motor/subject.py,sha256=L_GS6fvJTeX7X23o3T92oiZ4rtLVKA2OEd9GpHn_Dz4,445
|
7
|
-
moons_motor-0.0.9.dist-info/LICENSE,sha256=nsYjO800SjIjI85y2kVHR5mC3tca2vs4kK_BhNe89bM,1074
|
8
|
-
moons_motor-0.0.9.dist-info/METADATA,sha256=Y1-ZVPTG9hPVDJqpQGv8pnTXBAZ0M9Ix0wenTL2vnrE,1281
|
9
|
-
moons_motor-0.0.9.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
|
10
|
-
moons_motor-0.0.9.dist-info/top_level.txt,sha256=0dE-CR5_NYBw34jHIDGQNWpMllzO6mtUIuKyRv_rJLg,12
|
11
|
-
moons_motor-0.0.9.dist-info/RECORD,,
|
File without changes
|
File without changes
|