def set_velocity(self,pwmotor,motor_id): [pins,dma_ch] = self.motor_list[motor_id] c = [0,0] c[0] = PWM.get_channel_subcycle_time_us(dma_ch[0])/(100.0*PWM.get_pulse_incr_us()) #coefficient to convert duty to period c[1] = PWM.get_channel_subcycle_time_us(dma_ch[1])/(100.0*PWM.get_pulse_incr_us()) #coefficient to convert duty to period try: PWM.clear_channel_gpio(dma_ch[0], pins[0]) PWM.clear_channel_gpio(dma_ch[1], pins[1]) except: pass if pwmotor>0: PWM.add_channel_pulse(dma_ch[1],pins[1],0,0) PWM.add_channel_pulse(dma_ch[0],pins[0],0,int(abs(pwmotor)*c[0])) else: PWM.add_channel_pulse(dma_ch[0],pins[0],0,0) PWM.add_channel_pulse(dma_ch[1],pins[1],0,int(abs(pwmotor)*c[1]))
def set_speed(pin, chan, speed, speed_0): pulse_inc = PWM.get_pulse_incr_us() cycle_dur = PWM.get_channel_subcycle_time_us(chan) num_pulses = int(cycle_dur * speed / pulse_inc) if speed >= 0.99: num_pulses -= 1 PWM.add_channel_pulse(chan, pin, 0, num_pulses)
def set_velocity(self, pwmotor, motor_id): [pins, dma_ch] = self.motor_list[motor_id] c = [0, 0] c[0] = PWM.get_channel_subcycle_time_us( dma_ch[0]) / (100.0 * PWM.get_pulse_incr_us() ) #coefficient to convert duty to period c[1] = PWM.get_channel_subcycle_time_us( dma_ch[1]) / (100.0 * PWM.get_pulse_incr_us() ) #coefficient to convert duty to period try: PWM.clear_channel_gpio(dma_ch[0], pins[0]) PWM.clear_channel_gpio(dma_ch[1], pins[1]) except: pass if pwmotor > 0: PWM.add_channel_pulse(dma_ch[1], pins[1], 0, 0) PWM.add_channel_pulse(dma_ch[0], pins[0], 0, int(abs(pwmotor) * c[0])) else: PWM.add_channel_pulse(dma_ch[0], pins[0], 0, 0) PWM.add_channel_pulse(dma_ch[1], pins[1], 0, int(abs(pwmotor) * c[1]))
def setW(self, W): "Checks W% is between limits than sets it" import RPIO.PWM as PWM PW = 0 self.__W = W if self.__W < self.__WMin: self.__W = self.__WMin if self.__W > self.__WMax: self.__W = self.__WMax #on time[us]/granularity[us] PW = ((PWM.get_channel_subcycle_time_us(0) * self.__W)/100)/PWM.get_pulse_incr_us() # Set servo to xxx us if self.powered: self.__IO.set_servo(self.__pin, PW)
def setW(self, W): "Checks W% is between limits than sets it" import RPIO.PWM as PWM PW = 0 self.__W = W if self.__W < self.__WMin: self.__W = self.__WMin if self.__W > self.__WMax: self.__W = self.__WMax #on time[us]/granularity[us] PW = ((PWM.get_channel_subcycle_time_us(0) * self.__W) / 100) / PWM.get_pulse_incr_us() # Set servo to xxx us if self.powered: self.__IO.set_servo(self.__pin, PW)
print ("setup canale ", i, "chiamato") else: print ("setup canale ", i, " NON chiamato") 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!"
print ("setup canale ", k, "chiamato") else: print ("setup canale ", k, " NON chiamato") try: while True: # LED per vedere se tutto funziona for t in led_time: for p in gpio_port: RPIO.output(p, RPIO.HIGH) sleep(t) RPIO.output(p, 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: RPIO.setwarnings(False) for i in canale_dma: PWM.clear_channel(i) PWM.clear_channel_gpio(i,gpio_port(i)) PWM.cleanup() print "STOP!" print "Ciao!"