Skip to content

EV3-G API: ultrasonic sensor #364#445

Merged
dwalton76 merged 1 commit intoev3dev:developfrom
dwalton76:ultrasonic
Jan 31, 2018
Merged

EV3-G API: ultrasonic sensor #364#445
dwalton76 merged 1 commit intoev3dev:developfrom
dwalton76:ultrasonic

Conversation

@dwalton76
Copy link
Copy Markdown
Collaborator

No description provided.

@dwalton76
Copy link
Copy Markdown
Collaborator Author

Tested via

robot@evb[ev3dev-lang-python]# cat utils/test_us.py 
#!/usr/bin/env python3

from ev3dev2.sensor.lego import UltrasonicSensor
import logging

log = logging.getLogger(__name__)



logging.basicConfig(level=logging.INFO,
                    format='%(asctime)s %(filename)12s %(levelname)8s: %(message)s')
log = logging.getLogger(__name__)

# Color the errors and warnings in red
logging.addLevelName(logging.ERROR, "\033[91m   %s\033[0m" % logging.getLevelName(logging.ERROR))
logging.addLevelName(logging.WARNING, "\033[91m %s\033[0m" % logging.getLevelName(logging.WARNING))

us = UltrasonicSensor()
print("inches   : %s" % us.distance_inches)
print("inches(c): %s" % us.distance_inches_continuous)
print("inches(p): %s" % us.distance_inches_ping)
print("centimeters   : %s" % us.distance_centimeters)
print("centimeters(c): %s" % us.distance_centimeters_continuous)
print("centimeters(p): %s" % us.distance_centimeters_ping)
print("other : %s" % us.other_sensor_present)

robot@evb[ev3dev-lang-python]# 

The only thing odd I've noticed is that after running the program above the ultrasonic sensor "blinks". I've never used one before so am not sure if this is normal.

@dwalton76 dwalton76 merged commit 39dd003 into ev3dev:develop Jan 31, 2018
@dwalton76 dwalton76 deleted the ultrasonic branch January 31, 2018 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants