38 #include <arpa/inet.h> 46 : nh_(nh), rest_helper_(host,
"rc_hand_eye_calibration", 2000)
54 template <
typename Request,
typename Response>
64 catch (
const std::exception& ex)
88 ROS_INFO(
"Requesting (and broadcasting) calibration from rc_visard once");
120 ROS_INFO(
"Calibration has been removed, stopped /tf broadcasting.");
124 ROS_WARN(
"Failed to remove calibration: %s", res.message.c_str());
138 if (response.success)
140 ROS_INFO(
"Calibration request successful. Broadcasting new calibration.");
176 res.message =
"set_calibration is not supported in this firmware version";
185 CalibrationRequest req;
186 CalibrationResponse res;
240 for (
const auto&
param : params)
242 const auto& name =
param[
"name"];
243 if (name ==
"grid_width")
244 cfg.grid_width =
param[
"value"];
245 else if (name ==
"grid_height")
246 cfg.grid_height =
param[
"value"];
247 else if (name ==
"robot_mounted")
248 cfg.robot_mounted = (bool)
param[
"value"];
249 else if (name ==
"tcp_rotation_axis")
250 cfg.tcp_rotation_axis = (int)
param[
"value"];
251 else if (name ==
"tcp_offset")
252 cfg.tcp_offset =
param[
"value"];
258 hand_eye_calibrationConfig cfg;
267 nh_.
param(
"grid_width", cfg.grid_width, cfg.grid_width);
268 nh_.
param(
"grid_height", cfg.grid_height, cfg.grid_height);
269 nh_.
param(
"robot_mounted", cfg.robot_mounted, cfg.robot_mounted);
270 nh_.
param(
"tcp_rotation_axis", cfg.tcp_rotation_axis, cfg.tcp_rotation_axis);
271 nh_.
param(
"tcp_offset", cfg.tcp_offset, cfg.tcp_offset);
284 nh_.
setParam(
"tcp_rotation_axis", cfg.tcp_rotation_axis);
288 using RCFSRV = dynamic_reconfigure::Server<hand_eye_calibrationConfig>;
289 server_ = std::unique_ptr<RCFSRV>(
new RCFSRV(
nh_));
295 ROS_DEBUG(
"Reconfigure Request: (%f x %f) %s, 4DOF: %d, offset: %f", config.grid_width, config.grid_height,
296 config.robot_mounted ?
"True" :
"False", config.tcp_rotation_axis, config.tcp_offset);
299 json j_params, j_param;
300 j_param[
"name"] =
"grid_width";
301 j_param[
"value"] = config.grid_width;
302 j_params.push_back(j_param);
303 j_param[
"name"] =
"grid_height";
304 j_param[
"value"] = config.grid_height;
305 j_params.push_back(j_param);
306 j_param[
"name"] =
"robot_mounted";
307 j_param[
"value"] = config.robot_mounted;
308 j_params.push_back(j_param);
309 j_param[
"name"] =
"tcp_rotation_axis";
310 j_param[
"value"] = config.tcp_rotation_axis;
311 j_params.push_back(j_param);
312 j_param[
"name"] =
"tcp_offset";
313 j_param[
"value"] = config.tcp_offset;
314 j_params.push_back(j_param);
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val)
bool calibSrv(rc_hand_eye_calibration_client::CalibrationRequest &req, rc_hand_eye_calibration_client::CalibrationResponse &res)
Perform the calibration and return its result.
ros::SteadyTimer calib_request_timer_
ros::ServiceServer srv_get_result_
ros::ServiceServer srv_set_slot_
ros::SteadyTimer calib_publish_timer_
ros::ServiceServer srv_calibrate_
bool removeSrv(rc_hand_eye_calibration_client::TriggerRequest &req, rc_hand_eye_calibration_client::TriggerResponse &res)
Remove calibration so sensor reports as uncalibrated.
bool getCalibResultSrv(rc_hand_eye_calibration_client::CalibrationRequest &req, rc_hand_eye_calibration_client::CalibrationResponse &res)
Service call to get the result. Also returned directly via calibrate.
ros::ServiceServer srv_remove_
void advertiseServices()
Advertises the services in the namespace of nh_.
bool setCalibSrv(rc_hand_eye_calibration_client::SetCalibrationRequest &req, rc_hand_eye_calibration_client::SetCalibrationResponse &res)
Service call to set the calibration.
void sendCachedCalibration(const ros::SteadyTimerEvent &=ros::SteadyTimerEvent())
void updateCalibrationCache(const rc_hand_eye_calibration_client::CalibrationResponse &res)
Copy resp into current_calibration_.
ros::ServiceServer srv_save_
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
std::string camera_frame_id_
Default Frame Ids to be used for the tf broadcast.
void calibResponseHandler(CalibrationResponse &res)
update and broadcast the internally cached calibration result.
std::unique_ptr< dynamic_reconfigure::Server< rc_hand_eye_calibration_client::hand_eye_calibrationConfig > > server_
std::tuple< size_t, size_t, size_t > getImageVersion()
std::string base_frame_id_
SteadyTimer createSteadyTimer(WallDuration period, void(T::*callback)(const SteadyTimerEvent &), T *obj, bool oneshot=false, bool autostart=true) const
tf2_ros::TransformBroadcaster dynamic_tf2_broadcaster_
To be used for periodic sending.
ros::ServiceServer srv_set_calibration_
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
ros::ServiceServer srv_reset_
tf2_ros::StaticTransformBroadcaster static_tf2_broadcaster_
To be used for on-change sending only.
std::string endeff_frame_id_
Which one is used depends on the value of "robot_mounted" in the calibration response.
#define ROS_WARN_STREAM(args)
std::tuple< size_t, size_t, size_t > image_version_
void initTimers()
Initialize timers to periodically publish and/or request the calibration Depends on parameters: calib...
void requestCalibration(const ros::SteadyTimerEvent &)
Wraps the above getCalibResultSrv.
rc_rest_api::RestHelper rest_helper_
bool callService(const std::string &name, const Request &req, Response &res)
geometry_msgs::TransformStamped current_calibration_
json setParameters(const json &js_params)
double calib_publish_period_
Whether to send the transformation periodically instead of as a static transformation Zero or negativ...
bool setSlotSrv(rc_hand_eye_calibration_client::SetCalibrationPoseRequest &req, rc_hand_eye_calibration_client::SetCalibrationPoseResponse &res)
Save given pose and the pose of the grid indexed by the given request.slot.
void paramsToCfg(const json ¶ms, hand_eye_calibrationConfig &cfg)
HandEyeCalibClient(std::string host, ros::NodeHandle nh)
void setParam(const std::string &key, const XmlRpc::XmlRpcValue &v) const
bool saveSrv(rc_hand_eye_calibration_client::TriggerRequest &req, rc_hand_eye_calibration_client::TriggerResponse &res)
store hand eye calibration on sensor
double calib_request_period_
If non-negative: Periodically update the calibration by requesting it.
void dynamicReconfigureCb(rc_hand_eye_calibration_client::hand_eye_calibrationConfig &config, uint32_t)
bool resetSrv(rc_hand_eye_calibration_client::TriggerRequest &req, rc_hand_eye_calibration_client::TriggerResponse &res)
Delete all stored data, e.g., to start over.
json servicePutRequest(const std::string &service_name)