ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
-1

node crashes after rosrun !!

asked 2017-04-19 11:19:42 -0600

zubair gravatar image

updated 2017-04-20 03:20:48 -0600

hi guys i am doing blobdetection and tracking ,,, in ros i have implemented something using point cloud to get my x y and z ,, but while catkin_make i have no errors but after rosrun the image is not streaming ..image description

https://pastebin.com/i71RQcU2 this is my full code

please help guys

edit retag flag offensive close merge delete

Comments

ros::NodeHandle *n;

sensor_msgs::PointCloud2 depth; pcl::PointCloud < pcl::PointXYZ > pcl_cloud;

void depthcallback (const sensor_msgs::PointCloud2ConstPtr& cloud_msg) { my_pcl = *cloud_msg; hasNewPcl = true; }

zubair gravatar image zubair  ( 2017-04-19 11:21:24 -0600 )edit

and this is how i am subscribing to image call back

ros::Subscriber dep;
 dep = nh.subscribe ("/camera/depth_registered/points", 1, depthcallback);
zubair gravatar image zubair  ( 2017-04-19 11:22:05 -0600 )edit
3

Looks like there's a bug in your code. I can't tell what's going on in the screenshot; please edit your question to replace the screenshot with the full command you're running, the full error message from your node, and the full source code for your node (or a link to source code).

ahendrix gravatar image ahendrix  ( 2017-04-19 12:17:05 -0600 )edit
1

It's best to not use screen shots of text - it's hard to read and isn't searchable.

Airuno2L gravatar image Airuno2L  ( 2017-04-19 14:58:50 -0600 )edit

https://pastebin.com/i71RQcU2 this is my full code,,

please have a look

zubair gravatar image zubair  ( 2017-04-20 03:16:00 -0600 )edit
1

I can't access that link from my network. Why not just paste it here on this page?

Airuno2L gravatar image Airuno2L  ( 2017-04-20 06:26:04 -0600 )edit

its a very big code.. its out of comment reach

zubair gravatar image zubair  ( 2017-04-20 06:50:27 -0600 )edit

i pasted in pastebin ,, are you not able to see my code ??

