gazebo / gazebo / physics / bullet / BulletTypes_TEST.cc

The branch 'bullet_steve_motion_state' does not exist.
/*
 * Copyright 2012 Open Source Robotics Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
*/


#include <gtest/gtest.h>

#include "gazebo/physics/physics.hh"
#include "gazebo/physics/bullet/BulletTypes.hh"
#include "test_config.h"

#define NEAR_TOL 2e-5

using namespace gazebo;

/////////////////////////////////////////////////
/// Check Vector3 conversions
TEST(BulletTypes, ConvertVector3)
{
  {
    math::Vector3 vec, vec2;
    btVector3 bt = physics::BulletTypes::ConvertVector3(vec);
    EXPECT_NEAR(bt.getX(), 0, NEAR_TOL);
    EXPECT_NEAR(bt.getY(), 0, NEAR_TOL);
    EXPECT_NEAR(bt.getZ(), 0, NEAR_TOL);
    vec2 = physics::BulletTypes::ConvertVector3(bt);
    EXPECT_LT((vec-vec2).GetSquaredLength(), NEAR_TOL*NEAR_TOL);
  }

  {
    math::Vector3 vec(100.5, -2.314, 42), vec2;
    btVector3 bt = physics::BulletTypes::ConvertVector3(vec);
    EXPECT_NEAR(bt.getX(), vec.x, NEAR_TOL);
    EXPECT_NEAR(bt.getY(), vec.y, NEAR_TOL);
    EXPECT_NEAR(bt.getZ(), vec.z, NEAR_TOL);
    vec2 = physics::BulletTypes::ConvertVector3(bt);
    EXPECT_LT((vec-vec2).GetSquaredLength(), NEAR_TOL*NEAR_TOL);
  }
}

/////////////////////////////////////////////////
/// Check Vector4 conversions
TEST(BulletTypes, ConvertVector4)
{
  {
    math::Vector4 vec, vec2;
    btVector4 bt = physics::BulletTypes::ConvertVector4(vec);
    EXPECT_NEAR(bt.getX(), 0, NEAR_TOL);
    EXPECT_NEAR(bt.getY(), 0, NEAR_TOL);
    EXPECT_NEAR(bt.getZ(), 0, NEAR_TOL);
    EXPECT_NEAR(bt.getW(), 0, NEAR_TOL);
    vec2 = physics::BulletTypes::ConvertVector4(bt);
    EXPECT_LT((vec-vec2).GetSquaredLength(), NEAR_TOL*NEAR_TOL);
  }

  {
    math::Vector4 vec(100.5, -2.314, 42, 848.8), vec2;
    btVector4 bt = physics::BulletTypes::ConvertVector4(vec);
    EXPECT_NEAR(bt.getX(), vec.x, NEAR_TOL);
    EXPECT_NEAR(bt.getY(), vec.y, NEAR_TOL);
    EXPECT_NEAR(bt.getZ(), vec.z, NEAR_TOL);
    EXPECT_NEAR(bt.getW(), vec.w, NEAR_TOL);
    vec2 = physics::BulletTypes::ConvertVector4(bt);
    EXPECT_LT((vec-vec2).GetSquaredLength(), NEAR_TOL*NEAR_TOL);
  }
}

/////////////////////////////////////////////////
/// Check Pose conversions
TEST(BulletTypes, ConvertPose)
{
  {
    math::Pose pose, pose2;
    btTransform bt = physics::BulletTypes::ConvertPose(pose);
    EXPECT_NEAR(bt.getOrigin().getX(), 0, NEAR_TOL);
    EXPECT_NEAR(bt.getOrigin().getY(), 0, NEAR_TOL);
    EXPECT_NEAR(bt.getOrigin().getZ(), 0, NEAR_TOL);
    EXPECT_NEAR(bt.getRotation().getX(), 0, NEAR_TOL);
    EXPECT_NEAR(bt.getRotation().getY(), 0, NEAR_TOL);
    EXPECT_NEAR(bt.getRotation().getZ(), 0, NEAR_TOL);
    EXPECT_NEAR(bt.getRotation().getW(), 1, NEAR_TOL);
    pose2 = physics::BulletTypes::ConvertPose(bt);
    EXPECT_LT((pose.pos-pose2.pos).GetSquaredLength(), NEAR_TOL*NEAR_TOL);
    EXPECT_LT((pose.rot-pose2.rot).x, NEAR_TOL);
    EXPECT_LT((pose.rot-pose2.rot).y, NEAR_TOL);
    EXPECT_LT((pose.rot-pose2.rot).z, NEAR_TOL);
    EXPECT_LT((pose.rot-pose2.rot).w, NEAR_TOL);
  }

  {
    math::Pose pose(105.4, 3.1, -0.34, 3.14/8, 3.14/16, -3.14/2), pose2;
    btTransform bt = physics::BulletTypes::ConvertPose(pose);
    EXPECT_NEAR(bt.getOrigin().getX(), pose.pos.x, NEAR_TOL);
    EXPECT_NEAR(bt.getOrigin().getY(), pose.pos.y, NEAR_TOL);
    EXPECT_NEAR(bt.getOrigin().getZ(), pose.pos.z, NEAR_TOL);
    EXPECT_NEAR(bt.getRotation().getX(), pose.rot.x, NEAR_TOL);
    EXPECT_NEAR(bt.getRotation().getY(), pose.rot.y, NEAR_TOL);
    EXPECT_NEAR(bt.getRotation().getZ(), pose.rot.z, NEAR_TOL);
    EXPECT_NEAR(bt.getRotation().getW(), pose.rot.w, NEAR_TOL);
    pose2 = physics::BulletTypes::ConvertPose(bt);
    EXPECT_LT((pose.pos-pose2.pos).GetSquaredLength(), NEAR_TOL*NEAR_TOL);
    EXPECT_LT((pose.rot-pose2.rot).x, NEAR_TOL);
    EXPECT_LT((pose.rot-pose2.rot).y, NEAR_TOL);
    EXPECT_LT((pose.rot-pose2.rot).z, NEAR_TOL);
    EXPECT_LT((pose.rot-pose2.rot).w, NEAR_TOL);
  }
}

/////////////////////////////////////////////////
/// Main
int main(int argc, char **argv)
{
  ::testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.