Debugging

pull/1/head
Julius Riegel 7 years ago
parent f82b44397b
commit 56ddd9022d

@ -3,6 +3,8 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="49388e57-2b9e-468a-b880-1d7fb243112d" name="Default" comment=""> <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/controllib.py" afterPath="$PROJECT_DIR$/lib/controllib.py" />
<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> </list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="TRACKING_ENABLED" value="true" /> <option name="TRACKING_ENABLED" value="true" />
@ -29,8 +31,8 @@
<file leaf-file-name="main.py" pinned="false" current-in-tab="false"> <file leaf-file-name="main.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/main.py"> <entry file="file://$PROJECT_DIR$/main.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="697"> <state relative-caret-position="321">
<caret line="41" column="28" lean-forward="true" selection-start-line="41" selection-start-column="28" selection-end-line="41" selection-end-column="28" /> <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> <folding>
<element signature="e#0#19#0" expanded="true" /> <element signature="e#0#19#0" expanded="true" />
</folding> </folding>
@ -41,7 +43,7 @@
<file leaf-file-name="graphiclib.py" pinned="false" current-in-tab="false"> <file leaf-file-name="graphiclib.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/graphiclib.py"> <entry file="file://$PROJECT_DIR$/lib/graphiclib.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="389"> <state relative-caret-position="1103">
<caret line="86" column="12" lean-forward="false" selection-start-line="86" selection-start-column="12" selection-end-line="86" selection-end-column="12" /> <caret line="86" column="12" lean-forward="false" selection-start-line="86" selection-start-column="12" selection-end-line="86" selection-end-column="12" />
<folding> <folding>
<element signature="e#0#28#0" expanded="true" /> <element signature="e#0#28#0" expanded="true" />
@ -53,13 +55,25 @@
<file leaf-file-name="controllib.py" pinned="false" current-in-tab="true"> <file leaf-file-name="controllib.py" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/lib/controllib.py"> <entry file="file://$PROJECT_DIR$/lib/controllib.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="187"> <state relative-caret-position="493">
<caret line="11" column="58" lean-forward="false" selection-start-line="11" selection-start-column="58" selection-end-line="11" selection-end-column="58" /> <caret line="53" column="38" lean-forward="true" selection-start-line="53" selection-start-column="38" selection-end-line="53" selection-end-column="38" />
<folding /> <folding />
</state> </state>
</provider> </provider>
</entry> </entry>
</file> </file>
<file leaf-file-name="hardwarelib.py" pinned="false" current-in-tab="false">
<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" />
<folding>
<element signature="e#0#41#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="update.sh" pinned="false" current-in-tab="false"> <file leaf-file-name="update.sh" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/update.sh"> <entry file="file://$PROJECT_DIR$/update.sh">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
@ -108,9 +122,10 @@
<option value="$PROJECT_DIR$/servo_2.py" /> <option value="$PROJECT_DIR$/servo_2.py" />
<option value="$PROJECT_DIR$/thermo.py" /> <option value="$PROJECT_DIR$/thermo.py" />
<option value="$PROJECT_DIR$/update.sh" /> <option value="$PROJECT_DIR$/update.sh" />
<option value="$PROJECT_DIR$/main.py" />
<option value="$PROJECT_DIR$/lib/graphiclib.py" /> <option value="$PROJECT_DIR$/lib/graphiclib.py" />
<option value="$PROJECT_DIR$/lib/controllib.py" /> <option value="$PROJECT_DIR$/lib/controllib.py" />
<option value="$PROJECT_DIR$/lib/hardwarelib.py" />
<option value="$PROJECT_DIR$/main.py" />
</list> </list>
</option> </option>
</component> </component>
@ -321,14 +336,6 @@
<watches-manager /> <watches-manager />
</component> </component>
<component name="editorHistoryManager"> <component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/install.sh">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="0">
<caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/motors.py" /> <entry file="file://$PROJECT_DIR$/motors.py" />
<entry file="file://$PROJECT_DIR$/main.py"> <entry file="file://$PROJECT_DIR$/main.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
@ -496,10 +503,20 @@
</state> </state>
</provider> </provider>
</entry> </entry>
<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" />
<folding>
<element signature="e#0#41#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/main.py"> <entry file="file://$PROJECT_DIR$/main.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="697"> <state relative-caret-position="321">
<caret line="41" column="28" lean-forward="true" selection-start-line="41" selection-start-column="28" selection-end-line="41" selection-end-column="28" /> <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> <folding>
<element signature="e#0#19#0" expanded="true" /> <element signature="e#0#19#0" expanded="true" />
</folding> </folding>
@ -508,7 +525,7 @@
</entry> </entry>
<entry file="file://$PROJECT_DIR$/lib/graphiclib.py"> <entry file="file://$PROJECT_DIR$/lib/graphiclib.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="389"> <state relative-caret-position="1103">
<caret line="86" column="12" lean-forward="false" selection-start-line="86" selection-start-column="12" selection-end-line="86" selection-end-column="12" /> <caret line="86" column="12" lean-forward="false" selection-start-line="86" selection-start-column="12" selection-end-line="86" selection-end-column="12" />
<folding> <folding>
<element signature="e#0#28#0" expanded="true" /> <element signature="e#0#28#0" expanded="true" />
@ -518,8 +535,8 @@
</entry> </entry>
<entry file="file://$PROJECT_DIR$/lib/controllib.py"> <entry file="file://$PROJECT_DIR$/lib/controllib.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="187"> <state relative-caret-position="493">
<caret line="11" column="58" lean-forward="false" selection-start-line="11" selection-start-column="58" selection-end-line="11" selection-end-column="58" /> <caret line="53" column="38" lean-forward="true" selection-start-line="53" selection-start-column="38" selection-end-line="53" selection-end-column="38" />
<folding /> <folding />
</state> </state>
</provider> </provider>

