Ask Your Question
0

Regarding ros::WallTime

asked 2012-09-18 05:12:18 -0500

muin028 gravatar image

updated 2012-09-20 01:06:51 -0500

dornhege gravatar image

sequence1: this is my massage package:

Num.msg

Header header string data

this is my terminal massage,when i type $ rosmsg show Test/Num Header header

uint32 seq

time stamp

string frame_id

string data

Ques1:how to upgrade the "time" to "WallClock time",which will show the current time in "hr.min.sec" format??????????????

sequence2: this is my publisher node:

#include "ros/ros.h"
#include "Test/Num.h"
#include <sstream>

using namespace std;

int main(int argc, char **argv)
    {
        ros::init(argc, argv, "publisher");

        ros::NodeHandle m;

        ros::Publisher chatter_pub = m.advertise<Test::Num>("request", 1000);

        ros::Rate loop_rate(10);

        int counter = 0;
        while (ros::ok())
            {
                Test::Num msg1;
                msg1.header.stamp=ros::Time::now();
                msg1.header.frame_id="/current time";
                std::stringstream sst;
                sst << "Can you here me,hello..."<<counter;
                msg1.data = sst.str();

                ROS_INFO("%s", msg1.data);

                chatter_pub.publish(msg1);

                loop_rate.sleep();

                ++counter;

                ros::spinOnce();
            }


        return 0;
    }

ques2:in the above code "msg1.header.stamp=ros::Time::now();"--in this line what will be the member instead of "stamp" in case of ros::WallTime::now()?????????

sequence3: this is my subscriber node:

#include "ros/ros.h"
#include "Test/Num.h"
#include <sstream>

using namespace std;

void Request(const Test::Num& msg2)
    {
    Test::Num newMessage;
    newMessage.data = msg2.data;
    newMessage.header.stamp=ros::Time::now();
    newMessage.header.frame_id="/current time"; */
    ROS_INFO("I heard: [%s]", msg2.data);
    }

int main(int argc, char **argv)
{
   ros::init(argc, argv, "subscriber");

   ros::NodeHandle m;

   ros::Subscriber request_sub = m.subscribe("request", 1000, Request);

   ros::spin();

   return 0;
 }

ques3: if i want to add ros duration to subtract two time stamp to get the response time(time to publish massage in request topic-time to subscribe massage from request topi).what will be the command??????

ques4:in rosmake command i am getting following tewo errors: 1.warning: cannot pass objects of non-POD type ‘const struct std::basic_string<char, std::char_traits<char="">, std::allocator<char> >’ through ‘...’; call will abort at runtime 2.warning: format ‘%s’ expects type ‘char*’, but argument 8 has type ‘int’

Ques4:in rosrun Test publisher command ---it showing illigal instruction

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2012-09-18 05:23:20 -0500

dornhege gravatar image

Please open single questions in the future unless they are regarding the same problem.

1./2.: Just leave it as it is and use ros::WallTime instead of ros::Time. There is no need to rename the parameter, just put some time in there, and if you want use WallTime.

3.: You can just substract the two times with the normal "-" operator. You will automatically get a ros::Duration.

4.: Add a .c_str(), when you output a std::string to ROS_...() calls.

edit flag offensive delete link more

Comments

you said"There is no need to rename the parameter, if you want to use WallTime."error: no match for ‘operator=’ in ‘msg1.Test::Num_<std::allocator<void> >::header.std_msgs::Header_<std::allocator<void> >::stamp = ros::WallTime::now()()’......................but i am getting this kind of error.

muin028 gravatar imagemuin028 ( 2012-09-19 10:49:27 -0500 )edit

"just put some time in there".can you please give some more definition/clarify about this sentence..............Thanks in advance.

muin028 gravatar imagemuin028 ( 2012-09-19 10:52:51 -0500 )edit

They are both a ros::TimeBase, so you can construct a ros::Time from the sec/nsec parameters of WallTime. "just put some time" mean, you can use a ros::Time that you constructed in any way you want (e.g. from WallTime) as long as it represents a time. However, you cannot change the Header type.

dornhege gravatar imagedornhege ( 2012-09-19 23:05:48 -0500 )edit

thanks for the reply.....ros::Time and ros::WallTime are both different classes.of them ros::Time can take time primitive type,ros::WallTime can not take time primitive type.Because i tried lots of time but its saying the same thing.I think there are some bug in ros::WallTime class.

muin028 gravatar imagemuin028 ( 2012-09-20 00:53:22 -0500 )edit

They are both instantiations of the same template. You can thus create a ros::Time from the sec/nsec of a ros::WallTime and will get a respective object.

dornhege gravatar imagedornhege ( 2012-09-20 01:05:15 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-09-18 05:12:18 -0500

Seen: 1,179 times

Last updated: Sep 20 '12