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

Pigskin's profile - activity

2019-05-20 01:38:13 -0500 marked best answer no matching function for call to

Hey everybody, I'm working on a node that uses a service to repeat a string a variable amount of times. for this i made the following srv file:

string text
int32 nrOfDuplicates
---

this will be processed by the following C++ code:

#include "ros/ros.h"
#include "std_msgs/String.h"
#include "std_msgs/Int32.h"
#include <string>

void multiply (std_msgs::String::ConstPtr   & str, std_msgs::Int32      & var){
int amount = var.data;
    for(int i = 0 ; i < amount ; i++)
    {
        ROS_INFO("%s", str->data.c_str());
    }
 ROS_INFO("/n");
}

int main(int argc, char **argv)
{
  ros::init(argc, argv, "add_duplicates");
  ros::NodeHandle n;
  ros::ServiceServer service = n.advertiseService("add_duplicates", multiply);
  ros::spin();

  return 0;
}

however, when i use catkin_make to compile the node, i get the following error:

/home/osboxes/catkin_ws/src/final/src/duplicator.cpp: In function ‘int main(int, char**)’:
/home/osboxes/catkin_ws/src/final/src/duplicator.cpp:19:77: error: no matching function for call to ‘ros::NodeHandle::advertiseService(const char [15], void (&)(std_msgs::String_<std::allocator<void> >::ConstPtr&, std_msgs::Int32&))’
   ros::ServiceServer service = n.advertiseService("add_duplicates", multiply);
                                                                             ^

I was considering that it is looking for a function that uses a string and int32 instead of the Std_msgs counterpart, but i'm a total ROS newbie and am not sure if this is true, or how to write it otherwise.

all help is appreciated!

2019-05-20 01:36:55 -0500 marked best answer No response from service, node won't close either

I am running into an issue with calling a service in the callback function of a listener. I couldn't find a way to call the service as the initialization of the client stood in the main, but moving that to the function as well gave a whole different series of errors, so i tried to implement a work-around

#include "ros/ros.h"
#include "std_msgs/String.h"
#include "final/add_duplicates.h"
#include <string>
int message = 0;
std::string text;

void preparefortrouble(const std_msgs::String::ConstPtr& msg)
{
text = msg->data.c_str();
message = 1;
}

int main(int argc, char **argv)
{
    ros::init(argc, argv, "add_duplicates_client");
    ros::init(argc, argv, "print_twice");
    ros::NodeHandle n;  
    ros::Subscriber sub = n.subscribe("print_twice", 1, preparefortrouble);
    ros::ServiceClient client = n.serviceClient<final::add_duplicates>("add_duplicates");

    while (1){
        while (message == 1)
        {
            final::add_duplicates srv;
            srv.request.text = text.c_str();
            srv.request.nrOfDuplicates = 2;
            if (client.call(srv) == false)
            {
                ROS_ERROR("Orga het is stuk");
            }
            message = 0;
        }
    }
  ros::spin();

  return 0;
}

The server has been tested and works fine, the topic is called in the terminal. However, when i use this node, it cannot be close by crtl-c and sending a message to the topic results in nothing.

i try to call it with

$ rostopic pub /print_twice std_msgs/string “hello"

and my srv file is as following:

string text
int32 nrOfDuplicates
---
string multitext

thanks for the support.

2019-05-20 01:36:41 -0500 received badge  Famous Question (source)
2019-05-20 01:36:41 -0500 received badge  Notable Question (source)
2019-05-20 01:36:41 -0500 received badge  Popular Question (source)
2018-07-24 16:46:19 -0500 received badge  Famous Question (source)
2018-07-24 16:46:19 -0500 received badge  Notable Question (source)
2018-07-24 16:46:19 -0500 received badge  Popular Question (source)
2018-02-25 10:15:17 -0500 asked a question No response from service, node won't close either

No response from service, node won't close either I am running into an issue with calling a service in the callback func

2018-02-23 10:47:12 -0500 commented answer no matching function for call to

However, I still have a few questions. I have distilled that the callback should be a boolean, so it can check if the fu

2018-02-23 10:44:53 -0500 commented answer no matching function for call to

I have, However I think i lost the important bits when i got confused when they imported the srv from a different packag

2018-02-23 10:32:00 -0500 received badge  Supporter (source)
2018-02-23 10:24:08 -0500 asked a question no matching function for call to

no matching function for call to Hey everybody, I'm working on a node that uses a service to repeat a string a variable