8 #include <gtest/gtest.h> 9 #include "../../models/testhyq/RobCoGenTestHyQ.h" 22 using KinTpl_t = TestHyQ::tpl::Kinematics<size_type>;
27 const Eigen::Matrix<double, 3, 3>
Qpos = Eigen::Matrix<double, 3, 3>::Random();
31 std::shared_ptr<TermTaskspacePosition<KinTpl_t, true, hyqStateDim, hyqControlDim>>
termTaskspace(
32 new TermTaskspacePosition<KinTpl_t, true, hyqStateDim, hyqControlDim>(
eeId,
Qpos, Eigen::Vector3d::Random()));
34 std::shared_ptr<TermTaskspacePose<KinTpl_t, true, hyqStateDim, hyqControlDim>>
termTaskspacePose(
35 new TermTaskspacePose<KinTpl_t, true, hyqStateDim, hyqControlDim>(
eeId,
38 Eigen::Vector3d::Random(),
39 Eigen::Vector3d::Random()));
43 template <
typename SCALAR>
45 const Eigen::Matrix<SCALAR, hyqStateDim + hyqControlDim, 1> xu)
48 Eigen::Matrix<SCALAR, 1, 1> cost;
50 cost(0, 0) =
termTaskspace->evaluateCppadCg(xu.template head<hyqStateDim>(), xu.template tail<hyqControlDim>(), t);
53 TEST(RBD_JIT_Tests, TaskspacePositionCostFunctionTest)
57 typename derivativesCppadJIT::FUN_TYPE_CG f = testFunctionTaskSpacePosition<ct::core::ADCGScalar>;
67 jacCG.compileJIT(settings,
"taskSpaceCfTestLib",
verbose);
68 std::cout <<
"testTaskSpacePositionTerm compiled!" << std::endl;
69 }
catch (std::exception& e)
71 std::cout <<
"testTaskSpacePositionTerm failed!" << std::endl;
78 template <
typename SCALAR>
82 Eigen::Matrix<SCALAR, 1, 1> cost;
85 termTaskspacePose->evaluateCppadCg(xu.template head<hyqStateDim>(), xu.template tail<hyqControlDim>(), t);
88 TEST(RBD_JIT_Tests, TaskspacePoseCostFunctionTest)
92 typename derivativesCppadJIT::FUN_TYPE_CG f = testFunctionTaskSpacePose<ct::core::ADCGScalar>;
102 jacCG.compileJIT(settings,
"taskSpaceCfTestLib",
verbose);
103 std::cout <<
"testTaskSpacePoseTerm compiled!" << std::endl;
104 }
catch (std::exception& e)
106 std::cout <<
"testTaskSpacePoseTerm failed!" << std::endl;
113 template <
typename SCALAR>
117 kindr::Position<SCALAR, 3> pos(xu.template segment<3>(0));
118 kindr::EulerAnglesXyz<SCALAR> euler(xu.template segment<3>(3));
125 Eigen::Matrix<SCALAR, 1, 1> cost;
132 TEST(RBD_JIT_Tests, RigidBodyPoseTest)
136 typename derivativesCppadJIT::FUN_TYPE_CG f = testFunctionRBDPose<ct::core::ADCGScalar>;
146 jacCG.compileJIT(settings,
"rbdPoseTestLib",
verbose);
147 std::cout <<
"testRBDPose compiled!" << std::endl;
148 }
catch (std::exception& e)
150 std::cout <<
"testRBDPose failed!" << std::endl;
157 template <
typename SCALAR>
164 rigidBodyState.
velocities().getRotationalVelocity().toImplementation() = state.template segment<3>(6);
165 rigidBodyState.
velocities().getTranslationalVelocity().toImplementation() = state.template segment<3>(9);
167 kindr::Position<SCALAR, 3> pos(state.template segment<3>(0));
168 kindr::EulerAnglesXyz<SCALAR> euler(state.template segment<3>(3));
170 rigidBodyState.
pose().position() = pos;
171 rigidBodyState.
pose().setFromEulerAnglesXyz(euler);
177 Eigen::Matrix<SCALAR, 1, 1> cost;
180 cost(0, 0) = rigidBodyStateCopy.
pose().position().toImplementation().norm() +
181 rigidBodyStateCopy.
pose().getEulerAnglesXyz().toImplementation().norm() +
182 rigidBodyStateCopy.
velocities().getVector().norm();
186 TEST(RBD_JIT_Tests, RigidBodyStateTest)
190 typename derivativesCppadJIT::FUN_TYPE_CG f = testFunctionRigidBodyState<ct::core::ADCGScalar>;
200 jacCG.compileJIT(settings,
"rbdStateTestLib",
verbose);
201 std::cout <<
"testRigidBodyState compiled!" << std::endl;
202 }
catch (std::exception& e)
204 std::cout <<
"testRigidBodyState failed!" << std::endl;
211 template <
typename SCALAR>
218 baseState.
velocities().getRotationalVelocity().toImplementation() = x.template segment<3>(6);
219 baseState.
velocities().getTranslationalVelocity().toImplementation() = x.template segment<3>(9);
221 kindr::Position<SCALAR, 3> pos(x.template segment<3>(0));
222 kindr::EulerAnglesXyz<SCALAR> euler(x.template segment<3>(3));
223 baseState.
pose().position() = pos;
224 baseState.
pose().setFromEulerAnglesXyz(euler);
229 rbdState.
base() = baseState;
230 rbdState.
joints() = jointState;
233 Eigen::Matrix<SCALAR, 1, 1> cost;
242 TEST(RBD_JIT_Tests, RBDStateTest)
246 typename derivativesCppadJIT::FUN_TYPE_CG f = testFunctionRBDState<ct::core::ADCGScalar>;
256 jacCG.compileJIT(settings,
"rbdStateTestLib",
verbose);
257 std::cout <<
"testRBDState compiled!" << std::endl;
258 }
catch (std::exception& e)
260 std::cout <<
"testRBDState failed!" << std::endl;
state_vector_euler_t toStateVectorEulerXyz() const
Definition: RBDState.h:161
size_t eeId
Definition: rbdJITtests.h:24
RigidBodyState_t & base()
get base states
Definition: RBDState.h:63
Pose of a single rigid body.
Definition: RigidBodyPose.h:29
RigidBodyPose< SCALAR > & pose()
return the rigid body pose
Definition: RigidBodyState.h:38
const Position3Tpl & position() const
This method returns the position of the Base frame in the inertia frame.
Definition: RigidBodyPose.h:246
joint state and joint velocity
Definition: JointState.h:21
const size_t hyqStateDim
some global variables required for the TaskSpaceTerm test
Definition: rbdJITtests.h:19
const size_t hyqControlDim
Definition: rbdJITtests.h:20
RigidBodyVelocities< SCALAR > & velocities()
return the rigid body velocities
Definition: RigidBodyState.h:42
joint states and base states
Definition: RBDState.h:27
TestHyQ::tpl::Kinematics< size_type > KinTpl_t
Definition: rbdJITtests.h:22
clear all close all load ct GNMSLog0 mat reformat t
Eigen::Matrix< SCALAR, 1, 1 > testFunctionRigidBodyState(const Eigen::Matrix< SCALAR, 12, 1 > &state)
test the RigidBodyState class for JIT-compatibility
Definition: rbdJITtests.h:158
Eigen::Matrix< SCALAR, 1, 1 > testFunctionTaskSpacePosition(const Eigen::Matrix< SCALAR, hyqStateDim+hyqControlDim, 1 > xu)
test TermTaskSpacePosition term for JIT-compatibility
Definition: rbdJITtests.h:44
kindr::EulerAnglesXyz< SCALAR > getEulerAnglesXyz() const
This method returns the Euler angles rotation (X,Y,Z / roll,pitch,yaw).
Definition: RigidBodyPose.h:119
KinTpl_t kynTpl
Definition: rbdJITtests.h:23
DerivativesCppadJIT< inDim, outDim > derivativesCppadJIT
CppAD::AD< CppAD::cg::CG< double > > SCALAR
TEST(RBD_JIT_Tests, TaskspacePositionCostFunctionTest)
Definition: rbdJITtests.h:53
bool verbose
Definition: rbdJITtests.h:15
double Qrot
Definition: rbdJITtests.h:28
std::shared_ptr< TermTaskspacePose< KinTpl_t, true, hyqStateDim, hyqControlDim > > termTaskspacePose(new TermTaskspacePose< KinTpl_t, true, hyqStateDim, hyqControlDim >(eeId, Qpos, Qrot, Eigen::Vector3d::Random(), Eigen::Vector3d::Random()))
State (pose and velocities) of a single rigid body.
Definition: RigidBodyState.h:22
const Eigen::Matrix< double, 3, 3 > Qpos
Definition: rbdJITtests.h:27
Eigen::Matrix< SCALAR, 1, 1 > testFunctionTaskSpacePose(const Eigen::Matrix< SCALAR, hyqStateDim+hyqControlDim, 1 > xu)
test TermTaskSpacePose term for JIT-compatibility
Definition: rbdJITtests.h:79
std::shared_ptr< TermTaskspacePosition< KinTpl_t, true, hyqStateDim, hyqControlDim > > termTaskspace(new TermTaskspacePosition< KinTpl_t, true, hyqStateDim, hyqControlDim >(eeId, Qpos, Eigen::Vector3d::Random()))
Eigen::Matrix< SCALAR, 1, 1 > testFunctionRBDState(const Eigen::Matrix< SCALAR, hyqStateDim, 1 > &x)
test the RBDState class for JIT-compatibility
Definition: rbdJITtests.h:212
JointState< NJOINTS, SCALAR > & joints()
get joint states
Definition: RBDState.h:94
Eigen::Matrix< SCALAR, 1, 1 > testFunctionRBDPose(const Eigen::Matrix< SCALAR, 3+3, 1 > &xu)
test the RigidBodyPose class for JIT-compatibility
Definition: rbdJITtests.h:114
ct::core::ADCGScalar size_type
Definition: rbdJITtests.h:21
void setFromEulerAnglesXyz(const kindr::EulerAnglesXyz< SCALAR > &eulerAngles)
This method sets the Euler angles rotation (X,Y,Z / roll,pitch,yaw) from a kindr type.
Definition: RigidBodyPose.h:171