Debugging

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

@ -3,6 +3,8 @@
<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/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" />
@ -29,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="697">
<caret line="41" column="28" lean-forward="true" selection-start-line="41" selection-start-column="28" selection-end-line="41" selection-end-column="28" />
<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>
@ -41,7 +43,7 @@
<file leaf-file-name="graphiclib.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/graphiclib.py">
<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" />
<folding>
<element signature="e#0#28#0" expanded="true" />
@ -53,13 +55,25 @@
<file leaf-file-name="controllib.py" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/lib/controllib.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="187">
<caret line="11" column="58" lean-forward="false" selection-start-line="11" selection-start-column="58" selection-end-line="11" selection-end-column="58" />
<state relative-caret-position="493">
<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 />
</state>
</provider>
</entry>
</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">
<entry file="file://$PROJECT_DIR$/update.sh">
<provider selected="true" editor-type-id="text-editor">
@ -108,9 +122,10 @@
<option value="$PROJECT_DIR$/servo_2.py" />
<option value="$PROJECT_DIR$/thermo.py" />
<option value="$PROJECT_DIR$/update.sh" />
<option value="$PROJECT_DIR$/main.py" />
<option value="$PROJECT_DIR$/lib/graphiclib.py" />
<option value="$PROJECT_DIR$/lib/controllib.py" />
<option value="$PROJECT_DIR$/lib/hardwarelib.py" />
<option value="$PROJECT_DIR$/main.py" />
</list>
</option>
</component>
@ -321,14 +336,6 @@
<watches-manager />
</component>
<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$/main.py">
<provider selected="true" editor-type-id="text-editor">
@ -496,10 +503,20 @@
</state>
</provider>
</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">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="697">
<caret line="41" column="28" lean-forward="true" selection-start-line="41" selection-start-column="28" selection-end-line="41" selection-end-column="28" />
<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>
@ -508,7 +525,7 @@
</entry>
<entry file="file://$PROJECT_DIR$/lib/graphiclib.py">
<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" />
<folding>
<element signature="e#0#28#0" expanded="true" />
@ -518,8 +535,8 @@
</entry>
<entry file="file://$PROJECT_DIR$/lib/controllib.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="187">
<caret line="11" column="58" lean-forward="false" selection-start-line="11" selection-start-column="58" selection-end-line="11" selection-end-column="58" />
<state relative-caret-position="493">
<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 />
</state>
</provider>

@ -1,13 +1,13 @@
import pygame, os
class Joystick():
class Joystick():
def __init__(self, navigator, light, configuration, camera):
#joystick
# joystick
pygame.joystick.init()
joystick = pygame.joystick.Joystick(0)
joystick.init()
#sound
# sound
pygame.mixer.init()
sound = pygame.mixer.Sound('./sounds/gasgasgas.wav')
sound.set_volume(0.3)
@ -24,27 +24,27 @@ class Joystick():
c = self.configuration
nav = self.navigator
dict = {}
#axes
# axes
for i in range(self.joystick.get_numaxes()):
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()
elif i==c['GAS'] and axis<0.1:
elif i == c['GAS'] and axis < 0.1:
nav.stop()
#buttons
# buttons
for i in range(self.joystick.get_numbuttons()):
button = self.joystick.get_button(i)
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.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)
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:
self.sound.stop()
self.splaying = False
@ -52,35 +52,35 @@ class Joystick():
self.sound.play()
self.splaying = True
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)
elif i==c['VOLIN'] and button==1 and button not in self.pressed:
self.sound.set_volume(self.sound.get_volume()+0.1)
elif i == c['VOLIN'] and button == 1 and button not in self.pressed:
self.sound.set_volume(self.sound.get_volume() + 0.1)
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.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)
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)
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.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)
#hats
# hats
for i in range(self.joystick.get_numhats()):
hat = self.joystick.get_hat(i)
dict['Hat {}'.format(i)] = hat
if hat==(-1,0):
if hat == (-1, 0):
nav.left()
elif hat==(1,0):
elif hat == (1, 0):
nav.right()
else:
nav.straight()
@ -88,13 +88,12 @@ class Joystick():
dict['Volume'] = self.sound.get_volume()
return dict
def _save_camimg(self):
self.camera.new_frame()
img = self.camera.image
if os.path.isfile('image.jpg'):
count=0
count = 0
while os.path.isfile('./images/img{}.jpg'.format(count)):
count+=1
count += 1
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
import RPi.GPIO as GPIO
class Navigator():
"""Forward Motor with relais, Steering with servo"""
@ -11,29 +12,24 @@ class Navigator():
GPIO.setup(self.mrelpin, GPIO.OUT)
self.stop()
def left(self):
if self.steer != 'left':
call(['python', './lib/servolib.py', 'left'])
self.steer = 'left'
def right(self):
if self.steer != 'right':
call(['python', './lib/servolib.py', 'right'])
self.steer = 'right'
def straight(self):
if self.steer:
call(['python', './lib/servolib.py'])
self.steer = None
def forward(self):
GPIO.output(self.mrelpin, False)
def stop(self):
GPIO.output(self.mrelpin, True)
@ -47,16 +43,14 @@ class Light:
GPIO.output(self.pin, True)
self.shine = False
def switch(self):
print('light switch {}'.format(self.shine))
GPIO.output(self.pin, not self.shine)
self.shine = not self.shine
def switch_on(self):
GPIO.output(self.pin, False)
def switch_of(self):
GPIO.output(self.pin, True)
@ -65,15 +59,13 @@ class Ultrasonic:
"""A ultrasonic sensor"""
def __init__(self, trigger, echo):
self.sensor =ultrasonic.Sensor()
self.sensor = ultrasonic.Sensor()
self.sensor.init(trigger, echo)
def get_distance(self):
distance = self.sensor.echo()
return distance
def __del__(self):
self.sensor.clean()
@ -82,12 +74,11 @@ class Temperature:
"""A temperature sensor"""
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('|')
return temp
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('|')
return hum
return hum

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

Loading…
Cancel
Save