Example #1
0
def main():
    setup()
    if len(sys.argv) >= 2:
        if sys.argv[1] == "servo-install":
            if len(sys.argv) >= 3:
                print ("servo-install takes no value")
                usage()
            print("Servo now is set to 90 degree.")
            servo0 = Servo.Servo(0, bus_number=1)
            servo1 = Servo.Servo(1, bus_number=1)
            servo2 = Servo.Servo(2, bus_number=1)
            servo0.write(90)
            servo1.write(90)
            servo2.write(90)
        elif sys.argv[1] == "front-wheel-test":
            if len(sys.argv) >= 3:
                try:
                    chn = int(sys.argv[2])
                except:
                    print ("chn must be integer")
                    usage()
                if 0 <= chn <= 15 :
                    front_wheels.test(chn)
                else:
                    print ('chn must be in 0~15, not "%s"' % chn)
                    usage()
            front_wheels.test()
        elif sys.argv[1] == "rear-wheel-test":
            back_wheels.test()
        else:
            print ('Command error, "%s" is not in list' % sys.argv[1])
            usage()
    else:
        usage()
Example #2
0
def servo_install():
    import time
    delay = 1.0 / 180
    if len(sys.argv) >= 3:
        print "servo-install takes no value"
        usage()
    print("Servo now is set to 90 degree.")
    servo0 = Servo.Servo(0, bus_number=1)
    servo1 = Servo.Servo(1, bus_number=1)
    servo2 = Servo.Servo(2, bus_number=1)
    for i in range(90, -1, -1):
        servo0.write(i)
        servo1.write(i)
        servo2.write(i)
        time.sleep(delay)
    time.sleep(0.1)
    for i in range(0, 181, 1):
        servo0.write(i)
        servo1.write(i)
        servo2.write(i)
        time.sleep(delay)
    time.sleep(0.1)
    for i in range(180, 89, -1):
        servo0.write(i)
        servo1.write(i)
        servo2.write(i)
        time.sleep(delay)
    time.sleep(0.1)
    servo0.write(90)
    servo1.write(90)
    servo2.write(90)
    while True:
        time.sleep(1)
Example #3
0
def main():
    setup()
    if len(sys.argv) >= 2:
        if sys.argv[1] == "servo-install":
            if len(sys.argv) >= 3:
                print "servo-install takes no value"
                usage()
            Servo.install()
        elif sys.argv[1] == "front-wheel-test":
            if len(sys.argv) >= 3:
                try:
                    chn = int(sys.argv[2])
                except:
                    print "chn must be integer"
                    usage()
                if 0 <= chn <= 15:
                    front_wheels.test(chn)
                else:
                    print 'chn must be in 0~15, not "%s"' % chn
                    usage()
            front_wheels.test()
        elif sys.argv[1] == "rear-wheel-test":
            back_wheels.test()
        else:
            print 'Command error, "%s" is not in list' % sys.argv[1]
            usage()
    else:
        usage()
Example #4
0
 def __init__(self, s1=0, s2=1, s3=2):
     for i in range(0, 4):
         myservo.append(Servo.Servo(i))  # channel 1
         Servo.Servo(i).setup()
         print('myservo%s' % i)
     self.s1 = s1  # 底盘
     self.s2 = s2  # 中间
     self.s3 = s3  # 夹持器
Example #5
0
    def setupServos(self, steeringPin, motorPin):
        steering = Servo.Servo(steeringPin)
        motor = Servo.Servo(motorPin)

        Servo.Servo(steeringPin).setup()
        Servo.Servo(motorPin).setup()

        steering.write(self.defaultSteeringAngle)
        motor.write(self.defaultMotorAngle)
        return steering, motor
    def setupServos(self, steeringPin, motorPin):
        steering = Servo.Servo(steeringPin)
        motor = Servo.Servo(motorPin)

        Servo.Servo(steeringPin).setup()
        Servo.Servo(motorPin).setup()

        # writes (or sets) the default speed and angles to the servos
        steering.write(self.defaultSteeringAngle)
        motor.write(self.defaultMotorAngle)

        return steering, motor
Example #7
0
    def __init__(self,
                 debug=False,
                 db="config",
                 bus_number=1,
                 channel=FRONT_WHEEL_CHANNEL):
        ''' setup channels and basic stuff '''
        self.db = filedb.fileDB(db=db)
        self._channel = channel
        self._straight_angle = 90
        self.turning_max = 45
        self._turning_offset = int(
            self.db.get('turning_offset', default_value=0))

        self.wheel = Servo.Servo(self._channel,
                                 bus_number=bus_number,
                                 offset=self.turning_offset)
        self.debug = debug
        if self._DEBUG:
            print(self._DEBUG_INFO, 'Front wheel PWM channel:', self._channel)
            print(self._DEBUG_INFO, 'Front wheel offset value:',
                  self.turning_offset)

        self._angle = {
            "left": self._min_angle,
            "straight": self._straight_angle,
            "right": self._max_angle
        }
        if self._DEBUG:
            print(
                self._DEBUG_INFO,
                'left angle: %s, straight angle: %s, right angle: %s' %
                (self._angle["left"], self._angle["straight"],
                 self._angle["right"]))
