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

Clancy's profile - activity

2018-03-06 16:44:31 -0500 received badge  Nice Answer (source)
2017-07-26 10:49:03 -0500 received badge  Self-Learner (source)
2017-07-26 10:49:03 -0500 received badge  Teacher (source)
2015-04-29 15:11:53 -0500 commented answer Calling a ros service function from another one

It's as simple as tbh makes it out to be - just call that function name from inside the other service. No need to specify an address for the srv.request or srv.response, they are already included. So it looks like this:

serviceCallBack(some_srv.request, some_srv.response)

2015-04-23 18:57:02 -0500 commented answer How can I control the rqt_plot x-axis scale?

It's right-click and drag on 14.04 and Indigo.

2015-04-23 18:57:02 -0500 received badge  Commentator
2015-04-18 17:55:37 -0500 commented question RVIZ crashes and Qt has caught an exception thrown from an event handler

Did you ever figure this out?

2015-04-09 01:38:18 -0500 received badge  Enthusiast
2015-04-03 23:56:36 -0500 commented answer ROS remote master: can see topics but no data

This worked for me. Just add the publishing computer to the /etc/hosts file in the same format as the localhost is added.

2015-04-02 23:08:50 -0500 commented question urg_node single echo scan error

Fixed it. Downloaded "upgrade" and "reset" attachments from this website (directions on website):

http://wiki.ros.org/hokuyo_node/Troub...

Ran the programs.

Then I cycled the power on the laser and everything seemed to work fine.

2015-04-02 23:06:51 -0500 commented answer No transform from [base_link] to [/map]

Nice. Thank you.

2015-04-02 22:41:06 -0500 commented question urg_node single echo scan error

Having the same problem - using the urg node to run the 04LX Classic and I'm not getting any data.

2015-01-27 10:02:43 -0500 commented answer Trouble Including rosbag

This was very helpful. I was missing the CMakeLists.txt part. Thanks!

2015-01-03 16:53:37 -0500 received badge  Famous Question (source)
2014-11-23 23:17:26 -0500 received badge  Supporter (source)
2014-11-23 23:17:15 -0500 received badge  Scholar (source)
2014-11-23 23:16:58 -0500 commented answer Can a node be a subscriber and client at the same time?

Ha! Unfortunately I don't have enough points yet.

2014-11-20 12:44:52 -0500 received badge  Notable Question (source)
2014-11-20 11:23:36 -0500 received badge  Popular Question (source)
2014-11-20 11:01:56 -0500 received badge  Editor (source)
2014-11-20 11:00:48 -0500 commented question Can a node be a subscriber and client at the same time?

I'll have to check out the nodelet solution. My answer will go through a couple more revisions, but I wanted to put up our immediate solution so that others can see a way of doing it. Thanks.

2014-11-20 10:56:25 -0500 commented answer Can a node be a subscriber and client at the same time?

Sorry for the ambiguity, hopefully the answer clears things up.

2014-11-20 10:55:51 -0500 answered a question Can a node be a subscriber and client at the same time?

Yes. A node can be a subscriber and a client at the same time.

We needed a node that could subscribe to a topic and call a service request from another node at any given time. I couldn't find any solutions (probably because it is a relatively simple concept)... but I think there should be some documentation for other people stuck with the same problem.

The problem we were having: Most of the service request examples have the service request being called from inside the main function. When we tried to do this, we were only able to request a service once and then the node would be caught in a spin loop. To avoid this error, we decided to move the service request into the subscriber callback function. This way it would be called whenever the subscriber heard a message.

The basic idea: The client is instantiated in the main function, but it needs to be used in the callback function. I made a ros::ServiceClient pointer at a global level (w.r.t. the node) and then gave it the address of the client. In the callback function I dereference the client pointer and use it to request a service.

 void SUBSCRIBE_CALLBACK_FUNCTION (const PACKAGE_NAME::MESSAGE_NAME::ConstPtr& msg);
    ros::ServiceClient *clientPtr; //pointer for a client

    int main (int argc, char **argv)
    {

        ros::init(argc, argv, "MY_NODE");
        ros::NodeHandle n;
        ros::ServiceClient client = n.serviceClient<PACKAGE_NAME::SERVICE_NAME>("SERVICE_NAME"); //create the client

        clientPtr = &client; //give the address of the client to the clientPtr

        ros::Subscriber sub = n.subscribe<PACKAGE_NAME::MESSAGE_NAME>("TOPIC_NAME",1000,SUBSCRIBE_CALLBACK_FUNCTION); //subscribing

        ros::spin();

        return 0;

    }

    void SUBSCRIBE_CALLBACK_FUNCTION (const PACKAGE_NAME::MESSAGE_NAME::ConstPtr& msg)
    {
        PACKAGE_NAME::SERVICE_NAME srv;
        srv.request.someBool= false; //just some variables to give the service some structure.
        srv.request.someFloat = 4;
        srv.request.someFloat = 30;

        ros::ServiceClient client = (ros::ServiceClient)*clientPtr; //dereference the clientPtr

        if(client.call(srv)) //request service from the client
        {
            ROS_INFO("Success = %d", srv.response.success);
        }   
        else
        {
            ROS_ERROR("Failed to call service from motor_control_node");    
        }

    }
2014-11-20 09:31:49 -0500 asked a question Can a node be a subscriber and client at the same time?

I figured out how to do this, but couldn't find any documentation anywhere so I figured I'd help out anyone that is trying to do the same thing.