1 #ifndef VISUALSERVOINGSERVER_H 2 #define VISUALSERVOINGSERVER_H 4 #include "thrift/VisualServoingIDL.h" 12 #include <yarp/dev/CartesianControl.h> 13 #include <yarp/dev/GazeControl.h> 14 #include <yarp/dev/DeviceDriver.h> 15 #include <yarp/dev/IEncoders.h> 16 #include <yarp/dev/IVisualServoing.h> 17 #include <yarp/dev/PolyDriver.h> 18 #include <yarp/math/Math.h> 19 #include <yarp/os/Bottle.h> 20 #include <yarp/os/BufferedPort.h> 21 #include <yarp/os/ConstString.h> 22 #include <yarp/os/LogStream.h> 23 #include <yarp/os/Port.h> 24 #include <yarp/os/RpcClient.h> 25 #include <yarp/os/Thread.h> 26 #include <yarp/os/Searchable.h> 27 #include <yarp/sig/Image.h> 28 #include <yarp/sig/Matrix.h> 29 #include <yarp/sig/Vector.h> 33 public yarp::dev::IVisualServoing,
34 protected yarp::os::Thread,
45 bool open(yarp::os::Searchable &config)
override;
47 bool close()
override;
57 bool goToGoal(
const yarp::sig::Vector& vec_x,
const yarp::sig::Vector& vec_o)
override;
59 bool goToGoal(
const std::vector<yarp::sig::Vector>& vec_px_l,
const std::vector<yarp::sig::Vector>& vec_px_r)
override;
83 bool setOrientationGain(
const double K_x_1 = 1.5,
const double K_x_2 = 0.375)
override;
91 std::vector<yarp::sig::Vector>
getGoalPixelsFrom3DPose(
const yarp::sig::Vector& x,
const yarp::sig::Vector& o,
const CamSel& cam)
override;
95 bool storedInit(
const std::string& label)
override;
123 bool go_to_px_goal(
const std::vector<std::vector<double>>& vec_px_l,
const std::vector<std::vector<double>>& vec_px_r)
override;
125 bool go_to_pose_goal(
const std::vector<double>& vec_x,
const std::vector<double>& vec_o)
override;
157 std::vector<std::vector<double>>
get_goal_pixels_from_3D_pose(
const std::vector<double> & x,
const std::vector<double> & o,
const std::string& cam)
override;
159 bool quit()
override;
162 bool stored_init(
const std::string& label)
override;
193 std::array<double, 2>
K_x_ = {{0.5, 0.25}};
194 std::array<double, 2>
K_o_ = {{3.5, 0.5}};
215 yarp::sig::Vector
px_des_ = yarp::math::zeros(16);
226 std::vector<yarp::sig::Vector>
l_px_goal_ = std::vector<yarp::sig::Vector>(4);
227 std::vector<yarp::sig::Vector>
r_px_goal_ = std::vector<yarp::sig::Vector>(4);
264 std::vector<yarp::sig::Vector>
getPixelsFromPose(
const yarp::sig::Vector& pose,
const CamSel& cam);
270 yarp::sig::Vector
getPixelFromPoint(
const CamSel& cam,
const yarp::sig::Vector& p)
const;
275 yarp::sig::Vector& features, yarp::sig::Matrix& jacobian);
277 yarp::sig::Vector
getJacobianU(
const CamSel& cam,
const yarp::sig::Vector& px);
279 yarp::sig::Vector
getJacobianV(
const CamSel& cam,
const yarp::sig::Vector& px);
283 bool setPoseGoal(
const yarp::sig::Vector& goal_x,
const yarp::sig::Vector& goal_o);
285 bool setPixelGoal(
const std::vector<yarp::sig::Vector>& l_px_goal,
const std::vector<yarp::sig::Vector>& r_px_goal);
290 yarp::sig::Vector
averagePose(
const yarp::sig::Vector& l_pose,
const yarp::sig::Vector& r_pose)
const;
294 bool checkVisualServoingStatus(
const yarp::sig::Vector& pose_cur,
const double tol_position,
const double tol_orientation,
const double tol_angle);
298 void yInfoVerbose (
const yarp::os::ConstString& str)
const {
if(verbosity_) yInfo() << str; };
299 void yWarningVerbose(
const yarp::os::ConstString& str)
const {
if(verbosity_) yWarning() << str; };
300 void yErrorVerbose (
const yarp::os::ConstString& str)
const {
if(verbosity_) yError() << str; };
bool checkVisualServoingStatus(const yarp::sig::Vector &px_cur, const double tol)
std::mutex mtx_H_eye_cam_
bool set_translation_gain(const double K_x_1, const double K_x_2) override
Set the translation gains of the visual servoing control algorithm.
bool set_max_translation_velocity(const double max_x_dot) override
Set the maximum translation velocity of the visual servoing control algorithm (same for each axis)...
bool initFacilities(const bool use_direct_kin) override
yarp::os::BufferedPort< yarp::sig::Vector > port_kin_px_l_
yarp::os::RpcClient port_rpc_tracker_left_
bool check_visual_servoing_controller() override
Check once whether the visual servoing controller is running or not.
yarp::os::BufferedPort< yarp::sig::ImageOf< yarp::sig::PixelRgb > > port_image_right_out_
bool setOrientationGain(const double K_x_1=1.5, const double K_x_2=0.375) override
bool stop_facilities() override
Stop and disconnect support modules and connections used for visual servoing.
std::vector< yarp::sig::Vector > get3DGoalPositionsFrom3DPose(const yarp::sig::Vector &x, const yarp::sig::Vector &o) override
void getCurrentStereoFeaturesAndJacobian(const std::vector< yarp::sig::Vector > &left_px, const std::vector< yarp::sig::Vector > &right_px, yarp::sig::Vector &features, yarp::sig::Matrix &jacobian)
yarp::os::BufferedPort< yarp::sig::Vector > port_pose_px_l_
bool getVisualServoingInfo(yarp::os::Bottle &info) override
bool set_orientation_gain(const double K_o_1, const double K_o_2) override
Set the orientation gains of the visual servoing control algorithm.
yarp::sig::Vector getJacobianU(const CamSel &cam, const yarp::sig::Vector &px)
bool setVisualServoControl(const std::string &control) override
bool storedInit(const std::string &label) override
bool reset_facilities() override
Reset support modules and connections to perform the current initialized visual servoing task...
bool set_modality(const std::string &mode) override
Set visual servoing operating mode between:
yarp::sig::Vector stdVectorOfVectorsToVector(const std::vector< yarp::sig::Vector > &vectors)
yarp::os::BufferedPort< yarp::sig::Vector > port_pose_avg_
void cartesianPositionBasedVisualServoControl()
void decoupledImageBasedVisualServoControl()
bool is_stopping_backproc_update_vs_params
yarp::os::BufferedPort< yarp::sig::ImageOf< yarp::sig::PixelRgb > > port_image_right_in_
void afterStart(bool success) override
yarp::os::BufferedPort< yarp::sig::Vector > port_goal_px_r_
bool setOrientationGainSwitchTolerance(const double K_o_tol=30.0) override
bool waitVisualServoingDone(const double period=0.1, const double timeout=0.0) override
void backproc_UpdateVisualServoingParamters()
yarp::sig::Matrix l_proj_
yarp::os::BufferedPort< yarp::sig::Vector > port_pose_goal_
bool stored_init(const std::string &label) override
Initialize the robot to an initial position.
bool threadInit() override
bool set_go_to_goal_tolerance(const double tol) override
Set visual servoing goal tolerance.
bool stopFacilities() override
double K_orientation_tol_
std::vector< std::string > get_visual_servoing_info() override
Return useful information for visual servoing.
bool stored_go_to_goal(const std::string &label) override
Set the robot visual servoing goal.
bool checkVisualServoingController() override
yarp::sig::Vector px_des_
yarp::sig::Matrix l_H_r_to_cam_
yarp::os::BufferedPort< yarp::sig::Vector > port_pose_right_in_
bool setPoseGoal(const yarp::sig::Vector &goal_x, const yarp::sig::Vector &goal_o)
yarp::os::BufferedPort< yarp::sig::ImageOf< yarp::sig::PixelRgb > > port_image_left_in_
bool set_translation_gain_switch_tolerance(const double K_x_tol) override
Set the tolerance, in pixels, at which the translation control law swithces its gain value...
yarp::os::BufferedPort< yarp::sig::Vector > port_kin_px_r_
bool set_orientation_gain_switch_tolerance(const double K_o_tol) override
Set the tolerance, in pixels, at which the orientation control law swithces its gain value...
std::vector< yarp::sig::Vector > getGoalPixelsFrom3DPose(const yarp::sig::Vector &x, const yarp::sig::Vector &o, const CamSel &cam) override
bool setTranslationGainSwitchTolerance(const double K_x_tol=30.0) override
void yWarningVerbose(const yarp::os::ConstString &str) const
yarp::sig::Vector getJacobianV(const CamSel &cam, const yarp::sig::Vector &px)
yarp::sig::Matrix r_H_r_to_cam_
bool stop_controller() override
Ask for an immediate stop of the visual servoing controller.
std::vector< std::vector< double > > get_3D_goal_positions_from_3D_pose(const std::vector< double > &x, const std::vector< double > &o) override
Helper function: extract four Cartesian points lying on the plane defined by the frame o in the posit...
void yInfoVerbose(const yarp::os::ConstString &str) const
yarp::dev::IGazeControl * itf_gaze_
yarp::os::ConstString robot_name_
std::thread * thr_background_update_params_
bool goToSFMGoal() override
yarp::sig::Vector getControlPixelFromPoint(const CamSel &cam, const yarp::sig::Vector &p) const
void threadRelease() override
std::vector< yarp::sig::Vector > getPixelsFromPose(const yarp::sig::Vector &pose, const CamSel &cam)
VisualServoControl vs_control_
yarp::os::BufferedPort< yarp::sig::ImageOf< yarp::sig::PixelRgb > > port_image_left_out_
yarp::os::RpcClient port_rpc_tracker_right_
yarp::os::BufferedPort< yarp::sig::Vector > port_pose_px_r_
std::vector< std::vector< double > > get_goal_pixels_from_3D_pose(const std::vector< double > &x, const std::vector< double > &o, const std::string &cam) override
Helper function: extract four 2D pixel points lying on the plane defined by the frame o in the positi...
void beforeStart() override
bool setGoToGoalTolerance(const double tol=15.0) override
bool setTranslationGain(const double K_x_1=1.0, const double K_x_2=0.25) override
bool setPixelGoal(const std::vector< yarp::sig::Vector > &l_px_goal, const std::vector< yarp::sig::Vector > &r_px_goal)
yarp::sig::Matrix l_H_eye_to_r_
yarp::sig::Vector goal_pose_
bool setRightArmCartesianController()
std::vector< yarp::sig::Vector > l_px_goal_
bool set_visual_servo_control(const std::string &control) override
Set visual servo control law between:
bool resetFacilities() override
yarp::os::BufferedPort< yarp::sig::Vector > port_pose_kin_
yarp::os::Port port_rpc_command_
VisualServoingIDL IDL Interface to ServerVisualServoing functionalities.
yarp::dev::PolyDriver rightarm_cartesian_driver_
yarp::dev::PolyDriver gaze_driver_
bool stopController() override
std::vector< yarp::sig::Vector > getControlPixelsFromPose(const yarp::sig::Vector &pose, const CamSel &cam, const PixelControlMode &mode)
bool go_to_pose_goal(const std::vector< double > &vec_x, const std::vector< double > &vec_o) override
Set the goal point (3D for the position + 4D axis-angle for the orientation) and start visual servoin...
yarp::os::BufferedPort< yarp::os::Bottle > port_click_left_
std::vector< yarp::sig::Vector > r_px_goal_
yarp::os::BufferedPort< yarp::sig::Vector > port_goal_px_l_
bool setCameraTransformations()
yarp::sig::Matrix r_proj_
bool setModality(const std::string &mode) override
bool init_facilities(const bool use_direct_kin) override
Initialize support modules and connections to perform a visual servoing task.
bool goToGoal(const yarp::sig::Vector &vec_x, const yarp::sig::Vector &vec_o) override
void robustImageBasedVisualServoControl()
bool go_to_px_goal(const std::vector< std::vector< double >> &vec_px_l, const std::vector< std::vector< double >> &vec_px_r) override
yarp::sig::Vector getPixelFromPoint(const CamSel &cam, const yarp::sig::Vector &p) const
yarp::dev::ICartesianControl * itf_rightarm_cart_
bool setControlPoint(const yarp::os::ConstString &point) override
bool quit() override
Gently close the visual servoing device, deallocating resources.
yarp::sig::Matrix r_H_eye_to_r_
bool wait_visual_servoing_done(const double period, const double timeout) override
Wait until visual servoing reaches the goal.
yarp::sig::Vector averagePose(const yarp::sig::Vector &l_pose, const yarp::sig::Vector &r_pose) const
bool get_goal_from_sfm() override
Get goal point from SFM module.
bool storedGoToGoal(const std::string &label) override
yarp::os::BufferedPort< yarp::os::Bottle > port_click_right_
bool setMaxOrientationVelocity(const double max_o_dot) override
bool set_control_point(const std::string &point) override
Set the point controlled during visual servoing.
bool set_max_orientation_velocity(const double max_o_dot) override
Set the maximum angular velocity of the axis-angle velocity vector of the visual servoing control alg...
bool open(yarp::os::Searchable &config) override
yarp::os::BufferedPort< yarp::sig::Vector > port_pose_left_in_
std::vector< yarp::sig::Vector > getControlPointsFromPose(const yarp::sig::Vector &pose)
bool setMaxTranslationVelocity(const double max_x_dot) override
void yErrorVerbose(const yarp::os::ConstString &str) const
std::array< double, 2 > K_x_
std::array< double, 2 > K_o_