From d5c42c4951261c401c5f9148ce2d6bb1402ce75b Mon Sep 17 00:00:00 2001 From: Justin Berger Date: Sat, 24 Mar 2018 10:13:23 -0600 Subject: Some minor fixups around command line processing --- include/libsurvive/survive.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/libsurvive/survive.h b/include/libsurvive/survive.h index 0b85bf3..b1c32cd 100644 --- a/include/libsurvive/survive.h +++ b/include/libsurvive/survive.h @@ -202,11 +202,18 @@ struct SurviveContext void survive_verify_FLT_size(uint32_t user_size); // Baked in size of FLT to verify users of the library have the correct setting. - - - - SurviveContext * survive_init_internal( int argc, char * const * argv ); + +/** + * Call survive_init to get a populated SurviveContext pointer. + * + * This also sets up a number of configuration values based on command line + * arguments. Pass 0, 0 to this function if you specifically do not want + * command line processing. + * + * Note that this function _can_ return null based on command line arguments, + * notably if -h was passed in. + */ static inline SurviveContext * survive_init( int argc, char * const * argv ) { survive_verify_FLT_size(sizeof(FLT)); -- cgit v1.2.3 From d9ecb4d321bfa04b5d67fb501be0cd9c46140775 Mon Sep 17 00:00:00 2001 From: Justin Berger Date: Sun, 25 Mar 2018 21:29:32 -0600 Subject: Added tool to calculate various things about length of received pulses --- include/libsurvive/survive.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/libsurvive/survive.h b/include/libsurvive/survive.h index b1c32cd..8a1474b 100644 --- a/include/libsurvive/survive.h +++ b/include/libsurvive/survive.h @@ -16,6 +16,7 @@ extern "C" { typedef struct { FLT angles[SENSORS_PER_OBJECT][NUM_LIGHTHOUSES][2]; // 2 Axes (Angles in LH space) uint32_t timecode[SENSORS_PER_OBJECT][NUM_LIGHTHOUSES][2]; // Timecode per axis in ticks + uint32_t lengths[SENSORS_PER_OBJECT][NUM_LIGHTHOUSES][2]; // Timecode per axis in ticks FLT accel[3]; FLT gyro[3]; -- cgit v1.2.3 From 91f0cab811e983da63ea49f6e24afae283138a1c Mon Sep 17 00:00:00 2001 From: Justin Berger Date: Wed, 28 Mar 2018 20:36:05 -0600 Subject: Functional C# in windows --- include/libsurvive/survive.h | 63 ++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 28 deletions(-) (limited to 'include') diff --git a/include/libsurvive/survive.h b/include/libsurvive/survive.h index 8a1474b..85078f7 100644 --- a/include/libsurvive/survive.h +++ b/include/libsurvive/survive.h @@ -10,6 +10,13 @@ extern "C" { #endif + +#ifdef _WIN32 +#define SURVIVE_EXPORT __declspec(dllexport) +#else +#define SURVIVE_EXPORT +#endif + /** * This struct encodes what the last effective angles seen on a sensor were, and when they occured. */ @@ -203,7 +210,7 @@ struct SurviveContext void survive_verify_FLT_size(uint32_t user_size); // Baked in size of FLT to verify users of the library have the correct setting. -SurviveContext * survive_init_internal( int argc, char * const * argv ); +SURVIVE_EXPORT SurviveContext * survive_init_internal( int argc, char * const * argv ); /** * Call survive_init to get a populated SurviveContext pointer. @@ -224,20 +231,20 @@ static inline SurviveContext * survive_init( int argc, char * const * argv ) //For any of these, you may pass in 0 for the function pointer to use default behavior. //In general unless you are doing wacky things like recording or playing back data, you won't need to use this. -void survive_install_htc_config_fn( SurviveContext *ctx, htc_config_func fbp ); -void survive_install_info_fn( SurviveContext * ctx, text_feedback_func fbp ); -void survive_install_error_fn( SurviveContext * ctx, text_feedback_func fbp ); -void survive_install_light_fn( SurviveContext * ctx, light_process_func fbp ); -void survive_install_imu_fn( SurviveContext * ctx, imu_process_func fbp ); -void survive_install_angle_fn( SurviveContext * ctx, angle_process_func fbp ); -void survive_install_button_fn(SurviveContext * ctx, button_process_func fbp); -void survive_install_raw_pose_fn(SurviveContext * ctx, raw_pose_func fbp); -void survive_install_lighthouse_pose_fn(SurviveContext *ctx, lighthouse_pose_func fbp); -int survive_startup( SurviveContext * ctx ); -int survive_poll( SurviveContext * ctx ); -void survive_close( SurviveContext * ctx ); - -SurviveObject * survive_get_so_by_name( SurviveContext * ctx, const char * name ); +SURVIVE_EXPORT void survive_install_htc_config_fn( SurviveContext *ctx, htc_config_func fbp ); +SURVIVE_EXPORT void survive_install_info_fn( SurviveContext * ctx, text_feedback_func fbp ); +SURVIVE_EXPORT void survive_install_error_fn( SurviveContext * ctx, text_feedback_func fbp ); +SURVIVE_EXPORT void survive_install_light_fn( SurviveContext * ctx, light_process_func fbp ); +SURVIVE_EXPORT void survive_install_imu_fn( SurviveContext * ctx, imu_process_func fbp ); +SURVIVE_EXPORT void survive_install_angle_fn( SurviveContext * ctx, angle_process_func fbp ); +SURVIVE_EXPORT void survive_install_button_fn(SurviveContext * ctx, button_process_func fbp); +SURVIVE_EXPORT void survive_install_raw_pose_fn(SurviveContext * ctx, raw_pose_func fbp); +SURVIVE_EXPORT void survive_install_lighthouse_pose_fn(SurviveContext *ctx, lighthouse_pose_func fbp); +SURVIVE_EXPORT int survive_startup( SurviveContext * ctx ); +SURVIVE_EXPORT int survive_poll( SurviveContext * ctx ); +SURVIVE_EXPORT void survive_close( SurviveContext * ctx ); + +SURVIVE_EXPORT SurviveObject * survive_get_so_by_name( SurviveContext * ctx, const char * name ); //Utilitiy functions. int survive_simple_inflate( SurviveContext * ctx, const char * input, int inlen, char * output, int outlen ); @@ -249,30 +256,30 @@ int survive_send_magic( SurviveContext * ctx, int magic_code, void * data, int d #define SC_OVERRIDE 2 //Set, to new default value. #define SC_SETCONFIG 4 //Set, both in-memory and config file. Use in conjunction with SC_OVERRIDE. -FLT survive_configf( SurviveContext * ctx, const char *tag, char flags, FLT def ); -uint32_t survive_configi( SurviveContext * ctx, const char *tag, char flags, uint32_t def ); -const char * survive_configs( SurviveContext * ctx, const char *tag, char flags, const char *def ); +SURVIVE_EXPORT FLT survive_configf( SurviveContext * ctx, const char *tag, char flags, FLT def ); +SURVIVE_EXPORT uint32_t survive_configi( SurviveContext * ctx, const char *tag, char flags, uint32_t def ); +SURVIVE_EXPORT const char * survive_configs( SurviveContext * ctx, const char *tag, char flags, const char *def ); //Install the calibrator. -void survive_cal_install( SurviveContext * ctx ); //XXX This will be removed if not already done so. +SURVIVE_EXPORT void survive_cal_install( SurviveContext * ctx ); //XXX This will be removed if not already done so. // Read back a human-readable string description of the calibration status -int survive_cal_get_status( SurviveContext * ctx, char * description, int description_length ); +SURVIVE_EXPORT int survive_cal_get_status( SurviveContext * ctx, char * description, int description_length ); // Induce haptic feedback -int survive_haptic(SurviveObject * so, uint8_t reserved, uint16_t pulseHigh, uint16_t pulseLow, uint16_t repeatCount); +SURVIVE_EXPORT int survive_haptic(SurviveObject * so, uint8_t reserved, uint16_t pulseHigh, uint16_t pulseLow, uint16_t repeatCount); //Call these from your callback if overridden. //Accept higher-level data. -void survive_default_light_process( SurviveObject * so, int sensor_id, int acode, int timeinsweep, uint32_t timecode, uint32_t length , uint32_t lh); -void survive_default_imu_process( SurviveObject * so, int mode, FLT * accelgyro, uint32_t timecode, int id ); -void survive_default_angle_process( SurviveObject * so, int sensor_id, int acode, uint32_t timecode, FLT length, FLT angle, uint32_t lh ); -void survive_default_button_process(SurviveObject * so, uint8_t eventType, uint8_t buttonId, uint8_t axis1Id, uint16_t axis1Val, uint8_t axis2Id, uint16_t axis2Val); -void survive_default_raw_pose_process(SurviveObject *so, uint8_t lighthouse, SurvivePose *pose); -void survive_default_lighthouse_pose_process(SurviveContext *ctx, uint8_t lighthouse, SurvivePose *lh_pose, +SURVIVE_EXPORT void survive_default_light_process( SurviveObject * so, int sensor_id, int acode, int timeinsweep, uint32_t timecode, uint32_t length , uint32_t lh); +SURVIVE_EXPORT void survive_default_imu_process( SurviveObject * so, int mode, FLT * accelgyro, uint32_t timecode, int id ); +SURVIVE_EXPORT void survive_default_angle_process( SurviveObject * so, int sensor_id, int acode, uint32_t timecode, FLT length, FLT angle, uint32_t lh ); +SURVIVE_EXPORT void survive_default_button_process(SurviveObject * so, uint8_t eventType, uint8_t buttonId, uint8_t axis1Id, uint16_t axis1Val, uint8_t axis2Id, uint16_t axis2Val); +SURVIVE_EXPORT void survive_default_raw_pose_process(SurviveObject *so, uint8_t lighthouse, SurvivePose *pose); +SURVIVE_EXPORT void survive_default_lighthouse_pose_process(SurviveContext *ctx, uint8_t lighthouse, SurvivePose *lh_pose, SurvivePose *obj_pose); -int survive_default_htc_config_process(SurviveObject *so, char *ct0conf, int len); +SURVIVE_EXPORT int survive_default_htc_config_process(SurviveObject *so, char *ct0conf, int len); -- cgit v1.2.3 From 4856dd8d4121f23750baace5fd8bd81869f5ac81 Mon Sep 17 00:00:00 2001 From: Justin Berger Date: Thu, 29 Mar 2018 00:17:07 -0600 Subject: Filled out OO struct; most needed functions are there --- include/libsurvive/survive_types.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'include') diff --git a/include/libsurvive/survive_types.h b/include/libsurvive/survive_types.h index 160adda..7a7dbf1 100644 --- a/include/libsurvive/survive_types.h +++ b/include/libsurvive/survive_types.h @@ -50,8 +50,7 @@ typedef void (*imu_process_func)( SurviveObject * so, int mask, FLT * accelgyro, typedef void (*angle_process_func)( SurviveObject * so, int sensor_id, int acode, uint32_t timecode, FLT length, FLT angle, uint32_t lh); typedef void(*button_process_func)(SurviveObject * so, uint8_t eventType, uint8_t buttonId, uint8_t axis1Id, uint16_t axis1Val, uint8_t axis2Id, uint16_t axis2Val); typedef void (*raw_pose_func)(SurviveObject *so, uint8_t lighthouse, SurvivePose *pose); -typedef void (*lighthouse_pose_func)(SurviveContext *ctx, uint8_t lighthouse, SurvivePose *lighthouse_pose, - SurvivePose *object_pose); +typedef void (*lighthouse_pose_func)(SurviveContext *ctx, uint8_t lighthouse, SurvivePose *lighthouse_pose, SurvivePose *object_pose); // For lightcap, etc. Don't change this structure at all. Regular vive is dependent on it being exactly as-is. // When you write drivers, you can use this to send survive lightcap data. -- cgit v1.2.3 From 52bcccaea5de63a4de4b3df17236507455776409 Mon Sep 17 00:00:00 2001 From: Justin Berger Date: Fri, 30 Mar 2018 09:50:24 -0600 Subject: Added accessors for language bindings --- include/libsurvive/survive.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include') diff --git a/include/libsurvive/survive.h b/include/libsurvive/survive.h index 85078f7..ed43ddc 100644 --- a/include/libsurvive/survive.h +++ b/include/libsurvive/survive.h @@ -119,6 +119,11 @@ struct SurviveObject int tsl; }; +// These exports are mostly for language binding against +SURVIVE_EXPORT const char *survive_object_codename(SurviveObject *so); +SURVIVE_EXPORT int8_t survive_object_sensor_ct(SurviveObject *so); +SURVIVE_EXPORT const FLT *survive_object_sensor_locations(SurviveObject *so); +SURVIVE_EXPORT const FLT *survive_object_sensor_normals(SurviveObject *so); struct BaseStationData { -- cgit v1.2.3 From 22d40fb360fdb65da7916fb87f9b199f4f401f05 Mon Sep 17 00:00:00 2001 From: Justin Berger Date: Sun, 1 Apr 2018 07:52:00 -0600 Subject: overhal to calibration --- include/libsurvive/survive.h | 308 ++++++++++++++++++--------------- include/libsurvive/survive_reproject.h | 35 ++-- 2 files changed, 188 insertions(+), 155 deletions(-) (limited to 'include') diff --git a/include/libsurvive/survive.h b/include/libsurvive/survive.h index ed43ddc..e435752 100644 --- a/include/libsurvive/survive.h +++ b/include/libsurvive/survive.h @@ -10,11 +10,10 @@ extern "C" { #endif - #ifdef _WIN32 #define SURVIVE_EXPORT __declspec(dllexport) #else -#define SURVIVE_EXPORT +#define SURVIVE_EXPORT __attribute__((visibility("default"))) #endif /** @@ -32,6 +31,7 @@ typedef struct { struct PoserDataLight; struct PoserDataIMU; + /** * Adds a lightData packet to the table. */ @@ -53,69 +53,68 @@ bool SurviveSensorActivations_isPairValid(const SurviveSensorActivations *self, */ extern uint32_t SurviveSensorActivations_default_tolerance; -//DANGER: This structure may be redefined. Note that it is logically split into 64-bit chunks -//for optimization on 32- and 64-bit systems. +// DANGER: This structure may be redefined. Note that it is logically split into 64-bit chunks +// for optimization on 32- and 64-bit systems. -struct SurviveObject -{ - SurviveContext * ctx; +struct SurviveObject { + SurviveContext *ctx; - char codename[4]; //3 letters, null-terminated. Currently HMD, WM0, WM1. - char drivername[4]; //3 letters for driver. Currently "HTC" - void *driver; + char codename[4]; // 3 letters, null-terminated. Currently HMD, WM0, WM1. + char drivername[4]; // 3 letters for driver. Currently "HTC" + void *driver; int32_t buttonmask; int16_t axis1; int16_t axis2; int16_t axis3; - int8_t charge; - int8_t charging:1; - int8_t ison:1; - int8_t additional_flags:6; - - //Pose Information, also "poser" field. - FLT PoseConfidence; //0..1 - SurvivePose OutPose; //Final pose? (some day, one can dream!) - SurvivePose FromLHPose[NUM_LIGHTHOUSES]; //Filled out by poser, contains computed position from each lighthouse. - void * PoserData; //Initialized to zero, configured by poser, can be anything the poser wants. + int8_t charge; + int8_t charging : 1; + int8_t ison : 1; + int8_t additional_flags : 6; + + // Pose Information, also "poser" field. + FLT PoseConfidence; // 0..1 + SurvivePose OutPose; // Final pose? (some day, one can dream!) + SurvivePose FromLHPose[NUM_LIGHTHOUSES]; // Filled out by poser, contains computed position from each lighthouse. + void *PoserData; // Initialized to zero, configured by poser, can be anything the poser wants. PoserCB PoserFn; - //Device-specific information about the location of the sensors. This data will be used by the poser. - int8_t sensor_ct; // sensor count - FLT * sensor_locations; // size is sensor_ct*3. Contains x,y,z values for each sensor - FLT * sensor_normals;// size is nrlocations*3. cointains normal vector for each sensor - - //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; - int8_t oldcode; - int8_t sync_set_number; //0 = master, 1 = slave, -1 = fault. - int8_t did_handle_ootx; //If unset, will send lightcap data for sync pulses next time a sensor is hit. + // Device-specific information about the location of the sensors. This data will be used by the poser. + int8_t sensor_ct; // sensor count + FLT *sensor_locations; // size is sensor_ct*3. Contains x,y,z values for each sensor + FLT *sensor_normals; // size is nrlocations*3. cointains normal vector for each sensor + + // 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; + int8_t oldcode; + int8_t sync_set_number; // 0 = master, 1 = slave, -1 = fault. + int8_t did_handle_ootx; // If unset, will send lightcap data for sync pulses next time a sensor is hit. uint32_t last_sync_time[NUM_LIGHTHOUSES]; uint32_t last_sync_length[NUM_LIGHTHOUSES]; uint32_t recent_sync_time; - uint32_t last_lighttime; //May be a 24- or 32- bit number depending on what device. - + uint32_t last_lighttime; // May be a 24- or 32- bit number depending on what device. - FLT* acc_bias; // size is FLT*3. contains x,y,z - FLT* acc_scale; // size is FLT*3. contains x,y,z - FLT* gyro_bias; // size is FLT*3. contains x,y,z - FLT* gyro_scale; // size is FLT*3. contains x,y,z + FLT *acc_bias; // size is FLT*3. contains x,y,z + FLT *acc_scale; // size is FLT*3. contains x,y,z + FLT *gyro_bias; // size is FLT*3. contains x,y,z + FLT *gyro_scale; // size is FLT*3. contains x,y,z haptic_func haptic; SurviveSensorActivations activations; - //Debug + // Debug int tsl; }; @@ -125,34 +124,37 @@ SURVIVE_EXPORT int8_t survive_object_sensor_ct(SurviveObject *so); SURVIVE_EXPORT const FLT *survive_object_sensor_locations(SurviveObject *so); SURVIVE_EXPORT const FLT *survive_object_sensor_normals(SurviveObject *so); -struct BaseStationData -{ - uint8_t PositionSet:1; +typedef struct BaseStationCal { + FLT phase[2]; + FLT tilt[2]; + FLT curve[2]; + FLT gibpha[2]; + FLT gibmag[2]; +} BaseStationCal; + +struct BaseStationData { + uint8_t PositionSet : 1; SurvivePose Pose; - uint8_t OOTXSet:1; + uint8_t OOTXSet : 1; uint32_t BaseStationID; - FLT fcalphase[2]; - FLT fcaltilt[2]; - FLT fcalcurve[2]; - FLT fcalgibpha[2]; - FLT fcalgibmag[2]; - int8_t accel[3]; //"Up" vector + + BaseStationCal fcal; + + int8_t accel[3]; //"Up" vector + uint8_t mode; }; struct config_group; #define BUTTON_QUEUE_MAX_LEN 32 - - // note: buttonId and axisId are 1-indexed values. // a value of 0 for an id means that no data is present in that value // additionally, when x and y values are both present in axis data, // axis1 will be x, axis2 will be y. -typedef struct -{ - uint8_t isPopulated; //probably can remove this given the semaphore in the parent struct. helps with debugging +typedef struct { + uint8_t isPopulated; // probably can remove this given the semaphore in the parent struct. helps with debugging uint8_t eventType; uint8_t buttonId; uint8_t axis1Id; @@ -162,20 +164,28 @@ typedef struct SurviveObject *so; } ButtonQueueEntry; -typedef struct -{ - uint8_t nextReadIndex; //init to 0 +typedef struct { + uint8_t nextReadIndex; // init to 0 uint8_t nextWriteIndex; // init to 0 - void* buttonservicesem; + void *buttonservicesem; ButtonQueueEntry entry[BUTTON_QUEUE_MAX_LEN]; } ButtonQueue; typedef enum { SURVIVE_STOPPED = 0, SURVIVE_RUNNING, SURVIVE_CLOSING, SURVIVE_STATE_MAX } SurviveState; struct SurviveRecordingData; +struct survive_calibration_config; + +enum SurviveCalFlag { + SVCal_None = 0, + SVCal_Phase = 1, + SVCal_Tilt = 2, + SVCal_Curve = 4, + SVCal_Gib = 8, + SVCal_All = SVCal_Gib | SVCal_Curve | SVCal_Tilt | SVCal_Phase +}; -struct SurviveContext -{ +struct SurviveContext { text_feedback_func faultfunction; text_feedback_func notefunction; light_process_func lightproc; @@ -187,35 +197,39 @@ struct SurviveContext htc_config_func configfunction; handle_lightcap_func lightcapfunction; - struct config_group* global_config_values; - struct config_group* lh_config; //lighthouse configs - struct config_group* temporary_config_values; //Set per-session, from command-line. Not saved but override global_config_values + struct config_group *global_config_values; + struct config_group *lh_config; // lighthouse configs + struct config_group + *temporary_config_values; // Set per-session, from command-line. Not saved but override global_config_values - //Calibration data: + // Calibration data: int activeLighthouses; BaseStationData bsd[NUM_LIGHTHOUSES]; - SurviveCalData * calptr; //If and only if the calibration subsystem is attached. + SurviveCalData *calptr; // If and only if the calibration subsystem is attached. struct SurviveRecordingData *recptr; // Iff recording is attached - SurviveObject ** objs; + SurviveObject **objs; int objs_ct; - void ** drivers; - DeviceDriverCb * driverpolls; - DeviceDriverCb * drivercloses; - DeviceDriverMagicCb * drivermagics; + void **drivers; + DeviceDriverCb *driverpolls; + DeviceDriverCb *drivercloses; + DeviceDriverMagicCb *drivermagics; int driver_ct; SurviveState state; - void* buttonservicethread; + void *buttonservicethread; ButtonQueue buttonQueue; void *user_ptr; + enum SurviveCalFlag calibration_flag; + struct survive_calibration_config *calibration_config; }; -void survive_verify_FLT_size(uint32_t user_size); // Baked in size of FLT to verify users of the library have the correct setting. +void survive_verify_FLT_size( + uint32_t user_size); // Baked in size of FLT to verify users of the library have the correct setting. -SURVIVE_EXPORT SurviveContext * survive_init_internal( int argc, char * const * argv ); +SURVIVE_EXPORT SurviveContext *survive_init_internal(int argc, char *const *argv); /** * Call survive_init to get a populated SurviveContext pointer. @@ -227,98 +241,106 @@ SURVIVE_EXPORT SurviveContext * survive_init_internal( int argc, char * const * * Note that this function _can_ return null based on command line arguments, * notably if -h was passed in. */ -static inline SurviveContext * survive_init( int argc, char * const * argv ) -{ +static inline SurviveContext *survive_init(int argc, char *const *argv) { survive_verify_FLT_size(sizeof(FLT)); return survive_init_internal(argc, argv); } - -//For any of these, you may pass in 0 for the function pointer to use default behavior. -//In general unless you are doing wacky things like recording or playing back data, you won't need to use this. -SURVIVE_EXPORT void survive_install_htc_config_fn( SurviveContext *ctx, htc_config_func fbp ); -SURVIVE_EXPORT void survive_install_info_fn( SurviveContext * ctx, text_feedback_func fbp ); -SURVIVE_EXPORT void survive_install_error_fn( SurviveContext * ctx, text_feedback_func fbp ); -SURVIVE_EXPORT void survive_install_light_fn( SurviveContext * ctx, light_process_func fbp ); -SURVIVE_EXPORT void survive_install_imu_fn( SurviveContext * ctx, imu_process_func fbp ); -SURVIVE_EXPORT void survive_install_angle_fn( SurviveContext * ctx, angle_process_func fbp ); -SURVIVE_EXPORT void survive_install_button_fn(SurviveContext * ctx, button_process_func fbp); -SURVIVE_EXPORT void survive_install_raw_pose_fn(SurviveContext * ctx, raw_pose_func fbp); +// For any of these, you may pass in 0 for the function pointer to use default behavior. +// In general unless you are doing wacky things like recording or playing back data, you won't need to use this. +SURVIVE_EXPORT void survive_install_htc_config_fn(SurviveContext *ctx, htc_config_func fbp); +SURVIVE_EXPORT void survive_install_info_fn(SurviveContext *ctx, text_feedback_func fbp); +SURVIVE_EXPORT void survive_install_error_fn(SurviveContext *ctx, text_feedback_func fbp); +SURVIVE_EXPORT void survive_install_light_fn(SurviveContext *ctx, light_process_func fbp); +SURVIVE_EXPORT void survive_install_imu_fn(SurviveContext *ctx, imu_process_func fbp); +SURVIVE_EXPORT void survive_install_angle_fn(SurviveContext *ctx, angle_process_func fbp); +SURVIVE_EXPORT void survive_install_button_fn(SurviveContext *ctx, button_process_func fbp); +SURVIVE_EXPORT void survive_install_raw_pose_fn(SurviveContext *ctx, raw_pose_func fbp); SURVIVE_EXPORT void survive_install_lighthouse_pose_fn(SurviveContext *ctx, lighthouse_pose_func fbp); -SURVIVE_EXPORT int survive_startup( SurviveContext * ctx ); -SURVIVE_EXPORT int survive_poll( SurviveContext * ctx ); -SURVIVE_EXPORT void survive_close( SurviveContext * ctx ); - -SURVIVE_EXPORT SurviveObject * survive_get_so_by_name( SurviveContext * ctx, const char * name ); +SURVIVE_EXPORT int survive_startup(SurviveContext *ctx); +SURVIVE_EXPORT int survive_poll(SurviveContext *ctx); +SURVIVE_EXPORT void survive_close(SurviveContext *ctx); -//Utilitiy functions. -int survive_simple_inflate( SurviveContext * ctx, const char * input, int inlen, char * output, int outlen ); -int survive_send_magic( SurviveContext * ctx, int magic_code, void * data, int datalen ); +SURVIVE_EXPORT SurviveObject *survive_get_so_by_name(SurviveContext *ctx, const char *name); -//These functions search both the stored-general and temporary sections for a parameter and return it. -#define SC_GET 0 //Get, only. -#define SC_SET 1 //Set, if not present -#define SC_OVERRIDE 2 //Set, to new default value. -#define SC_SETCONFIG 4 //Set, both in-memory and config file. Use in conjunction with SC_OVERRIDE. +// Utilitiy functions. +int survive_simple_inflate(SurviveContext *ctx, const char *input, int inlen, char *output, int outlen); +int survive_send_magic(SurviveContext *ctx, int magic_code, void *data, int datalen); -SURVIVE_EXPORT FLT survive_configf( SurviveContext * ctx, const char *tag, char flags, FLT def ); -SURVIVE_EXPORT uint32_t survive_configi( SurviveContext * ctx, const char *tag, char flags, uint32_t def ); -SURVIVE_EXPORT const char * survive_configs( SurviveContext * ctx, const char *tag, char flags, const char *def ); +// These functions search both the stored-general and temporary sections for a parameter and return it. +#define SC_GET 0 // Get, only. +#define SC_SET 1 // Set, if not present +#define SC_OVERRIDE 2 // Set, to new default value. +#define SC_SETCONFIG 4 // Set, both in-memory and config file. Use in conjunction with SC_OVERRIDE. +SURVIVE_EXPORT FLT survive_configf(SurviveContext *ctx, const char *tag, char flags, FLT def); +SURVIVE_EXPORT uint32_t survive_configi(SurviveContext *ctx, const char *tag, char flags, uint32_t def); +SURVIVE_EXPORT const char *survive_configs(SurviveContext *ctx, const char *tag, char flags, const char *def); -//Install the calibrator. -SURVIVE_EXPORT void survive_cal_install( SurviveContext * ctx ); //XXX This will be removed if not already done so. +// Install the calibrator. +SURVIVE_EXPORT void survive_cal_install(SurviveContext *ctx); // XXX This will be removed if not already done so. // Read back a human-readable string description of the calibration status -SURVIVE_EXPORT int survive_cal_get_status( SurviveContext * ctx, char * description, int description_length ); +SURVIVE_EXPORT int survive_cal_get_status(SurviveContext *ctx, char *description, int description_length); // Induce haptic feedback -SURVIVE_EXPORT int survive_haptic(SurviveObject * so, uint8_t reserved, uint16_t pulseHigh, uint16_t pulseLow, uint16_t repeatCount); - -//Call these from your callback if overridden. -//Accept higher-level data. -SURVIVE_EXPORT void survive_default_light_process( SurviveObject * so, int sensor_id, int acode, int timeinsweep, uint32_t timecode, uint32_t length , uint32_t lh); -SURVIVE_EXPORT void survive_default_imu_process( SurviveObject * so, int mode, FLT * accelgyro, uint32_t timecode, int id ); -SURVIVE_EXPORT void survive_default_angle_process( SurviveObject * so, int sensor_id, int acode, uint32_t timecode, FLT length, FLT angle, uint32_t lh ); -SURVIVE_EXPORT void survive_default_button_process(SurviveObject * so, uint8_t eventType, uint8_t buttonId, uint8_t axis1Id, uint16_t axis1Val, uint8_t axis2Id, uint16_t axis2Val); +SURVIVE_EXPORT int survive_haptic(SurviveObject *so, uint8_t reserved, uint16_t pulseHigh, uint16_t pulseLow, + uint16_t repeatCount); + +// Call these from your callback if overridden. +// Accept higher-level data. +SURVIVE_EXPORT void survive_default_light_process(SurviveObject *so, int sensor_id, int acode, int timeinsweep, + uint32_t timecode, uint32_t length, uint32_t lh); +SURVIVE_EXPORT void survive_default_imu_process(SurviveObject *so, int mode, FLT *accelgyro, uint32_t timecode, int id); +SURVIVE_EXPORT void survive_default_angle_process(SurviveObject *so, int sensor_id, int acode, uint32_t timecode, + FLT length, FLT angle, uint32_t lh); +SURVIVE_EXPORT void survive_default_button_process(SurviveObject *so, uint8_t eventType, uint8_t buttonId, + uint8_t axis1Id, uint16_t axis1Val, uint8_t axis2Id, + uint16_t axis2Val); SURVIVE_EXPORT void survive_default_raw_pose_process(SurviveObject *so, uint8_t lighthouse, SurvivePose *pose); -SURVIVE_EXPORT void survive_default_lighthouse_pose_process(SurviveContext *ctx, uint8_t lighthouse, SurvivePose *lh_pose, - SurvivePose *obj_pose); -SURVIVE_EXPORT int survive_default_htc_config_process(SurviveObject *so, char *ct0conf, int len); - - +SURVIVE_EXPORT void survive_default_lighthouse_pose_process(SurviveContext *ctx, uint8_t lighthouse, + SurvivePose *lh_pose, SurvivePose *obj_pose); +SURVIVE_EXPORT int survive_default_htc_config_process(SurviveObject *so, char *ct0conf, int len); ////////////////////// Survive Drivers //////////////////////////// -void RegisterDriver(const char * name, void * data); +void RegisterDriver(const char *name, void *data); #ifdef _MSC_VER -#define REGISTER_LINKTIME( func ) \ - __pragma(comment(linker,"/export:REGISTER"#func));\ +#define REGISTER_LINKTIME(func) \ + __pragma(comment(linker, "/export:REGISTER" #func)); \ void REGISTER##func() { RegisterDriver(#func, &func); } #else -#define REGISTER_LINKTIME( func ) \ +#define REGISTER_LINKTIME(func) \ void __attribute__((constructor)) REGISTER##func() { RegisterDriver(#func, &func); } #endif - - ///////////////////////// General stuff for writing drivers /////// -//For device drivers to call. This actually attaches them. -int survive_add_object( SurviveContext * ctx, SurviveObject * obj ); -void survive_add_driver( SurviveContext * ctx, void * payload, DeviceDriverCb poll, DeviceDriverCb close, DeviceDriverMagicCb magic ); - -//This is the disambiguator function, for taking light timing and figuring out place-in-sweep for a given photodiode. -void handle_lightcap( SurviveObject * so, LightcapElement * le ); - -#define SV_INFO( ... ) { char stbuff[1024]; sprintf( stbuff, __VA_ARGS__ ); ctx->notefunction( ctx, stbuff ); } -#define SV_ERROR( ... ) { char stbuff[1024]; sprintf( stbuff, __VA_ARGS__ ); ctx->faultfunction( ctx, stbuff ); } -#define SV_KILL() exit(0) //XXX This should likely be re-defined. +// For device drivers to call. This actually attaches them. +int survive_add_object(SurviveContext *ctx, SurviveObject *obj); +void survive_add_driver(SurviveContext *ctx, void *payload, DeviceDriverCb poll, DeviceDriverCb close, + DeviceDriverMagicCb magic); + +// This is the disambiguator function, for taking light timing and figuring out place-in-sweep for a given photodiode. +void handle_lightcap(SurviveObject *so, LightcapElement *le); + +#define SV_INFO(...) \ + { \ + char stbuff[1024]; \ + sprintf(stbuff, __VA_ARGS__); \ + ctx->notefunction(ctx, stbuff); \ + } +#define SV_ERROR(...) \ + { \ + char stbuff[1024]; \ + sprintf(stbuff, __VA_ARGS__); \ + ctx->faultfunction(ctx, stbuff); \ + } +#define SV_KILL() exit(0) // XXX This should likely be re-defined. #ifdef __cplusplus }; #endif #endif - diff --git a/include/libsurvive/survive_reproject.h b/include/libsurvive/survive_reproject.h index 961db2a..c90d39c 100644 --- a/include/libsurvive/survive_reproject.h +++ b/include/libsurvive/survive_reproject.h @@ -1,6 +1,8 @@ #pragma once + #include "survive.h" #include +#include #include #ifdef __cplusplus @@ -13,7 +15,7 @@ typedef struct { bool swap; } survive_calibration_options_config; -typedef struct { +typedef struct survive_calibration_config { survive_calibration_options_config phase, tilt, curve, gibMag, gibPhase; @@ -21,10 +23,10 @@ typedef struct { } survive_calibration_config; -void survive_calibration_options_config_apply( - const survive_calibration_options_config *option, const FLT *input, - FLT *output); -const survive_calibration_config *survive_calibration_default_config(); +void survive_calibration_options_config_apply(const survive_calibration_options_config *option, const FLT *input, + FLT *output); + +const survive_calibration_config *survive_calibration_default_config(const SurviveContext *ctx); size_t survive_calibration_config_max_idx(); @@ -32,10 +34,9 @@ survive_calibration_config survive_calibration_config_create_from_idx(size_t v); size_t survive_calibration_config_index(const survive_calibration_config *config); -void survive_reproject(const SurviveContext *ctx, int lighthouse, FLT *point3d, - FLT *out); -void survive_reproject_from_pose(const SurviveContext *ctx, int lighthouse, - const SurvivePose *pose, FLT *point3d, +void survive_reproject(const SurviveContext *ctx, int lighthouse, FLT *point3d, FLT *out); + +void survive_reproject_from_pose(const SurviveContext *ctx, int lighthouse, const SurvivePose *pose, FLT *point3d, FLT *out); // This is given a lighthouse -- in the same system as stored in BaseStationData, and @@ -44,9 +45,19 @@ void survive_reproject_from_pose(const SurviveContext *ctx, int lighthouse, // While this is typically opposite of what we want to do -- we want to find the 3d // position from a 2D coordinate, this is helpful since the minimization of reprojection // error is a core mechanism to many types of solvers. -void survive_reproject_from_pose_with_config( - const SurviveContext *ctx, const survive_calibration_config *config, - int lighthouse, const SurvivePose *pose, const FLT *point3d, FLT *out); +void survive_reproject_from_pose_with_config(const SurviveContext *ctx, const survive_calibration_config *config, + int lighthouse, const SurvivePose *pose, const FLT *point3d, FLT *out); + +void survive_reproject_from_pose_with_bsd(const BaseStationData *bsd, const survive_calibration_config *config, + const SurvivePose *pose, const FLT *point3d, FLT *out); + +void survive_reproject_with_config(const SurviveContext *ctx, const survive_calibration_config *config, int lighthouse, + const FLT *point3d, FLT *out); + +void survive_calibration_config_fprint(FILE *file, const survive_calibration_config *config); + +void survive_apply_bsd_calibration_by_flag(SurviveContext *ctx, int lh, enum SurviveCalFlag f, const FLT *in, FLT *out); +void survive_apply_bsd_calibration(SurviveContext *ctx, int lh, const FLT *in, FLT *out); #ifdef __cplusplus } -- cgit v1.2.3 From 47c7fb15182700fb403894f65beaf143a7fad6ab Mon Sep 17 00:00:00 2001 From: Justin Berger Date: Sun, 1 Apr 2018 12:23:48 -0600 Subject: Tweaked how reproject / calibate interact --- include/libsurvive/survive.h | 10 +++++++-- include/libsurvive/survive_reproject.h | 37 ++++------------------------------ 2 files changed, 12 insertions(+), 35 deletions(-) (limited to 'include') diff --git a/include/libsurvive/survive.h b/include/libsurvive/survive.h index e435752..669821d 100644 --- a/include/libsurvive/survive.h +++ b/include/libsurvive/survive.h @@ -185,6 +185,13 @@ enum SurviveCalFlag { SVCal_All = SVCal_Gib | SVCal_Curve | SVCal_Tilt | SVCal_Phase }; +typedef struct survive_calibration_config { + enum SurviveCalFlag use_flag; + FLT phase_scale, tilt_scale, curve_scale, gib_scale; +} survive_calibration_config; + +survive_calibration_config survive_calibration_config_ctor(); + struct SurviveContext { text_feedback_func faultfunction; text_feedback_func notefunction; @@ -222,8 +229,7 @@ struct SurviveContext { ButtonQueue buttonQueue; void *user_ptr; - enum SurviveCalFlag calibration_flag; - struct survive_calibration_config *calibration_config; + struct survive_calibration_config calibration_config; }; void survive_verify_FLT_size( diff --git a/include/libsurvive/survive_reproject.h b/include/libsurvive/survive_reproject.h index c90d39c..6546e66 100644 --- a/include/libsurvive/survive_reproject.h +++ b/include/libsurvive/survive_reproject.h @@ -9,35 +9,12 @@ extern "C" { #endif -typedef struct { - bool enable[2]; - bool invert[2]; - bool swap; -} survive_calibration_options_config; - -typedef struct survive_calibration_config { - - survive_calibration_options_config phase, tilt, curve, gibMag, gibPhase; - - bool gibUseSin; - -} survive_calibration_config; - -void survive_calibration_options_config_apply(const survive_calibration_options_config *option, const FLT *input, - FLT *output); - -const survive_calibration_config *survive_calibration_default_config(const SurviveContext *ctx); - -size_t survive_calibration_config_max_idx(); - -survive_calibration_config survive_calibration_config_create_from_idx(size_t v); - -size_t survive_calibration_config_index(const survive_calibration_config *config); - void survive_reproject(const SurviveContext *ctx, int lighthouse, FLT *point3d, FLT *out); void survive_reproject_from_pose(const SurviveContext *ctx, int lighthouse, const SurvivePose *pose, FLT *point3d, FLT *out); +void survive_reproject_from_pose_with_config(const SurviveContext *ctx, struct survive_calibration_config *config, + int lighthouse, const SurvivePose *pose, FLT *point3d, FLT *out); // This is given a lighthouse -- in the same system as stored in BaseStationData, and // a 3d point and finds what the effective 'angle' value for a given lighthouse syste @@ -45,18 +22,12 @@ void survive_reproject_from_pose(const SurviveContext *ctx, int lighthouse, cons // While this is typically opposite of what we want to do -- we want to find the 3d // position from a 2D coordinate, this is helpful since the minimization of reprojection // error is a core mechanism to many types of solvers. -void survive_reproject_from_pose_with_config(const SurviveContext *ctx, const survive_calibration_config *config, - int lighthouse, const SurvivePose *pose, const FLT *point3d, FLT *out); void survive_reproject_from_pose_with_bsd(const BaseStationData *bsd, const survive_calibration_config *config, const SurvivePose *pose, const FLT *point3d, FLT *out); -void survive_reproject_with_config(const SurviveContext *ctx, const survive_calibration_config *config, int lighthouse, - const FLT *point3d, FLT *out); - -void survive_calibration_config_fprint(FILE *file, const survive_calibration_config *config); - -void survive_apply_bsd_calibration_by_flag(SurviveContext *ctx, int lh, enum SurviveCalFlag f, const FLT *in, FLT *out); +void survive_apply_bsd_calibration_by_flag(SurviveContext *ctx, int lh, struct survive_calibration_config *config, + const FLT *in, FLT *out); void survive_apply_bsd_calibration(SurviveContext *ctx, int lh, const FLT *in, FLT *out); #ifdef __cplusplus -- cgit v1.2.3 From aea08a70a033cc0aef0998267fadb54af5fb2c69 Mon Sep 17 00:00:00 2001 From: Justin Berger Date: Sun, 1 Apr 2018 15:37:16 -0600 Subject: More optimization of scale params for calibration --- include/libsurvive/survive.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/libsurvive/survive.h b/include/libsurvive/survive.h index 669821d..7248b1c 100644 --- a/include/libsurvive/survive.h +++ b/include/libsurvive/survive.h @@ -186,8 +186,8 @@ enum SurviveCalFlag { }; typedef struct survive_calibration_config { - enum SurviveCalFlag use_flag; FLT phase_scale, tilt_scale, curve_scale, gib_scale; + enum SurviveCalFlag use_flag; } survive_calibration_config; survive_calibration_config survive_calibration_config_ctor(); -- cgit v1.2.3 From 1724abef15a4090640bd82ba408681438316de7e Mon Sep 17 00:00:00 2001 From: Justin Berger Date: Sun, 1 Apr 2018 16:04:05 -0600 Subject: Made calibration on other posers use calibration data --- include/libsurvive/survive_reproject.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/libsurvive/survive_reproject.h b/include/libsurvive/survive_reproject.h index 6546e66..e4f21d0 100644 --- a/include/libsurvive/survive_reproject.h +++ b/include/libsurvive/survive_reproject.h @@ -17,8 +17,9 @@ void survive_reproject_from_pose_with_config(const SurviveContext *ctx, struct s int lighthouse, const SurvivePose *pose, FLT *point3d, FLT *out); // This is given a lighthouse -- in the same system as stored in BaseStationData, and -// a 3d point and finds what the effective 'angle' value for a given lighthouse syste +// a 3d point and finds what the effective 'angle' value for a given lighthouse system // would be. +// // While this is typically opposite of what we want to do -- we want to find the 3d // position from a 2D coordinate, this is helpful since the minimization of reprojection // error is a core mechanism to many types of solvers. @@ -26,10 +27,17 @@ void survive_reproject_from_pose_with_config(const SurviveContext *ctx, struct s void survive_reproject_from_pose_with_bsd(const BaseStationData *bsd, const survive_calibration_config *config, const SurvivePose *pose, const FLT *point3d, FLT *out); -void survive_apply_bsd_calibration_by_flag(SurviveContext *ctx, int lh, struct survive_calibration_config *config, - const FLT *in, FLT *out); +// This is given input from the light sensors and approximates the idealized version of them +// by incorporating the calibration data from the lighthouse. In theory, it's an approximation +// but in practice in converges pretty quickly and to a good degree of accuracy. +// That said, all things being equal, it is better to compare reprojection to raw incoming +// data if you are looking to minimize that error. void survive_apply_bsd_calibration(SurviveContext *ctx, int lh, const FLT *in, FLT *out); +// Same as above, but lets you specify the configuration. Used internally and also in some tools +void survive_apply_bsd_calibration_by_config(SurviveContext *ctx, int lh, struct survive_calibration_config *config, + const FLT *in, FLT *out); + #ifdef __cplusplus } #endif -- cgit v1.2.3