Example #1
0
    def test_motor1_backward(self, mock_class):
        mock_class.pin_function.return_value = mock_class.OUT
        g = Patroller_GPIO()

        g.set_high(Motor_1_Pins.current)
        self.assertTrue(mock_class.output.called,
                        "Calling set_high should call output")
        g.set_low(Motor_1_Pins.direction)
        self.assertTrue(mock_class.output.called,
                        "Calling set_low from any pin should call output")
        g.set_low(Motor_1_Pins.current)
        self.assertTrue(mock_class.output.called,
                        "Calling set_low should call output")
Example #2
0
    def test_motor0_forward(self, mock_class):
        """
        Check that when we instruct motor 0 to go fowrward the correct pins are set.
        """
        mock_class.pin_function.return_value = mock_class.OUT
        g = Patroller_GPIO()

        g.set_high(Motor_0_Pins.current)
        self.assertTrue(mock_class.output.called,
                        "Calling set_high should call output")
        g.set_high(Motor_0_Pins.direction)
        self.assertTrue(mock_class.output.called,
                        "Calling set_high from any pin should call output")
        g.set_low(Motor_0_Pins.current)
        self.assertTrue(mock_class.output.called,
                        "Calling set_low should call output")
Example #3
0
 def test_motor1_pin_config(self, mock_class):
     g = Patroller_GPIO()
     # Firstly ensure the pins are set to the correct function.
     mock_class.pin_function.return_value = mock_class.OUT
     self.assertTrue(g.is_output(Motor_1_Pins.current))
     self.assertTrue(mock_class.pin_function.called,
                     "Calling is_output should call pin_function")
     self.assertFalse(g.is_input(Motor_1_Pins.current))
     self.assertTrue(mock_class.pin_function.called,
                     "Calling is_input should call pin_function")
     self.assertTrue(g.is_output(Motor_1_Pins.pwm))
     self.assertTrue(mock_class.pin_function.called,
                     "Calling is_output should call pin_function")
     self.assertTrue(g.is_output(Motor_1_Pins.direction))
     self.assertTrue(mock_class.pin_function.called,
                     "Calling is_output should call pin_function")
Example #4
0
 def test_current_sensor(self, mock_class):
     mock_class.pin_function.return_value = mock_class.IN
     g = Patroller_GPIO()
Example #5
0
 def __init__(self, motor_pins):
     self.gpio = Patroller_GPIO()
     self.motor_pins = motor_pins
     self.gpio.set_low(self.motor_pins.current)
     self.gpio.set_low(self.motor_pins.direction)
     self.gpio.set_low(self.motor_pins.pwm)
Example #6
0
class Motor(object):
    """
    The Motor class represents a motor, and provides the interface required for driving it.
    The only abilities it has are to run the motor forward or backward at various rates.
    Anything more sophisticated will be controlled by higher level classes.
    """
    def __init__(self, motor_pins):
        self.gpio = Patroller_GPIO()
        self.motor_pins = motor_pins
        self.gpio.set_low(self.motor_pins.current)
        self.gpio.set_low(self.motor_pins.direction)
        self.gpio.set_low(self.motor_pins.pwm)

    def forward(self, rate):
        self.gpio.set_high(self.motor_pins.pwm)

    def backward(self, rate):
        self.gpio.set_low(self.motor_pins.direction)

    def stop(self):
        self.gpio.set_off(self.motor_pins.current)