Robotics StackExchange | Archived questions

data.data does not name a type

i create a node in order to publish topic, so i choose std_msgs::Float64 as a type of message sent by my publisher. then i wrote those lines to publish a random message :

std_msgs::Float64 test;
test.data=0.500785;
pub.publish(test);

and that gives me an error : 'test' does not name a type

and : pub.publish(test) does not name a type.

any ideas to solve that? PS: i'm coding in c++ can anyone help me?

Asked by samo on 2018-06-27 07:33:31 UTC

Comments

Hi! I ran into the same problem, so how did you solve this problem?

Asked by Lamfurst on 2021-05-15 22:17:59 UTC

Answers

You need the relevant include to be able to use this message:

#include <std_msgs/Float32.h>

You need to setupstd_msgs as a dependency of your package if you want that to work: http://wiki.ros.org/catkin/Tutorials/CreatingPackage

Asked by VictorLamoine on 2018-06-27 10:00:31 UTC

Comments

i already have std_msgs as a dependency, but it didn't work for me.

Asked by samo on 2018-06-27 10:08:27 UTC

Please provide a simple, full example ROS package demonstrating your problem if you want more help (edit your first message)

Asked by VictorLamoine on 2018-06-27 10:10:46 UTC

I think you may put this in your .h file, try put them at ,cpp file and compile again.

Asked by TifferPelode on 2018-06-27 21:47:30 UTC

they are already in the same .cpp file. but it gives me this error

Asked by samo on 2018-07-06 04:06:18 UTC

I have the same problem did you solve it?

Asked by Basma on 2022-09-05 03:58:03 UTC