init to commit it

This commit is contained in:
2022-03-11 12:39:20 -05:00
parent 608af373e6
commit f0bab10e25
28 changed files with 143 additions and 23 deletions

View File

@@ -0,0 +1,5 @@
wiper_servo:
pin: 17
min_pulse: 0.000544
max_pulse: 0.0024

View File

@@ -0,0 +1,11 @@
[Unit]
Description=Crawler service overseer, manages running main crawler software
After=multi-user.target
[Service]
Type=simple
Restart=always
ExecStart=/usr/bin/python /srv/crawler/crawler.py
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,2 @@
PySSTV
picamera

View File

@@ -0,0 +1,87 @@
from shutil import copyfile
from PIL import Image, ImageFont, ImageDraw
from pysstv import color
import logging as log
try:
from picamera import PiCamera
except ModuleNotFoundError:
log.info("Running in simulator mode")
def take_photo():
# This def is meant to take a photograph from the robot,
# it should include all steps and error checking to raise the mast
# Take the photo, and put the mast down.
# Copy in the test pattern png (if photo process errors out, this will be used instead)
log.debug('Copying test pattern.')
copyfile('photos/TEST_PATTERN.jpg', 'working/working.jpg')
# Software to take the photo should be here
#copyfile('photos/camera_latest.jpg', 'working/working.jpg')
log.debug('Initalizing camera.')
try:
camera = PiCamera()
log.info('Saving photo.')
camera.capture('working/working.jpg')
except NameError:
log.info("Running in simulator mode, not replacing test pattern")
def mark_photo():
log.info('Opening photo for viewing.')
raw_img = Image.open("working/working.jpg") # Open the current working image
log.info('Resizing image.')
img = raw_img.resize((320, 240), Image.ANTIALIAS) # resize it for the radio
log.info('Drawing on image.')
if False:
TINT_COLOR = (255, 255, 255) # White text bg
TEXT_COLOR = (0,0,0)
else:
TINT_COLOR = (0, 0, 0) # Black text bg
TEXT_COLOR = (255,255,255)
TRANSPARENCY = .25 # Degree of transparency, 0-100%
OPACITY = int(255 * TRANSPARENCY)
overlay = Image.new('RGBA', img.size, TINT_COLOR+(0,))
draw = ImageDraw.Draw(overlay)
#bigfont = ImageFont.truetype(r'C:\Users\System-Pc\Desktop\arial.ttf', 20)
#smallfont = ImageFont.truetype(r'C:\Users\System-Pc\Desktop\arial.ttf', 17)
draw.rectangle(((0, 0), (90, 20)), fill=TINT_COLOR+(OPACITY,))
#draw.text((0, 0),"KW1FOX",TEXT_COLOR,font=bigfont) # Draw KW1FOX in the top left
draw.rectangle(((0, 40), (83, 80)), fill=TINT_COLOR+(OPACITY,))
#draw.text((0, 40),"day: 25.2",TEXT_COLOR,font=smallfont)
#draw.text((0, 60),"Volt: 13.8",TEXT_COLOR,font=smallfont)
#draw.text((0, 80),"Miles: 1.02",TEXT_COLOR,font=smallfont)
log.info('Converting image color.')
img = img.convert("RGBA")
img = Image.alpha_composite(img, overlay)
img = img.convert("RGB")
img.save('working/working.jpg') # Save the working image
return img
if __name__ == "__main__":
log.basicConfig(level=log.DEBUG)
# Take photograph.
log.info('Taking Photograph')
take_photo() # Saves a photograph to the working/working.jpg location
log.info('Done taking photo.')
# Draw neccicary text on photo
log.info('Drawing on photo.')
radio_photo = mark_photo() # draws text on working/working.jpg and returns a PIL image
log.info('Done drawing on photo.')
log.info('Creating slowscan.')
slowscan = color.Robot36(radio_photo, 48000, 16) # Image, rate, bits
#slowscan = color.MartinM1(radio_photo, 48000, 16) # Image, rate, bits
log.info('Saving out slowscan.')
slowscan.write_wav('working/working.wav')
#sstv('working/working.png', 'working/radio.wav', mode='Robot36')

View File

