BaseTest.cpp
Go to the documentation of this file.
1 
21 
22 using namespace asr_next_best_view;
23 using namespace dynamic_reconfigure;
24 
26  init(true, false);
27  }
28 
29  BaseTest::BaseTest(bool useRos, bool silent) {
30  init(useRos, silent);
31  }
32 
34 
35  void BaseTest::init(bool useRos, bool silent) {
36  this->mNodeHandle = boost::shared_ptr<ros::NodeHandle>(new ros::NodeHandle("~"));
37 
38  // publishers
39  mInitPosePub = mNodeHandle->advertise<geometry_msgs::PoseWithCovarianceStamped>("/initialpose", 100, false);
40 
41  this->silent = silent;
42  if (useRos) {
43  initRosServices();
44  }
45  }
46 
48  // services
49  ros::service::waitForService("/nbv/set_init_robot_state", -1);
50  mSetInitRobotStateClient = mNodeHandle->serviceClient<asr_next_best_view::SetInitRobotState>("/nbv/set_init_robot_state");
51  ros::service::waitForService("/nbv/set_point_cloud", -1);
52  mSetPointCloudClient = mNodeHandle->serviceClient<asr_next_best_view::SetAttributedPointCloud>("/nbv/set_point_cloud");
53  ros::service::waitForService("/nbv/get_point_cloud", -1);
54  mGetPointCloudClient = mNodeHandle->serviceClient<asr_next_best_view::GetAttributedPointCloud>("/nbv/get_point_cloud");
55  ros::service::waitForService("/nbv/next_best_view", -1);
56  mGetNextBestViewClient = mNodeHandle->serviceClient<asr_next_best_view::GetNextBestView>("/nbv/next_best_view");
57  ros::service::waitForService("/nbv/update_point_cloud", -1);
58  mUpdatePointCloudClient = mNodeHandle->serviceClient<asr_next_best_view::UpdatePointCloud>("/nbv/update_point_cloud");
59  ros::service::waitForService("/nbv/reset_nbv_calculator", -1);
60  mResetCalculatorClient = mNodeHandle->serviceClient<asr_next_best_view::ResetCalculator>("/nbv/reset_nbv_calculator");
61  //ros::service::waitForService("/nbv/set_parameters", -1);
62  //mDynParametersClient = mNodeHandle->serviceClient<dynamic_reconfigure::Reconfigure>("/nbv/set_parameters");
63  ros::service::waitForService("/nbv/trigger_frustum_visualization", -1);
64  mTriggerFrustumVisClient = mNodeHandle->serviceClient<asr_next_best_view::TriggerFrustumVisualization>("/nbv/trigger_frustum_visualization");
65  }
66 
67  void BaseTest::setInitialPose(const geometry_msgs::Pose &initialPose, boost::shared_ptr<NextBestView> nbv) {
68  // waiting for buffers to fill
69  ros::Duration(5.0).sleep();
70 
71  geometry_msgs::PoseWithCovarianceStamped pose;
72  pose.header.frame_id = "map";
73  boost::array<double, 36> a = {
74  // x, y, z, roll, pitch, yaw
75  0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
76  0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
77  0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
78  0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
79  0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
80  0.0, 0.0, 0.0, 0.0, 0.0, 0.0
81  };
82  pose.pose.covariance = a;
83  pose.pose.pose = initialPose;
84 
85  mInitPosePub.publish(pose);
86 
87  this->setInitialRobotState(initialPose, nbv);
88  }
89 
90  void BaseTest::setInitialRobotState(const geometry_msgs::Pose &initialPose, boost::shared_ptr<NextBestView> nbv) {
91  robot_model_services::MILDRobotStatePtr statePtr = this->getRobotState(initialPose);
92 
93  asr_next_best_view::SetInitRobotState sirb;
94  sirb.request.robotState.pan = statePtr->pan;
95  sirb.request.robotState.tilt = statePtr->tilt;
96  sirb.request.robotState.rotation = statePtr->rotation;
97  sirb.request.robotState.x = statePtr->x;
98  sirb.request.robotState.y = statePtr->y;
99 
100  if (nbv) {
101  if (!nbv->processSetInitRobotStateServiceCall(sirb.request, sirb.response)) {
102  ROS_ERROR("Failed to process service SetInitRobotState.");
103  }
104  }
105  else
106  {
107  if (!mSetInitRobotStateClient.call(sirb)) {
108  ROS_ERROR("Failed to call service SetInitRobotState.");
109  }
110  }
111  }
112 
113  robot_model_services::MILDRobotStatePtr BaseTest::getRobotState(const geometry_msgs::Pose &initialPose) {
114  tf::Quaternion q(initialPose.orientation.x, initialPose.orientation.y, initialPose.orientation.z, initialPose.orientation.w);
115  tf::Matrix3x3 m(q);
116  double yaw, pitch, roll;
117  m.getRPY(roll, pitch, yaw);
118 
119  robot_model_services::MILDRobotStatePtr statePtr(new robot_model_services::MILDRobotState(0, 0, yaw, initialPose.position.x, initialPose.position.y));
120 
121  return statePtr;
122  }
123 
125  if (silent) {
126  return;
127  }
128  std::string dummy;
129  std::cout << "Press ENTER to continue.." << std::endl << ">";
130  std::getline(std::cin, dummy);
131  std::cout << std::endl;
132  }
133 
135  const Precision pitch,
136  const Precision yaw)
137  {
138 
139  Eigen::AngleAxis<Precision> rollAngle(M_PI*roll/180.0,SimpleVector3::UnitX());
140  Eigen::AngleAxis<Precision> pitchAngle(M_PI*pitch/180.0,SimpleVector3::UnitY());
141  Eigen::AngleAxis<Precision> yawAngle(M_PI*yaw/180.0,SimpleVector3::UnitZ());
142 
143  SimpleQuaternion q = rollAngle*pitchAngle*yawAngle;
144  return q;
145  }
146 
148  const Precision pitch,
149  const Precision yaw)
150  {
151 
152  Eigen::AngleAxis<Precision> Z1_Angle(M_PI*roll/180.0,SimpleVector3::UnitZ());
153  Eigen::AngleAxis<Precision> X_Angle(M_PI*pitch/180.0,SimpleVector3::UnitX());
154  Eigen::AngleAxis<Precision> Z2_Angle(M_PI*yaw/180.0,SimpleVector3::UnitZ());
155 
156  SimpleQuaternion q = Z1_Angle*X_Angle*Z2_Angle;
157  return q;
158  }
159 
SimpleQuaternion euler2Quaternion(const Precision roll, const Precision pitch, const Precision yaw)
Definition: BaseTest.cpp:134
bool sleep() const
void setInitialPose(const geometry_msgs::Pose &initialPose, boost::shared_ptr< NextBestView > nbv=nullptr)
Definition: BaseTest.cpp:67
robot_model_services::MILDRobotStatePtr getRobotState(const geometry_msgs::Pose &initialPose)
Definition: BaseTest.cpp:113
void initRosServices()
Definition: BaseTest.cpp:47
~BaseTest()
Definition: BaseTest.cpp:33
BaseTest()
Definition: BaseTest.cpp:25
void getRPY(tfScalar &roll, tfScalar &pitch, tfScalar &yaw, unsigned int solution_number=1) const
void setInitialRobotState(const geometry_msgs::Pose &initialPose, boost::shared_ptr< NextBestView > nbv=nullptr)
Definition: BaseTest.cpp:90
SimpleQuaternion ZXZ2Quaternion(const Precision roll, const Precision pitch, const Precision yaw)
Definition: BaseTest.cpp:147
void init(bool useRos, bool silent)
Definition: BaseTest.cpp:35
Eigen::Quaternion< Precision > SimpleQuaternion
Definition: typedef.hpp:67
void waitForEnter()
Definition: BaseTest.cpp:124
#define ROS_ERROR(...)
float Precision
Definition: typedef.hpp:36
ROSCPP_DECL bool waitForService(const std::string &service_name, int32_t timeout)


asr_next_best_view
Author(s): Aumann Florian, Borella Jocelyn, Heller Florian, Meißner Pascal, Schleicher Ralf, Stöckle Patrick, Stroh Daniel, Trautmann Jeremias, Walter Milena, Wittenbeck Valerij
autogenerated on Thu Jan 9 2020 07:20:18