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")
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")
def testUnderRangeThrottle(self): filesystem = SysfsWriterDummy() motor = Motor(0, 50.0).setSysfsWriter(filesystem) motor.start() motor.setThrottle(-10.0) throttle = motor.getThrottle() self.assertEquals(throttle, 0.0, "Throttle wasn't properly set")
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")
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")
from servo.motor import Motor from time import time from random import uniform NEUTRAL_THROTTLE = Motor.MIN_THROTTLE + (Motor.MAX_THROTTLE - Motor.MIN_THROTTLE) / 2.0 motor0 = Motor(0, NEUTRAL_THROTTLE) motor1 = Motor(1, NEUTRAL_THROTTLE) n = 0 motor0.start() motor1.start() startTime = time() try: while True: n += 1 throttle0 = uniform(0.0, 100.0) throttle1 = uniform(0.0, 100.0) motor0.setThrottle(throttle0) motor1.setThrottle(throttle1) except KeyboardInterrupt: pass finally: endTime = time() motor0.stop() motor1.stop() dTime = endTime - startTime avgTime = dTime / n freq = 1.0 / avgTime print("Avg. time={0}; f={1}".format(avgTime, freq))