Ask Your Question
1

working with cmvision/Blobs

asked 2014-08-12 09:36:19 -0500

ghanimmukhtar gravatar image

updated 2014-08-12 18:04:27 -0500

hi, I am trying to work with cmvision/Blobs topic "message" and when I use in my code cmvision/Blobs.x it gives me an error, can anyone please show me how to access the elements of Blobs (x,y in particular)?

EDIT:

Here is the code:

#include "ros/ros.h"
#include <geometry_msgs/Twist.h>
#include "cmvision/Blobs.h"
#include <turtlesim/Pose.h>

using namespace std;

ros::Publisher pub_msg;
geometry_msgs::Twist cmd_msg;
cmvision::Blobs lastobjectpose;
turtlesim::Pose lastFollowerPose;

void fblobCallback(cmvision::Blobs object_pose)
{
    lastobjectpose=object_pose;
}

void fposeCallback(turtlesim::Pose follower_pose)
{
    lastFollowerPose=follower_pose;
}

int main (int argc, char** argv)
{
    //ROS Initialization
    ros::init(argc, argv, "follower_leader");
    ROS_INFO("Node follower_leader Connected to roscore");
    ros::NodeHandle n ("~");
    ros::Subscriber pose_sub_object = n.subscribe<cmvision::Blobs>("/blobs",1,fblobCallback);
    ros::Subscriber pose_sub_follower = n.subscribe<turtlesim::Pose>("follower_pose",1,fposeCallback);

    pub_msg = n.advertise<geometry_msgs::Twist>("follower_velocity",1);
    ros::Rate rate(10);
    ROS_INFO("SPINNING @ 10Hz");

    while (ros::ok()){
        ros::spinOnce();
        double d = 0;
    d = sqrt(   pow(lastobjectpose.x-lastFollowerPose.x,2)
            + pow(lastobjectpose.y-lastFollowerPose.y,2) ) ;
    double dtheta = 0.0 ;
    if( d>0.01 ) {
        dtheta =   atan2(lastobjectpose.y-lastFollowerPose.y,
                 lastobjectpose.x-lastFollowerPose.x)
        - lastFollowerPose.theta ;
    }

    if(d>0.01){     
        cmd_msg.linear.x = 0.2*d;
        cmd_msg.angular.z = 4*dtheta;}else{cmd_msg.linear.x = 0;
        cmd_msg.angular.z = 0;}
    pub_msg.publish(cmd_msg);
        rate.sleep();
    } 

    ROS_INFO("ROS-Node Terminated\n");
}

And here is the error i receive when i do "catkin_make":

Base path: /home/ghanim/catkin_ws
Source space: /home/ghanim/catkin_ws/src
Build space: /home/ghanim/catkin_ws/build
Devel space: /home/ghanim/catkin_ws/devel
Install space: /home/ghanim/catkin_ws/install
####
#### Running command: "make cmake_check_build_system" in "/home/ghanim/catkin_ws/build"
####
####
#### Running command: "make -j2 -l2" in "/home/ghanim/catkin_ws/build"
####
[  0%] [  0%] Built target std_msgs_generate_messages_py
Built target std_msgs_generate_messages_cpp
[  0%] Built target std_msgs_generate_messages_lisp
[ 18%] Built target colorgui
[ 25%] Building CXX object color_follower/CMakeFiles/color_follower_node.dir/src/color_follower_node.cpp.o
[ 31%] Built target follower_leader_node
[ 43%] Built target cmvision_generate_messages_cpp
[ 62%] Built target cmvision_generate_messages_py
[ 75%] Built target cmvision_generate_messages_lisp
[ 75%] Built target cmvision_gencpp
[ 75%] Built target cmvision_generate_messages
[100%] Built target cmvision
/home/ghanim/catkin_ws/src/color_follower/src/color_follower_node.cpp: In function ‘int main(int, char**)’:
/home/ghanim/catkin_ws/src/color_follower/src/color_follower_node.cpp:60:33: error: ‘cmvision::Blobs’ has no member named ‘x’
/home/ghanim/catkin_ws/src/color_follower/src/color_follower_node.cpp:61:39: error: ‘cmvision::Blobs’ has no member named ‘y’
/home/ghanim/catkin_ws/src/color_follower/src/color_follower_node.cpp:64:36: error: ‘cmvision::Blobs’ has no member named ‘y’
/home/ghanim/catkin_ws/src/color_follower/src/color_follower_node.cpp:65:39: error: ‘cmvision::Blobs’ has no member named ‘x’
make[2]: *** [color_follower/CMakeFiles/color_follower_node.dir/src/color_follower_node.cpp.o] Error 1
make[1]: *** [color_follower/CMakeFiles/color_follower_node.dir/all] Error 2
make: *** [all] Error 2
Invoking "make" failed
edit retag flag offensive close merge delete

