Esempio n. 1
0
def disable():
    global ENABLED, RUNNING
    if not ENABLED: return
    PWM.stop(LEFT_SERVO_TX)
    PWM.stop(RIGHT_SERVO_TX)
    ENABLED = False
    RUNNING = False
Esempio n. 2
0
    def rotate(self, angle):
	PWM.start(channel,dutyCycle, PWM_freq)
	steps = 0
	num_steps = angle / 1.846
	time.sleep(stepTime*num_steps)
	PWM.stop(channel)
	return
Esempio n. 3
0
def listener():
    rospy.init_node('listener', anonymous=True)
    rospy.Subscriber("turn_rate", Float32, callback)
    rospy.spin()
    print ("test")
    PWM.stop(pwm_pin)
    PWM.cleanup()
Esempio n. 4
0
def ignite(debuglevel):
	threshold=340 #150mv threshold
	threshigh=1024 #450mv upper threshold
	ADC.setup()
	ADC.read_raw("AIN4") #Flush this
	baseline=ADC.read_raw("AIN4")
	GPIO.setup("P8_14",GPIO.OUT) #This pin fires the ignition
	GPIO.output("P8_14",GPIO.LOW)
	PWM.start("P8_19",15,49500) #works best with an 11 turn primary
	time.sleep(0.05) #50ms Settling time for the analogue front end
	ADC.read_raw("AIN4")
	selftest=ADC.read_raw("AIN4")
	if selftest>threshold and selftest<threshigh and baseline<128:
		GPIO.output("P8_14",GPIO.HIGH)
		if debuglevel:
			print "Igniting"
		time.sleep(2) #plenty of time for ignition
		failure=0		
	else:
		if debuglevel:
			print "Failed"
		failure=1
	GPIO.output("P8_14",GPIO.LOW)
	PWM.stop("P8_19")
	PWM.cleanup()
	#Debug output
	if debuglevel:
		print baseline
		print selftest
	return {'failure':failure, 'baseline':baseline ,'selftest':selftest }
def exit_gracefully(signum, frame):
    global pan_servo_pin
    global tilt_servo_pin

    pwm.stop(pan_servo_pin)
    pwm.stop(tilt_servo_pin)
    pwm.cleanup()
Esempio n. 6
0
def avoid_():

	

def readfile_coordinates():
	global line
	f = open('temp.txt', 'r')
	temp = f.readlines(line)
	f.close()
	latitude = temp.split("")[0]
	longitude = temp.split("")[1]


while True:
	try:
		while True:
			readfile_coordinates(line)
			scheduler()
			arbiter()
			
	except KeyboardInterrupt: # pressing ctrl C stops operation and cleans up

		PWM.stop(left_wheel)	
		PWM.stop(right_wheel)
		PWM.cleanup()
		GPIO.cleanup()
		ADC.cleanup()
    def cleanup(cls):
        PWM.stop(PWMA)
        PWM.stop(PWMB)
        PWM.cleanup()

        GPIO.cleanup()

        GPIO.output(STBY, GPIO.LOW)
Esempio n. 8
0
def testp:
	while 1:
		PWM.start("P8_19",15,49500)
		time.sleep(2)
		PWM.stop("P8_19")
		time.sleep(0.15)
		PWM.cleanup()
		time.sleep(0.1)
Esempio n. 9
0
 def triggerStepper(self):
     time.sleep(0.5)
     PWM.start("P9_16", 25, 100, 1)
     time.sleep(2)
     PWM.set_frequency("P9_16", 250)
     time.sleep(90)
     PWM.stop("P9_16")
     PWM.cleanup()
Esempio n. 10
0
def close_all():
    """
    Clean up all motor outputs
    """
    GPIO.output(STBY, GPIO.LOW)
    for motor in motor_ins:
        for pin in motor:
            GPIO.output(pin, GPIO.LOW)
    for pwm_pin in motor_pwms:
        PWM.stop(pwm_pin)
Esempio n. 11
0
def callback(data):
    rospy.loginfo(rospy.get_caller_id() + "I heard %s", data)
    angle = data.angular.z
    if angle == 42:
        PWM.stop(servo_pin)
        PWM.cleanup()
        return
    angle_f = float(angle)
    duty = ((-angle_f/2 + 0.5) * duty_span + duty_min)
    PWM.set_duty_cycle(servo_pin, duty)
