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

robo_ninja's profile - activity

2023-03-17 02:52:15 -0500 commented question Unable to access publisher in nodelet

Thank you for clarifying that. I was following [kobuki controller wiki page] (http://wiki.ros.org/kobuki/Tutorials/Write

2023-03-16 17:31:47 -0500 asked a question Unable to access publisher in nodelet

Unable to access publisher in nodelet I am writing a ROS nodelet wrapper class for my existing ROS node. My nodelet is p

2023-03-15 08:31:25 -0500 marked best answer nodelet: can't add argument to constructor

I am writing a ROS nodelet in which I have a GetInstance() method. I am trying to parse a string argument and it's throwing me the error. Can someone point out how this error can be fixed?? Any help is appreciated.

Following is the build error -

In file included from /opt/ros/noetic/include/class_loader/class_loader_core.hpp:45,
                 from /opt/ros/noetic/include/class_loader/class_loader.hpp:46,
                 from /opt/ros/noetic/include/pluginlib/./class_list_macros.hpp:40,
                 from /opt/ros/noetic/include/pluginlib/class_list_macros.h:35,
                 from /home/robo/test_ws/src/blob_detect/src/blob_detect/blob_detect_nodelet.cpp:3:
/opt/ros/noetic/include/class_loader/meta_object.hpp: In instantiation of ‘B* class_loader::impl::MetaObject<C, B>::create() const [with C = blob_detect::BlobDetectNodelet; B = nodelet::Nodelet]’:
/opt/ros/noetic/include/class_loader/meta_object.hpp:196:7:   required from here
/opt/ros/noetic/include/class_loader/meta_object.hpp:198:12: error: no matching function for call to ‘blob_detect::BlobDetectNodelet::BlobDetectNodelet()’
  198 |     return new C;
      |            ^~~~~
In file included from /home/robo/test_ws/src/blob_detect/src/blob_detect/blob_detect_nodelet.cpp:1:
/home/robo/test_ws/src/blob_detect/include/blob_detect/blob_detect_nodelet.h:22:3: note: candidate: ‘blob_detect::BlobDetectNodelet::BlobDetectNodelet(const string&)’
   22 |   BlobDetectNodelet(const std::string& cameraName) : nodelet::Nodelet() {}
      |   ^~~~~~~~~~~~~~~~~~~~~~
/home/robo/test_ws/src/blob_detect/include/blob_detect/blob_detect_nodelet.h:22:3: note:   candidate expects 1 argument, 0 provided
make[2]: *** [CMakeFiles/blob_detect.dir/build.make:63: CMakeFiles/blob_detect.dir/src/blob_detect/blob_detect_nodelet.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:183: CMakeFiles/blob_detect.dir/all] Error 2
make: *** [Makefile:141: all] Error 2

My blob_detect_nodelet.h file looks like the following -

#ifndef BLOB_DETECT_NODELET_H
#define BLOB_DETECT_NODELET_H

#include <cv_bridge/cv_bridge.h>
#include <ros/ros.h>
#include <sensor_msgs/Image.h>
#include <sensor_msgs/RegionOfInterest.h>
#include <sensor_msgs/image_encodings.h>
#include <boost/geometry.hpp>
#include <boost/range/irange.hpp>
#include <opencv2/opencv.hpp>
#include "nodelet/nodelet.h"

namespace blob_detect {

class BlobDetectNodelet : public nodelet::Nodelet {
 public:
  BlobDetectNodelet(const std::string& cameraName) : nodelet::Nodelet(){}
  static BlobDetectNodelet& GetInstance(const std::string& cameraName = "");
  inline const cv::Mat GetCurrentImage(void) const { return currentImage; }
  inline void SetCurrentImage(const cv::Mat& image) { currentImage = image; }

 private:
  void onInit() override;
  void imageCb(const sensor_msgs::Image::ConstPtr& msg);
  ros::NodeHandle nh;
  ros::NodeHandle private_nh;
  ros::Subscriber imageSub;
  ros::Publisher roiImagePub;
  const std::string cameraName;
  cv::Mat currentImage;

}

And following is my blob_detect_nodelet.cpp file -

#include <blob_detect/blob_detect_nodelet.h>
#include "pluginlib/class_list_macros.h"

namespace blob_detect {
void BlobDetectNodelet::onInit() {
  nh = getNodeHandle();
  private_nh = getPrivateNodeHandle();

  roiImagePub = nh.advertise<sensor_msgs::Image>("/camera_1/output_image", 100);
  imageSub = nh.subscribe("/camera_1/image_raw", 10, &BlobDetectNodelet::imageCb, this);
}

BlobDetectNodelet& BlobDetectNodelet::getInstance(const std::string& cameraName) {
  static BlobDetectNodelet instance(cameraName);
  return instance;
}

void BlobDetectNodelet::imageCb(const sensor_msgs::Image::ConstPtr& image) {
  cv_bridge::CvImageConstPtr cv_image = cv_bridge::toCvShare(image, "mono8");
}
}  // namespace blob_detect

PLUGINLIB_EXPORT_CLASS(blob_detect::BlobDetectNodelet, nodelet::Nodelet);
2023-03-14 13:46:29 -0500 asked a question nodelet: can't add argument to constructor

GetInstance() method in nodelet I am writing a ROS nodelet in which I have a GetInstance() method. I am trying to parse

2023-03-06 23:09:24 -0500 asked a question Load nodelet from another package

Load nodelet from another package Hi I am new to using nodelets. I am using an open source ros driver for a camera which

2021-05-06 04:28:28 -0500 received badge  Famous Question (source)
2020-05-15 11:19:39 -0500 received badge  Famous Question (source)
2018-10-09 15:22:09 -0500 marked best answer Subscribing to /rosout topic

Is there a way I can write a node to subscribe the log messages from the /rosout topic and save in a HTML file?

2018-07-30 02:57:33 -0500 received badge  Nice Question (source)
2018-06-04 08:09:32 -0500 received badge  Famous Question (source)
2018-04-18 01:54:39 -0500 received badge  Notable Question (source)
2018-04-18 01:54:39 -0500 received badge  Famous Question (source)
2018-04-18 01:54:39 -0500 received badge  Popular Question (source)
2018-02-28 07:09:01 -0500 received badge  Notable Question (source)
2018-01-18 07:53:24 -0500 received badge  Notable Question (source)
2017-12-06 11:02:04 -0500 received badge  Supporter (source)
2017-12-05 12:37:37 -0500 marked best answer Insert elements to a map listing the nodes

I am subscribing to /diagnostics topic, to which all my nodes are publishing their outputs. In my source file, I have created a map of all the node names as follows -

std::map<string, int> TextCode;
TextCode = {{"Camera_node1", 1}, {"LIDAR_node2", 2}};

I have prepopulated the map with few nodes (as above). I have a callback function, in which I publish the node name whenever the level of operation is ERROR -

void diagnosticCallback(const diagnostic_msgs::DiagnosticArrayPtr &diags_msg)
{
  int Maincode;
  if (diags_msg->status[0].level == diagnostic_msgs::DiagnosticStatus::ERROR)
  {
    Maincode = TextCode[diags_msg->status[0].name];
    ROS_INFO_STREAM("Error occured : " << Maincode);
  }
  else if (diags_msg->status[0].level == diagnostic_msgs::DiagnosticStatus::OK)
  {
    Maincode = TextCode[diags_msg->status[0].name];
    ROS_INFO_STREAM("No error");
  }
}

I want to check the node names every time we receive ERROR and then check all the elements of my map TextCode, if the name is present. If not then add the name as the next element in the map. How should I proceed with that?

Note - Diagnostics_msgs - http://docs.ros.org/api/diagnostic_msgs/html/msg/DiagnosticStatus.html)

2017-12-05 01:58:42 -0500 received badge  Popular Question (source)
2017-12-04 14:21:03 -0500 edited question Insert elements to a map listing the nodes

Insert elements to a map listing the nodes I am subscribing to /diagnostics topic, to which all my nodes are publishing

2017-12-04 14:20:40 -0500 edited question Insert elements to a map listing the nodes

Insert elements to a map listing the nodes I am subscribing to /diagnostics topic, to which all my nodes are publishing

2017-12-04 14:18:56 -0500 edited question Insert elements to a map listing the nodes

Insert elements to a map listing the nodes I am subscribing to /diagnostics topic, to which all my nodes are publishing

2017-12-04 14:18:40 -0500 edited question Insert elements to a map listing the nodes

Insert elements to a map listing the nodes I am subscribing to /diagnostics topic, to which all my nodes are publishing

2017-12-04 14:17:14 -0500 asked a question Insert elements to a map listing the nodes

Insert elements to a map listing the nodes I am subscribing to [/diagnostics](http://docs.ros.org/api/diagnostic_msgs/ht

2017-11-30 19:46:32 -0500 received badge  Popular Question (source)
2017-11-30 15:44:56 -0500 edited question Publishing multiple data at a time

Publishing multiple errors at a particular time I have a csv file listing all the errors the occur with the system. I am

2017-11-30 14:58:09 -0500 edited question Publishing multiple data at a time

Publishing multiple errors at a particular time I have a csv file listing all the errors the occur with the system. I am

2017-11-30 14:33:12 -0500 asked a question Publishing multiple data at a time

Publishing multiple errors at a particular time I have a csv file listing all the errors the occur with the system. I am

2017-11-16 08:01:11 -0500 received badge  Famous Question (source)
2017-11-10 14:07:45 -0500 received badge  Famous Question (source)
2017-11-10 14:07:45 -0500 received badge  Notable Question (source)
2017-11-10 09:33:30 -0500 marked best answer catkin_make errors while subscribing to diagnostic topic

I am trying to subscribe to diagnostic topic and based on the level published by the topic, I am trying to start and stop my operation. I have created 2 functions requestStart and requestNotStart for these purposes. I am getting the CMake errors which I am unable to fix (posted at the end of the post).

Following is my code -

using namespace std;
namespace errorLib
{
  class errorH
  {
    public:
      errorH(EC value, string text, int sec):
        value_(value),
        text_(text),
        is_started_(false),
        sec_(sec)
        {
        }
      EC value_;
      string text_;
      bool is_started_;
      int retry_seconds_;
  };
}
 void diagnosticCallback(const diagnostic_msgs::DiagnosticArrayPtr &diags_msg)
  {
    if (diags_msg[0].level == diagnostic_msgs::DiagnosticStatus::ERROR)
      errorcode = NodeToErrorCode[diags_msg[0].name];
      requestStart();

    else (diags_msg[0].level == diagnostic_msgs::DiagnosticStatus::OK)
      errorcode = NodeToErrorCode[diags_msg[0].name];
      requestNotStart();
  }

int requestStart(errorLib::errorH& c)
{
  if(!c.is_started_)
    retry_seconds_ = 2;
    // Start timer
    // Timer expired
  c.is_started_ = true;
  return 0;
}
int requestNotStart(errorLib::errorH& c)
{
   return 0;
}
int main(int argc, char **argv)
{
  errorLib::errorH c("For starting/ending", 2);
  requestStart(c);
  requestNotStart(c);
  ros::init(argc, argv, "<node_name>");
  ros::NodeHandle nh;
  std::map<std::string, int> NodeToErrorCode =
    {{"rosout", 1},
     {"<Node1>", 2},
     {"<Node2>", 3}};

  ros::Subscriber sub = nh.subscribe("diagnostics", 1000, diagnosticCallback);
  ros::spin();
  return 0;
}

Following are the errors for reference -

In function ‘void diagnosticCallback(const DiagnosticArrayPtr&)’:
/home/default_ws/src/err_pack/src/errors_node.cpp:52:21: error: invalid use of ‘boost::detail::sp_array_access<diagnostic_msgs::DiagnosticArray_<std::allocator<void> > >::type {aka void}’
     if (diags_msg[0].level == diagnostic_msgs::DiagnosticStatus::ERROR)
                     ^
/home/default_ws/src/err_pack/src/errors_node.cpp:54:7: error: ‘errorcode’ was not declared in this scope
       errorcode = NodeToErrorCode[diags_msg[0].name];
       ^
/home/default_ws/src/err_pack/src/errors_node.cpp:54:19: error: ‘NodeToErrorCode’ was not declared in this scope
       errorcode = NodeToErrorCode[diags_msg[0].name];
                   ^
/home/default_ws/src/err_pack/src/errors_node.cpp:54:47: error: invalid use of ‘boost::detail::sp_array_access<diagnostic_msgs::DiagnosticArray_<std::allocator<void> > >::type {aka void}’
       errorcode = NodeToErrorCode[diags_msg[0].name];
                                               ^
/home/default_ws/src/err_pack/src/errors_node.cpp:55:18: error: ‘requestStart’ was not declared in this scope
       requestStart();
                  ^
/home/default_ws/src/err_pack/src/errors_node.cpp:58:26: error: invalid use of ‘boost::detail::sp_array_access<diagnostic_msgs::DiagnosticArray_<std::allocator<void> > >::type {aka void}’
     else if (diags_msg[0].level == diagnostic_msgs::DiagnosticStatus::OK)
                          ^
/home/default_ws/src/err_pack/src/errors_node.cpp:59:47: error: invalid use of ‘boost::detail::sp_array_access<diagnostic_msgs::DiagnosticArray_<std::allocator<void> > >::type {aka void}’
       errorcode = NodeToErrorCode[diags_msg[0].name];
                                               ^
/home/default_ws/src/err_pack/src/errors_node.cpp:60:21: error: ‘requestNotStart’ was not declared in this scope
       requestNotStart();
                     ^
/home/default_ws/src/err_pack/src/errors_node.cpp: In function ‘int requestStart(errorLib::errorH&)’:
/home/default_ws/src/err_pack/src/errors_node.cpp: In function ‘int main(int, char**)’:
/home/default_ws/src/err_pack/src/errors_node.cpp:93:53: error: no matching function for call to ‘errorLib::errorH::errorH(const char [21], int)’
   errorLib::errorH c("For starting/ending", 2);
                                                     ^
/home/default_ws/src/err_pack/src/errors_node.cpp:93:53: note: candidates are:
/home/default_ws/src/err_pack/src/errors_node.cpp:21:7: note: errorLib::errorH::errorH(EC, std::string, int)
       errorH(EC value, string ...
(more)
2017-11-10 09:07:38 -0500 commented answer catkin_make errors while subscribing to diagnostic topic

Thank you @gvdhoorn for specifying each errors. I understand, I should have posted it in a more specific way. I was able

2017-11-10 04:04:13 -0500 received badge  Popular Question (source)
2017-11-09 15:41:14 -0500 edited question catkin_make errors while subscribing to diagnostic topic

catkin_make errors while subscribing to diagnostic topic I am trying to subscribe to diagnostic topic and based on the l

2017-11-09 15:40:42 -0500 edited question catkin_make errors while subscribing to diagnostic topic

catkin_make errors while subscribing to diagnostic topic I am trying to subscribe to diagnostic topic and based on the l

2017-11-09 15:39:40 -0500 edited question catkin_make errors while subscribing to diagnostic topic

catkin_make errors while subscribing to diagnostic topic I am trying to subscribe to diagnostic topic and based on the l

2017-11-09 15:38:18 -0500 asked a question catkin_make errors while subscribing to diagnostic topic

catkin_make errors while subscribing to diagnostic topic I am trying to subscribe to diagnostic topic and based on the l

2017-10-31 08:56:11 -0500 received badge  Famous Question (source)
2017-10-30 09:41:32 -0500 asked a question cmake execute_process command

cmake execute_process command I have created a /csv and /scripts directories in my /src directory. The /csv directory co

2017-10-27 13:58:40 -0500 received badge  Notable Question (source)
2017-10-27 10:54:43 -0500 marked best answer Generic path to read a file in a ROS directory

I have created a /csv and /scripts directories in my /src directory. The /csv directory contains a csv file and /scripts directory contains a Python script to parse the csv file. The first few lines of the script is as follows -

import csv
with open('/home//default_ws/src/<package_name>/csv/alarms.csv', 'rb') as csvfile:
    reader = csv.reader(csvfile)
    for row in reader:

How can I add a generic location path for the csv file in my Python script? And what modifications do I need to make in my CMakelists.txt in order to install the /csv and /scripts directories?

* CORRECT ANSWER *

import csv
import os, rospkg
rospack = rospkg.RosPack()
with open(os.path.join(rospack.get_path("package_name"), "csv", "alarms.csv"), 'rb') as csvfile:
    reader = csv.reader(csvfile)
    for row in reader:
2017-10-27 10:44:07 -0500 received badge  Student (source)
2017-10-27 10:26:11 -0500 commented answer Generic path to read a file in a ROS directory

It works! Thank you @gvdhoorn

2017-10-27 10:11:32 -0500 edited question Generic path to read a file in a ROS directory

Generic path to read a file in a ROS directory I have created a /csv and /scripts directories in my /src directory. The