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

catkin_make not installing new source

asked 2022-11-06 17:22:02 -0500

meropis gravatar image

updated 2022-11-06 23:08:44 -0500

  • 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

edit retag flag offensive close merge delete

Comments

1
  1. Instead of using argc, and argv, it is better to use rosparam. For example, rosrun roscpp_tutorials add_two_ints_client _launch:="example string". Please pay attention to _ character with launch param. Later, inside C++ you can use relative namespace nh.getParam("launch", launch);. A complete example is shown here.
  2. Next, you do not need to use (char*). The ROS_INFO("Data %s", msg.data.c_str()); should be enough.
  3. I am not sure why you are using atoi. Moreover, in a C++ code, I like to see/use C++ more than C.
ravijoshi gravatar image ravijoshi  ( 2022-11-06 21:47:11 -0500 )edit

@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)

meropis gravatar image meropis  ( 2022-11-06 21:55:50 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-11-07 09:43:54 -0500

meropis gravatar image

I am using Ubuntu Server 20.04. This means that every time you open a new terminal, it resets the source. Therefore I had to source it to the devel/setup.bash correctly with every new terminal and it worked!

command: source ~/catkin_ws/devel/setup.bash

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2022-11-06 17:22:02 -0500

Seen: 44 times

Last updated: Nov 07 '22