Loading SRT/Servers/SRTMinorServo/test/Makefile +1 −1 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ SRPProgramTrackTest_LIBS = $(GTEST_LIBS) SRTMinorServoSocketLibrary SRTMinorServ PFPProgramTrackTest_OBJECTS = PFPProgramTrackTest PFPProgramTrackTest_CFLAGS = -std=c++17 -fconcepts PFPProgramTrackTest_LIBS = $(GTEST_LIBS) SRTMinorServoSocketLibrary SRTMinorServoCommandLibrary IRALibrary ComponentErrors boost_filesystem PFPProgramTrackTest_LIBS = $(GTEST_LIBS) SRTMinorServoSocketLibrary SRTMinorServoCommandLibrary IRALibrary ComponentErrors MinorServoErrors boost_filesystem DerotatorProgramTrackTest_OBJECTS = DerotatorProgramTrackTest DerotatorProgramTrackTest_CFLAGS = -std=c++17 Loading SRT/Servers/SRTMinorServo/test/PFPProgramTrackTest.cpp +38 −19 Original line number Diff line number Diff line Loading @@ -4,13 +4,15 @@ #include <chrono> #include <ctime> #include <boost/filesystem.hpp> #include <MinorServoErrors.h> #include "SRTMinorServoUtils.h" #include "SRTMinorServoTestingSocket.h" #include "SRTMinorServoCommandLibrary.h" // This address and port are the ones set in the simulator // In order for the test to properly be executed, the simulator should be launched with the following command: // discos-simulator -s minor_servo start & #define SIMULATION //#define SIMULATION #ifdef SIMULATION #define ADDRESS std::string("127.0.0.1") #define PORT 12800 Loading @@ -22,8 +24,8 @@ #define ADVANCE_TIMEGAP 2.6 //#define MIN_RANGES std::vector<double>{ -1490, -200, -1 } //#define MAX_RANGES std::vector<double>{ 1490, 50, 76 } #define MIN_RANGES std::vector<double>{ -1000, -100, 0 } #define MAX_RANGES std::vector<double>{ 1000, 25, 20 } #define MIN_RANGES std::vector<double>{ -1000, -150, 0 } #define MAX_RANGES std::vector<double>{ 1000, 40, 70 } #define MAX_SPEED std::vector<double>{ 25, 5, 0.42 } #define STATUS_PERIOD 0.01 Loading Loading @@ -52,9 +54,20 @@ protected: double tn = CIRATools::getUNIXEpoch(); while(!terminate) while(!terminate.load()) { try { PFPStatus = socket.sendCommand(SRTMinorServoCommandLibrary::status("PFP")); } catch(MinorServoErrors::MinorServoErrorsEx& ex) { //MinorServoErrors::MinorServoErrorsExImpl impl(ex); std::cout << getErrorFromEx(ex) << std::endl; terminate.store(true); break; } std::string status = serializeStatus(PFPStatus); statusFile << status << std::endl; Loading @@ -72,7 +85,7 @@ protected: static void sigintHandler(int sig_num) { std::cout << std::endl << "Terminating..." << std::endl; terminate = true; terminate.store(true); } static std::string serializeStatus(SRTMinorServoAnswerMap map) Loading Loading @@ -288,7 +301,7 @@ protected: EXPECT_TRUE(PFPStatus.checkOutput()); std::cout << serializeStatus(PFPStatus) << std::endl; if(terminate) if(terminate.load()) FAIL() << "Aborting test..." << std::endl; } while(PFPStatus.get<unsigned int>("PFP_OPERATIVE_MODE") != 40); Loading Loading @@ -322,7 +335,7 @@ protected: void TearDown() override { SRTMinorServoTestingSocket::destroyInstance(); terminate = false; terminate.store(false); } }; Loading Loading @@ -355,7 +368,7 @@ TEST_F(PFPProgramTrackTest, ContinuousMovementTest) unsigned int idle_count = 0; bool idle = false; while(!terminate) while(!terminate.load()) { next_expected_time += TIMEGAP; Loading Loading @@ -414,7 +427,7 @@ TEST_F(PFPProgramTrackTest, AllAxesMovementTest) std::vector<unsigned int> idle_count = { 0, 0, 0 }; std::vector<bool> idle = { false, false, false }; while(!terminate) while(!terminate.load()) { next_expected_time += TIMEGAP; Loading Loading @@ -493,7 +506,7 @@ TEST_F(PFPProgramTrackTest, SineWaveMovementTest) double next_expected_time = start_time; while(!terminate) while(!terminate.load()) { next_expected_time += TIMEGAP; double time_delta = next_expected_time - start_time; Loading Loading @@ -525,24 +538,27 @@ TEST_F(PFPProgramTrackTest, SeparateMovementTest) ofstream programTrackFile; programTrackFile.open(directory + "/trajectory.txt", ios::out); unsigned int axis_to_move = 0; unsigned int axis_to_move = 1; int sign = 1; unsigned int idle_count = 0; bool idle = false; std::cout << "PRESET position reached, starting PROGRAMTRACK" << std::endl; std::cout << "PRESET position reached" << std::endl; std::vector<double> programTrackCoordinates = startingCoordinates; bool immediate = false; while(!terminate) while(!terminate.load()) { double start_time = CIRATools::getUNIXEpoch() + ADVANCE_TIMEGAP; std::cout << "starting PROGRAMTRACK with timestamp " << std::to_string(start_time) << std::endl; long unsigned int trajectory_id = int(start_time); double next_expected_time = start_time; unsigned int point_id = 0; PFPStatus = socket.sendCommand(SRTMinorServoCommandLibrary::programTrack("PFP", trajectory_id, point_id, programTrackCoordinates, start_time)); std::string command = SRTMinorServoCommandLibrary::programTrack("PFP", trajectory_id, point_id, programTrackCoordinates, start_time); //std::cout << command; PFPStatus = socket.sendCommand(command); EXPECT_TRUE(PFPStatus.checkOutput()); programTrackFile << PFPProgramTrackTest::serializeCoordinates(start_time, programTrackCoordinates) << std::endl; Loading @@ -552,7 +568,7 @@ TEST_F(PFPProgramTrackTest, SeparateMovementTest) EXPECT_TRUE(PFPStatus.checkOutput()); EXPECT_EQ(PFPStatus.get<unsigned int>("PFP_OPERATIVE_MODE"), 50); while(!terminate) while(!terminate.load()) { next_expected_time += TIMEGAP; Loading @@ -576,7 +592,10 @@ TEST_F(PFPProgramTrackTest, SeparateMovementTest) idle = true; } PFPStatus = socket.sendCommand(SRTMinorServoCommandLibrary::programTrack("PFP", trajectory_id, point_id, programTrackCoordinates)); command = SRTMinorServoCommandLibrary::programTrack("PFP", trajectory_id, point_id, programTrackCoordinates); PFPStatus = socket.sendCommand(command); //std::cout << command; //PFPStatus = socket.sendCommand(SRTMinorServoCommandLibrary::programTrack("PFP", trajectory_id, point_id, programTrackCoordinates)); EXPECT_TRUE(PFPStatus.checkOutput()); } Loading Loading @@ -604,7 +623,7 @@ TEST_F(PFPProgramTrackTest, RapidTrajectoryTest) std::cout << "PRESET position reached, starting PROGRAMTRACK" << std::endl; while(!terminate) while(!terminate.load()) { unsigned int axis_to_move = 1; int sign = -1; Loading @@ -627,7 +646,7 @@ TEST_F(PFPProgramTrackTest, RapidTrajectoryTest) EXPECT_TRUE(PFPStatus.checkOutput()); EXPECT_EQ(PFPStatus.get<unsigned int>("PFP_OPERATIVE_MODE"), 50); while(!terminate) while(!terminate.load()) { next_expected_time += TIMEGAP; Loading SRT/Servers/SRTMinorServo/test/SRPProgramTrackTest.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ #define TIMEGAP 0.2 #define ADVANCE_TIMEGAP 2.6 #define MAX_RANGES std::vector<double>{ 40, 40, 40, 0.2, 0.2, 0.2 } #define MAX_RANGES std::vector<double>{ 50, 110, 50, 0.25, 0.25, 0.25 } #define MAX_RANGES std::vector<double>{ 50, 120, 120, 0.25, 0.25, 0.25 } #define MAX_SPEED std::vector<double>{ 4, 4, 4, 0.04, 0.04, 0.04 } #define STATUS_PERIOD 0.01 Loading Loading @@ -432,7 +432,7 @@ TEST_F(SRPProgramTrackTest, SineWaveMovementTest) std::vector<double> phase_shift; std::vector<double> period; for(size_t axis = 0; axis < 6; axis++) for(size_t axis = 0; axis < 3; axis++) { double period_multiplier = axis < 3 ? 4 : 4; period.push_back(MAX_RANGES[axis] / MAX_SPEED[axis] * period_multiplier); Loading Loading @@ -465,7 +465,7 @@ TEST_F(SRPProgramTrackTest, SineWaveMovementTest) std::this_thread::sleep_for(std::chrono::microseconds((int)round(1000000 * std::max(0.0, next_expected_time - ADVANCE_TIMEGAP - CIRATools::getUNIXEpoch())))); point_id++; for(size_t axis = 0; axis < 6; axis++) for(size_t axis = 0; axis < 3; axis++) { programTrackCoordinates[axis] = MAX_RANGES[axis] * sin((time_delta + phase_shift[axis]) * 2 * M_PI / period[axis]); } Loading Loading
SRT/Servers/SRTMinorServo/test/Makefile +1 −1 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ SRPProgramTrackTest_LIBS = $(GTEST_LIBS) SRTMinorServoSocketLibrary SRTMinorServ PFPProgramTrackTest_OBJECTS = PFPProgramTrackTest PFPProgramTrackTest_CFLAGS = -std=c++17 -fconcepts PFPProgramTrackTest_LIBS = $(GTEST_LIBS) SRTMinorServoSocketLibrary SRTMinorServoCommandLibrary IRALibrary ComponentErrors boost_filesystem PFPProgramTrackTest_LIBS = $(GTEST_LIBS) SRTMinorServoSocketLibrary SRTMinorServoCommandLibrary IRALibrary ComponentErrors MinorServoErrors boost_filesystem DerotatorProgramTrackTest_OBJECTS = DerotatorProgramTrackTest DerotatorProgramTrackTest_CFLAGS = -std=c++17 Loading
SRT/Servers/SRTMinorServo/test/PFPProgramTrackTest.cpp +38 −19 Original line number Diff line number Diff line Loading @@ -4,13 +4,15 @@ #include <chrono> #include <ctime> #include <boost/filesystem.hpp> #include <MinorServoErrors.h> #include "SRTMinorServoUtils.h" #include "SRTMinorServoTestingSocket.h" #include "SRTMinorServoCommandLibrary.h" // This address and port are the ones set in the simulator // In order for the test to properly be executed, the simulator should be launched with the following command: // discos-simulator -s minor_servo start & #define SIMULATION //#define SIMULATION #ifdef SIMULATION #define ADDRESS std::string("127.0.0.1") #define PORT 12800 Loading @@ -22,8 +24,8 @@ #define ADVANCE_TIMEGAP 2.6 //#define MIN_RANGES std::vector<double>{ -1490, -200, -1 } //#define MAX_RANGES std::vector<double>{ 1490, 50, 76 } #define MIN_RANGES std::vector<double>{ -1000, -100, 0 } #define MAX_RANGES std::vector<double>{ 1000, 25, 20 } #define MIN_RANGES std::vector<double>{ -1000, -150, 0 } #define MAX_RANGES std::vector<double>{ 1000, 40, 70 } #define MAX_SPEED std::vector<double>{ 25, 5, 0.42 } #define STATUS_PERIOD 0.01 Loading Loading @@ -52,9 +54,20 @@ protected: double tn = CIRATools::getUNIXEpoch(); while(!terminate) while(!terminate.load()) { try { PFPStatus = socket.sendCommand(SRTMinorServoCommandLibrary::status("PFP")); } catch(MinorServoErrors::MinorServoErrorsEx& ex) { //MinorServoErrors::MinorServoErrorsExImpl impl(ex); std::cout << getErrorFromEx(ex) << std::endl; terminate.store(true); break; } std::string status = serializeStatus(PFPStatus); statusFile << status << std::endl; Loading @@ -72,7 +85,7 @@ protected: static void sigintHandler(int sig_num) { std::cout << std::endl << "Terminating..." << std::endl; terminate = true; terminate.store(true); } static std::string serializeStatus(SRTMinorServoAnswerMap map) Loading Loading @@ -288,7 +301,7 @@ protected: EXPECT_TRUE(PFPStatus.checkOutput()); std::cout << serializeStatus(PFPStatus) << std::endl; if(terminate) if(terminate.load()) FAIL() << "Aborting test..." << std::endl; } while(PFPStatus.get<unsigned int>("PFP_OPERATIVE_MODE") != 40); Loading Loading @@ -322,7 +335,7 @@ protected: void TearDown() override { SRTMinorServoTestingSocket::destroyInstance(); terminate = false; terminate.store(false); } }; Loading Loading @@ -355,7 +368,7 @@ TEST_F(PFPProgramTrackTest, ContinuousMovementTest) unsigned int idle_count = 0; bool idle = false; while(!terminate) while(!terminate.load()) { next_expected_time += TIMEGAP; Loading Loading @@ -414,7 +427,7 @@ TEST_F(PFPProgramTrackTest, AllAxesMovementTest) std::vector<unsigned int> idle_count = { 0, 0, 0 }; std::vector<bool> idle = { false, false, false }; while(!terminate) while(!terminate.load()) { next_expected_time += TIMEGAP; Loading Loading @@ -493,7 +506,7 @@ TEST_F(PFPProgramTrackTest, SineWaveMovementTest) double next_expected_time = start_time; while(!terminate) while(!terminate.load()) { next_expected_time += TIMEGAP; double time_delta = next_expected_time - start_time; Loading Loading @@ -525,24 +538,27 @@ TEST_F(PFPProgramTrackTest, SeparateMovementTest) ofstream programTrackFile; programTrackFile.open(directory + "/trajectory.txt", ios::out); unsigned int axis_to_move = 0; unsigned int axis_to_move = 1; int sign = 1; unsigned int idle_count = 0; bool idle = false; std::cout << "PRESET position reached, starting PROGRAMTRACK" << std::endl; std::cout << "PRESET position reached" << std::endl; std::vector<double> programTrackCoordinates = startingCoordinates; bool immediate = false; while(!terminate) while(!terminate.load()) { double start_time = CIRATools::getUNIXEpoch() + ADVANCE_TIMEGAP; std::cout << "starting PROGRAMTRACK with timestamp " << std::to_string(start_time) << std::endl; long unsigned int trajectory_id = int(start_time); double next_expected_time = start_time; unsigned int point_id = 0; PFPStatus = socket.sendCommand(SRTMinorServoCommandLibrary::programTrack("PFP", trajectory_id, point_id, programTrackCoordinates, start_time)); std::string command = SRTMinorServoCommandLibrary::programTrack("PFP", trajectory_id, point_id, programTrackCoordinates, start_time); //std::cout << command; PFPStatus = socket.sendCommand(command); EXPECT_TRUE(PFPStatus.checkOutput()); programTrackFile << PFPProgramTrackTest::serializeCoordinates(start_time, programTrackCoordinates) << std::endl; Loading @@ -552,7 +568,7 @@ TEST_F(PFPProgramTrackTest, SeparateMovementTest) EXPECT_TRUE(PFPStatus.checkOutput()); EXPECT_EQ(PFPStatus.get<unsigned int>("PFP_OPERATIVE_MODE"), 50); while(!terminate) while(!terminate.load()) { next_expected_time += TIMEGAP; Loading @@ -576,7 +592,10 @@ TEST_F(PFPProgramTrackTest, SeparateMovementTest) idle = true; } PFPStatus = socket.sendCommand(SRTMinorServoCommandLibrary::programTrack("PFP", trajectory_id, point_id, programTrackCoordinates)); command = SRTMinorServoCommandLibrary::programTrack("PFP", trajectory_id, point_id, programTrackCoordinates); PFPStatus = socket.sendCommand(command); //std::cout << command; //PFPStatus = socket.sendCommand(SRTMinorServoCommandLibrary::programTrack("PFP", trajectory_id, point_id, programTrackCoordinates)); EXPECT_TRUE(PFPStatus.checkOutput()); } Loading Loading @@ -604,7 +623,7 @@ TEST_F(PFPProgramTrackTest, RapidTrajectoryTest) std::cout << "PRESET position reached, starting PROGRAMTRACK" << std::endl; while(!terminate) while(!terminate.load()) { unsigned int axis_to_move = 1; int sign = -1; Loading @@ -627,7 +646,7 @@ TEST_F(PFPProgramTrackTest, RapidTrajectoryTest) EXPECT_TRUE(PFPStatus.checkOutput()); EXPECT_EQ(PFPStatus.get<unsigned int>("PFP_OPERATIVE_MODE"), 50); while(!terminate) while(!terminate.load()) { next_expected_time += TIMEGAP; Loading
SRT/Servers/SRTMinorServo/test/SRPProgramTrackTest.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ #define TIMEGAP 0.2 #define ADVANCE_TIMEGAP 2.6 #define MAX_RANGES std::vector<double>{ 40, 40, 40, 0.2, 0.2, 0.2 } #define MAX_RANGES std::vector<double>{ 50, 110, 50, 0.25, 0.25, 0.25 } #define MAX_RANGES std::vector<double>{ 50, 120, 120, 0.25, 0.25, 0.25 } #define MAX_SPEED std::vector<double>{ 4, 4, 4, 0.04, 0.04, 0.04 } #define STATUS_PERIOD 0.01 Loading Loading @@ -432,7 +432,7 @@ TEST_F(SRPProgramTrackTest, SineWaveMovementTest) std::vector<double> phase_shift; std::vector<double> period; for(size_t axis = 0; axis < 6; axis++) for(size_t axis = 0; axis < 3; axis++) { double period_multiplier = axis < 3 ? 4 : 4; period.push_back(MAX_RANGES[axis] / MAX_SPEED[axis] * period_multiplier); Loading Loading @@ -465,7 +465,7 @@ TEST_F(SRPProgramTrackTest, SineWaveMovementTest) std::this_thread::sleep_for(std::chrono::microseconds((int)round(1000000 * std::max(0.0, next_expected_time - ADVANCE_TIMEGAP - CIRATools::getUNIXEpoch())))); point_id++; for(size_t axis = 0; axis < 6; axis++) for(size_t axis = 0; axis < 3; axis++) { programTrackCoordinates[axis] = MAX_RANGES[axis] * sin((time_delta + phase_shift[axis]) * 2 * M_PI / period[axis]); } Loading