Example #1
0
def loop_for(seconds, *args):
    endtime = datetime.datetime.now() + datetime.timedelta(seconds=seconds)

    while True:
        if datetime.datetime.now() >= endtime:
            break
        pwm.set_duty_cycle(*args)
        pwm2.set_duty_cycle(*args)
        pwm3.set_duty_cycle(*args)
        pwm4.set_duty_cycle(*args)
Example #2
0
 def callback(data):
     print("servo incoming data:{0}".format(data))
     scaled = data.data
     # clip the range
     if (scaled > PWM_MAX):
         scaled = PWM_MAX
     if (scaled < PWM_MIN):
         scaled = PWM_MIN
     # get the corresponding value
     scaled = (1.0 * scaled - 1.0 * PWM_MIN) / (
         1.0 * PWM_MAX - 1.0 * PWM_MIN) * (TIME_MAX - TIME_MIN) + TIME_MIN
     print("scaled output:{0}".format(scaled))
     pwm.set_duty_cycle(scaled)
Example #3
0
def motor_speed_loop():
    if Motor_currentSpeed == 0:
	Motor_curentSpeed = Motor_Neutral
    while (True):
	pwm.set_duty_cycle(Motor_currentSpeed)
Example #4
0
import sys
import time

import navio.pwm
import navio.util

navio.util.check_apm()

PWM_OUTPUT = 0
SERVO_MIN = 1.250  #ms
SERVO_MAX = 1.750  #ms

with navio.pwm.PWM(PWM_OUTPUT) as pwm:
    pwm.set_period(50)
    pwm.enable()

    while (True):
        pwm.set_duty_cycle(SERVO_MIN)
        time.sleep(1)
        pwm.set_duty_cycle(SERVO_MAX)
        time.sleep(1)
Example #5
0
def write(inc):
    signal = (inc / 90.0) + 1.5  # convertimos grados a seƱal pwm
    pwm.set_duty_cycle(signal)
Example #6
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)

# So even if you terminate the script, they will keep spinning
# We have to send a stop signal to every motor before we leave
for pwm in pwmArray:
    pwm.set_duty_cycle(0)
Example #7
0
import sys
import time

import navio.pwm
import navio.util

navio.util.check_apm()

PWM_OUTPUT = 0
SERVO_MIN = 1.250  #ms
SERVO_MAX = 1.750  #ms

with navio.pwm.PWM(PWM_OUTPUT) as pwm:
    pwm.set_period(50)
    pwm.enable()

    #    while (True):
    #        pwm.set_duty_cycle(SERVO_MIN)
    #        time.sleep(1)
    #        pwm.set_duty_cycle(SERVO_MAX)
    #        time.sleep(1)

    pwm.set_duty_cycle(1.600)
    print("Motor started")
    time.sleep(10)
    pwm.set_duty_cycle(1.500)
    pwm.disable()
Example #8
0
 def _min_pwm():
     pwm.set_duty_cycle(self.min_pwm)
def callback(pwm, val):
    pwm.set_duty_cycle(val)
Example #10
0
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")
    #time.sleep(5)
    #pwm.set_duty_cycle(1.5)
    #print("Print starting initialisation, set 1500")
    #time.sleep(15)
    #print("End of initialisation")
Example #11
0
def callback(data):
    pwm.set_duty_cycle()
Example #12
0
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)
Example #13
0
PWM_MIN = rospy.get_param("~val_min", 0.0)
TIME_MAX = rospy.get_param("~time_max", 2.00)  # in ms
TIME_MIN = rospy.get_param("~time_min", 1.00)
PRIME_REQUIRED = rospy.get_param("~prime", False)
topic = rospy.get_param("~topic", "thrust")
print(rospy.get_param("~topic"))
rospy.sleep(2 * PWM_OUTPUT)  # to resolve priming errors
with navio.pwm.PWM(PWM_OUTPUT) as pwm:
    pwm.set_period(50)
    pwm.enable()
    if (PRIME_REQUIRED):
        # perform a priming sequence, by setting to zero, 0.5, 0 for some time.

        rate = rospy.Rate(50)
        for i in range(100):
            pwm.set_duty_cycle((TIME_MAX + TIME_MIN) / 2)
            rate.sleep()

        for i in range(100):
            pwm.set_duty_cycle((TIME_MAX * 1.5 + TIME_MIN * 0.5) / 2)
            rate.sleep()

        for i in range(100):
            pwm.set_duty_cycle((TIME_MAX + TIME_MIN) / 2)
            rate.sleep()
        #priming done!

    def callback(data):
        print("servo incoming data:{0}".format(data))
        scaled = data.data
        # clip the range
Example #14
0
def stop(
):  #This will stop every action your Pi is performing for ESC ofcourse.
    pwm.set_duty_cycle(0)
    pwm2.set_duty_cycle(0)
    pwm3.set_duty_cycle(0)
    pwm4.set_duty_cycle(0)
Example #15
0
import sys
import time

import navio.pwm
import navio.util

navio.util.check_apm()

PWM_OUTPUT = 1
SERVO_MIN = 1.250 #ms
SERVO_MAX = 1.750 #ms

with navio.pwm.PWM(PWM_OUTPUT) as pwm:
    pwm.set_period(50)
    pwm.enable()

#    while (True):
#        pwm.set_duty_cycle(SERVO_MIN)
#        time.sleep(1)
#        pwm.set_duty_cycle(SERVO_MAX)
#        time.sleep(1)

    pwm.set_duty_cycle(SERVO_MIN)
    time.sleep(5)
    pwm.set_duty_cycle(1.5)
    pwm.disable()

Example #16
0
def speed(x):
    pwm.set_duty_cycle(x)
    pwm2.set_duty_cycle(x)
    pwm3.set_duty_cycle(x)
    pwm4.set_duty_cycle(x)
Example #17
0
 def _max_pwm():
     pwm.set_duty_cycle(self.max_pwm)