def motodrv(dist,speed = 100):
    #Code to drive the Dc motor using PWM for speed control
    #Postion control is done by driving the motor for desired time only
    #Min speed at pwm = 20
    #Max at 100
    #setting default speed at 45
    #Frequency set at 40kHz
    
    PWM.start("P8_13",speed,40000)
    time.sleep(dist*2.0)
    PWM.stop("P8_13")
Esempio n. 13
0
    def buzzer(self):
	print 'starting buzz..'
	PWM.start(self.buzz,90,8000,0)
	#GPIO.output(self.buzz,GPIO.HIGH)
	time.sleep(5)
	PWM.stop(self.buzz)
	PWM.start(self.buzz,90,4000,0)
	time.sleep(5)	
	PWM.stop(self.buzz)
	#GPIO.output(self.buzz,GPIO.LOW)
	return
    def buzzer(self):		# Method for activating buzzer ; Generates PWM on buzz pin
	print 'starting buzz..'
	PWM.start(self.buzz,90,8000,0)
	#GPIO.output(self.buzz,GPIO.HIGH)
	time.sleep(5)
	PWM.stop(self.buzz)
	PWM.start(self.buzz,90,4000,0)
	time.sleep(5)	
	PWM.stop(self.buzz)
	#GPIO.output(self.buzz,GPIO.LOW)
	return
Esempio n. 15
0
 def handleClose(self):
     self.do_beep(0.25)
     for PIN in self.PROXIMITY_GPIO:
         GPIO.remove_event_detect(PIN)
     GPIO.remove_event_detect(self.STOP_BUTTON)
     GPIO.remove_event_detect(self.ECHO_RETURN)
     self.SCAN = False
     sleep(1)
     PWM.stop(self.SERVO_PWM)
     PWM.stop(self.SPEAKER_PWM)
     self.saber.stop()
     print self.address, 'closed'
Esempio n. 16
0
 def __speaker(self):
     if self.SPEAKER:
         return
     self.SPEAKER = True
     PWM.start(self.SPEAKER_PWM, 50, 3000)
     for dir in [-1,2]:
         for x in range(3,20):
             PWM.set_frequency(self.SPEAKER_PWM, 3000 + (dir * x * 100))
             sleep(0.05)
     PWM.stop(self.SPEAKER_PWM)
     self.SPEAKER = False
     return
def servo(whichDevice, where):
    # This function activates the servo motor

    # Import important libraries
    import Adafruit_BBIO.PWM as PWM
    import time
    import os
    from animals import animal
    from random import randint
    
    os.system('clear')

    # Time at which the servo starts to work
    cur_time = time.time()    

    # Set pin    
    if whichDevice == 1:
        servo_pin = "P8_13"
    elif whichDevice == 2:
        servo_pin = "P9_14"
    
#    print whichDevice
#    print servo_pin    
    
    # Set duty cycle parameters
    duty_min = 3
    duty_max = 14.5
    duty_span = duty_max - duty_min
    
    # Set duty cycle and frequency to pin
    PWM.start(servo_pin, (100-duty_min), 200.0)
    
    # Give direction/angle and a random animal to display
    if where == 'open':
        angle = 90
        print('\n\nOpening device!\n\n')
        animal_out = randint(1, 6)
        animal(animal_out)
    else:
        angle = 0
        print('\n\nClosing device...\n\n')
        animal_out = randint(1, 6)
        animal(animal_out)

    # Activate servo for 3 seconds    
    while True:
        angle_f = float(angle)
        duty = 100 - ((angle_f / 180) * duty_span + duty_min)
        PWM.set_duty_cycle(servo_pin, duty)
        if time.time() > (cur_time + 3.1):
            PWM.stop(servo_pin)
            PWM.cleanup()
            break
 def soft_stop(self):
     """ Method to soft stop (coast to stop) an individual motor"""
     
     # Make both control pins low
     GPIO.output(self.ControlPin1, GPIO.LOW)
     GPIO.output(self.ControlPin2, GPIO.LOW)
     PWM.stop(self.PWMpin)
     GPIO.output(self.STBYpin, GPIO.LOW)
     
     # set the status attributes
     self.isRunning = False
     self.currentDirection = None
     self.currentSpeed = 0.0