@ -1,13 +1,13 @@
import pygame, os import pygame, os
class Joystick():
class Joystick():
def __init__(self, navigator, light, configuration, camera): def __init__(self, navigator, light, configuration, camera):
#joystick # joystick
pygame.joystick.init() pygame.joystick.init()
joystick = pygame.joystick.Joystick(0) joystick = pygame.joystick.Joystick(0)
joystick.init() joystick.init()
#sound # sound
pygame.mixer.init() pygame.mixer.init()
sound = pygame.mixer.Sound('./sounds/gasgasgas.wav') sound = pygame.mixer.Sound('./sounds/gasgasgas.wav')
sound.set_volume(0.3) sound.set_volume(0.3)
@ -24,27 +24,27 @@ class Joystick():
c = self.configuration c = self.configuration
nav = self.navigator nav = self.navigator
dict = {} dict = {}
#axes # axes
for i in range(self.joystick.get_numaxes()): for i in range(self.joystick.get_numaxes()):
axis = self.joystick.get_axis(i) axis = self.joystick.get_axis(i)
dict['Axis {}'.format(i)]=axis dict['Axis {}'.format(i)] = axis
if i==c['GAS'] and axis>0.1: if i == c['GAS'] and axis > 0.1:
nav.forward() nav.forward()
elif i==c['GAS'] and axis<0.1: elif i == c['GAS'] and axis < 0.1:
nav.stop() nav.stop()
#buttons # buttons
for i in range(self.joystick.get_numbuttons()): for i in range(self.joystick.get_numbuttons()):
button = self.joystick.get_button(i) button = self.joystick.get_button(i)
dict['Button {}'.format(i)] = button dict['Button {}'.format(i)] = button
if i==c['LIGHT'] and button==1 and button not in self.pressed: if i == c['LIGHT'] and button == 1 and button not in self.pressed:
self.light.switch() self.light.switch()
self.pressed.append(i) self.pressed.append(i)
elif i==c['LIGHT'] and button==0 and button in self.pressed: elif i == c['LIGHT'] and button == 0 and button in self.pressed:
self.pressed.remove(i) self.pressed.remove(i)
elif i==c['MUSIC'] and button==1 and button not in self.pressed: elif i == c['MUSIC'] and button == 1 and button not in self.pressed:
if self.splaying: if self.splaying:
self.sound.stop() self.sound.stop()
self.splaying = False self.splaying = False
@ -52,35 +52,35 @@ class Joystick():
self.sound.play() self.sound.play()
self.splaying = True self.splaying = True
self.pressed.append(i) self.pressed.append(i)
elif i==c['MUSIC'] and button==0 and button in self.pressed: elif i == c['MUSIC'] and button == 0 and button in self.pressed:
self.pressed.remove(i) self.pressed.remove(i)
elif i==c['VOLIN'] and button==1 and button not in self.pressed: elif i == c['VOLIN'] and button == 1 and button not in self.pressed:
self.sound.set_volume(self.sound.get_volume()+0.1) self.sound.set_volume(self.sound.get_volume() + 0.1)
self.pressed.append(i) self.pressed.append(i)
elif i==c['VOLIN'] and button==0 and button in self.pressed: elif i == c['VOLIN'] and button == 0 and button in self.pressed:
self.sound.set_volume(self.sound.get_volume() - 0.1) self.sound.set_volume(self.sound.get_volume() - 0.1)
self.pressed.remove(i) self.pressed.remove(i)
elif i==c['VOLDE'] and button==1 and button not in self.pressed: elif i == c['VOLDE'] and button == 1 and button not in self.pressed:
self.pressed.append(i) self.pressed.append(i)
elif i==c['VOLDE'] and button==0 and button in self.pressed: elif i == c['VOLDE'] and button == 0 and button in self.pressed:
self.pressed.remove(i) self.pressed.remove(i)
elif i==c['REC'] and button==1 and button not in self.pressed: elif i == c['REC'] and button == 1 and button not in self.pressed:
self._save_camimg() self._save_camimg()
self.pressed.append(i) self.pressed.append(i)
elif i==c['REC'] and button==0 and button in self.pressed: elif i == c['REC'] and button == 0 and button in self.pressed:
self.pressed.remove(i) self.pressed.remove(i)
#hats # hats
for i in range(self.joystick.get_numhats()): for i in range(self.joystick.get_numhats()):
hat = self.joystick.get_hat(i) hat = self.joystick.get_hat(i)
dict['Hat {}'.format(i)] = hat dict['Hat {}'.format(i)] = hat
if hat==(-1,0): if hat == (-1, 0):
nav.left() nav.left()
elif hat==(1,0): elif hat == (1, 0):
nav.right() nav.right()
else: else:
nav.straight() nav.straight()
@ -88,13 +88,12 @@ class Joystick():
dict['Volume'] = self.sound.get_volume() dict['Volume'] = self.sound.get_volume()
return dict return dict
def _save_camimg(self): def _save_camimg(self):
self.camera.new_frame() self.camera.new_frame()
img = self.camera.image img = self.camera.image
if os.path.isfile('image.jpg'): if os.path.isfile('image.jpg'):
count=0 count = 0
while os.path.isfile('./images/img{}.jpg'.format(count)): while os.path.isfile('./images/img{}.jpg'.format(count)):
count+=1 count += 1
os.rename('image.jpg', 'images/img{}.jpg'.format(count)) os.rename('image.jpg', 'images/img{}.jpg'.format(count))
pygame.image.save(img, 'image.jpg') pygame.image.save(img, 'image.jpg')

