3 #include <iCub/ctrl/minJerkCtrl.h> 4 #include <opencv2/core/core.hpp> 5 #include <opencv2/imgproc/imgproc.hpp> 6 #include <yarp/math/Math.h> 7 #include <yarp/math/SVD.h> 8 #include <yarp/os/Network.h> 9 #include <yarp/os/Property.h> 10 #include <yarp/os/RpcClient.h> 11 #include <yarp/os/Time.h> 23 yInfo() <<
"*** Invoked VisualServoingClient ctor ***";
24 yInfo() <<
"*** VisualServoingClient constructed ***";
30 yInfo() <<
"*** Invoked VisualServoingClient dtor ***";
31 yInfo() <<
"*** VisualServoingClient destructed ***";
38 verbosity_ = config.check(
"verbosity", Value(
false)).asBool();
39 yInfo() <<
"|> Verbosity: " + ConstString(verbosity_?
"ON" :
"OFF");
42 yInfoVerbose(
"*** Configuring VisualServoingClient ***");
44 local_ = config.check(
"local", Value(
"")).asString();
45 yInfoVerbose(
"|> Local port prefix: " + local_);
48 yErrorVerbose(
"Invalid local port prefix name.");
52 yInfoVerbose(
"|> Local port command name: " + local_);
54 remote_ = config.check(
"remote", Value(
"")).asString();
55 yInfoVerbose(
"|> Remote port name: " + remote_);
58 yErrorVerbose(
"Invalid remote port prefix name.");
62 yInfoVerbose(
"|> Remote port command name: " + remote_);
64 if (!port_rpc_command_.open(local_))
66 yErrorVerbose(
"Could not open " + local_ +
" port.");
70 if (!Network::connect(local_, remote_,
"tcp", verbosity_))
72 yErrorVerbose(
"Could not connect to " + local_ +
" remote port.");
76 if (!visualservoing_control.yarp().attachAsClient(port_rpc_command_))
78 yErrorVerbose(
"Cannot attach the RPC client command port.");
82 yInfoVerbose(
"*** VisualServoingClient configured! ***");
90 yInfoVerbose(
"*** Interrupting VisualServoingClient ***");
92 yInfoVerbose(
"Interrupting ports.");
93 port_rpc_command_.interrupt();
95 yInfoVerbose(
"*** Interrupting VisualServoingClient done! ***");
98 yInfoVerbose(
"*** Closing VisualServoingClient ***");
100 yInfoVerbose(
"Closing ports.");
101 port_rpc_command_.close();
103 yInfoVerbose(
"*** Closing VisualServoingClient done! ***");
113 return visualservoing_control.init_facilities(use_direct_kin);
119 return visualservoing_control.reset_facilities();
125 return visualservoing_control.stop_facilities();
131 if (vec_x.size() != 3 || vec_o.size() != 4)
134 std::vector<double> std_vec_x(vec_x.data(), vec_x.data() + vec_x.size());
135 std::vector<double> std_vec_o(vec_o.data(), vec_o.data() + vec_o.size());
137 return visualservoing_control.go_to_pose_goal(std_vec_x, std_vec_o);
143 if (vec_px_l.size() != vec_px_r.size())
146 const size_t num_points = vec_px_l.size();
148 std::vector<std::vector<double>> std_vec_px_l(num_points);
149 std::vector<std::vector<double>> std_vec_px_r(num_points);
151 for (
size_t i = 0; i < num_points; ++i)
153 const Vector& yv_l = vec_px_l[i];
154 std::vector<double>& v_l = std_vec_px_l[i];
156 const Vector& yv_r = vec_px_r[i];
157 std::vector<double>& v_r = std_vec_px_r[i];
159 v_l = std::vector<double>(yv_l.data(), yv_l.data() + yv_l.size());
160 v_r = std::vector<double>(yv_r.data(), yv_r.data() + yv_r.size());
163 return visualservoing_control.go_to_px_goal(std_vec_px_l, std_vec_px_r);
169 return visualservoing_control.set_modality(mode);
175 return visualservoing_control.set_visual_servo_control(control);
181 yWarningVerbose(
"*** Service setControlPoint is unimplemented. ***");
189 yWarningVerbose(
"*** Service getVisualServoingInfo is unimplemented. ***");
197 return visualservoing_control.set_go_to_goal_tolerance(tol);
203 return visualservoing_control.check_visual_servoing_controller();
209 return visualservoing_control.wait_visual_servoing_done(period, timeout);
215 return visualservoing_control.stop_controller();
221 return visualservoing_control.set_translation_gain(K_x_1, K_x_2);
227 return visualservoing_control.set_max_translation_velocity(max_x_dot);
233 return visualservoing_control.set_translation_gain_switch_tolerance(K_x_tol);
239 return visualservoing_control.set_orientation_gain(K_o_1, K_o_2);
245 return visualservoing_control.set_max_orientation_velocity(max_o_dot);
251 return visualservoing_control.set_orientation_gain_switch_tolerance(K_o_tol);
257 std::vector<double> std_x(x.data(), x.data() + x.size());
258 std::vector<double> std_o(o.data(), o.data() + o.size());
260 std::vector<std::vector<double>> std_vec_goal_points = visualservoing_control.get_3D_goal_positions_from_3D_pose(std_x, std_o);
262 size_t num_points = std_vec_goal_points.size();
263 std::vector<Vector> vec_goal_points(num_points);
264 for (
size_t i = 0; i < num_points; ++i)
265 vec_goal_points[i] = Vector(std_vec_goal_points[i].size(), std_vec_goal_points[i].data());
267 return vec_goal_points;
273 std::vector<double> std_x(x.data(), x.data() + x.size());
274 std::vector<double> std_o(o.data(), o.data() + o.size());
276 std::vector<std::vector<double>> std_vec_goal_points = visualservoing_control.get_goal_pixels_from_3D_pose(std_x, std_o, (cam == CamSel::left ?
"left" :
"right"));
278 size_t num_points = std_vec_goal_points.size();
279 std::vector<Vector> vec_goal_points(num_points);
280 for (
size_t i = 0; i < num_points; ++i)
281 vec_goal_points[i] = Vector(std_vec_goal_points[i].size(), std_vec_goal_points[i].data());
283 return vec_goal_points;
289 return visualservoing_control.stored_init(label);
295 return visualservoing_control.stored_go_to_goal(label);
301 return visualservoing_control.get_goal_from_sfm();
bool setTranslationGainSwitchTolerance(const double K_x_tol=30.0) override
bool initFacilities(const bool use_direct_kin) override
bool goToGoal(const yarp::sig::Vector &vec_x, const yarp::sig::Vector &vec_o) override
bool setTranslationGain(const double K_x_1=1.0, const double K_x_2=0.25) override
bool setVisualServoControl(const std::string &control) override
bool resetFacilities() override
bool stopFacilities() override
bool checkVisualServoingController() override
bool open(yarp::os::Searchable &config) override
bool setControlPoint(const yarp::os::ConstString &point) override
bool setModality(const std::string &mode) override
bool goToSFMGoal() override
bool setMaxTranslationVelocity(const double max_x_dot) override
bool storedGoToGoal(const std::string &label) override
bool setOrientationGainSwitchTolerance(const double K_o_tol=30.0) override
bool setMaxOrientationVelocity(const double max_o_dot) override
bool stopController() override
std::vector< yarp::sig::Vector > getGoalPixelsFrom3DPose(const yarp::sig::Vector &x, const yarp::sig::Vector &o, const CamSel &cam) override
std::vector< yarp::sig::Vector > get3DGoalPositionsFrom3DPose(const yarp::sig::Vector &x, const yarp::sig::Vector &o) override
bool setOrientationGain(const double K_o_1=1.5, const double K_o_2=0.375) override
bool waitVisualServoingDone(const double period=0.1, const double timeout=0.0) override
bool storedInit(const std::string &label) override
bool getVisualServoingInfo(yarp::os::Bottle &info) override
bool setGoToGoalTolerance(const double tol=15.0) override