Custom message
Hello,
I have defined this custom message, FloatsStamped.msg :
Header header
float32[] data
The CMakeLists.txt is:
cmake_minimum_required(VERSION 2.8.3)
project(grideye)
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
message_generation
)
################################################
## Declare ROS messages, services and actions ##
################################################
## Generate messages in the 'msg' folder
add_message_files(
FILES
FloatsStamped.msg
)
## Generate added messages and services with any dependencies listed here
generate_messages(
DEPENDENCIES
std_msgs
)
###################################
## catkin specific configuration ##
###################################
catkin_package(
CATKIN_DEPENDS roscpp rospy std_msgs message_runtime
)
###########
## Build ##
###########
include_directories(
${catkin_INCLUDE_DIRS}
)
My package.xml is :
<?xml version="1.0"?>
<package>
<name>grideye</name>
<version>0.0.0</version>
<description>The grideye package</description>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>roscpp</build_depend>
<build_depend>rospy</build_depend>
<build_depend>std_msgs</build_depend>
<build_depend>message_generation</build_depend>
<run_depend>message_runtime</run_depend>
<run_depend>roscpp</run_depend>
<run_depend>rospy</run_depend>
<run_depend>std_msgs</run_depend>
<build_depend>python-numpy</build_depend>
<run_depend>python-numpy</run_depend>
</package>
And finally the code I use is:
#!/usr/bin/env python
import rospy
import numpy
from grideye.msg import FloatsStamped
from grideye_class import GridEye
def talker():
pub = rospy.Publisher('thermal_pixels', FloatsStamped, queue_size=10)
rospy.init_node('grideye', anonymous=True)
r = rospy.Rate(5)
pix = []
while not rospy.is_shutdown():
pix = mysensor.getPixels()
print(pix)
#feed a FloatsStamped msg
a = FloatsStamped
a.header.stamp = rospy.Time.now()
a.data = numpy.array(pix, dtype=numpy.float32)
pub.publish(a)
r.sleep()
if __name__ == '__main__':
mysensor = GridEye()
rospy.loginfo("Starting data retrieving from Grid Eye sensor Board")
talker()
I get an error message indicating that :
a.header.stamp = rospy.Time.now() AttributeError: 'member_descriptor'
object has no attribute 'stamp'
I declare a
as FloatsStamped message and this message includes the Header message, so I don't understand why I get this error message.
matt
Try
a = FloatsStamped()
, with the trailing parentheses.@Thomas D comment should really be an answer, as it is most likely the answer.
@mattMGN: you are assigning to
a
the type ofFloatStamped
(ie: the class), not to an instance of it (ie: an object).data
is not a field of the class, but of the object.