Esempio n. 19
0
def listener():


    rospy.init_node('listener', anonymous=False)
    
    PWM.start(servo_pin,93, 60.0,1)

    rospy.Subscriber('angle', Float32, callback)

    # spin() simply keeps python from exiting until this node is stopped
    rospy.spin()
    PWM.stop(servo_pin)
    PWM.cleanup()
Esempio n. 20
0
def simple_ignite(debuglevel):
	GPIO.setup("P8_14",GPIO.OUT) #This pin fires the ignition
	GPIO.output("P8_14",GPIO.LOW)
	PWM.start("P8_19",15,49500) #works best with an 11 turn primary
	GPIO.output("P8_14",GPIO.HIGH)
	if debuglevel:
		print "Igniting"
	time.sleep(2) #plenty of time for ignition
	GPIO.output("P8_14",GPIO.LOW)
	PWM.stop("P8_19")
	PWM.cleanup()
	failure=0
	return {'failure':failure}
def srvdrv(angl):
    #Code to drive the servo motor using PWM 
    #Min angle at pwm = 8
    #Max angle at pwm = 12
    #Frequency set at 60Hz

    angl += (3.1415/3)
    angl *= 4.0
    angl /= (2*(3.1415/3))
    angl += 8.0
    
    PWM.start("P8_19",angl,60)
    time.sleep(0.2)
    PWM.stop("P8_19")
Esempio n. 22
0
    def __init__(self, blower_pin):
        """
        Initializes the controller for a blower and sets the blower speed to 0

        :param blower_pin: The BBB PWM to use, e.g. P9_14
        :type blower_pin: str
        """
        self._blower_pin = blower_pin
        self._speed = 0
        self._low_speed_handle = None

        PWM.start(blower_pin, 0)
        PWM.stop(blower_pin)
        PWM.cleanup()
Esempio n. 23
0
    def dim_current_and_move_next(self):
        duty_cycle = 0.0
        PWM.start(self.current_pwm(), duty_cycle, 1000, 1)

        while duty_cycle <= 100.0:
            self.key_pressed = self.screen.getch()
            if self.key_pressed == ord(QUIT_CHARACTER):
                PWM.stop(self.current_pwm())
                return

            PWM.set_duty_cycle(self.current_pwm(), duty_cycle)
            curses.napms(DIM_DELAY_MS)
            duty_cycle += DUTY_CYCLE_INCREMENT

        PWM.stop(self.current_pwm())
        self.move_next()
Esempio n. 24
0
def exit_gracefully(signum, frame):
    global pan_servo_pin
    global tilt_servo_pin
    global original_sigterm
    global original_sigabrt
    global original_sigint

    signal.signal(signal.SIGTERM, original_sigterm)
    signal.signal(signal.SIGABRT, original_sigabrt)
    signal.signal(signal.SIGINT, original_sigint)

    pwm.stop(pan_servo_pin)
    pwm.stop(tilt_servo_pin)
    pwm.cleanup()

    signal.signal(signal.SIGTERM, exit_gracefully)
    signal.signal(signal.SIGABRT, exit_gracefully)
    signal.signal(signal.SIGINT, exit_gracefully)    
Esempio n. 25
0
def init_motors():
    """
    Initialize the pins needed for the motor driver.
    """
    global motor_ins
    global motor_pwms
    # initialize GPIO pins
    GPIO.setup(STBY, GPIO.OUT)
    GPIO.output(STBY, GPIO.HIGH)
    for motor in motor_ins:
        for pin in motor:
            GPIO.setup(pin, GPIO.OUT)
            GPIO.output(pin, GPIO.LOW)
                                                                             # initialize PWM pins
    # first need bogus start due to unknown bug in library
    PWM.start("P9_14", 0.0)
    PWM.stop("P9_14")
    # now start the desired PWMs
    for pwm_pin in motor_pwms:
        PWM.start(pwm_pin, 0.0)
Esempio n. 26
0
def cleanUp():
    PWM.start(PIN_RED, 100)
    PWM.start(PIN_GREEN, 100)
    PWM.start(PIN_BLUE, 100)
    
    PWM.stop(PIN_RED)
    PWM.stop(PIN_BLUE)
    PWM.stop(PIN_GREEN)
