Skip to content

Commit

Permalink
Updated readme and imu tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PrasRsRos committed Aug 31, 2023
1 parent 66ba4ee commit 6922d4d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 30 deletions.
20 changes: 17 additions & 3 deletions realsense2_camera/test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,21 @@ The below command finds the test with the name test_static_tf_1 in realsense2_ca

pytest-3 -s -k test_static_tf_1 realsense2_camera/test/

### Points to be noted while writing pytests
The tests that are in one file are nromally run in parallel. So if there are multiple tests in one file, the system capacity can influence the test execution. It's recomended to have 3-4 tests in file, more than that can affect the test results due to delays.

## Points to be noted while writing pytests
The tests that are in one file are normally run in parallel. So if there are multiple tests in one file, the system capacity can influence the test execution. It's recomended to have 3-4 tests in file, more than that can affect the test results due to delays.
### Passing/changing parameters
The parameters passed while creating the node can be initialized individually for each test, please see the test_parameterized_template example for reference. The default values are taken from rs_launch.py and the passed parameters are used for overriding the default values. The parameters that can be dynamically modified can be changed using the param interface provided. However, the function create_param_ifs has to be called to create this interface. Please see the test_d455_basic_tests.py for reference. There are specific functions to change the string, integer and bool parameters, the utils can be extended if any more types are needed.
### Difference in setting the bool parameters
There is a difference between setting the default values of bool parameters and setting them dynamically.
The bool test params are assinged withn quotes as below.
test_params_all_profiles_d455 = {
'camera_name': 'D455',
'device_type': 'D455',
'enable_accel':"True",
'enable_gyro':"True",
'unite_imu_method':1,
}

However the function that implements the setting of bool parameter dynamically takes the python bool datatype. For example:
self.set_bool_param('enable_accel', False)

41 changes: 16 additions & 25 deletions realsense2_camera/test/live_camera/test_camera_imu_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
test_params_all_profiles_d455 = {
'camera_name': 'D455',
'device_type': 'D455',
'enable_accel':True,
'enable_gyro':True,
'enable_accel':"True",
'enable_gyro':"True",
'unite_imu_method':1,
}

Expand All @@ -64,62 +64,53 @@ def test_LiveCamera_check_motion_sensor(self,launch_descr_with_parameters):
if params['unite_imu_method'] == '0':
themes[IMU_TOPIC]['expected_data_chunks'] = 0
try:
'''
initialize, run and check the data
'''
msg = "Test with the default params "
#initialize
self.init_test("RsTest"+params['camera_name'])
self.create_param_ifs(get_node_heirarchy(params))


#run with default params and check the data
msg = "Test with the default params "
print(msg)
ret = self.run_test(themes)
ret = self.run_test(themes, timeout=50)
assert ret[0], msg + str(ret[1])
assert self.process_data(themes), msg + " failed"


msg = "Test with the accel false "
self.set_bool_param('enable_accel', False)
self.set_bool_param('enable_gyro', True)
'''
This step fails if the next line is commented
'''
self.set_integer_param('unite_imu_method', 0) #this shouldn't matter because the unite_imu_method cannot be changed
themes[ACCEL_TOPIC]['expected_data_chunks'] = 0
#uncomment once RSDEV-550 is closed
#themes[IMU_TOPIC]['expected_data_chunks'] = 0
print(msg)
ret = self.run_test(themes)
assert ret[0], msg + str(ret[1])
assert self.process_data(themes), msg + " failed"
'''
Test fails
'''

msg = "Test with the gyro false "
self.set_bool_param('enable_accel', True)
self.set_bool_param('enable_gyro', False)
self.set_integer_param('unite_imu_method', 0) #this shouldn't matter because the unite_imu_method cannot be changed
themes[IMU_TOPIC]['expected_data_chunks'] = 1
themes[IMU_TOPIC]['expected_data_chunks'] = 0
themes[ACCEL_TOPIC]['expected_data_chunks'] = 1
themes[GYRO_TOPIC]['expected_data_chunks'] = 0
print(msg)
self.spin_for_time(wait_time=1.0)
ret = self.run_test(themes)
assert ret[0], msg + str(ret[1])
assert self.process_data(themes), msg + " failed"

'''
Test fails, both gyro and accel data is available, not imu
'''
msg = "Test with both gyro and accel false "
self.set_bool_param('enable_accel', False)
self.set_bool_param('enable_gyro', False)
self.set_integer_param('unite_imu_method', 1) #this shouldn't matter because the unite_imu_method cannot be changed

self.set_integer_param('unite_imu_method', 1)
self.spin_for_time(wait_time=1.0)
themes[ACCEL_TOPIC]['expected_data_chunks'] = 0
themes[GYRO_TOPIC]['expected_data_chunks'] = 0
themes[IMU_TOPIC]['expected_data_chunks'] = 1 #Seems that imu data is available even if gyro and accel is disabled
themes[IMU_TOPIC]['expected_data_chunks'] = 0
print(msg)
ret = self.run_test(themes, initial_wait_time=1.0) #wait_time added as test doesn't have to wait for any data
ret = self.run_test(themes, initial_wait_time=1.0)
assert ret[0], msg + " failed"
assert self.process_data(themes), msg +" failed"

finally:
#this step is important because the test will fail next time
pytest_rs_utils.kill_realsense2_camera_node()
Expand Down
8 changes: 6 additions & 2 deletions realsense2_camera/test/utils/pytest_rs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,9 +819,12 @@ def spin_for_data(self,themes, timeout=5.0):
'''
print('Waiting for topic... ' )
flag = False
data_not_expected = [i for i in themes if (i["expected_data_chunks"]) == 0]
while (time.time() - start) < timeout:
rclpy.spin_once(self.node, timeout_sec=1)
debug_print('Spun once... ' )
if data_not_expected == True:
continue
all_found = True
for theme in themes:
if theme['expected_data_chunks'] > int(self.node.get_num_chunks(theme['topic'])):
Expand All @@ -831,8 +834,9 @@ def spin_for_data(self,themes, timeout=5.0):
flag =True
break
else:
print("Timed out waiting for", timeout, "seconds" )
return False, "run_test timedout"
if data_not_expected == False:
print("Timed out waiting for", timeout, "seconds" )
return False, "run_test timedout"
return flag,""

def spin_for_time(self,wait_time):
Expand Down

0 comments on commit 6922d4d

Please sign in to comment.