zubair gravatar image zubair  ( 2017-04-20 06:55:38 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2017-04-21 05:38:10 -0600

mohsen1989m gravatar image

Instead of rosrun Use gdb to find the point in which your node is crashing.

 gdb ~/(catkin_ws)/devel/lib/(pkg_name)/(executable_name)

enter r and wait for the node to crash, you will have some information about the line in which crash happens and even the line number

Enter bt to track the segmentation fault. One of the most common causes of the segmentation fault is attempting to access a vector index which does not exist

edit flag offensive delete link more
-1

answered 2017-04-20 06:56:11 -0600

zubair gravatar image

updated 2017-04-20 08:21:52 -0600

/* * blobdetection.cpp


  • Created on: 23/03/2017
  • Author: zubair khan */

#include <ros ros.h=""> #include <stdlib.h> #include <iostream> #include <opencv2 highgui="" highgui.hpp=""> #include <opencv2 opencv.hpp=""> #include <opencv2 imgproc="" imgproc.hpp=""> #include <opencv2 core="" core.hpp=""> #include <librealsense rs.hpp=""> #include <librealsense rscore.hpp=""> #include <cv_bridge cv_bridge.h=""> #include <image_transport image_transport.h=""> #include <sensor_msgs image_encodings.h=""> #include <geometry_msgs twist.h=""> #include <geometry_msgs vector3.h=""> #include <pcl point_types.h=""> #include <pcl_ros transforms.h=""> #include <pcl conversions.h=""> #include <pcl pclpointcloud2.h=""> #include <pcl_conversions pcl_conversions.h=""> #include <boost foreach.hpp=""> #include <geometry_msgs point.h=""> #include <sensor_msgs pointcloud2.h="">

namespace enc = sensor_msgs::image_encodings; using namespace std;

static const char WINDOW[] = "Image Processed"; static const char RESULT[] = "Tracking";

sensor_msgs::PointCloud2 my_pcl;

//Use method of ImageTransport to create image publisher image_transport::Publisher pub; bool hasNewPcl = false;

int LowerH = 170; int LowerS = 150; int LowerV = 60; int UpperH = 179; int UpperS = 255; int UpperV = 255;

int posX; int posY;

ros::NodeHandle *n;

sensor_msgs::PointCloud2 depth; pcl::PointCloud < pcl::PointXYZ > pcl_cloud;

typedef pcl::PointCloud<pcl::PointXYZ> PointCloud;

void depthcallback (const sensor_msgs::PointCloud2ConstPtr& cloud_msg) { my_pcl = *cloud_msg; hasNewPcl = true; cout<<"here"<<endl;< p="">

}

void getXYZ(int x, int y) { int arrayPosition = ymy_pcl.row_step + xmy_pcl.point_step; int arrayPosX = arrayPosition + my_pcl.fields[0].offset; int arrayPosY = arrayPosition + my_pcl.fields[1].offset; int arrayPosZ = arrayPosition + my_pcl.fields[2].offset;

float X ;

float Y ; float Z ;

memcpy(&X, &my_pcl.data[arrayPosX], sizeof(float));
memcpy(&Y, &my_pcl.data[arrayPosY], sizeof(float));
memcpy(&Z, &my_pcl.data[arrayPosZ], sizeof(float));

geometry_msgs::Point p; // put data into the point p p.x = X; p.y = Y; p.z = Z; std::cout<<"z:"<<p.z&lt;<std::endl; }<="" p="">

void blobDetectionCallback(const sensor_msgs::ImageConstPtr& original_image) { //Convert from the ROS image message to a CvImage suitable for working with OpenCV for processing cv_bridge::CvImagePtr cv_ptr; try { cv_ptr = cv_bridge::toCvCopy(original_image, enc::BGR8); } catch (cv_bridge::Exception& e) { //if there is an error during conversion, display it ROS_ERROR("tutorialROSOpenCV::main.cpp::cv_bridge exception: %s", e.what()); return; } cv::Mat img_mask,img_hsv; cv::cvtColor(cv_ptr->image,img_hsv,CV_BGR2HSV); cv::inRange(img_hsv,cv::Scalar(LowerH,LowerS,LowerV),cv::Scalar(UpperH,UpperS,UpperV),img_mask);

cv::erode(img_mask, img_mask, cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(5, 5)) );
cv::dilate(img_mask, img_mask, cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(5, 5)) ); 

cv::erode(img_mask, img_mask, cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(5, 5)) );
cv::dilate(img_mask, img_mask, cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(5, 5)) ); 

//Calculate the moments of the thresholded image
cv:: Moments oMoments = moments(img_mask);

double dM01 = oMoments.m01;
double dM10 = oMoments.m10;
double dArea = oMoments.m00;

posX = dM10 / dArea;
posY = dM01 / dArea;

std::cout<<"posx:"<<posX<<"posy:"<<posY<<std::endl;   

cv::circle(img_mask, cv::Point(posX, posY), 10, cv::Scalar(0,255,255), 2);

    cv::Mat Points;
cv::findNonZero(img_mask,Points);
cv::Rect Min_Rect=boundingRect(Points);

cv::rectangle(img_mask,Min_Rect.tl(),Min_Rect.br(),cv::Scalar(255,0,0),1);

cv::imshow(RESULT, img_mask);

//Convert the CvImage to a ROS image message and publish it on the "camera/image_processed" topic.
pub ...
(more)
edit flag offensive delete link more

Comments

sory for bad align,, but this is how it is,, now i am getting x y an z from point cloud,, but i am not able to see imshow images and my trackbars

zubair gravatar image zubair  ( 2017-04-20 06:57:06 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-04-19 11:19:42 -0600

Seen: 870 times

Last updated: Apr 21 '17