8 #include <gtest/gtest.h> 25 TEST(FrankaHWTests, InterfacesWorkForReadAndCommand) {
26 auto robot_ptr = std::make_unique<FrankaHW>();
29 EXPECT_TRUE(robot_ptr->initParameters(root_nh, private_nh));
30 robot_ptr->initROSInterfaces(private_nh);
45 ASSERT_NE(
nullptr, js_interface);
46 ASSERT_NE(
nullptr, pj_interface);
47 ASSERT_NE(
nullptr, vj_interface);
48 ASSERT_NE(
nullptr, ej_interface);
49 ASSERT_NE(
nullptr, fpc_interface);
50 ASSERT_NE(
nullptr, fvc_interface);
51 ASSERT_NE(
nullptr, fs_interface);
55 ASSERT_EQ(
nullptr, fm_interface);
58 fpc_interface->getHandle(
arm_id +
"_robot"));
60 std::array<double, 16> pose_command = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
61 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
63 EXPECT_EQ(pose_command, fpc_handle.getCommand());
66 fvc_interface->getHandle(
arm_id +
"_robot"));
68 std::array<double, 6> vel_command = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
70 EXPECT_EQ(vel_command, fvc_handle.getCommand());
72 EXPECT_NO_THROW(fs_interface->getHandle(
arm_id +
"_robot"));
75 TEST(FrankaHWTests, JointLimitInterfacesEnforceLimitsOnCommands) {
76 auto robot_ptr = std::make_unique<FrankaHW>();
78 ASSERT_TRUE(robot_ptr->initParameters(nh, nh));
79 robot_ptr->initROSInterfaces(nh);
87 ASSERT_NE(
nullptr, pj_interface);
88 ASSERT_NE(
nullptr, vj_interface);
89 ASSERT_NE(
nullptr, ej_interface);
91 std::vector<joint_limits_interface::JointLimits> joint_limits(7);
92 std::vector<hardware_interface::JointHandle> position_handles(7);
93 std::vector<hardware_interface::JointHandle> velocity_handles(7);
94 std::vector<hardware_interface::JointHandle> effort_handles(7);
100 auto urdf_joint = urdf_model.getJoint(
joint_names[i]);
103 ASSERT_NO_THROW(velocity_handles[i] = vj_interface->getHandle(
joint_names[i]));
104 ASSERT_NO_THROW(effort_handles[i] = ej_interface->getHandle(
joint_names[i]));
107 std::uniform_real_distribution<double> uniform_distribution(0.1, 3.0);
108 std::default_random_engine random_engine;
111 position_handles[i].setCommand(joint_limits[i].max_position +
112 uniform_distribution(random_engine));
113 velocity_handles[i].setCommand(joint_limits[i].max_velocity +
114 uniform_distribution(random_engine));
115 effort_handles[i].setCommand(joint_limits[i].max_effort + uniform_distribution(random_engine));
119 EXPECT_LE(position_handles[i].getCommand(), joint_limits[i].max_position);
120 EXPECT_GE(position_handles[i].getCommand(), joint_limits[i].min_position);
121 EXPECT_LE(velocity_handles[i].getCommand(), joint_limits[i].max_velocity);
122 EXPECT_GE(velocity_handles[i].getCommand(), -joint_limits[i].max_velocity);
123 EXPECT_LE(effort_handles[i].getCommand(), joint_limits[i].max_effort);
124 EXPECT_GE(effort_handles[i].getCommand(), -joint_limits[i].max_effort);
128 position_handles[i].setCommand(joint_limits[i].min_position -
129 uniform_distribution(random_engine));
130 velocity_handles[i].setCommand(-joint_limits[i].max_velocity -
131 uniform_distribution(random_engine));
132 effort_handles[i].setCommand(-joint_limits[i].max_effort - uniform_distribution(random_engine));
136 EXPECT_LE(position_handles[i].getCommand(), joint_limits[i].max_position);
137 EXPECT_GE(position_handles[i].getCommand(), joint_limits[i].min_position);
138 EXPECT_LE(velocity_handles[i].getCommand(), joint_limits[i].max_velocity);
139 EXPECT_GE(velocity_handles[i].getCommand(), -joint_limits[i].max_velocity);
140 EXPECT_LE(effort_handles[i].getCommand(), joint_limits[i].max_effort);
141 EXPECT_GE(effort_handles[i].getCommand(), -joint_limits[i].max_effort);
Hardware interface to command Cartesian poses.
URDF_EXPORT bool initParamWithNodeHandle(const std::string ¶m, const ros::NodeHandle &nh=ros::NodeHandle())
Hardware interface to read the complete robot state.
TEST(FrankaHWTests, InterfacesWorkForReadAndCommand)
std::array< std::string, 7 > joint_names
void setCommand(const std::array< double, 16 > &command) noexcept
Sets the given command.
Handle to read and command a Cartesian velocity.
Handle to read and command a Cartesian pose.
void setCommand(std::array< double, 6 > &command) noexcept
Sets the given command.
JointHandle getHandle(const std::string &name)
Hardware interface to command Cartesian velocities.
bool getJointLimits(urdf::JointConstSharedPtr urdf_joint, JointLimits &limits)
Hardware interface to perform calculations using the dynamic model of a robot.