gazebo::msgs How do I set Time in a stamped message?
Hi, maybe someone could help me with howto set the time in a stamped message. For example the gps.proto and poses_stamped.proto have required Time time = 1;
I can't figure out how to get hold of time.sec and time.nsec in the protostruct have tried set_allocated_time(time); and msg.set_time.nsec(43); plus various tries to cast recast and other stufff. No luck
Could some c++ guru please help and educate me what I am doing wrong....
The current (below) code gives the following errors:
~/src/gazebo-11/examples/stand_alone/publisher/publisher.cc: In function ‘int main(int, char**)’:
~/src/gazebo-11/examples/stand_alone/publisher/publisher.cc:49:10: error: invalid use of member function ‘google::protobuf::int32 gazebo::msgs::Time::sec() const’ (did you forget the ‘()’ ?)
49 | time.sec=(32);
| ~~~~~^~~
| ()
~/src/gazebo-11/examples/stand_alone/publisher/publisher.cc:50:10: error: invalid use of member function ‘google::protobuf::int32 gazebo::msgs::Time::nsec() const’ (did you forget the ‘()’ ?)
50 | time.nsec=(43);
| ~~~~~^~~~
| ()
~/src/gazebo-11/examples/stand_alone/publisher/publisher.cc:51:28: error: cannot convert ‘gazebo::msgs::Time’ to ‘gazebo::msgs::Time*’
51 | msg.set_allocated_time(time);
| ^~~~
| |
| gazebo::msgs::Time
In file included from /usr/include/gazebo-11/gazebo/msgs/MessageTypes.hh:32,
from /usr/include/gazebo-11/gazebo/msgs/msgs.hh:35,
from /usr/include/gazebo-11/gazebo/transport/CallbackHelper.hh:29,
from /usr/include/gazebo-11/gazebo/transport/transport.hh:2,
from ~/src/gazebo-11/examples/stand_alone/publisher/publisher.cc:18:
/usr/include/gazebo-11/gazebo/msgs/gps.pb.h:318:59: note: initializing argument 1 of ‘void gazebo::msgs::GPS::set_allocated_time(gazebo::msgs::Time*)’
318 | inline void GPS::set_allocated_time(::gazebo::msgs::Time* time) {
| ~~~~~~~~~~~~~~~~~~~~~~^~~~
~/src/gazebo-11/examples/stand_alone/publisher/publisher.cc:52:9: error: ‘class gazebo::msgs::GPS’ has no member named ‘set_time’
52 | msg.set_time.nsec(43);
| ^~~~~~~~
make[2]: *** [CMakeFiles/publisher.dir/build.make:63: CMakeFiles/publisher.dir/publisher.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/publisher.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
// publisher.cc
/* CMakelist.txt
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
find_package(gazebo REQUIRED)
include_directories(${GAZEBO_INCLUDE_DIRS})
link_directories(${GAZEBO_LIBRARY_DIRS})
list(APPEND CMAKE_CXX_FLAGS "${GAZEBO_CXX_FLAGS}")
add_executable(publisher publisher.cc)
target_link_libraries(publisher ${GAZEBO_LIBRARIES})
*/
int main(int _argc, char **_argv)
{
// Load gazebo
gazebo::client::setup(_argc, _argv);
// Create our node for communication
gazebo::transport::NodePtr node(new gazebo::transport::Node());
node->Init();
// Publish to a Gazebo topic
gazebo::transport::PublisherPtr pub =
node->Advertise<gazebo::msgs::GPS>("~/test_example");
// Wait for a subscriber to connect
pub->WaitForConnection();
// Publisher loop...replace with your own code.
while (true) {
//Throttle Publication
gazebo::common::Time::MSleep(100);
gazebo::msgs::GPS msg;
gazebo::msgs::Time time;
time.sec=(32);
time.nsec=(43);
msg.set_allocated_time(time);
msg.set_time.nsec(43);
msg.set_link_name("test_link");
msg.set_latitude_deg(0.831097);
msg.set_longitude_deg(-2.135595);
msg.set_altitude(17.01);
msg.set_velocity_east(0.0);
msg.set_velocity_north(0.0);
msg.set_velocity_up(0.0);
// Publish message
pub->Publish(msg);
}
// Make sure to shut everything down.
gazebo::client::shutdown();
}