acceptancetest_hironx.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2014, TORK (Tokyo Opensource Robotics Kyokai Association)
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of JSK Lab, University of Tokyo. nor the
18  * names of its contributors may be used to endorse or promote products
19  * derived from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #include <iostream>
36 #include <string>
37 #include <vector>
38 
39 #include <ros/ros.h>
40 #include <ros_client.cpp>
43 
44 #include <sstream>
45 
46 template<class T>
47  std::string to_string(T a)
48  {
49  std::stringstream ss;
50  ss << a;
51  return ss.str();
52  }
53 
55 {
56  /*
57  This class holds methods that can be used for verification of the robot
58  Kawada Industries' dual-arm robot Hiro (and the same model of other robots
59  e.g. NEXTAGE OPEN).
60 
61  This test class is:
62  - Intended to be run as nosetests, ie. roscore isn't available by itself.
63  - Almost all the testcases don't run without an access to a robot running.
64 
65  Above said, combined with a rostest that launches roscore and robot (either
66  simulation or real) hopefully these testcases can be run, both in batch
67  manner by rostest and in nosetest manner.
68 
69  Prefix for methods 'at' means 'acceptance test'.
70 
71  All time arguments are second.
72 
73  */
74 public:
75  typedef std::vector<double> DVEC;
76  typedef std::vector<DVEC> DMAT;
77 
78  static const double positions_larm_deg_up[6];
79  static const double positions_larm_deg_down[6];
80  static const double positions_rarm_deg_down[6];
81  static const double positions_larm_deg_up_sync[6];
82  static const double positions_rarm_deg_up_sync[6];
83  static const double rotation_angles_head_1[2][2];
84  static const double rotation_angles_head_2[2][2];
85  static const double positions_torso_deg[2][1];
86  static const double R_Z_SMALLINCREMENT;
87  // WORKSPACE; x near, y far
88  static const double pos_l_x_near_y_far[3];
89  static const double rpy_l_x_near_y_far[3];
90  static const double pos_r_x_near_y_far[3];
91  static const double rpy_r_x_near_y_far[3];
92  // workspace; x far, y far
93  static const double pos_l_x_far_y_far[3];
94  static const double rpy_l_x_far_y_far[3];
95  static const double pos_r_x_far_y_far[3];
96  static const double rpy_r_x_far_y_far[3];
97 
98  static const double TASK_DURATION_DEFAULT;
99  static const double TASK_DURATION_TORSO;
100  static const double DURATION_EACH_SMALLINCREMENT;
101  static const double TASK_DURATION_HEAD;
102  static const int SLEEP_TIME;
103  static const int SLEEP_OVERWRITE;
104 
105  static const int DURATION_TOTAL_SMALLINCREMENT; // second
106 
115 
116  // WORKSPACE; X NEAR, Y FAR
121  // WORKSPACE; X FAR, Y FAR
126 
127 #define INIT_VEC(name, num) name, name+num
128 #define VEC_COPY(from, to, N1, N2) for (int i = 0; i < N1; ++i) for (int j = 0; j < N2; ++j)to[i][j] = from[i][j];
129  AcceptanceTest_Hiro(std::string name = "Hironx(Robot)0", std::string url = "") :
131  POSITIONS_LARM_DEG_UP(INIT_VEC(positions_larm_deg_up, 6)),
132  POSITIONS_LARM_DEG_DOWN(INIT_VEC(positions_larm_deg_down, 6)),
133  POSITIONS_RARM_DEG_DOWN(INIT_VEC(positions_rarm_deg_down, 6)),
134  POSITIONS_LARM_DEG_UP_SYNC(INIT_VEC(positions_larm_deg_up_sync, 6)),
135  POSITIONS_RARM_DEG_UP_SYNC(INIT_VEC(positions_rarm_deg_up_sync, 6)),
136 
137  ROTATION_ANGLES_HEAD_1(2, DVEC(2)), ROTATION_ANGLES_HEAD_2(2, DVEC(2)), POSITIONS_TORSO_DEG(2, DVEC(1)),
138 
139  // WORKSPACE, X NEAR, Y FAR
140  POS_L_X_NEAR_Y_FAR(INIT_VEC(pos_l_x_near_y_far, 3)), RPY_L_X_NEAR_Y_FAR(INIT_VEC(rpy_l_x_near_y_far, 3)),
141  POS_R_X_NEAR_Y_FAR(INIT_VEC(pos_r_x_near_y_far, 3)), RPY_R_X_NEAR_Y_FAR(INIT_VEC(rpy_r_x_near_y_far, 3)),
142  // WORKSPACE, X FAR, Y FAR
143  POS_L_X_FAR_Y_FAR(INIT_VEC(pos_l_x_far_y_far, 3)), RPY_L_X_FAR_Y_FAR(INIT_VEC(rpy_l_x_far_y_far, 3)),
144  POS_R_X_FAR_Y_FAR(INIT_VEC(pos_r_x_far_y_far, 3)), RPY_R_X_FAR_Y_FAR(INIT_VEC(rpy_r_x_far_y_far, 3))
145  {
146  VEC_COPY(rotation_angles_head_1, ROTATION_ANGLES_HEAD_1, 2, 2)
147  VEC_COPY(rotation_angles_head_2, ROTATION_ANGLES_HEAD_2, 2, 2)
148  VEC_COPY(positions_torso_deg, POSITIONS_TORSO_DEG, 2, 1)
149  }
150 
151  std::string retName()
152  {
153  return rtm_robotname;
154  }
155 
156  void wait_input(std::string msg, bool do_wait_input = false)
157  {
158  /*
159  @type msg: str
160  @param msg: To be printed on prompt.
161  @param do_wait_input: If True python commandline waits for any input
162  to proceed.
163  */
164  if (!msg.empty())
165  msg = "\n" + msg + "= ";
166  if (do_wait_input)
167  {
168  // exception
169  }
170  }
171 
172  void run_test_ros(bool do_wait_input = false)
173  {
174  /*
175  Run by ROS exactly the same actions that run_tests_rtm performs.
176  @param do_wait_input: If True, the user will be asked to hit any key
177  before each task to proceed.
178  */
179  ROS_INFO("********RUN_TEST_ROS************");
180  run_tests(acceptance_ros_client, do_wait_input);
181  }
182 
183  void run_tests(AbstAcceptanceTest& test_client, bool do_wait_input = false)
184  {
185  std::string msg_type_client = "";
186  if (typeid(test_client) == typeid(AcceptanceTestRos))
187  msg_type_client = "(ROS) ";
188  // else if(typeid(test_client) == typeid(AcceptanceTestRTM))
189  // msg_type_client = "(RTM) ";
190  std::string msg = msg_type_client;
191 
192  test_client.go_initpos();
193 
194  std::string msg_task = "TASK-1. Move each arm separately to the given pose by passing joint space.";
195  msg = msg_type_client + msg_task;
196  wait_input(msg, do_wait_input);
197  move_armbyarm_jointangles(test_client);
198 
199  msg_task =
200  "TASK-1. Move each arm separately to the given pose by passing pose in hand space "
201  "(i.e. orthogonal coordinate of eef).";
202  ROS_INFO("%s", msg_task.c_str());
203  msg = msg_type_client + msg_task;
204  wait_input(msg, do_wait_input);
205  move_armbyarm_pose(test_client);
206 
207  msg_task = "TASK-2. Move both arms at the same time using relative distance and angle from the current pose.";
208  ROS_INFO("%s", msg_task.c_str());
209  msg = msg_type_client + msg_task;
210  wait_input(msg, do_wait_input);
211  movearms_together(test_client);
212 
213  msg_task = "TASK-3. Move arm with very small increment (0.1mm/sec).\n\tRight hand 3 cm upward over 30 seconds.";
214  msg = msg_type_client + msg_task;
215  wait_input(msg, do_wait_input);
216  set_pose_relative(test_client);
217 
218  msg_task = "In the beginning you\"ll see the displacement of the previous task."
219  "\nTASK-4. Move head using Joint angles in degree.";
220  ROS_INFO("%s", msg_task.c_str());
221  msg = msg_type_client + msg_task;
222  wait_input(msg, do_wait_input);
223  move_head(test_client);
224 
225  msg_task = "TASK-5. Rotate torso to the left and right 130 degree.";
226  ROS_INFO("%s", msg_task.c_str());
227  msg = msg_type_client + msg_task;
228  wait_input(msg, do_wait_input);
229  move_torso(test_client);
230 
231  msg_task = std::string("TASK-6. Overwrite ongoing action.\n\t6-1."
232  "While rotating torso toward left, it getscanceled and rotate toward "
233  "right.\n\t6-2. While lifting left hand, right hand also tries to reach "
234  "the same height that gets cancelled so that it stays lower than the left hand.");
235  ROS_INFO("%s", msg_task.c_str());
236  msg = msg_type_client + msg_task;
237  wait_input(msg, do_wait_input);
238  overwrite_torso(test_client);
239  // task6-2
240  overwrite_arm(test_client);
241 
242  msg_task = "TASK-7. Show the capable workspace on front side of the robot.";
243  msg = msg_type_client + msg_task;
244  wait_input(msg, do_wait_input);
245  show_workspace(test_client);
246  }
247 
249  {
250  /*
251  @type test_client: hironx_ros_robotics.abst_acceptancetest.AbstAcceptanceTest
252  */
253  test_client.go_initpos(7.0);
254  std::string arm = AbstAcceptanceTest::GRNAME_LEFT_ARM;
255  test_client.set_joint_angles(arm, POSITIONS_LARM_DEG_UP, "Task1 " + to_string(arm));
256 
258  test_client.set_joint_angles(arm, POSITIONS_RARM_DEG_DOWN, "Task1 " + to_string(arm));
259  ros::Duration(SLEEP_TIME).sleep();
260  }
261 
263  {
264  ROS_INFO("** _move_armbyarm_pose isn\"t yet implemented");
265  }
266 
268  {
269  // @type test_client: hironx_ros_robotics.abst_acceptancetest.AbstAcceptanceTest
270  test_client.go_initpos();
271  std::string arm = AbstAcceptanceTest::GRNAME_LEFT_ARM;
272  test_client.set_joint_angles(arm, POSITIONS_LARM_DEG_UP_SYNC, to_string(arm), TASK_DURATION_DEFAULT, false);
273  /*
274  task2; Under current implementation, left arm
275  always moves first, followed immediately by right arm")
276  */
278  test_client.set_joint_angles(arm, POSITIONS_RARM_DEG_DOWN, to_string(arm), TASK_DURATION_DEFAULT, false);
279  ros::Duration(SLEEP_TIME).sleep();
280  }
281 
283  {
284  test_client.go_initpos();
285  double delta = R_Z_SMALLINCREMENT;
287  double t_total_sec = DURATION_TOTAL_SMALLINCREMENT;
288  int total_increment = t_total_sec / t;
289  std::string msg_1 = "Right arm is moving upward with " + to_string(delta) + "mm increment per " + to_string(t)
290  + "s.";
291  std::string msg_2 = " (Total " + to_string(delta * total_increment) + "cm over " + to_string(t_total_sec) + "s).";
292  ROS_INFO("%s", (msg_1 + msg_2).c_str());
293  for (int i = 0; i < total_increment; ++i)
294  {
295  std::string msg_eachloop = to_string(i);
296  msg_eachloop += "th loop;";
297  test_client.set_pose_relative(AbstAcceptanceTest::GRNAME_RIGHT_ARM, 0, 0, delta, 0, 0, 0, msg_eachloop, t, true);
298  }
299  }
300 
301  void move_head(AbstAcceptanceTest& test_client)
302  {
303  test_client.go_initpos();
304 
305  for (std::vector<std::vector<double> >::iterator positions = ROTATION_ANGLES_HEAD_1.begin();
306  positions != ROTATION_ANGLES_HEAD_1.end(); ++positions)
307  {
308  test_client.set_joint_angles(AbstAcceptanceTest::GRNAME_HEAD, *positions, "(1);", TASK_DURATION_HEAD);
309  }
310  for (std::vector<std::vector<double> >::iterator positions = ROTATION_ANGLES_HEAD_2.begin();
311  positions != ROTATION_ANGLES_HEAD_2.end(); ++positions)
312  {
313  test_client.set_joint_angles(AbstAcceptanceTest::GRNAME_HEAD, *positions, "(2);", TASK_DURATION_HEAD);
314  }
315  }
316 
317  void move_torso(AbstAcceptanceTest& test_client)
318  {
319  test_client.go_initpos();
320  for (std::vector<std::vector<double> >::iterator positions = POSITIONS_TORSO_DEG.begin();
321  positions != POSITIONS_TORSO_DEG.end(); ++positions)
322  {
323  test_client.set_joint_angles(AbstAcceptanceTest::GRNAME_TORSO, *positions);
324  }
325  }
326 
328  {
329  test_client.go_initpos();
330  test_client.set_joint_angles(AbstAcceptanceTest::GRNAME_TORSO, POSITIONS_TORSO_DEG[0], "(1)", TASK_DURATION_TORSO,
331  false);
332 
333  ros::Duration(SLEEP_OVERWRITE).sleep();
334 
335  test_client.set_joint_angles(AbstAcceptanceTest::GRNAME_TORSO, POSITIONS_TORSO_DEG[1], "(2)", TASK_DURATION_TORSO,
336  true);
337 
338  ros::Duration(SLEEP_OVERWRITE).sleep();
339  }
340 
342  {
343  test_client.go_initpos();
344  test_client.set_joint_angles(AbstAcceptanceTest::GRNAME_LEFT_ARM, POSITIONS_LARM_DEG_UP_SYNC, "(1)",
345  TASK_DURATION_DEFAULT, false);
346  test_client.set_joint_angles(
348  POSITIONS_RARM_DEG_UP_SYNC,
349  std::string("(2) begins. Overwrite previous arm command.\n\t"
350  "In the beginning both arm starts to move to the\n\tsame height"
351  "but to the left arm interrupting\ncommand is sent and it goes downward."),
352  TASK_DURATION_DEFAULT, false);
353 
354  ros::Duration(SLEEP_OVERWRITE).sleep();
355 
356  test_client.set_joint_angles(AbstAcceptanceTest::GRNAME_LEFT_ARM, POSITIONS_LARM_DEG_DOWN, "(3)",
357  TASK_DURATION_DEFAULT, false);
358 
359  ros::Duration((int)TASK_DURATION_DEFAULT).sleep();
360  }
361 
363  {
364  test_client.go_initpos();
365  std::string msg = "; ";
366 
367  std::string larm = AbstAcceptanceTest::GRNAME_LEFT_ARM;
368  std::string rarm = AbstAcceptanceTest::GRNAME_RIGHT_ARM;
369  // X near, Y far.
370  test_client.set_pose(larm, POS_L_X_NEAR_Y_FAR, RPY_L_X_NEAR_Y_FAR, msg + to_string(larm), TASK_DURATION_DEFAULT,
371  false);
372  test_client.set_pose(rarm, POS_R_X_NEAR_Y_FAR, RPY_R_X_NEAR_Y_FAR, msg + to_string(rarm), TASK_DURATION_DEFAULT,
373  true);
374  // X far, Y far.
375  test_client.set_pose(larm, POS_L_X_FAR_Y_FAR, RPY_L_X_FAR_Y_FAR, msg + to_string(larm), TASK_DURATION_DEFAULT,
376  false);
377  test_client.set_pose(rarm, POS_R_X_FAR_Y_FAR, RPY_R_X_FAR_Y_FAR, msg + to_string(rarm), TASK_DURATION_DEFAULT,
378  true);
379  }
380 
381 private:
382  const std::string rtm_robotname;
383  const std::string rtm_url;
384 
387 };
388 
389 // init parameters
390 const double AcceptanceTest_Hiro::positions_larm_deg_up[6] = {-4.697, -2.012, -117.108, -17.180, 29.146, -3.739};
391 const double AcceptanceTest_Hiro::positions_larm_deg_down[6] = {6.196, -5.311, -73.086, -15.287, -12.906, -2.957};
392 const double AcceptanceTest_Hiro::positions_rarm_deg_down[6] = {-4.949, -3.372, -80.050, 15.067, -7.734, 3.086};
393 const double AcceptanceTest_Hiro::positions_larm_deg_up_sync[6] = {-4.695, -2.009, -117.103, -17.178, 29.138, -3.738};
394 const double AcceptanceTest_Hiro::positions_rarm_deg_up_sync[6] = {4.695, -2.009, -117.103, 17.178, 29.138, 3.738};
395 const double AcceptanceTest_Hiro::rotation_angles_head_1[2][2] = { {0.1, 0.0}, {50.0, 10.0}};
396 const double AcceptanceTest_Hiro::rotation_angles_head_2[2][2] = { {-50, -10}, {0, 0}};
397 const double AcceptanceTest_Hiro::positions_torso_deg[2][1] = { {130.0}, {-130.0}};
398 
399 const double AcceptanceTest_Hiro::R_Z_SMALLINCREMENT = 0.0001;
400 // Workspace; X near, Y far
401 const double AcceptanceTest_Hiro::pos_l_x_near_y_far[3] = {0.326, 0.474, 1.038};
402 const double AcceptanceTest_Hiro::rpy_l_x_near_y_far[3] = {-3.075, -1.569, 3.074};
403 const double AcceptanceTest_Hiro::pos_r_x_near_y_far[3] = {0.326, -0.472, 1.048};
404 const double AcceptanceTest_Hiro::rpy_r_x_near_y_far[3] = {3.073, -1.569, -3.072};
405 // workspace; x far, y far
406 const double AcceptanceTest_Hiro::pos_l_x_far_y_far[3] = {0.47548142379781055, 0.17430276793604782, 1.0376878025614884};
407 const double AcceptanceTest_Hiro::rpy_l_x_far_y_far[3] = {-3.075954857224205, -1.5690261926181046, 3.0757659493049574};
408 const double AcceptanceTest_Hiro::pos_r_x_far_y_far[3] = {0.4755337947019357, -0.17242322190721648, 1.0476395479774052};
409 const double AcceptanceTest_Hiro::rpy_r_x_far_y_far[3] = {3.0715850722714944, -1.5690204449882248, -3.071395243174742};
410 
415 const int AcceptanceTest_Hiro::SLEEP_TIME = 2;
417 
419 int main(int argc, char* argv[])
420 {
421  // Init the ROS node
422  ros::init(argc, argv, "hironx_ros_client");
423 
425  test.run_test_ros();
426  return 0;
427 }
static const double pos_l_x_near_y_far[3]
#define INIT_VEC(name, num)
void move_torso(AbstAcceptanceTest &test_client)
static const double positions_larm_deg_up[6]
void overwrite_arm(AbstAcceptanceTest &test_client)
virtual void set_pose_relative(std::string joint_group, int dx=0, int dy=0, int dz=0, int dr=0, int dp=0, int dw=0, std::string msg_tasktitle="", double task_duration=7.0, bool do_wait=true)
static std::string GRNAME_HEAD
static std::string GRNAME_LEFT_ARM
bool sleep() const
std::vector< DVEC > DMAT
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
static const double rpy_r_x_far_y_far[3]
name
const std::string rtm_robotname
static const double pos_r_x_far_y_far[3]
static const double DURATION_EACH_SMALLINCREMENT
png_uint_32 i
void wait_input(std::string msg, bool do_wait_input=false)
static const double TASK_DURATION_DEFAULT
std::string to_string(T a)
static const double rotation_angles_head_2[2][2]
static const double TASK_DURATION_TORSO
static const double rpy_l_x_far_y_far[3]
#define ROS_INFO(...)
AcceptanceTest_Hiro(std::string name="Hironx(Robot)0", std::string url="")
virtual void set_pose(std::string joint_group, std::vector< double > pose, std::vector< double > rpy, std::string msg_tasktitle="", double task_duration=7.0, bool do_wait=true, std::string ref_frame_name="")
void move_armbyarm_jointangles(AbstAcceptanceTest &test_client)
#define VEC_COPY(from, to, N1, N2)
t
static const double pos_r_x_near_y_far[3]
void set_pose_relative(AbstAcceptanceTest &test_client)
static const double rpy_l_x_near_y_far[3]
void move_head(AbstAcceptanceTest &test_client)
static const double pos_l_x_far_y_far[3]
static const double rpy_r_x_near_y_far[3]
static const double rotation_angles_head_1[2][2]
url
Definition: hironx.py:82
static const int SLEEP_OVERWRITE
static const double R_Z_SMALLINCREMENT
void run_tests(AbstAcceptanceTest &test_client, bool do_wait_input=false)
std::vector< double > DVEC
static const double positions_torso_deg[2][1]
virtual void set_joint_angles(std::string joint_group, std::vector< double > joint_angles, std::string msg_tasktitle="", double task_duration=7.0, bool do_wait=true)
void run_test_ros(bool do_wait_input=false)
static const int DURATION_TOTAL_SMALLINCREMENT
static const double positions_larm_deg_down[6]
static const double positions_rarm_deg_up_sync[6]
static const double TASK_DURATION_HEAD
AcceptanceTestRos acceptance_ros_client
static std::string GRNAME_RIGHT_ARM
void movearms_together(AbstAcceptanceTest &test_client)
virtual void go_initpos(double dtaskduration=7.0)
static const double positions_larm_deg_up_sync[6]
static std::string GRNAME_TORSO
void move_armbyarm_pose(AbstAcceptanceTest &test_client)
void show_workspace(AbstAcceptanceTest &test_client)
int main(int argc, char *argv[])
static const double positions_rarm_deg_down[6]
void overwrite_torso(AbstAcceptanceTest &test_client)


hironx_ros_bridge
Author(s): Kei Okada , Isaac I.Y. Saito
autogenerated on Thu May 14 2020 03:52:05