Week 3. Sep 5.12 2018 - michelle-qin/Portfolio GitHub Wiki
Updated Paint game to implement joystick function. The goal is to expand applications so that different buttons on external devices (e.g. the joystick) can control different colors on the paint canvas. Specifically, the code is written so that the mouse click results in color white and pressing joystick button results in color red. Currently in debugging stage as the joystick button seems to override the mouse click (i.e. once color changes to red, it won't change back). Edited code see below.
from random import random from kivy.app import App from kivy.uix.widget import Widget from kivy.uix.button import Button from kivy.graphics import Color, Ellipse, Line
import pygame pygame.init() pygame.joystick.init() global joysticks joysticks = pygame.joystick.Joystick(0) joysticks.init()
class MyPaintWidget(Widget):
def on_touch_down(self, touch):
with self.canvas:
import pygame
pygame.init()
pygame.joystick.init()
global joysticks
joysticks = pygame.joystick.Joystick(0)
joysticks.init()
pygame.event.pump()
if (joysticks.get_button(0)):
joysticks.init()
color = (0, 1, 1)
Color(*color, mode='hsv')
joysticks.init()
if(joysticks.get_button(1)):
joysticks.init()
color1 = (1, 0, 0)
Color(*color1, mode='hsv')
joysticks.init()
d = 30.
Ellipse(pos=(touch.x - d / 2, touch.y - d / 2), size=(d, d))
touch.ud['line'] = Line(points=(touch.x, touch.y))
joysticks.init()
def on_touch_move(self,touch):
touch.ud['line'].points += [touch.x, touch.y]
class MyPaintApp(App):
def build(self):
parent = Widget()
self.painter = MyPaintWidget()
clearbtn = Button(text='Clear')
clearbtn.bind(on_release=self.clear_canvas)
parent.add_widget(self.painter)
parent.add_widget(clearbtn)
return parent
def clear_canvas(self, obj):
self.painter.canvas.clear()
if name == 'main': MyPaintApp().run()
Began working on fixing robotic arm. Learned electrical components and the structure of putting the arduino boards together. Noticed that robotic arm seems to be bypassing the sensor (thus, crashing repeatedly into a post). It seems like the issue was a hardware one, so we used logic analyzer to track the activity in different ports.
Helped in connecting arduino boards for a perpetual motion structure. Further familiarized myself with logic behind hardware. After encountering another problem (the gate on the structure wouldn't open when we called it), we noticed it might be a software problem. Went into the code and found that the sys.path's were not updated. Since the code was written, documents were moved/organized which resulted in rearrangement of files. Updated the code to reflect changes (see below).
import RPi.GPIO as GPIO sys.path.insert(0, "/home/pi/Documents/RaspberryPiCommon/Libraries/Hardware") import Stepper sys.path.insert(0, "/home/pi/Documents/RaspberryPiCommon/Libraries/Hardware/RPiMIB") import RPiMIB
Continued to run into errors with opening gate. Went back into the code to focus on method "openGate." Realized parameters for RPiMIB.sendPWM may be wrong, as RPiMIB has been updated since code was originally written. Played around and tried new numbers (see below - we assumed first parameter represents port, second parameter represents amount of power). Still didn't work, currently trouble-shooting.
def openGate(self, isOpen):
if (isOpen == OPEN):
self.ids.gate.text = "Close Gate"
print('close gate')
RPiMIB.sendPWM(4, 2000)
else:
self.ids.gate.text = "Open Gate"
print('open gate')
RPiMIB.sendPWM(4, 1000)
self.isGateOpen = isOpen