Beispiel #1
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.
Beispiel #2
0
def setup():
	global leftPWM, rightPWM, homePWM, pwm
	leftPWM = 400
	homePWM = 450
	rightPWM = 500
	offset =0
	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.
Beispiel #3
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. 
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'