pose_tracking_test.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2020, PickNik LLC
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of PickNik LLC nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Andy Zelenak
36  Desc: Test of tracking toward a pose
37 */
38 
39 // C++
40 #include <string>
41 #include <thread>
42 
43 // ROS
44 #include <ros/ros.h>
45 
46 // Testing
47 #include <gtest/gtest.h>
48 
49 // Servo
52 
53 static const std::string LOGNAME = "servo_cpp_interface_test";
54 static constexpr double TRANSLATION_TOLERANCE = 0.01; // meters
55 static constexpr double ROTATION_TOLERANCE = 0.1; // quaternion
56 static constexpr double ROS_PUB_SUB_DELAY = 4; // allow for subscribers to initialize
57 
58 namespace moveit_servo
59 {
60 class PoseTrackingFixture : public ::testing::Test
61 {
62 public:
63  void SetUp() override
64  {
65  // Wait for several key topics / parameters
66  ros::topic::waitForMessage<sensor_msgs::JointState>("/joint_states");
67  while (!nh_.hasParam("/robot_description") && ros::ok())
68  {
69  ros::Duration(0.1).sleep();
70  }
71 
72  // Load the planning scene monitor
73  planning_scene_monitor_ = std::make_shared<planning_scene_monitor::PlanningSceneMonitor>("robot_description");
74  planning_scene_monitor_->startSceneMonitor();
75  planning_scene_monitor_->startStateMonitor();
76  planning_scene_monitor_->startWorldGeometryMonitor(
79  false /* skip octomap monitor */);
80 
81  tracker_ = std::make_shared<moveit_servo::PoseTracking>(nh_, planning_scene_monitor_);
82 
83  target_pose_pub_ = nh_.advertise<geometry_msgs::PoseStamped>("target_pose", 1 /* queue */, true /* latch */);
84 
85  // Tolerance for pose seeking
87  }
88  void TearDown() override
89  {
90  }
91 
92 protected:
94  planning_scene_monitor::PlanningSceneMonitorPtr planning_scene_monitor_;
95  Eigen::Vector3d translation_tolerance_;
98 }; // class PoseTrackingFixture
99 
100 // Check for commands going out to ros_control
101 TEST_F(PoseTrackingFixture, OutgoingMsgTest)
102 {
103  // halt Servoing when first msg to ros_control is received
104  // and test some conditions
105  trajectory_msgs::JointTrajectory last_received_msg;
106  boost::function<void(const trajectory_msgs::JointTrajectoryConstPtr&)> traj_callback =
107  [&/* this */](const trajectory_msgs::JointTrajectoryConstPtr& msg) {
108  EXPECT_EQ(msg->header.frame_id, "panda_link0");
109  // Check for an expected joint position command
110  // As of now, the robot doesn't actually move because there are no controllers enabled.
111  double angle_tolerance = 0.08; // rad
112  EXPECT_NEAR(msg->points[0].positions[0], 0, angle_tolerance);
113  EXPECT_NEAR(msg->points[0].positions[1], -0.785, angle_tolerance);
114  EXPECT_NEAR(msg->points[0].positions[2], 0, angle_tolerance);
115  EXPECT_NEAR(msg->points[0].positions[3], -2.360, angle_tolerance);
116  EXPECT_NEAR(msg->points[0].positions[4], 0, angle_tolerance);
117  EXPECT_NEAR(msg->points[0].positions[5], 1.571, angle_tolerance);
118  EXPECT_NEAR(msg->points[0].positions[6], 0.785, angle_tolerance);
119 
120  this->tracker_->stopMotion();
121  return;
122  };
123  auto traj_sub = nh_.subscribe("servo_server/command", 1, traj_callback);
124 
125  geometry_msgs::PoseStamped target_pose;
126  target_pose.header.frame_id = "panda_link4";
127  target_pose.header.stamp = ros::Time::now();
128  target_pose.pose.position.x = 0.2;
129  target_pose.pose.position.y = 0.2;
130  target_pose.pose.position.z = 0.2;
131  target_pose.pose.orientation.w = 1;
132 
133  // Republish the target pose in a new thread, as if the target is moving
134  std::thread target_pub_thread([&] {
135  size_t msg_count = 0;
136  while (++msg_count < 100)
137  {
138  target_pose_pub_.publish(target_pose);
139  ros::Duration(0.01).sleep();
140  }
141  });
142 
144 
145  // resetTargetPose() can be used to clear the target pose and wait for a new one, e.g. when moving between multiple
146  // waypoints
147  tracker_->resetTargetPose();
148 
149  tracker_->moveToPose(translation_tolerance_, ROTATION_TOLERANCE, 1 /* target pose timeout */);
150 
151  target_pub_thread.join();
152 }
153 
154 } // namespace moveit_servo
155 
156 int main(int argc, char** argv)
157 {
158  ros::init(argc, argv, LOGNAME);
159  testing::InitGoogleTest(&argc, argv);
160 
162  spinner.start();
163 
164  int result = RUN_ALL_TESTS();
165  return result;
166 }
ros::Publisher
ROTATION_TOLERANCE
static constexpr double ROTATION_TOLERANCE
Definition: pose_tracking_test.cpp:55
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
moveit_servo::PoseTrackingFixture::TearDown
void TearDown() override
Definition: pose_tracking_test.cpp:88
ros.h
moveit_servo::PoseTrackingFixture::tracker_
moveit_servo::PoseTrackingPtr tracker_
Definition: pose_tracking_test.cpp:96
ros::AsyncSpinner
moveit_servo::PoseTrackingFixture::translation_tolerance_
Eigen::Vector3d translation_tolerance_
Definition: pose_tracking_test.cpp:95
main
int main(int argc, char **argv)
Definition: pose_tracking_test.cpp:156
make_shared_from_pool.h
ros::NodeHandle::advertise
Publisher advertise(AdvertiseOptions &ops)
ros::ok
ROSCPP_DECL bool ok()
spinner
void spinner()
planning_scene_monitor::PlanningSceneMonitor::DEFAULT_PLANNING_SCENE_WORLD_TOPIC
static const std::string DEFAULT_PLANNING_SCENE_WORLD_TOPIC
EXPECT_NEAR
#define EXPECT_NEAR(a, b, prec)
moveit_servo
Definition: collision_check.h:50
moveit_servo::PoseTrackingPtr
std::shared_ptr< PoseTracking > PoseTrackingPtr
Definition: pose_tracking.h:224
ROS_PUB_SUB_DELAY
static constexpr double ROS_PUB_SUB_DELAY
Definition: pose_tracking_test.cpp:56
planning_scene_monitor::PlanningSceneMonitor::DEFAULT_COLLISION_OBJECT_TOPIC
static const std::string DEFAULT_COLLISION_OBJECT_TOPIC
ros::NodeHandle::hasParam
bool hasParam(const std::string &key) const
pose_tracking.h
moveit_servo::PoseTrackingFixture::nh_
ros::NodeHandle nh_
Definition: pose_tracking_test.cpp:93
ros::Duration::sleep
bool sleep() const
moveit_servo::PoseTrackingFixture
Definition: pose_tracking_test.cpp:60
moveit_servo::PoseTrackingFixture::target_pose_pub_
ros::Publisher target_pose_pub_
Definition: pose_tracking_test.cpp:97
TRANSLATION_TOLERANCE
static constexpr double TRANSLATION_TOLERANCE
Definition: pose_tracking_test.cpp:54
LOGNAME
static const std::string LOGNAME
Definition: pose_tracking_test.cpp:53
moveit_servo::TEST_F
TEST_F(ServoFixture, SendTwistStampedTest)
Definition: basic_servo_tests.cpp:94
ros::Duration
moveit_servo::PoseTrackingFixture::planning_scene_monitor_
planning_scene_monitor::PlanningSceneMonitorPtr planning_scene_monitor_
Definition: pose_tracking_test.cpp:94
EXPECT_EQ
#define EXPECT_EQ(a, b)
moveit_servo::PoseTrackingFixture::SetUp
void SetUp() override
Definition: pose_tracking_test.cpp:63
ros::NodeHandle
ros::Time::now
static Time now()


moveit_servo
Author(s): Brian O'Neil, Andy Zelenak , Blake Anderson, Alexander Rössler , Tyler Weaver
autogenerated on Sat May 3 2025 02:27:56