def __init__(self): PWM.cleanup() self.servo = PWM.Servo() self.servo.set_servo(17, 1500) self.servo_lr_angle = 0 self.servo.set_servo(22, 1500) self.servo_ud_angle = 0
def main(): servo = Servo() time.sleep(5) servo.servo_control_up_down(45) servo.servo_control_left_right(-45) time.sleep(3) servo.servo_reset() time.sleep(3) PWM.cleanup()
def cleanup(self): self._print("Cleaning up...") for pin in self.pins: self.servo.set_servo(pin, self.pwm_min) self.servo.stop_servo(pin) PWM.cleanup() self._print("Cleaned.")
def stop(pwm): # stops cells individually stop_cell(pwm['A']) stop_cell(pwm['B']) stop_cell(pwm['C']) stop_cell(pwm['D']) # Shutdown all PWM and DMA activity PWM.cleanup()
def __exit__(self, eType, eValue, eTrace): """ Clean up routine for context manager (with-statement). Takes care of closing DMA channel - failure to do this breaks OS and a reboot will be needed.""" log.info("Destroying " + str(self)) self.set([0, 0, 0]) sleep(PWM_PRD / 1e6) # wait a period to ensure set() has been actioned PWM.clear_channel(PWM_DMA) PWM.clear_channel(PWM_DMA1) PWM.cleanup() return False
def main(): servo = PWM.Servo() time.sleep(0.2) init(servo) move(servo, 0) move(servo, 180) move(servo, 0) PWM.cleanup()
def cleardownGPIO(self): self.power(0) self.setBottomLED(0) self.setTopLED(0) PWM.clear_channel_gpio(relayChannel, relay) PWM.clear_channel_gpio(ledChannel, topLed) PWM.clear_channel_gpio(ledChannel, bottomLed) # Shutdown all PWM and DMA activity PWM.cleanup()
def pwm_example2(): from RPIO import PWM # Setup PWM and DMA channel 0 PWM.setup() PWM.init_channel(0) # Add some pulses to the subcycle PWM.add_channel_pulse(0, 17, 0, 50) PWM.add_channel_pulse(0, 17, 100, 50) # Stop PWM for specific GPIO on channel 0 PWM.clear_channel_gpio(0, 17) # Shutdown all PWM and DMA activity PWM.cleanup()
def __init__(self): PWM.cleanup() PWM.setup(1) PWM.init_channel(1, 5000) PWM.init_channel(2, 5000) PWM.init_channel(3, 5000) self.r = 0 self.g = 0 self.b = 0 self.dimFactor = 1. self.fadeTimer = None self.fadeCallback = None self.fadeStartTime = datetime.now() self.fadeSeconds = None
def kickServo(): #hmm RPIO seems to f**k up occasionally and start sending crappy #commands to the servo. I'm not sure what causes it except it #may be related to USB camera use? not verified. in any case #it sucks; the servo just jitters and once the problem occurs #it appears to persist until the script is shut down cleanly #(DMA shutdown) and reloaded. Maybe this bullshit will fix it. #Nope... it didn't. global servo print "restarting servo..." PWM.cleanup() servo = PWM.Servo() print "restarted." yield print "restarting servo again..." PWM.cleanup() servo = PWM.Servo() print "restarted."
def main(): # Set up Frequency in Hertz FREQUENCY = 1000 SUBCYCLE_US = ((1 / FREQUENCY) * 1000000) CHANNEL = 0 # Set duty_cycle 0 -> 100 DUTY_CYCLE = 50 # Set Pin PINO = PIN.CEL_A_1 # Setup PWM and DMA channel 0 PWM.setup() PWM.init_channel(channel=CHANNEL, subcycle_time_us=SUBCYCLE_US) # Test initialization if not (PWM.is_channel_initialized(CHANNEL)): print("ERROR: Channel could not be initialized!") return -1 # Test Frequency if not (PWM.get_channel_subcycle_time_us(CHANNEL) == SUBCYCLE_US): print("ERROR: Frequency could not be setted!") return -1 # Add pwm Pulse PWM.add_channel_pulse(dma_channel=CHANNEL, gpio=PINO, start=0, width=((SUBCYCLE_US / 10) * (DUTY_CYCLE / 100))) # fake while print("Press any key to stop") input() # Stop PWM for specific GPIO on channel 0 PWM.clear_channel_gpio(0, PINO) # Shutdown all PWM and DMA activity PWM.cleanup() return 0
def eStop(self): PWM.cleanup(); RPIO.output(self.APHASE_Pin,RPIO.LOW); RPIO.output(self.BPHASE_Pin,RPIO.LOW);
def __del__(self): PWM.cleanup()
def cleanup(self): #self.ser.close() PWM.clear_channel_gpio(1, 17) PWM.clear_channel_gpio(2, 27) PWM.clear_channel_gpio(3, 22) PWM.cleanup()
def clean_up(): # Clean up and exit script set_led(0,0,0) GPIO.cleanup() PWM.cleanup() time.sleep(0.5) sys.exit()
def destroy(): webiopi.debug("Script with macros - Destroy") # Shutdown all PWM and DMA activity PWM.cleanup()
def shutdown(self): PWM.cleanup()
servo = PWM.Servo() servo.set_servo(pPan, servo_center) servo.set_servo(pTilt, servo_center) time.sleep(2) servo.set_servo(pPan, servo_min) time.sleep(2) servo.set_servo(pPan, servo_max) time.sleep(2) servo.set_servo(pPan, servo_center) servo.set_servo(pTilt, servo_min) time.sleep(2) servo.set_servo(pTilt, servo_max) time.sleep(2) servo.set_servo(pTilt, servo_center) time.sleep(2) servo.stop_servo(pPan) servo.stop_servo(pTilt) PWM.cleanup()
def Close(self): PWM.clear_channel(0) PWM.cleanup()
def cleanup(): PWM.cleanup()
def end(): PWM.cleanup()
def deInit(self): self.servo.stop_servo(self.gpioPin) PWM.cleanup()
while tecla != ord('q'): tecla = stdscr.getch() if tecla == curses.KEY_UP: eixox=1 acelerar(1,eixox) elif tecla == curses.KEY_DOWN: eixox=0 acelerar(1,eixox) elif tecla == curses.KEY_LEFT: dire=1 rota(8,dire) elif tecla == curses.KEY_RIGHT: dire=0 rota(8,dire) elif tecla == ord('a'): camesquerda() elif tecla == ord('d'): camdireita() elif tecla == ord('s): camcentro() #---FINALIZAÇÃO PWM.clear_channel_gpio(0, ServoCam) #Limpa Canal 0 do Servo da Câmera PWM.cleanup() # Limpa Pinos de PWM stdscr.keypad(0) #Desabilita Teclado Numérico curses.nocbreak() #Desabilita Curses curses.echo() #Habilita Verbose Terminal curses.endwin() #Desliga Biblioteca Curses GPIO.cleanup() #Limpa Pinos GPIO
def handle(clientsocket): print('Made connection\n') # Look for if any exceptions are thrown try: flying = 1 while(flying): # Wait for first command from client buf = clientsocket.recv(MAX_LENGTH) navigating = 0 movDirection = 2 search = 0 serInput = '' sensor1 = 0 sensor2 = 0 sensor3 = 0 sensor4 = 0 # If command is takeoff then initialize and takeoff if(buf == 'takeoff'): autopilot.initialize() autopilot.arm() autopilot.takeOff() navigating = 1 # If client is lost then leave method if buf == '': return # Handle navigation and object avoidance while(navigating == 1): #print("In navigation\n") # Check for serial input -- Not implemented yet if(ser.inWaiting()): serInput = ser.readline() #if 'f' in serInput: sensor1 = 1 #else: sensor1 = 0 #if 'r' in serInput: sensor2 = 1 #else: sensor2 = 0 #if 'b' in serInput: sensor3 = 1 #else: sensor3 = 0 #if 'l' in serInput: sensor4 = 1 #else: sensor4 = 0 #if 'k' in serInput: isKill = 1 #else: isKill = 0 print(serInput) #time.sleep(1) # Prints to see what values are received #sensor1 = GPIO.input(9) #print("Sensor1 = " + str(sensor1)) #sensor2 = GPIO.input(7) #print("Sensor2 = " + str(sensor2)) #sensor3 = GPIO.input(8) #print("Sensor3 = " + str(sensor3)) #sensor4 = GPIO.input(11) #print("Sensor4 = " + str(sensor4)) # Wait for next input from client -- causes program # to hang until it receives something. Needs changed! #buf = clientsocket.recv(MAX_LENGTH) #if buf == '': return #isKill = GPIO.input(15) print(isKill) # Initial move right if(sensor3 == 1 and sensor1 == 0 and sensor4 == 0 and sensor2 == 0 and movDirection == 2): #print("Initial move right") autopilot.strafeR() autopilot.forward() movDirection = 2 print('Moving right') if(sensor3 == 0 and sensor1 == 0 and sensor4 == 0 and sensor2 == 0 and movDirection == 2): autopilot.strafeR() autopilot.backward() movDirection = 2 print('Moving right-ADJ') # End initial move right # Found right wall, start moving forward if(sensor1 == 0 and sensor2 == 1 and (sensor3 == 0 or sensor3 == 1) and sensor4 == 0 and movDirection == 2): #print("Found right wall, start moving forward") autopilot.stop() time.sleep(1) autopilot.forward() movDirection = 1 print('Start Moving forward') # Following right wall if(sensor1 == 0 and sensor2 == 1 and sensor3 == 0 and sensor4 == 0 and movDirection == 1): #print("Following right wall") #autopilot.stop() autopilot.forward() autopilot.strafeL() #movDirection = 1 print('Moving forward') if(sensor1 == 0 and sensor2 == 0 and sensor3 == 0 and sensor4 == 0 and movDirection == 1): #autopilot.stop() autopilot.forward() autopilot.strafeR() #movDirection = 1 print('Moving forward-ADJ') # End following right wall # Hit a right back corner if(sensor1 == 1 and sensor4 == 0 and sensor2 == 1 and sensor3 == 0 and movDirection == 1): #print("Hit a right back corner") autopilot.stop() #time.sleep(.3) autopilot.strafeL() movDirection = 4 print('Start Moving left') # Moving left following front wall if(sensor1 == 1 and sensor4 == 0 and sensor2 == 0 and sensor3 == 0 and movDirection == 4): #print("Moving left following front wall") autopilot.stop() #time.sleep(.3) autopilot.strafeL() autopilot.backward() #movDirection = 4 print('Moving left') if(sensor1 == 0 and sensor4 == 0 and sensor2 == 0 and sensor3 == 0 and movDirection == 4): autopilot.stop() #time.sleep(.3) autopilot.strafeL() autopilot.forward() #movDirection = 4 print('Moving left-ADJ') # End following front wall # Lost front wall if(sensor1 == 0 and sensor2 == 0 and sensor3 == 0 and sensor4 == 0 and movDirection == 4): #print("Lost front wall") autopilot.stop() time.sleep(.3) audopilot.strafeL() time.sleep(.3) autopilot.stop() time.sleep(.5) autopilot.forward() time.sleep(.5) autopilot.stop() time.sleep(.5) movDirection = 2 while (sensor3 == 0): autopilot.strafeR() time.sleep(1) autopilot.stop() print('Wall vanished') ser.flush() # Found back left corner if(sensor1 == 1 and sensor2 == 0 and sensor3 == 0 and sensor4 == 1 and movDirection == 4): print("Found back left corner") autopilot.stop() time.sleep(1) autopilot.turnR() time.sleep(1.5) autopilot.stop() time.sleep(1) search = 1 navigating = 0 ser.flush() # No direction to fly if(sensor1 == 1 and sensor2 == 1 and sensor3 == 1 and sensor4 == 1): #print("No direction to fly") autopilot.land() time.sleep(5) flying = 0 print('Can\'t fly') # Emergency kill command if(buf == "kill"): autopilot.throttleCut() #time.sleep(10) #autopilot.landed() flying = 0 #print('Killing operation') if(isKill): #autopilot.throttleCut() autopilot.stop() autopilot.land() time.sleep(10) flying = 0 return #print('Killed manually') # Variable for if ball is seen seen = 0 # Start searching for ball -- Needs implemented #while(search == 1 and buf != 'stop'): # Capture image and look for ball # Close the socket if ctrl+c key combination is used except KeyboardInterrupt: clientsocket.close() # Close the socket in all other exceptions except: print('Error occured, closing socket') PWM.cleanup() clientsocket.close()
def clean_up(): # Clean up and exit script set_led(0, 0, 0) GPIO.cleanup() PWM.cleanup() time.sleep(0.5) sys.exit()
def end(self): """Cleanup after usage.""" PWM.cleanup()
def cleanup(self): if self.__backlight: PWM.clear_channel_gpio(0, self.__backlight) PWM.cleanup() GPIO.cleanup()
def stop(self): RPIO.del_interrupt_callback(self.pPanicBtn) PWM.clear_channel(0) PWM.cleanup()
try: while True: # LED per vedere se tutto funziona for t in led_time: for i in gpio_port: RPIO.output(i, RPIO.HIGH) sleep(t) RPIO.output(i, RPIO.LOW) sleep(t) for d in canale_dma: subcycle_T = PWM.get_channel_subcycle_time_us(d) incr_T = PWM.get_pulse_incr_us() print("CANALE ", d, "subcycle_T =", subcycle_T, "--- incr_T =", incr_T) sleep(2) # if PWM.is_setup(): #è stato fatto il setup d'inizializzazione # granularity=granularity*10 #se sì: incremento la granularity # PWM.setup(granularity,0) #rifaccio il setup except KeyboardInterrupt: pass for i in canale_dma: PWM.clear_channel(i) PWM.clear_channel_gpio(i,gpio_port(i)) PWM.cleanup() print "STOP!" print "Ciao!"
def cleanup_all_motors(cls): PWM.cleanup()