smartpi 0.1.9__py3-none-any.whl → 0.1.11__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 +1 -1
- smartpi/base_driver.py +15 -15
- smartpi/color_sensor.py +2 -2
- smartpi/humidity.py +2 -2
- smartpi/led.py +3 -3
- smartpi/light_sensor.py +2 -2
- smartpi/motor.py +25 -25
- smartpi/move.py +28 -37
- smartpi/servo.py +28 -28
- smartpi/temperature.py +2 -2
- smartpi/touch_sensor.py +2 -2
- smartpi/ultrasonic.py +2 -2
- {smartpi-0.1.9.dist-info → smartpi-0.1.11.dist-info}/METADATA +1 -1
- smartpi-0.1.11.dist-info/RECORD +18 -0
- smartpi-0.1.9.dist-info/RECORD +0 -18
- {smartpi-0.1.9.dist-info → smartpi-0.1.11.dist-info}/WHEEL +0 -0
- {smartpi-0.1.9.dist-info → smartpi-0.1.11.dist-info}/top_level.txt +0 -0
smartpi/__init__.py
CHANGED
smartpi/base_driver.py
CHANGED
|
@@ -55,7 +55,7 @@ MIN_FRAME_LEN = 9 # 最小帧长度
|
|
|
55
55
|
|
|
56
56
|
# 串口配置参数
|
|
57
57
|
SERIAL_PORT = "/dev/ttyS3" # 串口设备路径
|
|
58
|
-
BAUD_RATE =
|
|
58
|
+
BAUD_RATE = 921600 # 波特率
|
|
59
59
|
TIMEOUT = 0.1 # 读取超时时间(秒)
|
|
60
60
|
|
|
61
61
|
ser = serial.Serial(
|
|
@@ -75,7 +75,7 @@ def uart3_init() -> Optional[serial.Serial]:
|
|
|
75
75
|
"""初始化串口"""
|
|
76
76
|
try:
|
|
77
77
|
if ser.is_open:
|
|
78
|
-
print("UART3初始化成功")
|
|
78
|
+
# print("UART3初始化成功")
|
|
79
79
|
return ser
|
|
80
80
|
else:
|
|
81
81
|
print("Error opening UART3")
|
|
@@ -208,7 +208,7 @@ def read_device_model() -> Optional[bytes]:
|
|
|
208
208
|
if time.time() - start_time > 3:
|
|
209
209
|
print("读取超时")
|
|
210
210
|
buffer.clear()
|
|
211
|
-
return
|
|
211
|
+
return None
|
|
212
212
|
|
|
213
213
|
"""读取版本号"""
|
|
214
214
|
def read_version() -> Optional[bytes]:
|
|
@@ -224,7 +224,7 @@ def read_version() -> Optional[bytes]:
|
|
|
224
224
|
if time.time() - start_time > 3:
|
|
225
225
|
print("读取超时")
|
|
226
226
|
buffer.clear()
|
|
227
|
-
return
|
|
227
|
+
return None
|
|
228
228
|
|
|
229
229
|
"""读取工厂信息"""
|
|
230
230
|
def read_factory_data() -> Optional[bytes]:
|
|
@@ -240,7 +240,7 @@ def read_factory_data() -> Optional[bytes]:
|
|
|
240
240
|
if time.time() - start_time > 3:
|
|
241
241
|
print("读取超时")
|
|
242
242
|
buffer.clear()
|
|
243
|
-
return
|
|
243
|
+
return None
|
|
244
244
|
|
|
245
245
|
"""读取硬件ID"""
|
|
246
246
|
def read_hardware_ID() -> Optional[bytes]:
|
|
@@ -256,7 +256,7 @@ def read_hardware_ID() -> Optional[bytes]:
|
|
|
256
256
|
if time.time() - start_time > 3:
|
|
257
257
|
print("读取超时")
|
|
258
258
|
buffer.clear()
|
|
259
|
-
return
|
|
259
|
+
return None
|
|
260
260
|
|
|
261
261
|
"""读取设备名称"""
|
|
262
262
|
def read_device_name() -> Optional[bytes]:
|
|
@@ -272,7 +272,7 @@ def read_device_name() -> Optional[bytes]:
|
|
|
272
272
|
if time.time() - start_time > 3:
|
|
273
273
|
print("读取超时")
|
|
274
274
|
buffer.clear()
|
|
275
|
-
return
|
|
275
|
+
return None
|
|
276
276
|
|
|
277
277
|
"""设置设备名称"""
|
|
278
278
|
def write_device_name(send_data: str) -> Optional[bytes]:
|
|
@@ -289,7 +289,7 @@ def write_device_name(send_data: str) -> Optional[bytes]:
|
|
|
289
289
|
if time.time() - start_time > 3:
|
|
290
290
|
print("读取超时")
|
|
291
291
|
buffer.clear()
|
|
292
|
-
return
|
|
292
|
+
return None
|
|
293
293
|
|
|
294
294
|
"""读取连接方式"""
|
|
295
295
|
def read_connected() -> Optional[bytes]:
|
|
@@ -305,7 +305,7 @@ def read_connected() -> Optional[bytes]:
|
|
|
305
305
|
if time.time() - start_time > 3:
|
|
306
306
|
print("读取超时")
|
|
307
307
|
buffer.clear()
|
|
308
|
-
return
|
|
308
|
+
return None
|
|
309
309
|
|
|
310
310
|
"""读取电池电量百分比"""
|
|
311
311
|
def read_battery() -> Optional[bytes]:
|
|
@@ -313,7 +313,7 @@ def read_battery() -> Optional[bytes]:
|
|
|
313
313
|
if sensor.init():
|
|
314
314
|
return sensor.get_soc(0)
|
|
315
315
|
else:
|
|
316
|
-
return
|
|
316
|
+
return None
|
|
317
317
|
|
|
318
318
|
###############################################################################固件升级
|
|
319
319
|
|
|
@@ -431,7 +431,7 @@ def read_peripheral() -> Optional[bytes]:
|
|
|
431
431
|
if time.time() - start_time > 3:
|
|
432
432
|
print("读取超时")
|
|
433
433
|
buffer.clear()
|
|
434
|
-
return
|
|
434
|
+
return None
|
|
435
435
|
|
|
436
436
|
"""单次操作外设"""
|
|
437
437
|
def single_operate_sensor(op_struct: bytes) -> Optional[bytes]:
|
|
@@ -449,7 +449,7 @@ def single_operate_sensor(op_struct: bytes) -> Optional[bytes]:
|
|
|
449
449
|
if time.time() - start_time > 3:
|
|
450
450
|
print("读取超时")
|
|
451
451
|
buffer.clear()
|
|
452
|
-
return
|
|
452
|
+
return None
|
|
453
453
|
|
|
454
454
|
#P端口初始化释放
|
|
455
455
|
def P_port_init(port:bytes) -> Optional[bytes]:
|
|
@@ -459,7 +459,7 @@ def P_port_init(port:bytes) -> Optional[bytes]:
|
|
|
459
459
|
if response:
|
|
460
460
|
return 0
|
|
461
461
|
else:
|
|
462
|
-
return
|
|
462
|
+
return None
|
|
463
463
|
|
|
464
464
|
"""从机模式转换"""
|
|
465
465
|
def mode_change(send_data: str) -> Optional[bytes]:
|
|
@@ -477,7 +477,7 @@ def mode_change(send_data: str) -> Optional[bytes]:
|
|
|
477
477
|
if time.time() - start_time > 3:
|
|
478
478
|
print("读取超时")
|
|
479
479
|
buffer.clear()
|
|
480
|
-
return
|
|
480
|
+
return None
|
|
481
481
|
|
|
482
482
|
"""智能模式发送周期"""
|
|
483
483
|
def mode_change(send_data: str) -> Optional[bytes]:
|
|
@@ -495,7 +495,7 @@ def mode_change(send_data: str) -> Optional[bytes]:
|
|
|
495
495
|
if time.time() - start_time > 3:
|
|
496
496
|
print("读取超时")
|
|
497
497
|
buffer.clear()
|
|
498
|
-
return
|
|
498
|
+
return None
|
|
499
499
|
|
|
500
500
|
"""H2-RCU初始化"""
|
|
501
501
|
def smartpi_init():
|
smartpi/color_sensor.py
CHANGED
smartpi/humidity.py
CHANGED
|
@@ -10,8 +10,8 @@ def get_value(port:bytes) -> Optional[bytes]:
|
|
|
10
10
|
humi_str[0]=0XA0+port
|
|
11
11
|
humi_str[4]=0X01
|
|
12
12
|
response = base_driver.single_operate_sensor(humi_str)
|
|
13
|
-
if response ==
|
|
14
|
-
return
|
|
13
|
+
if response == None:
|
|
14
|
+
return None
|
|
15
15
|
else:
|
|
16
16
|
return response[4]
|
|
17
17
|
|
smartpi/led.py
CHANGED
|
@@ -10,8 +10,8 @@ def set_color(port:bytes,command:bytes) -> Optional[bytes]:
|
|
|
10
10
|
color_lamp_str[0]=0XA0+port
|
|
11
11
|
color_lamp_str[2]=command
|
|
12
12
|
response = base_driver.single_operate_sensor(color_lamp_str)
|
|
13
|
-
if response:
|
|
14
|
-
return
|
|
13
|
+
if response == None:
|
|
14
|
+
return None
|
|
15
15
|
else:
|
|
16
|
-
return
|
|
16
|
+
return 0
|
|
17
17
|
|
smartpi/light_sensor.py
CHANGED
|
@@ -9,8 +9,8 @@ def get_value(port:bytes) -> Optional[bytes]:
|
|
|
9
9
|
light_str[0]=0XA0+port
|
|
10
10
|
light_str[2]=1
|
|
11
11
|
response = base_driver.single_operate_sensor(light_str)
|
|
12
|
-
if response ==
|
|
13
|
-
return
|
|
12
|
+
if response == None:
|
|
13
|
+
return None
|
|
14
14
|
else:
|
|
15
15
|
light_data=response[4:-1]
|
|
16
16
|
light_num=int.from_bytes(light_data, byteorder='big', signed=True)
|
smartpi/motor.py
CHANGED
|
@@ -9,8 +9,8 @@ def get_motor_encoder(port:bytes) -> Optional[bytes]:
|
|
|
9
9
|
motor_str=[0xA0, 0x01, 0x01, 0xBE]
|
|
10
10
|
motor_str[0]=0XA0+port
|
|
11
11
|
response = base_driver.single_operate_sensor(motor_str)
|
|
12
|
-
if response ==
|
|
13
|
-
return
|
|
12
|
+
if response == None:
|
|
13
|
+
return None
|
|
14
14
|
else:
|
|
15
15
|
code_data=response[4:-1]
|
|
16
16
|
code_num=int.from_bytes(code_data, byteorder='big', signed=True)
|
|
@@ -21,10 +21,10 @@ def reset_motor_encoder(port:bytes) -> Optional[bytes]:
|
|
|
21
21
|
motor_str=[0xA0, 0x01, 0x03, 0xBE]
|
|
22
22
|
motor_str[0]=0XA0+port
|
|
23
23
|
response = base_driver.single_operate_sensor(motor_str)
|
|
24
|
-
if response:
|
|
25
|
-
return
|
|
24
|
+
if response == None:
|
|
25
|
+
return None
|
|
26
26
|
else:
|
|
27
|
-
return
|
|
27
|
+
return 0
|
|
28
28
|
|
|
29
29
|
#���﷽����� port:����M�˿ڣ�dir:0��1
|
|
30
30
|
def set_motor_direction(port:bytes,direc:bytes) -> Optional[bytes]:
|
|
@@ -32,10 +32,10 @@ def set_motor_direction(port:bytes,direc:bytes) -> Optional[bytes]:
|
|
|
32
32
|
motor_str[0]=0XA0+port
|
|
33
33
|
motor_str[4]=direc
|
|
34
34
|
response = base_driver.single_operate_sensor(motor_str)
|
|
35
|
-
if response:
|
|
36
|
-
return
|
|
35
|
+
if response == None:
|
|
36
|
+
return None
|
|
37
37
|
else:
|
|
38
|
-
return
|
|
38
|
+
return 0
|
|
39
39
|
|
|
40
40
|
#�����ٶ�ת�� port:����M�˿ڣ�speed:-100~100
|
|
41
41
|
def set_motor(port:bytes,speed:int) -> Optional[bytes]:
|
|
@@ -53,20 +53,20 @@ def set_motor(port:bytes,speed:int) -> Optional[bytes]:
|
|
|
53
53
|
motor_str[4]=m_par
|
|
54
54
|
|
|
55
55
|
response = base_driver.single_operate_sensor(motor_str)
|
|
56
|
-
if response:
|
|
57
|
-
return
|
|
56
|
+
if response == None:
|
|
57
|
+
return None
|
|
58
58
|
else:
|
|
59
|
-
return
|
|
59
|
+
return 0
|
|
60
60
|
|
|
61
61
|
#����ֹͣ port:����M�˿ڣ�
|
|
62
62
|
def set_motor_stop(port:bytes) -> Optional[bytes]:
|
|
63
63
|
motor_str=[0xA0, 0x01, 0x0B, 0xBE]
|
|
64
64
|
motor_str[0]=0XA0+port
|
|
65
65
|
response = base_driver.single_operate_sensor(motor_str)
|
|
66
|
-
if response:
|
|
67
|
-
return
|
|
66
|
+
if response == None:
|
|
67
|
+
return None
|
|
68
68
|
else:
|
|
69
|
-
return
|
|
69
|
+
return 0
|
|
70
70
|
|
|
71
71
|
#����Ƕȿ��� port:����M�˿ڣ�speed:-100~100��degree:0~65535
|
|
72
72
|
def set_motor_angle(port:bytes,speed:int,degree:int) -> Optional[bytes]:
|
|
@@ -86,10 +86,10 @@ def set_motor_angle(port:bytes,speed:int,degree:int) -> Optional[bytes]:
|
|
|
86
86
|
motor_str[6]=degree//256
|
|
87
87
|
motor_str[7]=degree%256
|
|
88
88
|
response = base_driver.single_operate_sensor(motor_str)
|
|
89
|
-
if response:
|
|
90
|
-
return
|
|
89
|
+
if response == None:
|
|
90
|
+
return None
|
|
91
91
|
else:
|
|
92
|
-
return
|
|
92
|
+
return 0
|
|
93
93
|
|
|
94
94
|
#���ﶨʱת�� port:����M�˿ڣ�speed:-100~100��second:1~256
|
|
95
95
|
def set_motor_second(port:bytes,speed:int,second:bytes) -> Optional[bytes]:
|
|
@@ -108,10 +108,10 @@ def set_motor_second(port:bytes,speed:int,second:bytes) -> Optional[bytes]:
|
|
|
108
108
|
motor_str[4]=m_par
|
|
109
109
|
motor_str[6]=second
|
|
110
110
|
response = base_driver.single_operate_sensor(motor_str)
|
|
111
|
-
if response:
|
|
112
|
-
return
|
|
111
|
+
if response == None:
|
|
112
|
+
return None
|
|
113
113
|
else:
|
|
114
|
-
return
|
|
114
|
+
return 0
|
|
115
115
|
|
|
116
116
|
#���ﶨ��ת�� port:����M�˿ڣ�speed:-100~100
|
|
117
117
|
def set_motor_constspeed(port:bytes,speed:int) -> Optional[bytes]:
|
|
@@ -130,18 +130,18 @@ def set_motor_constspeed(port:bytes,speed:int) -> Optional[bytes]:
|
|
|
130
130
|
motor_str[4]=m_par
|
|
131
131
|
|
|
132
132
|
response = base_driver.single_operate_sensor(motor_str)
|
|
133
|
-
if response:
|
|
134
|
-
return
|
|
133
|
+
if response == None:
|
|
134
|
+
return None
|
|
135
135
|
else:
|
|
136
|
-
return
|
|
136
|
+
return 0
|
|
137
137
|
|
|
138
138
|
#�����ٶȶ�ȡ port:����M�˿ڣ�
|
|
139
139
|
def get_motor_speed(port:bytes) -> Optional[bytes]:
|
|
140
140
|
motor_str=[0xA0, 0x01, 0x10, 0xBE]
|
|
141
141
|
motor_str[0]=0XA0+port
|
|
142
142
|
response = base_driver.single_operate_sensor(motor_str)
|
|
143
|
-
if response ==
|
|
144
|
-
return
|
|
143
|
+
if response == None:
|
|
144
|
+
return None
|
|
145
145
|
else:
|
|
146
146
|
code_data=response[4:-1]
|
|
147
147
|
code_num=int.from_bytes(code_data, byteorder='big', signed=True)
|
smartpi/move.py
CHANGED
|
@@ -4,7 +4,7 @@ from typing import List, Optional
|
|
|
4
4
|
from smartpi import base_driver
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
#以速度移动x
|
|
7
|
+
#以速度移动x秒:dir:方向forward、backward、turnright、turnleft;speed:0~100;second:x秒
|
|
8
8
|
def run_second(dir:bytes,speed:bytes,second:bytes) -> Optional[bytes]:
|
|
9
9
|
move_str=[0xA0, 0x01, 0x11, 0x71, 0x00, 0x71, 0x00, 0x71, 0x00, 0xBE]
|
|
10
10
|
|
|
@@ -21,12 +21,12 @@ def run_second(dir:bytes,speed:bytes,second:bytes) -> Optional[bytes]:
|
|
|
21
21
|
move_str[8]=second
|
|
22
22
|
|
|
23
23
|
response = base_driver.single_operate_sensor(move_str)
|
|
24
|
-
if response ==
|
|
25
|
-
return
|
|
24
|
+
if response == None:
|
|
25
|
+
return None
|
|
26
26
|
else:
|
|
27
27
|
return 0
|
|
28
28
|
|
|
29
|
-
#以速度移动x
|
|
29
|
+
#以速度移动x度:dir:方向forward、backward、turnright、turnleft:speed:0~100:angle:65535
|
|
30
30
|
def run_angle(dir:bytes,speed:bytes,angle:int) -> Optional[bytes]:
|
|
31
31
|
move_str=[0xA0, 0x01, 0x12, 0x71, 0x00, 0x71, 0x00, 0x81, 0x00, 0x00, 0xBE]
|
|
32
32
|
|
|
@@ -44,13 +44,13 @@ def run_angle(dir:bytes,speed:bytes,angle:int) -> Optional[bytes]:
|
|
|
44
44
|
move_str[9]=angle%256
|
|
45
45
|
|
|
46
46
|
response = base_driver.single_operate_sensor(move_str)
|
|
47
|
-
if response ==
|
|
48
|
-
return
|
|
47
|
+
if response == None:
|
|
48
|
+
return None
|
|
49
49
|
else:
|
|
50
50
|
return 0
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
def run(dir:bytes,speed:
|
|
52
|
+
#以速度移动:dir:方向forward、backward、turnright、turnleft;speed:0~100;
|
|
53
|
+
def run(dir:bytes,speed:bytes) -> Optional[bytes]:
|
|
54
54
|
move_str=[0xA0, 0x01, 0x13, 0x71, 0x00, 0x71, 0x00, 0xBE]
|
|
55
55
|
|
|
56
56
|
if dir=="forward":
|
|
@@ -61,25 +61,16 @@ def run(dir:bytes,speed:int) -> Optional[bytes]:
|
|
|
61
61
|
move_str[4]=0x03
|
|
62
62
|
elif dir=="turnleft":
|
|
63
63
|
move_str[4]=0x04
|
|
64
|
-
|
|
65
|
-
if speed>100:
|
|
66
|
-
m_par=100
|
|
67
|
-
elif speed>=0 and speed<=100:
|
|
68
|
-
m_par=speed
|
|
69
|
-
elif speed<-100:
|
|
70
|
-
m_par=156
|
|
71
|
-
elif speed<=0 and speed>=-100:
|
|
72
|
-
m_par=256+speed
|
|
73
64
|
|
|
74
|
-
move_str[6]=
|
|
65
|
+
move_str[6]=speed
|
|
75
66
|
|
|
76
67
|
response = base_driver.single_operate_sensor(move_str)
|
|
77
|
-
if response ==
|
|
78
|
-
return
|
|
68
|
+
if response == None:
|
|
69
|
+
return None
|
|
79
70
|
else:
|
|
80
71
|
return 0
|
|
81
72
|
|
|
82
|
-
#设置左右轮速度移动x
|
|
73
|
+
#设置左右轮速度移动x秒:Lspeed:-100~100;Rspeed:-100~100;second:1~255
|
|
83
74
|
def run_speed_second(Lspeed:int,Rspeed:int,second:bytes) -> Optional[bytes]:
|
|
84
75
|
move_str=[0xA0, 0x01, 0x14, 0x71, 0x00, 0x71, 0x00, 0x71, 0x00, 0xBE]
|
|
85
76
|
|
|
@@ -108,12 +99,12 @@ def run_speed_second(Lspeed:int,Rspeed:int,second:bytes) -> Optional[bytes]:
|
|
|
108
99
|
move_str[8]=second
|
|
109
100
|
|
|
110
101
|
response = base_driver.single_operate_sensor(move_str)
|
|
111
|
-
if response ==
|
|
112
|
-
return
|
|
102
|
+
if response == None:
|
|
103
|
+
return None
|
|
113
104
|
else:
|
|
114
105
|
return 0
|
|
115
106
|
|
|
116
|
-
|
|
107
|
+
#设置左右轮速度移动:Lspeed:-100~100;Rspeed:-100~100;
|
|
117
108
|
def run_speed(Lspeed:int,Rspeed:int) -> Optional[bytes]:
|
|
118
109
|
move_str=[0xA0, 0x01, 0x15, 0x71, 0x00, 0x71, 0x00, 0xBE]
|
|
119
110
|
|
|
@@ -140,12 +131,12 @@ def run_speed(Lspeed:int,Rspeed:int) -> Optional[bytes]:
|
|
|
140
131
|
move_str[4]=m_par
|
|
141
132
|
|
|
142
133
|
response = base_driver.single_operate_sensor(move_str)
|
|
143
|
-
if response ==
|
|
144
|
-
return
|
|
134
|
+
if response == None:
|
|
135
|
+
return None
|
|
145
136
|
else:
|
|
146
137
|
return 0
|
|
147
138
|
|
|
148
|
-
|
|
139
|
+
#设置左右轮功率移动:Lpower:0~100;Rpower:0~100;
|
|
149
140
|
def run_power(Lpower:bytes,Rpower:bytes) -> Optional[bytes]:
|
|
150
141
|
move_str=[0xA0, 0x01, 0x17, 0x71, 0x00, 0x71, 0x00, 0xBE]
|
|
151
142
|
|
|
@@ -153,12 +144,12 @@ def run_power(Lpower:bytes,Rpower:bytes) -> Optional[bytes]:
|
|
|
153
144
|
move_str[6]=Lpower
|
|
154
145
|
|
|
155
146
|
response = base_driver.single_operate_sensor(move_str)
|
|
156
|
-
if response ==
|
|
157
|
-
return
|
|
147
|
+
if response == None:
|
|
148
|
+
return None
|
|
158
149
|
else:
|
|
159
150
|
return 0
|
|
160
151
|
|
|
161
|
-
|
|
152
|
+
#设置最大功率:M1:0~100;M2:0~100;M3:0~100;M4:0~100;M5:0~100;M6:0~100;
|
|
162
153
|
def set_maxpower(M1:bytes,M2:bytes,M3:bytes,M4:bytes,M5:bytes,M6:bytes) -> Optional[bytes]:
|
|
163
154
|
move_str=[0xA0, 0x01, 0x18, 0x71, 0x00, 0x71, 0x00, 0x71, 0x00, 0x71, 0x00, 0x71, 0x00, 0x71, 0x00, 0xBE]
|
|
164
155
|
|
|
@@ -170,8 +161,8 @@ def set_maxpower(M1:bytes,M2:bytes,M3:bytes,M4:bytes,M5:bytes,M6:bytes) -> Optio
|
|
|
170
161
|
move_str[14]=M6
|
|
171
162
|
|
|
172
163
|
response = base_driver.single_operate_sensor(move_str)
|
|
173
|
-
if response ==
|
|
174
|
-
return
|
|
164
|
+
if response == None:
|
|
165
|
+
return None
|
|
175
166
|
else:
|
|
176
167
|
return 0
|
|
177
168
|
|
|
@@ -180,12 +171,12 @@ def stop() -> Optional[bytes]:
|
|
|
180
171
|
move_str=[0xA0, 0x01, 0x0A, 0xBE]
|
|
181
172
|
|
|
182
173
|
response = base_driver.single_operate_sensor(move_str)
|
|
183
|
-
if response ==
|
|
184
|
-
return
|
|
174
|
+
if response == None:
|
|
175
|
+
return None
|
|
185
176
|
else:
|
|
186
177
|
return 0
|
|
187
178
|
|
|
188
|
-
|
|
179
|
+
#设置左右轮方向:Lmotor:1~6;Rmotor:1~6;state: no_reversal、all_reversal、left_reversal、right_reversal
|
|
189
180
|
def set_move_init(Lmotor:bytes,Rmotor:bytes,state:bytes) -> Optional[bytes]:
|
|
190
181
|
move_str=[0xA0, 0x01, 0x19, 0x71, 0x00, 0x71, 0x00, 0x71, 0x00, 0xBE]
|
|
191
182
|
|
|
@@ -202,8 +193,8 @@ def set_move_init(Lmotor:bytes,Rmotor:bytes,state:bytes) -> Optional[bytes]:
|
|
|
202
193
|
move_str[8]=Lmotor
|
|
203
194
|
|
|
204
195
|
response = base_driver.single_operate_sensor(move_str)
|
|
205
|
-
if response ==
|
|
206
|
-
return
|
|
196
|
+
if response == None:
|
|
197
|
+
return None
|
|
207
198
|
else:
|
|
208
199
|
return 0
|
|
209
200
|
|
smartpi/servo.py
CHANGED
|
@@ -10,10 +10,10 @@ def steer_angle(port:bytes,angle:bytes) -> Optional[bytes]:
|
|
|
10
10
|
servo_str[0]=0XA0+port
|
|
11
11
|
servo_str[4]=angle
|
|
12
12
|
response = base_driver.single_operate_sensor(servo_str)
|
|
13
|
-
if response:
|
|
14
|
-
return
|
|
13
|
+
if response == None:
|
|
14
|
+
return None
|
|
15
15
|
else:
|
|
16
|
-
return
|
|
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]:
|
|
@@ -23,10 +23,10 @@ def steer_angle_delay(port:bytes,angle:bytes,second:bytes) -> Optional[bytes]:
|
|
|
23
23
|
servo_str[5]=angle%256
|
|
24
24
|
servo_str[7]=second
|
|
25
25
|
response = base_driver.single_operate_sensor(servo_str)
|
|
26
|
-
if response:
|
|
27
|
-
return
|
|
26
|
+
if response == None:
|
|
27
|
+
return None
|
|
28
28
|
else:
|
|
29
|
-
return
|
|
29
|
+
return 0
|
|
30
30
|
|
|
31
31
|
#BE-9528���ֶ�����ٶ�ת���Ƕ� port:����P�˿ڣ�angle:�Ƕ�(0~360)��speed:�ٶ�(0~100)��
|
|
32
32
|
def set_angle_speed(port:bytes,angle:bytes,speed:bytes) -> Optional[bytes]:
|
|
@@ -36,10 +36,10 @@ def set_angle_speed(port:bytes,angle:bytes,speed:bytes) -> Optional[bytes]:
|
|
|
36
36
|
servo_str[5]=angle%256
|
|
37
37
|
servo_str[7]=speed
|
|
38
38
|
response = base_driver.single_operate_sensor(servo_str)
|
|
39
|
-
if response:
|
|
40
|
-
return
|
|
39
|
+
if response == None:
|
|
40
|
+
return None
|
|
41
41
|
else:
|
|
42
|
-
return
|
|
42
|
+
return 0
|
|
43
43
|
|
|
44
44
|
#���ֶ��ת�����Ƕ���ʱʱ�� port:����P�˿ڣ�angle:�Ƕ�(0~360)��ms:��ʱʱ��(0~65535)��
|
|
45
45
|
def set_angle_ms(port:bytes,angle:bytes,ms:int) -> Optional[bytes]:
|
|
@@ -50,28 +50,28 @@ def set_angle_ms(port:bytes,angle:bytes,ms:int) -> Optional[bytes]:
|
|
|
50
50
|
servo_str[7]=ms//256
|
|
51
51
|
servo_str[8]=ms%256
|
|
52
52
|
response = base_driver.single_operate_sensor(servo_str)
|
|
53
|
-
if response:
|
|
54
|
-
return
|
|
53
|
+
if response == None:
|
|
54
|
+
return None
|
|
55
55
|
else:
|
|
56
|
-
return
|
|
56
|
+
return 0
|
|
57
57
|
|
|
58
58
|
#���ֶ����λ port:����P�˿ڣ�
|
|
59
59
|
def set_init(port:bytes) -> Optional[bytes]:
|
|
60
60
|
servo_str=[0xA0, 0x12, 0x01, 0xBE]
|
|
61
61
|
servo_str[0]=0XA0+port
|
|
62
62
|
response = base_driver.single_operate_sensor(servo_str)
|
|
63
|
-
if response:
|
|
64
|
-
return
|
|
63
|
+
if response == None:
|
|
64
|
+
return None
|
|
65
65
|
else:
|
|
66
|
-
return
|
|
66
|
+
return 0
|
|
67
67
|
|
|
68
68
|
#��ȡ���ֶ���Ƕ� port:����P�˿ڣ�
|
|
69
69
|
def get_angle(port:bytes) -> Optional[bytes]:
|
|
70
70
|
servo_str=[0xA0, 0x13, 0x01, 0xBE]
|
|
71
71
|
servo_str[0]=0XA0+port
|
|
72
72
|
response = base_driver.single_operate_sensor(servo_str)
|
|
73
|
-
if response ==
|
|
74
|
-
return
|
|
73
|
+
if response == None:
|
|
74
|
+
return None
|
|
75
75
|
else:
|
|
76
76
|
angle_data=response[4:-1]
|
|
77
77
|
angle_num=int.from_bytes(angle_data, byteorder='big', signed=True)
|
|
@@ -92,10 +92,10 @@ def set_speed(port:bytes,speed:int) -> Optional[bytes]:
|
|
|
92
92
|
|
|
93
93
|
servo_str[4]=m_par
|
|
94
94
|
response = base_driver.single_operate_sensor(servo_str)
|
|
95
|
-
if response:
|
|
96
|
-
return
|
|
95
|
+
if response == None:
|
|
96
|
+
return None
|
|
97
97
|
else:
|
|
98
|
-
return
|
|
98
|
+
return 0
|
|
99
99
|
|
|
100
100
|
#���ֶ������ת�� port:����P�˿ڣ�code:����(0~65535)��speed:�ٶ�(-100~100)��
|
|
101
101
|
def set_code_speed(port:bytes,code:int,speed:int) -> Optional[bytes]:
|
|
@@ -116,28 +116,28 @@ def set_code_speed(port:bytes,code:int,speed:int) -> Optional[bytes]:
|
|
|
116
116
|
servo_str[7]=m_par
|
|
117
117
|
|
|
118
118
|
response = base_driver.single_operate_sensor(servo_str)
|
|
119
|
-
if response:
|
|
120
|
-
return
|
|
119
|
+
if response == None:
|
|
120
|
+
return None
|
|
121
121
|
else:
|
|
122
|
-
return
|
|
122
|
+
return 0
|
|
123
123
|
|
|
124
124
|
#���ֶ������ֵ���� port:����P�˿ڣ�
|
|
125
125
|
def reset_encode(port:bytes) -> Optional[bytes]:
|
|
126
126
|
servo_str=[0xA0, 0x16, 0x01, 0xBE]
|
|
127
127
|
servo_str[0]=0XA0+port
|
|
128
128
|
response = base_driver.single_operate_sensor(servo_str)
|
|
129
|
-
if response:
|
|
130
|
-
return
|
|
129
|
+
if response == None:
|
|
130
|
+
return None
|
|
131
131
|
else:
|
|
132
|
-
return
|
|
132
|
+
return 0
|
|
133
133
|
|
|
134
134
|
#��ȡ���ֶ������ֵ port:����P�˿ڣ�
|
|
135
135
|
def get_encoder(port:bytes) -> Optional[bytes]:
|
|
136
136
|
servo_str=[0xA0, 0x17, 0x01, 0xBE]
|
|
137
137
|
servo_str[0]=0XA0+port
|
|
138
138
|
response = base_driver.single_operate_sensor(servo_str)
|
|
139
|
-
if response ==
|
|
140
|
-
return
|
|
139
|
+
if response == None:
|
|
140
|
+
return None
|
|
141
141
|
else:
|
|
142
142
|
code_data=response[4:-1]
|
|
143
143
|
code_num=int.from_bytes(code_data, byteorder='big', signed=True)
|
smartpi/temperature.py
CHANGED
smartpi/touch_sensor.py
CHANGED
|
@@ -8,8 +8,8 @@ def get_value(port:bytes) -> Optional[bytes]:
|
|
|
8
8
|
read_sw_str=[0xA0, 0x03, 0x01, 0xBE]
|
|
9
9
|
read_sw_str[0]=0XA0+port
|
|
10
10
|
response = base_driver.single_operate_sensor(read_sw_str)
|
|
11
|
-
if response ==
|
|
12
|
-
return
|
|
11
|
+
if response == None:
|
|
12
|
+
return None
|
|
13
13
|
else:
|
|
14
14
|
return response[4]
|
|
15
15
|
|
smartpi/ultrasonic.py
CHANGED
|
@@ -10,8 +10,8 @@ def get_value(port:bytes) -> Optional[bytes]:
|
|
|
10
10
|
ultrasonic_str[2]=1
|
|
11
11
|
response = base_driver.single_operate_sensor(ultrasonic_str)
|
|
12
12
|
|
|
13
|
-
if response ==
|
|
14
|
-
return
|
|
13
|
+
if response == None:
|
|
14
|
+
return None
|
|
15
15
|
else:
|
|
16
16
|
distance_data=response[4:-1]
|
|
17
17
|
distance_num=int.from_bytes(distance_data, byteorder='big', signed=True)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
smartpi/__init__.py,sha256=CD_hKLtgmxyccH-ALP0bESCFPd6DvzMJQDqN9sKrtwg,55
|
|
2
|
+
smartpi/base_driver.py,sha256=RVZQX1wbSVToJ_fsvxeVcc-v31LnND3YUPCybyUZa3s,18021
|
|
3
|
+
smartpi/color_sensor.py,sha256=sTqD3jApjmc6qHMrDyEy2UjaRt8vhJZNR88vzgUiLKs,496
|
|
4
|
+
smartpi/cw2015.py,sha256=1lAF-pi_ye_ya1AZQS1sjbgsDf7MThO5IAskKsNGBzA,5695
|
|
5
|
+
smartpi/gui.py,sha256=E98_soyWbEf_dwYhXZgMSXrgY5QuYoDTuFCPK63flIQ,2102
|
|
6
|
+
smartpi/humidity.py,sha256=xtALQ_IlcwR2RCYvopCSmeNajB45kQU_ckk6FZ0rqko,497
|
|
7
|
+
smartpi/led.py,sha256=n3_k1jGcQptfGXhezDLaYzH6UptgluP4Ze6qP_Y4WmU,536
|
|
8
|
+
smartpi/light_sensor.py,sha256=kWmoXklYS1QG0eDz4Qn9FF4WueR3GARb3OwQSkXqUNA,569
|
|
9
|
+
smartpi/motor.py,sha256=uvuAwt2j5LjdLaMfNisXqaGh1ro3fZDvHU8IXd2fn9Q,4527
|
|
10
|
+
smartpi/move.py,sha256=3qzrJCGA-qbsLXBpklY2DErtw0jlzMELzozjhEvRzKs,6028
|
|
11
|
+
smartpi/servo.py,sha256=0KfWM1PEBL2u15-lZnzav_qTWErf0ldeuX265c6oUPM,4623
|
|
12
|
+
smartpi/temperature.py,sha256=px2YeqgG63nPkyhJA1wDg3dwYx_oOCYuhMjtsVm_YO0,460
|
|
13
|
+
smartpi/touch_sensor.py,sha256=F6IIQGewNRhC9U1RbHpVzuGYqb8H41lpeQ1Ejwsc_T8,438
|
|
14
|
+
smartpi/ultrasonic.py,sha256=0meczFKXFLUt92kLxipeEc37vb5duvJjPs4kgtlpO8M,622
|
|
15
|
+
smartpi-0.1.11.dist-info/METADATA,sha256=Vthva8Lex9bj8dr-QULiRbD0GuitBBR_0hRnCLlFRZQ,311
|
|
16
|
+
smartpi-0.1.11.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
17
|
+
smartpi-0.1.11.dist-info/top_level.txt,sha256=PoLhUCmWAiQUg5UeN2fS-Y1iQyBbF2rdUlizXtpHGRQ,8
|
|
18
|
+
smartpi-0.1.11.dist-info/RECORD,,
|
smartpi-0.1.9.dist-info/RECORD
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
smartpi/__init__.py,sha256=1GIYn_KvjJ8KECZ8TW56CcZUERF5WVdQ-QM6gyofxlw,54
|
|
2
|
-
smartpi/base_driver.py,sha256=nfvzjcVZGrRldtAeAtL4MDlEMh4qbF28gbrf1-71N0c,17994
|
|
3
|
-
smartpi/color_sensor.py,sha256=IubJb8zd87oWf3qTn07wTHM2vjUADwgSdXUChGgovHw,492
|
|
4
|
-
smartpi/cw2015.py,sha256=1lAF-pi_ye_ya1AZQS1sjbgsDf7MThO5IAskKsNGBzA,5695
|
|
5
|
-
smartpi/gui.py,sha256=E98_soyWbEf_dwYhXZgMSXrgY5QuYoDTuFCPK63flIQ,2102
|
|
6
|
-
smartpi/humidity.py,sha256=-awlSiy7ea6iwtirUMdDAMmmdIgVQZ3D7cDzgXmy314,493
|
|
7
|
-
smartpi/led.py,sha256=92SBKjQbg1HN6rtKRH1NNWvAFRBP2-5OUGM9muOvhyQ,526
|
|
8
|
-
smartpi/light_sensor.py,sha256=wsW0_ZnKeHN6IWRH3CIybKLdHPVK2I8jSTCqXlUECVk,565
|
|
9
|
-
smartpi/motor.py,sha256=vdtLjHSwCodFkqhYh0y3l8RSl7IUlMwdNuktgQ3FdkQ,4449
|
|
10
|
-
smartpi/move.py,sha256=MUu1Hnu77gebTJLjnYq27mLYrjvBvDh9a6TWJ-GXgLk,6155
|
|
11
|
-
smartpi/servo.py,sha256=_eM3ZAcBA543iVyFi8agOAXt0K3LEauxwyq7SFCpygM,4537
|
|
12
|
-
smartpi/temperature.py,sha256=JeuiwsV6AUjnFQsQxgvjM3AuBrVvK5DuSE-BbX1Di2s,456
|
|
13
|
-
smartpi/touch_sensor.py,sha256=jlKqvcoSmfZzH9zJeafBeVEQhxIYkkzXe4_fifX0COI,434
|
|
14
|
-
smartpi/ultrasonic.py,sha256=5MS0EdQNirAl8iZbdwZ63fnjp6axHRZHw6dJwcwuXnQ,618
|
|
15
|
-
smartpi-0.1.9.dist-info/METADATA,sha256=7JJLk0Uol-2FcoiVBjYyqYhCIuKfilRYAxSuwEv4fKc,310
|
|
16
|
-
smartpi-0.1.9.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
17
|
-
smartpi-0.1.9.dist-info/top_level.txt,sha256=PoLhUCmWAiQUg5UeN2fS-Y1iQyBbF2rdUlizXtpHGRQ,8
|
|
18
|
-
smartpi-0.1.9.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|