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

using simple timers in ROS - doesn't show up in rqt [closed]

asked 2014-06-26 16:18:44 -0500

updated 2014-06-26 16:21:09 -0500

I am on ROS Hydro (with Catkin). I made a node with a C++ timer, with the following code;

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

int main(int args,char* argv[])
{
 clock_t startTime = clock(); //Start timer
 double secondsPassed;

 bool flag = true;
 while(flag)
  {
   secondsPassed = (clock() - startTime) / CLOCKS_PER_SEC;
   if(secondsPassed >= 120)
    {
     std::cout << "Hello ROS, this is a C++ node and " << secondsPassed << " seconds have passed" << std::endl;
     flag = false;
    }
  }
}

This works just fine ! but the funny part is that it doesn't show up on rqt. If the node is running for 120 seconds, it should register in rqt for those 120 seconds - which it doesn't ! Any hints ? explanation ? or am I doing something wrong ?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Arkapravo
close date 2014-06-26 23:01:55.494568

1 Answer

Sort by ยป oldest newest most voted
1

answered 2014-06-26 20:31:10 -0500

Hamid Didari gravatar image

add these lines in the first of your program:

 /**
   * The ros::init() function needs to see argc and argv so that it can perform
   * any ROS arguments and name remapping that were provided at the command line. For programmatic
   * remappings you can use a different version of init() which takes remappings
   * directly, but for most command-line programs, passing argc and argv is the easiest
   * way to do it.  The third argument to init() is the name of the node.
   *
   * You must call one of the versions of ros::init() before using any other
   * part of the ROS system.
   */
  ros::init(argc, argv, "Timer");

  /**
   * NodeHandle is the main access point to communications with the ROS system.
   * The first NodeHandle constructed will fully initialize this node, and the last
   * NodeHandle destructed will close down the node.
   */
  ros::NodeHandle n;

and also you nee incude:

#include "ros/ros.h"
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-06-26 16:18:44 -0500

Seen: 191 times

Last updated: Jun 26 '14