def test_units(self):
        clean_arena()
        populate_arena([('large_motor', 0, 'outA'),
                        ('large_motor', 1, 'outB')])

        m = Motor()

        self.assertEqual(
            SpeedPercent(35).to_native_units(m), 35 / 100 * m.max_speed)
        self.assertEqual(SpeedDPS(300).to_native_units(m), 300)
        self.assertEqual(SpeedNativeUnits(300).to_native_units(m), 300)
        self.assertEqual(SpeedDPM(30000).to_native_units(m), (30000 / 60))
        self.assertEqual(SpeedRPS(2).to_native_units(m), 360 * 2)
        self.assertEqual(SpeedRPM(100).to_native_units(m), (360 * 100 / 60))

        self.assertEqual(DistanceMillimeters(42).mm, 42)
        self.assertEqual(DistanceCentimeters(42).mm, 420)
        self.assertEqual(DistanceDecimeters(42).mm, 4200)
        self.assertEqual(DistanceMeters(42).mm, 42000)

        self.assertAlmostEqual(DistanceInches(42).mm, 1066.8)
        self.assertAlmostEqual(DistanceFeet(42).mm, 12801.6)
        self.assertAlmostEqual(DistanceYards(42).mm, 38404.8)

        self.assertEqual(DistanceStuds(42).mm, 336)
    def test_units(self):
        clean_arena()
        populate_arena([('large_motor', 0, 'outA'), ('large_motor', 1, 'outB')])

        m = Motor()

        self.assertEqual(SpeedPercent(35).get_speed_pct(m), 35)
        self.assertEqual(SpeedDPS(300).get_speed_pct(m), 300 / 1050 * 100)
        self.assertEqual(SpeedNativeUnits(300).get_speed_pct(m), 300 / 1050 * 100)
        self.assertEqual(SpeedDPM(30000).get_speed_pct(m), (30000 / 60) / 1050 * 100)
        self.assertEqual(SpeedRPS(2).get_speed_pct(m), 360 * 2 / 1050 * 100)
        self.assertEqual(SpeedRPM(100).get_speed_pct(m), (360 * 100 / 60) / 1050 * 100)
Beispiel #3
0
    def test_units(self):
        clean_arena()
        populate_arena([('large_motor', 0, 'outA'),
                        ('large_motor', 1, 'outB')])

        m = Motor()

        self.assertEqual(
            SpeedPercent(35).to_native_units(m), 35 / 100 * m.max_speed)
        self.assertEqual(SpeedDPS(300).to_native_units(m), 300)
        self.assertEqual(SpeedNativeUnits(300).to_native_units(m), 300)
        self.assertEqual(SpeedDPM(30000).to_native_units(m), (30000 / 60))
        self.assertEqual(SpeedRPS(2).to_native_units(m), 360 * 2)
        self.assertEqual(SpeedRPM(100).to_native_units(m), (360 * 100 / 60))
    def test_tank_units(self):
        clean_arena()
        populate_arena([('large_motor', 0, 'outA'), ('large_motor', 1, 'outB')])

        drive = MoveTank(OUTPUT_A, OUTPUT_B)
        drive.on_for_rotations(SpeedDPS(400), SpeedDPM(10000), 10)

        self.assertEqual(drive.left_motor.position, 0)
        self.assertEqual(drive.left_motor.position_sp, 10 * 360)
        self.assertEqual(drive.left_motor.speed_sp, 400)

        self.assertEqual(drive.right_motor.position, 0)
        self.assertAlmostEqual(drive.right_motor.position_sp, 10 * 360 * ((10000 / 60) / 400), delta=7)
        self.assertAlmostEqual(drive.right_motor.speed_sp, 10000 / 60, delta=1)
Beispiel #5
0
def large_motor():
    lm = LargeMotor()
    '''
    This will run the large motor at 50% of its
    rated maximum speed of 1050 deg/s.
    50% x 1050 = 525 deg/s
    '''
    lm.on_for_seconds(50, seconds=3)
    sleep(1)
    '''
    speed and seconds are both POSITIONAL
    arguments which means
    you don't have to include the parameter names as
    long as you put the arguments in this order 
    (speed then seconds) so this is the same as
    the previous command:
    '''
    lm.on_for_seconds(50, 3)
    sleep(1)
    '''
    This will run at 500 degrees per second (DPS).
    You should be able to hear that the motor runs a
    little slower than before.
    '''
    lm.on_for_seconds(SpeedDPS(500), seconds=3)
    sleep(1)

    # 36000 degrees per minute (DPM) (rarely useful!)
    lm.on_for_seconds(SpeedDPM(36000), seconds=3)
    sleep(1)

    # 2 rotations per second (RPS)
    lm.on_for_seconds(SpeedRPS(2), seconds=3)
    sleep(1)

    # 100 rotations per minute(RPM)
    lm.on_for_seconds(SpeedRPM(100), seconds=3)