def pwmcontrol ():
	global input_percentage
	global changed
	global kill
	changed = False
	PWM.cleanup()
	start_freq = 300.0
	start_duty = 0.0

	period = 1.0 / start_freq
	minimum = 100.0 * (.001 / period)
	maximum = 100.0 * (.002 / period)

	print "Frequency:" + str(start_freq)
	print "Period:" + str(period)
	print "Minimum:" + str(minimum)
	print "Maximum:" + str(maximum)

	PWM.start("P9_14",start_duty,start_freq)
	PWM.start("P8_13",start_duty,start_freq)
	PWM.start("P9_21",start_duty,start_freq)
	PWM.start("P9_42",start_duty,start_freq)

	print "Start"

	while input_percentage >= 0:
		if changed == True:
			changed = False
			duty_cycle = ((0.01*input_percentage) * (maximum - minimum)) + minimum
			print "Duty Cycle: " + str(duty_cycle)
			PWM.set_duty_cycle("P8_13",duty_cycle)
			PWM.set_duty_cycle("P9_14",duty_cycle)
			PWM.set_duty_cycle("P9_21",duty_cycle)
			PWM.set_duty_cycle("P9_42",duty_cycle)
		else:
			time.sleep(0.1)
	PWM.stop("P9_14")
	PWM.stop("P8_13")
	PWM.stop("P9_21")
	PWM.stop("P9_42")
	PWM.cleanup()
	quit()
	return
Esempio n. 28
0
	def stop(self):

		#left Side
		#writes to motor 1
		GPIO.output("P9_11", 0)
		GPIO.output("P9_12", 0)
		#writes to motor 2
		GPIO.output("P9_13", 0)
		GPIO.output("P9_15", 0)
		#right side
		#writes to motor 3
		GPIO.output("P8_14", 0)
		GPIO.output("P8_16", 0)
		#writes to motor 4
		GPIO.output("P8_10", 0)
		GPIO.output("P8_18", 0)

		#pwm for motor 1 and 2
		PWM.stop("P9_14")
		PWM.stop("P9_16")
		#pwm for motor 3 and 4
		PWM.stop("P8_13")
		PWM.stop("P8_19")
Esempio n. 29
0
    def RestartProgram(self):
    	# Routine called when the angle is out of range and we need to restart the program
	PC.stopAndReset()
	PWM.stop(Pconst.PWM_RF)
	PWM.stop(Pconst.PWM_RR)
	PWM.stop(Pconst.PWM_LF)
	PWM.stop(Pconst.PWM_LR)
	PWM.cleanup()
	GPIO.output(Pconst.GreenLED, GPIO.LOW)
	GPIO.output(Pconst.RedLED, GPIO.LOW)
	GPIO.output(Pconst.BlueLED, GPIO.HIGH)

	print "\nProBot angle's out of range!!!"
	print "\nPut ProBot at 90 degrees!!!"
	
	while self.filteredX<-0.2 or self.filteredX>0.2:
		ProBot.MPU6050Readings()

	publisher2=Pub_Sub.publisher2(userChoice, userChoice1)
	GPIO.output(Pconst.BlueLED, GPIO.LOW)	
	print "\nRestarting the Program..."
      
   	python = sys.executable
    	os.execl(python, python, * sys.argv)
Esempio n. 30
0
import Adafruit_BBIO.PWM as PWM

servo_pin = "P9_14"
duty_min = 3
duty_max = 14.5
duty_span = duty_max - duty_min

PWM.start(servo_pin, (100 - duty_min), 60.0)

while True:
    angle = raw_input("Angle (0 to 180 x to exit):")
    if angle == 'x':
        PWM.stop(servo_pin)
        PWM.cleanup()
        break
    angle_f = float(angle)
    duty = 100 - ((angle_f / 180) * duty_span + duty_min)
    PWM.set_duty_cycle(servo_pin, duty)
Esempio n. 31
0
import Adafruit_BBIO.PWM as PWM

motor1 = "p8_13"
duty_stop = 9
duty_forward = 12
duty_back = 6
PWM.start(motor1, duty_stop, 60)

print "Ready"

