31 #include <trajectory_msgs/JointTrajectory.h> 32 #include <sensor_msgs/JointState.h> 34 #include <gtest/gtest.h> 36 TEST(Planner2DOFSerialJoints, Plan)
42 trajectory_msgs::JointTrajectory::ConstPtr planned;
43 const auto cb_plan = [&planned](
const trajectory_msgs::JointTrajectory::ConstPtr&
msg)
49 sensor_msgs::JointState
s;
50 s.name.push_back(
"front");
51 s.position.push_back(-1.57);
52 s.name.push_back(
"rear");
53 s.position.push_back(0.0);
55 trajectory_msgs::JointTrajectory cmd;
56 cmd.joint_names.push_back(
"front");
57 cmd.joint_names.push_back(
"rear");
58 trajectory_msgs::JointTrajectoryPoint p;
59 p.positions.push_back(-4.71);
60 p.positions.push_back(0.0);
61 cmd.points.push_back(p);
79 ASSERT_EQ(2u, planned->joint_names.size());
80 ASSERT_EQ(
"front", planned->joint_names[0]);
81 ASSERT_EQ(
"rear", planned->joint_names[1]);
84 const float fc = -3.14;
86 for (
int i = 1; i < static_cast<int>(planned->points.size()); ++i)
88 const trajectory_msgs::JointTrajectoryPoint& p0 = planned->points[i - 1];
89 const trajectory_msgs::JointTrajectoryPoint& p1 = planned->points[i];
90 ASSERT_EQ(2u, p0.positions.size());
91 ASSERT_EQ(2u, p1.positions.size());
93 const float f0 = p0.positions[0];
94 const float r0 = p0.positions[1];
95 const float f1 = p1.positions[0];
96 const float r1 = p1.positions[1];
100 ASSERT_LT(-3.14, r0);
102 ASSERT_LT(-6.28, f1);
104 ASSERT_LT(-3.14, r1);
107 const float front_diff = f1 - f0;
108 const float rear_diff = r1 - r0;
116 std::hypot(front_diff, rear_diff);
122 int main(
int argc,
char** argv)
124 testing::InitGoogleTest(&argc, argv);
125 ros::init(argc, argv,
"test_planner_2dof_serial_joints");
127 return RUN_ALL_TESTS();
void publish(const boost::shared_ptr< M > &message) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
int main(int argc, char **argv)
ROSCPP_DECL void spinOnce()
TEST(Planner2DOFSerialJoints, Plan)