Skip to content

Commit b03061b

Browse files
🐛
1 parent fbdeec6 commit b03061b

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "exboard"
3-
version = "1.0.10"
3+
version = "1.0.12"
44
authors = [
55
{ name="Allen", email="[email protected]" },
66
]

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name='exboard',
5-
version='1.0.10',
5+
version='1.0.12',
66
packages=find_packages(where='src'),
77
package_dir={'': 'src'},
88
include_package_data=True,

src/exboard/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
22
# coding:utf-8
3-
# Version: 1.0.10
3+
# Version: 1.0.12
44

55
def get_linux_distribution():
66
try:

src/exboard/jetson.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -993,12 +993,13 @@ class Ultrasound:
993993
最大测距理论值小于343
994994
"""
995995

996-
def __init__(self, trigger_pin=4, echo_pin=5, max_cm=None, timeout=0.1):
996+
def __init__(self, trigger_pin=4, echo_pin=5, max_cm=None, timeout=0.2,debug=False):
997997
# set GPIO Pins
998998
self.trigger = GPIO(trigger_pin, "out")
999999
self.echo = GPIO(echo_pin, "in")
10001000
self.max_cm = max_cm
10011001
self.timeout = timeout # 超时时间(秒)
1002+
self.debug = debug
10021003

10031004
def read(self):
10041005
# set Trigger to HIGH
@@ -1018,6 +1019,8 @@ def read(self):
10181019
while self.echo.read() == 0:
10191020
StartTime = time.time()
10201021
if time.time() - start_time > self.timeout: # 检查是否超时
1022+
if self.debug:
1023+
print("未检测到回声")
10211024
return 0
10221025
# save time of arrival
10231026
while self.echo.read() == 1:
@@ -1026,13 +1029,16 @@ def read(self):
10261029
if StopTime - StartTime > self.max_cm * 2 / 34300:
10271030
return self.max_cm
10281031
if time.time() - start_time > self.timeout: # 检查是否超时
1032+
if self.debug:
1033+
print("能检测到回声信号,但是滞后超时")
10291034
return 0
10301035

10311036
# time difference between start and arrival
10321037
TimeElapsed = StopTime - StartTime
10331038
# multiply with the sonic speed (34300 cm/s)
10341039
# and divide by 2, because there and back
1035-
distance = int(TimeElapsed * 34300) / 2
1040+
distance = round(TimeElapsed * 34300 / 2, 2) # 保留2位小数
1041+
distance = max(distance, 1.0) # 设置最小距离为1厘米
10361042
time.sleep(0.01)
10371043
return distance
10381044

0 commit comments

Comments
 (0)