key = '0'
while key != 'q':
    key = raw_input(">")
    print key
    if key == '1':
        PWM.set_duty_cycle(motor1, duty_forward)
    elif key == '2':
        PWM.set_duty_cycle(motor1, duty_back)
    elif key == '3':
        PWM.set_duty_cycle(motor1, duty_stop)
    elif key == '4':
        PWM.stop(motor1)

PWM.cleanup()
 def close_servo(self):
     PWM.stop(self.servo_pin)
     PWM.cleanup()
Esempio n. 33
0
	
	#Calculates Return to Center Position Simulation Time with a 10% Duty Cycle
	simTime2 = simTime*dutyCycle/10

	#Gets sleep command from BBB to allow pauses
	from time import sleep

	#Based off the direction the user chose, set which of the 4 motors needs to be reversed and start the simulation
	#After simulation runs, waits 5 seconds, then returns to the original position at a slow speed (10% duty cycle)
	if direction == 1:
		GPIO.output(dir1, GPIO.HIGH)
		GPIO.output(dir3, GPIO.HIGH)
		PWM.start(myPWM, dutyCycle, 1000)
		PWM.start(myPWM2, dutyCycle, 1000)
		sleep(simTime)
		PWM.stop(myPWM)
		PWM.stop(myPWM2)
		GPIO.output(dir1, GPIO.LOW)
		GPIO.output(dir3, GPIO.LOW)
		sleep(5)
		GPIO.output(dir2, GPIO.HIGH)
		GPIO.output(dir4, GPIO.HIGH)
		PWM.start(myPWM, 10, 1000)
		PWM.start(myPWM2, 10, 1000)
		sleep(simTime2)
		PWM.stop(myPWM)
		PWM.stop(myPWM2)
		GPIO.output(dir2, GPIO.LOW)
		GPIO.output(dir4, GPIO.LOW)
	elif direction == 2:
		GPIO.output(dir2, GPIO.HIGH)
Esempio n. 34
0
def servo_off():
    PWM.stop(SERVO_OUTPUT)
Esempio n. 35
0
 def stop_motor(self, motor="M1"):
     print "motor", motor, " stopped"
     PWM.stop(getattr(self, motor + "_EN"))
     self.motor_enabled[motor] = False
Esempio n. 36
0
	print raw1, raw2, raw3, raw4
	time.sleep(1)
     

print
print "Setting up PWM 4kHz on P9_16...buzzer test"
pwm_pin = 'P8_19'
PWM.start(pwm_pin, 25, 4000)

PWM.set_duty_cycle(pwm_pin, 50)
time.sleep(2)

PWM.set_duty_cycle(pwm_pin, 0)

print "Tearing down...",
PWM.stop(pwm_pin)

PWM.cleanup()
print "Done...buzzer test"

pwm_pin = 'P9_16'

print "Setting up PWM..."
print "Fan...100% duty cycle"
PWM.start(pwm_pin, 100, 20000)

time.sleep(6)

print "Fan...75% duty cycle"
PWM.set_duty_cycle(pwm_pin, 75)
time.sleep(6)
Esempio n. 37
0
def play_note(pin, vout):
    """ Play's note based on pin and vout inputs"""
    
    PWM.stop(piezo_pin)
    if (pin == "AIN0" and vout < 0.80):
        note = NOTE_A7
        PWM.start(piezo_pin, 50, note)
        time.sleep(3)
        PWM.stop(piezo_pin)
    elif (pin == "AIN1" and vout < 0.80):
        note = NOTE_B6
        PWM.start(piezo_pin, 50, note)
        time.sleep(3)
        PWM.stop(piezo_pin)
    elif (pin == "AIN2" and vout < 0.80):
        note = NOTE_C6
        PWM.start(piezo_pin, 50, note)
        time.sleep(3)
        PWM.stop(piezo_pin)
    elif (pin == "AIN3" and vout < 0.83 ):
        note = NOTE_D6
        PWM.start(piezo_pin, 50, note)
        time.sleep(3)
        PWM.stop(piezo_pin)
    elif (pin == "AIN4" and vout < 0.80):
        note = NOTE_E6 
        PWM.start(piezo_pin, 50, note)
        time.sleep(3)
        PWM.stop(piezo_pin)
    elif (pin == "AIN5" and vout < 0.40):
        note = NOTE_F7 
        PWM.start(piezo_pin, 50, note)
        time.sleep(3)
        PWM.stop(piezo_pin)
    elif (pin == "AIN6" and vout < 0.38):
        note = NOTE_G6
        PWM.start(piezo_pin, 50, note)
        time.sleep(3)
        PWM.stop(piezo_pin)
    elif (pin == "AIN7" and vout < 0.23):
        note = NOTE_A7
        PWM.start(piezo_pin, 50, note)
        time.sleep(3)
        PWM.stop(piezo_pin)
