catkin_make not installing new source
- ROS: noetic
- Ubuntu 20.04 LTS server
I have modified the AddTwoInts service code as follows:
roscpp_tutorials/srv/TwoInts.srv
string launch
---
string check
roscpp_tutorials/add_two_ints_server/add_two_ints_server.cpp
#include "ros/ros.h"
#include "roscpp_tutorials/TwoInts.h"
bool add(roscpp_tutorials::TwoInts::Request &req,
roscpp_tutorials::TwoInts::Response &res )
{
res.check = req.launch;
ROS_INFO("request: launch=%s", (char*)req.launch.c_str());
ROS_INFO(" sending back response: [%s]", (char*)res.check.c_str());
return true;
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "add_two_ints_server");
ros::NodeHandle n;
// %Tag(SERVICE_SERVER)%
ros::ServiceServer service = n.advertiseService("add_two_ints", add);
// %EndTag(SERVICE_SERVER)%
ros::spin();
return 0;
}
roscpp_tutorials/add_two_ints_client/add_two_ints_client.cpp
#include "ros/ros.h"
#include "roscpp_tutorials/TwoInts.h"
#include <cstdlib>
int main(int argc, char **argv)
{
ros::init(argc, argv, "add_two_ints_client");
if (argc != 3)
{
ROS_INFO("usage: add_two_ints_client '<package name> <launch file name>'");
return 1;
}
ros::NodeHandle n;
ros::ServiceClient client = n.serviceClient<roscpp_tutorials::TwoInts>("add_two_ints");
roscpp_tutorials::TwoInts srv;
srv.request.launch = atoi(argv[1]);
if (client.call(srv))
{
ROS_INFO("Check: %s", (char*)srv.response.check.c_str());
}
else
{
ROS_ERROR("Failed to call service add_two_ints");
return 1;
}
return 0;
}
If you haven't already worked it out I'm attempting to roslaunch a launch file from a service with roslibjs and rosbridge (I know the risks of service calls - just a test for now).
This builds as normal with catkin_make
with no errors but even after deleting the build and devel folders the original code seems to still run? E.g. if I start the server with rosrun roscpp_tutorials add_two_ints_server
, then run rosrun roscpp_tutorials add_two_ints_client "example string"
it outputs "usage: rosrun add_two_ints_client X Y" instead of what I've changed it to, and errors when I pass in a string instead of an int64. Am I forgetting to change something here?
Should I clear the contents of /opt/ros/noetic/share
? Really unsure what I'm doing wrong here if it builds properly, if its super simple I'm sure I'll kick myself.
Thanks
N.b if you'd like to look at original source its here
argc
, andargv
, it is better to userosparam
. For example,rosrun roscpp_tutorials add_two_ints_client _launch:="example string"
. Please pay attention to_
character withlaunch
param. Later, inside C++ you can use relative namespacenh.getParam("launch", launch);
. A complete example is shown here.(char*)
. TheROS_INFO("Data %s", msg.data.c_str());
should be enough.atoi
. Moreover, in a C++ code, I like to see/use C++ more than C.@ravijoshi Thank you for the example, really helpful :)
Also, do you think this would solve the issue of my code not running with latest changes? The build is fine with no errors, I don't really understand what's going on. I'm making your changes now, and really appreciate your answer.
For a bit more context, if I run
rosrun roscpp_tutorials add_two_ints_client "test string"
, it still prints the original text"usage: add_two_ints_client X Y"
instead of"usage: add_two_ints_client '<package name> <launch file name>'"
- this tells me its not running my latest code. Is there any reason you could think of that could be causing that?Update: removed build and devel folder and re-ran, code updated! Now, I'm getting an MD5Sum error. I think the "add_two_ints_client" code updated, but the "add_two_ints_server" code didnt. This is so strange
Second Update: went into the dreaded opt/ros/noetic/share and /lib ...(more)