34 PKG =
"pr2_camera_synchronizer" 35 import roslib; roslib.load_manifest(PKG)
38 import pr2_camera_synchronizer.cfg.CameraSynchronizerConfig
as Config
49 return list(sum(l, ()))
52 def runCase(self, rate, length, shift, out_repeat_period, out_proj_end, out_alt_end, out_noproj_end, level = lvl_projector):
54 param_proj_rate : rate,
55 "projector_pulse_length" : length,
56 "projector_pulse_shift" : shift,
57 "projector_tweak" : 0,
58 "projector_mode" : Config.CameraSynchronizer_ProjectorOn,
61 proj.process_update(config, level)
63 if level & lvl_projector != 0:
64 self.assert_(math.fmod(config[
"projector_rate"], ETHERCAT_INTERVAL))
65 self.assert_(config[
"projector_pulse_length"] >= length,
"Pulse length %f"%config[
"projector_pulse_length"])
66 self.assertEqual(config[
"projector_pulse_length"], proj.pulse_length)
67 self.assert_(math.fmod(proj.pulse_length, ETHERCAT_INTERVAL) == 0,
"Pulse length %f"%proj.pulse_length)
68 self.assertEqual(len(proj.pulse_ends), 4)
69 self.assertEqual(len(proj.pulse_starts), 4)
71 self.assertEqual(4. / proj.repeat_period, config[
"projector_rate"])
73 self.assertEqual(out_repeat_period, proj.repeat_period)
74 self.assertEqual(out_proj_end, proj.proj_end_offset)
75 self.assertEqual(out_noproj_end, proj.noproj_end_offset)
76 self.assertAlmostEqual(out_alt_end, proj.alt_end_offset, DIGITS)
81 proj,config = self.
runCase(30, 0.002, 0, 0.132, 0.003, 0.036, 0.032)
84 def runCase(self, proj_rate, proj_length, proj_shift, rate, trig_mode, out_period, out_ext_trig, out_imager_period, out_end_offset, level = 1, reset_camera = False):
85 paramnames = dict((name,name)
for name
in camera_parameters)
87 param_proj_rate : proj_rate,
88 "projector_pulse_length" : proj_length,
89 "projector_pulse_shift" : proj_shift,
90 "projector_tweak" : 0,
91 "projector_mode" : Config.CameraSynchronizer_ProjectorOn,
93 param_trig_mode : trig_mode,
94 "camera_reset" : reset_camera,
98 proj.process_update(config, lvl_projector)
99 camera =
Camera(
"test_cam", proj, 1, **paramnames)
100 camera.process_update(config, level)
103 self.assert_(math.fmod(camera.period, ETHERCAT_INTERVAL) == 0)
104 self.assertEqual(config[param_rate], 1. / camera.period)
106 self.assert_(out_period > 0,
"Period %f"%out_period)
107 self.assertAlmostEqual(camera.period, out_period, DIGITS)
108 self.assertEqual(camera.ext_trig, out_ext_trig)
109 self.assert_(out_imager_period > 0,
"Imager period %f"%out_imager_period)
110 self.assertAlmostEqual(camera.imager_period, out_imager_period, DIGITS)
111 self.assertAlmostEqual(camera.end_offset, out_end_offset, DIGITS)
113 return camera, proj, config
116 self.
runCase(60, 0.001, 0, 30, Config.CameraSynchronizer_WithProjector, 0.034,
True, 0.033, 0.002)
118 self.
runCase(60, 0.001, 0, 30, Config.CameraSynchronizer_AlternateProjector, 0.034,
True, 0.033, 0.019)
120 self.
runCase(60, 0.001, 0, 30, Config.CameraSynchronizer_WithoutProjector, 0.034,
True, 0.033, 0.016)
122 self.
runCase(60, 0.001, 0, 30, Config.CameraSynchronizer_InternalTrigger, 1/30.0,
False, 1/30.0, -1)
124 if __name__ ==
'__main__':
130 rospy.get_time = time.time
132 rostest.rosrun(PKG,
'test_projector', TestProjector)
133 rostest.rosrun(PKG,
'test_camera', TestCamera)
def testBasicNoProj(self)
def testBasicFreeRun(self)
def runCase(self, proj_rate, proj_length, proj_shift, rate, trig_mode, out_period, out_ext_trig, out_imager_period, out_end_offset, level=1, reset_camera=False)
def killAsynchronousUpdaters()
def runCase(self, rate, length, shift, out_repeat_period, out_proj_end, out_alt_end, out_noproj_end, level=lvl_projector)
def testBasicAlwaysProj(self)
def testBasicFunctionality(self)
def testBasicAlternateProj(self)