def setup(): global pwm bus = SMBus(1) # Raspberry Pi revision 2 pwm[0] = PWM(bus, i2c_address) pwm[0].setFreq(fPWM) pwm[1] = PWM(bus, i2c_address + 1) pwm[1].setFreq(fPWM)
def __init__(self, bus_number=None, address=0x40, frequency = 60, drive = 0, steer = 1, drive_n = 369, steer_c = 390): ''' This is very important part of set ESC. If you want to drive motor by this source, you have to use pca9685 drive. Because the ESC circuit is connected with PCA9685 PWM circuit board's channel pins Argument bus_number : bus type of raspberry Pi. If it doesn't set, pca9685 module set value as default. address : I2C slave address frequency : driving motor(forward/backward motor) PWM frequency. driver : pca9685 channel number of driving motor steer : pca9685 channel number of steering motor ''' self.pwm = PWM(bus_number, address) self.pwm.frequency = frequency self.pwm.setup() self.drive = drive self.steer = steer #self.steer_NEUTRAL = 390 #default value. It needs to calibrate self.steer_NEUTRAL = steer_c self.steer_MIN = 280 self.steer_MAX = 500 #self.drive_NEUTRAL = 369 #default value. It needs to calibrate self.drive_NEUTRAL = drive_n self.drive_MIN = 280 self.drive_MAX = 450 self.steer_val = self.steer_NEUTRAL self.drive_val = self.drive_NEUTRAL self.speed_forward = self.steer_NEUTRAL self.speed_backward = self.steer_NEUTRAL self.steer_diff = 35 self.drive_diff = 5 self.is_stop = True
def __init__(self): self.state = 2 self.fPWM = 50 self.i2c_address = 0x40 # (standard) adapt to your module self.channel = 0 # adapt to your wiring self.a = 8.5 # adapt to your servo self.b = 2 # adapt to your servo self.bus = SMBus(3) # Raspberry Pi revision 2 self.pwm = PWM(self.bus, self.i2c_address) self.pwm.setFreq(self.fPWM) self.setup() self.zeroBot() self.frLeg = Leg3d(side=1) self.flLeg = Leg3d(side=2) self.lrLeg = Leg3d(side=2) self.rrLeg = Leg3d(side=1) self.t = 0 # walker = Walk3d(stride_height=-0.01,stride_length =.02) bpm = 138#music tempo self.freq = bpm/60.*2*pi self.amp = 0.015
def __init__(self): self.pwm = PWM(0x40) self.pwm.set_pwm_freq(60) self.backwardMax = 350 self.forwardMax = 300 self.neutralbackandforth = 333 self.rightMax = 397 self.leftMax = 466 self.neutralleftandright = 436 #used to control eye lights via servo controllers. Workaround for lack of physical resources. Instead, probably implement like the error light in controller.py self.leftrightservo = 0 self.forwardbackwardservo = 1 self.leftEyeLed = 13 self.rightEyeLed = 14
def __init__(self, drive, steer, bus_number=None, address=0x40, frequency = 60, drive_ch = 0, steer_ch = 1): ''' This is very important part of set ESC. If you want to drive motor by this source, you have to use pca9685 drive. Because the ESC circuit is connected with PCA9685 PWM circuit board's channel pins Argument bus_number : bus type of raspberry Pi. If it doesn't set, pca9685 module set value as default. address : I2C slave address frequency : driving motor(forward/backward motor) PWM frequency. driver : pca9685 channel number of driving motor steer : pca9685 channel number of steering motor ''' #mode - 0 : forward, 1 : backward, 2 : Neutral, 3 : None self.set_mode = 3 self.steer_value_loaded = False self.drive_value_loaded = False self.current_mode = ["Forward", "Backward", "Neutral", "None"] #Set Channel self.drive_ch = drive_ch self.steer_ch = steer_ch #Default values for steer #self.steer_NEUTRAL = 390 self.steer_center = steer self.steer_MIN = 280 self.steer_MAX = 500 self.steer_val = 0 self.steer_diff = 15 #Default values for drive(engine) #self.drive_NEUTRAL = 369 self.drive_neutral = drive self.drive_MIN = 280 self.drive_MAX = 450 #self.drive_val = self.drive_neutral self.speed_forward = 0 self.speed_backward = 0 self.drive_diff = 5 # PWM init self.pwm = PWM(bus_number, address) self.pwm.frequency = frequency self.pwm.setup() time.sleep(0.1) self.pwm.write(self.drive_ch,0,0) self.pwm.write(self.steer_ch,0,0)
import time import smbus from PCA9685 import PWM bus = smbus.SMBus(1) channel = 0 frequency = 50 address = 0x40 pwm = PWM(bus, address) pwm.setFreq(frequency) pwm.setDuty(channel, 2) time.sleep(3) while 1: for i in range(2, 13, 1): pwm.setDuty(channel, i) time.sleep(0.3) for i in range(12, 1, -1): pwm.setDuty(channel, i) time.sleep(0.3)
flirZoom = 2 GPIO.setmode(GPIO.BCM) PWM_OEpin = 4 GPIO.setup(PWM_OEpin, GPIO.OUT) zoomInPin = 11 zoomOutPin = 9 GPIO.setup(zoomInPin, GPIO.OUT) GPIO.setup(zoomOutPin, GPIO.OUT) GPIO.output(zoomInPin, 0) GPIO.output(zoomOutPin, 0) pwm_frequency = 50 pwm_i2c_address = 0x40 pwm = PWM(SMBus(1), pwm_i2c_address) pwm.setFreq(pwm_frequency) print("Starting Lidar and Battery") measThread = threading.Thread(target=getMeasurements) measThread.daemon = True measThread.start() print("Starting Motor Control") motorThread = threading.Thread(target=controlMotors) motorThread.daemon = True #motorThread.start() def stopmotors():
def setup(): global pwm # Raspberry Pi revision 2 bus = SMBus(1) pwm = PWM(bus, i2c_address) pwm.setFreq(fPWM)
def setupSteereServo(): global pwm bus = SMBus(1) pwm = PWM(bus, i2c_address) pwm.setFreq(fPWM)
#!usr/bin/env python # -*- coding:utf-8 -*- # _*_ coding:cp1254 _*_ #Ahmed Demirezen Feezx1 import socket import RPi.GPIO as gpio import time from PCA9685 import PWM from smbus import SMBus #gpio ayarları gpio.setmode(gpio.BCM) #PCA9685 setup i2c_adres = 0x40 bus = SMBus(1) pwm_s = PWM(bus, i2c_adres) pwm_s.setFreq(50) #step gpio.setup(4, gpio.OUT) gpio.setup(17, gpio.OUT) gpio.setup(23, gpio.OUT) gpio.setup(24, gpio.OUT) #dc gpio.setup(26, gpio.OUT) gpio.setup(19, gpio.OUT) gpio.output(26, gpio.LOW) gpio.output(19, gpio.HIGH) pwm_s.setDuty(2, 0) #Server bilgileri(Çalıştırmadan önce bilgileri güncelleyin)
def __init__(self): global pwm bus = SMBus(1) # Raspberry Pi revision 2 pwm = PWM(bus, self.i2c_address) pwm.setFreq(self.fPWM)
def setup(self): self.pwm = PWM(self.bus, self.i2c_address) self.pwm.setFreq(self.fPWM)
def __init__(self, ipAddress="", buttonEvent=None): ''' Creates an instance of MyRobot and initalizes the GPIO. ''' if MyRobot._myInstance != None: raise Exception("Only one instance of MyRobot allowed") global _isButtonEnabled, _buttonListener _buttonListener = buttonEvent # Use physical pin numbers GPIO.setmode(GPIO.BOARD) GPIO.setwarnings(False) # Left motor GPIO.setup(SharedConstants.P_LEFT_FORWARD, GPIO.OUT) SharedConstants.LEFT_MOTOR_PWM[0] = GPIO.PWM( SharedConstants.P_LEFT_FORWARD, SharedConstants.MOTOR_PWM_FREQ) SharedConstants.LEFT_MOTOR_PWM[0].start(0) GPIO.setup(SharedConstants.P_LEFT_BACKWARD, GPIO.OUT) SharedConstants.LEFT_MOTOR_PWM[1] = GPIO.PWM( SharedConstants.P_LEFT_BACKWARD, SharedConstants.MOTOR_PWM_FREQ) SharedConstants.LEFT_MOTOR_PWM[1].start(0) # Right motor GPIO.setup(SharedConstants.P_RIGHT_FORWARD, GPIO.OUT) SharedConstants.RIGHT_MOTOR_PWM[0] = GPIO.PWM( SharedConstants.P_RIGHT_FORWARD, SharedConstants.MOTOR_PWM_FREQ) SharedConstants.RIGHT_MOTOR_PWM[0].start(0) GPIO.setup(SharedConstants.P_RIGHT_BACKWARD, GPIO.OUT) SharedConstants.RIGHT_MOTOR_PWM[1] = GPIO.PWM( SharedConstants.P_RIGHT_BACKWARD, SharedConstants.MOTOR_PWM_FREQ) SharedConstants.RIGHT_MOTOR_PWM[1].start(0) # IR sensors GPIO.setup(SharedConstants.P_FRONT_LEFT, GPIO.IN, GPIO.PUD_UP) GPIO.setup(SharedConstants.P_FRONT_CENTER, GPIO.IN, GPIO.PUD_UP) GPIO.setup(SharedConstants.P_FRONT_RIGHT, GPIO.IN, GPIO.PUD_UP) GPIO.setup(SharedConstants.P_LINE_LEFT, GPIO.IN, GPIO.PUD_UP) GPIO.setup(SharedConstants.P_LINE_RIGHT, GPIO.IN, GPIO.PUD_UP) # Establish event recognition from battery monitor GPIO.setup(SharedConstants.P_BATTERY_MONITOR, GPIO.IN, GPIO.PUD_UP) GPIO.add_event_detect(SharedConstants.P_BATTERY_MONITOR, GPIO.RISING, _onBatteryDown) Tools.debug("Trying to detect I2C bus") self._bus = smbus.SMBus(1) # For revision 2 Raspberry Pi Tools.debug("Found SMBus for revision 2") # I2C PWM chip PCM9685 for LEDs and servos self.pwm = PWM(self._bus, SharedConstants.PWM_I2C_ADDRESS) self.pwm.setFreq(SharedConstants.PWM_FREQ) self.isPCA9685Available = self.pwm._isAvailable if self.isPCA9685Available: # clear all LEDs for id in range(3): self.pwm.setDuty(3 * id, 0) self.pwm.setDuty(3 * id + 1, 0) self.pwm.setDuty(3 * id + 2, 0) # I2C analog extender chip Tools.debug("Trying to detect PCF8591P I2C expander") channel = 0 try: self._bus.write_byte(SharedConstants.ADC_I2C_ADDRESS, channel) self._bus.read_byte( SharedConstants.ADC_I2C_ADDRESS) # ignore reply data = self._bus.read_byte(SharedConstants.ADC_I2C_ADDRESS) Tools.debug("Found PCF8591P I2C expander") except: Tools.debug("PCF8591P I2C expander not found") self.displayType = "none" Tools.debug("Trying to detect OLED display") self.oled = OLED1306() if self.oled.isDeviceAvailable(): self.displayType = "oled" else: Tools.debug("'oled' display not found") self.oled = None Tools.debug("Trying to detect 7-segment display") try: addr = 0x20 rc = self._bus.read_byte_data(addr, 0) if rc != 0xA0: # returns 255 for 4tronix raise Exception() Tools.delay(100) self.displayType = "didel1" except: Tools.debug("'didel1' display not found") if self.displayType == "none": try: addr = 0x20 self._bus.write_byte_data( addr, 0x00, 0x00) # Set all of bank 0 to outputs Tools.delay(100) self.displayType = "4tronix" except: Tools.debug("'4tronix' display not found") if self.displayType == "none": try: addr = 0x24 # old dgTell from didel data = [0] * 4 self._bus.write_i2c_block_data( addr, data[0], data[1:]) # trying to clear display self.displayType = "didel" except: Tools.debug("'didel (old type)' display not found") Tools.debug("Display type '" + self.displayType + "'") # Initializing (clear) display, if available if self.displayType == "4tronix": Disp4tronix().clear() elif self.displayType == "didel": DgTell().clear() elif self.displayType == "didel1": DgTell1().clear() GPIO.setup(SharedConstants.P_BUTTON, GPIO.IN, GPIO.PUD_UP) # Establish event recognition from button event GPIO.add_event_detect(SharedConstants.P_BUTTON, GPIO.BOTH, _onButtonEvent) _isButtonEnabled = True Tools.debug("MyRobot instance created. Lib Version: " + SharedConstants.VERSION) self.sensorThread = None MyRobot._myInstance = self