1 #include "header/robotVisionInterface.h" 14 this->robotName = robotName;
15 this->topicRoot =
"/uwsim/" + robotName +
"/";
17 std::cout <<
"[" << robotName <<
"][ROBOT_VISION_INTERFACE] Start"<<std::endl;
19 pubTwist = nh.advertise<geometry_msgs::TwistStamped>((topicRoot +
"twist_command"),1);
21 image_transport::ImageTransport it(nh);
23 subRightImage = it.subscribe(topicRoot +
"cameraR", 1, &RobotVisionInterface::imageRightCallback,
this);
24 subRangeRightImage = it.subscribe(topicRoot +
"rangeCameraR", 1, &RobotVisionInterface::imageRangeRightCallback,
this);
28 int RobotVisionInterface::init(){
35 std::string topic =
"/" + robotName;
36 tfListener.waitForTransform(
"world", topic, ros::Time(0), ros::Duration(3.0));
39 ros::Rate loop_rate(100);
40 while (leftImage == NULL) {
42 std::cout <<
"[" << robotName <<
"][ROBOT_VISION_INTERFACE] No left images yet..." << std::endl;
47 while (rightImage == NULL) {
49 std::cout <<
"[" << robotName <<
"][ROBOT_VISION_INTERFACE] No right images yet..." << std::endl;
55 std::cout <<
"[" << robotName <<
"][ROBOT_VISION_INTERFACE] Init done" << std::endl;
60 int RobotVisionInterface::getwTv(Eigen::Matrix4d* wTv_eigen){
66 tf::StampedTransform wTv_tf;
68 std::string topic =
"/" + robotName;
70 tfListener.lookupTransform(
"world", topic, ros::Time(0), wTv_tf);
72 }
catch (tf::TransformException &ex) {
73 ROS_ERROR(
"%s",ex.what());
74 ros::Duration(1.0).sleep();
77 *wTv_eigen = CONV::transfMatrix_tf2eigen(wTv_tf);
83 int RobotVisionInterface::sendyDot(std::vector<double> yDot){
88 if (yDot.size() != 6){
89 std::cout <<
"[" << robotName <<
"][ROBOT_VISION_INTERFACE] yDot must be of size 6 instead of " 90 << yDot.size() << std::endl;
94 geometry_msgs::TwistStamped twist;
95 twist.twist.linear.x=yDot.at(0);
96 twist.twist.linear.y=yDot.at(1);
97 twist.twist.linear.z=yDot.at(2);
98 twist.twist.angular.x=yDot.at(3);
99 twist.twist.angular.y=yDot.at(4);
100 twist.twist.angular.z=yDot.at(5);
102 pubTwist.publish(twist);
118 cv_bridge::CvImagePtr imageCVPtr =
119 cv_bridge::toCvCopy(leftImage, sensor_msgs::image_encodings::MONO8);
120 *imageCV = imageCVPtr.get()->image;
123 (*imageCV) = (*imageCV)(cv::Rect(0, 60, (*imageCV).cols, (*imageCV).rows-60));
128 int RobotVisionInterface::getRightImage(cv::Mat *imageCV){
130 cv_bridge::CvImagePtr imageCVPtr =
131 cv_bridge::toCvCopy(rightImage, sensor_msgs::image_encodings::MONO8);
132 *imageCV = imageCVPtr.get()->image;
135 (*imageCV) = (*imageCV)(cv::Rect(0, 60, (*imageCV).cols, (*imageCV).rows-60));
140 int RobotVisionInterface::getRangeRightImage(cv::Mat *imageCV){
142 cv_bridge::CvImagePtr imageCVPtr =
143 cv_bridge::toCvCopy(rangeRightImage,
"32FC1");
144 *imageCV = imageCVPtr.get()->image;
160 void RobotVisionInterface::imageRightCallback(
const sensor_msgs::ImageConstPtr& msg)
165 void RobotVisionInterface::imageRangeRightCallback(
const sensor_msgs::ImageConstPtr& msg)
167 rangeRightImage = msg;
void imageLeftCallback(const sensor_msgs::ImageConstPtr &msg)
RobotVisionInterface::imageLeftCallback store in member class the image arrived, process it only when...
int getLeftImage(cv::Mat *imageCV)
RobotVisionInterface::getLeftImage for now convert in 8bit grayscale image.
RobotVisionInterface(ros::NodeHandle nh, std::string robotName)
RobotVisionInterface::RobotInterfaceVision Constructor.