ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To use your own custom message, you have to tell ROS about it when you build your package. More specifically, ROS needs to generate the message headers and put them in the proper location (depends on build tool). The Creating a Msg and Srv tutorial has the steps for doing this, and it's explained in the msg wiki.

If it's a custom message as part of a third-party package, the message generation should happen automatically when you build/install that package. To check if it's installed properly and ROS can find it, you can run rosmsg show <package_name>/<msg_name> in a terminal. In this case, it would be:

rosmsg show dvs_msgs/Event

The output should match the message definition:

uint16 x
uint16 y
time ts
bool polarity

Once the headers are available, you can use the message just like any other. Here's the Event message added to the rosbag Python API example:

import rosbag
import rospy  # Need this to create a rospy.Time object for Event.ts
from std_msgs.msg import Int32, String
from dvs_msgs.msg import Event  # Imports the message from whichever package generated it

bag = rosbag.Bag('test.bag', 'w')

try:
    s = String()
    s.data = 'foo'

    i = Int32()
    i.data = 42

    e = Event()
    e.x = 23
    e.y = 17
    e.ts = rospy.Time.now()
    e.polarity = False

    bag.write('chatter', s)
    bag.write('numbers', i)
    bag.write('events', e)
finally:
    bag.close()

I didn't actually test this code, so let me know if you run into problems.

To use your own custom message, you have to tell ROS about it when you build your package. More specifically, ROS needs to generate the message headers and put them in the proper location (depends on build tool). The Creating a Msg and Srv tutorial has the steps for doing this, and it's explained in the msg wiki.

If it's a custom message as part of a third-party package, the message generation should happen automatically when you build/install that package. To check if it's installed properly and ROS can find it, you can run rosmsg show <package_name>/<msg_name> in a terminal. In this case, it would be:

rosmsg show dvs_msgs/Event

The output should match the message definition:

uint16 x
uint16 y
time ts
bool polarity

Once the headers are available, you can use the message just like any other. Here's the Event message added to the rosbag Python API example:

import rosbag
import rospy  # Need this to create a rospy.Time object for Event.ts
from std_msgs.msg import Int32, String
from dvs_msgs.msg import Event  # Imports the custom message from whichever package generated it
its package

bag = rosbag.Bag('test.bag', 'w')

try:
    s = String()
    s.data = 'foo'

    i = Int32()
    i.data = 42

    e = Event()
    e.x = 23
    e.y = 17
    e.ts = rospy.Time.now()
    e.polarity = False

    bag.write('chatter', s)
    bag.write('numbers', i)
    bag.write('events', e)
finally:
    bag.close()

I didn't actually test this code, so let me know if you run into problems.