Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Regarding ros::WallTime

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

click to hide/show revision 2
No.2 Revision

Regarding ros::WallTime

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>

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

using namespace std;

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

"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>

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

using namespace std;

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");

"subscriber"); ros::NodeHandle m;

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

ros::spin();

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