30 #include <gtest/gtest.h> 40 timeval temp_time_struct;
41 gettimeofday(&temp_time_struct,NULL);
42 srand(temp_time_struct.tv_usec);
50 unsigned int runs = 100;
55 std::vector<double>
values(runs);
60 for ( uint64_t i = 1; i < runs ; i++ )
62 values[i] = 10.0 * ((double) rand() - (double)RAND_MAX /2.0) /(double)RAND_MAX;
74 for ( uint64_t i = 1; i < runs ; i++ )
86 unsigned int runs = 100;
91 std::vector<double>
values(runs);
96 for (
int i = runs -1; i >= 0 ; i-- )
98 values[i] = 10.0 * ((double) rand() - (double)RAND_MAX /2.0) /(double)RAND_MAX;
107 for ( uint64_t i = 1; i < runs ; i++ )
121 double my_vals[] = {13,2,5,4,9,7,3,11,15,14,12,1,6,10,0,8};
122 std::vector<double>
values (my_vals, my_vals +
sizeof(my_vals)/
sizeof(
double));
123 unsigned int runs = values.size();
128 for ( uint64_t i = 0; i <runs ; i++ )
130 values[i] = 10.0 * ((double) rand() - (double)RAND_MAX /2.0) /(double)RAND_MAX;
139 for ( uint64_t i = 1; i < runs ; i++ )
154 std::vector<double>
values(runs);
159 for ( uint64_t i = 0; i <runs ; i++ )
161 values[i] = 10.0 * ((double) rand() - (double)RAND_MAX /2.0) /(double)RAND_MAX;
173 for ( uint64_t i = 1; i < runs ; i++ )
202 std::vector<double> xvalues(2);
203 std::vector<double> yvalues(2);
204 std::vector<double> zvalues(2);
206 uint64_t offset = 200;
211 for ( uint64_t i = 1; i < runs ; i++ )
215 xvalues[
step] = 10.0 * ((double) rand() - (double)RAND_MAX /2.0) /(double)RAND_MAX;
216 yvalues[
step] = 10.0 * ((double) rand() - (double)RAND_MAX /2.0) /(double)RAND_MAX;
217 zvalues[
step] = 10.0 * ((double) rand() - (double)RAND_MAX /2.0) /(double)RAND_MAX;
226 for (
int pos = 0; pos < 100 ; pos++)
232 EXPECT_NEAR(xvalues[0] + (xvalues[1] - xvalues[0]) * (
double)pos/100.0, x_out, epsilon);
233 EXPECT_NEAR(yvalues[0] + (yvalues[1] - yvalues[0]) * (
double)pos/100.0, y_out, epsilon);
234 EXPECT_NEAR(zvalues[0] + (zvalues[1] - zvalues[0]) * (
double)pos/100.0, z_out, epsilon);
350 for (uint64_t i = 0 ; i < runs ; i++)
352 q2.
setEuler(1.0 * ((
double) rand() - (
double)RAND_MAX /2.0) /(
double)RAND_MAX,
353 1.0 * ((
double) rand() - (
double)RAND_MAX /2.0) /(
double)RAND_MAX,
354 1.0 * ((
double) rand() - (
double)RAND_MAX /2.0) /(
double)RAND_MAX);
359 EXPECT_NEAR(q3.
angle(q1), q2.
angle(q3), 1e-5);
372 std::vector<double> yawvalues(2);
373 std::vector<double> pitchvalues(2);
374 std::vector<double> rollvalues(2);
375 uint64_t offset = 200;
377 std::vector<tf::Quaternion> quats(2);
382 for ( uint64_t i = 1; i < runs ; i++ )
386 yawvalues[
step] = 10.0 * ((double) rand() - (double)RAND_MAX /2.0) /(double)RAND_MAX / 100.0;
387 pitchvalues[
step] = 0;
388 rollvalues[
step] = 0;
389 quats[
step].setRPY(yawvalues[
step], pitchvalues[step], rollvalues[step]);
397 for (
int pos = 0; pos < 100 ; pos ++)
406 EXPECT_NEAR(0,
angle(ground_truth, quat), epsilon);
431 EXPECT_TRUE(!std::isnan(stor.
rotation_.x()));
432 EXPECT_TRUE(!std::isnan(stor.
rotation_.y()));
433 EXPECT_TRUE(!std::isnan(stor.
rotation_.z()));
434 EXPECT_TRUE(!std::isnan(stor.
rotation_.w()));
438 int main(
int argc,
char **argv){
439 testing::InitGoogleTest(&argc, argv);
440 return RUN_ALL_TESTS();
The Quaternion implements quaternion to perform linear algebra rotations in combination with Matrix3x...
TEST(TimeCache, Repeatability)
Time & fromNSec(uint64_t t)
std::vector< double > values
A class to keep a sorted linked list in time This builds and maintains a list of timestamped data...
Quaternion slerp(const Quaternion &q, const tfScalar &t) const
Return the quaternion which is the result of Spherical Linear Interpolation between this and the othe...
TFSIMD_FORCE_INLINE Quaternion slerp(const Quaternion &q1, const Quaternion &q2, const tfScalar &t)
Return the result of spherical linear interpolation betwen two quaternions.
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
Return the ***half*** angle between two quaternions.
int main(int argc, char **argv)
TFSIMD_FORCE_INLINE const tfScalar & x() const
Return the x value.
tfScalar angle(const Quaternion &q) const
Return the ***half*** angle between this quaternion and the other.
TFSIMD_FORCE_INLINE const tfScalar & z() const
Return the z value.
bool insertData(const TransformStorage &new_data)
TFSIMD_FORCE_INLINE const tfScalar & y() const
Return the y value.
void setEuler(const tfScalar &yaw, const tfScalar &pitch, const tfScalar &roll)
Set the quaternion using Euler angles.
bool getData(ros::Time time, TransformStorage &data_out, std::string *error_str=0)
Vector3 can be used to represent 3D points and vectors. It has an un-used w component to suit 16-byte...