46 #include <gtest/gtest.h>
52 static const std::string
LOGNAME =
"basic_servo_tests";
62 ros::topic::waitForMessage<sensor_msgs::JointState>(
"/joint_states");
87 servo_->servo_calcs_->enforceVelLimits(delta_theta);
98 auto parameters = servo_->getParameters();
101 size_t received_count = 0;
102 boost::function<void(
const trajectory_msgs::JointTrajectoryConstPtr&)> traj_callback =
103 [&received_count](
const trajectory_msgs::JointTrajectoryConstPtr& ) { ++received_count; };
104 auto traj_sub = nh_.subscribe(parameters.command_out_topic, 1, traj_callback);
107 auto twist_stamped_pub = nh_.advertise<geometry_msgs::TwistStamped>(parameters.cartesian_command_in_topic, 1);
109 constexpr
double test_duration = 1.0;
110 const double publish_period = parameters.publish_period;
111 const size_t num_commands =
static_cast<size_t>(test_duration / publish_period);
115 ros::Rate publish_rate(2. / publish_period);
118 for (
size_t i = 0; i < num_commands &&
ros::ok(); ++i)
120 auto msg = moveit::util::make_shared_from_pool<geometry_msgs::TwistStamped>();
122 msg->header.frame_id =
"panda_link0";
123 msg->twist.angular.y = 1.0;
126 twist_stamped_pub.publish(msg);
127 publish_rate.
sleep();
130 EXPECT_GT(received_count, num_commands - 20);
131 EXPECT_GT(received_count, (
unsigned)0);
132 EXPECT_LT(received_count, num_commands + 20);
133 servo_->setPaused(
true);
140 auto parameters = servo_->getParameters();
143 size_t received_count = 0;
144 boost::function<void(
const trajectory_msgs::JointTrajectoryConstPtr&)> traj_callback =
145 [&received_count](
const trajectory_msgs::JointTrajectoryConstPtr& ) { ++received_count; };
146 auto traj_sub = nh_.subscribe(parameters.command_out_topic, 1, traj_callback);
149 auto joint_servo_pub = nh_.advertise<control_msgs::JointJog>(parameters.joint_command_in_topic, 1);
151 constexpr
double test_duration = 1.0;
152 const double publish_period = parameters.publish_period;
153 const size_t num_commands =
static_cast<size_t>(test_duration / publish_period);
157 ros::Rate publish_rate(2. / publish_period);
160 for (
size_t i = 0; i < num_commands &&
ros::ok(); ++i)
162 auto msg = moveit::util::make_shared_from_pool<control_msgs::JointJog>();
164 msg->header.frame_id =
"panda_link3";
165 msg->velocities.push_back(0.1);
168 joint_servo_pub.publish(msg);
169 publish_rate.
sleep();
172 EXPECT_GT(received_count, num_commands - 20);
173 EXPECT_GT(received_count, (
unsigned)0);
174 EXPECT_LT(received_count, num_commands + 20);
175 servo_->setPaused(
true);
181 auto parameters = servo_->getParameters();
182 const double publish_period = parameters.publish_period;
185 Eigen::ArrayXd delta_theta(7);
187 delta_theta[1] = 0.01;
188 delta_theta[2] = 0.02;
189 delta_theta[3] = 0.03;
190 delta_theta[4] = 0.04;
191 delta_theta[5] = 0.05;
192 delta_theta[6] = 0.06;
195 Eigen::ArrayXd orig_delta_theta = delta_theta;
196 enforceVelLimits(delta_theta);
199 const double panda_max_joint_vel = 2.610;
200 const double velocity_scaling_factor = panda_max_joint_vel / (orig_delta_theta.maxCoeff() / publish_period);
202 for (
int i = 0; i < 7; ++i)
210 delta_theta[1] = -0.01;
211 delta_theta[2] = -0.02;
212 delta_theta[3] = -0.03;
213 delta_theta[4] = -0.04;
214 delta_theta[5] = -0.05;
215 delta_theta[6] = -0.06;
218 orig_delta_theta = delta_theta;
219 enforceVelLimits(delta_theta);
220 for (
int i = 0; i < 7; ++i)
228 delta_theta[1] = -0.013;
229 delta_theta[2] = 0.023;
230 delta_theta[3] = -0.004;
231 delta_theta[4] = 0.021;
232 delta_theta[5] = 0.012;
233 delta_theta[6] = 0.0075;
236 orig_delta_theta = delta_theta;
237 enforceVelLimits(delta_theta);
238 for (
int i = 0; i < 7; ++i)
245 int main(
int argc,
char** argv)
248 testing::InitGoogleTest(&argc, argv);
253 int result = RUN_ALL_TESTS();