moveit2
The MoveIt Motion Planning Framework for ROS 2.
servo_cpp_fixture.hpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2023, PickNik Inc.
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 Inc. 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 /* Title : servo_cpp_fixture.hpp
36  * Project : moveit_servo
37  * Created : 07/13/2020
38  * Author : Adam Pettinger, V Mohammed Ibrahim
39  *
40  * Description : Resources used by servo c++ integration tests
41  */
42 
43 #pragma once
44 
45 #include <gtest/gtest.h>
46 #include <moveit_servo/servo.hpp>
50 #include <tf2_eigen/tf2_eigen.hpp>
51 
52 class ServoCppFixture : public testing::Test
53 {
54 protected:
55  void SetUp() override
56  {
57  // Create a node to be given to Servo.
58  servo_test_node_ = std::make_shared<rclcpp::Node>("moveit_servo_test");
59 
60  // Create a Servo object for testing.
61  const std::string servo_param_namespace = "moveit_servo_test";
62  servo_param_listener_ = std::make_shared<servo::ParamListener>(servo_test_node_, servo_param_namespace);
63  servo_params_ = servo_param_listener_->get_params();
64 
66  // Wait for complete state update before starting MoveIt Servo.
67  if (!planning_scene_monitor_->getStateMonitor()->waitForCompleteState("panda_arm", 1.0))
68  {
69  FAIL() << "Could not retrieve complete robot state";
70  }
71  // Forward state update to planning scene
72  planning_scene_monitor_->updateSceneWithCurrentState();
73 
75  std::make_shared<moveit_servo::Servo>(servo_test_node_, servo_param_listener_, planning_scene_monitor_);
76  }
77 
79  Eigen::Isometry3d getCurrentPose(const std::string& target_frame) const
80  {
82  return locked_scene->getCurrentState().getGlobalLinkTransform(target_frame);
83  }
84 
85  std::shared_ptr<rclcpp::Node> servo_test_node_;
86  std::shared_ptr<const servo::ParamListener> servo_param_listener_;
87  servo::Params servo_params_;
88  std::shared_ptr<moveit_servo::Servo> servo_test_instance_;
89  planning_scene_monitor::PlanningSceneMonitorPtr planning_scene_monitor_;
90 };
Eigen::Isometry3d getCurrentPose(const std::string &target_frame) const
Helper function to get the current pose of a specified frame.
std::shared_ptr< rclcpp::Node > servo_test_node_
std::shared_ptr< const servo::ParamListener > servo_param_listener_
servo::Params servo_params_
void SetUp() override
std::shared_ptr< moveit_servo::Servo > servo_test_instance_
planning_scene_monitor::PlanningSceneMonitorPtr planning_scene_monitor_
This is a convenience class for obtaining access to an instance of a locked PlanningScene.
planning_scene_monitor::PlanningSceneMonitorPtr createPlanningSceneMonitor(const rclcpp::Node::SharedPtr &node, const servo::Params &servo_params)
Creates the planning scene monitor used by servo.
Definition: common.cpp:480