services_clients.cpp
Go to the documentation of this file.
1 #include <ros/ros.h>
4 
5 #include <ram_msgs/AdditiveManufacturingPose.h>
6 #include <ram_msgs/AdditiveManufacturingTrajectory.h>
7 #include <ram_display/DisplayTrajectory.h>
8 #include <ram_display/DeleteTrajectory.h>
9 
10 #include <gtest/gtest.h>
11 
12 std::unique_ptr<ros::NodeHandle> nh;
13 bool use_gui;
16 
17 // DisplayTrajectory service
18 TEST(TestSuite, testDisplayServiceExistence)
19 {
20  display_traj_client = nh->serviceClient<ram_display::DisplayTrajectory>(
21  "ram/display/add_trajectory");
22  bool exists(display_traj_client.waitForExistence(ros::Duration(1)));
23  EXPECT_TRUE(exists);
24 }
25 
26 // Display: Pose number, wire + axis mode, one color per speed
27 TEST(TestSuite, testSendFirstTrajectoryFirstParameters)
28 {
29  ros::Publisher pub = nh->advertise<ram_msgs::AdditiveManufacturingTrajectory>("ram/trajectory", 1, true);
30  ram_msgs::AdditiveManufacturingTrajectory msg;
31  Eigen::Isometry3d pose_isometry = Eigen::Isometry3d::Identity();
32  for (unsigned j(1); j <= 2; j++) // 2 layers
33  {
34  for (unsigned i(0); i < 14; ++i)
35  {
36  pose_isometry.translation()[0] = cos(i * M_PI / 8);
37  pose_isometry.translation()[1] = sin(i * M_PI / 8);
38  pose_isometry.translation()[2] = j;
39 
40  geometry_msgs::Pose pose_srv;
41  tf::poseEigenToMsg(pose_isometry, pose_srv);
42 
43  ram_msgs::AdditiveManufacturingPose ram_pose;
44  ram_pose.pose = pose_srv;
45  ram_pose.layer_level = j;
46  ram_pose.params.speed = i;
47  msg.poses.push_back(ram_pose);
48  }
49  }
50  while (pub.getNumSubscribers() == 0)
51  {
52  ROS_WARN_STREAM("No subscriber on topic ram/trajectory, waiting...");
53  ros::Duration(0.5).sleep();
54  }
55  pub.publish(msg);
56 
57  ram_display::DisplayTrajectory srv;
58  srv.request.cylinder_size = 0.01;
59  srv.request.wire_size = 5;
60  srv.request.axis_size = 0.2;
61  srv.request.display_mode = 2;
62  srv.request.color_mode = 1;
63  srv.request.display_labels = false;
64  bool success(display_traj_client.call(srv));
65  EXPECT_TRUE(success);
66  EXPECT_TRUE(srv.response.error.empty());
67 
68  if (!srv.response.error.empty())
69  ROS_ERROR_STREAM(srv.response.error);
70 
71  if (use_gui)
72  {
73  ROS_WARN_STREAM("Press enter in the terminal to skip to the next test");
74  while (std::cin.get() != '\n')
75  ros::Duration(0.1).sleep();
76  }
77 }
78 
79 // Display: layer number, cylinder + axis mode, one color per layer
80 TEST(TestSuite, testSendSecondParameters)
81 {
82  // We re-us the same trajectory, no need to publish a new one
83  ram_display::DisplayTrajectory srv;
84  srv.request.cylinder_size = 0.01;
85  srv.request.wire_size = 5;
86  srv.request.axis_size = 0.2;
87  srv.request.display_mode = 3;
88  srv.request.color_mode = 0;
89  srv.request.display_labels = true;
90  srv.request.label_type = 0;
91  srv.request.labels_size = 9;
92  bool success(display_traj_client.call(srv));
93  EXPECT_TRUE(success);
94  EXPECT_TRUE(srv.response.error.empty());
95 
96  if (!srv.response.error.empty())
97  ROS_ERROR_STREAM(srv.response.error);
98 
99  if (use_gui)
100  {
101  ROS_WARN_STREAM("Press enter in the terminal to skip to the next test");
102  while (std::cin.get() != '\n')
103  ros::Duration(0.1).sleep();
104  }
105 }
106 
107 // Send and wrong value in display_mode
108 TEST(TestSuite, testSendSecondWrongParameters)
109 {
110  if (use_gui)
111  return;
112 
113  ram_display::DisplayTrajectory srv;
114  srv.request.display_mode = 5;
115  bool success(display_traj_client.call(srv));
116  EXPECT_TRUE(success);
117  EXPECT_FALSE(srv.response.error.empty());
118 }
119 
120 // DeleteTrajectory service
121 TEST(TestSuite, testDeleteMarkersServiceExistence)
122 {
123  delete_markers_client = nh->serviceClient<ram_display::DeleteTrajectory>("ram/display/delete_trajectory");
124  bool exists(delete_markers_client.waitForExistence(ros::Duration(1)));
125  EXPECT_TRUE(exists);
126 }
127 
128 // Call DeleteTrajectory
129 TEST(TestSuite, testDeleteMarkers)
130 {
131  ram_display::DeleteTrajectory srv;
132  bool success(delete_markers_client.call(srv));
133  EXPECT_TRUE(success);
134 
135  if (use_gui)
136  {
137  ROS_WARN_STREAM("Press enter in the terminal to skip to the next test");
138  while (std::cin.get() != '\n')
139  ros::Duration(0.1).sleep();
140  }
141 
142  if (use_gui)
143  ROS_ERROR_STREAM("PLEASE CLOSE THE RViz WINDOW TO TERMINATE");
144 }
145 
146 int main(int argc,
147  char **argv)
148 {
149  ros::init(argc, argv, "services_clients");
150  nh.reset(new ros::NodeHandle);
151 
152  // Determine if we are running with RViz or not
153  nh->param<bool>("use_gui", use_gui, false);
154  std::string trajectory_frame;
155  nh->param<std::string>("ram/trajectory_frame", trajectory_frame, "base");
156 
157  tf2_ros::Buffer tf_buffer;
158  tf2_ros::TransformListener listener(tf_buffer);
159 
160  bool fetched(false);
161  while (!fetched && ros::ok())
162  {
163  try
164  {
165  tf_buffer.lookupTransform(trajectory_frame, "base", ros::Time(0), ros::Duration(1));
166  fetched = true;
167  }
168  catch (...)
169  {
170  ROS_WARN_STREAM("Could not fetch transformation from " << trajectory_frame << " to base");
171  }
172  }
173 
174  testing::InitGoogleTest(&argc, argv);
175  return RUN_ALL_TESTS();
176 }
std::string trajectory_frame
Definition: ram_display.cpp:21
ros::ServiceClient display_traj_client
void publish(const boost::shared_ptr< M > &message) const
void poseEigenToMsg(const Eigen::Affine3d &e, geometry_msgs::Pose &m)
TEST(TestSuite, testDisplayServiceExistence)
bool sleep() const
std::unique_ptr< ros::NodeHandle > nh
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool call(MReq &req, MRes &res)
int main(int argc, char **argv)
bool waitForExistence(ros::Duration timeout=ros::Duration(-1))
ROSCPP_DECL bool ok()
ros::Publisher pub
#define ROS_WARN_STREAM(args)
uint32_t getNumSubscribers() const
ros::ServiceClient delete_markers_client
bool use_gui
ROSCPP_DECL bool exists(const std::string &service_name, bool print_failure_reason)
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
#define ROS_ERROR_STREAM(args)
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)


ram_display
Author(s): Andres Campos - Institut Maupertuis
autogenerated on Mon Jun 10 2019 14:49:58