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

Mandar's profile - activity

2018-04-17 06:02:59 -0500 received badge  Taxonomist
2016-08-04 04:05:09 -0500 received badge  Good Question (source)
2015-08-10 09:27:48 -0500 received badge  Nice Question (source)
2014-06-27 07:23:37 -0500 received badge  Famous Question (source)
2014-04-07 05:04:47 -0500 received badge  Famous Question (source)
2014-03-24 03:57:47 -0500 received badge  Notable Question (source)
2014-02-25 21:23:12 -0500 received badge  Enthusiast
2014-02-17 03:30:54 -0500 received badge  Popular Question (source)
2014-02-17 03:26:58 -0500 commented question roscpp and valgrind: memory leaks

Sorry, I guess I had some left-over statements that I didn't snip out properly while copying here. But I removed the `close(sd)` and `return status` commands, made a new package & ran it. I get the same leaks. Can't/Shouldn't really change to ubuntu12.10 right now. Guess it's valgrind 3.7

2014-02-17 01:24:56 -0500 commented question roscpp and valgrind: memory leaks

Well I'm on the latest one for Ubuntu 12.04 - running valgrind-3.7.0

2014-02-17 00:09:51 -0500 received badge  Editor (source)
2014-02-16 22:58:55 -0500 asked a question roscpp and valgrind: memory leaks

I've been building and testing a program that reads the serial port and the publishes some data off to a topic. Now in the course of checking memory leaks, I realized that just declaring a Publisher or Timer gives rise to memory leaks of the type 'possibly lost'. Here's the basic code I have. It does nothing:

int main(int argc, char **argv)
{ 
  std::string node_name = "node";
  std::string pub_type;   
  std::string init_time;
  ros::init(argc, argv,"talker");  
  ros::Timer timer2;
  ros::Publisher pubsensID;
  ros::Publisher chatter_pub[10] = {};   
  ros::NodeHandle n;
  pubsensID = n.advertise<std_msgs::String>("SensorIDs", 1000);
  std::cout<<"Publisher service started with this configuration: "<<endl;
  std::cout<<"\t#Node name:             "<< node_name <<endl;
  ros::shutdown();
  close(sd);
  return status;

}

If I comment out the lines declaring the ros::Timer and ros::Publisher I get a clean output from Valgrind. If not, then I get this: [EDIT: Reran it with -leak-check=full option as suggested by @ahendrix]

HEAP SUMMARY:
    in use at exit: 1,421 bytes in 43 blocks
  total heap usage: 2,877 allocs, 2,834 frees, 137,330 bytes allocated

16 bytes in 1 blocks are possibly lost in loss record 11 of 39
   at 0x402B9B4: operator new(unsigned int) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
   by 0x44027D3: std::string::_Rep::_S_create(unsigned int, unsigned int, std::allocator<char> const&) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
   by 0x146B003: ???

16 bytes in 1 blocks are possibly lost in loss record 12 of 39
   at 0x402B9B4: operator new(unsigned int) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
   by 0x44027D3: std::string::_Rep::_S_create(unsigned int, unsigned int, std::allocator<char> const&) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
   by 0x4404A47: char* std::string::_S_construct<char const*>(char const*, char const*, std::allocator<char> const&, std::forward_iterator_tag) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
   by 0x4404BB5: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
   by 0x474B805: log4cxx::Level::getAll() (in /usr/lib/liblog4cxx.so.10.0.0)
   by 0x474171D: log4cxx::Hierarchy::Hierarchy() (in /usr/lib/liblog4cxx.so.10.0.0)
   by 0x380170BF: ??? (in /usr/lib/valgrind/memcheck-x86-linux)

