<commit_before>#!/usr/bin/env python
import Adafruit_BBIO.PWM as PWM

class Servo:
    """Servo Controller defaults to pin8_13"""

    def __init__(self, pin = "P8_13", start_angle = 90):
        self.servo_pin = pin
        self.duty_max = 14.5
        self.duty_min = 3.
        self.duty_span = self.duty_max - self.duty_min
        self.upper_lim = 180.
        self.lower_lim = 0.
        self.running = False
        self.set_angle(start_angle)
        return

    def start(self):
        print "Starting the servo! Turn on the 5v line"
        PWM.start(servo_pin, duty_max / 2., 60.0)
        self.running = True
        return

    def stop(self):
        print "Stopping the servo! Turn off the 5v line"
        PWM.stop(servo_pin)
        PWM.cleanup()
        self.running = False
        return

    def clamp (self, angle):
        if angle < self.lower_lim: return self.lower_lim
        if angle > self.upper_lim: return self.upper_lim
        return angle

    def set_angle(self, angle):
        self.angle = float(self.clamp(angle))
        if self.running:
            duty = self.angle / 180. * self.duty_span + self.duty_min
            PWM.set_duty_cycle(servo_pin, duty)
        return

def main():
    print "main method"
    servo = Servo()
    while True:
        input = raw_input("Enter and angle from 0 to 180. 'x' to exit:")<commit_msg>Comments and this and that<commit_after>#!/usr/bin/env python
import Adafruit_BBIO.PWM as PWM

# Author: <NAME>
# MIT License

# This class controls a servo by converting angles between 0 and 180
# into the proper frequency for servo PWM. It can also have maximum
# and minimum angles that clamp input angles.

class Servo:
    """Servo Controller defaults to pin8_13"""

    # Starts the servo controller with a PWM pin and initial angle.
    # Todo: set a GPIO pin to control on/off
    def __init__(self, pin = "P8_13", start_angle = 90):
        self.servo_pin = pin
        self.duty_max = 14.5
        self.duty_min = 3.
        self.duty_span = self.duty_max - self.duty_min
        self.upper_lim = 180.
        self.lower_lim = 0.
        self.running = False
        self.angle = 0.
        self.set_angle(start_angle)
        return
    
    # Still need to implement powering on
    def start(self):
        # Step 1: turn on 5v power line (will need to know GPIO pin)
        print "Starting the servo! Turn on the 5v line"
        # Step 2: start PWM
        PWM.start(servo_pin, self.angle, 60.0)
        # Step 3: set running flag to true
        self.running = True
        return
    
    # Still need to implement powering off
    def stop(self):
        print "Stopping the servo! Turn off the 5v line"
        PWM.stop(servo_pin)
        PWM.cleanup()
        self.running = False
        return

    # Prevents the angle from going beyond the upper and lower angle limits
    def clamp (self, angle):
        if angle < self.lower_lim: return self.lower_lim
        if angle > self.upper_lim: return self.upper_lim
        return angle

    # Sets the angle of the servo (clamped).
    # If the servo is not currently on (self.running == True) then only the
    # self.angle variable is changed. Otherwise the PWM duty cycle is also
    # changed.
    def set_angle(self, angle, clamp = true):
        if clamp: self.angle = float(self.clamp(angle))
        else: self.angle = float(angle)
        if self.running:
            duty = self.angle / 180. * self.duty_span + self.duty_min
            PWM.set_duty_cycle(servo_pin, duty)
        return

def main():
    print "main method"
    servo = Servo()
    while True:
        input = raw_input("Enter and angle from 0 to 180. 'x' to exit:")
{'fraction_non_alphanumeric': 0.08661417322834646, 'fraction_numerical': 0.017920173771382025, 'mean_word_length': 2.1676698194325024, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '2848194', 'n_tokens_mistral': 1232, 'n_tokens_neox': 1126, 'n_words': 386}