Ask Your Question
0

Custom message

asked 2018-02-22 06:09:19 -0500

mattMGN gravatar image

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

edit retag flag offensive close merge delete

Comments

Try a = FloatsStamped(), with the trailing parentheses.

Thomas D gravatar imageThomas D ( 2018-02-22 08:20:40 -0500 )edit

@Thomas D comment should really be an answer, as it is most likely the answer.

@mattMGN: you are assigning to a the type of FloatStamped (ie: the class), not to an instance of it (ie: an object). data is not a field of the class, but of the object.

gvdhoorn gravatar imagegvdhoorn ( 2018-02-23 04:05:21 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2018-02-23 16:40:29 -0500

Thomas D gravatar image

Try a = FloatsStamped(), with the trailing parentheses.

As @gvdhoorn points out in a comment: you are assigning to a the type of FloatStamped (ie: the class), not to an instance of it (ie: an object). data is not a field of the class, but of the object.

edit flag offensive delete link more

Comments

You are right, It now works Thanks for your comment

mattMGN gravatar imagemattMGN ( 2018-02-27 03:38:28 -0500 )edit
0

answered 2018-02-22 07:05:33 -0500

agutenkunst gravatar image

I think it should be

std_msgs/Header header
float32[] data
edit flag offensive delete link more

Comments

Ok, I will give it a try on next week

mattMGN gravatar imagemattMGN ( 2018-02-22 16:30:40 -0500 )edit

That's was not the point, as that it works both with and without std_msgs thank you for your input

mattMGN gravatar imagemattMGN ( 2018-02-27 03:39:42 -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

1 follower

Stats

Asked: 2018-02-22 06:09:19 -0500

Seen: 1,209 times

Last updated: Feb 23 '18