Added Ultrasonic Sensor

Ultrasonic sensor implemented and now in use.
pull/1/head
Julius Riegel 7 years ago
parent d0a058e662
commit cbcd4cf937

@ -2,8 +2,9 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="49388e57-2b9e-468a-b880-1d7fb243112d" name="Default" comment="">
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/lib/controllib.py" afterPath="$PROJECT_DIR$/lib/controllib.py" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/lib/graphiclib.py" afterPath="$PROJECT_DIR$/lib/graphiclib.py" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/install.sh" afterPath="$PROJECT_DIR$/install.sh" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/lib/hardwarelib.py" afterPath="$PROJECT_DIR$/lib/hardwarelib.py" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/main.py" afterPath="$PROJECT_DIR$/main.py" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="TRACKING_ENABLED" value="true" />
@ -20,8 +21,8 @@
<file leaf-file-name="install.sh" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/install.sh">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="136">
<caret line="8" column="20" lean-forward="false" selection-start-line="8" selection-start-column="20" selection-end-line="8" selection-end-column="20" />
<state relative-caret-position="102">
<caret line="6" column="33" lean-forward="false" selection-start-line="6" selection-start-column="33" selection-end-line="6" selection-end-column="33" />
<folding />
</state>
</provider>
@ -30,8 +31,8 @@
<file leaf-file-name="main.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/main.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="321">
<caret line="37" column="30" lean-forward="false" selection-start-line="37" selection-start-column="30" selection-end-line="37" selection-end-column="30" />
<state relative-caret-position="272">
<caret line="28" column="18" lean-forward="false" selection-start-line="28" selection-start-column="18" selection-end-line="28" selection-end-column="18" />
<folding>
<element signature="e#0#19#0" expanded="true" />
</folding>
@ -51,21 +52,21 @@
</provider>
</entry>
</file>
<file leaf-file-name="controllib.py" pinned="false" current-in-tab="true">
<file leaf-file-name="controllib.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/controllib.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="266">
<state relative-caret-position="321">
<caret line="42" column="38" lean-forward="true" selection-start-line="42" selection-start-column="38" selection-end-line="42" selection-end-column="38" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="hardwarelib.py" pinned="false" current-in-tab="false">
<file leaf-file-name="hardwarelib.py" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/lib/hardwarelib.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="306">
<caret line="48" column="35" lean-forward="true" selection-start-line="48" selection-start-column="35" selection-end-line="48" selection-end-column="35" />
<state relative-caret-position="185">
<caret line="70" column="35" lean-forward="false" selection-start-line="70" selection-start-column="35" selection-end-line="70" selection-end-column="35" />
<folding>
<element signature="e#0#41#0" expanded="true" />
</folding>
@ -125,16 +126,16 @@
<option value="$PROJECT_DIR$/gyro_test.py" />
<option value="$PROJECT_DIR$/ultrasonic.py" />
<option value="$PROJECT_DIR$/gyro.py" />
<option value="$PROJECT_DIR$/install.sh" />
<option value="$PROJECT_DIR$/motors.py" />
<option value="$PROJECT_DIR$/motor.py" />
<option value="$PROJECT_DIR$/servo_2.py" />
<option value="$PROJECT_DIR$/thermo.py" />
<option value="$PROJECT_DIR$/update.sh" />
<option value="$PROJECT_DIR$/lib/hardwarelib.py" />
<option value="$PROJECT_DIR$/main.py" />
<option value="$PROJECT_DIR$/lib/graphiclib.py" />
<option value="$PROJECT_DIR$/lib/controllib.py" />
<option value="$PROJECT_DIR$/install.sh" />
<option value="$PROJECT_DIR$/main.py" />
<option value="$PROJECT_DIR$/lib/hardwarelib.py" />
</list>
</option>
</component>
@ -482,14 +483,6 @@
<entry file="file://$PROJECT_DIR$/main beta.py" />
<entry file="file://$PROJECT_DIR$/gyro.py" />
<entry file="file://$PROJECT_DIR$/motors.py" />
<entry file="file://$PROJECT_DIR$/install.sh">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="136">
<caret line="8" column="20" lean-forward="false" selection-start-line="8" selection-start-column="20" selection-end-line="8" selection-end-column="20" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/gyro_test.py" />
<entry file="file://$PROJECT_DIR$/ultrasonic_test.py" />
<entry file="file://$PROJECT_DIR$/ultrasonic.py" />
@ -512,41 +505,49 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/hardwarelib.py">
<entry file="file://$PROJECT_DIR$/lib/graphiclib.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="306">
<caret line="48" column="35" lean-forward="true" selection-start-line="48" selection-start-column="35" selection-end-line="48" selection-end-column="35" />
<state relative-caret-position="457">
<caret line="64" column="32" lean-forward="false" selection-start-line="64" selection-start-column="32" selection-end-line="64" selection-end-column="32" />
<folding>
<element signature="e#0#41#0" expanded="true" />
<element signature="e#0#28#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/main.py">
<entry file="file://$PROJECT_DIR$/install.sh">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="102">
<caret line="6" column="33" lean-forward="false" selection-start-line="6" selection-start-column="33" selection-end-line="6" selection-end-column="33" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/controllib.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="321">
<caret line="37" column="30" lean-forward="false" selection-start-line="37" selection-start-column="30" selection-end-line="37" selection-end-column="30" />
<folding>
<element signature="e#0#19#0" expanded="true" />
</folding>
<caret line="42" column="38" lean-forward="true" selection-start-line="42" selection-start-column="38" selection-end-line="42" selection-end-column="38" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/graphiclib.py">
<entry file="file://$PROJECT_DIR$/main.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="457">
<caret line="64" column="32" lean-forward="false" selection-start-line="64" selection-start-column="32" selection-end-line="64" selection-end-column="32" />
<state relative-caret-position="272">
<caret line="28" column="18" lean-forward="false" selection-start-line="28" selection-start-column="18" selection-end-line="28" selection-end-column="18" />
<folding>
<element signature="e#0#28#0" expanded="true" />
<element signature="e#0#19#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/controllib.py">
<entry file="file://$PROJECT_DIR$/lib/hardwarelib.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="266">
<caret line="42" column="38" lean-forward="true" selection-start-line="42" selection-start-column="38" selection-end-line="42" selection-end-column="38" />
<folding />
<state relative-caret-position="185">
<caret line="70" column="35" lean-forward="false" selection-start-line="70" selection-start-column="35" selection-end-line="70" selection-end-column="35" />
<folding>
<element signature="e#0#41#0" expanded="true" />
</folding>
</state>
</provider>
</entry>