@@ -0,0 +1,73 @@
from discord_webhook import DiscordWebhook
from picamera import PiCamera
from time import sleep
from gps import *
from smbus import SMBus
import time
addr = 0x4 # bus address
bus = SMBus(1) # indicates /dev/ic2-1
numb = 1
def writeData(value):
byteValue = StringToBytes(value)
bus.write_i2c_block_data(addr,0x00,byteValue) #first byte is 0=command byte.. just is.
return -1
def StringToBytes(val):
retVal = []
for c in val:
retVal.append(ord(c))
return retVal
try:
for _x in range (0, 2):
for i in range(78, 130):
writeData("WIPE-" + str(i))
time.sleep(0.02)
for i in range(130, 78, -1):
writeData("WIPE-" + str(i))
time.sleep(0.02)
except OSError:
print("Could not speak to ardujmemo")
def get_uptime():
with open('/proc/uptime', 'r') as f:
uptime_seconds = float(f.readline().split()[0])
return uptime_seconds
def getPositionData(gps):
location = [None]
while(location[0] == None):
print("Trying again")
nx = gpsd.next()
# For a list of all supported classes and fields refer to:
# https://gpsd.gitlab.io/gpsd/gpsd_json.html
if nx['class'] == 'TPV':
latitude = getattr(nx,'lat', "Unknown")
longitude = getattr(nx,'lon', "Unknown")
#print "Your position: lon = " + str(longitude) + ", lat = " + str(latitude)
location = [latitude, longitude]
return location
gpsd = gps(mode=WATCH_ENABLE|WATCH_NEWSTYLE)
loc = getPositionData(gpsd)
webhookURL = "https://discord.com/api/webhooks/856609966404534272/TR9tnLq2sIGZoOeADNswmGRNlzBcqM5aKihfU6snVTP9WhSSoVVvi7nT6i-ZfZS7Hcqm"
print(loc[0])
print(loc[1])
webhook = DiscordWebhook(url=webhookURL, content="Uptime: " + str( round( ((get_uptime() / 60) / 60 ), 2 )) + " hours. Lat is " + str(loc[0]) + ", long is " + str(loc[1]))
camera = PiCamera()
sleep(3) # let iso settle out
camera.capture('still.jpg')
with open("still.jpg", "rb") as f:
webhook.add_file(file=f.read(), filename='still.jpg')
response = webhook.execute() # Hit send

View File

@@ -0,0 +1,19 @@
import RPi.GPIO as GPIO
import time
servoPIN = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(servoPIN, GPIO.OUT)
p = GPIO.PWM(servoPIN, 50) # GPIO 17 for PWM with 50Hz
p.start(2.5) # Initialization
try:
while True:
p.ChangeDutyCycle(10)
time.sleep(2)
p.ChangeDutyCycle(2.5)
time.sleep(2)
except KeyboardInterrupt:
p.stop()
GPIO.cleanup()

View File

@@ -0,0 +1,20 @@
import smbus
import time
import struct
# for RPI version 1, use bus = smbus.SMBus(0)
bus = smbus.SMBus(1)
# This is the address we setup in the Arduino Program
address = 0x04
try:
for _x in range (0, 2):
for i in range(78, 130):
bus.write_i2c_block_data(address, 0, [1, i])
time.sleep(0.02)
for i in range(130, 78, -1):
bus.write_i2c_block_data(address, 0, [1, i])
time.sleep(0.02)
except OSError:
print("Could not speak to ardujmemo")

View File

@@ -0,0 +1,35 @@
# Raspberry Pi Master for Arduino Slave
# i2c_master_pi.py
# Connects to Arduino via I2C
# DroneBot Workshop 2019
# https://dronebotworkshop.com
from smbus import SMBus
import time
addr = 0x8 # bus address
bus = SMBus(1) # indicates /dev/ic2-1
numb = 1
print ("Enter num")
for _x in range (0, 4):
for i in range(76, 130):
bus.write_byte(addr, i)
time.sleep(0.02)
for i in range(130, 76, -1):
bus.write_byte(addr, i)
time.sleep(0.02)
#while numb == 1:
#
# ledstate = input(">>>> ")
#
# if ledstate == "1":
# bus.write_byte(addr, 0x1) # switch it on
# elif ledstate == "0":
# bus.write_byte(addr, 0x0) # switch it on
# else:
# numb = 0

View File

@@ -0,0 +1,12 @@
import RPi.GPIO as GPIO # Import Raspberry Pi GPIO library
from time import sleep # Import the sleep function from the time module
GPIO.setwarnings(False) # Ignore warning for now
GPIO.setmode(GPIO.BOARD) # Use physical pin numbering
GPIO.setup(12, GPIO.OUT, initial=GPIO.LOW) # Set pin 8 to be an output pin and set initial value to low (off)
while True: # Run forever
GPIO.output(12, GPIO.HIGH) # Turn on
sleep(1) # Sleep for 1 second
GPIO.output(12, GPIO.LOW) # Turn off
sleep(1) # Sleep for 1 second