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 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.
Do you have the custom message installed already?
Probably not, what do you mean? I have to install it like a python module? I only have that .msg file but I did not know that it could be installed.