コード例 #1
0
ファイル: motorTestCase.py プロジェクト: Aamirnadeem/Gimbal
    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")
コード例 #2
0
ファイル: motorTestCase.py プロジェクト: Aamirnadeem/Gimbal
    def testIdle(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.idle()
        throttle = motor.getThrottle()

        self.assertEquals(throttle, 50.0, "Throttle wasn't properly set")
コード例 #3
0
ファイル: driver.py プロジェクト: Aamirnadeem/Gimbal
    def _createMotor(self, motorId, sysfsWriterFactory):
        '''
        Creates a new motor instance
        '''

        if self._motorType == Configuration.VALUE_MOTOR_CLASS_LOCAL:
            motor = Motor(motorId, Driver.NEUTRAL_THROTTLE)
            if sysfsWriterFactory:
                motor.setSysfsWriter(sysfsWriterFactory.create())

        else:  #default VALUE_MOTOR_CLASS_DUMMY
            motor = MotorDummy(motorId, Driver.NEUTRAL_THROTTLE)

        return motor
コード例 #4
0
ファイル: motorTestCase.py プロジェクト: Aamirnadeem/Gimbal
    def testAddThrottle(self):

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

        motor.addThrottle(15.0)
        throttle = motor.getThrottle()

        self.assertEquals(throttle, 25.0, "Throttle wasn't properly added")
コード例 #5
0
ファイル: motorTestCase.py プロジェクト: Aamirnadeem/Gimbal
    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")
コード例 #6
0
ファイル: motorTestCase.py プロジェクト: Aamirnadeem/Gimbal
    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")
コード例 #7
0
ファイル: motorTestCase.py プロジェクト: Aamirnadeem/Gimbal
    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")
コード例 #8
0
ファイル: motorTestCase.py プロジェクト: Aamirnadeem/Gimbal
    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")
コード例 #9
0
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))