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

solb22's profile - activity

2018-12-05 13:31:28 -0500 received badge  Notable Question (source)
2018-12-05 13:31:28 -0500 received badge  Popular Question (source)
2017-11-14 07:52:28 -0500 received badge  Student (source)
2017-05-08 00:56:45 -0500 received badge  Famous Question (source)
2017-01-15 13:55:41 -0500 received badge  Famous Question (source)
2016-09-24 00:10:25 -0500 asked a question Roslibjs publish topic error

I set up the roslibjs exactly as the tutorial suggets, and subscribing is working great ( I am able to connect to the websocket, etc). However, whenever I try to publish I get an error in the rosbridge websocket below:

[ERROR] [15.500000] [/rosbridge_websocket]: [Client 7] [id: publish:/cmd_vel:2] publish: 'type'

I am using the indigo release of ROS & Ubuntu 14.04, and the current version of both eventransmitter & roslibjs from the CDN Here is the link:http://wiki.ros.org/roslibjs/Tutorials/BasicRosFunctionality

2016-09-24 00:09:46 -0500 received badge  Notable Question (source)
2016-05-31 09:23:18 -0500 received badge  Famous Question (source)
2016-02-21 05:02:04 -0500 commented answer roscpp Callback Thread Safety SEGFAULT

I don't see an unsubscribe member function on ros::Subscriber. I only see shutdown

2016-02-20 18:01:45 -0500 commented answer roscpp Callback Thread Safety SEGFAULT

I posted the error from gdb, Ill post the full stacktrace. I'm create a new nodehandle for each topic, and then calling shutdown(). Is that not allowed? I wasn't aware of how to use only one nodehandle for the entire node and unsubscribe from a particular topic

2016-02-20 18:00:08 -0500 received badge  Popular Question (source)
2016-02-20 01:59:00 -0500 received badge  Editor (source)
2016-02-19 23:56:55 -0500 asked a question roscpp Callback Thread Safety SEGFAULT

I'm currently subscribing to every topic ever published in my program via ShapeShifter, and deserializing as necessary. This works great, but I'm receiving SEGFAULTs when using ros::AsyncSpinner. I'm essentially trying to create a live rqt_graph, which monitors latency between sent and received messages.

Why is the below not threadsafe? From my console, it looks like the shared::ptr to Shapeshifter msg within my callback get changed on me without me finishing the callback. Is it not safe to pass shared::ptr to ROS callback threads?

ERROR MESSAGE

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffea7fc700 (LWP 31281)]
__memcpy_sse2_unaligned () at ../sysdeps/x86_64/multiarch/memcpy-sse2-unaligned.S:79
79  ../sysdeps/x86_64/multiarch/memcpy-sse2-unaligned.S: No such file or directory.

MAIN

int main(int argc, char* argv[])
{
  ros::init(argc, argv, "performance_tracker_node");

  ros::AsyncSpinner spinner(4);
  spinner.start();

  // Loop on the main thread and search for new topics being published
  // If the topic caught doesn't exist in our Node list yet, add it
  while(ros::ok()){
       //Code that finds new topics not included
                PerformanceTracker newNode = PerformanceTracker(info.name);
                performanceNodes.insert(std::pair<std::string, PerformanceTracker>(info.name, newNode));
     }
      ros::waitForShutdown;
}

Performance Tracker Constructor

PerformanceTracker::PerformanceTracker(std::string topicName):
_topicName(topicName)
 {
   ros::NodeHandle nh("~");
  _nh = nh;
  // Subscribe To Generic Message 
 _sub =  _nh.subscribe( _topicName, 10, &PerformanceTracker::topicCallback, this);
}

Performance Tracker Callback

