Example #1
0
    def testSetThrottle(self):

        filesystem = SysfsWriterDummy()
        motor = Motor(0, 50.0).setSysfsWriter(filesystem)
        motor.start()

        motor.setThrottle(10.0)

        throttle = motor.getThrottle()
        duty = motor.getDuty()

        self.assertEquals(throttle, 10.0, "Throttle wasn't properly set")
        self.assertEquals(duty, 1100000, "Duty wasn't properly set")
        #pwm6 corresponds to the motor number 0
        self.assertEquals(int(filesystem.read("/sys/class/pwm/pwm6/duty_ns")),
                          1100000, "Duty wasn't properly written")
Example #2
0
    def testGetThrottle(self):

        filesystem = SysfsWriterDummy()
        motor = Motor(0, 50.0).setSysfsWriter(filesystem)
        motor.start()
        motor.setThrottle(10.0)

        throttle = motor.getThrottle()
        self.assertEquals(throttle, 10.0, "Throttle wasn't properly returned")
Example #3
0
    def testSetMinThrottle(self):

        filesystem = SysfsWriterDummy()
        motor = Motor(0, 50.0).setSysfsWriter(filesystem)
        motor.start()

        motor.setMinThrottle()
        throttle = motor.getThrottle()

        self.assertEquals(throttle, 0.0, "Throttle wasn't properly set")
Example #4
0
    def testGetDuty(self):

        filesystem = SysfsWriterDummy()
        motor = Motor(0, 50.0).setSysfsWriter(filesystem)
        motor.start()
        motor.setThrottle(10.0)

        duty = motor.getDuty()

        self.assertEquals(duty, 1100000, "Duty wasn't properly returned")
Example #5
0
    def testStop(self):

        filesystem = SysfsWriterDummy()
        motor = Motor(0, 50.0).setSysfsWriter(filesystem)
        motor.start()

        motor.setThrottle(10.0)
        throttle = motor.getThrottle()
        self.assertEquals(throttle, 10.0, "Throttle wasn't properly set")

        motor.stop()

        throttle = motor.getThrottle()
        self.assertEquals(throttle, 50.0,
                          "Throttle wasn't properly set at neutral value")

        #pwm6 corresponds to the motor number 0
        self.assertEquals(int(filesystem.read("/sys/class/pwm/pwm6/run")), 0,
                          "Motor wasn't properly stopped")
Example #6
0
    def testStart(self):

        filesystem = SysfsWriterDummy()
        motor = Motor(0, 50.0).setSysfsWriter(filesystem)
        motor.start()

        throttle = motor.getThrottle()
        duty = motor.getDuty()

        self.assertEquals(throttle, 50.0, "Incorrect throttle")
        self.assertEquals(duty, 1500000, "Incorrect duty")

        #pwm6 corresponds to the motor number 0
        self.assertEquals(int(filesystem.read("/sys/class/pwm/pwm6/run")), 1,
                          "Motor not running")
        self.assertEquals(
            int(filesystem.read("/sys/class/pwm/pwm6/period_ns")), 20000000,
            "Incorrect period")
        self.assertEquals(int(filesystem.read("/sys/class/pwm/pwm6/duty_ns")),
                          1500000, "Motor not running")
Example #7
0
    def test_calculateDuty(self):

        filesystem = SysfsWriterDummy()
        motor = Motor(0, 50.0).setSysfsWriter(filesystem)

        duty = motor._calculateDuty(0.0)
        self.assertEquals(duty, 1000000, "Wrong duty")

        duty = motor._calculateDuty(50.0)
        self.assertEquals(duty, 1500000, "Wrong duty")

        duty = motor._calculateDuty(100.0)
        self.assertEquals(duty, 2000000, "Wrong duty")