Esempio n. 38
0
                      (distance, temp, R, count * 1, cycle))
                tdata.write("%.2f,%.2f,%.2f,%.1f,%d\n" %
                            (distance, temp, R, count * 1, cycle))
                time.sleep(0.1)
            PWM.set_duty_cycle(Act, 0)
            while distance > ct:
                GPIO.output(Fan, GPIO.LOW)
                distance = -myEncoder.position * 0.02
                temp = max(sensor.readPixels())
                Vr = ADC.read(analogPin)
                R = 99.00 * Vr / (1.8 - Vr)
                count = count + 1
                print("%.2f,%.2f,%.2f,%.1f,%d" %
                      (distance, temp, R, count * 1, cycle))
                tdata.write("%.2f,%.2f,%.2f,%.1f,%d\n" %
                            (distance, temp, R, count * 1, cycle))
                time.sleep(0.1)
            GPIO.output(Fan, GPIO.HIGH)
            PWM.set_duty_cycle(Act, 0)
    elif a == 5:
        myEncoder.zero()
    elif a == 6:
        pwm = int(input('PWM value(1~100) : '))
    elif a == 7:
        print(pwm)

PWM.stop("P8_13")
PWM.cleanup()
GPIO.cleanup()
tdata.close()
Esempio n. 39
0
def stop_all():
    stop()
    PWM.stop(claw)
    PWM.stop(arm)
    PWM.cleanup()
    return None
Esempio n. 40
0
 def cleanup(self):
     '''Execute steps to clean up the PWM hardware'''
     PWM.stop(self.pin)
     PWM.cleanup()
     self.initialized = False
Esempio n. 41
0

# Utility funtion to convert a number in one range to another range
def map(x, min, max, newmin, newmax):
    x = x - min
    max = max - min
    x = x / max
    newspan = newmax - newmin
    x = x * newspan
    x = x + newmin
    return x


# for loop = laziness
for i in range(0, 10000):
    # reads in y axis accelerations and merges into one number
    b = i2c.readS8(0x3D)
    s = i2c.readU8(0x3E)
    rawaccel = b * 256 + s
    # converts raw reading into g's according to mode (+- 2 g's)
    g = rawaccel / 16384.
    # maps g's to the duty cycle range
    duty = map(g, -2, 2, duty_min, duty_max)
    # calls PWM & moves the servo
    PWM.set_duty_cycle(servoAddr, duty)

# cleanup time
PWM.stop(servoAddr)
PWM.cleanup()
i2c.write8(0x6B, 0x40)
Esempio n. 42
0
# A01 and A02 have to be opposite to move, toggle to change direction
# Up
# GPIO.output(A01, GPIO.HIGH)
# GPIO.output(A02, GPIO.LOW)
# GPIO.output(B01, GPIO.LOW)
# GPIO.output(B02, GPIO.HIGH)

# Down
GPIO.output(A01, GPIO.LOW)
GPIO.output(A02, GPIO.HIGH)
GPIO.output(B01, GPIO.HIGH)
GPIO.output(B02, GPIO.LOW)

# Start the motors
# PWM.start(channel, duty, freq=2000, polarity=0)
PWM.start(PWMA, 100)
PWM.start(PWMB, 100)

# optionally, change the PWM frequency and polarity from their defaults
# PWM.start("P9_14", 50, 1000, 1)

# Run the motor for 10s
time.sleep(0.5)

# Stop the motor and cleanup the PWM
PWM.stop(PWMA)
PWM.stop(PWMB)
PWM.cleanup()

# Make standby pin low to go back into standby mode
GPIO.output(STBY, GPIO.LOW)
Esempio n. 43
0
    def cleanup(self):
        """Stop pwm services."""
        print('stop PWM duty cycle 0 Prportional Valve ', self.name)

        PWM.stop(self.pwm_pin)
        PWM.cleanup()