void PerformanceTracker::topicCallback(const boost::shared_ptr<topic_tools::ShapeShifter> msg){
//Current Time
ros::Time begin = ros::Time::now();

    //Prevent OOB error by only checking msgs that are at least the size of a header msg 
    if(msg->size() >= sizeof(std_msgs::Header)){
        //Deserialize message
        std_msgs::Header header;
        uint8_t buf[msg->size()];
        ros::serialization::OStream stream(buf, msg->size());
        msg->write(stream);
        header.seq = ((uint32_t *)buf)[0];
        header.stamp.sec = ((int32_t *)buf)[1];
        header.stamp.nsec = ((int32_t *)buf)[2];

        // Delays greater than 1 hour are clearly wrong., and the header doesn't exist, so skip this
        double lagTime = (begin-header.stamp).toSec();
        if(lagTime > 3600){
            // Skip this topic in the future
            std::cout << "Topic " << _topicName <<  " sent at " <<  header.stamp << " returned nonsense time for " << lagTime <<  " seconds" << std::endl;
            _nh.shutdown();
        }
       //if delayed, then log time lag
        else if(lagTime > 1){
            std::cout << "Topic " << _topicName <<  " sent at " <<  header.stamp << " delayed for" << lagTime <<  " seconds" << std::endl;
        }
    }
     // Remove topic for future if topic message type is too small 
    else{
        // Skip this topic in the future
        std::cout << "Topic " << _topicName <<  " message size was smaller than just a std::msg Header, and likely did not have a header "<< std::endl;
        _nh.shutdown();
    }
 }
2016-02-16 23:27:17 -0500 received badge  Notable Question (source)
2016-02-16 08:29:55 -0500 received badge  Popular Question (source)
2016-02-16 03:09:35 -0500 commented answer One Thread Per Subscriber

Hm, I guess it does, is there a limit to the number of thread I can pass to that? The documentation made it look like I was limited to the number of cores on my machine. I was actually looking at ros::AsyncSpinner

2016-02-16 01:59:21 -0500 asked a question One Thread Per Subscriber

I'm using roscpp, and I am programmatically creating a bunch of subscriber callbacks (using ShapeShifter). Each callback is not computationally expensive, but I'm measuring the difference between the published time in the header, and the received time. As such, the first line of my callback defines the received time.

So having a single threaded model isn't great, because one subscriber callback will block another callback, and increase its lag time.

Ideally I'd like to create one thread per subscriber. I can't use a custom callback queue, because these are not called by ros::spin.

So what is the most idiomatic way to have each subscriber run on its own thread?

2016-02-16 01:33:32 -0500 received badge  Enthusiast
2016-02-13 02:35:30 -0500 answered a question Error when subscribing to ShapeShifter

Adding topic_tools to CMake catkin_depends and find_package, as well and build_depend and run_depend to packages.xml caused this to work. Not sure why, so if someone can comment a more thorough reason that would be great

2016-02-12 23:33:16 -0500 asked a question Error when subscribing to ShapeShifter

I'm attempting to subscribe to ShapeShifter, but I'm getting a bunch of undefined reference errors when trying to compile. What am I missing?

 PerformanceTracker::PerformanceTracker(std::string topicName, ros::NodeHandle nh):
_topicName(topicName),
_nh(nh)
 {
  // Subscribe To Generic Message 
  _sub =  _nh.subscribe( _topicName, 1, &PerformanceTracker::topicCallback, this);
}


void PerformanceTracker::topicCallback(const topic_tools::ShapeShifter& topicType){
//Current Time
  ros::Time begin = ros::Time::now();
  std::cout << "IM ALIVE" << std::endl;
}

CMakeFiles/performance_tracker.dir/src/performance_tracker.cpp.o: In function `ros::SubscriptionCallbackHelperT<topic_tools::ShapeShifter const&, void>::getTypeInfo()':
/opt/ros/indigo/include/ros/subscription_callback_helper.h:150: undefined reference to `typeinfo for topic_tools::ShapeShifter'

CMakeFiles/performance_tracker.dir/src/performance_tracker.cpp.o: In function `boost::detail::sp_if_not_array<topic_tools::ShapeShifter>::type boost::make_shared<topic_tools::ShapeShifter>()':
/usr/include/boost/smart_ptr/make_shared_object.hpp:146: undefined reference to   `topic_tools::ShapeShifter::ShapeShifter()'

