2
2
3
3
import static org .junit .Assert .*;
4
4
5
+ import org .apache .commons .math3 .geometry .euclidean .threed .RotationConvention ;
6
+ import org .apache .commons .math3 .geometry .euclidean .threed .RotationOrder ;
5
7
import org .junit .Test ;
6
8
7
9
import com .neuronrobotics .sdk .addons .kinematics .math .RotationNR ;
@@ -19,50 +21,66 @@ public class RotationNRTest {
19
21
@ Test
20
22
public void test () {
21
23
int failCount = 0 ;
22
- int iterations = 100 ;
23
- for (int i = 0 ; i < iterations ; i ++) {
24
- double tilt = Math .toRadians ((Math .random () *360.0 ) -180 );
25
- double elevation = Math .toRadians ((Math .random () * 360.0 ) -180 );
26
- double azumus = Math .toRadians ((Math .random () * 360.0 ) -180 );
27
- RotationNR rotTest = new RotationNR (Math .toDegrees (tilt ), Math .toDegrees (azumus ),
28
- Math .toDegrees (elevation ));
29
- System .out .println ("\n \n Test #" + i );
30
- System .out .println ("Testing Az=" + Math .toDegrees (azumus ) + " El=" + Math .toDegrees (elevation ) + " Tl="
31
- + Math .toDegrees (tilt ));
32
- System .out .println ("Got Az=" + Math .toDegrees (rotTest .getRotationAzimuth ()) + " El="
33
- + Math .toDegrees (rotTest .getRotationElevation ()) + " Tl="
34
- + Math .toDegrees (rotTest .getRotationTilt ()));
35
-
36
- if (!RotationNR .bound (tilt - .01 , tilt + .01 , rotTest .getRotationTilt ())) {
37
- failCount ++;
38
- System .err .println ("Rotation Tilt is not consistant. expected " + Math .toDegrees (tilt ) + " got "
39
- + Math .toDegrees (rotTest .getRotationTilt ())+
40
- " \t \t Off By " +(Math .toDegrees (tilt ) - Math .toDegrees (rotTest .getRotationTilt ()) )
41
- );
42
- }
43
- if (!RotationNR .bound (elevation - .01 , elevation + .01 , rotTest .getRotationElevation ())) {
44
- failCount ++;
45
- System .err .println ("Rotation Elevation is not consistant. expected " + Math .toDegrees (elevation )
46
- + " got " + Math .toDegrees (rotTest .getRotationElevation ())+
47
- " \t \t Off By " +(Math .toDegrees (elevation ) + Math .toDegrees (rotTest .getRotationElevation ()) )
48
-
49
- );
50
- }
51
- if (!RotationNR .bound (azumus - .01 , azumus + .01 , rotTest .getRotationAzimuth ())) {
52
- failCount ++;
53
- System .err .println ("Rotation Tilt is not consistant. expected " + Math .toDegrees (azumus ) + " got "
54
- + Math .toDegrees (rotTest .getRotationAzimuth ())+
55
- " \t \t Off By " +(Math .toDegrees (azumus ) - Math .toDegrees (rotTest .getRotationAzimuth ()) )
24
+ int iterations = 10 ;
25
+ RotationOrder [] list = { RotationOrder .XYZ ,
26
+ RotationOrder .XZY , RotationOrder .YXZ , RotationOrder .YZX ,
27
+ RotationOrder .ZXY , RotationOrder .ZYX , RotationOrder .XYX , RotationOrder .XZX , RotationOrder .YXY ,
28
+ RotationOrder .YZY , RotationOrder .ZXZ , RotationOrder .ZYZ
29
+
30
+ };
31
+ RotationConvention [] conventions = { RotationConvention .FRAME_TRANSFORM , RotationConvention .VECTOR_OPERATOR };
32
+ for (RotationConvention conv : conventions ) {
33
+ RotationNR .setConvention (conv );
34
+ System .out .println ("\n \n Using convention " + conv .toString ());
35
+ for (RotationOrder ro : list ) {
36
+ RotationNR .setOrder (ro );
37
+ System .out .println ("\n \n Using rotationOrder " + ro .toString ());
38
+ failCount = 0 ;
39
+ for (int i = 0 ; i < iterations ; i ++) {
40
+ double tilt = Math .toRadians ((Math .random () * 359 ) - 179.5 );
41
+ double elevation = Math .toRadians ((Math .random () * 359 ) - 179.5 );
42
+ double azumus = Math .toRadians ((Math .random () * 359 ) - 179.5 );
43
+ RotationNR rotTest = new RotationNR (Math .toDegrees (tilt ), Math .toDegrees (azumus ),
44
+ Math .toDegrees (elevation ));
45
+ System .out .println ("\n \n Test #" + i );
46
+ System .out .println ("Testing Az=" + Math .toDegrees (azumus ) + " El=" + Math .toDegrees (elevation )
47
+ + " Tl=" + Math .toDegrees (tilt ));
48
+ System .out .println ("Got Az=" + Math .toDegrees (rotTest .getRotationAzimuth ()) + " El="
49
+ + Math .toDegrees (rotTest .getRotationElevation ()) + " Tl="
50
+ + Math .toDegrees (rotTest .getRotationTilt ()));
51
+
52
+ if (!RotationNR .bound (tilt - .01 , tilt + .01 , rotTest .getRotationTilt ())) {
53
+ failCount ++;
54
+ System .err .println ("Rotation Tilt is not consistant. expected " + Math .toDegrees (tilt ) + " got "
55
+ + Math .toDegrees (rotTest .getRotationTilt ()) + " \t \t Off By "
56
+ + (Math .toDegrees (tilt ) - Math .toDegrees (rotTest .getRotationTilt ())));
57
+ }
58
+ if (!RotationNR .bound (elevation - .01 , elevation + .01 , rotTest .getRotationElevation ())) {
59
+ failCount ++;
60
+ System .err .println ("Rotation Elevation is not consistant. expected " + Math .toDegrees (elevation )
61
+ + " got " + Math .toDegrees (rotTest .getRotationElevation ()) + " \t \t Off By "
62
+ + (Math .toDegrees (elevation ) + Math .toDegrees (rotTest .getRotationElevation ()))
63
+
56
64
);
65
+ }
66
+ if (!RotationNR .bound (azumus - .01 , azumus + .01 , rotTest .getRotationAzimuth ())) {
67
+ failCount ++;
68
+ System .err .println ("Rotation azumus is not consistant. expected " + Math .toDegrees (azumus )
69
+ + " got " + Math .toDegrees (rotTest .getRotationAzimuth ()) + " \t \t Off By "
70
+ + (Math .toDegrees (azumus ) - Math .toDegrees (rotTest .getRotationAzimuth ())));
71
+ }
72
+ ThreadUtil .wait (20 );
73
+ }
74
+ if (failCount < 1 ) {
75
+ System .out .println ("Orentation " + ro .toString () + " worked ina all cases" );
76
+ return ;
77
+ }
57
78
}
58
- ThreadUtil .wait (20 );
59
79
}
60
-
61
80
if (failCount > 1 ) {
62
- fail ("Rotation failed " + failCount + " times of " + iterations * 3 );
81
+ fail ("Rotation failed " + failCount + " times of " + (( iterations * 3 * list . length ) - 0 ) );
63
82
64
83
}
65
-
66
84
}
67
85
68
86
}
0 commit comments