@ -2,6 +2,7 @@ from subprocess import call, check_output
from lib import ultrasonic from lib import ultrasonic
import RPi.GPIO as GPIO import RPi.GPIO as GPIO
class Navigator(): class Navigator():
"""Forward Motor with relais, Steering with servo""" """Forward Motor with relais, Steering with servo"""
@ -11,29 +12,24 @@ class Navigator():
GPIO.setup(self.mrelpin, GPIO.OUT) GPIO.setup(self.mrelpin, GPIO.OUT)
self.stop() self.stop()
def left(self): def left(self):
if self.steer != 'left': if self.steer != 'left':
call(['python', './lib/servolib.py', 'left']) call(['python', './lib/servolib.py', 'left'])
self.steer = 'left' self.steer = 'left'
def right(self): def right(self):
if self.steer != 'right': if self.steer != 'right':
call(['python', './lib/servolib.py', 'right']) call(['python', './lib/servolib.py', 'right'])
self.steer = 'right' self.steer = 'right'
def straight(self): def straight(self):
if self.steer: if self.steer:
call(['python', './lib/servolib.py']) call(['python', './lib/servolib.py'])
self.steer = None self.steer = None
def forward(self): def forward(self):
GPIO.output(self.mrelpin, False) GPIO.output(self.mrelpin, False)
def stop(self): def stop(self):
GPIO.output(self.mrelpin, True) GPIO.output(self.mrelpin, True)
@ -47,16 +43,14 @@ class Light:
GPIO.output(self.pin, True) GPIO.output(self.pin, True)
self.shine = False self.shine = False
def switch(self): def switch(self):
print('light switch {}'.format(self.shine))
GPIO.output(self.pin, not self.shine) GPIO.output(self.pin, not self.shine)
self.shine = not self.shine self.shine = not self.shine
def switch_on(self): def switch_on(self):
GPIO.output(self.pin, False) GPIO.output(self.pin, False)
def switch_of(self): def switch_of(self):
GPIO.output(self.pin, True) GPIO.output(self.pin, True)
@ -65,15 +59,13 @@ class Ultrasonic:
"""A ultrasonic sensor""" """A ultrasonic sensor"""
def __init__(self, trigger, echo): def __init__(self, trigger, echo):
self.sensor =ultrasonic.Sensor() self.sensor = ultrasonic.Sensor()
self.sensor.init(trigger, echo) self.sensor.init(trigger, echo)
def get_distance(self): def get_distance(self):
distance = self.sensor.echo() distance = self.sensor.echo()
return distance return distance
def __del__(self): def __del__(self):
self.sensor.clean() self.sensor.clean()
@ -82,12 +74,11 @@ class Temperature:
"""A temperature sensor""" """A temperature sensor"""
def get_Temperature(self): def get_Temperature(self):
outp = check_output(['python','-u','./lib/thermolib.py']).decode('ISO-8859-1') outp = check_output(['python', '-u', './lib/thermolib.py']).decode('ISO-8859-1')
temp, hum = outp.split('|') temp, hum = outp.split('|')
return temp return temp
def get_Humidity(self): def get_Humidity(self):
outp = check_output(['python','-u','./lib/thermolib.py']).decode('ISO-8859-1') outp = check_output(['python', '-u', './lib/thermolib.py']).decode('ISO-8859-1')
temp, hum = outp.split('|') temp, hum = outp.split('|')
return hum return hum

@ -36,15 +36,10 @@ def main():
running = False running = False
dict = jstick.handle() dict = jstick.handle()
print('joystick handled')
list.set_dict(dict) list.set_dict(dict)
print('list has dict')
all_sprites.update() all_sprites.update()
print('updating sprites')
update_rects = all_sprites.draw(screen.screen) update_rects = all_sprites.draw(screen.screen)
print('drawing sprites')
screen.refresh(rectangles= update_rects) screen.refresh(rectangles= update_rects)
print('refreshing screen')
pygame.quit() pygame.quit()

Loading…
Cancel
Save