EasyManua.ls Logo

SunFounder PiDog - Page 87

Default Icon
109 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
SunFounder PiDog Kit, Release 1.0
"single_bark_1"
"single_bark_2"
"snoring"
"woohoo"
Here is an example of usage:
from pidog import Pidog
import time
my_dog = Pidog()
try:
my_dog.do_action("sit", speed=60)
my_dog.wait_all_done()
time.sleep(0.5)
my_dog.do_action("wag_tail", step_count=100,speed=20)
my_dog.do_action("tilting_head", step_count=2, speed=20)
my_dog.speak('confused_3')
my_dog.wait_head_done()
my_dog.stop_and_lie()
except KeyboardInterrupt:
pass
except Exception as e:
print(f"\033[31mERROR: {e}\033[m")
finally:
print("closing ...")
my_dog.close()
2.3.8 Read Distance
Through the Ultrasonic Module in its head, PiDog can detect obstacles ahead.
An ultrasonic module can detect objects between 2 and 400 cm away.
With the following function, you can read the distance as a floating point number.
Pidog.ultrasonic.read_distance()
Here is an example of usage:
from pidog import Pidog
import time
my_dog = Pidog()
while True:
distance = my_dog.ultrasonic.read_distance()
distance = round(distance,2)
print(f"Distance: {distance} cm")
time.sleep(0.5)
2.3. Easy Coding 83

Related product manuals