Пример #1
0
def setup():
	#setup for DC motor pins
	GPIO.setFunction(Motor1A,GPIO.OUT)
	GPIO.setFunction(Motor1B,GPIO.OUT)
	GPIO.setFunction(Motor1E,GPIO.OUT)

	GPIO.setFunction(Motor2A,GPIO.OUT)
	GPIO.setFunction(Motor2B,GPIO.OUT)
	GPIO.setFunction(Motor2E,GPIO.OUT)
	 
	GPIO.setFunction(Motor3A,GPIO.OUT)
	GPIO.setFunction(Motor3B,GPIO.OUT)
	GPIO.setFunction(Motor3E,GPIO.OUT)

	GPIO.setFunction(Motor4A,GPIO.OUT)
	GPIO.setFunction(Motor4B,GPIO.OUT)
	GPIO.setFunction(Motor4E,GPIO.OUT)



	#setup for ESC control pin
	#BLDCGPIO.setmode(BLDCGPIO.BCM)
	pigpio = pigpio.pi()

	# ESC calibaration: set max speed then min speed
	pigpio.set_servo_pulsewidth(GPIO_ESC, 2000)
	sleep(2)
	pigpio.set_servo_pulsewidth(GPIO_ESC, 1000)
	sleep(2)
Пример #2
0
def setSteering(direction):
    pin = 17
    presets = ["left", "right", "center"]
    if isinstance(speed, str) and speed in presets:
        pwm = [1800, 1200, 1500]
        pigpio.set_servo_pulsewidth(pin, pwm[presets.index(speed)])
    elif isinstance(speed, int) and speed in range(1000, 2001):
        pwm = speed
        pigpio.set_servo_pulsewidth(pin, pwm)
    #Error Handler
    else:
        if reportErrors:
            print("direction is invalid or incorrect type %s" %
                  type(direction))
Пример #3
0
def t3():
   global t3_reset, t3_count, t3_on, t3_off

   pw=[500.0, 1500.0, 2500.0]
   dc=[0.2, 0.4, 0.6, 0.8]

   print("PWM/Servo pulse accuracy tests.")

   t3cb = pigpio.callback(GPIO, pigpio.EITHER_EDGE, t3cbf)

   t = 0
   for x in pw:
      t += 1
      pigpio.set_servo_pulsewidth(GPIO, x)
      time.sleep(1)
      t3_reset = True
      time.sleep(4)
      c = t3_count
      on = t3_on
      off = t3_off
      CHECK(3, t, int((1E3*(on+off))/on), int(2E7/x), 1, "set servo pulsewidth")


   pigpio.set_servo_pulsewidth(GPIO, 0)
   pigpio.set_PWM_frequency(GPIO, 1000)
   f = pigpio.get_PWM_frequency(GPIO)
   CHECK(3, 4, f, 1000, 0, "set/get PWM frequency")

   rr = pigpio.set_PWM_range(GPIO, 100)
   CHECK(3, 5, rr, 200, 0, "set PWM range")

   t = 5
   for x in dc:
      t += 1
      pigpio.set_PWM_dutycycle(GPIO, x*100)
      time.sleep(1)
      t3_reset = True
      time.sleep(2)
      c = t3_count
      on = t3_on
      off = t3_off
      CHECK(3, t, int((1E3*on)/(on+off)), int(1E3*x), 1, "set PWM dutycycle")

   pigpio.set_PWM_dutycycle(GPIO, 0)
Пример #4
0
def two():	
	pigpio.set_servo_pulsewidth(GPIO_ESC, 1500)	
Пример #5
0
def one():
	pigpio.set_servo_pulsewidth(GPIO_ESC,1000)	#min speed
Пример #6
0
def stop_servo(pin):
    pigpio.set_servo_pulsewidth(pin, 0)
Пример #7
0
def move_servo(pin, duty_cycle_us=0, sleep=SLEEP):
    pigpio.set_servo_pulsewidth(pin, duty_cycle_us)
    time.sleep(sleep)