17 bytes in 1 blocks are possibly lost in loss record 13 of 39
   at 0x402B9B4: operator new(unsigned int) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
   by 0x44027D3: std::string::_Rep::_S_create(unsigned int, unsigned int, std::allocator<char> const&) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
   by 0x4404A47: char* std::string::_S_construct<char const*>(char const*, char const*, std::allocator<char> const&, std::forward_iterator_tag) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
   by 0x4404BB5: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
   by 0x474BDA5: log4cxx::Level::getInfo() (in /usr/lib/liblog4cxx.so.10.0.0)
   by 0x4641D30: __static_initialization_and_destruction_0(int, int) (in /home/mharshe/ros/core/devel/lib/librosconsole ...
(more)
2014-02-03 04:27:59 -0500 received badge  Famous Question (source)
2014-01-24 02:39:45 -0500 commented answer boost::bind errors in subscriber callback functions

Wow, that was simple to fix. I wonder which method would be better to use - this answer or using classes as suggested by @Wolf.

2014-01-24 01:47:04 -0500 received badge  Notable Question (source)
2014-01-24 01:34:20 -0500 commented answer boost::bind errors in subscriber callback functions

I modified the example code you provided to follow the tutorial http://wiki.ros.org/roscpp_tutorials/Tutorials/UsingClassMethodsAsCallbacks more closely. This way, only the function write_enocean and the topic_name were in the class, while the subscriber was defined outside, rather than class method

2014-01-24 01:01:29 -0500 commented question boost::bind errors in subscriber callback functions

I'm not sure I understand what you mean. Do I use it something like boost::function(bind, ...) or? I've not really used boost before, hence the confusion.

2014-01-24 01:00:01 -0500 received badge  Popular Question (source)
2014-01-24 00:30:13 -0500 commented answer boost::bind errors in subscriber callback functions

I'll try this out and report back in case of errors. Thanks!

2014-01-24 00:28:44 -0500 received badge  Supporter (source)
2014-01-23 21:56:59 -0500 asked a question boost::bind errors in subscriber callback functions

Hey, Kind of newbie in using boost, and this is driving me crazy. I wanted to pass on the topicname to the callback function of subscriber, so I followed the various questions already asked and wrote the following: My callback function:

void write_enocean(const palgate_madynes_msg::EnOceanFrame& msg,std::string topic)

Subscriber:

sub[i] = nh.subscribe(Topiclist[i].name,1000,boost::bind(&write_enocean,_1,Topicname[i].name));

If I do this, I get the following error:

error: no matching function for call to ‘ros::NodeHandle::subscribe(std::string&, int, boost::_bi::bind_t<void, void (*)(const palgate_madynes_msg::EnOceanFrame_<std::allocator<void> >&, std::basic_string<char>), boost::_bi::list2<boost::arg<1>, boost::_bi::value<std::basic_string<char> > > >*)’

followed by the various candidates, and then:

node_handle.h:785:14: note:   candidate expects 1 argument, 3 provided

On the other hand, if write the subscriber as such:

 sub[i] = nh.subscribe<palgate_madynes_msg::EnOceanFrame>(Topiclist[i].name,1000,boost::bind(&write_enocean,_1,test));

I get the error:

/usr/include/boost/bind/bind.hpp:313:9: error: invalid initialization of reference of type ‘const palgate_madynes_msg::EnOceanFrame_<std::allocator<void> >&’ from expression of type ‘const boost::shared_ptr<const palgate_madynes_msg::EnOceanFrame_<std::allocator<void> > >’

What am I doing wrong with boost? My CMakeLists.text already includes the rosbuild_add_boost_directories() but gives me an error if write rosbuild_link_boost(topic_listener bind) saying it could not locate bind.

2014-01-22 03:59:05 -0500 received badge  Nice Answer (source)
2014-01-21 21:37:10 -0500 received badge  Scholar (source)
2014-01-21 11:42:37 -0500 received badge  Teacher (source)
2014-01-21 11:42:37 -0500 received badge  Self-Learner (source)
2014-01-21 11:37:07 -0500 received badge  Notable Question (source)
2014-01-20 23:18:27 -0500 answered a question Python Multiprocessing to publish to multiple topics

I managed to solve this problem (Note to self: Read the python docs). Turns out that a new process thread creates a copy of all the data from the parent, and I had not taken care of this properly.

The way I solved it was thus: I called the Popen (listen_stat in this case) from the device method get_status:

 def get_status(self):
    varnum = 0  # for testing only
    while not rospy.is_shutdown():
       self.response_line = self.listen_stat.stdout.readline().split()
       self.new_detect.value = int(self.response_line[varnum])

The important detail was declaring the variable new_detect as a multiprocessing.Value() and then calling this function instead for the multiprocess.

stat_procs = []
for device in device_props:
    sp = multiprocessing.Process(target=device.get_status)
    stat_procs.append(sp)
    sp.start()

The actual publisher then was just called in a normal loop:

try:
    while not rospy.is_shutdown():
        for device in device_props:
            device.device_talker()
except (KeyboardInterrupt,rospy.ROSInterruptException,IOError) as e:
    for p in stat_procs:
       p.join()

Hope this helps the others.

2014-01-20 15:06:23 -0500 received badge  Nice Question (source)
2014-01-20 09:31:25 -0500 received badge  Student (source)
2014-01-20 07:20:36 -0500 received badge  Popular Question (source)
2014-01-20 01:52:46 -0500 commented question Python Multiprocessing to publish to multiple topics

I realize that I may be using the multiprocessing module wrong to share variables (the publisher for instance). It would be helpful if someone could suggest a way to fix that.

2014-01-19 23:21:42 -0500 asked a question Python Multiprocessing to publish to multiple topics

I currently have a setup where I have about 10 shell scripts that listen to 10 different KNX addresses (using the shell command grouplisten) and publish their state to a ROS topic. These scripts can run in the background, so it's quite convenient to 'listen' to the state of these devices.

I tried to replace these 10 scripts with a single python program that basically does this:

  1. Declare a subprocess.Popen for each device, to listen to its knx device.

    self.listen_stat = subprocess.Popen(self.cmds,stdout=subprocess.PIPE,preexec_fn=os.setsid)
    
  2. Declare the node (in __main__) , and topic for each device ( in device.__init__()).

    class DeviceProp:
    def __init__(self):
      ...
      self.pub = rospy.Publisher(self.name,Int32,latch=True)
    
  3. Call a talker function like so:
try:
  for device in device_props:
       p = multiprocessing.Process(target=device.device_talker)
       procs.append(p)
       p.start()
except (KeyboardInterrupt,rospy.ROSInterruptException,IOError) as e:
    for p in procs:
       p.join()

(The device_talker basically just publishes new data to device.pub)

What happens is that the logs suggest data is being published, but I don't see anything on when I subscribe to those topics or if I do rostopic echo. If I run rostopic pub from a new shell, I get the data on the topic as expected. I've also added a rospy.sleep(1) at multiple places (in loops too) so that even if I lose the first few messages, I _should_ get the later ones. But I don't.

Any suggestions on what I should do? (In case you are wondering why - I want to replace 10 scripts with 1 for easier code management. Also, Since I can store all address and device props in a yaml file, it will be trivial to add, or edit the configuration file).