Beispiel #6
0
'''
lm.on_for_seconds(speed=50, seconds=3)
sleep(1)
'''
speed and seconds are both POSITIONAL
arguments which means
you don't have to include the parameter names as
long as you put the arguments in this order 
(speed then seconds) so this is the same as
the previous command:
'''
lm.on_for_seconds(50, 3)
sleep(1)
'''
This will run at 500 degrees per second (DPS).
You should be able to hear that the motor runs a
little slower than before.
'''
lm.on_for_seconds(speed=SpeedDPS(500), seconds=3)
sleep(1)

# 36000 degrees per minute (DPM) (rarely useful!)
lm.on_for_seconds(speed=SpeedDPM(36000), seconds=3)
sleep(1)

# 2 rotations per second (RPS)
lm.on_for_seconds(speed=SpeedRPS(2), seconds=3)
sleep(1)

# 100 rotations per minute(RPM)
lm.on_for_seconds(speed=SpeedRPM(100), seconds=3)
Beispiel #7
0
from ev3dev2.motor import SpeedDPS, SpeedRPM, SpeedRPS, SpeedDPM

lm = LargeMotor(OUTPUT_C)   # 연결 포트를 지정 안하면 기본 포트로 동작

#region 시간으로 제어 => on_for_seconds(speed, seconds, brake=True, block=True)
#region 1.시간으로 제어
lm.on_for_seconds(speed = 50, seconds=3)    # maximum speed(1050 deg/s)의 50% 속도로 3초 동안 회전
sleep(1)
lm.on_for_seconds(50, 3)   # 매개 변수 이름을 명시하지 않아도 된다. 
sleep(1)
#endregion

#region 2.시간당 각도로 제어
lm.on_for_seconds(speed=SpeedDPS(300), seconds=3)   # DPS(degrees per second) 초당 300도를 도는 속도로 3초 동안 회전
sleep(1)
lm.on_for_seconds(speed=SpeedDPM(36000), seconds=3) # DPM(degrees per minute) 분당 36000도
sleep(1)
#endregion

#region 3.시간당 회전수로 제어 
lm.on_for_seconds(speed=SpeedRPS(1), seconds=2)     # RPS(rotations per second) 초당 1바퀴를 도는 속도로 seconds 초 동안 회전
sleep(1)    
lm.on_for_seconds(speed=SpeedRPM(100), seconds=3)   # RPM(rotations per minute) 분당 100바퀴를 도는 속도 seconds 초 동안 회전
sleep(1)
#endregion
#endregion

#region 바퀴 회전으로 제어 => on_for_rotations(speed, rotations, brake=True, block=True)
#region 1.모터의 정격 스피드의 비율로 동작 
lm.on_for_rotations(speed=50, rotations=3)  # 정격 최대 속도(1050 deg/s)의 50%의 속도로 3바퀴 회전 
sleep(1)
# Run motors at some speed (speed is a percantegate of the max motor power)
lMotorLeft.on_for_seconds(
    speed=50, seconds=2
)  # "speed = 50" - 50% of the max speed of 1050 deg/s for L motor and 1560 for M motor
# or lMotorLeft.on_for_seconds(50, 2)
sleep(0.5)

# Run motors at some speed with use of SpeedDPS/DPM/RPS/RPM funcs.
#  DPS - degrees per second
#  DPM - degress per minute
#  RPS - rotations per second
#  RPM - rotations per minute
lMotorLeft.on_for_seconds(speed=SpeedDPS(500), seconds=2)
sleep(0.5)
lMotorLeft.on_for_seconds(speed=SpeedDPM(36000), seconds=2)
sleep(0.5)
lMotorLeft.on_for_seconds(speed=SpeedRPS(2), seconds=2)
sleep(0.5)
lMotorLeft.on_for_seconds(speed=SpeedRPM(100), seconds=2)
sleep(0.5)

# Run motors for certain speed with implicit 'brake' and 'block' paramters (True by default)
# "brake = False" - don't stop the motor after it finishes the command (use friction to stop)
# "block = False" - don't block the run of script (continue to run script)
lMotorLeft.on_for_seconds(speed=SpeedRPS(2),
                          seconds=3,
                          brake=False,
                          block=False)
lMotorRight.on_for_seconds(speed=SpeedRPS(2),
                           seconds=3,