Comments

3

Please update your question with the error message you're getting, and the code that produces it.

Dan Lazewatsky gravatar imageDan Lazewatsky ( 2014-08-12 10:53:30 -0500 )edit
2

When adding code, please don't create an answer. I moved the code to your original question, and deleted the answer you created.

jarvisschultz gravatar imagejarvisschultz ( 2014-08-12 18:05:39 -0500 )edit

okay and thanks

ghanimmukhtar gravatar imageghanimmukhtar ( 2014-08-13 03:45:29 -0500 )edit

2 Answers

Sort by » oldest newest most voted
2

answered 2014-08-12 16:21:31 -0500

ahubers gravatar image

Here is the cmvision/Blobs message structure:

std_msgs/Header header
  uint32 seq
  time stamp
  string frame_id
uint32 image_width
uint32 image_height
uint32 blob_count
cmvision/Blob[] blobs
  string name
  uint32 red
  uint32 green
  uint32 blue
  uint32 area
  uint32 x
  uint32 y
  uint32 left
  uint32 right
  uint32 top
  uint32 bottom

When you access your cmvision::Blobs struct like so pow(lastobjectpose.x-lastFollowerPose.x,2), you are implying that the Blobs message type has some x member. However, the x and y that you are looking for are in actuality in lastobjectpose.blobs[some_index].x and so it goes for y. Hence it might make sense for you to instead loop through lastobjectpose.blobs, using lastobjectpose.blob_count as your bound, i.e,

for (i = 0; i < lastobjectpose.blob_count; i++) {
  //Do your stuff.
}
edit flag offensive delete link more

Comments

Thanks very much it is compiling now, i have another question though how can I access the image_width and height ?

ghanimmukhtar gravatar imageghanimmukhtar ( 2014-08-13 03:46:45 -0500 )edit

I'm not much of a C++ person, but I believe you can think of a message in your code as you do a struct. Since image_width and image_height are direct members of this message, you can write lastobjectpose.image_width and lastobjectpose.image_height, respectively.

ahubers gravatar imageahubers ( 2014-08-13 11:32:56 -0500 )edit

thanks very much actually i have done this way and yeah it is working :)

ghanimmukhtar gravatar imageghanimmukhtar ( 2014-08-13 15:13:12 -0500 )edit
0

answered 2014-08-13 05:58:32 -0500

Mobile_robot gravatar image

Hello, I used this code to have the access to the CMVISION's Blobs, I remind you that Blobs is a type of the message that includes another message called Blob, And also in my code I just used the FIRST Blob (which is the bigger one in size) , so you can modify as you want.

This is your callback function.

if (msg1->blob_count > 0){
    // If you want to access to ALL Blobs
    //for (int i = 0; i < msg1->blob_count; i++){

    //This is for the case that you want to catch a Blob with some size limitation.
    //if(msg1->blobs[i].right - msg1->blobs[i].left > 7 || msg1->blobs[i].top - msg1->blobs[i].bottom > 7   )
    //{
        X = msg1->blobs[0].x ;
        Y = msg1->blobs[0].y ;
    //}

    //}

}
edit flag offensive delete link more

Comments

yeah i basically used the same, thanks

ghanimmukhtar gravatar imageghanimmukhtar ( 2014-08-13 15:22:13 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-08-12 09:36:19 -0500

Seen: 559 times

Last updated: Aug 13 '14