From 1800889bc765fc0a6b81b997a769fabe354b01a0 Mon Sep 17 00:00:00 2001 From: cnlohr Date: Tue, 24 Apr 2018 21:00:16 -0400 Subject: Get rid of disambiguator-specifc stuff in the objects. --- include/libsurvive/survive.h | 8 -------- src/survive_charlesbiguator.c | 28 ++++++++++++++++++---------- src/survive_default_devices.c | 7 ------- src/survive_driver_dummy.c | 7 ------- src/survive_process.c | 4 +++- 5 files changed, 21 insertions(+), 33 deletions(-) diff --git a/include/libsurvive/survive.h b/include/libsurvive/survive.h index fb95c80..28c96c3 100644 --- a/include/libsurvive/survive.h +++ b/include/libsurvive/survive.h @@ -81,14 +81,6 @@ struct SurviveObject { // Timing sensitive data (mostly for disambiguation) int32_t timebase_hz; // 48,000,000 for normal vive hardware. (checked) - int32_t timecenter_ticks; // 200,000 for normal vive hardware. (checked) (This doubles-up as 2x this = full - // sweep length) - int32_t pulsedist_max_ticks; // 500,000 for normal vive hardware. (guessed) - int32_t pulselength_min_sync; // 2,200 for normal vive hardware. (guessed) - int32_t pulse_in_clear_time; // 35,000 for normal vive hardware. (guessed) - int32_t pulse_max_for_sweep; // 1,800 for normal vive hardware. (guessed) - int32_t pulse_synctime_offset; // 20,000 for normal vive hardware. (guessed) - int32_t pulse_synctime_slack; // 5,000 for normal vive hardware. (guessed) // Flood info, for calculating which laser is currently sweeping. void *disambiguator_data; diff --git a/src/survive_charlesbiguator.c b/src/survive_charlesbiguator.c index 83b3681..52f94bb 100644 --- a/src/survive_charlesbiguator.c +++ b/src/survive_charlesbiguator.c @@ -6,6 +6,14 @@ #include #include +#define PULSELENGTH_MIN_SYNC 2200 +#define TIMECENTER_TICKS (48000000/240) +#define PULSEDIST_MAX_TICKS 500000 +#define PULSE_IN_CLEAR_TIME 35000 +#define PULSE_MAX_FOR_SWEEP 1800 +#define PULSE_SYNCTIME_OFFSET 20000 //unused? +#define PULSE_SYNCTIME_SLACK 5000 + static int32_t decode_acode(uint32_t length, int32_t main_divisor) { //+50 adds a small offset and seems to help always get it right. // Check the +50 in the future to see how well this works on a variety of hardware. @@ -82,22 +90,22 @@ void DisambiguatorCharles(SurviveObject *so, LightcapElement *le) { int last_sync_length = so->last_sync_length[ssn]; int32_t delta = le->timestamp - last_sync_time; // Handle time wrapping (be sure to be int32) - if (delta < -so->pulsedist_max_ticks || delta > so->pulsedist_max_ticks) { + if (delta < -PULSEDIST_MAX_TICKS || delta > PULSEDIST_MAX_TICKS) { // Reset pulse, etc. so->sync_set_number = -1; - delta = so->pulsedist_max_ticks; + delta = PULSEDIST_MAX_TICKS; // return; //if we don't know what lighthouse this is we don't care to do much else } - if (le->length > so->pulselength_min_sync) // Pulse longer indicates a sync pulse. + if (le->length > PULSELENGTH_MIN_SYNC) // Pulse longer indicates a sync pulse. { - int is_new_pulse = delta > so->pulselength_min_sync /*1500*/ + last_sync_length; + int is_new_pulse = delta > PULSELENGTH_MIN_SYNC /*1500*/ + last_sync_length; if (is_new_pulse) { - int is_master_sync_pulse = delta > so->pulse_in_clear_time /*40000*/; + int is_master_sync_pulse = delta > PULSE_IN_CLEAR_TIME /*40000*/; int is_pulse_from_same_lh_as_last_sweep; - int tp = delta % (so->timecenter_ticks * 2); - is_pulse_from_same_lh_as_last_sweep = tp < so->pulse_synctime_slack && tp > -so->pulse_synctime_slack; + int tp = delta % (TIMECENTER_TICKS * 2); + is_pulse_from_same_lh_as_last_sweep = tp < PULSE_SYNCTIME_SLACK && tp > -PULSE_SYNCTIME_SLACK; if (!so->did_handle_ootx) { HandleOOTX(ctx, so); @@ -161,7 +169,7 @@ void DisambiguatorCharles(SurviveObject *so, LightcapElement *le) { // Any else- statements below here are // See if this is a valid actual pulse. - else if (le->length < so->pulse_max_for_sweep && delta > so->pulse_in_clear_time && ssn >= 0) { + else if (le->length < PULSE_MAX_FOR_SWEEP && delta > PULSE_IN_CLEAR_TIME && ssn >= 0) { int32_t tpco = so->last_sync_length[0]; #if NUM_LIGHTHOUSES != 2 @@ -187,8 +195,8 @@ void DisambiguatorCharles(SurviveObject *so, LightcapElement *le) { int32_t offset_from = le->timestamp - dl + le->length / 2; // Make sure pulse is in valid window - if (offset_from < so->timecenter_ticks * 2 - so->pulse_in_clear_time && - offset_from > so->pulse_in_clear_time) { + if (offset_from < TIMECENTER_TICKS * 2 - PULSE_IN_CLEAR_TIME && + offset_from > PULSE_IN_CLEAR_TIME) { ctx->lightproc(so, le->sensor_id, acode, offset_from, le->timestamp, le->length, whichlh); } } diff --git a/src/survive_default_devices.c b/src/survive_default_devices.c index c24bb92..05dd10d 100644 --- a/src/survive_default_devices.c +++ b/src/survive_default_devices.c @@ -17,13 +17,6 @@ survive_create_device(SurviveContext *ctx, const char *driver_name, memcpy(device->drivername, driver_name, strlen(driver_name)); device->timebase_hz = 48000000; - device->pulsedist_max_ticks = 500000; - device->pulselength_min_sync = 2200; - device->pulse_in_clear_time = 35000; - device->pulse_max_for_sweep = 1800; - device->pulse_synctime_offset = 20000; - device->pulse_synctime_slack = 5000; - device->timecenter_ticks = device->timebase_hz / 240; device->imu_freq = 250.f; device->haptic = fn; diff --git a/src/survive_driver_dummy.c b/src/survive_driver_dummy.c index d940d21..ae3dd30 100644 --- a/src/survive_driver_dummy.c +++ b/src/survive_driver_dummy.c @@ -70,13 +70,6 @@ int DriverRegDummy(SurviveContext *ctx) memcpy(device->drivername, "DUM", 4); device->timebase_hz = 48000000; - device->pulsedist_max_ticks = 500000; - device->pulselength_min_sync = 2200; - device->pulse_in_clear_time = 35000; - device->pulse_max_for_sweep = 1800; - device->pulse_synctime_offset = 20000; - device->pulse_synctime_slack = 5000; - device->timecenter_ticks = device->timebase_hz / 240; device->imu_freq = 1000.0f; device->haptic = dummy_haptic; diff --git a/src/survive_process.c b/src/survive_process.c index abde02d..56e6420 100644 --- a/src/survive_process.c +++ b/src/survive_process.c @@ -9,6 +9,8 @@ //XXX TODO: Once data is avialble in the context, use the stuff here to handle converting from time codes to //proper angles, then from there perform the rest of the solution. +#define TIMECENTER_TICKS (48000000/240) //for now. + void survive_default_light_process( SurviveObject * so, int sensor_id, int acode, int timeinsweep, uint32_t timecode, uint32_t length, uint32_t lh) { SurviveContext * ctx = so->ctx; @@ -45,7 +47,7 @@ void survive_default_light_process( SurviveObject * so, int sensor_id, int acode //No loner need sync information past this point. if( sensor_id < 0 ) return; - FLT angle = (timeinsweep - so->timecenter_ticks) * (1./so->timecenter_ticks * 3.14159265359/2.0); + FLT angle = (timeinsweep - TIMECENTER_TICKS) * (1./TIMECENTER_TICKS * 3.14159265359/2.0); //Need to now do angle correction. static int use_bsd_cal = -1; -- cgit v1.2.3