Ejemplo n.º 1
0
    def __init__(self, *args):
        util.traceCall()
        if len(args) == 1 and isinstance(args[0], dict):
            self.__dict__ = args[0]
        elif len(args) == 3:
            name, pinF, pinB = args
            self.name = name
            self._pinForward = pinF
            self._pinBackward = pinB

        # Set the GPIO modes
        util.trace("set the GPIO mode and the pins " + str(self._pinForward) +
                   " and " + str(self._pinBackward))
        if self._nb_instances == 0:
            GPIO.setmode(GPIO.BCM)
            GPIO.setwarnings(False)
        GPIO.setup(self._pinForward, GPIO.OUT)
        GPIO.setup(self._pinBackward, GPIO.OUT)

        # Set the GPIO to software PWM at 'Frequency' Hertz
        self._pwmMotorForward = GPIO.PWM(self._pinForward, self._frequency)
        self._pwmMotorBackward = GPIO.PWM(self._pinBackward, self._frequency)

        # Start the software PWM with a duty cycle of 0 (i.e. not moving)
        self._pwmMotorForward.start(self._stopCycle)
        self._pwmMotorBackward.start(self._stopCycle)

        # end of instance initialization
        self._nb_instances += 1
Ejemplo n.º 2
0
 def motorStop(self):
     util.traceCall()
     if util.getDebug() > 0:
         return
     util.trace("_pwmMotorForward.ChangeDutyCycle to stop")
     util.trace("_pwmMotorBackward.ChangeDutyCycle to stop")
     self._pwmMotorForward.ChangeDutyCycle(self._stopCycle)
     self._pwmMotorBackward.ChangeDutyCycle(self._stopCycle)
Ejemplo n.º 3
0
def isOverBlack():
	# If the sensor is Low (=0), it's above the black line
	if GPIO.input(pinLineFollower) == 0:
		util.trace("The sensor is seeing a black surface")
		return True
	# If not (else), print the following
	else:
		util.trace("The sensor is seeing a white surface")
		return False
Ejemplo n.º 4
0
def init():
    util.trace("lib_motors_base.init")
    # Set the GPIO modes
    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)

    # Set the GPIO Pin mode
    for x in range(pinMotorLeftBackwards, pinMotorRightForwards + 1):
        util.trace("set pin " + str(x))
        GPIO.setup(x, GPIO.OUT)
Ejemplo n.º 5
0
 def setSpeed(self, v):
     util.traceCall()
     if v <= self.getMaxSpeed():
         if self._curSpeed != v:
             # apply the new speed
             self._curSpeed = v
             self.motorUpdate()
         else:
             util.trace("The speed was already " + v)
     else:
         util.trace("The speed must be lower than " + self.getMaxSpeed())
Ejemplo n.º 6
0
 def setWay(self, way):
     util.traceCall()
     if way in self._way:
         if self._curWay != way:
             # apply the new way
             self._curWay = way
             self.motorStop()
             self.motorUpdate()
         else:
             util.trace("The way was already " + way)
     else:
         util.trace("The way must be in " + str(self._way))
Ejemplo n.º 7
0
def leftMotorSpeed(speed_f, speed_b):
	util.trace("lib_motors_evol.leftMotorSpeed with speed_f=" + str(speed_f) + " and speed_b=" + str(speed_b))
	if util.getDebug() > 0:
		return
	if 1 <= speed_f <= speed_max:
		pwmMotorLeftForwards.ChangeDutyCycle(DutyCycleLeft * speed_f)
	else:
		pwmMotorLeftForwards.ChangeDutyCycle(Stop)
	if 1 <= speed_b <= speed_max:
		pwmMotorLeftBackwards.ChangeDutyCycle(DutyCycleLeft * speed_b)
	else:
		pwmMotorLeftBackwards.ChangeDutyCycle(Stop)
Ejemplo n.º 8
0
def startRightMotor(speed):
	util.trace("lib_motors_evol.startRightMotor with speed=" + str(speed))
	s = speed
	if speed == 0:
		rightMotorSpeed(0, 0)
	elif speed > 0:
		if speed > speed_max:
			s = speed_max
		rightMotorSpeed(s, 0)
	else:
		if speed < -speed_max:
			s = -speed_max
		rightMotorSpeed(0, s)
Ejemplo n.º 9
0
    def __init__(self, *args):
        util.traceCall()
        if len(args) == 1 and isinstance(args[0], dict):
            self.__dict__ = args[0]
        elif len(args) == 3:
            name = args
            self.name = name

        # Define the 2 wheels
        util.trace("Define the 2 wheels")
        self._wheel_left = motor.Motor("left_wheel", 8, 7)
        self._wheel_right = motor.Motor("right_wheel", 10, 9)

        # end of instance initialization
        self._nb_instances += 1
