def setWheelSpeed(self, index, speed): if index == 0: speed = -speed pwm_val = math.fabs(speed) * self.pwm_period pwm_val = int(pwm_val) if pwm_val > self.pwm_period: pwm_val = self.pwm_period if (speed < 0): gpio_val = logi_hal.getGPIOVal(GPIO_ADDR) gpio_val &= ~self.dir_mask[index] logi_hal.setGPIOVal(GPIO_ADDR, gpio_val) else: gpio_val = logi_hal.getGPIOVal(GPIO_ADDR) gpio_val |= (self.dir_mask[index]) logi_hal.setGPIOVal(GPIO_ADDR, gpio_val) logi_hal.setPWMPulse(PWM_ADDR, index, pwm_val)
def setWheelSpeed(self, index, speed): if index == 0: speed = -speed pwm_val = math.fabs(speed) * self.pwm_period pwm_val = int(pwm_val) if pwm_val > self.pwm_period: pwm_val = self.pwm_period if(speed < 0): gpio_val = logi_hal.getGPIOVal(GPIO_ADDR) gpio_val &= ~self.dir_mask[index] logi_hal.setGPIOVal(GPIO_ADDR, gpio_val) else: gpio_val = logi_hal.getGPIOVal(GPIO_ADDR) gpio_val |= (self.dir_mask[index]) logi_hal.setGPIOVal(GPIO_ADDR, gpio_val) logi_hal.setPWMPulse(PWM_ADDR, index, pwm_val)
import sys sys.path.append("/home/ubuntu/logi-tools/python/") import time,math import logi_hal gpio_0=0x0000 logi_hal.setGPIODir(gpio_0,0x2) logi_hal.setGPIOVal(gpio_0,0x2) #beaglebone下,运行sudo python gpio.py
def __init__(self): logi_hal.setGPIODir(GPIO_ADDR, 0x0007) logi_hal.setGPIOVal(GPIO_ADDR, 0x0006) logi_hal.setPWMDivider(PWM_ADDR, 0x003F) logi_hal.setPWMPeriod(PWM_ADDR, self.pwm_period)