test_robot_utils.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2019
3  *
4  * LAAS-CNRS
5  *
6  * François Bailly
7  */
8 
9 /* -------------------------------------------------------------------------- */
10 /* --- INCLUDES ------------------------------------------------------------- */
11 /* -------------------------------------------------------------------------- */
12 #include <dynamic-graph/factory.h>
13 
14 #include <iostream>
15 #include <sot/core/debug.hh>
16 #include <sot/core/robot-utils.hh>
17 
18 using namespace std;
19 using namespace dynamicgraph;
20 using namespace dynamicgraph::sot;
21 
22 std::string localName("robot_test");
24 int main(void) {
26  /*Test set and get joint_limits_for_id */
27  const double upper_lim(1);
28  const double lower_lim(2);
29  robot_util->set_joint_limits_for_id(1, lower_lim, upper_lim);
30  if (robot_util->get_joint_limits_from_id(1).upper == upper_lim &&
31  robot_util->get_joint_limits_from_id(1).lower == lower_lim) {
32  std::cout << "joint_limits_for_id works !" << std::endl;
33  } else {
34  std::cout << "ERROR: joint_limits_for_id does not work !" << std::endl;
35  }
36  if (robot_util->cp_get_joint_limits_from_id(1).upper == upper_lim &&
37  robot_util->cp_get_joint_limits_from_id(1).lower == lower_lim) {
38  std::cout << "cp_get_joint_limits_for_id works !" << std::endl;
39  } else {
40  std::cout << "ERROR: cp_get_joint_limits_for_id does not work !"
41  << std::endl;
42  }
43 
44  /*Test set and get name_to_id */
45  const std::string joint_name("test_joint");
46  const Index joint_id(10);
47  robot_util->set_name_to_id(joint_name, joint_id);
48  if (robot_util->get_id_from_name(joint_name) == joint_id &&
49  robot_util->get_name_from_id(joint_id) == joint_name) {
50  std::cout << "name_to_id works !" << std::endl;
51  } else {
52  std::cout << "ERROR: name_to_id does not work !" << std::endl;
53  }
54 
55  /*Test create_id_to_name_map */
56  robot_util->create_id_to_name_map();
57 
58  /*Test set urdf_to_sot */
59 
60  dynamicgraph::Vector urdf_to_sot(3);
61  urdf_to_sot << 0, 2, 1;
62  robot_util->set_urdf_to_sot(urdf_to_sot);
63  if (urdf_to_sot == robot_util->m_dgv_urdf_to_sot) {
64  std::cout << "urdf_to_sot works !" << std::endl;
65  } else {
66  std::cout << "ERROR: urdf_to_sot does not work !" << std::endl;
67  }
68  /*Test joints_urdf_to_sot and joints_sot_to_urdf */
69  dynamicgraph::Vector q_urdf(3);
70  q_urdf << 10, 20, 30;
71  dynamicgraph::Vector q_sot(3);
72  dynamicgraph::Vector q_test_urdf(3);
73  robot_util->joints_urdf_to_sot(q_urdf, q_sot);
74  robot_util->joints_sot_to_urdf(q_sot, q_test_urdf);
75  if (q_urdf == q_test_urdf) {
76  std::cout << "joints_urdf_to_sot and joints_sot_to_urdf work !"
77  << std::endl;
78  } else {
79  std::cout << "ERROR: joints_urdf_to_sot or joints_sot_to_urdf "
80  "do not work !"
81  << std::endl;
82  }
83 
84  /*Test velocity_sot_to_urdf and velocity_urdf_to_sot */
85  dynamicgraph::Vector q2_urdf(10);
86  dynamicgraph::Vector v_urdf(9);
87  dynamicgraph::Vector v_sot(9);
88  robot_util->velocity_urdf_to_sot(q2_urdf, v_urdf, v_sot);
89  robot_util->velocity_sot_to_urdf(q2_urdf, v_sot, v_urdf);
90  std::cout << "velocity_sot_to_urdf and velocity_urdf_to_sot work !"
91  << std::endl;
92 
93  /*Test base_urdf_to_sot and base_sot_to_urdf */
94  dynamicgraph::Vector base_q_urdf(7);
95  dynamicgraph::Vector base_q_sot(6);
96  robot_util->base_urdf_to_sot(base_q_urdf, base_q_sot);
97  robot_util->base_sot_to_urdf(base_q_sot, base_q_urdf);
98  std::cout << "base_urdf_to_sot and base_sot_to_urdf work !" << std::endl;
99 
100  /*Test config_urdf_to_sot and config_sot_to_urdf */
101  dynamicgraph::Vector q2_sot(9);
102  robot_util->config_urdf_to_sot(q2_urdf, q2_sot);
103  robot_util->config_sot_to_urdf(q2_sot, q2_urdf);
104  std::cout << "config_urdf_to_sot and config_sot_to_urdf work !" << std::endl;
105 
106  robot_util->display(std::cout);
107  robot_util->sendMsg("test", MSG_TYPE_ERROR_STREAM);
108 
109  /*Test set_name_to_force_id of forceutil */
110  const std::string rf("rf");
111  const std::string lf("lf");
112  const std::string lh("lh");
113  const std::string rh("rh");
114 
115  robot_util->m_force_util.set_name_to_force_id(rf, 0);
116  robot_util->m_force_util.set_name_to_force_id(lf, 1);
117  robot_util->m_force_util.set_name_to_force_id(lh, 2);
118  robot_util->m_force_util.set_name_to_force_id(rh, 3);
119 
120  dynamicgraph::Vector lf_lim(6);
121  lf_lim << 1, 2, 3, 4, 5, 6;
122  dynamicgraph::Vector uf_lim(6);
123  uf_lim << 10, 20, 30, 40, 50, 60;
124  robot_util->m_force_util.set_force_id_to_limits(1, lf_lim, uf_lim);
125  if (robot_util->m_force_util.get_id_from_name(rf) == 0 &&
126  robot_util->m_force_util.get_id_from_name(lf) == 1 &&
127  robot_util->m_force_util.get_id_from_name(lh) == 2 &&
128  robot_util->m_force_util.get_id_from_name(rh) == 3) {
129  std::cout << "force_util set and get id_from_name work !" << std::endl;
130  } else {
131  std::cout << "ERROR: force_util set and get id_from_name do not work !"
132  << std::endl;
133  }
134  if (robot_util->m_force_util.get_name_from_id(0) == rf &&
135  robot_util->m_force_util.get_name_from_id(1) == lf &&
136  robot_util->m_force_util.get_name_from_id(2) == lh &&
137  robot_util->m_force_util.get_name_from_id(3) == rh) {
138  std::cout << "force_util get name_from_id works !" << std::endl;
139  } else {
140  std::cout << "ERROR: force_util get name_from_id does not work !"
141  << std::endl;
142  }
143  if (robot_util->m_force_util.get_limits_from_id(1).upper == uf_lim &&
144  robot_util->m_force_util.get_limits_from_id(1).lower == lf_lim) {
145  std::cout << "force_util set and get id to limits work !" << std::endl;
146  } else {
147  std::cout << "ERROR: force_util set and get id to "
148  "limits works do not work !"
149  << std::endl;
150  }
151  robot_util->m_force_util.display(std::cout);
152  robot_util->m_foot_util.display(std::cout);
153  return 0;
154 }
dynamicgraph::sot::createRobotUtil
RobotUtilShrPtr createRobotUtil(std::string &robotName)
Definition: robot-utils.cpp:536
dynamicgraph
main
int main(void)
Definition: test_robot_utils.cpp:24
robot-utils.hh
debug.hh
dynamicgraph::sot::RobotUtilShrPtr
std::shared_ptr< RobotUtil > RobotUtilShrPtr
Accessors - This should be changed to RobotUtilPtrShared.
Definition: robot-utils.hh:300
localName
std::string localName("robot_test")
Index
std::size_t Index
dynamicgraph::Vector
Eigen::VectorXd Vector
MSG_TYPE_ERROR_STREAM
MSG_TYPE_ERROR_STREAM
joint_name
string joint_name
dynamicgraph::sot
robot_util
RobotUtilShrPtr robot_util
Definition: test_robot_utils.cpp:23
joint_id
joint_id


sot-core
Author(s): Olivier Stasse, ostasse@laas.fr
autogenerated on Tue Oct 24 2023 02:26:32