CMakeFiles/performance_tracker.dir/src/performance_tracker.cpp.o: In function `ros::serialization::PreDeserialize<topic_tools::ShapeShifter>::notify(ros::serialization::PreDeserializeParams<topic_tools::ShapeShifter> const&)':
/opt/ros/indigo/include/topic_tools/shape_shifter.h:178: undefined reference to  `topic_tools::ShapeShifter::morph(std::string const&, std::string const&, std::string const&, std::string const&)'
collect2: error: ld returned 1 exit status 
make[2]: *** [/ros/devel/lib/performance_tracker/performance_tracker] Error 1
make[1]: *** [CMakeFiles/performance_tracker.dir/all] Error 2
make: *** [all] Error 2
2016-02-12 04:08:26 -0500 commented answer Extract Header from ShapeShifter

One last question. Why in the SFINAE, is it static yes& test(typename C::_header_type); ? What does C::_header_type mean? Type has a data member named _header_type? Does that match the current ros header data member name? And not just plain C::_header*?

2016-02-12 03:35:43 -0500 received badge  Scholar (source)
2016-02-12 03:35:42 -0500 commented answer Extract Header from ShapeShifter

Yeah, I'm going to port that to C++11

2016-02-12 03:26:48 -0500 received badge  Notable Question (source)
2016-02-12 02:51:16 -0500 commented answer Extract Header from ShapeShifter

Ok thanks. Yes the SFINAE is much less clear. Would I just include that file and user timewarp.extractTime() ? Thank you very much for the help !

2016-02-12 01:51:57 -0500 received badge  Popular Question (source)
2016-02-12 01:49:54 -0500 commented answer Extract Header from ShapeShifter

Thanks Stefan, I will try both and get back to you. What do you means the drawback of always serializing messages? Are you saying serializing the messages wastes computation time? I can set the received time to before the serialization starts, so it wont affect the measurement of published-received

2016-02-12 01:46:37 -0500 received badge  Supporter (source)
2016-02-11 19:29:03 -0500 asked a question ShapeShifter extra Header.stamp from generic topic

I'm trying to extract a Header.stamp from a generic topic in roscpp, in order to compare the published time to the received time.

I'm running into a wall on how to extract data from a generic topic at runtime. Rospy has rospy.anymessage, and I know rosbag implements something like this with SubscriptionCallbackHelperT, but I can't figure out how to extract from either the unsigned char* or SubscriptionCallbackHelperT the header.

void PerformanceTracker::topicCallback(const ShapeShifter::ConstPtr topicType){
ros::Time begin = ros::Time::now();
unsigned char* data = ShapeShifterGetData(topicType);
} 

unsigned char* ShapeShifterGetData(const ShapeShifter::ConstPtr message)
{
  unsigned char* data = new unsigned char[message->size()];
  std::OStream stream(data, message->size());
  message->write(stream);
  return data;
}
2016-02-11 19:27:28 -0500 asked a question Extract Header from ShapeShifter

I'm trying to implement something similar to rospy.anymessage via roscpp. I am using Shapeshifter to extract the data. I only need the Header.stamp (I want to compare received time from the time the topic was published).

I'm running into a wall trying to extract the header stamp. I know rosbag imeplement something like this, but I could only find they use SubscriptionCallbackHelperT, but not how.

How can I extract the Header.stamp from a generic ros topic message?

void PerformanceTracker::topicCallback(const ShapeShifter::ConstPtr topicType){
   ros::Time begin = ros::Time::now();
   unsigned char* data = ShapeShifterGetData(topicType);
}

unsigned char* ShapeShifterGetData(const ShapeShifter::ConstPtr message){
  unsigned char* data = new unsigned char[message->size()];
  std::OStream stream(data, message->size());
  message->write(stream);
  return data;
}