diff --git a/CHANGELOG b/CHANGELOG index e2bc13fef4eb665be1acc5e31d739bf927c321f3..f9b825ab88f6e0157c66638a43ba72eff6de82ef 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,6 @@ -************************************** -* ARIEL FGS HFS Repository CHANGELOG * -************************************** +***************************************************************** +* ARIEL FGS HFS Repository, ARIEL-UVIE-PL-ML-001 0.2, CHANGELOG * +***************************************************************** ################################################################################ V0.1: @@ -27,3 +27,18 @@ V0.1: which are both centered on the center of the Detector reference frame. Future version shall allow for configurable offsets between the frames. ################################################################################ +V0.2: +15.June, 2022 Gerald Mösenlechner <gerald.moesenlechner@univie.ac.at> + + Fixed Issues: + + - Fixed conversion from Spacecraft reference frame to detector reference + frame. + + - Fixed typo in conversion matrix. + + - Fixed typo in quaternion multiplication. + + - Added validation signal to input parameters of hfs_parameter struct. + This should prevent wrong or invalid identification when changing targets. +################################################################################ diff --git a/MANUAL b/MANUAL index d788ef1b2e8cd05a63fc744e57a1be35cf64dee6..f9da4e6ef3968100180cbe8e9906733ac8ca10eb 100644 --- a/MANUAL +++ b/MANUAL @@ -1,6 +1,6 @@ -************************ -* ARIEL FGS HFS MANUAL * -************************ +***************************************************** +* ARIEL FGS HFS, , ARIEL-UVIE-PL-ML-001 0.2, MANUAL * +***************************************************** The FGS HFS is based on the c++ object "FGS" defined in HFS_API.hpp. The constructor for this object has following notation: @@ -42,6 +42,8 @@ from of a hfs_parameters struct update. The struct is defined as follows: - unsigned int set_invalid: Flag to set the validity of all measuremets to false + - unsigned int validation_signal: Singal used for target identification [ADU/s] + - unsigned int mode: Operational mode, defined as an interger due to Simulink not supporting chars. The equiviliant modes and numbers are: diff --git a/Quaternion_Calculator.py b/Quaternion_Calculator.py index e34d83e8f2d5f6ecf7e1c4ede61c0ff529b347e3..17aaf406674839fad4bd61379a615044d0fc7961 100644 --- a/Quaternion_Calculator.py +++ b/Quaternion_Calculator.py @@ -61,7 +61,7 @@ def mult_quaternion(q1, q2): q_out = np.zeros(4) - q_out[0] = q1[0]*q2[0] + dot(q1,q2) + q_out[0] = q1[0]*q2[0] - dot(q1,q2) vec = q1[0]*q2[1:] + q2[0]*q1[1:] + cross3d(q1[1:], q2[1:]) q_out[1] = vec[0] @@ -92,9 +92,9 @@ if __name__ == "__main__": star = star_cat.loc[star_cat['Name'] == id] print("Quaternion for Star:", id) - star_vec = np.array((np.cos(star.dec)*np.cos(star.ra), np.cos(star.dec)*np.sin(star.ra), np.sin(star.dec))) + star_vec = np.array((np.cos(star.dec*(np.pi/180))*np.cos(star.ra*(np.pi/180)), np.cos(star.dec*(np.pi/180))*np.sin(star.ra*(np.pi/180)), np.sin(star.dec*(np.pi/180)))) - sc_vec = np.array((1.00000197, 0, -0.00017)) #target sc-vector + sc_vec = np.array((1.001698, 0, -0.0017)) #target sc-vector quat = calc_quaternion(sc_vec, star_vec) @@ -105,8 +105,8 @@ if __name__ == "__main__": print("Expected Signals:") print("\tFGS1:") - print("\t\tTracking:", float(star.FGS1*0.125)) - print("\t\tAcquisition:", float(star.FGS1*0.5)) + print("\t\tTracking:", float(star.FGS1*0.125), "ADU") + print("\t\tAcquisition:", float(star.FGS1*0.5), "ADU") print("\tFGS2:") - print("\t\tTracking:", float(star.FGS2*0.125)) - print("\t\tAcquisition:", float(star.FGS2*0.5)) + print("\t\tTracking:", float(star.FGS2*0.125), "ADU/s") + print("\t\tAcquisition:", float(star.FGS2*0.5), "ADU/s") diff --git a/README b/README index 4e41fc684dab70bd5f6cd66d9bc309b9407745b4..fc7d1ac2a7b16f0bb526ef265ea54f53c4562150 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ -**************************** -* ARIEL FGS HFS Repository * -**************************** +****************************************************** +* ARIEL FGS HFS Repository, ARIEL-UVIE-PL-ML-001 0.2 * +****************************************************** This repository contains the HFS, the simulator SW used to simulate the behaviour of the FGS IASW for the AOCS closed loop test. diff --git a/matlab_model/Example_model.slx b/matlab_model/Example_model.slx index 92b3703ac34c60b2698ebd20e9af98a69b30dab3..a52bffe6762f2ed1b93c45b49d2ad1592cba2c7a 100644 Binary files a/matlab_model/Example_model.slx and b/matlab_model/Example_model.slx differ diff --git a/matlab_model/HFS_Wrapper.cpp b/matlab_model/HFS_Wrapper.cpp index 1bc78a747ba92eb0c1e306054b483fc664be5ad7..8ac8e14e354660a9c85a79b83d6ce19eef4b3239 100644 --- a/matlab_model/HFS_Wrapper.cpp +++ b/matlab_model/HFS_Wrapper.cpp @@ -73,6 +73,7 @@ void updateFGS(hfs_parameters *update, centroid_packet *output) u_new.reset = update -> reset; u_new.save = update -> save; u_new.set_invalid = update -> set_invalid; + u_new.validation_signal = update -> validation_signal; u_new.sync_flag = update -> sync_flag; fgsSim -> set_params(u_new, output); diff --git a/matlab_model/HFS_bus.mat b/matlab_model/HFS_bus.mat index 8239bcb877b865fcafbc983448e9ffdcc8988b66..e561d1aa6ab50fce1786f0466ffe151f6eed9389 100644 Binary files a/matlab_model/HFS_bus.mat and b/matlab_model/HFS_bus.mat differ diff --git a/src/HFS_API.cpp b/src/HFS_API.cpp index 9dc14d7b8c9dad18747d4f675cf83f520dbc2457..6c302c1ea5714101a167e36351d26c62e4838e49 100644 --- a/src/HFS_API.cpp +++ b/src/HFS_API.cpp @@ -2,7 +2,7 @@ * @file HFS_API.cpp * @author Gerald Mösenlechner (gerald.moesenlechner@univie.ac.at) * @date May, 2022 -* @version 0.1 +* @version 0.2 * * @copyright * This program is free software; you can redistribute it and/or modify it @@ -30,7 +30,7 @@ const char* MODE_ACQU = "Acquisition"; const char* MODE_TRAC = "Tracking"; const char* MODE_STBY = "Standby"; -static double ROTMATRIX[9] = {-1, 0, 0, 0, 0.999998, -0.00017, 0, -0.00017, -0.999998}; +static double ROTMATRIX[9] = {-1, 0, 0, 0, 0.999998, -0.0017, 0, -0.0017, -0.999998}; static double ROTMATRIX_SC[9] = {0, -1, 0, 0, 0, 1, -1, 0, 0}; double smear_kernel_os[125*125]; @@ -366,11 +366,11 @@ int FGS :: perform_algorithm() if (med_acq == 1) { MedFilter3x3(image, dim_x, dim_y, med_threshold, filtered_image); - output = SourceDetection(filtered_image, dim_x, dim_y, 0, channel, 10, target_signal, tolerance_acq, 10, iter_acq, 10, 15, target_signal*0.01, val_sigma, pearson_limit); + output = SourceDetection(filtered_image, dim_x, dim_y, 0, channel, 10, target_signal*exposure_time, tolerance_acq, 10, iter_acq, 10, 15, target_signal*0.01, val_sigma, pearson_limit); } else { - output = SourceDetection(image, dim_x, dim_y, 0, channel, 10, target_signal, tolerance_acq, 10, iter_acq, 10, 15, target_signal*0.01, val_sigma, pearson_limit); + output = SourceDetection(image, dim_x, dim_y, 0, channel, 10, target_signal*exposure_time, tolerance_acq, 10, iter_acq, 10, 15, target_signal*0.01, val_sigma, pearson_limit); } } else if (strcmp(mode, MODE_TRAC) == 0) @@ -748,13 +748,13 @@ int FGS :: transform_to_detector(double (&vec)[3], double* output) dmatmult(rot_matrix_sc, vector, &transf_opt); dmatmult(rot_matrix_opt, transf_opt, &transf); - if(abs(transf.data[0]*3600000) < (dim_x/2)*plate_scale) + if(abs(transf.data[0]*3600000*(360/TWO_PI)) < (dim_x/2)*plate_scale) { - if(abs(transf.data[1]*3600000) < (dim_y/2)*plate_scale) + if(abs(transf.data[1]*3600000*(360/TWO_PI)) < (dim_y/2)*plate_scale) { - output[0] = transf.data[0]*3600000/plate_scale; - output[1] = transf.data[1]*3600000/plate_scale; + output[0] = transf.data[0]*(360/TWO_PI)*3600000/plate_scale; + output[1] = transf.data[1]*(360/TWO_PI)*3600000/plate_scale; return 0; } } @@ -792,9 +792,9 @@ int FGS :: transform_star_coordinates(double (&quaternion)[4]) for(i = 0; i < targets -> number; i++) { star_quat[0] = 0.; - star_quat[1] = cos(targets -> dec[i])*cos(targets -> ra[i]); - star_quat[2] = cos(targets -> dec[i])*sin(targets -> ra[i]); - star_quat[3] = sin(targets -> dec[i]); + star_quat[1] = cos(targets -> dec[i] * (TWO_PI/360))*cos(targets -> ra[i] * (TWO_PI/360)); + star_quat[2] = cos(targets -> dec[i] * (TWO_PI/360))*sin(targets -> ra[i] * (TWO_PI/360)); + star_quat[3] = sin(targets -> dec[i] * (TWO_PI/360)); /*apply quaternion to vector*/ multiply_quaternion(quaternion, star_quat, tmp_quat); @@ -886,10 +886,11 @@ int FGS :: set_params(hfs_parameters update, centroid_packet *cent_packet) centroid.y = (centroid.y - dim_y/2) * plate_scale; sync_ctr = 0; send_cent = 1; - if((strcmp(mode, update_mode_char) != 0) || channel != update.channel) + if((strcmp(mode, update_mode_char) != 0) || channel != update.channel || target_signal != update.validation_signal) { set_mode(update_mode_char); set_channel(update.channel); + target_signal = update.validation_signal; } } else @@ -911,10 +912,11 @@ int FGS :: set_params(hfs_parameters update, centroid_packet *cent_packet) centroid.y = (centroid.y - dim_y/2) * plate_scale; sync_ctr = 0; send_cent = 1; - if((strcmp(mode, update_mode_char) != 0) || channel != update.channel) + if((strcmp(mode, update_mode_char) != 0) || channel != update.channel || target_signal != update.validation_signal) { set_mode(update_mode_char); set_channel(update.channel); + target_signal = update.validation_signal; } } else @@ -935,10 +937,11 @@ int FGS :: set_params(hfs_parameters update, centroid_packet *cent_packet) cent_packet -> validity_index = 100.; cent_packet -> validity_flag = 0; cent_packet -> time = time; - if((strcmp(mode, update_mode_char) != 0) || channel != update.channel) + if((strcmp(mode, update_mode_char) != 0) || channel != update.channel || target_signal != update.validation_signal) { set_mode(update_mode_char); set_channel(update.channel); + target_signal = update.validation_signal; } } } @@ -1062,7 +1065,7 @@ int multiply_quaternion(double (&quaternion1)[4], double (&quaternion2)[4], doub unsigned int i; cross3(q_vec1, q_vec2, cross); - output[0] = s1 * s2 * dot(q_vec1, q_vec2, 3); + output[0] = s1 * s2 - dot(q_vec1, q_vec2, 3); for(i = 0; i < 3; i++) { diff --git a/src/HFS_API.hpp b/src/HFS_API.hpp index b67dc05df0e72672bb52f86d36164ca57fffe037..9168df6d1da0dff37800c64a6e71600ffe56f414 100644 --- a/src/HFS_API.hpp +++ b/src/HFS_API.hpp @@ -2,7 +2,7 @@ * @file HFS_API.hpp * @author Gerald Mösenlechner (gerald.moesenlechner@univie.ac.at) * @date May, 2022 -* @version 0.1 +* @version 0.2 * * @copyright * This program is free software; you can redistribute it and/or modify it @@ -51,6 +51,7 @@ #define FL_FGS2 27.08 /*Focal lenght in m*/ #define PS_FGS1 175.0 /*Plate scale in mas/px*/ #define PS_FGS2 137.1 /*Plate scale in mas/px*/ +#define TWO_PI 6.28318531f extern const char* MODE_ACQU; @@ -81,6 +82,7 @@ struct hfs_state * @param save: flag for saving the current state of the HFS * @param reset: flag for reseting the HFS * @param set_invalid: flag for setting the validity flag to false + * @param validation_signal: Target Signal used for validation and identification * @param mode: operational mode of the FGS 0: Standby, 1: Acquisition, 2: Tracking * @note Operational modes are integers as Simulink doesn't support c */ @@ -88,7 +90,7 @@ typedef struct{ double position_quat[4]; double ang_rate[3]; double time; - unsigned int sync_flag, channel, save, reset, set_invalid; + unsigned int sync_flag, channel, save, reset, set_invalid, validation_signal; unsigned int mode; } hfs_parameters; diff --git a/src/HFS_bus.mat b/src/HFS_bus.mat index a453fb79d9832dc08fffe5eb28795fb99963cfd9..d8f28171de2c7b3965bb1d9bf8c45118f6d1fe0b 100644 Binary files a/src/HFS_bus.mat and b/src/HFS_bus.mat differ diff --git a/src/HFS_config.xml b/src/HFS_config.xml index c6667a38b7742028629fccb3d52381e5b6ae9a3f..f38d22bf92d005b3fac38112157b4a4ebcb36ad8 100644 --- a/src/HFS_config.xml +++ b/src/HFS_config.xml @@ -92,7 +92,7 @@ Note: must be lower than the integration time (0.5 s) --> <delay>0.1</delay> <!-- Brightness tolerance for target identification default is 20% --> - <tolerance>20</tolerance> + <tolerance>50</tolerance> </Acquisition> <!-- Relative path to the star catalouge --> diff --git a/src/detector_features.c b/src/detector_features.c index 2c8b82c4752811589320d90b48b698271bae8cae..90bb675773bde93b4b8496269cbb4355f328cf50 100644 --- a/src/detector_features.c +++ b/src/detector_features.c @@ -2,7 +2,7 @@ * @file detector_features.c * @author Gerald Mösenlechner (gerald.moesenlechner@univie.ac.at) * @date May, 2022 -* @version 0.1 +* @version 0.2 * * @copyright * This program is free software; you can redistribute it and/or modify it diff --git a/src/fcu_algorithms.c b/src/fcu_algorithms.c index 4e0e435825deb925cfb1fd3a638396c0115593b1..e8d31a59401a4205bd2a2ccfc12324c56b7989cd 100644 --- a/src/fcu_algorithms.c +++ b/src/fcu_algorithms.c @@ -2,7 +2,7 @@ * @file fcu_algorithms.c * @author Gerald Mösenlechner (gerald.moesenlechner@univie.ac.at) * @date May, 2022 -* @version 0.1 +* @version 0.2 * * @copyright * This program is free software; you can redistribute it and/or modify it @@ -1570,5 +1570,6 @@ struct coord SourceDetection(unsigned int *data, unsigned int xdim, unsigned int { result.validity.flag = 1; } + result.time = 0.; return result; } diff --git a/src/utilities.c b/src/utilities.c index e374818cec51cf3b912791d4d66c909c963824b6..c349d21ce9f40bc6dd244833ce7930215ddd13f5 100644 --- a/src/utilities.c +++ b/src/utilities.c @@ -2,7 +2,7 @@ * @file utilities.c * @author Gerald Mösenlechner (gerald.moesenlechner@univie.ac.at) * @date May, 2022 -* @version 0.1 +* @version 0.2 * * @copyright * This program is free software; you can redistribute it and/or modify it @@ -88,7 +88,7 @@ void random_poisson_trm(double *matrix, double mean, unsigned int size) unsigned int i; double k; double U, V, slam, loglam, a, b, invalpha, vr, us, enlam, prod, X; - + slam = sqrt(mean); loglam = log(mean); b = 0.931 + 2.53*slam; diff --git a/test/HFSTest.cpp b/test/HFSTest.cpp index 72ae1e4f5dc054d6cfedfa606ea72b6e57016fe4..60d592c66115bd181a4de83bf6fcf24388089445 100644 --- a/test/HFSTest.cpp +++ b/test/HFSTest.cpp @@ -6,6 +6,8 @@ #include <stdlib.h> #include <experimental/filesystem> +#define TWO_PI 6.28318531f + // Registers the fixture into the 'registry' CPPUNIT_TEST_SUITE_REGISTRATION(HFSTest); @@ -134,23 +136,23 @@ void HFSTest::testTransformation() fgs.transform_to_detector(vecx, output); CPPUNIT_ASSERT_DOUBLES_EQUAL(output[0], 0, 1e-7); - CPPUNIT_ASSERT_DOUBLES_EQUAL(output[1], 0.00017*1e-5*3600000/175.0, 1e-7); + CPPUNIT_ASSERT_DOUBLES_EQUAL(output[1], 0.0017*1e-5*(360/TWO_PI)*3600000/175.0, 1e-7); fgs.transform_to_detector(vecy, output); - CPPUNIT_ASSERT_DOUBLES_EQUAL(output[0], 1e-5*3600000/175.0, 1e-7); + CPPUNIT_ASSERT_DOUBLES_EQUAL(output[0], 1e-5*(360/TWO_PI)*3600000/175.0, 1e-7); CPPUNIT_ASSERT_DOUBLES_EQUAL(output[1], 0, 1e-7); fgs.transform_to_detector(vecz, output); CPPUNIT_ASSERT_DOUBLES_EQUAL(output[0], 0, 1e-7); - CPPUNIT_ASSERT_DOUBLES_EQUAL(output[1], 0.999998*1e-5*3600000/175.0, 1e-5); + CPPUNIT_ASSERT_DOUBLES_EQUAL(output[1], 0.999998*1e-5*(360/TWO_PI)*3600000/175.0, 1e-5); } void HFSTest::testParameterUpdate() { struct hfs_state state; - struct hfs_parameters update; - struct centroid_packet output; + hfs_parameters update; + centroid_packet output; char path[] = "./test/HFS_config_test.xml"; char* real_path = realpath(path, NULL); FGS fgs(real_path); @@ -161,13 +163,14 @@ void HFSTest::testParameterUpdate() update.sync_flag = 1; update.time = 0.015626; update.channel = 1; - update.mode = "Standby"; + update.mode = 0; update.save = 0; update.reset = 0; update.set_invalid = 0; update.ang_rate[0] = 1e-5; update.ang_rate[1] = 1e-5; update.ang_rate[2] = 1e-5; + update.validation_signal = 100000; fgs.set_params(update, &output); state = fgs.get_hfs_state(); @@ -177,7 +180,7 @@ void HFSTest::testParameterUpdate() state = fgs.get_hfs_state(); CPPUNIT_ASSERT(strcmp(state.mode, "Standby") == 0); - update.mode = "Tracking"; + update.mode = 2; update.sync_flag = 0; fgs.set_params(update, &output); fgs.set_params(update, &output); diff --git a/test/example.cpp b/test/example.cpp index e065b9a086792799cb509e9ddb5fb800a46f7e16..8d43b9513bbc447acafd7f63a3b8e50fc2a20877 100644 --- a/test/example.cpp +++ b/test/example.cpp @@ -18,7 +18,7 @@ int main() double sum_x_tra, sum_y_tra, sum_x_acq, sum_y_acq; /*Values for mean*/ /*Quaternion to put WASP-11 in the center of the DRF*/ /*The resuling measurement of the */ - double quat[4] = {3.77743614e-01, 4.02209431e-05, -8.95172007e-01,2.36594249e-01 }; + double quat[4] = {0.8892834993148474, -0.0006038143244162956, 0.2873837014059442, -0.3557880006700909}; /*Initialise FGS simulator by calling constructor*/ FGS fgs(real_path); @@ -58,6 +58,9 @@ int main() /*mark all cantroid packets as invalid*/ update.set_invalid = 0; + /*Set signal for target identification in ADU/s*/ + update.validation_signal = 100000; + /*Unit quaternion of the current SC attitude in reference to J2000*/ update.position_quat[0] = quat[0]; update.position_quat[1] = quat[1]; @@ -170,8 +173,8 @@ int main() std::cout << "Sim is " << output.time / (ms_double.count()/1000) << " times faster than real time!\n"; std::cout << "Mean Measurement for Tracking: \n x: " << sum_x_tra/ctr_tra << "\n y: " << sum_y_tra/ctr_tra << "\n\n"; - std::cout << "Tracking Reference Values: \n x: ~ 248mas\n y: ~ 387mas\n\n"; + std::cout << "Tracking Reference Values: \n x: ~ 256mas\n y: ~ 983mas\n\n"; std::cout << "Mean Measurement for Acquisition: \n x: " << sum_x_acq/ctr_acq << "\n y: " << sum_y_acq/ctr_acq << "\n\n"; - std::cout << "Acquisition Reference Values: \n x: ~ 276mas\n y: ~ 267mas\n\n"; + std::cout << "Acquisition Reference Values: \n x: ~ 237mas\n y: ~ 911mas\n\n"; }