system.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002  * C++ unit test for oxford_gps_eth
00003  * Verify correct handling of UDP packets
00004  *********************************************************************/
00005 
00006 #include <gtest/gtest.h>
00007 
00008 #include <ros/ros.h>
00009 #include <sensor_msgs/NavSatFix.h>
00010 #include <sensor_msgs/Imu.h>
00011 #include <geometry_msgs/TwistWithCovarianceStamped.h>
00012 
00013 // Tf Quaternions
00014 #include <tf/LinearMath/Quaternion.h>
00015 
00016 // Ethernet
00017 #include <arpa/inet.h>
00018 #include <sys/socket.h>
00019 
00020 // Helper classes
00021 #include "MsgRx.h"
00022 
00023 // Packet structure
00024 #include "../src/dispatch.h"
00025 
00026 // Parameters
00027 std::string g_ip_address = "";
00028 int g_port = 3000;
00029 std::string g_frame_id_gps = "gps";
00030 std::string g_frame_id_vel = "enu";
00031 std::string g_frame_id_odom = "base_footprint";
00032 
00033 // Subscribed topics
00034 ros::Subscriber g_sub_fix;
00035 ros::Subscriber g_sub_vel;
00036 ros::Subscriber g_sub_imu;
00037 
00038 // Received messages
00039 MsgRx<sensor_msgs::NavSatFix> g_msg_fix;
00040 MsgRx<geometry_msgs::TwistWithCovarianceStamped> g_msg_vel;
00041 MsgRx<sensor_msgs::Imu> g_msg_imu;
00042 void recvClear() {
00043   g_msg_fix.clear();
00044   g_msg_vel.clear();
00045   g_msg_imu.clear();
00046 }
00047 
00048 // Subscriber receive callbacks
00049 void recvGpsFix(const sensor_msgs::NavSatFix::ConstPtr& msg) { g_msg_fix.set(*msg); }
00050 void recvGpsVel(const geometry_msgs::TwistWithCovarianceStamped::ConstPtr& msg) { g_msg_vel.set(*msg); }
00051 void recvImuData(const sensor_msgs::Imu::ConstPtr& msg) { g_msg_imu.set(*msg); }
00052 
00053 // Set sync byte and apply checksums
00054 static void fixPacket(Packet &packet) {
00055   packet.sync = 0xE7;
00056   const uint8_t *ptr = ((uint8_t*)&packet) + 1;
00057   uint8_t chksum = 0;
00058   for (; ptr < &packet.chksum1; ptr++) {
00059     chksum += *ptr;
00060   }
00061   packet.chksum1 = chksum;
00062   for (; ptr < &packet.chksum2; ptr++) {
00063     chksum += *ptr;
00064   }
00065   packet.chksum2 = chksum;
00066   for (; ptr < &packet.chksum3; ptr++) {
00067     chksum += *ptr;
00068   }
00069   packet.chksum3 = chksum;
00070 }
00071 
00072 // Open socket and send UDP packet
00073 static bool sendPacket(const Packet &packet) {
00074   recvClear();
00075   static int fd = -1;
00076   if (fd == -1) {
00077     fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); // Create UDP socket
00078   }
00079   if (fd != -1) {
00080     struct sockaddr_in si_other;
00081     memset(&si_other, 0x00, sizeof(si_other));
00082     si_other.sin_family = AF_INET;
00083     si_other.sin_port = htons(g_port);
00084     if (inet_aton(g_ip_address.c_str(), &si_other.sin_addr)) {
00085       if (sendto(fd, &packet, sizeof(packet), 0, (struct sockaddr *) &si_other, sizeof(si_other)) == sizeof(packet)) {
00086         return true;
00087       }
00088     }
00089   }
00090   return false;
00091 }
00092 
00093 // Helper wait functions
00094 static inline double SQUARE(double x) { return x * x; }
00095 static bool waitForTopics(ros::WallDuration dur) {
00096   const ros::WallTime start = ros::WallTime::now();
00097   while (true) {
00098     if ((g_sub_fix.getNumPublishers() == 1) &&
00099         (g_sub_vel.getNumPublishers() == 1) &&
00100         (g_sub_imu.getNumPublishers() == 1)) {
00101       return true;
00102     }
00103     if ((ros::WallTime::now() - start) > dur) {
00104       return false;
00105     }
00106     ros::WallDuration(0.001).sleep();
00107     ros::spinOnce();
00108   }
00109 }
00110 static bool waitForMsgs(ros::WallDuration dur) {
00111   const ros::WallTime start = ros::WallTime::now();
00112   while (true) {
00113     if (g_msg_fix.valid() && g_msg_vel.valid() && g_msg_imu.valid()) {
00114       return true;
00115     }
00116     if ((ros::WallTime::now() - start) > dur) {
00117       return false;
00118     }
00119     ros::WallDuration(0.001).sleep();
00120     ros::spinOnce();
00121   }
00122 }
00123 
00124 // Wait for node to startup and verify connections
00125 TEST(Main, topics)
00126 {
00127   EXPECT_TRUE(waitForTopics(ros::WallDuration(2.0)));
00128   ASSERT_EQ(1, g_sub_fix.getNumPublishers());
00129   ASSERT_EQ(1, g_sub_vel.getNumPublishers());
00130   ASSERT_EQ(1, g_sub_imu.getNumPublishers());
00131   EXPECT_FALSE(g_msg_fix.valid());
00132   EXPECT_FALSE(g_msg_vel.valid());
00133   EXPECT_FALSE(g_msg_imu.valid());
00134 }
00135 
00136 // Verify correct handling of packets
00137 TEST(Main, packets)
00138 {
00139   // Variables
00140   Packet packet;
00141   const ros::WallDuration DURATION(0.2);
00142   memset(&packet, 0x00, sizeof(packet));
00143 
00144   // Empty packet should fail the sync byte and checksum tests
00145   ASSERT_TRUE(sendPacket(packet));
00146   EXPECT_FALSE(waitForMsgs(DURATION));
00147   EXPECT_FALSE(g_msg_fix.valid());
00148   EXPECT_FALSE(g_msg_vel.valid());
00149   EXPECT_FALSE(g_msg_imu.valid());
00150 
00151   // Empty packet should fail because nav_status is missing
00152   fixPacket(packet);
00153   ASSERT_TRUE(sendPacket(packet));
00154   EXPECT_FALSE(waitForMsgs(DURATION));
00155   EXPECT_FALSE(g_msg_fix.valid());
00156   EXPECT_FALSE(g_msg_vel.valid());
00157   EXPECT_FALSE(g_msg_imu.valid());
00158 
00159   // Just enough data for a successful packet
00160   packet.nav_status = 4;
00161   fixPacket(packet);
00162   ASSERT_TRUE(sendPacket(packet));
00163   EXPECT_TRUE(waitForMsgs(DURATION));
00164   ASSERT_TRUE(g_msg_fix.valid());
00165   ASSERT_TRUE(g_msg_vel.valid());
00166   ASSERT_TRUE(g_msg_imu.valid());
00167 }
00168 
00169 // Verify message frame_ids and timestamps
00170 TEST(Main, header)
00171 {
00172   // Variables
00173   Packet packet;
00174   const ros::WallDuration DURATION(0.2);
00175   memset(&packet, 0x00, sizeof(packet));
00176 
00177   // Verify that all messages have the same non-zero timestamp and that the frame_ids are correct
00178   ros::Time stamp = ros::Time::now();
00179   packet.nav_status = 4;
00180   fixPacket(packet);
00181   ASSERT_TRUE(sendPacket(packet));
00182   EXPECT_TRUE(waitForMsgs(DURATION));
00183   ASSERT_TRUE(g_msg_fix.valid());
00184   ASSERT_TRUE(g_msg_vel.valid());
00185   ASSERT_TRUE(g_msg_imu.valid());
00186   EXPECT_STREQ(g_msg_fix.get().header.frame_id.c_str(), g_frame_id_gps.c_str());
00187   EXPECT_STREQ(g_msg_vel.get().header.frame_id.c_str(), g_frame_id_vel.c_str());
00188   EXPECT_STREQ(g_msg_imu.get().header.frame_id.c_str(), g_frame_id_gps.c_str());
00189   EXPECT_EQ(g_msg_fix.get().header.stamp, g_msg_vel.get().header.stamp);
00190   EXPECT_EQ(g_msg_fix.get().header.stamp, g_msg_imu.get().header.stamp);
00191   EXPECT_NE(g_msg_fix.get().header.stamp, ros::Time(0));
00192   EXPECT_NEAR((g_msg_fix.get().header.stamp - stamp).toSec(), 0, 0.01);
00193 }
00194 
00195 // Verify correct fields in the sensor_msgs::NavSatFix message
00196 TEST(Main, fix)
00197 {
00198   // Variables
00199   Packet packet;
00200   const ros::WallDuration DURATION(0.2);
00201   memset(&packet, 0x00, sizeof(packet));
00202 
00203   // Send valid packet
00204   packet.nav_status = 4;
00205   packet.latitude = 1.23456789012345;
00206   packet.longitude = 9.87654321098765;
00207   packet.altitude = 1.234567;
00208   fixPacket(packet);
00209   ASSERT_TRUE(sendPacket(packet));
00210   EXPECT_TRUE(waitForMsgs(DURATION));
00211   ASSERT_TRUE(g_msg_fix.valid());
00212   ASSERT_TRUE(g_msg_vel.valid());
00213   ASSERT_TRUE(g_msg_imu.valid());
00214   EXPECT_STREQ(g_msg_fix.get().header.frame_id.c_str(), g_frame_id_gps.c_str());
00215   EXPECT_EQ(g_msg_fix.get().status.status, sensor_msgs::NavSatStatus::STATUS_NO_FIX);
00216   EXPECT_EQ(g_msg_fix.get().status.service, sensor_msgs::NavSatStatus::SERVICE_GPS);
00217   EXPECT_EQ(g_msg_fix.get().latitude, packet.latitude * (180 / M_PI));
00218   EXPECT_EQ(g_msg_fix.get().longitude, packet.longitude * (180 / M_PI));
00219   EXPECT_EQ(g_msg_fix.get().altitude, packet.altitude);
00220   EXPECT_EQ(g_msg_fix.get().position_covariance_type, sensor_msgs::NavSatFix::COVARIANCE_TYPE_UNKNOWN);
00221   EXPECT_EQ(g_msg_fix.get().position_covariance[0], 0);
00222   EXPECT_EQ(g_msg_fix.get().position_covariance[1], 0);
00223   EXPECT_EQ(g_msg_fix.get().position_covariance[2], 0);
00224   EXPECT_EQ(g_msg_fix.get().position_covariance[3], 0);
00225   EXPECT_EQ(g_msg_fix.get().position_covariance[4], 0);
00226   EXPECT_EQ(g_msg_fix.get().position_covariance[5], 0);
00227   EXPECT_EQ(g_msg_fix.get().position_covariance[6], 0);
00228   EXPECT_EQ(g_msg_fix.get().position_covariance[7], 0);
00229   EXPECT_EQ(g_msg_fix.get().position_covariance[8], 0);
00230 
00231   // Set position mode on channel 0
00232   memset(&packet.chan, 0x00, sizeof(packet.chan));
00233   packet.channel = 0;
00234   packet.chan.chan0.position_mode = MODE_RTK_INTEGER;
00235   fixPacket(packet);
00236   ASSERT_TRUE(sendPacket(packet));
00237   EXPECT_TRUE(waitForMsgs(DURATION));
00238   ASSERT_TRUE(g_msg_fix.valid());
00239   ASSERT_TRUE(g_msg_vel.valid());
00240   ASSERT_TRUE(g_msg_imu.valid());
00241   EXPECT_STREQ(g_msg_fix.get().header.frame_id.c_str(), g_frame_id_gps.c_str());
00242   EXPECT_EQ(g_msg_fix.get().status.status, sensor_msgs::NavSatStatus::STATUS_GBAS_FIX);
00243   EXPECT_EQ(g_msg_fix.get().status.service, sensor_msgs::NavSatStatus::SERVICE_GPS);
00244   EXPECT_EQ(g_msg_fix.get().latitude, packet.latitude * (180 / M_PI));
00245   EXPECT_EQ(g_msg_fix.get().longitude, packet.longitude * (180 / M_PI));
00246   EXPECT_EQ(g_msg_fix.get().altitude, packet.altitude);
00247   EXPECT_EQ(g_msg_fix.get().position_covariance_type, sensor_msgs::NavSatFix::COVARIANCE_TYPE_UNKNOWN);
00248   EXPECT_EQ(g_msg_fix.get().position_covariance[0], 0);
00249   EXPECT_EQ(g_msg_fix.get().position_covariance[1], 0);
00250   EXPECT_EQ(g_msg_fix.get().position_covariance[2], 0);
00251   EXPECT_EQ(g_msg_fix.get().position_covariance[3], 0);
00252   EXPECT_EQ(g_msg_fix.get().position_covariance[4], 0);
00253   EXPECT_EQ(g_msg_fix.get().position_covariance[5], 0);
00254   EXPECT_EQ(g_msg_fix.get().position_covariance[6], 0);
00255   EXPECT_EQ(g_msg_fix.get().position_covariance[7], 0);
00256   EXPECT_EQ(g_msg_fix.get().position_covariance[8], 0);
00257 
00258   // Set position covariance on channel 3
00259   memset(&packet.chan, 0x00, sizeof(packet.chan));
00260   packet.channel = 3;
00261   packet.chan.chan3.age = 10;
00262   packet.chan.chan3.acc_position_east  = 123;
00263   packet.chan.chan3.acc_position_north = 1234;
00264   packet.chan.chan3.acc_position_down  = 12345;
00265   fixPacket(packet);
00266   ASSERT_TRUE(sendPacket(packet));
00267   EXPECT_TRUE(waitForMsgs(DURATION));
00268   ASSERT_TRUE(g_msg_fix.valid());
00269   ASSERT_TRUE(g_msg_vel.valid());
00270   ASSERT_TRUE(g_msg_imu.valid());
00271   EXPECT_STREQ(g_msg_fix.get().header.frame_id.c_str(), g_frame_id_gps.c_str());
00272   EXPECT_EQ(g_msg_fix.get().status.status, sensor_msgs::NavSatStatus::STATUS_GBAS_FIX);
00273   EXPECT_EQ(g_msg_fix.get().status.service, sensor_msgs::NavSatStatus::SERVICE_GPS);
00274   EXPECT_EQ(g_msg_fix.get().latitude, packet.latitude * (180 / M_PI));
00275   EXPECT_EQ(g_msg_fix.get().longitude, packet.longitude * (180 / M_PI));
00276   EXPECT_EQ(g_msg_fix.get().altitude, packet.altitude);
00277   EXPECT_EQ(g_msg_fix.get().position_covariance_type, sensor_msgs::NavSatFix::COVARIANCE_TYPE_DIAGONAL_KNOWN);
00278   EXPECT_EQ(g_msg_fix.get().position_covariance[0], SQUARE(packet.chan.chan3.acc_position_east * 1e-3)); // x
00279   EXPECT_EQ(g_msg_fix.get().position_covariance[1], 0);
00280   EXPECT_EQ(g_msg_fix.get().position_covariance[2], 0);
00281   EXPECT_EQ(g_msg_fix.get().position_covariance[3], 0);
00282   EXPECT_EQ(g_msg_fix.get().position_covariance[4], SQUARE(packet.chan.chan3.acc_position_north * 1e-3)); // y
00283   EXPECT_EQ(g_msg_fix.get().position_covariance[5], 0);
00284   EXPECT_EQ(g_msg_fix.get().position_covariance[6], 0);
00285   EXPECT_EQ(g_msg_fix.get().position_covariance[7], 0);
00286   EXPECT_EQ(g_msg_fix.get().position_covariance[8], SQUARE(packet.chan.chan3.acc_position_down * 1e-3)); // z
00287 
00288   // Set position covariance on channel 3 with old age
00289   memset(&packet.chan, 0x00, sizeof(packet.chan));
00290   packet.channel = 3;
00291   packet.chan.chan3.age = 190;
00292   packet.chan.chan3.acc_position_east  = 123;
00293   packet.chan.chan3.acc_position_north = 1234;
00294   packet.chan.chan3.acc_position_down  = 12345;
00295   fixPacket(packet);
00296   ASSERT_TRUE(sendPacket(packet));
00297   EXPECT_TRUE(waitForMsgs(DURATION));
00298   ASSERT_TRUE(g_msg_fix.valid());
00299   ASSERT_TRUE(g_msg_vel.valid());
00300   ASSERT_TRUE(g_msg_imu.valid());
00301   EXPECT_STREQ(g_msg_fix.get().header.frame_id.c_str(), g_frame_id_gps.c_str());
00302   EXPECT_EQ(g_msg_fix.get().status.status, sensor_msgs::NavSatStatus::STATUS_GBAS_FIX);
00303   EXPECT_EQ(g_msg_fix.get().status.service, sensor_msgs::NavSatStatus::SERVICE_GPS);
00304   EXPECT_EQ(g_msg_fix.get().latitude, packet.latitude * (180 / M_PI));
00305   EXPECT_EQ(g_msg_fix.get().longitude, packet.longitude * (180 / M_PI));
00306   EXPECT_EQ(g_msg_fix.get().altitude, packet.altitude);
00307   EXPECT_EQ(g_msg_fix.get().position_covariance_type, sensor_msgs::NavSatFix::COVARIANCE_TYPE_UNKNOWN);
00308   EXPECT_EQ(g_msg_fix.get().position_covariance[0], 0);
00309   EXPECT_EQ(g_msg_fix.get().position_covariance[1], 0);
00310   EXPECT_EQ(g_msg_fix.get().position_covariance[2], 0);
00311   EXPECT_EQ(g_msg_fix.get().position_covariance[3], 0);
00312   EXPECT_EQ(g_msg_fix.get().position_covariance[4], 0);
00313   EXPECT_EQ(g_msg_fix.get().position_covariance[5], 0);
00314   EXPECT_EQ(g_msg_fix.get().position_covariance[6], 0);
00315   EXPECT_EQ(g_msg_fix.get().position_covariance[7], 0);
00316   EXPECT_EQ(g_msg_fix.get().position_covariance[8], 0);
00317 }
00318 
00319 // Verify correct fields in the geometry_msgs::TwistWithCovarianceStamped message
00320 TEST(Main, vel)
00321 {
00322   // Variables
00323   Packet packet;
00324   const ros::WallDuration DURATION(0.2);
00325   memset(&packet, 0x00, sizeof(packet));
00326 
00327   // Send valid packet
00328   packet.nav_status = 4;
00329   packet.vel_east  =  1234567;
00330   packet.vel_north = -7654321;
00331   packet.vel_down  =  3456789;
00332   fixPacket(packet);
00333   ASSERT_TRUE(sendPacket(packet));
00334   EXPECT_TRUE(waitForMsgs(DURATION));
00335   ASSERT_TRUE(g_msg_fix.valid());
00336   ASSERT_TRUE(g_msg_vel.valid());
00337   ASSERT_TRUE(g_msg_imu.valid());
00338   EXPECT_STREQ(g_msg_vel.get().header.frame_id.c_str(), g_frame_id_vel.c_str());
00339   EXPECT_EQ(g_msg_vel.get().twist.twist.linear.x, (double)packet.vel_east  * 1e-4);
00340   EXPECT_EQ(g_msg_vel.get().twist.twist.linear.y, (double)packet.vel_north * 1e-4);
00341   EXPECT_EQ(g_msg_vel.get().twist.twist.linear.z, (double)packet.vel_down * -1e-4);
00342   for (size_t i = 0; i < g_msg_vel.get().twist.covariance.size(); i++) {
00343     EXPECT_EQ(g_msg_vel.get().twist.covariance[i], 0);
00344   }
00345 
00346   // Set velocity covariance on channel 4
00347   memset(&packet.chan, 0x00, sizeof(packet.chan));
00348   packet.channel = 4;
00349   packet.chan.chan4.age = 10;
00350   packet.chan.chan4.acc_velocity_east  = 123;
00351   packet.chan.chan4.acc_velocity_north = 1234;
00352   packet.chan.chan4.acc_velocity_down  = 12345;
00353   fixPacket(packet);
00354   ASSERT_TRUE(sendPacket(packet));
00355   EXPECT_TRUE(waitForMsgs(DURATION));
00356   ASSERT_TRUE(g_msg_fix.valid());
00357   ASSERT_TRUE(g_msg_vel.valid());
00358   ASSERT_TRUE(g_msg_imu.valid());
00359   EXPECT_STREQ(g_msg_vel.get().header.frame_id.c_str(), g_frame_id_vel.c_str());
00360   EXPECT_EQ(g_msg_vel.get().twist.twist.linear.x, (double)packet.vel_east  * 1e-4);
00361   EXPECT_EQ(g_msg_vel.get().twist.twist.linear.y, (double)packet.vel_north * 1e-4);
00362   EXPECT_EQ(g_msg_vel.get().twist.twist.linear.z, (double)packet.vel_down * -1e-4);
00363   EXPECT_EQ(g_msg_vel.get().twist.covariance[0], SQUARE(packet.chan.chan4.acc_velocity_east  * 1e-3)); // x
00364   EXPECT_EQ(g_msg_vel.get().twist.covariance[7], SQUARE(packet.chan.chan4.acc_velocity_north * 1e-3)); // y
00365   EXPECT_EQ(g_msg_vel.get().twist.covariance[14], SQUARE(packet.chan.chan4.acc_velocity_down * 1e-3)); // z
00366 
00367   // Set velocity covariance on channel 4 with old age
00368   memset(&packet.chan, 0x00, sizeof(packet.chan));
00369   packet.channel = 4;
00370   packet.chan.chan4.age = 190;
00371   packet.chan.chan4.acc_velocity_east  = 123;
00372   packet.chan.chan4.acc_velocity_north = 1234;
00373   packet.chan.chan4.acc_velocity_down  = 12345;
00374   fixPacket(packet);
00375   ASSERT_TRUE(sendPacket(packet));
00376   EXPECT_TRUE(waitForMsgs(DURATION));
00377   ASSERT_TRUE(g_msg_fix.valid());
00378   ASSERT_TRUE(g_msg_vel.valid());
00379   ASSERT_TRUE(g_msg_imu.valid());
00380   EXPECT_STREQ(g_msg_vel.get().header.frame_id.c_str(), g_frame_id_vel.c_str());
00381   EXPECT_EQ(g_msg_vel.get().twist.twist.linear.x, (double)packet.vel_east  * 1e-4);
00382   EXPECT_EQ(g_msg_vel.get().twist.twist.linear.y, (double)packet.vel_north * 1e-4);
00383   EXPECT_EQ(g_msg_vel.get().twist.twist.linear.z, (double)packet.vel_down * -1e-4);
00384   for (size_t i = 0; i < g_msg_vel.get().twist.covariance.size(); i++) {
00385     EXPECT_EQ(g_msg_vel.get().twist.covariance[i], 0);
00386   }
00387 }
00388 
00389 // Verify correct fields in the sensor_msgs::Imu message
00390 TEST(Main, imu)
00391 {
00392   // Variables
00393   Packet packet;
00394   const ros::WallDuration DURATION(0.2);
00395   memset(&packet, 0x00, sizeof(packet));
00396   tf::Quaternion q;
00397 
00398   // Send valid packet
00399   packet.nav_status = 4;
00400   packet.accel_x =  1234567;
00401   packet.accel_y = -7654321;
00402   packet.accel_z =  3456789;
00403   packet.gyro_x  =  2345678;
00404   packet.gyro_y  = -6543210;
00405   packet.gyro_z  =  4567890;
00406   packet.heading =  5678901;
00407   packet.pitch   =  -123456;
00408   packet.roll    =   234567;
00409   fixPacket(packet);
00410   ASSERT_TRUE(sendPacket(packet));
00411   EXPECT_TRUE(waitForMsgs(DURATION));
00412   ASSERT_TRUE(g_msg_fix.valid());
00413   ASSERT_TRUE(g_msg_vel.valid());
00414   ASSERT_TRUE(g_msg_imu.valid());
00415   EXPECT_STREQ(g_msg_imu.get().header.frame_id.c_str(), g_frame_id_gps.c_str());
00416   q.setRPY((double)packet.roll * 1e-6, (double)packet.pitch * 1e-6, M_PI_2 - (double)packet.heading * 1e-6);
00417   EXPECT_EQ(g_msg_imu.get().orientation.w, q.w());
00418   EXPECT_EQ(g_msg_imu.get().orientation.x, q.x());
00419   EXPECT_EQ(g_msg_imu.get().orientation.y, q.y());
00420   EXPECT_EQ(g_msg_imu.get().orientation.z, q.z());
00421   EXPECT_EQ(g_msg_imu.get().linear_acceleration.x, (double)packet.accel_x *  1e-4);
00422   EXPECT_EQ(g_msg_imu.get().linear_acceleration.y, (double)packet.accel_y *  1e-4);
00423   EXPECT_EQ(g_msg_imu.get().linear_acceleration.z, (double)packet.accel_z * -1e-4);
00424   EXPECT_EQ(g_msg_imu.get().angular_velocity.x, (double)packet.gyro_x *  1e-5);
00425   EXPECT_EQ(g_msg_imu.get().angular_velocity.y, (double)packet.gyro_y *  1e-5);
00426   EXPECT_EQ(g_msg_imu.get().angular_velocity.z, (double)packet.gyro_z * -1e-5);
00427   EXPECT_EQ(g_msg_imu.get().angular_velocity_covariance[0], 0.0); // x
00428   EXPECT_EQ(g_msg_imu.get().angular_velocity_covariance[4], 0.0); // y
00429   EXPECT_EQ(g_msg_imu.get().angular_velocity_covariance[8], 0.0); // z
00430   EXPECT_EQ(g_msg_imu.get().linear_acceleration_covariance[0], 0.0); // x
00431   EXPECT_EQ(g_msg_imu.get().linear_acceleration_covariance[4], 0.0); // y
00432   EXPECT_EQ(g_msg_imu.get().linear_acceleration_covariance[8], 0.0); // z
00433   EXPECT_EQ(g_msg_imu.get().orientation_covariance[0], 0.0); // x
00434   EXPECT_EQ(g_msg_imu.get().orientation_covariance[4], 0.0); // y
00435   EXPECT_EQ(g_msg_imu.get().orientation_covariance[8], 0.0); // z
00436 
00437   // Set orientation covariance on channel 5
00438   memset(&packet.chan, 0x00, sizeof(packet.chan));
00439   packet.channel = 5;
00440   packet.chan.chan5.age = 10;
00441   packet.chan.chan5.acc_heading = 123;
00442   packet.chan.chan5.acc_pitch   = 1234;
00443   packet.chan.chan5.acc_roll    = 12345;
00444   fixPacket(packet);
00445   ASSERT_TRUE(sendPacket(packet));
00446   EXPECT_TRUE(waitForMsgs(DURATION));
00447   ASSERT_TRUE(g_msg_fix.valid());
00448   ASSERT_TRUE(g_msg_vel.valid());
00449   ASSERT_TRUE(g_msg_imu.valid());
00450   EXPECT_STREQ(g_msg_imu.get().header.frame_id.c_str(), g_frame_id_gps.c_str());
00451   q.setRPY((double)packet.roll * 1e-6, (double)packet.pitch * 1e-6, M_PI_2 - (double)packet.heading * 1e-6);
00452   EXPECT_EQ(g_msg_imu.get().orientation.w, q.w());
00453   EXPECT_EQ(g_msg_imu.get().orientation.x, q.x());
00454   EXPECT_EQ(g_msg_imu.get().orientation.y, q.y());
00455   EXPECT_EQ(g_msg_imu.get().orientation.z, q.z());
00456   EXPECT_EQ(g_msg_imu.get().linear_acceleration.x, (double)packet.accel_x *  1e-4);
00457   EXPECT_EQ(g_msg_imu.get().linear_acceleration.y, (double)packet.accel_y *  1e-4);
00458   EXPECT_EQ(g_msg_imu.get().linear_acceleration.z, (double)packet.accel_z * -1e-4);
00459   EXPECT_EQ(g_msg_imu.get().angular_velocity.x, (double)packet.gyro_x *  1e-5);
00460   EXPECT_EQ(g_msg_imu.get().angular_velocity.y, (double)packet.gyro_y *  1e-5);
00461   EXPECT_EQ(g_msg_imu.get().angular_velocity.z, (double)packet.gyro_z * -1e-5);
00462   EXPECT_EQ(g_msg_imu.get().angular_velocity_covariance[0], 0.0); // x
00463   EXPECT_EQ(g_msg_imu.get().angular_velocity_covariance[4], 0.0); // y
00464   EXPECT_EQ(g_msg_imu.get().angular_velocity_covariance[8], 0.0); // z
00465   EXPECT_EQ(g_msg_imu.get().linear_acceleration_covariance[0], 0.0); // x
00466   EXPECT_EQ(g_msg_imu.get().linear_acceleration_covariance[4], 0.0); // y
00467   EXPECT_EQ(g_msg_imu.get().linear_acceleration_covariance[8], 0.0); // z
00468   EXPECT_EQ(g_msg_imu.get().orientation_covariance[0], SQUARE(packet.chan.chan5.acc_roll    * 1e-5)); // x
00469   EXPECT_EQ(g_msg_imu.get().orientation_covariance[4], SQUARE(packet.chan.chan5.acc_pitch   * 1e-5)); // y
00470   EXPECT_EQ(g_msg_imu.get().orientation_covariance[8], SQUARE(packet.chan.chan5.acc_heading * 1e-5)); // z
00471 
00472   // Set orientation covariance on channel 5 with old age
00473   memset(&packet.chan, 0x00, sizeof(packet.chan));
00474   packet.channel = 5;
00475   packet.chan.chan5.age = 190;
00476   packet.chan.chan5.acc_heading = 123;
00477   packet.chan.chan5.acc_pitch   = 1234;
00478   packet.chan.chan5.acc_roll    = 12345;
00479   fixPacket(packet);
00480   ASSERT_TRUE(sendPacket(packet));
00481   EXPECT_TRUE(waitForMsgs(DURATION));
00482   ASSERT_TRUE(g_msg_fix.valid());
00483   ASSERT_TRUE(g_msg_vel.valid());
00484   ASSERT_TRUE(g_msg_imu.valid());
00485   EXPECT_STREQ(g_msg_imu.get().header.frame_id.c_str(), g_frame_id_gps.c_str());
00486   q.setRPY((double)packet.roll * 1e-6, (double)packet.pitch * 1e-6, M_PI_2 - (double)packet.heading * 1e-6);
00487   EXPECT_EQ(g_msg_imu.get().orientation.w, q.w());
00488   EXPECT_EQ(g_msg_imu.get().orientation.x, q.x());
00489   EXPECT_EQ(g_msg_imu.get().orientation.y, q.y());
00490   EXPECT_EQ(g_msg_imu.get().orientation.z, q.z());
00491   EXPECT_EQ(g_msg_imu.get().linear_acceleration.x, (double)packet.accel_x *  1e-4);
00492   EXPECT_EQ(g_msg_imu.get().linear_acceleration.y, (double)packet.accel_y *  1e-4);
00493   EXPECT_EQ(g_msg_imu.get().linear_acceleration.z, (double)packet.accel_z * -1e-4);
00494   EXPECT_EQ(g_msg_imu.get().angular_velocity.x, (double)packet.gyro_x *  1e-5);
00495   EXPECT_EQ(g_msg_imu.get().angular_velocity.y, (double)packet.gyro_y *  1e-5);
00496   EXPECT_EQ(g_msg_imu.get().angular_velocity.z, (double)packet.gyro_z * -1e-5);
00497   EXPECT_EQ(g_msg_imu.get().angular_velocity_covariance[0], 0.0); // x
00498   EXPECT_EQ(g_msg_imu.get().angular_velocity_covariance[4], 0.0); // y
00499   EXPECT_EQ(g_msg_imu.get().angular_velocity_covariance[8], 0.0); // z
00500   EXPECT_EQ(g_msg_imu.get().linear_acceleration_covariance[0], 0.0); // x
00501   EXPECT_EQ(g_msg_imu.get().linear_acceleration_covariance[4], 0.0); // y
00502   EXPECT_EQ(g_msg_imu.get().linear_acceleration_covariance[8], 0.0); // z
00503   EXPECT_EQ(g_msg_imu.get().orientation_covariance[0], 0.0); // x
00504   EXPECT_EQ(g_msg_imu.get().orientation_covariance[4], 0.0); // x
00505   EXPECT_EQ(g_msg_imu.get().orientation_covariance[8], 0.0); // x
00506 }
00507 
00508 // Run all the tests that were declared with TEST()
00509 int main(int argc, char **argv)
00510 {
00511   testing::InitGoogleTest(&argc, argv);
00512   ros::init(argc, argv, "test");
00513 
00514   // Parameters
00515   ros::NodeHandle priv_nh("~");
00516   priv_nh.getParam("ip_address", g_ip_address);
00517   priv_nh.getParam("port", g_port);
00518   priv_nh.getParam("frame_id_gps", g_frame_id_gps);
00519   priv_nh.getParam("frame_id_vel", g_frame_id_vel);
00520   priv_nh.getParam("frame_id_odom", g_frame_id_odom);
00521   if (g_ip_address.empty()) {
00522     g_ip_address = "127.0.0.1";
00523   }
00524 
00525   // Subscribers
00526   ros::NodeHandle nh;
00527   g_sub_fix = nh.subscribe("gps/fix", 2, recvGpsFix);
00528   g_sub_vel = nh.subscribe("gps/vel", 2, recvGpsVel);
00529   g_sub_imu = nh.subscribe("imu/data", 2, recvImuData);
00530 
00531   return RUN_ALL_TESTS();
00532 }
00533 


oxford_gps_eth
Author(s): Kevin Hallenbeck
autogenerated on Wed Jul 10 2019 03:30:07