31 #include <gtest/gtest.h> 45 std::string host =
"127.0.0.1";
46 TCPSocket::setup(host, port);
50 TCPSocket::setReceiveTimeout(tv);
53 void send(
const int32_t& result)
55 uint8_t buffer[
sizeof(int32_t)];
56 int32_t val = htobe32(result);
57 std::memcpy(buffer, &val,
sizeof(int32_t));
59 TCPSocket::write(buffer,
sizeof(buffer), written);
63 int32_t& blend_radius_or_spline_type, int32_t& motion_type)
66 uint8_t buf[
sizeof(int32_t) * 21];
69 size_t remainder =
sizeof(int32_t) * 21;
72 TCPSocket::setOptions(getSocketFD());
73 if (!TCPSocket::read(b_pos, remainder, read))
75 std::cout <<
"Failed to read from socket, this should not happen during a test!" << std::endl;
85 for (
unsigned int i = 0; i < pos.size(); ++i)
87 std::memcpy(&val, b_pos,
sizeof(int32_t));
88 pos[i] = be32toh(val);
89 b_pos +=
sizeof(int32_t);
93 for (
unsigned int i = 0; i < pos.size(); ++i)
95 std::memcpy(&val, b_pos,
sizeof(int32_t));
96 vel[i] = be32toh(val);
97 b_pos +=
sizeof(int32_t);
101 for (
unsigned int i = 0; i < pos.size(); ++i)
103 std::memcpy(&val, b_pos,
sizeof(int32_t));
104 acc[i] = be32toh(val);
105 b_pos +=
sizeof(int32_t);
109 std::memcpy(&val, b_pos,
sizeof(int32_t));
110 goal_time = be32toh(val);
111 b_pos +=
sizeof(int32_t);
114 std::memcpy(&val, b_pos,
sizeof(int32_t));
115 blend_radius_or_spline_type = be32toh(val);
116 b_pos +=
sizeof(int32_t);
119 std::memcpy(&val, b_pos,
sizeof(int32_t));
120 motion_type = be32toh(val);
125 int32_t goal_time, blend_radius_or_spline_type, motion_type;
127 readMessage(pos, vel, acc, goal_time, blend_radius_or_spline_type, motion_type);
133 int32_t goal_time, blend_radius_or_spline_type, motion_type;
135 readMessage(pos, vel, acc, goal_time, blend_radius_or_spline_type, motion_type);
141 int32_t goal_time, blend_radius_or_spline_type, motion_type;
143 readMessage(pos, vel, acc, goal_time, blend_radius_or_spline_type, motion_type);
149 int32_t goal_time, blend_radius_or_spline_type, motion_type;
151 readMessage(pos, vel, acc, goal_time, blend_radius_or_spline_type, motion_type);
152 return blend_radius_or_spline_type;
157 int32_t goal_time, blend_radius_or_spline_type, motion_type;
159 readMessage(pos, vel, acc, goal_time, blend_radius_or_spline_type, motion_type);
177 virtual bool open(
int socket_fd,
struct sockaddr* address,
size_t address_len)
179 return ::connect(socket_fd, address, address_len) == 0;
186 client_.reset(
new Client(50003));
188 std::this_thread::sleep_for(std::chrono::seconds(1));
205 std::lock_guard<std::mutex> lk(trajectory_end_mutex_);
206 trajectory_end_.notify_one();
213 std::unique_lock<std::mutex> lk(trajectory_end_mutex_);
214 if (trajectory_end_.wait_for(lk, std::chrono::milliseconds(milliseconds)) == std::cv_status::no_timeout ||
217 if (result_ == result)
234 traj_point_interface_->writeTrajectoryPoint(&send_positions, 0, 0, 0);
237 EXPECT_EQ(send_positions[0], ((
double)received_positions[0]) / traj_point_interface_->MULT_JOINTSTATE);
238 EXPECT_EQ(send_positions[1], ((
double)received_positions[1]) / traj_point_interface_->MULT_JOINTSTATE);
239 EXPECT_EQ(send_positions[2], ((
double)received_positions[2]) / traj_point_interface_->MULT_JOINTSTATE);
240 EXPECT_EQ(send_positions[3], ((
double)received_positions[3]) / traj_point_interface_->MULT_JOINTSTATE);
241 EXPECT_EQ(send_positions[4], ((
double)received_positions[4]) / traj_point_interface_->MULT_JOINTSTATE);
242 EXPECT_EQ(send_positions[5], ((
double)received_positions[5]) / traj_point_interface_->MULT_JOINTSTATE);
250 float send_goal_time = 0.5;
251 traj_point_interface_->writeTrajectorySplinePoint(&send_pos, &send_vel, &send_acc, send_goal_time);
252 Client::TrajData received_data = client_->getData();
255 EXPECT_EQ(send_pos[0], ((
double)received_data.pos[0]) / traj_point_interface_->MULT_JOINTSTATE);
256 EXPECT_EQ(send_pos[1], ((
double)received_data.pos[1]) / traj_point_interface_->MULT_JOINTSTATE);
257 EXPECT_EQ(send_pos[2], ((
double)received_data.pos[2]) / traj_point_interface_->MULT_JOINTSTATE);
258 EXPECT_EQ(send_pos[3], ((
double)received_data.pos[3]) / traj_point_interface_->MULT_JOINTSTATE);
259 EXPECT_EQ(send_pos[4], ((
double)received_data.pos[4]) / traj_point_interface_->MULT_JOINTSTATE);
260 EXPECT_EQ(send_pos[5], ((
double)received_data.pos[5]) / traj_point_interface_->MULT_JOINTSTATE);
263 EXPECT_EQ(send_vel[0], ((
double)received_data.vel[0]) / traj_point_interface_->MULT_JOINTSTATE);
264 EXPECT_EQ(send_vel[1], ((
double)received_data.vel[1]) / traj_point_interface_->MULT_JOINTSTATE);
265 EXPECT_EQ(send_vel[2], ((
double)received_data.vel[2]) / traj_point_interface_->MULT_JOINTSTATE);
266 EXPECT_EQ(send_vel[3], ((
double)received_data.vel[3]) / traj_point_interface_->MULT_JOINTSTATE);
267 EXPECT_EQ(send_vel[4], ((
double)received_data.vel[4]) / traj_point_interface_->MULT_JOINTSTATE);
268 EXPECT_EQ(send_vel[5], ((
double)received_data.vel[5]) / traj_point_interface_->MULT_JOINTSTATE);
271 EXPECT_EQ(send_acc[0], ((
double)received_data.acc[0]) / traj_point_interface_->MULT_JOINTSTATE);
272 EXPECT_EQ(send_acc[1], ((
double)received_data.acc[1]) / traj_point_interface_->MULT_JOINTSTATE);
273 EXPECT_EQ(send_acc[2], ((
double)received_data.acc[2]) / traj_point_interface_->MULT_JOINTSTATE);
274 EXPECT_EQ(send_acc[3], ((
double)received_data.acc[3]) / traj_point_interface_->MULT_JOINTSTATE);
275 EXPECT_EQ(send_acc[4], ((
double)received_data.acc[4]) / traj_point_interface_->MULT_JOINTSTATE);
276 EXPECT_EQ(send_acc[5], ((
double)received_data.acc[5]) / traj_point_interface_->MULT_JOINTSTATE);
279 EXPECT_EQ(send_goal_time, ((
double)received_data.goal_time / traj_point_interface_->MULT_TIME));
283 received_data.blend_radius_or_spline_type);
294 float send_goal_time = 1.5;
295 traj_point_interface_->writeTrajectorySplinePoint(&send_pos, &send_vel,
nullptr, send_goal_time);
296 Client::TrajData received_data = client_->getData();
299 EXPECT_EQ(send_pos[0], ((
double)received_data.pos[0]) / traj_point_interface_->MULT_JOINTSTATE);
300 EXPECT_EQ(send_pos[1], ((
double)received_data.pos[1]) / traj_point_interface_->MULT_JOINTSTATE);
301 EXPECT_EQ(send_pos[2], ((
double)received_data.pos[2]) / traj_point_interface_->MULT_JOINTSTATE);
302 EXPECT_EQ(send_pos[3], ((
double)received_data.pos[3]) / traj_point_interface_->MULT_JOINTSTATE);
303 EXPECT_EQ(send_pos[4], ((
double)received_data.pos[4]) / traj_point_interface_->MULT_JOINTSTATE);
304 EXPECT_EQ(send_pos[5], ((
double)received_data.pos[5]) / traj_point_interface_->MULT_JOINTSTATE);
307 EXPECT_EQ(send_vel[0], ((
double)received_data.vel[0]) / traj_point_interface_->MULT_JOINTSTATE);
308 EXPECT_EQ(send_vel[1], ((
double)received_data.vel[1]) / traj_point_interface_->MULT_JOINTSTATE);
309 EXPECT_EQ(send_vel[2], ((
double)received_data.vel[2]) / traj_point_interface_->MULT_JOINTSTATE);
310 EXPECT_EQ(send_vel[3], ((
double)received_data.vel[3]) / traj_point_interface_->MULT_JOINTSTATE);
311 EXPECT_EQ(send_vel[4], ((
double)received_data.vel[4]) / traj_point_interface_->MULT_JOINTSTATE);
312 EXPECT_EQ(send_vel[5], ((
double)received_data.vel[5]) / traj_point_interface_->MULT_JOINTSTATE);
315 EXPECT_EQ(send_acc[0], ((
double)received_data.acc[0]) / traj_point_interface_->MULT_JOINTSTATE);
316 EXPECT_EQ(send_acc[1], ((
double)received_data.acc[1]) / traj_point_interface_->MULT_JOINTSTATE);
317 EXPECT_EQ(send_acc[2], ((
double)received_data.acc[2]) / traj_point_interface_->MULT_JOINTSTATE);
318 EXPECT_EQ(send_acc[3], ((
double)received_data.acc[3]) / traj_point_interface_->MULT_JOINTSTATE);
319 EXPECT_EQ(send_acc[4], ((
double)received_data.acc[4]) / traj_point_interface_->MULT_JOINTSTATE);
320 EXPECT_EQ(send_acc[5], ((
double)received_data.acc[5]) / traj_point_interface_->MULT_JOINTSTATE);
323 EXPECT_EQ(send_goal_time, ((
double)received_data.goal_time) / traj_point_interface_->MULT_TIME);
327 received_data.blend_radius_or_spline_type);
338 float send_goal_time = 0.5;
339 traj_point_interface_->writeTrajectorySplinePoint(&send_pos, &send_vel, &send_acc, send_goal_time);
342 EXPECT_EQ(send_vel[0], ((
double)received_velocities[0]) / traj_point_interface_->MULT_JOINTSTATE);
343 EXPECT_EQ(send_vel[1], ((
double)received_velocities[1]) / traj_point_interface_->MULT_JOINTSTATE);
344 EXPECT_EQ(send_vel[2], ((
double)received_velocities[2]) / traj_point_interface_->MULT_JOINTSTATE);
345 EXPECT_EQ(send_vel[3], ((
double)received_velocities[3]) / traj_point_interface_->MULT_JOINTSTATE);
346 EXPECT_EQ(send_vel[4], ((
double)received_velocities[4]) / traj_point_interface_->MULT_JOINTSTATE);
347 EXPECT_EQ(send_vel[5], ((
double)received_velocities[5]) / traj_point_interface_->MULT_JOINTSTATE);
355 float send_goal_time = 0.5;
356 traj_point_interface_->writeTrajectorySplinePoint(&send_pos, &send_vel, &send_acc, send_goal_time);
359 EXPECT_EQ(send_vel[0], ((
double)received_velocities[0]) / traj_point_interface_->MULT_JOINTSTATE);
360 EXPECT_EQ(send_vel[1], ((
double)received_velocities[1]) / traj_point_interface_->MULT_JOINTSTATE);
361 EXPECT_EQ(send_vel[2], ((
double)received_velocities[2]) / traj_point_interface_->MULT_JOINTSTATE);
362 EXPECT_EQ(send_vel[3], ((
double)received_velocities[3]) / traj_point_interface_->MULT_JOINTSTATE);
363 EXPECT_EQ(send_vel[4], ((
double)received_velocities[4]) / traj_point_interface_->MULT_JOINTSTATE);
364 EXPECT_EQ(send_vel[5], ((
double)received_velocities[5]) / traj_point_interface_->MULT_JOINTSTATE);
370 float send_goal_time = 0.5;
371 traj_point_interface_->writeTrajectoryPoint(&send_positions, send_goal_time, 0, 0);
372 int32_t received_goal_time = client_->getGoalTime();
374 EXPECT_EQ(send_goal_time, ((
float)received_goal_time) / traj_point_interface_->MULT_TIME);
380 float send_blend_radius = 0.5;
381 traj_point_interface_->writeTrajectoryPoint(&send_positions, 0, send_blend_radius, 0);
382 int32_t received_blend_radius = client_->getBlendRadius();
384 EXPECT_EQ(send_blend_radius, ((
float)received_blend_radius) / traj_point_interface_->MULT_TIME);
391 bool send_cartesian =
true;
392 traj_point_interface_->writeTrajectoryPoint(&send_positions, 0, 0, send_cartesian);
393 bool received_cartesian = bool(client_->getMotionType());
395 EXPECT_EQ(send_cartesian, received_cartesian);
398 send_cartesian =
false;
399 traj_point_interface_->writeTrajectoryPoint(&send_positions, 0, 0, send_cartesian);
400 received_cartesian = bool(client_->getMotionType());
402 EXPECT_EQ(send_cartesian, received_cartesian);
407 traj_point_interface_->setTrajectoryEndCallback(
420 int main(
int argc,
char* argv[])
422 ::testing::InitGoogleTest(&argc, argv);
424 return RUN_ALL_TESTS();
std::unique_ptr< Client > client_
TrajectoryResult
Types for encoding trajectory execution result.
void handleTrajectoryEnd(control::TrajectoryResult result)
virtual bool open(int socket_fd, struct sockaddr *address, size_t address_len)
The TrajectoryPointInterface class handles trajectory forwarding to the robot. Full trajectories are ...
int32_t blend_radius_or_spline_type
vector6int32_t getPosition()
vector6int32_t getVelocity()
std::unique_ptr< control::TrajectoryPointInterface > traj_point_interface_
TEST_F(TrajectoryPointInterfaceTest, write_postions)
bool waitTrajectoryEnd(int milliseconds=100, control::TrajectoryResult result=control::TrajectoryResult::TRAJECTORY_RESULT_CANCELED)
Aborted due to error during execution.
void readMessage(vector6int32_t &pos, vector6int32_t &vel, vector6int32_t &acc, int32_t &goal_time, int32_t &blend_radius_or_spline_type, int32_t &motion_type)
std::mutex trajectory_end_mutex_
std::condition_variable trajectory_end_
std::array< int32_t, 6 > vector6int32_t
Class for TCP socket abstraction.
constexpr std::underlying_type< E >::type toUnderlying(const E e) noexcept
Converts an enum type to its underlying type.
Socket is connected and ready to use.
void send(const int32_t &result)
control::TrajectoryResult result_
std::array< double, 6 > vector6d_t
int main(int argc, char *argv[])