fixed_point_test.cpp
Go to the documentation of this file.
00001 
00025 #include <gtest/gtest.h>
00026 #include <iostream>
00027 #include "puma_motor_driver/driver.h"
00028 #include "puma_motor_driver/message.h"
00029 
00030 TEST(TestFixedPoint16x16, test16x16interpret)
00031 {
00032   double cases[7] =
00033   {
00034     0.0,
00035     1.0,
00036     -1.0,
00037     -0.00001,
00038     5000.00001,
00039     32000.000025,
00040     -32000.000025
00041   };
00042 
00043   for (int i = 0; i < 7; i++)
00044   {
00045     puma_motor_driver::Driver::StatusField status;
00046     int32_t input = cases[i] * static_cast<double>(1<<16);
00047     memcpy(&status.data, &input, 4);
00048     EXPECT_NEAR(cases[i], status.interpretFixed16x16(), 1.0 / static_cast<double>(1<<16));
00049   }
00050 }
00051 
00052 TEST(TestFixedPoint8x8, test8x8interpret)
00053 {
00054   float cases[7] =
00055   {
00056     0.0,
00057     1.0,
00058     -1.0,
00059     -0.00001,
00060     127.001,
00061     -127.002,
00062     123.42678
00063   };
00064 
00065   for (int i = 0; i < 7; i++)
00066   {
00067     puma_motor_driver::Driver::StatusField status;
00068     int16_t input = cases[i] * static_cast<float>(1<<8);
00069     memcpy(&status.data, &input, 2);
00070     EXPECT_NEAR(cases[i], status.interpretFixed8x8(), 1.0 / static_cast<float>(1<<8));
00071   }
00072 }
00073 
00074 int main(int argc, char **argv)
00075 {
00076   testing::InitGoogleTest(&argc, argv);
00077   return RUN_ALL_TESTS();
00078 }


puma_motor_driver
Author(s):
autogenerated on Sat Jun 8 2019 18:55:15