33 #include <gtest/gtest.h> 35 #include <trajectory_msgs/JointTrajectory.h> 36 #include <pr2_arm_ik_action/trajectory_unwrap.h> 43 TiXmlDocument robot_model_xml;
44 robot_model_xml.LoadFile(file);
45 TiXmlElement *robot_xml = robot_model_xml.FirstChildElement(
"robot");
47 std::cerr <<
"ERROR: Could not load the xml into TiXmlElement" << std::endl;
52 std::cerr <<
"ERROR: Model Parsing the xml failed" << std::endl;
59 TEST(TrajectoryUnwarp, single_unwrap)
65 trajectory_msgs::JointTrajectory traj_in, traj_out, traj_expected;
67 traj_in.points.resize(2);
68 traj_in.joint_names.push_back(
"joint1");
69 traj_in.joint_names.push_back(
"joint2");
70 traj_in.points[0].positions.push_back(0.0);
71 traj_in.points[0].positions.push_back(0.0);
72 traj_in.points[1].positions.push_back(12.0);
73 traj_in.points[1].positions.push_back(0.0);
76 traj_expected =traj_in;
77 traj_expected.points[1].positions[0]=-0.566371;
80 int points_size = traj_out.points.size();
81 int num_jnts = traj_out.points[0].positions.size();
83 for(
int i=0; i<points_size; i++)
85 for(
int j=0; j<num_jnts; j++)
87 EXPECT_NEAR(traj_expected.points[i].positions[j],traj_out.points[i].positions[j], epsilon);
92 TEST(TrajectoryUnwarp, double_unwrap)
98 trajectory_msgs::JointTrajectory traj_in, traj_out, traj_expected;
100 traj_in.points.resize(2);
101 traj_in.joint_names.push_back(
"joint1");
102 traj_in.joint_names.push_back(
"joint3");
103 traj_in.points[0].positions.push_back(0.0);
104 traj_in.points[0].positions.push_back(6.10);
105 traj_in.points[1].positions.push_back(12.0);
106 traj_in.points[1].positions.push_back(12.0);
108 traj_expected =traj_in;
109 traj_expected.points[1].positions[0]=-0.566371;
110 traj_expected.points[1].positions[1]= 5.71682;
113 int points_size = traj_out.points.size();
114 int num_jnts = traj_out.points[0].positions.size();
116 for(
int i=0; i<points_size; i++)
118 for(
int j=0; j<num_jnts; j++)
120 EXPECT_NEAR(traj_expected.points[i].positions[j],traj_out.points[i].positions[j], epsilon);
125 TEST(TrajectoryUnwarp, multipoint_unwrap)
131 trajectory_msgs::JointTrajectory traj_in, traj_out, traj_expected;
133 traj_in.points.resize(3);
134 traj_in.joint_names.push_back(
"joint1");
135 traj_in.joint_names.push_back(
"joint3");
136 traj_in.points[0].positions.push_back(0.0);
137 traj_in.points[0].positions.push_back(6.10);
138 traj_in.points[1].positions.push_back(12.0);
139 traj_in.points[1].positions.push_back(12.0);
140 traj_in.points[2].positions.push_back(1.5);
141 traj_in.points[2].positions.push_back(1.5);
143 traj_expected =traj_in;
144 traj_expected.points[1].positions[0]=-0.566371;
145 traj_expected.points[1].positions[1]= 5.71682;
146 traj_expected.points[2].positions[1]= 7.78318;
149 int points_size = traj_out.points.size();
150 int num_jnts = traj_out.points[0].positions.size();
152 for(
int i=0; i<points_size; i++)
154 for(
int j=0; j<num_jnts; j++)
156 EXPECT_NEAR(traj_expected.points[i].positions[j],traj_out.points[i].positions[j], epsilon);
161 TEST(TrajectoryUnwarp, near_limit_unwrap)
167 trajectory_msgs::JointTrajectory traj_in, traj_out, traj_expected;
169 traj_in.points.resize(3);
170 traj_in.joint_names.push_back(
"joint2");
171 traj_in.points[0].positions.push_back(-1.5);
172 traj_in.points[1].positions.push_back(-3.5);
173 traj_in.points[2].positions.push_back(1.7);
175 traj_expected =traj_in;
176 traj_expected.points[1].positions[0]= 2.78318;
177 traj_expected.points[2].positions[0]= 1.7;
180 int points_size = traj_out.points.size();
181 int num_jnts = traj_out.points[0].positions.size();
183 for(
int i=0; i<points_size; i++)
185 for(
int j=0; j<num_jnts; j++)
187 EXPECT_NEAR(traj_expected.points[i].positions[j],traj_out.points[i].positions[j], epsilon);
196 int main(
int argc,
char **argv){
197 testing::InitGoogleTest(&argc, argv);
198 ros::init(argc, argv,
"trajectory_unwrap_test");
199 return RUN_ALL_TESTS();
void unwrap(urdf::Model &robot_model, const trajectory_msgs::JointTrajectory &traj_in, trajectory_msgs::JointTrajectory &traj_out)
int main(int argc, char **argv)
URDF_EXPORT bool initXml(TiXmlElement *xml)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
TEST(TrajectoryUnwarp, single_unwrap)
bool getParam(const std::string &key, std::string &s) const
bool get_model(urdf::Model &robot)