Example #8
0
def init():
    global steer
    steer = Servo.Servo(0)
    global pan
    pan = Servo.Servo(1)
    global tilt
    tilt = Servo.Servo(2)
    Servo.Servo(0).setup()
    Servo.Servo(1).setup()
    Servo.Servo(2).setup()
    setPan(90)
Example #9
0
#curses.cbreak()
key.keypad(1)
key.nodelay(1)

# Set default positions
s = [90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90]
sservo = 0
r = [90, 70, 70, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90]
l = [90, 90, 90, 90, 90, 110, 110, 90, 90, 90, 90, 90, 90, 90, 90, 90]
w = [90, 90, 90, 90, 90, 90, 90, 90, 70, 120, 120, 20, 90, 90, 90, 90]
f = [90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90]

# Set up servos
myservo = []
for i in range(0, 16):
    myservo.append(Servo.Servo(i))  # channel 1
    Servo.Servo(i).setup()

while True:
    char = key.getch()
    if char == ord('q'):
        break
    elif char == ord('1'):
        sservo = 1
    elif char == ord('2'):
        sservo = 2
    elif char == ord('3'):
        sservo = 3
    elif char == ord('4'):
        sservo = 4
    elif char == ord('5'):
Example #10
0
import time
from SunFounder_TB6612 import TB6612
import RPi.GPIO as GPIO
import time
from SunFounder_PCA9685 import Servo
print "********************************************"
print "*                                          *"
print "*           SunFounder TB6612              *"
print "*                                          *"
print "*          Connect MA to BCM17             *"
print "*          Connect MB to BCM18             *"
print "*         Connect PWMA to BCM27            *"
print "*         Connect PWMB to BCM22            *"
print "*                                          *"
print "********************************************"
a = Servo.Servo(4)
b = Servo.Servo(5)
Servo.Servo(4).setup()
Servo.Servo(5).setup()
#GPIO.setmode(GPIO.BCM)
#GPIO.setup((27, 22), GPIO.OUT)
#a = GPIO.PWM(27, 60)
#b = GPIO.PWM(22, 60)
#a.start(0)
#b.start(0))

def a_speed(value):
	a.write(value)

def b_speed(value):
	b.write(value)
Example #11
0
def main():
	import time
	motorapwm = Servo.Servo(4)
	Servo.Servo(4).setup()

	print "********************************************"
	print "*                                          *"
	print "*           SunFounder TB6612              *"
	print "*                                          *"
	print "*          Connect MA to BCM17             *"
	print "*          Connect MB to BCM18             *"
	print "*         Connect PWMA to BCM27            *"
	print "*         Connect PWMB to BCM22            *"
	print "*                                          *"
	print "********************************************"
	GPIO.setmode(GPIO.BCM)
	GPIO.setup((27, 22), GPIO.OUT)
	a = GPIO.PWM(27, 60)
	b = GPIO.PWM(22, 60)
	a.start(0)
	b.start(0)

	def a_speed(value):
		a.ChangeDutyCycle(value)

	def b_speed(value):
		b.ChangeDutyCycle(value)

	motorA = TB6612.Motor(17)
	motorB = TB6612.Motor(18)
	motorA.debug = True
	motorB.debug = True
	motorA.pwm = a_speed
	motorB.pwm = b_speed

	delay = 0.05

	motorA.forward()
	for i in range(0, 101):
		motorapwm.write(i)
		motorA.speed = i
		time.sleep(delay)
	for i in range(100, -1, -1):
		motorapwm.write(i)
		motorA.speed = i
		time.sleep(delay)

	motorA.backward()
	for i in range(0, 101):
		motorapwm.write(i)
		motorA.speed = i
		time.sleep(delay)
	for i in range(100, -1, -1):
		motorapwm.write(i)
		motorA.speed = i
		time.sleep(delay)

	motorB.forward()
	for i in range(0, 101):
		motorB.speed = i
		time.sleep(delay)
	for i in range(100, -1, -1):
		motorB.speed = i
		time.sleep(delay)

	motorB.backward()
	for i in range(0, 101):
		motorB.speed = i
		time.sleep(delay)
	for i in range(100, -1, -1):
		motorB.speed = i
		time.sleep(delay)
Example #12
0
import time
from SunFounder_PCA9685 import Servo

motorA = Servo.Servo(4)
motorB = Servo.Servo(5)

Servo.Servo(4).setup()
Servo.Servo(5).setup()

motorA.write(0)
motorB.write(0)