44 #include <rclcpp/rclcpp.hpp>
47 #include <gtest/gtest.h>
54 static const rclcpp::Logger
LOGGER = rclcpp::get_logger(
"moveit_servo.pose_tracking_test");
56 static constexpr
double TRANSLATION_TOLERANCE = 0.01;
57 static constexpr
double ROTATION_TOLERANCE = 0.1;
71 if (servo_parameters_ ==
nullptr)
73 RCLCPP_FATAL(LOGGER,
"Could not get servo parameters!");
79 auto test_parameters = std::make_shared<struct TestParameters>();
81 test_parameters->publish_period = 1.0 / test_parameters->publish_hz;
82 test_parameters->timeout_iterations = 10 * test_parameters->publish_hz;
89 RCLCPP_ERROR_STREAM(LOGGER,
"Error in setting up the PlanningSceneMonitor.");
105 RCLCPP_ERROR_STREAM(LOGGER,
"Error waiting for current robot state in PlanningSceneMonitor.");
116 :
node_(std::make_shared<
rclcpp::Node>(
"pose_tracking_testing"))
117 ,
executor_(std::make_shared<
rclcpp::executors::SingleThreadedExecutor>())
160 trajectory_msgs::msg::JointTrajectory last_received_msg;
161 std::function<void(
const trajectory_msgs::msg::JointTrajectory::ConstSharedPtr)> traj_callback =
162 [&](
const trajectory_msgs::msg::JointTrajectory::ConstSharedPtr& msg) {
163 EXPECT_EQ(msg->header.frame_id,
"panda_link0");
167 moveit::core::RobotStatePtr temp_state(planning_scene_monitor_->getStateMonitor()->getCurrentState());
168 const std::string group_name =
"panda_arm";
170 std::vector<double> positions(msg->points[0].positions);
171 temp_state->copyJointGroupPositions(group_name, positions);
172 Eigen::Isometry3d hand_tf = temp_state->getFrameTransform(
"panda_hand");
174 moveit::core::RobotStatePtr test_state(planning_scene_monitor_->getStateMonitor()->getCurrentState());
175 std::vector<double> test_positions = { 0, -0.785, 0, -2.360, 0, 1.571, 0.758 };
176 test_state->copyJointGroupPositions(group_name, test_positions);
177 Eigen::Isometry3d test_hand_tf = test_state->getFrameTransform(
"panda_hand");
179 double precision = 0.02;
180 EXPECT_TRUE(test_hand_tf.isApprox(hand_tf, precision));
182 this->tracker_->stopMotion();
185 auto traj_sub = node_->create_subscription<trajectory_msgs::msg::JointTrajectory>(
186 "/panda_arm_controller/joint_trajectory", rclcpp::SystemDefaultsQoS(), traj_callback);
188 geometry_msgs::msg::PoseStamped target_pose;
189 target_pose.header.frame_id =
"panda_link4";
190 target_pose.header.stamp = node_->now();
191 target_pose.pose.position.x = 0.2;
192 target_pose.pose.position.y = 0.2;
193 target_pose.pose.position.z = 0.2;
194 target_pose.pose.orientation.w = 1;
197 std::thread target_pub_thread([&] {
198 size_t msg_count = 0;
199 rclcpp::WallRate loop_rate(50);
200 while (++msg_count < 100)
202 target_pose_pub_->publish(target_pose);
208 tracker_->resetTargetPose();
210 tracker_->moveToPose(translation_tolerance_, ROTATION_TOLERANCE, 1 );
212 target_pub_thread.join();
217 int main(
int argc,
char** argv)
219 rclcpp::init(argc, argv);
220 ::testing::InitGoogleTest(&argc, argv);
222 int result = RUN_ALL_TESTS();
Eigen::Vector3d translation_tolerance_
std::shared_ptr< const struct TestParameters > test_parameters_
rclcpp::Executor::SharedPtr executor_
std::thread executor_thread_
rclcpp::Publisher< geometry_msgs::msg::PoseStamped >::SharedPtr target_pose_pub_
rclcpp::Node::SharedPtr node_
moveit_servo::PoseTrackingPtr tracker_
moveit_servo::ServoParameters::SharedConstPtr servo_parameters_
planning_scene_monitor::PlanningSceneMonitorPtr planning_scene_monitor_
static const std::string DEFAULT_COLLISION_OBJECT_TOPIC
The name of the topic used by default for receiving collision objects in the world.
static const std::string DEFAULT_PLANNING_SCENE_WORLD_TOPIC
@ UPDATE_SCENE
The entire scene was updated.
Vec3fX< details::Vec3Data< double > > Vector3d
std::shared_ptr< PoseTracking > PoseTrackingPtr
TEST_F(PoseTrackingFixture, OutgoingMsgTest)
const rclcpp::Logger LOGGER
int main(int argc, char **argv)
double timeout_iterations
std::shared_ptr< const ServoParameters > SharedConstPtr
static SharedConstPtr makeServoParameters(const rclcpp::Node::SharedPtr &node, const std::string &ns="moveit_servo", bool dynamic_parameters=true)