17 string toString(cpr::Response resp)
20 s <<
"status code: " << resp.status_code << endl
21 <<
"url: " << resp.url << endl
22 <<
"text: " << resp.text << endl
23 <<
"error: " << resp.error.message;
27 void handleCPRResponse(cpr::Response r)
29 if (r.status_code != 200)
31 throw runtime_error(toString(r));
39 : nh_(nh), host_(host),
40 servicesUrl_(
"http://" + host +
"/api/v1/nodes/rc_hand_eye_calibration/services/"),
41 paramsUrl_(
"http://" + host +
"/api/v1/nodes/rc_hand_eye_calibration/parameters")
50 std_srvs::TriggerResponse &response)
52 cpr::Url url = cpr::Url{
servicesUrl_ +
"save_calibration"};
53 auto rest_resp = cpr::Put(url, cpr::Timeout{
timeoutCurl_ });
54 handleCPRResponse(rest_resp);
56 auto json_resp = json::parse(rest_resp.text)[
"response"];
57 response.success = (bool) json_resp[
"success"];
58 response.message = json_resp[
"message"];
66 std_srvs::TriggerResponse &response)
68 cpr::Url url = cpr::Url{
servicesUrl_ +
"reset_calibration"};
69 auto rest_resp = cpr::Put(url, cpr::Timeout{
timeoutCurl_ });
70 handleCPRResponse(rest_resp);
72 auto json_resp = json::parse(rest_resp.text)[
"response"];
73 response.success = (bool) json_resp[
"success"];
74 response.message = json_resp[
"message"];
80 std_srvs::TriggerResponse &response)
82 cpr::Url url = cpr::Url{
servicesUrl_ +
"remove_calibration"};
83 auto rest_resp = cpr::Put(url, cpr::Timeout{
timeoutCurl_ });
84 handleCPRResponse(rest_resp);
86 auto json_resp = json::parse(rest_resp.text)[
"response"];
87 response.success = (bool) json_resp[
"success"];
88 response.message = json_resp[
"message"];
94 rc_hand_eye_calibration_client::SetCalibrationPoseResponse &response)
97 json js_pos, js_ori, js_pose;
98 js_pos[
"x"] = request.pose.position.x;
99 js_pos[
"y"] = request.pose.position.y;
100 js_pos[
"z"] = request.pose.position.z;
101 js_ori[
"x"] = request.pose.orientation.x;
102 js_ori[
"y"] = request.pose.orientation.y;
103 js_ori[
"z"] = request.pose.orientation.z;
104 js_ori[
"w"] = request.pose.orientation.w;
105 js_pose[
"position"] = js_pos;
106 js_pose[
"orientation"] = js_ori;
110 js_args[
"args"][
"pose"] = js_pose;
111 js_args[
"args"][
"slot"] = request.slot;
115 auto rest_resp = cpr::Put(url, cpr::Timeout{
timeoutCurl_ }, cpr::Body{ js_args.dump() },
116 cpr::Header{ {
"Content-Type",
"application/json" } });
117 handleCPRResponse(rest_resp);
120 auto json_resp = json::parse(rest_resp.text)[
"response"];
121 response.success = (bool) json_resp[
"success"];
122 response.status = json_resp[
"status"];
123 response.message = json_resp[
"message"];
129 rc_hand_eye_calibration_client::CalibrationResponse &response)
133 auto rest_resp = cpr::Put(url, cpr::Timeout{
timeoutCurl_ });
134 handleCPRResponse(rest_resp);
137 auto json_resp = json::parse(rest_resp.text)[
"response"];
138 response.success = (bool) json_resp[
"success"];
139 response.status = json_resp[
"status"];
140 response.message = json_resp[
"message"];
141 response.error = json_resp[
"error"];
142 response.robot_mounted = (bool) json_resp[
"robot_mounted"];
144 json js_pose = json_resp[
"pose"];
145 response.pose.position.x = js_pose[
"position"][
"x"];
146 response.pose.position.y = js_pose[
"position"][
"y"];
147 response.pose.position.z = js_pose[
"position"][
"z"];
148 response.pose.orientation.x = js_pose[
"orientation"][
"x"];
149 response.pose.orientation.y = js_pose[
"orientation"][
"y"];
150 response.pose.orientation.z = js_pose[
"orientation"][
"z"];
151 response.pose.orientation.w = js_pose[
"orientation"][
"w"];
158 rc_hand_eye_calibration_client::CalibrationResponse &response)
161 cpr::Url url = cpr::Url{
servicesUrl_ +
"get_calibration" };
162 auto rest_resp = cpr::Put(url, cpr::Timeout{
timeoutCurl_ });
163 handleCPRResponse(rest_resp);
166 auto json_resp = json::parse(rest_resp.text)[
"response"];
167 response.success = (bool) json_resp[
"success"];
168 response.status = json_resp[
"status"];
169 response.message = json_resp[
"message"];
170 response.error = json_resp[
"error"];
171 response.robot_mounted = (bool) json_resp[
"robot_mounted"];
173 json js_pose = json_resp[
"pose"];
174 response.pose.position.x = js_pose[
"position"][
"x"];
175 response.pose.position.y = js_pose[
"position"][
"y"];
176 response.pose.position.z = js_pose[
"position"][
"z"];
177 response.pose.orientation.x = js_pose[
"orientation"][
"x"];
178 response.pose.orientation.y = js_pose[
"orientation"][
"y"];
179 response.pose.orientation.z = js_pose[
"orientation"][
"z"];
180 response.pose.orientation.w = js_pose[
"orientation"][
"w"];
205 rc_hand_eye_calibration_client::hand_eye_calibrationConfig cfg;
209 handleCPRResponse(rest_resp);
210 auto json_resp = json::parse(rest_resp.text);
211 for (
auto&
param : json_resp) {
212 string name =
param[
"name"];
213 if (
param[
"name"] ==
"grid_width")
215 cfg.grid_width =
param[
"value"];
216 }
else if (
param[
"name"] ==
"grid_height")
218 cfg.grid_height =
param[
"value"];
219 }
else if (
param[
"name"] ==
"robot_mounted")
221 cfg.robot_mounted = (bool)
param[
"value"];
227 nh_.
param(
"grid_width", cfg.grid_width, cfg.grid_width);
228 nh_.
param(
"grid_height", cfg.grid_height, cfg.grid_height);
229 nh_.
param(
"robot_mounted", cfg.robot_mounted, cfg.robot_mounted);
237 using RCFSRV = dynamic_reconfigure::Server<rc_hand_eye_calibration_client::hand_eye_calibrationConfig>;
238 server_ = unique_ptr<RCFSRV>(
new dynamic_reconfigure::Server<rc_hand_eye_calibration_client::hand_eye_calibrationConfig>(
nh_));
247 ROS_DEBUG(
"Reconfigure Request: (%f x %f) %s",
248 config.grid_width, config.grid_height,
249 config.robot_mounted ?
"True" :
"False");
252 json js_params, js_param;
253 js_param[
"name"] =
"grid_width";
254 js_param[
"value"] = config.grid_width;
255 js_params.push_back(js_param);
256 js_param[
"name"] =
"grid_height";
257 js_param[
"value"] = config.grid_height;
258 js_params.push_back(js_param);
259 js_param[
"name"] =
"robot_mounted";
260 js_param[
"value"] = config.robot_mounted;
261 js_params.push_back(js_param);
265 cpr::Body{ js_params.dump() },
266 cpr::Header{ {
"Content-Type",
"application/json" } });
268 handleCPRResponse(rest_resp);
bool saveSrv(std_srvs::TriggerRequest &request, std_srvs::TriggerResponse &response)
store hand eye calibration on sensor
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val)
ros::ServiceServer srv_save_
bool removeSrv(std_srvs::TriggerRequest &request, std_srvs::TriggerResponse &response)
Remove calibration so sensor reports as uncalibrated.
std::unique_ptr< dynamic_reconfigure::Server< rc_hand_eye_calibration_client::hand_eye_calibrationConfig > > server_
void dynamicReconfigureCb(rc_hand_eye_calibration_client::hand_eye_calibrationConfig &config, uint32_t)
bool setSlotSrv(rc_hand_eye_calibration_client::SetCalibrationPoseRequest &request, rc_hand_eye_calibration_client::SetCalibrationPoseResponse &response)
Save given pose and the pose of the grid indexed by the given request.slot.
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
bool getCalibResultSrv(rc_hand_eye_calibration_client::CalibrationRequest &request, rc_hand_eye_calibration_client::CalibrationResponse &response)
Service call to get the result. Also returned directly via calibrate.
bool resetSrv(std_srvs::TriggerRequest &request, std_srvs::TriggerResponse &response)
Delete all stored data, e.g., to start over.
void advertiseServices()
Advertises the services in the namespace of nh_.
bool calibSrv(rc_hand_eye_calibration_client::CalibrationRequest &request, rc_hand_eye_calibration_client::CalibrationResponse &response)
Perform the calibration and return its result.
ros::ServiceServer srv_reset_
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
CalibrationWrapper(std::string host, ros::NodeHandle nh)
ros::ServiceServer srv_get_result_
ros::ServiceServer srv_set_slot_
ros::ServiceServer srv_remove_
void setParam(const std::string &key, const XmlRpc::XmlRpcValue &v) const
ros::ServiceServer srv_calibrate_