Пример #8
0
 def on_message(self, message):
     self.write_message(message)
     if message == '38':
         #up
         print 'up'
         pigpio.set_servo_pulsewidth(7,2500)
         pigpio.set_servo_pulsewidth(8,500)
     elif message == '40':
         #down
         print 'down'
         pigpio.set_servo_pulsewidth(7,500)
         pigpio.set_servo_pulsewidth(8,2500)
     elif message == '37':
         #right
         print 'right'
         pigpio.set_servo_pulsewidth(7,1400)
         pigpio.set_servo_pulsewidth(8,1400)
     elif message == '39':
         #right
         print 'left'
         pigpio.set_servo_pulsewidth(7,1800)
         pigpio.set_servo_pulsewidth(8,1800)
     elif message == '32':
         #space
         print 'stop'
         pigpio.set_servo_pulsewidth(7,0)
         pigpio.set_servo_pulsewidth(8,0)
     elif message == '65':
         print 'a'
         #print self.cam_value
         if (self.cam_value < 1800):
             pigpio.set_servo_pulsewidth(24,self.cam_value+100)
             self.cam_value+=100
         else:
             self.cam_value=1800
     elif message == '90':
         print 'z'
         #print self.cam_value
         if (self.cam_value > 1300):
             pigpio.set_servo_pulsewidth(24,self.cam_value+100)
             self.cam_value-=100
         else:
             self.cam_value=1300
Пример #9
0
servMid = 1400
servMin = 600

delayTime1 = 0.01
servStep = 20
servPin1 = 18 #GPIO 18

#Reset pigpio
pigpio.stop()
time.sleep(.5)
pigpio.start()

#Initialize PWM values
pigpio.set_PWM_frequency(servPin1, 50)  
pigpio.set_PWM_range(servPin1, servMax)
pigpio.set_servo_pulsewidth(servPin1, servMin) #pulsewidth sets position - start at minimum


### END SERVO SETUP


### MAIN LOOP ###
try:
    
    while True:
        print "Play sound"
        os.system('mpg321 "./sounds/Sci Fi Beep 02.mp3" &')
        
        setDir("fwd")
        pigpio.set_servo_pulsewidth(servPin1, servMin)
        time.sleep(2)
Пример #10
0
               1230)  #back motor speed initialised at 1230 ms pulse width
motors = []  #array of motors to be controlled
motors.append(motor1)
motors.append(motor2)

if pigpio.start(''):  # must run notification test on localhost
    print("Connected to pigpio daemon.")

    #initialisation
    pigpio.set_mode(pin1, pigpio.OUTPUT)
    pigpio.set_mode(pin2, pigpio.OUTPUT)
    pigpio.set_PWM_range(pin1, 255)
    pigpio.set_PWM_range(pin2, 255)
    pigpio.set_PWM_frequency(pin1, 50)
    pigpio.set_PWM_frequency(pin2, 50)
    pigpio.set_servo_pulsewidth(pin1, 0)
    pigpio.set_servo_pulsewidth(pin2, 0)

    #open the serial port rfcomm1 defined in rfcomm.conf file
    ser = serial.Serial('/dev/rfcomm1', 38400, timeout=.08)

    print("\nConnected\n")
    ser.write('Connected')  #send message to the smartphone
    raw = ser.readline()

    while (raw != 'stop'):  #message 'stop' terminates the program
        raw = ser.readline()
        if (raw != ''):  #ignore empty messages
            print(raw + '\n')
            if (raw == 's'):  #stop both motors
                pigpio.set_servo_pulsewidth(motor1.pin, 0)
Пример #11
0
motor2 = motor(pin2, 1230)  # back motor speed initialised at 1230 ms pulse width
motors = []  # array of motors to be controlled
motors.append(motor1)
motors.append(motor2)

if pigpio.start(""):  # must run notification test on localhost
    print("Connected to pigpio daemon.")

    # initialisation
    pigpio.set_mode(pin1, pigpio.OUTPUT)
    pigpio.set_mode(pin2, pigpio.OUTPUT)
    pigpio.set_PWM_range(pin1, 255)
    pigpio.set_PWM_range(pin2, 255)
    pigpio.set_PWM_frequency(pin1, 50)
    pigpio.set_PWM_frequency(pin2, 50)
    pigpio.set_servo_pulsewidth(pin1, 0)
    pigpio.set_servo_pulsewidth(pin2, 0)

    # open the serial port rfcomm1 defined in rfcomm.conf file
    ser = serial.Serial("/dev/rfcomm1", 38400, timeout=0.08)

    print("\nConnected\n")
    ser.write("Connected")  # send message to the smartphone
    raw = ser.readline()

    while raw != "stop":  # message 'stop' terminates the program
        raw = ser.readline()
        if raw != "":  # ignore empty messages
            print(raw + "\n")
            if raw == "s":  # stop both motors
                pigpio.set_servo_pulsewidth(motor1.pin, 0)
