Skip to content

Commit

Permalink
Merge pull request #13 from AvaPL/PawelC
Browse files Browse the repository at this point in the history
Might be the final version.
  • Loading branch information
AvaPL authored Feb 21, 2020
2 parents 5f3fbce + 00bb8ca commit bf1dee1
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 5 deletions.
20 changes: 15 additions & 5 deletions ARM/Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
arm = Arm(servoNumber, pulseWidths, initialAngles)

GPIO.setmode(GPIO.BCM)

connectionAvailablePin = 20
GPIO.setup(connectionAvailablePin, GPIO.OUT)

leftMotorPWMPin = 12
leftMotorDirectionPin = 5
rightMotorPWMPin = 13
Expand All @@ -25,19 +29,25 @@

commandInterpreter = CommandInterpreter(bluetoothConnection, arm, mobilePlatform)


def shutdown():
cleanup()
subprocess.call("sudo shutdown -h now", shell=True)


def cleanup():
bluetoothConnection.close()
mobilePlatform.stop()
GPIO.cleanup()
# subprocess.call("sudo shutdown -h now", shell=True) TODO: Uncomment, debug only.


try:
shutdownReceived = False
while not shutdownReceived: # Establish a new connection if the client disconnected.
while not shutdownReceived: # Establish a new connection if the client disconnected.
GPIO.output(connectionAvailablePin, GPIO.HIGH)
bluetoothConnection.establish()
GPIO.output(connectionAvailablePin, GPIO.LOW)
shutdownReceived = commandInterpreter.readCommands()
shutdown()
except:
pass
finally:
shutdown() # TODO: System shouldn't be always shut down eg. service restart.
cleanup()
12 changes: 12 additions & 0 deletions ARM/services/arm-service-activity.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Signals arm.service activity via led diode and provides a way of manual restart.
After=multi-user.target

[Service]
Type=idle
ExecStart=/usr/bin/python3 /home/pi/Projects/PyCharm/ARM/support/ARMServiceActivity.py
StandardOutput=file:/home/pi/Projects/PyCharm/ARM/support/ARMServiceActivity.out.log
StandardError=file:/home/pi/Projects/PyCharm/ARM/support/ARMServiceActivity.err.log

[Install]
WantedBy=multi-user.target
12 changes: 12 additions & 0 deletions ARM/services/arm-system-activity.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Signals system activity via led diode and provides a way of manual shutdown.
After=multi-user.target

[Service]
Type=idle
ExecStart=/usr/bin/python3 /home/pi/Projects/PyCharm/ARM/support/SystemActivity.py
StandardOutput=file:/home/pi/Projects/PyCharm/ARM/support/SystemActivity.out.log
StandardError=file:/home/pi/Projects/PyCharm/ARM/support/SystemActivity.err.log

[Install]
WantedBy=multi-user.target
12 changes: 12 additions & 0 deletions ARM/services/arm.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=ARM - Bluetooth-controlled robotic arm
After=bluetooth.target

[Service]
Type=idle
ExecStart=/usr/bin/python3 /home/pi/Projects/PyCharm/ARM/Main.py
StandardOutput=file:/home/pi/Projects/PyCharm/ARM/ARM.out.log
StandardError=file:/home/pi/Projects/PyCharm/ARM/ARM.err.log

[Install]
WantedBy=bluetooth.target
36 changes: 36 additions & 0 deletions ARM/support/ARMServiceActivity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from threading import Thread

import RPi.GPIO as GPIO
import subprocess

from Common import blinkLed, isButtonHeld

GPIO.setmode(GPIO.BCM)
restartServicePin = 26
GPIO.setup(restartServicePin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
activityLedPin = 16
GPIO.setup(activityLedPin, GPIO.OUT)


def restartService():
while True:
if isButtonHeld(restartServicePin, bouncetimeMillis=200, holdtimeMillis=2000):
callRestartSubprocess()


def callRestartSubprocess():
for i in range(5):
blinkLed(activityLedPin, onTimeMillis=100, offTimeMillis=100)
subprocess.call("sudo systemctl restart arm.service", shell=True)


restartServiceThread = Thread(target=restartService, daemon=True)
restartServiceThread.start()

try:
while True:
serviceStatus = subprocess.call("systemctl is-active --quiet arm.service", shell=True)
if serviceStatus == 0:
blinkLed(activityLedPin, onTimeMillis=200, offTimeMillis=2800)
finally:
GPIO.cleanup()
20 changes: 20 additions & 0 deletions ARM/support/Common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from time import sleep

import RPi.GPIO as GPIO


def isButtonHeld(pin, bouncetimeMillis, holdtimeMillis):
GPIO.wait_for_edge(pin, GPIO.FALLING)
sleep(bouncetimeMillis / 1000) # Debounce
if GPIO.input(pin) == GPIO.LOW:
edgeDetected = GPIO.wait_for_edge(pin, GPIO.RISING, timeout=holdtimeMillis - bouncetimeMillis)
if edgeDetected is None:
return True
return False


def blinkLed(pin, onTimeMillis, offTimeMillis):
GPIO.output(pin, GPIO.HIGH)
sleep(onTimeMillis / 1000)
GPIO.output(pin, GPIO.LOW)
sleep(offTimeMillis / 1000)
35 changes: 35 additions & 0 deletions ARM/support/SystemActivity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from threading import Thread

import RPi.GPIO as GPIO
import subprocess

from Common import blinkLed, isButtonHeld

GPIO.setmode(GPIO.BCM)
shutdownPin = 21
GPIO.setup(shutdownPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
activityLedPin = 19
GPIO.setup(activityLedPin, GPIO.OUT)


def shutdown():
while True:
if isButtonHeld(shutdownPin, bouncetimeMillis=200, holdtimeMillis=2000):
callShutdownSubprocess()


def callShutdownSubprocess():
for i in range(5):
blinkLed(activityLedPin, onTimeMillis=100, offTimeMillis=100)
GPIO.cleanup()
subprocess.call("sudo shutdown -h now", shell=True)


shutdownThread = Thread(target=shutdown, daemon=True)
shutdownThread.start()

try:
while True:
blinkLed(activityLedPin, onTimeMillis=200, offTimeMillis=2800)
finally:
GPIO.cleanup()
Binary file modified Chassis/Chassis_bottom.dwg
Binary file not shown.
Binary file modified Chassis/Chassis_bottom.pdf
Binary file not shown.
Binary file modified Chassis/Chassis_top.dwg
Binary file not shown.
Binary file modified Chassis/Chassis_top.pdf
Binary file not shown.

0 comments on commit bf1dee1

Please sign in to comment.