def test_dynamixel_scan(self, mock_robot_init): robot = BaseRobot(**mock_robot_init['dynamixel']) robot.start() ids = robot.buses['ttys1'].scan() assert 11 in ids assert 12 in ids robot.stop()
def test_i2c_sensorXYZ_value(self, mock_robot_init, caplog): robot = BaseRobot(**mock_robot_init['i2crobot']) robot.start() s = robot.sensors['gyro'] d = robot.devices['imu'] exp_x = - d.word_g_x.value exp_y = d.word_g_y.value + 256 exp_z = - d.word_g_z.value + 1024 assert s.x == exp_x assert s.y == exp_y assert s.z == exp_z assert s.value == (exp_x, exp_y, exp_z) # byte sensor s = robot.sensors['accel_byte'] exp_x = d.byte_xl_x.value + 128 exp_y = - d.byte_xl_y.value -128 exp_z = d.byte_xl_z.value + 64 assert s.x == exp_x assert s.y == exp_y assert s.z == exp_z assert s.value == (exp_x, exp_y, exp_z) assert s.active # activate w/o register caplog.clear() s.active = True assert len(caplog.records) == 1 assert 'attempted to change activation of sensor' in caplog.text
def test_i2c_sensor(self, mock_robot_init, caplog): robot = BaseRobot(**mock_robot_init['i2crobot']) robot.start() s = robot.sensors['temp'] d = robot.devices['imu'] assert s.device == d assert s.read_register == d.temp assert s.activate_register == d.activate_temp assert not s.active # removed the masking in sensor # assert s.bits is None assert s.offset == 0 assert s.inverse assert s.auto_activate s.active = True assert s.active assert s.value == -10.0 # masks assert robot.sensors['status0'].value assert not robot.sensors['status1'].value # setting active for register w/o active register caplog.clear() robot.sensors['status0'].active = True assert len(caplog.records) == 1 assert 'attempted to change activation of sensor' in caplog.text
def test_i2c_write2_with_errors(self, mock_robot_init, caplog): robot = BaseRobot(**mock_robot_init['i2crobot']) robot.start() device = robot.devices['imu'] for _ in range(20): # so that we also get some errors device.word_control_2.value = 0x2121 assert device.word_control_2.value == 0x2121
def test_open_device_with_sync_items(self, mock_robot_init): robot = BaseRobot(**mock_robot_init['dynamixel']) robot.start() dev = robot.devices['d11'] dev.present_position_deg.sync = True dev.open() robot.stop()
def test_dynamixel_register_4Bytes(self, mock_robot_init): robot = BaseRobot(**mock_robot_init['dynamixel']) robot.start() dev = robot.devices['d11'] register = BaseRegister(name='test', device=dev, address=150, size=4, access='RW') register.value = 100 assert register.value == 100
def test_dynamixel_write(self, mock_robot_init): robot = BaseRobot(**mock_robot_init['dynamixel']) robot.start() dev = robot.devices['d11'] for _ in range(100): # so that we also hit some comm errors dev.temperature_limit.value = 85 assert dev.temperature_limit.value == 85 dev.cw_angle_limit_deg.value = 10 assert (dev.cw_angle_limit_deg.value - 10) < 0.2 robot.stop()
def test_register_with_dynamic_conversion(self, mock_robot_init): mock_robot_init['i2crobot']['buses']['i2c2']['err'] = 0 robot = BaseRobot(**mock_robot_init['i2crobot']) robot.start() d = robot.devices['imu'] # set the control register d.range_control.value = 0b110000 assert d.range_control_conv.value == 3 assert d.dynamic_register.value == 1024.0 / 10.0 * 3.0 d.range_control_conv.value = 6 assert d.range_control.value == 0b1100000 assert d.dynamic_register.value == 1024.0 / 10.0 * 6.0
def test_i2c_robot(self, mock_robot_init, caplog): robot = BaseRobot(**mock_robot_init['i2crobot']) robot.start() dev = robot.devices['imu'] # 1 Byte registers for _ in range(5): # to account for possible comm errs dev.byte_xl_x.value = 20 assert dev.byte_xl_x.value == 20 # word register dev.word_xl_x.value = 12345 assert dev.word_xl_x.value == 12345 robot.stop()
def test_dynamixel_bus_acquire_bulkread(self, mock_robot_init, caplog): # syncs robot = BaseRobot(**mock_robot_init['dynamixel']) robot.start() robot.buses['ttys1'].can_use() # lock the bus caplog.clear() robot.syncs['bulkread'].start() time.sleep(1) assert len(caplog.records) >= 1 assert 'failed to acquire bus ttys1' in caplog.text robot.syncs['bulkread'].stop() # release bus robot.buses['ttys1'].stop_using() robot.stop()
def test_i2c_register_with_sign(self, mock_robot_init): robot = BaseRobot(**mock_robot_init['i2crobot']) robot.start() d = robot.devices['imu'] # no factor d.word_xl_x.value = 10 assert d.word_xl_x.value == 10 assert d.word_xl_x.int_value == 10 d.word_xl_x.value = -10 assert d.word_xl_x.value == -10 assert d.word_xl_x.int_value == (65536 - 10) # with factor d.word_xl_y.value = 100 assert d.word_xl_y.value == 100 assert d.word_xl_y.int_value == 1000 d.word_xl_y.value = -100 assert d.word_xl_y.value == -100 assert d.word_xl_y.int_value == (65536 - 1000)
def test_dynamixel_bus_acquire(self, mock_robot_init, caplog): robot = BaseRobot(**mock_robot_init['dynamixel']) robot.start() dev = robot.devices['d11'] bus = robot.buses['ttys1'] bus.can_use() # lock the bus # read caplog.clear() bus.read(dev.return_delay_time) assert len(caplog.records) >= 1 assert 'failed to acquire bus ttys1' in caplog.text # write caplog.clear() bus.write(dev.return_delay_time, 10) assert len(caplog.records) >= 1 assert 'failed to acquire bus ttys1' in caplog.text # release bus bus.stop_using() robot.stop()
def test_i2c_loop_failed_acquire(self, mock_robot_init, caplog): robot = BaseRobot(**mock_robot_init['i2crobot']) robot.start() # lock the bus robot.buses['i2c2'].can_use() # read caplog.clear() robot.syncs['read_g'].start() time.sleep(1) assert len(caplog.records) >= 1 assert 'failed to acquire bus' in caplog.text robot.syncs['read_g'].stop() # write caplog.clear() robot.syncs['write_xl'].start() time.sleep(1) assert len(caplog.records) >= 1 assert 'failed to acquire bus' in caplog.text robot.syncs['read_g'].stop()
def test_i2c_sensorXYZ(self, mock_robot_init): robot = BaseRobot(**mock_robot_init['i2crobot']) robot.start() s = robot.sensors['gyro'] d = robot.devices['imu'] assert s.device == d assert s.x_register == d. word_g_x assert s.y_register == d. word_g_y assert s.z_register == d. word_g_z assert s.activate_register == d.activate_g assert not s.active assert s.x_offset == 0 assert s.x_inverse assert s.y_offset == 256 assert not s.y_inverse assert s.z_offset == 1024 assert s.z_inverse assert s.auto_activate s.active = True assert s.active
def test_i2c_write_loop(self, mock_robot_init): robot = BaseRobot(**mock_robot_init['i2crobot']) robot.start() robot.syncs['write_xl'].start() time.sleep(1) robot.stop()
def test_dynamixel_rangeread(self, mock_robot_init): robot = BaseRobot(**mock_robot_init['dynamixel']) robot.start() robot.syncs['rangeread'].start() time.sleep(1) robot.stop()
def test_dynamixel_bulkwrite(self, mock_robot_init): robot = BaseRobot(**mock_robot_init['dynamixel']) robot.start() robot.syncs['bulkwrite'].start() time.sleep(1) robot.stop()
def test_dynamixel_robot(self, mock_robot_init): for name, init_dict in mock_robot_init.items(): break robot = BaseRobot(name=name, **init_dict) robot.start() robot.stop()
def test_i2c_read_loop(self, mock_robot_init): robot = BaseRobot(**mock_robot_init['i2crobot']) robot.start() robot.syncs['read_g'].start() time.sleep(1) robot.stop()
def test_dynamixel_ping(self, mock_robot_init): robot = BaseRobot(**mock_robot_init['dynamixel']) robot.start() assert robot.buses['ttys1'].ping(11) == True robot.stop()