Ejemplo n.º 1
0
def camera_y(angle):
    global Current_y
    Current_y = angle + home_y  # Add offset
    clamp(Current_y, Ymin, Ymax)
    pwm.setPWM(15, 0, Current_y)
    text = "%s" % (Current_y)
    return text
Ejemplo n.º 2
0
def camera_x(angle):
    global Current_x
    Current_x = angle + home_x  # Add offset
    clamp(Current_x, Xmin, Xmax)
    pwm.setPWM(14, 0, Current_x)
    text = "%s" % (Current_x)
    return text
Ejemplo n.º 3
0
def turn(angle):
    angle_original = angle
    angle *= -1  #Reverse value
    angle = clamp(angle, -100, 100)
    angle = angle + turn_offset + 450  #Add offset and middle number
    pwm.setPWM(0, 0, angle)
    text = "%s -> %s" % (angle_original, angle)
    return text
Ejemplo n.º 4
0
def setup():
    global pwm, turn_offset, Xmin, Ymin, Xmax, Ymax, home_x, home_y
    global forward0, forward1
    forward0 = 1
    forward1 = 1
    GPIO.setwarnings(False)
    GPIO.setmode(GPIO.BOARD)  # Number GPIOs by its physical location

    # Fix the config motor direction reader, please:
    try:
        for line in open(FILE_CONFIG):
            if line[0:8] == "forward0" and line[11:-1] == 'True':
                forward0 = 1
            else:
                forward0 = 0
            if line[0:8] == "forward1" and line[11:-1] == 'True':
                forward1 = 1
            else:
                forward1 = 0
            print "forward0 = %s, forward1 = %s" % (forward0, forward1)

    except:
        print "Excepted config motor direction reader"
        pass
    try:
        for line in open(FILE_CONFIG):
            if line[0:8] == 'offset =':
                turn_offset = int(line[9:-1])
    except:
        print "Excepted config turning offset reader"

    try:
        for line in open(FILE_CONFIG):
            if line[0:8] == 'offset_x':
                offset_x = int(line[11:-1])
                #print 'offset_x =', offset_x
            if line[0:8] == 'offset_y':
                offset_y = int(line[11:-1])
                #print 'offset_y =', offset_y
    except:
        print "Excepted config camera offset reader"
        pass

    Xmin = MinPulse + offset_x
    Xmax = MaxPulse + offset_x
    Ymin = MinPulse + offset_y
    Ymax = MaxPulse + offset_y
    home_x = (Xmax + Xmin) / 2
    home_y = Ymin + 80
    pwm = servo.init()  # Initialize the servo controller.
Ejemplo n.º 5
0
def setup():
	global leftPWM, rightPWM, homePWM, pwm
	leftPWM = 375
	homePWM = 450
	rightPWM = 575
	offset =-10
	try:
		for line in open('config'):
			if line[0:8] == 'offset =':
				offset = int(line[9:-1])
	except:
		print 'config error'
	leftPWM += offset
	homePWM += offset
	rightPWM += offset
	pwm = servo.init()         # Initialize the servo controller.
Ejemplo n.º 6
0
def setup():
	global leftPWM, rightPWM, homePWM, pwm
	leftPWM = 400
	homePWM = 450
	rightPWM = 500
	offset =0
	try:
		for line in open(CONFIG_PATH):
			if line[0:8] == 'offset =':
				offset = int(line[9:-1])
	except:
		print('config error')
	leftPWM += offset
	homePWM += offset
	rightPWM += offset
	pwm = servo.init()         # Initialize the servo controller.
Ejemplo n.º 7
0
def setup():
    global leftPWM, rightPWM, homePWM, pwm
    leftPWM = 375
    homePWM = 450
    rightPWM = 575
    offset = -10
    try:
        for line in open('config'):
            if line[0:8] == 'offset =':
                offset = int(line[9:-1])
    except:
        print 'config error'
    leftPWM += offset
    homePWM += offset
    rightPWM += offset
    pwm = servo.init()  # Initialize the servo controller.
Ejemplo n.º 8
0
def setup():
    global Xmin, Ymin, Xmax, Ymax, home_x, home_y, pwm
    offset_x = 0
    offset_y = 0
    try:
        for line in open(FILE_CONFIG):
            if line[0:8] == 'offset_x':
                offset_x = int(line[11:-1])
                #print 'offset_x =', offset_x
            if line[0:8] == 'offset_y':
                offset_y = int(line[11:-1])
                #print 'offset_y =', offset_y
    except:
        pass
    Xmin = MinPulse + offset_x
    Xmax = MaxPulse + offset_x
    Ymin = MinPulse + offset_y
    Ymax = MaxPulse + offset_y
    home_x = (Xmax + Xmin) / 2
    home_y = Ymin + 80
    pwm = servo.init()  # Initialize the servo controller.
def setup():
	global Xmin, Ymin, Xmax, Ymax, home_x, home_y, pwm
	offset_x = 0
	offset_y = 0
	try:
		for line in open(FILE_CONFIG):
			if line[0:8] == 'offset_x':
				offset_x = int(line[11:-1])
				#print 'offset_x =', offset_x
			if line[0:8] == 'offset_y':
				offset_y = int(line[11:-1])
				#print 'offset_y =', offset_y
	except:
		pass
	Xmin = MinPulse + offset_x
	Xmax = MaxPulse + offset_x
	Ymin = MinPulse + offset_y
	Ymax = MaxPulse + offset_y
	home_x = (Xmax + Xmin)/2
	home_y = Ymin + 80
	pwm = servo.init()           # Initialize the servo controller. 
Ejemplo n.º 10
0
commonDataStruct = {}
dataLock = threading.Lock()
yourThread = threading.Thread()"""
# Background loop imports END

FILE_CONFIG = "/var/www/Raspbrr/config"

Motor0_A = 11  # pin11
Motor0_B = 12  # pin12
Motor1_A = 13  # pin13
Motor1_B = 15  # pin15

EN_M0 = 4  # servo driver IC CH4
EN_M1 = 5  # servo driver IC CH5

p = pwm.init()

MinPulse = 200
MaxPulse = 700
offset_x = 0
offset_y = 0
turn_offset = 0


def setup():
    global pwm, turn_offset, Xmin, Ymin, Xmax, Ymax, home_x, home_y
    global forward0, forward1
    forward0 = 1
    forward1 = 1
    GPIO.setwarnings(False)
    GPIO.setmode(GPIO.BOARD)  # Number GPIOs by its physical location
# ===========================================================================
Motor0_A = 11  # pin11
Motor0_B = 12  # pin12
Motor1_A = 13  # pin13
Motor1_B = 15  # pin15

# ===========================================================================
# Set channel 4 and 5 of the servo driver IC to generate PWM, thus 
# controlling the speed of the car
# ===========================================================================
EN_M0    = 4  # servo driver IC CH4
EN_M1    = 5  # servo driver IC CH5

pins = [Motor0_A, Motor0_B, Motor1_A, Motor1_B]

p = pwm.init()

# ===========================================================================
# Adjust the duty cycle of the square waves output from channel 4 and 5 of
# the servo driver IC, so as to control the speed of the car.
# ===========================================================================
def setSpeed(speed):
	speed *= 40
	print 'speed is: ', speed
	p.setPWM(EN_M0, 0, speed)
	p.setPWM(EN_M1, 0, speed)

def setup():
	global forward0, forward1, backward1, backward0
	forward0 = 'True'
	forward1 = 'True'