@ -3,8 +3,8 @@ sudo apt update
sudo apt upgrade
sudo apt dist-upgrade
sudo pip3 install pygame
sudo apt install python-smbus
sudo apt install i2c-tools
sudo apt-get install -y python-smbus
sudo apt-get install -y i2c-tools
sudo pip install adafruit-pca9685
sudo apt install vsftpd
sudo apt install vlc

@ -1,6 +1,7 @@
from subprocess import call, check_output
from lib import ultrasonic
import RPi.GPIO as GPIO
import time
class Navigator():
@ -61,10 +62,14 @@ class Ultrasonic:
def __init__(self, trigger, echo):
self.sensor = ultrasonic.Sensor()
self.sensor.init(trigger, echo)
self.time = 0
self.distance = 0
def get_distance(self):
distance = self.sensor.echo()
return distance
if (time.time()-self.time)>1:
self.distance = self.sensor.echo()
self.time = time.time()
return self.distance
def __del__(self):
self.sensor.clean()

@ -29,6 +29,7 @@ def main():
running = True
while running:
clock.tick(25)
for event in pygame.event.get():
if event.type == pygame.QUIT:
@ -36,6 +37,7 @@ def main():
running = False
dict = jstick.handle()
dict['Distance'] = ultrasonic.get_distance()
list.set_dict(dict)
all_sprites.update()
update_rects = all_sprites.draw(screen.screen)

Loading…
Cancel
Save