RobotModel_Service.cpp
Go to the documentation of this file.
1 
25 #include <ros/ros.h>
27 #include "asr_robot_model_services/CalculateCameraPose.h"
28 #include "asr_robot_model_services/CalculateCameraPoseCorrection.h"
29 #include "asr_robot_model_services/IsPositionAllowed.h"
30 #include "asr_robot_model_services/RobotStateMessage.h"
31 #include "asr_robot_model_services/GetPose.h"
32 #include "asr_robot_model_services/GetDistance.h"
33 #include <Eigen/Dense>
34 #include <tf/transform_datatypes.h>
35 #include <eigen_conversions/eigen_msg.h>
36 
37 using namespace robot_model_services;
38 //Since not all functionalities are implemented in the robot model with approximated IK,
39 //two pointers are used for the basic functionalies implemented all child classes and the advanced functionalities only implmented in the RobotModelWithExactIK class
42 
43 bool getDistance(asr_robot_model_services::GetDistance::Request &req, asr_robot_model_services::GetDistance::Response &res)
44 {
45  res.distance = basicFunctionRobotModelPtr->getDistance(req.sourcePosition, req.targetPosition);
46  return true;
47 }
48 
49 bool processCalculateCameraPoseServiceCall(asr_robot_model_services::CalculateCameraPose::Request &req, asr_robot_model_services::CalculateCameraPose::Response &res)
50 {
51  MILDRobotState * sourceRobotState = new MILDRobotState(req.sourceRobotState.pan, req.sourceRobotState.tilt,req.sourceRobotState.rotation,req.sourceRobotState.x,req.sourceRobotState.y);
52  RobotStatePtr sourceRobotStatePtr(sourceRobotState);
53  res.cameraFrame = basicFunctionRobotModelPtr->calculateCameraPose(sourceRobotStatePtr);
54  return true;
55 }
56 
57 bool processIsPositionAllowedServiceCall(asr_robot_model_services::IsPositionAllowed::Request &req, asr_robot_model_services::IsPositionAllowed::Response &res)
58 {
59  res.isAllowed = basicFunctionRobotModelPtr->isPositionAllowed(req.targetPosition);
60  return true;
61 }
62 
63 bool processGetRobotPoseServiceCall(asr_robot_model_services::GetPose::Request &req, asr_robot_model_services::GetPose::Response &res)
64 {
65  res.pose = basicFunctionRobotModelPtr->getRobotPose();
66  return true;
67 }
68 
69 bool processGetCameraPoseServiceCall(asr_robot_model_services::GetPose::Request &req, asr_robot_model_services::GetPose::Response &res)
70 {
71  res.pose = basicFunctionRobotModelPtr->getCameraPose();
72  return true;
73 }
74 
75 bool processCalculateCameraPoseCorrectionServiceCall(asr_robot_model_services::CalculateCameraPoseCorrection::Request &req, asr_robot_model_services::CalculateCameraPoseCorrection::Response &res)
76 {
77  MILDRobotState * sourceRobotState = new MILDRobotState(req.sourceRobotState.pan, req.sourceRobotState.tilt,req.sourceRobotState.rotation,req.sourceRobotState.x,req.sourceRobotState.y);
78  RobotStatePtr sourceRobotStatePtr(sourceRobotState);
79  SimpleVector3 position(req.position.x, req.position.y, req.position.z);
80  SimpleQuaternion orientation(req.orientation.w, req.orientation.x, req.orientation.y, req.orientation.z);
81  PTUConfig resultConfig = advancedFunctionRobotModelPtr->calculateCameraPoseCorrection(sourceRobotStatePtr, position, orientation);
82  res.pan = std::get<0>(resultConfig);
83  res.tilt = std::get<1>(resultConfig);
84  return true;
85 }
86 
87 int main(int argc, char *argv[])
88 {
89  ros::init(argc, argv, "getMovementCosts");
91 
92  double panMin, panMax, tiltMin, tiltMax;
93  int robotModelId;
94  n.param("panMin", panMin, -60.);
95  n.param("panMax", panMax, 60.);
96  n.param("tiltMin", tiltMin, -45.);
97  n.param("tiltMax", tiltMax, 45.);
98  n.param("robotModelId", robotModelId, 1);
99  ROS_INFO_STREAM("panMin: " << panMin);
100  ROS_INFO_STREAM("panMax: " << panMax);
101  ROS_INFO_STREAM("tiltMin: " << tiltMin);
102  ROS_INFO_STREAM("tiltMax: " << tiltMax);
103 
104  advancedFunctionRobotModelPtr = MILDRobotModelWithExactIKPtr(new MILDRobotModelWithExactIK());
105  advancedFunctionRobotModelPtr->setTiltAngleLimits(tiltMin, tiltMax);
106  advancedFunctionRobotModelPtr->setPanAngleLimits(panMin, panMax);
107  switch (robotModelId) {
108  case 1:
109  ROS_INFO_STREAM("NBV Service: Using new IK model");
110  //Use the same robot model with exact IK for basic and advanced functionalities
111  basicFunctionRobotModelPtr = advancedFunctionRobotModelPtr;
112  break;
113  case 2:
114  ROS_INFO_STREAM("NBV Service:: Using old IK model");
115  //Use robot model with exact IK for advanced functionalities only, create a new robot model with approximated IK for basic functionality
116  basicFunctionRobotModelPtr = MILDRobotModelWithApproximatedIKPtr(new MILDRobotModelWithApproximatedIK());
117  basicFunctionRobotModelPtr->setTiltAngleLimits(tiltMin, tiltMax);
118  basicFunctionRobotModelPtr->setPanAngleLimits(panMin, panMax);
119  break;
120  default:
121  std::stringstream ss;
122  ss << robotModelId << " is not a valid robot model ID";
123  ROS_ERROR_STREAM(ss.str());
124  throw std::runtime_error(ss.str());
125  }
126  ros::ServiceServer service_GetDistance = n.advertiseService("GetDistance", getDistance);
127  ros::ServiceServer service_CalculateCameraPose = n.advertiseService("CalculateCameraPose", processCalculateCameraPoseServiceCall);
128  ros::ServiceServer service_IsPositionAllowed = n.advertiseService("IsPositionAllowed", processIsPositionAllowedServiceCall);
129  ros::ServiceServer service_GetRobotPose = n.advertiseService("GetRobotPose", processGetRobotPoseServiceCall);
130  ros::ServiceServer service_GetCameraPose = n.advertiseService("GetCameraPose", processGetCameraPoseServiceCall);
131  ros::ServiceServer service_CalculateCameraPoseCorrection = n.advertiseService("CalculateCameraPoseCorrection", processCalculateCameraPoseCorrectionServiceCall);
132 
133  ROS_INFO("RobotModel Service started.");
134  ros::spin();
135 
136  return 0;
137 }
bool processGetCameraPoseServiceCall(asr_robot_model_services::GetPose::Request &req, asr_robot_model_services::GetPose::Response &res)
MILDRobotModelWithExactIKPtr advancedFunctionRobotModelPtr
std::tuple< double, double > PTUConfig
MILDRobotModelWithExactIK implements a model of pan tilt unit robot where the inverse kinematic is ca...
boost::shared_ptr< MILDRobotModelWithApproximatedIK > MILDRobotModelWithApproximatedIKPtr
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool processIsPositionAllowedServiceCall(asr_robot_model_services::IsPositionAllowed::Request &req, asr_robot_model_services::IsPositionAllowed::Response &res)
ROSCPP_DECL const std::string & getName()
Eigen::Matrix< Precision, 3, 1 > SimpleVector3
Definition: typedef.hpp:50
MILDRobotModelWithApproximatedIK implements a model of pan tilt unit robot where the inverse kinemati...
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
bool getDistance(asr_robot_model_services::GetDistance::Request &req, asr_robot_model_services::GetDistance::Response &res)
int main(int argc, char *argv[])
ROSCPP_DECL void spin(Spinner &spinner)
bool processCalculateCameraPoseServiceCall(asr_robot_model_services::CalculateCameraPose::Request &req, asr_robot_model_services::CalculateCameraPose::Response &res)
bool processCalculateCameraPoseCorrectionServiceCall(asr_robot_model_services::CalculateCameraPoseCorrection::Request &req, asr_robot_model_services::CalculateCameraPoseCorrection::Response &res)
#define ROS_INFO(...)
bool param(const std::string &param_name, T &param_val, const T &default_val) const
this namespace contains all generally usable classes.
Definition: DebugHelper.hpp:27
bool processGetRobotPoseServiceCall(asr_robot_model_services::GetPose::Request &req, asr_robot_model_services::GetPose::Response &res)
#define ROS_INFO_STREAM(args)
boost::shared_ptr< MILDRobotModelWithExactIK > MILDRobotModelWithExactIKPtr
#define ROS_ERROR_STREAM(args)
MILDRobotModelPtr basicFunctionRobotModelPtr
Eigen::Quaternion< Precision > SimpleQuaternion
Definition: typedef.hpp:64


asr_robot_model_services
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 Mon Jun 10 2019 12:49:59