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

prasgane's profile - activity

2019-05-20 02:10:09 -0500 marked best answer Question on turtlesim tutorial: Go to Goal

Hello,

I am new to ROS and I am trying to implement the Go to Goal tutorial in C++ (the tutorial itself is in python but wanted to implemented it in C++). The part I am having trouble understanding is, in the function move2goal() there is a while loop who's condition depends on the magnitude of the error between the current pose and goal pose and it is in this loop that the commanded velocity is calculated. I ran the script and it works fine.

When I try to implement the same code in C++ I too have a function, velocity_calc() which has a while loop based on the magnitude error. It is in this loop that I calculate the commanded velocity (same as tutorial). The problem I am facing is, when I call this function in my main() (like they did in the tutorial) the compiler gets stuck in the while loop and is not able to update the current pose ie go to the call back function. I did over come this by replacing the while loop with an if condition in my callback and got it to work. But I am still curious as to why the while loop does not work for me. How is the python script able to update the current pose in the while loop?

turtle_cl.h


#ifndef TURTLECL_H
#define TURTLECL_H
#include <ros ros.h="">
#include <turtlesim pose.h="">
#include <geometry_msgs twist.h="">
#include <math.h>

namespace turtle_cl {   class turtleCL {

  public:
    turtleCL();
    void velocity_calc();



  private:
    ros::NodeHandle nh_;
    ros::NodeHandle nh_private_;

    ros::Subscriber pose_subscriber_;
    ros::Publisher vel_publisher_;

    void poseCallback(const turtlesim::PoseConstPtr &msg);


    turtlesim::Pose current_pose;
    geometry_msgs::Twist cmd_vel;

    float k_p_lin, k_p_ang, tol, goal_x, goal_y, mag;   };

}
#endif

turtle_cl.cpp


#include "turtle_cl/turtlecl.h"

namespace turtle_cl
{
  turtleCL::turtleCL() :
    nh_(ros::NodeHandle()),
    nh_private_(ros::NodeHandle("~"))
  {

    pose_subscriber_ = nh_.subscribe<turtlesim::pose>
                        ("/turtle1/pose",10, &turtleCL::poseCallback, this);

    vel_publisher_ = nh_.advertise<geometry_msgs::twist>
                        ("/turtle1/cmd_vel",10,this);

    nh_private_.param<float>("p_gain_linear",k_p_lin,0.1);
    nh_private_.param<float>("p_gain_ang",k_p_ang,0.1);
    nh_private_.param<float>("tolerance",tol,0.1);
    nh_private_.param<float>("xGoal",goal_x,1);
    nh_private_.param<float>("yGoal",goal_y,1);

  }

  void turtleCL::poseCallback(const turtlesim::PoseConstPtr &msg)
  {
    current_pose = *msg;
    float mag1, mag2;
    mag1 = pow((goal_x - msg->x),2);
    mag2 = pow((goal_y - msg->y),2);
    mag = sqrt(mag1 + mag2);
    // ROS_INFO("in callback");
    // if(mag >= tol)
    //   velocity_calc();

  }

  void turtleCL::velocity_calc()
  {

    //ROS_INFO("in velocity_cal %f",mag);
    while(mag >= tol)
    {
      float velx,angx,angy;
      angx = goal_x - current_pose.x;
      angy = goal_y - current_pose.y;
      cmd_vel.linear.x = k_p_lin * mag;
      cmd_vel.angular.z = k_p_ang * atan2(angy,angx) - current_pose.theta;
      vel_publisher_.publish(cmd_vel);
    }
    //ROS_INFO("in while %f",current_pose.x);

  }

}

turtle_cl_node.cpp


#include <ros ros.h="">
#include <turtle_cl turtlecl.h="">


int main(int argc, char** argv)
{
  ros::init(argc,argv,"turtle_cl_node");
  ros::NodeHandle nh;

  turtle_cl::turtleCL hello;
  hello.velocity_calc();

  ros::spin();
}

