cartesian_command_interface_test.cpp
Go to the documentation of this file.
1 // -- BEGIN LICENSE BLOCK ----------------------------------------------
2 // Copyright 2020 FZI Forschungszentrum Informatik
3 // Created on behalf of Universal Robots A/S
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 // -- END LICENSE BLOCK ------------------------------------------------
17 
18 //----------------------------------------------------------------------
25 //----------------------------------------------------------------------
26 
27 #include <gtest/gtest.h>
28 
31 
32 using namespace ros_controllers_cartesian;
33 
34 class CartesianCommandInterfaceTest : public ::testing::Test
35 {
36 protected:
37  std::string reference_frame = "base";
38  std::string controlled_frame = "tool0";
39  geometry_msgs::Pose pose_buffer;
40  geometry_msgs::Twist twist_buffer;
41  geometry_msgs::Accel accel_buffer;
42  geometry_msgs::Accel jerk_buffer;
43  CartesianStateHandle state_handle{ reference_frame, controlled_frame, &pose_buffer,
44  &twist_buffer, &accel_buffer, &jerk_buffer };
45  geometry_msgs::Pose pose_cmd_buffer;
46  geometry_msgs::Twist twist_cmd_buffer;
47  geometry_msgs::Accel accel_cmd_buffer;
48  geometry_msgs::Accel jerk_cmd_buffer;
49 };
50 
51 TEST_F(CartesianCommandInterfaceTest, TestPoseHandleConstructor)
52 {
53  EXPECT_NO_THROW(PoseCommandHandle obj(state_handle, &pose_cmd_buffer));
54  EXPECT_THROW(PoseCommandHandle obj(state_handle, nullptr), hardware_interface::HardwareInterfaceException);
55 }
56 
57 TEST_F(CartesianCommandInterfaceTest, TestPoseHandleDataHandling)
58 {
59  PoseCommandHandle cmd_handle(state_handle, &pose_cmd_buffer);
60 
62  iface.registerHandle(cmd_handle);
63 
64  EXPECT_NO_THROW(iface.getHandle(controlled_frame));
65 
66  cmd_handle = iface.getHandle(controlled_frame);
67 
68  EXPECT_EQ(controlled_frame, cmd_handle.getName());
69  geometry_msgs::Pose new_cmd;
70  new_cmd.position.x = 1.0;
71  new_cmd.position.y = 2.0;
72  new_cmd.position.z = 3.0;
73  new_cmd.orientation.x = 0.5;
74  new_cmd.orientation.y = 0.5;
75  new_cmd.orientation.z = 0.0;
76  new_cmd.orientation.w = 0.0;
77  cmd_handle.setCommand(new_cmd);
78  EXPECT_DOUBLE_EQ(new_cmd.position.x, cmd_handle.getCommand().position.x);
79  EXPECT_DOUBLE_EQ(new_cmd.position.y, cmd_handle.getCommand().position.y);
80  EXPECT_DOUBLE_EQ(new_cmd.position.z, cmd_handle.getCommand().position.z);
81  EXPECT_DOUBLE_EQ(new_cmd.orientation.x, cmd_handle.getCommand().orientation.x);
82  EXPECT_DOUBLE_EQ(new_cmd.orientation.y, cmd_handle.getCommand().orientation.y);
83  EXPECT_DOUBLE_EQ(new_cmd.orientation.z, cmd_handle.getCommand().orientation.z);
84  EXPECT_DOUBLE_EQ(new_cmd.orientation.w, cmd_handle.getCommand().orientation.w);
85 }
86 
87 TEST_F(CartesianCommandInterfaceTest, TestTwistHandleConstructor)
88 {
89  EXPECT_NO_THROW(TwistCommandHandle obj(state_handle, &twist_cmd_buffer));
90  EXPECT_THROW(TwistCommandHandle obj(state_handle, nullptr), hardware_interface::HardwareInterfaceException);
91 }
92 
93 TEST_F(CartesianCommandInterfaceTest, TestTwistHandleDataHandling)
94 {
95  TwistCommandHandle cmd_handle(state_handle, &twist_cmd_buffer);
96 
98  iface.registerHandle(cmd_handle);
99 
100  EXPECT_NO_THROW(iface.getHandle(controlled_frame));
101 
102  cmd_handle = iface.getHandle(controlled_frame);
103 
104  EXPECT_EQ(controlled_frame, cmd_handle.getName());
105  geometry_msgs::Twist new_cmd;
106  new_cmd.linear.x = 1.0;
107  new_cmd.linear.y = 2.0;
108  new_cmd.linear.z = 3.0;
109  new_cmd.angular.x = 0.5;
110  new_cmd.angular.y = 0.5;
111  new_cmd.angular.z = 0.0;
112  cmd_handle.setCommand(new_cmd);
113  EXPECT_DOUBLE_EQ(new_cmd.linear.x, cmd_handle.getCommand().linear.x);
114  EXPECT_DOUBLE_EQ(new_cmd.linear.y, cmd_handle.getCommand().linear.y);
115  EXPECT_DOUBLE_EQ(new_cmd.linear.z, cmd_handle.getCommand().linear.z);
116  EXPECT_DOUBLE_EQ(new_cmd.angular.x, cmd_handle.getCommand().angular.x);
117  EXPECT_DOUBLE_EQ(new_cmd.angular.y, cmd_handle.getCommand().angular.y);
118  EXPECT_DOUBLE_EQ(new_cmd.angular.z, cmd_handle.getCommand().angular.z);
119 }
120 
121 int main(int argc, char** argv)
122 {
123  testing::InitGoogleTest(&argc, argv);
124  return RUN_ALL_TESTS();
125 }
main
int main(int argc, char **argv)
Definition: cartesian_command_interface_test.cpp:121
ros_controllers_cartesian::CartesianStateHandle::getName
std::string getName() const
Definition: cartesian_state_handle.h:80
ros_controllers_cartesian
Definition: cartesian_command_interface.h:31
ros_controllers_cartesian::CartesianStateHandle
A state handle for Cartesian hardware interfaces.
Definition: cartesian_state_handle.h:48
ros_controllers_cartesian::PoseCommandInterface
A Cartesian command interface for poses.
Definition: cartesian_command_interface.h:124
ros_controllers_cartesian::TwistCommandInterface
A Cartesian command interface for twists.
Definition: cartesian_command_interface.h:136
hardware_interface::HardwareResourceManager::getHandle
ResourceHandle getHandle(const std::string &name)
ros_controllers_cartesian::PoseCommandHandle::getCommand
geometry_msgs::Pose getCommand() const
Definition: cartesian_command_interface.h:60
CartesianCommandInterfaceTest::pose_cmd_buffer
geometry_msgs::Pose pose_cmd_buffer
Definition: cartesian_command_interface_test.cpp:45
cartesian_command_interface.h
CartesianCommandInterfaceTest::jerk_buffer
geometry_msgs::Accel jerk_buffer
Definition: cartesian_command_interface_test.cpp:42
CartesianCommandInterfaceTest::twist_buffer
geometry_msgs::Twist twist_buffer
Definition: cartesian_command_interface_test.cpp:40
ros_controllers_cartesian::TwistCommandHandle::getCommand
geometry_msgs::Twist getCommand() const
Definition: cartesian_command_interface.h:102
ros_controllers_cartesian::TwistCommandHandle
A handle for setting twist commands.
Definition: cartesian_command_interface.h:81
ros_controllers_cartesian::PoseCommandHandle
A handle for setting pose commands.
Definition: cartesian_command_interface.h:39
ros_controllers_cartesian::PoseCommandHandle::setCommand
void setCommand(const geometry_msgs::Pose &pose)
Definition: cartesian_command_interface.h:54
ros_controllers_cartesian::TwistCommandHandle::setCommand
void setCommand(const geometry_msgs::Twist &twist)
Definition: cartesian_command_interface.h:96
CartesianCommandInterfaceTest::accel_buffer
geometry_msgs::Accel accel_buffer
Definition: cartesian_command_interface_test.cpp:41
hardware_interface::ResourceManager::registerHandle
void registerHandle(const ResourceHandle &handle)
hardware_interface::HardwareInterfaceException
CartesianCommandInterfaceTest::twist_cmd_buffer
geometry_msgs::Twist twist_cmd_buffer
Definition: cartesian_command_interface_test.cpp:46
CartesianCommandInterfaceTest::jerk_cmd_buffer
geometry_msgs::Accel jerk_cmd_buffer
Definition: cartesian_command_interface_test.cpp:48
TEST_F
TEST_F(CartesianCommandInterfaceTest, TestPoseHandleConstructor)
Definition: cartesian_command_interface_test.cpp:51
CartesianCommandInterfaceTest::accel_cmd_buffer
geometry_msgs::Accel accel_cmd_buffer
Definition: cartesian_command_interface_test.cpp:47
CartesianCommandInterfaceTest::pose_buffer
geometry_msgs::Pose pose_buffer
Definition: cartesian_command_interface_test.cpp:39
CartesianCommandInterfaceTest
Definition: cartesian_command_interface_test.cpp:34
cartesian_state_handle.h


cartesian_interface
Author(s):
autogenerated on Tue Oct 15 2024 02:09:12