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

jpde.lopes's profile - activity

2021-06-07 21:26:27 -0500 received badge  Nice Question (source)
2021-01-07 11:29:54 -0500 marked best answer How can I access NodeHandle w/ Nodelets?

Hi,

I have the following Nodelet onInit:

void OD::onInit()
{
    ros::NodeHandle& private_nh = getPrivateNodeHandle();
    ros::NodeHandle& nh = getNodeHandle();
    NODELET_DEBUG("Initialized the Nodelet (OD)");
    odom_sub        = nh.subscribe("/base_odometry/odom", 10, &OD::odomCallback, this);
}

Where I have declared a nodeHandle and a privateNodeHandle. If I understood correctly, a good rule of thumb is to use the nodeHandle with Topics and the Private one with Parameters.

Well, on the odomCallback, I want check if nh.ok() or if private_nh.ok(), as well as private_nh.param<float>("uav_sphere_scale", scale, 1);, but none of this work and give the error:

error: ‘nh’ was not declared in this scope
(...)
error: ‘private_nh’ was not declared in this scope
private_nh.param<float>("uav_sphere_scale", scale, 1);

On my class, OD, the onInit was declared as public and the odomCallback as protected.

My question is, how can I access, either the NodeHandle, or the PrivateNodeHandle on my callback function?

EDIT: I already tried to declare the NodeHandlers a-priori:

namespace nodelet_obstacle_detector

