|
1 | 1 | using Aqua |
2 | 2 | using JSON |
3 | 3 | using ModernRoboticsBook |
| 4 | +using StaticArrays |
4 | 5 | using Test |
5 | 6 |
|
6 | 7 | import LinearAlgebra as LA |
@@ -1043,6 +1044,82 @@ Aqua.test_all(ModernRoboticsBook) |
1043 | 1044 | @test_throws ErrorException load_robot(:nonexistent_robot) |
1044 | 1045 | end |
1045 | 1046 |
|
| 1047 | + @testset "zero allocations for core helpers" begin |
| 1048 | + # Inputs as regular Matrix/Vector |
| 1049 | + so3 = [0.0 -3.0 2.0; 3.0 0.0 -1.0; -2.0 1.0 0.0] |
| 1050 | + R = [ |
| 1051 | + -0.694921 0.713521 0.0892929 |
| 1052 | + -0.192007 -0.303785 0.933192 |
| 1053 | + 0.692978 0.63135 0.348107 |
| 1054 | + ] |
| 1055 | + se3 = [ |
| 1056 | + 0.0 -3.0 2.0 4.0 |
| 1057 | + 3.0 0.0 -1.0 5.0 |
| 1058 | + -2.0 1.0 0.0 6.0 |
| 1059 | + 0.0 0.0 0.0 0.0 |
| 1060 | + ] |
| 1061 | + T = [ |
| 1062 | + 1.0 0.0 0.0 0.0 |
| 1063 | + 0.0 0.0 -1.0 0.0 |
| 1064 | + 0.0 1.0 0.0 3.0 |
| 1065 | + 0.0 0.0 0.0 1.0 |
| 1066 | + ] |
| 1067 | + v3 = [1.0, 2.0, 3.0] |
| 1068 | + v6 = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0] |
| 1069 | + |
| 1070 | + # Inputs as SMatrix/SVector |
| 1071 | + sso3 = SMatrix{3,3}(so3) |
| 1072 | + sR = SMatrix{3,3}(R) |
| 1073 | + sse3 = SMatrix{4,4}(se3) |
| 1074 | + sT = SMatrix{4,4}(T) |
| 1075 | + sv3 = SVector{3}(v3) |
| 1076 | + sv6 = SVector{6}(v6) |
| 1077 | + |
| 1078 | + # Warm up all functions (trigger compilation) |
| 1079 | + vec_to_so3(v3); |
| 1080 | + vec_to_so3(sv3) |
| 1081 | + so3_to_vec(so3); |
| 1082 | + so3_to_vec(sso3) |
| 1083 | + matrix_exp3(so3); |
| 1084 | + matrix_exp3(sso3) |
| 1085 | + matrix_log3(R); |
| 1086 | + matrix_log3(sR) |
| 1087 | + vec_to_se3(v6); |
| 1088 | + vec_to_se3(sv6) |
| 1089 | + se3_to_vec(se3); |
| 1090 | + se3_to_vec(sse3) |
| 1091 | + transform_inv(T); |
| 1092 | + transform_inv(sT) |
| 1093 | + adjoint_representation(T); |
| 1094 | + adjoint_representation(sT) |
| 1095 | + matrix_exp6(se3); |
| 1096 | + matrix_exp6(sse3) |
| 1097 | + matrix_log6(T); |
| 1098 | + matrix_log6(sT) |
| 1099 | + ad(v6); |
| 1100 | + ad(sv6) |
| 1101 | + |
| 1102 | + # Test zero allocations with SMatrix/SVector inputs |
| 1103 | + @test @allocated(vec_to_so3(sv3)) == 0 |
| 1104 | + @test @allocated(so3_to_vec(sso3)) == 0 |
| 1105 | + @test @allocated(matrix_exp3(sso3)) == 0 |
| 1106 | + @test @allocated(matrix_log3(sR)) == 0 |
| 1107 | + @test @allocated(vec_to_se3(sv6)) == 0 |
| 1108 | + @test @allocated(se3_to_vec(sse3)) == 0 |
| 1109 | + @test @allocated(transform_inv(sT)) == 0 |
| 1110 | + @test @allocated(adjoint_representation(sT)) == 0 |
| 1111 | + @test @allocated(matrix_exp6(sse3)) == 0 |
| 1112 | + @test @allocated(matrix_log6(sT)) == 0 |
| 1113 | + @test @allocated(ad(sv6)) == 0 |
| 1114 | + |
| 1115 | + # Test zero allocations with regular Matrix/Vector inputs |
| 1116 | + @test @allocated(vec_to_so3(v3)) == 0 |
| 1117 | + @test @allocated(so3_to_vec(so3)) == 0 |
| 1118 | + @test @allocated(vec_to_se3(v6)) == 0 |
| 1119 | + @test @allocated(se3_to_vec(se3)) == 0 |
| 1120 | + @test @allocated(ad(v6)) == 0 |
| 1121 | + end |
| 1122 | + |
1046 | 1123 | @testset "cross-validate UR5 against Pinocchio" begin |
1047 | 1124 | # Pinocchio reference uses gravity [0, 0, -9.81] which matches our default |
1048 | 1125 | robot = load_robot(:ur5) |
|
0 commit comments