diff --git a/src/xrt/drivers/north_star/ns_hmd.c b/src/xrt/drivers/north_star/ns_hmd.c index 982911247..497e454ca 100644 --- a/src/xrt/drivers/north_star/ns_hmd.c +++ b/src/xrt/drivers/north_star/ns_hmd.c @@ -33,7 +33,7 @@ #include "../realsense/rs_interface.h" #endif -DEBUG_GET_ONCE_LOG_OPTION(ns_log, "NS_LOG", U_LOGGING_WARN) +DEBUG_GET_ONCE_LOG_OPTION(ns_log, "NS_LOG", U_LOGGING_INFO) /* * @@ -41,6 +41,12 @@ DEBUG_GET_ONCE_LOG_OPTION(ns_log, "NS_LOG", U_LOGGING_WARN) * */ + +static double map(double value, double fromLow, double fromHigh, double toLow, double toHigh) { + return (value - fromLow) * (toHigh - toLow) / (fromHigh - fromLow) + toLow; +} // Math copied from https://www.arduino.cc/reference/en/language/functions/math/map/ +// This is pure math so it is still under the Boost Software License. + static void ns_hmd_destroy(struct xrt_device *xdev) { @@ -224,14 +230,15 @@ ns_fov_calculate(struct xrt_fov *fov, struct xrt_quat projection) fov->angle_left = projection.z; // atanf(fabsf(projection.z) / near_plane); fov->angle_right = - projection.w; // atanf(fabsf(projection.w) / near_plane); + projection.w; // atanf(fabsf(projection.w) / near_plane); } /* - * + * * V2 optics. - * - */ + * + * + */ static void @@ -305,8 +312,15 @@ ns_v2_mesh_calc(struct xrt_device *xdev, float v, struct xrt_uv_triplet *result) { - u = 1.0 - u; // Not sure why these are necessary: somewhat concerning. - v = 1.0 - v; // They make it work though, so hey. + /*! @todo (Moses Turner) It should not be necessary to reverse the U and V coords. + * I have no idea why it is like this. It shouldn't be like this. + * It must be something wrong with the undistortion calibrator. + * The V2 undistortion calibrator software is here if you want to look: + * https://github.com/BryanChrisBrown/ProjectNorthStar/tree/feat-gen-2-software/Software/North%20Star%20Gen%202/North%20Star%20Calibrator + */ + //u = 1.0 - u; + v = 1.0 - v; + struct ns_hmd *ns = ns_hmd(xdev); @@ -321,20 +335,9 @@ ns_v2_mesh_calc(struct xrt_device *xdev, float up_ray_bound = tan(ns->eye_configs_v2[view].fov.angle_up); float down_ray_bound = tan(ns->eye_configs_v2[view].fov.angle_down); + float u_eye = map(x_ray, left_ray_bound, right_ray_bound, 0, 1); - - // Both of these are very concise implementations of map() in Arduino. - // https://www.arduino.cc/reference/en/language/functions/math/map/ - // In other words, a one-axis linear transformation. - // I wish I was better at linear algebra so I had could describe this - // better - - // map(x_ray, left_ray_bound, right_ray_bound, 0, 1) - float u_eye = - (x_ray + right_ray_bound) / (right_ray_bound - left_ray_bound); - - // map(y_ray, down_ray_bound, up_ray_bound, 0, 1) - float v_eye = (y_ray + up_ray_bound) / (up_ray_bound - down_ray_bound); + float v_eye = map(y_ray, down_ray_bound, up_ray_bound, 0, 1); // boilerplate, put the UV coordinates in all the RGB slots @@ -404,6 +407,9 @@ ns_config_load(struct ns_hmd *ns) cJSON_GetObjectItemCaseSensitive(config_json, "baseline"), &ns->ipd); ns->ipd = ns->ipd / 1000.0f; // converts from mm to m + /*! @todo (Moses Turner) Next four u_json_get_float_array calls don't make any sense. + * They put the X coefficients from the JSON file into the Y coefficients in the structs, which is totally wrong, but the distortion looks totally wrong if we don't do this. + */ u_json_get_float_array(cJSON_GetObjectItemCaseSensitive( config_json, "left_uv_to_rect_x"), ns->eye_configs_v2[0].y_coefficients, @@ -423,7 +429,7 @@ ns_config_load(struct ns_hmd *ns) if (!u_json_get_float( cJSON_GetObjectItemCaseSensitive(config_json, - "leftEyeAngleLeft"), + "left_fov_radians_left"), &ns->eye_configs_v2[0] .fov .angle_left)) { // not putting this directly in @@ -437,43 +443,46 @@ ns_config_load(struct ns_hmd *ns) "example in " "src/xrt/drivers/north_star/" "v2_example_config.json."); - ns->eye_configs_v2[0].fov.angle_left = -0.6; - ns->eye_configs_v2[0].fov.angle_right = 0.6; - ns->eye_configs_v2[0].fov.angle_up = 0.6; - ns->eye_configs_v2[0].fov.angle_down = -0.6; + ns->eye_configs_v2[0].fov.angle_left = -0.8; + ns->eye_configs_v2[0].fov.angle_right = 0.8; + ns->eye_configs_v2[0].fov.angle_up = 0.8; + ns->eye_configs_v2[0].fov.angle_down = -0.8; - ns->eye_configs_v2[1].fov.angle_left = -0.6; - ns->eye_configs_v2[1].fov.angle_right = 0.6; - ns->eye_configs_v2[1].fov.angle_up = 0.6; - ns->eye_configs_v2[1].fov.angle_down = -0.6; + ns->eye_configs_v2[1].fov.angle_left = -0.8; + ns->eye_configs_v2[1].fov.angle_right = 0.8; + ns->eye_configs_v2[1].fov.angle_up = 0.8; + ns->eye_configs_v2[1].fov.angle_down = -0.8; } else { - u_json_get_float( - cJSON_GetObjectItemCaseSensitive( - config_json, "leftEyeAngleRight"), - &ns->eye_configs_v2[0].fov.angle_right); - u_json_get_float(cJSON_GetObjectItemCaseSensitive( - config_json, "leftEyeAngleUp"), - &ns->eye_configs_v2[0].fov.angle_up); - u_json_get_float(cJSON_GetObjectItemCaseSensitive( - config_json, "leftEyeAngleDown"), - &ns->eye_configs_v2[0].fov.angle_down); + u_json_get_float(cJSON_GetObjectItemCaseSensitive( - config_json, "rightEyeAngleLeft"), - &ns->eye_configs_v2[1].fov.angle_left); - u_json_get_float( - cJSON_GetObjectItemCaseSensitive( - config_json, "rightEyeAngleRight"), - &ns->eye_configs_v2[1].fov.angle_right); + config_json, "left_fov_radians_left"), + &ns->eye_configs_v2[0].fov.angle_left); u_json_get_float(cJSON_GetObjectItemCaseSensitive( - config_json, "rightEyeAngleUp"), - &ns->eye_configs_v2[1].fov.angle_up); + config_json, "left_fov_radians_right"), + &ns->eye_configs_v2[0].fov.angle_right); u_json_get_float(cJSON_GetObjectItemCaseSensitive( - config_json, "rightEyeAngleDown"), - &ns->eye_configs_v2[1].fov.angle_down); + config_json, "left_fov_radians_up"), + &ns->eye_configs_v2[0].fov.angle_up); + u_json_get_float(cJSON_GetObjectItemCaseSensitive( + config_json, "left_fov_radians_down"), + &ns->eye_configs_v2[0].fov.angle_down); + + u_json_get_float(cJSON_GetObjectItemCaseSensitive( + config_json, "right_fov_radians_left"), + &ns->eye_configs_v2[1].fov.angle_left); + u_json_get_float(cJSON_GetObjectItemCaseSensitive( + config_json, "right_fov_radians_right"), + &ns->eye_configs_v2[1].fov.angle_right); + u_json_get_float(cJSON_GetObjectItemCaseSensitive( + config_json, "right_fov_radians_up"), + &ns->eye_configs_v2[1].fov.angle_up); + u_json_get_float(cJSON_GetObjectItemCaseSensitive( + config_json, "right_fov_radians_down"), + &ns->eye_configs_v2[1].fov.angle_down); } ns->is_v2 = true; diff --git a/src/xrt/drivers/north_star/v1_example_config.json.license b/src/xrt/drivers/north_star/v1_example_config.json.license new file mode 100644 index 000000000..5858fb1d7 --- /dev/null +++ b/src/xrt/drivers/north_star/v1_example_config.json.license @@ -0,0 +1,3 @@ +Copyright 2020, CombineReality. + +SPDX-License-Identifier: BSL-1.0 \ No newline at end of file diff --git a/src/xrt/drivers/north_star/v1_example_config.json b/src/xrt/drivers/north_star/v1_example_config_deckx_50cm.json similarity index 53% rename from src/xrt/drivers/north_star/v1_example_config.json rename to src/xrt/drivers/north_star/v1_example_config_deckx_50cm.json index 4578b3489..23af1ea28 100644 --- a/src/xrt/drivers/north_star/v1_example_config.json +++ b/src/xrt/drivers/north_star/v1_example_config_deckx_50cm.json @@ -3,19 +3,19 @@ "ellipseMinorAxis": 0.24494899809360505, "ellipseMajorAxis": 0.3099985122680664, "screenForward": { - "x": 0.2824554741382599, - "y": -0.20611988008022309, - "z": 0.9368743300437927 + "x": 0.37583938241004946, + "y": -0.2950916886329651, + "z": 0.878445029258728 }, "screenPosition": { - "x": -0.07859157025814057, - "y": -0.005049339961260557, - "z": 0.012514465488493443 + "x": -0.07663544267416, + "y": -0.006479046773165464, + "z": 0.015394501388072968 }, "eyePosition": { - "x": -0.03200000151991844, - "y": 0.001083331648260355, - "z": -0.012499995529651642 + "x": -0.030106136575341226, + "y": -0.014616160653531552, + "z": -0.004279683344066143 }, "eyeRotation": { "x": 7.395533370627759e-32, @@ -33,33 +33,33 @@ "e00": 0.05101080238819122, "e01": 0.06071346998214722, "e02": 0.29330453276634219, - "e03": -0.11532726138830185, + "e03": -0.1151043102145195, "e10": 0.0, "e11": 0.23695310950279237, "e12": -0.07855913043022156, - "e13": 0.026422245427966119, + "e13": 0.026667742058634759, "e20": -0.23957861959934236, "e21": 0.012927045114338398, "e22": 0.062450066208839419, - "e23": -0.05475877597928047, + "e23": -0.05541845038533211, "e30": 0.0, "e31": 0.0, "e32": 0.0, "e33": 1.0 }, "worldToScreenSpace": { - "e00": 1.3777992725372315, - "e01": 14.81815242767334, - "e02": 2.8447227478027345, - "e03": 0.14750510454177857, - "e10": -16.076780319213868, - "e11": 0.5414643883705139, - "e12": 4.966066360473633, - "e13": -1.3229130506515504, - "e20": 0.2824554145336151, - "e21": -0.2061198651790619, - "e22": 0.9368743300437927, - "e23": 0.009433363564312458, + "e00": 2.027873992919922, + "e01": 14.474093437194825, + "e02": 3.994591236114502, + "e03": 0.1876906156539917, + "e10": -15.437186241149903, + "e11": 0.3111684322357178, + "e12": 6.709270000457764, + "e13": -1.284305453300476, + "e20": 0.37583935260772707, + "e21": -0.2950916290283203, + "e22": 0.8784450888633728, + "e23": 0.013367477804422379, "e30": 0.0, "e31": 0.0, "e32": 0.0, @@ -70,19 +70,19 @@ "ellipseMinorAxis": 0.24494899809360505, "ellipseMajorAxis": 0.3099985122680664, "screenForward": { - "x": -0.2919599413871765, - "y": -0.20477625727653504, - "z": 0.934251606464386 + "x": -0.35585933923721316, + "y": -0.27381938695907595, + "z": 0.8935251235961914 }, "screenPosition": { - "x": 0.07982077449560166, - "y": -0.005731542594730854, - "z": 0.01401037909090519 + "x": 0.07577500492334366, + "y": -0.009351296350359917, + "z": 0.014919517561793328 }, "eyePosition": { - "x": 0.03200000151991844, - "y": 0.001083331648260355, - "z": -0.012499995529651642 + "x": 0.0300484336912632, + "y": 0.006817266810685396, + "z": 0.0022060188930481674 }, "eyeRotation": { "x": 7.395533370627759e-32, @@ -100,33 +100,33 @@ "e00": 0.05101081356406212, "e01": -0.060713451355695727, "e02": -0.29330453276634219, - "e03": 0.11689796298742295, + "e03": 0.1155824139714241, "e10": 0.0, "e11": 0.23695312440395356, "e12": -0.07855910062789917, - "e13": 0.026351751759648324, + "e13": 0.02368796430528164, "e20": 0.23957861959934236, "e21": 0.0129270413890481, "e22": 0.062450066208839419, - "e23": -0.052946362644433978, + "e23": -0.0545220747590065, "e30": 0.0, "e31": 0.0, "e32": 0.0, "e33": 1.0 }, "worldToScreenSpace": { - "e00": -1.4188950061798096, - "e01": 14.821781158447266, - "e02": 2.805335283279419, - "e03": 0.15890516340732575, - "e10": -16.02415657043457, - "e11": -0.5628440976142883, - "e12": -5.131026744842529, - "e13": 1.3477222919464112, - "e20": -0.2919600307941437, - "e21": -0.2047763168811798, - "e22": 0.9342517256736755, - "e23": 0.00904157105833292, + "e00": -1.7429742813110352, + "e01": 14.570849418640137, + "e02": 3.7710490226745607, + "e03": 0.21206799149513246, + "e10": -15.61334228515625, + "e11": -0.23936468362808228, + "e12": -6.291592597961426, + "e13": 1.2747303247451783, + "e20": -0.35585933923721316, + "e21": -0.27381935715675356, + "e22": 0.8935251235961914, + "e23": 0.011073712259531021, "e30": 0.0, "e31": 0.0, "e32": 0.0, @@ -139,14 +139,14 @@ "localPose": { "position": { "x": 0.0, - "y": 0.039777886122465137, - "z": 0.0804821103811264 + "y": 0.02151, + "z": 0.06684 }, "rotation": { - "x": 0.3123600482940674, - "y": 0.0, - "z": 0.0, - "w": 0.9499638080596924 + "x": 0.3255681, + "y": 0, + "z": 0, + "w": 0.9455186 } } } diff --git a/src/xrt/drivers/north_star/v2_example_config.json b/src/xrt/drivers/north_star/v2_example_config.json deleted file mode 100644 index a7cba35d5..000000000 --- a/src/xrt/drivers/north_star/v2_example_config.json +++ /dev/null @@ -1,17 +0,0 @@ -{"baseline": 64.0, - "left_uv_to_rect_x": [-0.6496146862315304, 1.522223227078294, -0.4813404618897057, 0.35702657717980785, -0.07956037872995925, 1.1454020997970913, -3.2505199559593336, 1.6279076622052455, 0.38831554051443307, -3.5783949261594095, 7.668716710704405, -4.166750433790205, -0.2855168004377634, 2.304654520623994, -4.773857525576798, 2.6771905826607756], - "left_uv_to_rect_y": [0.5735680823264238, -0.07201032485360503, -0.3760147865913098, 0.12237851205003134, -1.1789607449622186, -0.3639051399896993, 1.9433544351592553, -1.428768695251512, 0.43448180786102064, 1.4198893425729027, -4.061494083054925, 2.5833812097228908, -0.20318807476847794, -0.8824999019236596, 2.2256952824902, -1.3778198332457088], - "right_uv_to_rect_x": [-0.6265143917747795, 1.2911622275040877, -0.5517955125123675, 0.34277683878971815, -0.008660007647723567, 0.5057868616188462, -0.7608772693869136, 0.441561492954449, 0.01102824175518119, -0.32306477445426557, 0.7580684800480195, -0.4808991141180218, -0.0517219007106306, 0.2799238117904546, -0.4494394376437649, 0.3706889336770174], - "right_uv_to_rect_y": [0.5259106471825626, -0.1663727700922601, 0.28233333974385694, 0.1745576324081204, -1.0358003574621981, 0.13565673296823005, 0.03669780270514961, -0.28419296928833887, 0.4258466087687195, -0.03876248767088333, -0.37766287840406676, 0.43848943099165466, -0.34808893357030296, 0.22156250909608152, 0.13817451999521518, -0.2468046426038312], - - "leftEyeAngleLeft": -0.6, - "leftEyeAngleRight": 0.6, - "leftEyeAngleUp": 0.6, - "leftEyeAngleDown": -0.6, - - "rightEyeAngleLeft": -0.6, - "rightEyeAngleRight": 0.6, - "rightEyeAngleUp": 0.6, - "rightEyeAngleDown": -0.6 - -} \ No newline at end of file diff --git a/src/xrt/drivers/north_star/v2_example_config_lonestar_50cm.json b/src/xrt/drivers/north_star/v2_example_config_lonestar_50cm.json new file mode 100644 index 000000000..f329583bf --- /dev/null +++ b/src/xrt/drivers/north_star/v2_example_config_lonestar_50cm.json @@ -0,0 +1,96 @@ +{ + "baseline": 64.0, + "left_fov_radians_left": -0.8, + "left_fov_radians_right": 0.8, + "left_fov_radians_up": 0.8, + "left_fov_radians_down": -0.8, + "right_fov_radians_left": -0.8, + "right_fov_radians_right": 0.8, + "right_fov_radians_up": 0.8, + "right_fov_radians_down": -0.8, + "t265_to_eyes_center": { + "translation_meters": { + "x": 0, + "y": -0.0683, + "z": 0.0744 + }, + "rotation_quaternion": { + "x": 0.102931, + "y": 0, + "z": 0, + "w": 0.994689 + } + }, + "left_uv_to_rect_x": [ + -0.7801988839098829, + 1.5908068712799723, + -0.9827824328911254, + 0.5263358892466966, + 0.18664841081239514, + -0.5246668149574745, + 1.4048420164308815, + -0.9330577906613924, + -0.15392100230529293, + 1.106540330862997, + -2.87151330241086, + 2.0315485110726668, + -0.06427965195537277, + -0.3146940276594198, + 1.5763979534056192, + -1.1327966252705322 + ], + "left_uv_to_rect_y": [ + -0.4409536269756768, + 0.2888996614465091, + -0.3848014983107932, + -0.1223362997546647, + 0.9670157125483582, + -0.3256816024594271, + 0.533926353628004, + -0.23310084856690347, + -0.17082017203715041, + -0.059688885588560045, + -0.9941995171671563, + 1.0721046441395208, + 0.2547327106222003, + -0.25419242442834455, + 1.0488819862049827, + -0.9515005068294279 + ], + "right_uv_to_rect_x": [ + -0.6710613688416264, + 1.1362689645641848, + 0.3956957345987107, + -0.21326295396259742, + -0.5335462524956397, + 4.546071135245812, + -10.207643227900032, + 5.846282899290887, + 1.3039161130160792, + -10.66129593656746, + 22.158725872611857, + -12.912719005943362, + -0.9563087974847321, + 6.870750205887958, + -13.828097816218262, + 8.10122851327323 + ], + "right_uv_to_rect_y": [ + -0.36496330390320814, + -0.34773830007498274, + 1.1607448604832324, + -0.5639076806706572, + 0.5129009330129037, + 4.133391411431411, + -9.131958871130214, + 5.601050711809029, + 1.1111421772677867, + -10.247117862137081, + 20.539322154891007, + -12.003706549179878, + -0.671733941602777, + 6.353458803843707, + -12.784556822147636, + 7.548883311524131 + ] +} \ No newline at end of file diff --git a/src/xrt/drivers/north_star/v2_example_config_lonestar_50cm.json.license b/src/xrt/drivers/north_star/v2_example_config_lonestar_50cm.json.license new file mode 100644 index 000000000..3c3644cab --- /dev/null +++ b/src/xrt/drivers/north_star/v2_example_config_lonestar_50cm.json.license @@ -0,0 +1,3 @@ +Copyright 2021, Moses Turner + +SPDX-License-Identifier: BSL-1.0 \ No newline at end of file