{ class OD : public nodelet::Nodelet { public: virtual void onInit(); ros::NodeHandle& private_nh; ros::NodeHandle& nh;

But it shows the following error when I compile:

/home/(...)/nodelet_obstacle_detector.h:49:11: error: uninitialized reference member in ‘class nodelet_obstacle_detector::OD’
 class OD : public nodelet::Nodelet
       ^
/home/(...)/nodelet_obstacle_detector.h:54:30: note: ‘ros::NodeHandle& nodelet_obstacle_detector::OD::nh’ should be initialized
         ros::NodeHandle& nh;

Thank you in advance.

2020-11-13 03:44:33 -0500 received badge  Student (source)
2020-02-27 12:15:47 -0500 marked best answer LaserScan from bag causing Error: "Lookup would require extrapolation into the past."

Hello,

I am trying to convert a LaserScan message from a bag. On my header file, I have the following:

#include <ros/ros.h>
#include <tf/transform_listener.h>
#include "sensor_msgs/LaserScan.h"
#include "sensor_msgs/PointCloud.h"
#include <laser_geometry/laser_geometry.h>

class laserScan2PC   {
public:

ros::NodeHandle nh_;
ros::Subscriber scan_sub_;
ros::Publisher cloud_pub_;
tf::TransformListener listener;
tf::StampedTransform transform;
laser_geometry::LaserProjection projector_;
sensor_msgs::PointCloud2 cloud;
laserScan2PC(ros::NodeHandle nh_);

void scanCallback (const sensor_msgs::LaserScan::ConstPtr& scan_in);
};

And on the .cpp file:

#include "../include/PrecisionAgriculture/laserScan2PC.h"

laserScan2PC ::laserScan2PC(ros::NodeHandle nh) : nh_(nh){
// http://wiki.ros.org/tf/Tutorials/Writing%20a%20tf%20listener%20(C%2B%2B)
scan_sub_  = nh.subscribe("/base_scan/scan", 1000, &laserScan2PC::scanCallback, this);
cloud_pub_ = nh.advertise<sensor_msgs::PointCloud2>("/pt_cloud", 1);

}

void laserScan2PC :: scanCallback(const sensor_msgs::LaserScan::ConstPtr& scan_in)
{

    // http://wiki.ros.org/laser_geometry
    if(!listener.waitForTransform(scan_in->header.frame_id, "/base_link",scan_in->header.stamp + ros::Duration().fromSec(scan_in->ranges.size()*scan_in->time_increment),ros::Duration(2.0)))
    {
         ROS_ERROR("Unable to transform");
    }
    else
    {
        projector_.transformLaserScanToPointCloud("/base_link", *scan_in, cloud, listener);
    }
    cloud_pub_.publish(cloud);
}

The problem is that after having the following error messages (caused by the LookupTransform):

[ERROR] [1521684287.419099514]: Unable to transform
[ERROR] [1521684289.429183124]: Unable to transform
(...)
[ERROR] [1521684303.469321561]: Unable to transform
[ERROR] [1521684305.470800803]: Unable to transform

I get the following error:

terminate called after throwing an instance of 'tf2::ExtrapolationException'
  what():  Lookup would require extrapolation into the past.  Requested time 1357578703.109095188 but the earliest data is at time 1357578703.124125818, when looking up transform from frame [base_scan_link] to frame [base_link]
[laserScan2PC-2] process has died [pid 7674, exit code -6, (...)

Which is caused by the projector_.

I have tried to use ros::Time(0) or ros::Time::now() instead of the scan_in->header.stamp.

I think this is related to the fact that the stamp of the laser scan is not in agreement with the transform stamp, but I couldn't find a solution so far.

Finally, I am using the commands below before I play the bag:

rosparam use_sim_time_true
rosbag play --clock <nameOfTheBag>

Any hints on how to solve the error? Thank you in advance!

EDIT:

I have tried to use try/catch to avoid the exception but the problem remains unsolved, only avoiding the crashing of the program. Something like this:

ros::Time time;

try {
    time = scan_in->header.stamp + ros::Duration().fromSec(scan_in->ranges.size()*scan_in->time_increment);

    if(!listener.waitForTransform("/base_link", "/servo_link", time, ros::Duration(1.0)))
    {
        ROS_ERROR("Unable to transform");
        return;
    }
    projector_.transformLaserScanToPointCloud("/base_link", *scan_in, cloud, listener);
    ROS_INFO("Transform Retrieved!");
}
catch (tf::TransformException &ex) {
    ROS_ERROR("%s", ex.what());
    ros::Duration(1.0).sleep();
}

Which causes the output depicted below:

[ERROR] [1521729232.549585422]: Unable to transform
(...)
[ERROR] [1521729243.626700137]: Unable to transform
[ERROR] [1521729244.632651396]: Unable to transform
[ERROR] [1521729244.633163741]: Lookup would require extrapolation into the past.  Requested time 1357578703.149084276 but the earliest data is at time 1357578703.164612891, when looking up transform from frame [base_scan_link] to frame [base_link]
[ INFO] [1521729245.633830180]: Transform Retrieved!
[ INFO] [1521729245.634297009]: Transform Retrieved!
(...)
[ INFO] [1521729245.669169912]: Transform ...
(more)
2019-05-09 00:48:08 -0500 received badge  Notable Question (source)
2019-05-09 00:48:08 -0500 received badge  Popular Question (source)
2019-05-09 00:48:08 -0500 received badge  Famous Question (source)
2019-03-24 13:08:42 -0500 received badge  Famous Question (source)
2019-02-06 11:49:00 -0500 received badge  Famous Question (source)
2019-01-11 12:40:03 -0500 marked best answer How to receive Octree?

Hello,

I am currently creating an Octomap through the Octomap Server. What I want to do next is to receive the octree for detecting obstacles while the octomap is being created. I've tried this:

    octomap::OcTree* octree = NULL;
    serv_name = "/octomap_binary";

    while((nh_.ok() && !ros::service::call(serv_name, req, resp)) || resp.map.data.size()==0)
    {
        ROS_WARN("Request to %s failed; trying again...", nh_.resolveName(serv_name).c_str());
        usleep(1000000);
    }

    //Receive Octree
    msg_octree = octomap_msgs::msgToMap(resp.map);

    if (msg_octree)
        //Create object of type octomap::OcTree*
        octree = dynamic_cast<octomap::OcTree*>(msg_octree);
    if (octree)
    {
        ROS_INFO("%s: Octomap received %zu nodes, %f m of resolution", ros::this_node::getName().c_str(), octree->size(), octree->getResolution());
        tree_fcl = (new fcl::OcTree(std::shared_ptr<const octomap::OcTree>(octree)));
    } else
        ROS_ERROR("Error reading OcTree from stream");

Which works! This piece of code is inside a callback which loops with ros::spinOnce(). As this is the way it is done inside the octomap_server files, is it the best way for me to receive the Octree? Because while the vehicle is scanning the environment, the map keeps increasing, to the point where I am receiving more than 2 million nodes at once!!!.

Instead of updating the current Octree, I am receiving the whole Octree every time it loops through that code, right? My problem is that the code starts getting really slow. Is there a better way for me to receive the octree where I keep updating it instead of receiving all of it every time (with 2+ million nodes)?

Thank you in advance.

2018-11-24 16:36:04 -0500 received badge  Famous Question (source)
2018-11-15 22:18:19 -0500 received badge  Notable Question (source)
2018-11-08 03:17:19 -0500 received badge  Famous Question (source)
2018-10-22 11:15:31 -0500 commented answer Robot Localization Package: Transform was unavailable for the time requested. Using latest instead.

The reason why I have removed the Z measurement was because it was really unstable, going up and down, and I didnt know

2018-10-22 11:12:34 -0500 commented answer Robot Localization Package: Transform was unavailable for the time requested. Using latest instead.

Thank you very much for your reply. Instead of IMU and GPS, would adding an extra IMU help? Or is the optical flow prefe

2018-10-22 11:12:15 -0500 commented answer Robot Localization Package: Transform was unavailable for the time requested. Using latest instead.

I am currently not with the IMU and GPS setup to test, but on Wednesday, I will perform new tests having your answer in

2018-10-22 11:10:40 -0500 commented answer Robot Localization Package: Transform was unavailable for the time requested. Using latest instead.

Thank you very much for your reply. Instead of IMU and GPS, would adding an extra IMU help? Or is the optical flow prefe

2018-10-12 16:19:42 -0500 received badge  Famous Question (source)
2018-10-10 16:13:07 -0500 received badge  Famous Question (source)
2018-10-09 12:08:13 -0500 received badge  Notable Question (source)
2018-10-03 14:58:34 -0500 received badge  Notable Question (source)
2018-09-19 13:17:27 -0500 received badge  Notable Question (source)
2018-09-17 11:06:35 -0500 received badge  Popular Question (source)
2018-09-11 07:10:35 -0500 received badge  Popular Question (source)
2018-09-11 00:44:29 -0500 edited question Hector Quadrotor Demo: Take Off Not Working.

Hector Quadrotor Demo: Take Off Not Working. Hello, I am trying to use the hector_quadrotor_demo, but the UAV is not ta

2018-09-10 22:25:07 -0500 edited question Hector Quadrotor Demo: Take Off Not Working.

Hector Quadrotor Demo: Take Off Not Working. Hello, I am trying to use the hector_quadrotor_demo, but the UAV is not ta

2018-09-10 21:56:05 -0500 asked a question Hector Quadrotor Demo: Take Off Not Working.

Hector Quadrotor Demo: Take Off Not Working. Hello, I am trying to use the hector_quadrotor_demo, but the UAV is not ta

2018-09-10 04:41:39 -0500 received badge  Popular Question (source)
2018-09-10 02:47:21 -0500 edited question Robot Localization Package: Transform was unavailable for the time requested. Using latest instead.

Robot Localization Package: Transform was unavailable for the time requested. Using latest instead. Hello, I am using an

2018-09-10 02:09:49 -0500 edited question Robot Localization Package: Transform was unavailable for the time requested. Using latest instead.

Robot Localization Package: Transform was unavailable for the time requested. Using latest instead. Hello, I am using an

2018-09-09 21:39:47 -0500 edited question Robot Localization Package: Transform was unavailable for the time requested. Using latest instead.

Robot Localization Package: Transform was unavailable for the time requested. Using latest instead. Hello, I am using an

2018-09-09 19:59:59 -0500 edited question Robot Localization Package: Transform was unavailable for the time requested. Using latest instead.

Robot Localization Package: Transform was unavailable for the time requested. Using latest instead. Hello, I am using an

2018-09-09 19:57:46 -0500 edited question Robot Localization Package: Transform was unavailable for the time requested. Using latest instead.

Robot Localization Package: Transform was unavailable for the time requested. Using latest instead. Hello, I am using an

2018-09-09 19:56:44 -0500 edited question Robot Localization Package: Transform was unavailable for the time requested. Using latest instead.

Robot Localization Package: Transform was unavailable for the time requested. Using latest instead. Hello, I am using an

2018-09-09 19:39:04 -0500 commented question Robot Localization Package: Transform from base_link to odom was unavailable for the time requested. Using latest instead. (IMU+GPS)

I have created another question w/ more significant data.

2018-09-09 19:38:55 -0500 commented answer Robot Localization Package: Transform from base_link to odom was unavailable for the time requested. Using latest instead. (IMU+GPS)

I have created another question w/ more significant data.

2018-09-09 19:35:59 -0500 asked a question Robot Localization Package: Transform was unavailable for the time requested. Using latest instead.

Robot Localization Package: Transform was unavailable for the time requested. Using latest instead. Hello, I am using an

2018-09-05 20:24:34 -0500 commented answer Robot Localization Package: Transform from base_link to odom was unavailable for the time requested. Using latest instead. (IMU+GPS)

Thank you for your answer. I have updated my question with a sample of the sensors.

2018-09-05 20:22:51 -0500 commented question Robot Localization Package: Transform from base_link to odom was unavailable for the time requested. Using latest instead. (IMU+GPS)

Hi, I have tried it. The rate remains the same.

2018-09-05 20:19:15 -0500 edited question Robot Localization Package: Transform from base_link to odom was unavailable for the time requested. Using latest instead. (IMU+GPS)

Robot Localization Package: Transform from base_link to odom was unavailable for the time requested. Using latest instea

2018-09-02 21:00:42 -0500 received badge  Famous Question (source)
2018-08-27 04:26:41 -0500 received badge  Notable Question (source)
2018-08-25 03:27:34 -0500 asked a question How to filter ground w/ Octomap leaf iterator?

How to filter ground w/ Octomap leaf iterator? Hello, I know that it is possible to filter ground using the RANSAC meth

2018-08-21 02:32:33 -0500 asked a question Problem w/ Robot Localization Package (x,y,z): IMU & GPS.

Problem w/ Robot Localization Package (x,y,z): IMU & GPS. Hello, I am using the robot localization package togethe

2018-08-17 21:05:40 -0500 received badge  Popular Question (source)
2018-08-15 12:47:31 -0500 commented question Robot Localization Package: Transform from base_link to odom was unavailable for the time requested. Using latest instead. (IMU+GPS)

That is what I thought as well (that is very slow). Thank you for the presented solution. I will try it.

2018-08-13 15:54:28 -0500 commented question Robot Localization Package: Transform from base_link to odom was unavailable for the time requested. Using latest instead. (IMU+GPS)

Everything seems fine with the frames. Sometimes I notice that the frequency drops from approximately 2Hz to 0.002Hz or

2018-08-13 13:28:25 -0500 commented question Robot Localization Package: Transform from base_link to odom was unavailable for the time requested. Using latest instead. (IMU+GPS)

I'll check that (view_frames) and will give feedback.

2018-08-13 13:25:58 -0500 commented question Robot Localization Package: Transform from base_link to odom was unavailable for the time requested. Using latest instead. (IMU+GPS)

On my case, I've used 10Hz, but if I reduce it to 3Hz, for example, I see much less of those TF warnings.

2018-08-13 13:24:58 -0500 commented question Robot Localization Package: Transform from base_link to odom was unavailable for the time requested. Using latest instead. (IMU+GPS)

Thank you for your answer @autonomy. Yes, I tried to run hz on the original topics. Both the IMU and GPS are around 2Hz.