Пример #12
0
Файл: gong.py Проект: wr/gongpi
def stop_servo():
    move_servo(CENTER)
    pigpio.set_servo_pulsewidth(PIN, 0)
Пример #13
0
Файл: gong.py Проект: wr/gongpi
def move_servo(duty_cycle_us=0):
    pigpio.set_servo_pulsewidth(PIN, duty_cycle_us)
    time.sleep(SLEEP)
Пример #14
0
def three():
	pigpio.set_servo_pulsewidth(GPIO_ESC, 2000)	#max speed
Пример #15
0
 def set_duty_cycle(self, pulse_width_us):
     pigpio.set_servo_pulsewidth(self.pin, pulse_width_us)
     self.logger.info("Position = %s" % pulse_width_us)
Пример #16
0
def stopbldc():
	pigpio.set_servo_pulsewidth(GPIO_ESC, 0)	#stop the pulses
Пример #17
0
#!/usr/bin/python

import tornado.web
import tornado.websocket
import tornado.ioloop
import pigpio
from time import sleep
import os.path

pigpio.start(port='8889')
#
cam_value = 1400
#
pigpio.set_servo_pulsewidth(7,0)
pigpio.set_servo_pulsewidth(8,0)
pigpio.set_servo_pulsewidth(24,cam_value)

# This is our WebSocketHandler - it handles the messages
# from the tornado server
class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.render("index.html")

class WebSocketHandler(tornado.websocket.WebSocketHandler):
    cam_value = 1400
    # the client connected
    def open(self):
        print "New client connected"
        self.write_message("You are connected")

    # the client sent the message
Пример #18
0
#!/usr/bin/env python
 
import time
 
import pigpio
 
servos = [14,15,18,23] #GPIO number
 
pigpio.start()
#pulsewidth can only set between 500-2500
try:
    while True:
 
        pigpio.set_servo_pulsewidth(servos[1], 1000) #servo 1 to 0 degree
        print("Servo {} {} micro pulses".format(servos, 1000))
        time.sleep(1)
        pigpio.set_servo_pulsewidth(servos[3], 600) #servo 2 to 90 degree
        print("Servo {} {} micro pulses".format(servos, 600))
        time.sleep(3)
		pigpio.set_servo_pulsewidth(servos[1], 2400) #servo 1 to 0 degree
        print("Servo {} {} micro pulses".format(servos, 2400))
        time.sleep(1)
		pigpio.set_servo_pulsewidth(servos[2], 1000) #servo 1 to 0 degree
        print("Servo {} {} micro pulses".format(servos, 1000))
        time.sleep(1)
	    pigpio.set_servo_pulsewidth(servos[0], 2200)
        print("Servo {} {} micro pulses".format(servos, 2200))
        time.sleep(3)
        pigpio.set_servo_pulsewidth(servos[2], 2500)
        print("Servo {} {} micro pulses".format(servos, 2500))
        time.sleep(1)
Пример #19
0
#Author : Nikunj Parmar

import time
import pigpio

servos = 11 #gpio no

pigpio.start()

try:
    while True:
        pigpio.set_servo_pulsewidth(servos, 500)
        print("servo {} {} micro pulses".format(servos, 1000))
        time.sleep(1)
        pigpio.set_servo_pulsewidth(servos, 1500)
        print("servo {} {} micro pulses".format(servos, 1500))
        time.sleep(1)
        pigpio.set_servo_pulsewidth(servos, 2500)
        print("servo {} {} micro pulses".format(servos, 2500))
        time.sleep(1)
        pigpio.set_servo_pulsewidth(servos, 1500)
        print("servo {} {} micro pulses".format(servos, 1500))
        time.sleep(1)
except KeyboardInterrupt:
    pigpio.set_servo_pulsewidth(servos, 0)

pigpio.stop()