def send_pwm_continuesly(self): with navio.pwm.PWM(self.rc_channel) as pwm: pwm.enable() pwm.set_period(50) def _max_pwm(): pwm.set_duty_cycle(self.max_pwm) def send_max_pwm(): rospy.loginfo("Sending max pwm ({}) to {}. channel...".format( self.min_pwm, self.rc_channel)) try: _max_pwm() except: rospy.logerr("Error occured while sending max pwm...") rospy.loginfo("Sent") self.pub_stat.publish("open") def _min_pwm(): pwm.set_duty_cycle(self.min_pwm) def send_min_pwm(): rospy.loginfo("Sending max pwm ({}) to {}. channel...".format( self.min_pwm, self.rc_channel)) try: _min_pwm() except: rospy.logerr("Error occured while sending min pwm...") rospy.loginfo("Sent") self.pub_stat.publish("close") while (True): if self.next_state == self.state: if self.state == "open": rospy.loginfo("STILL open") send_min_pwm() elif self.state == "close": rospy.loginfo("STILL close") send_max_pwm() else: rospy.logerr( "States are the same but... unknown error happend..." ) else: if self.next_state == "open": rospy.loginfo("RECEIVED open") send_min_pwm() self.change_state("open") elif self.next_state == "close": rospy.loginfo("RECEIVED close") send_max_pwm() self.change_state("close") else: rospy.logerr("Ooo!") rospy.spin()
def main(): pwm = navio.pwm.PWM(PWM_OUTPUT) pwm.initialize() pwm.set_period(50) pwm.enable() loop_for(2, pwm.set_duty_cycle, SERVO_MAX) loop_for(2, pwm.set_duty_cycle, SERVO_MIN) loop_for(2, pwm.set_duty_cycle, SERVO_NOM) while (True): loop_for(1, pwm.set_duty_cycle, 1.3)
#Spower = Decimal((1300.000 + (a * 700.000 / 640.000))/1000.000) #Spower = round(Spower, 3) #print Spower pwm = navio.pwm.PWM(PWM_OUTPUT) pwm2 = navio.pwm.PWM(PWM_OUTPUT2) pwm3 = navio.pwm.PWM(PWM_OUTPUT3) pwm4 = navio.pwm.PWM(PWM_OUTPUT4) pwm.initialize() pwm2.initialize() pwm3.initialize() pwm4.initialize() pwm.set_period(50) pwm2.set_period(50) pwm3.set_period(50) pwm4.set_period(50) pwm.enable() pwm2.enable() pwm3.enable() pwm4.enable() t1 = threading.Thread(target=servo, args=[]) t1.start() stream = io.BytesIO() print "*****Command*****"
import navio.pwm import navio.util navio.util.check_apm() PWM_OUTPUT = 0 # These are just some good values to know when seting the motor power SERVO_MIN = 1.250 #ms SERVO_MAX = 1.750 #ms # Now every time we want to use a motor, we have to enable it first # Let's enable all 4 (they're numbered 0-3) pwmArray = [] for num in range(0,3+1): # This loops over 0,1,2,3 pwm = navio.pwm.PWM(num) pwm.set_period(50) pwmArray.append(pwm) cycles = 3; # How many cycles you want to spin the rotors for # Otherwise it'll keep spinning forever while (cycles > 0): cycles -= 1 # Now we alternate all motors between fast and slow for pwm in pwmArray: pwm.set_duty_cycle(SERVO_MIN) # They will keep spinning until we send a new signal time.sleep(1) for pwm in pwmArray: pwm.set_duty_cycle(SERVO_MAX) time.sleep(1)
import sys import time import navio.pwm import navio.util navio.util.check_apm() PWM_OUTPUT = 0 SERVO_MIN = 1.200 #ms SERVO_MAX = 1.800 #ms sequence = [1.500, 1, 1.600, 1] with navio.pwm.PWM(PWM_OUTPUT) as pwm: pwm.disable() pwm.set_period(20) time.sleep(3) pwm.enable() for v, i in enumerate(sequence): if v % 2 == 0: pwm.set_duty_cycle(i) print("set:{0}".format(i)) else: time.sleep(i) print("wait:{0}".format(i)) while True: pwm.set_duty_cycle(1.6) #print("Turning on") #time.sleep(5) #pwm.set_duty_cycle(1.700) # Give it a kick at first #print("Giving it a boost")
import navio.pwm import navio.adc import navio.util navio.util.check_apm() adc = navio.adc.ADC() results = [0] * adc.channel_count PWM_OUTPUT = 0 SERVO_MIN = 1.000 #ms SERVO_MAX = 1.500 #ms pwm = navio.pwm.PWM(PWM_OUTPUT) pwm.set_period(400) #pwm.set_duty_cycle(SERVO_MIN) #time.sleep(10) while (True): results[5] = adc.read(5) duty=0.001*int(1000+900*results[5]/5000) #ms pwm.set_duty_cycle(duty) print duty time.sleep(0.1) # pwm.set_duty_cycle(SERVO_MAX) # time.sleep(0.2)