smartpi 0.1.30__py3-none-any.whl → 0.1.32__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.
- smartpi/__init__.py +4 -2
- smartpi/base_driver.py +42 -127
- smartpi/led.py +6 -5
- smartpi/light_sensor.py +12 -0
- smartpi/motor.py +42 -35
- smartpi/servo.py +54 -46
- {smartpi-0.1.30.dist-info → smartpi-0.1.32.dist-info}/METADATA +7 -1
- {smartpi-0.1.30.dist-info → smartpi-0.1.32.dist-info}/RECORD +10 -10
- {smartpi-0.1.30.dist-info → smartpi-0.1.32.dist-info}/WHEEL +0 -0
- {smartpi-0.1.30.dist-info → smartpi-0.1.32.dist-info}/top_level.txt +0 -0
smartpi/__init__.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
from ._gui import gui
|
|
2
|
+
from .base_driver import P1, P2, P3, P4, P5, P6, M1, M2, M3, M4, M5, M6
|
|
2
3
|
|
|
3
|
-
__all__ = ["base_driver","gui","ultrasonic","touch_sensor","temperature","humidity","light_sensor","color_sensor","motor","servo","led","flash"
|
|
4
|
+
__all__ = ["base_driver","gui","ultrasonic","touch_sensor","temperature","humidity","light_sensor","color_sensor","motor","servo","led","flash",
|
|
5
|
+
"P1", "P2", "P3", "P4", "P5", "P6", "M1", "M2", "M3", "M4", "M5", "M6"]
|
|
4
6
|
|
|
5
|
-
__version__ = "0.1.
|
|
7
|
+
__version__ = "0.1.32"
|
|
6
8
|
|
smartpi/base_driver.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# coding=utf-8
|
|
2
|
-
import serial,time,struct,threading,fcntl
|
|
2
|
+
import serial,time,struct,threading,fcntl,os
|
|
3
3
|
from typing import List, Optional
|
|
4
4
|
from collections import deque
|
|
5
|
-
from . import servo,motor,cw2015
|
|
5
|
+
from . import servo,motor,cw2015,led,light_sensor
|
|
6
6
|
|
|
7
7
|
# 创建全局线程锁
|
|
8
8
|
serial_lock = threading.RLock()
|
|
@@ -49,6 +49,20 @@ MODE_CHANGE_L = 0X03
|
|
|
49
49
|
SEND_CYCLE_H = 0X01
|
|
50
50
|
SEND_CYCLE_L = 0X04
|
|
51
51
|
|
|
52
|
+
P1 = 1
|
|
53
|
+
P2 = 2
|
|
54
|
+
P3 = 3
|
|
55
|
+
P4 = 4
|
|
56
|
+
P5 = 5
|
|
57
|
+
P6 = 6
|
|
58
|
+
|
|
59
|
+
M1 = 1
|
|
60
|
+
M2 = 2
|
|
61
|
+
M3 = 3
|
|
62
|
+
M4 = 4
|
|
63
|
+
M5 = 5
|
|
64
|
+
M6 = 6
|
|
65
|
+
|
|
52
66
|
frames_queue = deque()
|
|
53
67
|
buffer = bytearray()
|
|
54
68
|
HEADER = bytes.fromhex('86 AB') # 帧头
|
|
@@ -119,7 +133,7 @@ def write_data(command_h: int, command_l: int, send_data: bytes= None) -> Option
|
|
|
119
133
|
# for x in send_bytes:
|
|
120
134
|
# print(f"{x:02X}", end=' ')
|
|
121
135
|
# print("\n")
|
|
122
|
-
|
|
136
|
+
buffer.clear()
|
|
123
137
|
ser.write(send_bytes)
|
|
124
138
|
|
|
125
139
|
|
|
@@ -267,25 +281,10 @@ def read_factory_data() -> Optional[bytes]:
|
|
|
267
281
|
|
|
268
282
|
"""读取硬件ID"""
|
|
269
283
|
def read_hardware_ID() -> Optional[bytes]:
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
while True:
|
|
275
|
-
response =process_received_data()
|
|
276
|
-
if response:
|
|
277
|
-
serial_lock.release() #释放线程锁
|
|
278
|
-
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
279
|
-
display_data = response[6:-3].decode(errors="ignore")
|
|
280
|
-
# print(f"硬件ID: {display_data}")
|
|
281
|
-
return display_data
|
|
282
|
-
else:
|
|
283
|
-
if time.time() - start_time > 3:
|
|
284
|
-
print("读取超时")
|
|
285
|
-
buffer.clear()
|
|
286
|
-
serial_lock.release() #释放线程锁
|
|
287
|
-
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
288
|
-
return None
|
|
284
|
+
result = os.popen("cat /proc/cpuinfo | grep Serial").read().strip()
|
|
285
|
+
if ":" in result:
|
|
286
|
+
return result.split(":")[1].strip()
|
|
287
|
+
return None
|
|
289
288
|
|
|
290
289
|
"""读取设备名称"""
|
|
291
290
|
def read_device_name() -> Optional[bytes]:
|
|
@@ -361,104 +360,6 @@ def read_battery() -> Optional[bytes]:
|
|
|
361
360
|
return sensor.get_soc(0)
|
|
362
361
|
else:
|
|
363
362
|
return None
|
|
364
|
-
|
|
365
|
-
###############################################################################固件升级
|
|
366
|
-
|
|
367
|
-
#"""下载更新请求"""
|
|
368
|
-
#def update_request() -> Optional[bytes]:
|
|
369
|
-
# write_data(UPDATE_REQUEST_H, UPDATE_REQUEST_L)
|
|
370
|
-
# start_time = time.time()
|
|
371
|
-
# while True:
|
|
372
|
-
# response =process_received_data()
|
|
373
|
-
# if response:
|
|
374
|
-
# display_data = response[6:-3].decode(errors="ignore")
|
|
375
|
-
# print(f"从机响应: {display_data}")
|
|
376
|
-
# return display_data
|
|
377
|
-
# else:
|
|
378
|
-
# if time.time() - start_time > 3:
|
|
379
|
-
# print("读取超时")
|
|
380
|
-
# buffer.clear()
|
|
381
|
-
# return None
|
|
382
|
-
#
|
|
383
|
-
#"""查询最大通讯长度"""
|
|
384
|
-
#def read_max_com_len() -> Optional[bytes]:
|
|
385
|
-
# write_data(MAX_COM_LEN_H, MAX_COM_LEN_L)
|
|
386
|
-
# start_time = time.time()
|
|
387
|
-
# while True:
|
|
388
|
-
# response =process_received_data()
|
|
389
|
-
# if response:
|
|
390
|
-
# display_data = response[6:-3].decode(errors="ignore")
|
|
391
|
-
# print(f"从机响应: {display_data}")
|
|
392
|
-
# return display_data
|
|
393
|
-
# else:
|
|
394
|
-
# if time.time() - start_time > 3:
|
|
395
|
-
# print("读取超时")
|
|
396
|
-
# buffer.clear()
|
|
397
|
-
# return None
|
|
398
|
-
#
|
|
399
|
-
#"""下载文件的信息"""
|
|
400
|
-
#def download_massage() -> Optional[bytes]:
|
|
401
|
-
# write_data(DL_MESSAGE_H, DL_MESSAGE_L, file_data)#文件信息来源从哪获取?
|
|
402
|
-
# start_time = time.time()
|
|
403
|
-
# while True:
|
|
404
|
-
# response =process_received_data()
|
|
405
|
-
# if response:
|
|
406
|
-
# display_data = response[6:-3].decode(errors="ignore")
|
|
407
|
-
# print(f"从机响应: {display_data}")
|
|
408
|
-
# return display_data
|
|
409
|
-
# else:
|
|
410
|
-
# if time.time() - start_time > 3:
|
|
411
|
-
# print("读取超时")
|
|
412
|
-
# buffer.clear()
|
|
413
|
-
# return None
|
|
414
|
-
#
|
|
415
|
-
#"""查询设备状态"""
|
|
416
|
-
#def read_device_status() -> Optional[bytes]:
|
|
417
|
-
# write_data(READ_STATUS_H, READ_STATUS_L)
|
|
418
|
-
# start_time = time.time()
|
|
419
|
-
# while True:
|
|
420
|
-
# response =process_received_data()
|
|
421
|
-
# if response:
|
|
422
|
-
# display_data = response[6:-3].decode(errors="ignore")
|
|
423
|
-
# print(f"从机响应: {display_data}")
|
|
424
|
-
# return display_data
|
|
425
|
-
# else:
|
|
426
|
-
# if time.time() - start_time > 3:
|
|
427
|
-
# print("读取超时")
|
|
428
|
-
# buffer.clear()
|
|
429
|
-
# return None
|
|
430
|
-
#
|
|
431
|
-
#"""发送页校验码"""
|
|
432
|
-
#def write_page_check() -> Optional[bytes]:
|
|
433
|
-
# write_data(PAGE_CHECK_H, PAGE_CHECK_L, page_check_data)
|
|
434
|
-
# start_time = time.time()
|
|
435
|
-
# while True:
|
|
436
|
-
# response =process_received_data()
|
|
437
|
-
# if response:
|
|
438
|
-
# display_data = response[6:-3].decode(errors="ignore")
|
|
439
|
-
# print(f"从机响应: {display_data}")
|
|
440
|
-
# return display_data
|
|
441
|
-
# else:
|
|
442
|
-
# if time.time() - start_time > 3:
|
|
443
|
-
# print("读取超时")
|
|
444
|
-
# buffer.clear()
|
|
445
|
-
# return None
|
|
446
|
-
#
|
|
447
|
-
#"""发送页数据"""
|
|
448
|
-
#def write_page_check() -> Optional[bytes]:
|
|
449
|
-
# write_data(PAGE_SEND_H, PAGE_SEND_L, page_send_data)
|
|
450
|
-
# start_time = time.time()
|
|
451
|
-
# while True:
|
|
452
|
-
# response =process_received_data()
|
|
453
|
-
# if response:
|
|
454
|
-
# display_data = response[6:-3].decode(errors="ignore")
|
|
455
|
-
# print(f"从机响应: {display_data}")
|
|
456
|
-
# return display_data
|
|
457
|
-
# else:
|
|
458
|
-
# if time.time() - start_time > 3:
|
|
459
|
-
# print("读取超时")
|
|
460
|
-
# buffer.clear()
|
|
461
|
-
# return None
|
|
462
363
|
|
|
463
364
|
###############################################################################读取传感器信息
|
|
464
365
|
|
|
@@ -614,12 +515,7 @@ def smartpi_init():
|
|
|
614
515
|
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
615
516
|
uart3_init()
|
|
616
517
|
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
617
|
-
|
|
618
|
-
P_port_init(2)
|
|
619
|
-
P_port_init(3)
|
|
620
|
-
P_port_init(4)
|
|
621
|
-
P_port_init(5)
|
|
622
|
-
P_port_init(6)
|
|
518
|
+
|
|
623
519
|
servo.set_init(1)
|
|
624
520
|
servo.set_init(2)
|
|
625
521
|
servo.set_init(3)
|
|
@@ -643,7 +539,26 @@ def smartpi_init():
|
|
|
643
539
|
motor.reset_motor_encoder(3)
|
|
644
540
|
motor.reset_motor_encoder(4)
|
|
645
541
|
motor.reset_motor_encoder(5)
|
|
646
|
-
motor.reset_motor_encoder(6)
|
|
542
|
+
motor.reset_motor_encoder(6)
|
|
543
|
+
light_sensor.turn_off(1)
|
|
544
|
+
light_sensor.turn_off(2)
|
|
545
|
+
light_sensor.turn_off(3)
|
|
546
|
+
light_sensor.turn_off(4)
|
|
547
|
+
light_sensor.turn_off(5)
|
|
548
|
+
light_sensor.turn_off(6)
|
|
549
|
+
led.set_color(1,0)
|
|
550
|
+
led.set_color(2,0)
|
|
551
|
+
led.set_color(3,0)
|
|
552
|
+
led.set_color(4,0)
|
|
553
|
+
led.set_color(5,0)
|
|
554
|
+
led.set_color(6,0)
|
|
555
|
+
P_port_init(1)
|
|
556
|
+
P_port_init(2)
|
|
557
|
+
P_port_init(3)
|
|
558
|
+
P_port_init(4)
|
|
559
|
+
P_port_init(5)
|
|
560
|
+
P_port_init(6)
|
|
561
|
+
|
|
647
562
|
time.sleep(0.1)
|
|
648
563
|
serial_lock.release()
|
|
649
564
|
time.sleep(0.1)
|
smartpi/led.py
CHANGED
|
@@ -9,9 +9,10 @@ def set_color(port:bytes,command:bytes) -> Optional[bytes]:
|
|
|
9
9
|
color_lamp_str=[0xA0, 0x05, 0x00, 0xBE]
|
|
10
10
|
color_lamp_str[0]=0XA0+port
|
|
11
11
|
color_lamp_str[2]=command
|
|
12
|
-
response = base_driver.single_operate_sensor(color_lamp_str,0)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
# response = base_driver.single_operate_sensor(color_lamp_str,0)
|
|
13
|
+
base_driver.write_data(0X01, 0X02, color_lamp_str)
|
|
14
|
+
# if response == None:
|
|
15
|
+
# return None
|
|
16
|
+
# else:
|
|
17
|
+
return 0
|
|
17
18
|
|
smartpi/light_sensor.py
CHANGED
|
@@ -3,6 +3,18 @@ import time
|
|
|
3
3
|
from typing import List, Optional
|
|
4
4
|
from smartpi import base_driver
|
|
5
5
|
|
|
6
|
+
#����ֵ��ȡ port:����P�˿ڣ� �������أ���ֵ����; ��ȡ����-1
|
|
7
|
+
def turn_off(port:bytes) -> Optional[bytes]:
|
|
8
|
+
light_str=[0xA0, 0x02, 0x00, 0xBE]
|
|
9
|
+
light_str[0]=0XA0+port
|
|
10
|
+
light_str[2]=0x03
|
|
11
|
+
# response = base_driver.single_operate_sensor(light_str,0)
|
|
12
|
+
# base_driver.write_data(0X01, 0X02, light_str)
|
|
13
|
+
# if response == None:
|
|
14
|
+
# return None
|
|
15
|
+
# else:
|
|
16
|
+
return 0
|
|
17
|
+
|
|
6
18
|
#����ֵ��ȡ port:����P�˿ڣ� �������أ���ֵ����; ��ȡ����-1
|
|
7
19
|
def get_value(port:bytes) -> Optional[bytes]:
|
|
8
20
|
light_str=[0xA0, 0x02, 0x00, 0xBE]
|
smartpi/motor.py
CHANGED
|
@@ -21,22 +21,24 @@ def get_motor_encoder(port:bytes) -> Optional[bytes]:
|
|
|
21
21
|
def reset_motor_encoder(port:bytes) -> Optional[bytes]:
|
|
22
22
|
motor_str=[0xA0, 0x01, 0x03, 0xBE]
|
|
23
23
|
motor_str[0]=0XA0+port
|
|
24
|
-
response = base_driver.single_operate_sensor(motor_str,0)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
# response = base_driver.single_operate_sensor(motor_str,0)
|
|
25
|
+
base_driver.write_data(0X01, 0X02, motor_str)
|
|
26
|
+
# if response == None:
|
|
27
|
+
# return None
|
|
28
|
+
# else:
|
|
29
|
+
return 0
|
|
29
30
|
|
|
30
31
|
#���﷽����� port:����M�˿ڣ�dir:0��1
|
|
31
32
|
def set_motor_direction(port:bytes,direc:bytes) -> Optional[bytes]:
|
|
32
33
|
motor_str=[0xA0, 0x01, 0x06, 0x71, 0x00, 0xBE]
|
|
33
34
|
motor_str[0]=0XA0+port
|
|
34
35
|
motor_str[4]=direc
|
|
35
|
-
response = base_driver.single_operate_sensor(motor_str,0)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
# response = base_driver.single_operate_sensor(motor_str,0)
|
|
37
|
+
base_driver.write_data(0X01, 0X02, motor_str)
|
|
38
|
+
# if response == None:
|
|
39
|
+
# return None
|
|
40
|
+
# else:
|
|
41
|
+
return 0
|
|
40
42
|
|
|
41
43
|
#�����ٶ�ת�� port:����M�˿ڣ�speed:-100~100
|
|
42
44
|
def set_motor(port:bytes,speed:int) -> Optional[bytes]:
|
|
@@ -53,21 +55,23 @@ def set_motor(port:bytes,speed:int) -> Optional[bytes]:
|
|
|
53
55
|
|
|
54
56
|
motor_str[4]=m_par
|
|
55
57
|
|
|
56
|
-
response = base_driver.single_operate_sensor(motor_str,0)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
# response = base_driver.single_operate_sensor(motor_str,0)
|
|
59
|
+
base_driver.write_data(0X01, 0X02, motor_str)
|
|
60
|
+
# if response == None:
|
|
61
|
+
# return None
|
|
62
|
+
# else:
|
|
63
|
+
return 0
|
|
61
64
|
|
|
62
65
|
#����ֹͣ port:����M�˿ڣ�
|
|
63
66
|
def set_motor_stop(port:bytes) -> Optional[bytes]:
|
|
64
67
|
motor_str=[0xA0, 0x01, 0x0B, 0xBE]
|
|
65
68
|
motor_str[0]=0XA0+port
|
|
66
|
-
response = base_driver.single_operate_sensor(motor_str,0)
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
# response = base_driver.single_operate_sensor(motor_str,0)
|
|
70
|
+
base_driver.write_data(0X01, 0X02, motor_str)
|
|
71
|
+
# if response == None:
|
|
72
|
+
# return None
|
|
73
|
+
# else:
|
|
74
|
+
return 0
|
|
71
75
|
|
|
72
76
|
#����Ƕȿ��� port:����M�˿ڣ�speed:-100~100��degree:0~65535
|
|
73
77
|
def set_motor_angle(port:bytes,speed:int,degree:int) -> Optional[bytes]:
|
|
@@ -86,11 +90,12 @@ def set_motor_angle(port:bytes,speed:int,degree:int) -> Optional[bytes]:
|
|
|
86
90
|
motor_str[4]=m_par
|
|
87
91
|
motor_str[6]=degree//256
|
|
88
92
|
motor_str[7]=degree%256
|
|
89
|
-
response = base_driver.single_operate_sensor(motor_str,0)
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
# response = base_driver.single_operate_sensor(motor_str,0)
|
|
94
|
+
base_driver.write_data(0X01, 0X02, motor_str)
|
|
95
|
+
# if response == None:
|
|
96
|
+
# return None
|
|
97
|
+
# else:
|
|
98
|
+
return 0
|
|
94
99
|
|
|
95
100
|
#���ﶨʱת�� port:����M�˿ڣ�speed:-100~100��second:1~256
|
|
96
101
|
def set_motor_second(port:bytes,speed:int,second:float) -> Optional[bytes]:
|
|
@@ -116,11 +121,12 @@ def set_motor_second(port:bytes,speed:int,second:float) -> Optional[bytes]:
|
|
|
116
121
|
motor_str[8]=byte_array[2]
|
|
117
122
|
motor_str[9]=byte_array[3]
|
|
118
123
|
|
|
119
|
-
response = base_driver.single_operate_sensor(motor_str,
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
+
# response = base_driver.single_operate_sensor(motor_str,0)
|
|
125
|
+
base_driver.write_data(0X01, 0X02, motor_str)
|
|
126
|
+
# if response == None:
|
|
127
|
+
# return None
|
|
128
|
+
# else:
|
|
129
|
+
return 0
|
|
124
130
|
|
|
125
131
|
#���ﶨ��ת�� port:����M�˿ڣ�speed:-100~100
|
|
126
132
|
def set_motor_constspeed(port:bytes,speed:int) -> Optional[bytes]:
|
|
@@ -138,11 +144,12 @@ def set_motor_constspeed(port:bytes,speed:int) -> Optional[bytes]:
|
|
|
138
144
|
|
|
139
145
|
motor_str[4]=m_par
|
|
140
146
|
|
|
141
|
-
response = base_driver.single_operate_sensor(motor_str,0)
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
147
|
+
# response = base_driver.single_operate_sensor(motor_str,0)
|
|
148
|
+
base_driver.write_data(0X01, 0X02, motor_str)
|
|
149
|
+
# if response == None:
|
|
150
|
+
# return None
|
|
151
|
+
# else:
|
|
152
|
+
return 0
|
|
146
153
|
|
|
147
154
|
#�����ٶȶ�ȡ port:����M�˿ڣ�
|
|
148
155
|
def get_motor_speed(port:bytes) -> Optional[bytes]:
|
smartpi/servo.py
CHANGED
|
@@ -3,17 +3,17 @@ import time
|
|
|
3
3
|
from typing import List, Optional
|
|
4
4
|
from smartpi import base_driver
|
|
5
5
|
|
|
6
|
-
|
|
7
6
|
#С������� port:����P�˿ڣ�angle:�Ƕ�0~270��
|
|
8
7
|
def steer_angle(port:bytes,angle:bytes) -> Optional[bytes]:
|
|
9
8
|
servo_str=[0xA0, 0x0E, 0x01, 0x71, 0x00, 0xBE]
|
|
10
9
|
servo_str[0]=0XA0+port
|
|
11
10
|
servo_str[4]=angle
|
|
12
|
-
response = base_driver.single_operate_sensor(servo_str,0)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
# response = base_driver.single_operate_sensor(servo_str,0)
|
|
12
|
+
base_driver.write_data(0X01, 0X02, servo_str)
|
|
13
|
+
# if response == None:
|
|
14
|
+
# return None
|
|
15
|
+
# else:
|
|
16
|
+
return 0
|
|
17
17
|
|
|
18
18
|
#С�����ʱ���� port:����P�˿ڣ�angle:�Ƕ�0~270��second:1~256
|
|
19
19
|
def steer_angle_delay(port:bytes,angle:bytes,second:bytes) -> Optional[bytes]:
|
|
@@ -22,22 +22,24 @@ def steer_angle_delay(port:bytes,angle:bytes,second:bytes) -> Optional[bytes]:
|
|
|
22
22
|
servo_str[4]=angle//256
|
|
23
23
|
servo_str[5]=angle%256
|
|
24
24
|
servo_str[7]=second
|
|
25
|
-
response = base_driver.single_operate_sensor(servo_str,0)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
# response = base_driver.single_operate_sensor(servo_str,0)
|
|
26
|
+
base_driver.write_data(0X01, 0X02, servo_str)
|
|
27
|
+
# if response == None:
|
|
28
|
+
# return None
|
|
29
|
+
# else:
|
|
30
|
+
return 0
|
|
30
31
|
|
|
31
32
|
#���ֶ������ת������(���ԽǶ�) port:����P�˿ڣ�dir:0:����Խ0��;1:��̾�����ת;2:˳ʱ����ת;3:��ʱ����ת
|
|
32
33
|
def set_dir(port:bytes,dir:bytes) -> Optional[bytes]:
|
|
33
34
|
servo_str=[0xA0, 0x24, 0x01, 0x71, 0x00, 0xBE]
|
|
34
35
|
servo_str[0]=0XA0+port
|
|
35
36
|
servo_str[4]=dir
|
|
36
|
-
response = base_driver.single_operate_sensor(servo_str,0)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
# response = base_driver.single_operate_sensor(servo_str,0)
|
|
38
|
+
base_driver.write_data(0X01, 0X02, servo_str)
|
|
39
|
+
# if response == None:
|
|
40
|
+
# return None
|
|
41
|
+
# else:
|
|
42
|
+
return 0
|
|
41
43
|
|
|
42
44
|
#BE-9528���ֶ�����ٶ�ת���Ƕ� port:����P�˿ڣ�angle:�Ƕ�(0~360)��speed:�ٶ�(0~100)��
|
|
43
45
|
def set_angle_speed(port:bytes,angle:bytes,speed:bytes) -> Optional[bytes]:
|
|
@@ -46,11 +48,12 @@ def set_angle_speed(port:bytes,angle:bytes,speed:bytes) -> Optional[bytes]:
|
|
|
46
48
|
servo_str[4]=angle//256
|
|
47
49
|
servo_str[5]=angle%256
|
|
48
50
|
servo_str[7]=speed
|
|
49
|
-
response = base_driver.single_operate_sensor(servo_str,0)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
#response = base_driver.single_operate_sensor(servo_str,0)
|
|
52
|
+
base_driver.write_data(0X01, 0X02, servo_str)
|
|
53
|
+
# if response == None:
|
|
54
|
+
# return None
|
|
55
|
+
# else:
|
|
56
|
+
return 0
|
|
54
57
|
|
|
55
58
|
#���ֶ��ת�����Ƕ���ʱʱ�� port:����P�˿ڣ�angle:�Ƕ�(0~360)��ms:��ʱʱ��(0~65535)��
|
|
56
59
|
def set_angle_ms(port:bytes,angle:bytes,ms:int) -> Optional[bytes]:
|
|
@@ -60,21 +63,23 @@ def set_angle_ms(port:bytes,angle:bytes,ms:int) -> Optional[bytes]:
|
|
|
60
63
|
servo_str[5]=angle%256
|
|
61
64
|
servo_str[7]=ms//256
|
|
62
65
|
servo_str[8]=ms%256
|
|
63
|
-
response = base_driver.single_operate_sensor(servo_str,0)
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
# response = base_driver.single_operate_sensor(servo_str,0)
|
|
67
|
+
base_driver.write_data(0X01, 0X02, servo_str)
|
|
68
|
+
# if response == None:
|
|
69
|
+
# return None
|
|
70
|
+
# else:
|
|
71
|
+
return 0
|
|
68
72
|
|
|
69
73
|
#���ֶ����λ port:����P�˿ڣ�
|
|
70
74
|
def set_init(port:bytes) -> Optional[bytes]:
|
|
71
75
|
servo_str=[0xA0, 0x12, 0x01, 0xBE]
|
|
72
76
|
servo_str[0]=0XA0+port
|
|
73
|
-
response = base_driver.single_operate_sensor(servo_str,0)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
77
|
+
# response = base_driver.single_operate_sensor(servo_str,0)
|
|
78
|
+
base_driver.write_data(0X01, 0X02, servo_str)
|
|
79
|
+
# if response == None:
|
|
80
|
+
# return None
|
|
81
|
+
# else:
|
|
82
|
+
return 0
|
|
78
83
|
|
|
79
84
|
#��ȡ���ֶ���Ƕ� port:����P�˿ڣ�
|
|
80
85
|
def get_angle(port:bytes) -> Optional[bytes]:
|
|
@@ -102,11 +107,12 @@ def set_speed(port:bytes,speed:int) -> Optional[bytes]:
|
|
|
102
107
|
m_par=256+speed
|
|
103
108
|
|
|
104
109
|
servo_str[4]=m_par
|
|
105
|
-
response = base_driver.single_operate_sensor(servo_str,0)
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
+
# response = base_driver.single_operate_sensor(servo_str,0)
|
|
111
|
+
base_driver.write_data(0X01, 0X02, servo_str)
|
|
112
|
+
# if response == None:
|
|
113
|
+
# return None
|
|
114
|
+
# else:
|
|
115
|
+
return 0
|
|
110
116
|
|
|
111
117
|
#���ֶ������ת�� port:����P�˿ڣ�code:����(0~65535)��speed:�ٶ�(-100~100)��
|
|
112
118
|
def set_code_speed(port:bytes,code:int,speed:int) -> Optional[bytes]:
|
|
@@ -126,21 +132,23 @@ def set_code_speed(port:bytes,code:int,speed:int) -> Optional[bytes]:
|
|
|
126
132
|
m_par=256+speed
|
|
127
133
|
servo_str[7]=m_par
|
|
128
134
|
|
|
129
|
-
response = base_driver.single_operate_sensor(servo_str,0)
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
135
|
+
# response = base_driver.single_operate_sensor(servo_str,0)
|
|
136
|
+
base_driver.write_data(0X01, 0X02, servo_str)
|
|
137
|
+
# if response == None:
|
|
138
|
+
# return None
|
|
139
|
+
# else:
|
|
140
|
+
return 0
|
|
134
141
|
|
|
135
142
|
#���ֶ������ֵ���� port:����P�˿ڣ�
|
|
136
143
|
def reset_encode(port:bytes) -> Optional[bytes]:
|
|
137
144
|
servo_str=[0xA0, 0x16, 0x01, 0xBE]
|
|
138
145
|
servo_str[0]=0XA0+port
|
|
139
|
-
response = base_driver.single_operate_sensor(servo_str,0)
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
146
|
+
# response = base_driver.single_operate_sensor(servo_str,0)
|
|
147
|
+
base_driver.write_data(0X01, 0X02, servo_str)
|
|
148
|
+
# if response == None:
|
|
149
|
+
# return None
|
|
150
|
+
# else:
|
|
151
|
+
return 0
|
|
144
152
|
|
|
145
153
|
#��ȡ���ֶ������ֵ port:����P�˿ڣ�
|
|
146
154
|
def get_encoder(port:bytes) -> Optional[bytes]:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: smartpi
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.32
|
|
4
4
|
Summary: A library use for H2-RCU
|
|
5
5
|
Author: ZMROBO
|
|
6
6
|
Classifier: Programming Language :: Python :: 3
|
|
@@ -9,3 +9,9 @@ Classifier: Operating System :: OS Independent
|
|
|
9
9
|
Requires-Python: >=3.7
|
|
10
10
|
Description-Content-Type: text/markdown
|
|
11
11
|
|
|
12
|
+
灵芯派函数库
|
|
13
|
+
SmartPi library
|
|
14
|
+
|
|
15
|
+
V0.1.31
|
|
16
|
+
1、更新了设备硬件ID读取函数;
|
|
17
|
+
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
smartpi/__init__.py,sha256=
|
|
1
|
+
smartpi/__init__.py,sha256=lUBmDOfuGaZ59JU3nE42ao8-9nV_D5vheF1X7Dq400k,356
|
|
2
2
|
smartpi/_gui.py,sha256=ij-6HZAEIwdy_hvU7f0NkyQjx_-eephijlKbGUhf8Uo,2177
|
|
3
|
-
smartpi/base_driver.py,sha256=
|
|
3
|
+
smartpi/base_driver.py,sha256=WtRBSkjcOHikU402lU1cBSVlRHhyWGZMll_zffg2F2U,20609
|
|
4
4
|
smartpi/color_sensor.py,sha256=YXJjknYjp7teTZsHYZRAWgi73CH0MhBp1go9y0Inxyo,498
|
|
5
5
|
smartpi/cw2015.py,sha256=1lAF-pi_ye_ya1AZQS1sjbgsDf7MThO5IAskKsNGBzA,5695
|
|
6
6
|
smartpi/flash.py,sha256=-pUqg6FSVoBiLFKqrG9B4dFqn8lICnQsSPJr_MtZLIU,4132
|
|
7
7
|
smartpi/humidity.py,sha256=nZwiBtMWKNipVM83ymajZACPHxkC2vUJjDMmCOPN9lw,499
|
|
8
|
-
smartpi/led.py,sha256=
|
|
9
|
-
smartpi/light_sensor.py,sha256=
|
|
10
|
-
smartpi/motor.py,sha256=
|
|
8
|
+
smartpi/led.py,sha256=HXebd7mRO6HUjO2Xc2LBgJlAew0-IAAKpvcmVRhdGcA,594
|
|
9
|
+
smartpi/light_sensor.py,sha256=oG6hHr1Tb9Xcv-Y-OjhkED5DS1u82F-kduHKAiM3B5Q,2256
|
|
10
|
+
smartpi/motor.py,sha256=HTH0JqZ0d8D2HRdQ6UT9wwqBkyqErq6QaMuS_ZsDq9A,5144
|
|
11
11
|
smartpi/move.py,sha256=mYw5li1qQe97845cqclMksuaKOL9n_0E0n9652EIMcI,6046
|
|
12
|
-
smartpi/servo.py,sha256=
|
|
12
|
+
smartpi/servo.py,sha256=XbI2pc-nejhh1QewE2liaiyoP01BWf2M2x7gwFcUTfI,5514
|
|
13
13
|
smartpi/temperature.py,sha256=VT79CYA41q1d_4AM-Y0eIMeIw7AtCkSXjWVws6Yx5yE,462
|
|
14
14
|
smartpi/touch_sensor.py,sha256=P57RRQlqY0KexpMi-ydqwF5albOKCBOGb0Rb6zeVTqk,440
|
|
15
15
|
smartpi/trace.py,sha256=tut7BMbq87ShaR5eNuv7PZtAEz9DS5_BDf0_muIZ-tQ,4577
|
|
16
16
|
smartpi/ultrasonic.py,sha256=kmVpUfvE1oHoqgv92ZU6Fi-sO6DSwm10ssKsImNeOkY,624
|
|
17
|
-
smartpi-0.1.
|
|
18
|
-
smartpi-0.1.
|
|
19
|
-
smartpi-0.1.
|
|
20
|
-
smartpi-0.1.
|
|
17
|
+
smartpi-0.1.32.dist-info/METADATA,sha256=YBHCXdnPlErDsEQmhqsrXSD6g2Jen0OT9ZKV8san8gw,399
|
|
18
|
+
smartpi-0.1.32.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
19
|
+
smartpi-0.1.32.dist-info/top_level.txt,sha256=PoLhUCmWAiQUg5UeN2fS-Y1iQyBbF2rdUlizXtpHGRQ,8
|
|
20
|
+
smartpi-0.1.32.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|