<commit_before>import time
import datetime
import subprocess
from collections import OrderedDict
from catnet.turning import stop, turn_clockwise, turn_c_clockwise
from catnet.compass import get_bearing
import RPi.GPIO as GPIO
import RPIO
import threading


GPIO_sensors = OrderedDict([
    (23, 0),
    (24, 117),
    (25, 180),
    (18, 278),
])

#Create a variable called daemon running, and a global set
angle_offset = None
daemon_running = False
motion_set = set()

#Function for reading motion_set and working out the correct angle to turn
def motion_bearing():
    motion_bearing = []
    for sensor, angle in GPIO_sensors.items():
        if sensor in motion_set:
            motion_bearing.append(angle)
    bearing = sum(motion_bearing)/len(motion_bearing)
    if bearing > 360:
        bearing = bearing - 360
    return bearing

#Function for activating turret
def turret(target_bearing):
    while True:
        current_bearing = get_bearing() - angle_offset
        if current_bearing < 0:
            current_bearing = current_bearing + 360
        print current_bearing
        if current_bearing - target_bearing > 10:
            turn_c_clockwise()
        elif current_bearing - target_bearing < -10:
            turn_clockwise()
        else:
            stop()
            break
        time.sleep(0.02)

#take picture function
def take_snap():
    time.sleep(1)
    file_name = (datetime.datetime.now()).strftime('%Y-%m-%d-%H-%M-%S')
    subprocess.call('fswebcam --device v4l2:/dev/video0 --input 0 --resolution 320x240 --skip 100 --jpeg 80 /home/jenny/test/image-{}.jpg'.format(file_name), shell=True)
    print "picture taken"

#Daemon thread
def activate_turret():
    global daemon_running
    time.sleep(0.5)
    print "daemon waking after sleep"
    print motion_set
    bearing = motion_bearing()<commit_msg>More debug<commit_after>import time
import datetime
import subprocess
from collections import OrderedDict
from catnet.turning import stop, turn_clockwise, turn_c_clockwise
from catnet.compass import get_bearing
import RPi.GPIO as GPIO
import RPIO
import threading


GPIO_sensors = OrderedDict([
    (23, 0),
    (24, 117),
    (25, 180),
    (18, 278),
])

#Create a variable called daemon running, and a global set
angle_offset = None
daemon_running = False
motion_set = set()

#Function for reading motion_set and working out the correct angle to turn
def motion_bearing():
    motion_bearing = []
    for sensor, angle in GPIO_sensors.items():
        if sensor in motion_set:
            motion_bearing.append(angle)
    print("detected motion at", motion_bearing)
    bearing = sum(motion_bearing)/len(motion_bearing)
    if bearing > 360:
        bearing = bearing - 360
    return bearing

#Function for activating turret
def turret(target_bearing):
    print("turning to", target_bearing);
    while True:
        current_bearing = get_bearing() - angle_offset
        if current_bearing < 0:
            current_bearing = current_bearing + 360
        print current_bearing
        if current_bearing - target_bearing > 10:
            turn_c_clockwise()
        elif current_bearing - target_bearing < -10:
            turn_clockwise()
        else:
            stop()
            break
        time.sleep(0.02)

#take picture function
def take_snap():
    time.sleep(1)
    file_name = (datetime.datetime.now()).strftime('%Y-%m-%d-%H-%M-%S')
    subprocess.call('fswebcam --device v4l2:/dev/video0 --input 0 --resolution 320x240 --skip 100 --jpeg 80 /home/jenny/test/image-{}.jpg'.format(file_name), shell=True)
    print "picture taken"

#Daemon thread
def activate_turret():
    global daemon_running
    time.sleep(0.5)
    print "daemon waking after sleep"
    print motion_set
    bearing = motion_bearing()
{'fraction_non_alphanumeric': 0.09281914893617021, 'fraction_numerical': 0.028191489361702127, 'mean_word_length': 3.065945945945946, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2533836', 'n_tokens_mistral': 1243, 'n_tokens_neox': 1098, 'n_words': 331}