Ejemplo n.º 10
0
def init():
	util.trace("lib_motors_evol.init")
	base.init()

	# Declare the PWM variables
	global pwmMotorLeftForwards
	global pwmMotorLeftBackwards
	global pwmMotorRightForwards
	global pwmMotorRightBackwards

	# Set the GPIO to software PWM at 'Frequency' Hertz
	pwmMotorLeftForwards = GPIO.PWM(base.pinMotorLeftForwards, Frequency)
	pwmMotorLeftBackwards = GPIO.PWM(base.pinMotorLeftBackwards, Frequency)
	pwmMotorRightForwards = GPIO.PWM(base.pinMotorRightForwards, Frequency)
	pwmMotorRightBackwards = GPIO.PWM(base.pinMotorRightBackwards, Frequency)

	# Start the software PWM with a duty cycle of 0 (i.e. not moving)
	pwmMotorLeftForwards.start(Stop)
	pwmMotorLeftBackwards.start(Stop)
	pwmMotorRightForwards.start(Stop)
	pwmMotorRightBackwards.start(Stop)
Ejemplo n.º 11
0
 def motorUpdate(self):
     util.traceCall()
     if util.getDebug() > 0:
         return
     if self._curWay == 0:
         # forward
         util.trace("_pwmMotorForward.ChangeDutyCycle to " +
                    str(self._dutyCycle * self._curSpeed))
         util.trace("_pwmMotorBackward.ChangeDutyCycle to stop")
         self._pwmMotorForward.ChangeDutyCycle(self._dutyCycle *
                                               self._curSpeed)
         self._pwmMotorBackward.ChangeDutyCycle(self._stopCycle)
     else:
         # backward
         util.trace("_pwmMotorForward.ChangeDutyCycle to stop")
         util.trace("_pwmMotorBackward.ChangeDutyCycle to " +
                    str(self._dutyCycle * self._curSpeed))
         self._pwmMotorForward.ChangeDutyCycle(self._stopCycle)
         self._pwmMotorBackward.ChangeDutyCycle(self._dutyCycle *
                                                self._curSpeed)
Ejemplo n.º 12
0
def left():
    util.trace("lib_motors_base.left")
    stopLeftMotor()
    forwardsRightMotor()
Ejemplo n.º 13
0
def backwards():
    util.trace("lib_motors_base.backwards")
    backwardsRightMotor()
    backwardsLeftMotor()
Ejemplo n.º 14
0
def forwards():
    util.trace("lib_motors_base.forwards")
    forwardsRightMotor()
    forwardsLeftMotor()
Ejemplo n.º 15
0
def backwardsLeftMotor():
    util.trace("lib_motors_base.backwardsLeftMotor")
    GPIO.output(pinMotorLeftForwards, 0)
    if util.getDebug == 0:
        GPIO.output(pinMotorLeftBackwards, 1)
Ejemplo n.º 16
0
def forwardsRightMotor():
    util.trace("lib_motors_base.forwardsRightMotor")
    if util.getDebug == 0:
        GPIO.output(pinMotorRightForwards, 1)
    GPIO.output(pinMotorRightBackwards, 0)
Ejemplo n.º 17
0
def end():
	util.trace("lib_motors_evol.end")
	stopMotors()
	base.end()
Ejemplo n.º 18
0
def backwards():
	util.trace("lib_motors_evol.backwards")
	leftMotorBackwards()
	rightMotorBackwards()
Ejemplo n.º 19
0
def right():
	util.trace("lib_motors_evol.right")
	leftMotorForwards()
	stopRightMotor()
Ejemplo n.º 20
0
def end():
    util.trace("lib_motors_base.end")
    stopMotors()
    # Reset the GPIO pins (turn off motors too)
    GPIO.cleanup()
Ejemplo n.º 21
0
def rightStay():
    util.trace("lib_motors_base.rightStay")
    forwardsLeftMotor()
    backwardsRightMotor()
Ejemplo n.º 22
0
def right():
    util.trace("lib_motors_base.right")
    forwardsLeftMotor()
    stopRightMotor()
Ejemplo n.º 23
0
def stopRightMotor():
	util.trace("lib_motors_evol.stopRightMotor")
	if util.getDebug() > 0:
		return
	pwmMotorRightForwards.ChangeDutyCycle(Stop)
	pwmMotorRightBackwards.ChangeDutyCycle(Stop)
Ejemplo n.º 24
0
def setSpeed(v):
	if v < -speed_max or v > speed_max:
		util.trace("The speed must be in range " + str(-speed_max) + ".." + str(speed_max))
	else:
		my_speed = v
Ejemplo n.º 25
0
def left():
	util.trace("lib_motors_evol.left")
	stopLeftMotor()
	rightMotorForwards()
Ejemplo n.º 26
0
def stopRightMotor():
    util.trace("lib_motors_base.stopRightMotor")
    GPIO.output(pinMotorRightForwards, 0)
    GPIO.output(pinMotorRightBackwards, 0)
Ejemplo n.º 27
0
def move(speed_l, speed_r):
	util.trace("lib_motors_evol.move with speed_l=" + str(speed_l) + " and speed_r=" + str(speed_r))
	startLeftMotor(speed_l)
	startRightMotor(speed_r)
Ejemplo n.º 28
0
def stopLeftMotor():
    util.trace("lib_motors_base.stopLeftMotor")
    GPIO.output(pinMotorLeftForwards, 0)
    GPIO.output(pinMotorLeftBackwards, 0)
Ejemplo n.º 29
0
def stopMotors():
    util.trace("lib_motors_base.stopMotors")
    stopRightMotor()
    stopLeftMotor()
Ejemplo n.º 30
0
def rightStay():
	util.trace("lib_motors_evol.rightStay")
	leftMotorForwards()
	rightMotorBackwards()