2018-01-27 01:48:24 -0500 received badge  Famous Question (source)
2018-01-14 06:42:25 -0500 received badge  Notable Question (source)
2018-01-14 06:42:25 -0500 received badge  Popular Question (source)
2018-01-10 11:12:02 -0500 commented answer CSM Package Not Found

I got an error saying "Could not find a package configuration file provided by "csm" with any of the following names:

2017-12-06 15:06:02 -0500 commented question " ‘selectROI’ was not declared in this scope "

I am on Kinetic and yes, I built it myself.

2017-12-06 12:14:11 -0500 asked a question " ‘selectROI’ was not declared in this scope "

" ‘selectROI’ was not declared in this scope " Hello, I am trying to use OpenCV's object tracker(s) and I am running in

2017-11-23 02:06:39 -0500 received badge  Famous Question (source)
2017-11-05 10:32:23 -0500 received badge  Notable Question (source)
2017-10-02 15:59:08 -0500 received badge  Enthusiast
2017-09-25 08:38:49 -0500 answered a question Question on turtlesim tutorial: Go to Goal

Adding ros::spinOnce() in velocity_calc() fixes this. I also learnt that python supports multi threading which enables i

2017-09-25 08:36:43 -0500 received badge  Popular Question (source)
2017-09-21 11:02:22 -0500 edited question Question on turtlesim tutorial: Go to Goal

Question on turtlesim tutorial: Go to Goal Hello, I am new to ROS and I am trying to implement the Go to Goal tutorial

2017-09-21 10:05:41 -0500 received badge  Supporter (source)
2017-09-21 10:04:53 -0500 asked a question Question on turtlesim tutorial: Go to Goal

Question on turtlesim tutorial: Go to Goal Hello, I am new to ROS and I am trying to implement the Go to Goal tutorial

2017-09-21 09:34:11 -0500 received badge  Notable Question (source)
2017-09-21 09:34:11 -0500 received badge  Popular Question (source)
2016-04-05 10:51:34 -0500 commented question Error with laser_filter node

Log file when it ran the node with gdb and typed bt: https://drive.google.com/file/d/0B9ML...

2016-04-04 23:26:40 -0500 commented question Error with laser_filter node

I have 5 ultrasonic sensors and all the five range data is put into one laser_scan message under the topic guidance/ultrasonic.

2016-04-04 23:25:09 -0500 commented question Error with laser_filter node

Program received signal SIGSEGV, Segmentation fault. 0x00007fffec98dc62 in std::vector<boost::shared_ptr<filters::multichannelfilterbase<float> >, std::allocator<boost::shared_ptr<filters::multichannelfilterbase<float> > > >::size() const () from /home/prashant/ultra_filter/catkin_ws/devel/lib//l

2016-04-04 17:28:24 -0500 asked a question Error with laser_filter node

I am trying to implement a laser_filter for ultrasound data so I implemented a LaserScanRangeFilter to filter sensor dropouts and a median filter after. When I roslaunch my package, the following error comes up:

[filter_node-1] process has died [pid 5260, exit code -11, cmd /opt/ros/indigo/lib/laser_filters/scan_to_scan_filter_chain scan:=guidance/ultrasonic __name:=filter_node __log:=/home/prashant/.ros/log/1ce416e0-fa85-11e5-aa95-34e6add66343/filter_node-1.log]. log file: /home/prashant/.ros/log/1ce416e0-fa85-11e5-aa95-34e6add66343/filter_node-1*.log

multiple_filters.yaml file is: scan_filter_chain: - type: laser_filters/LaserScanRangeFilter
name: range params: lower_threshold: 0 upper_threshold: 50 - type: laser_filters/LaserArrayFilter name: laser_median_5 params: range_filter_chain: - name: median_5 type: filters/MultiChannelMedianFilterFloat params: number_of_observations: 5 unused: 10