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

New node and custom msg giving a data_class error

asked 2015-07-27 13:37:45 -0600

FindogJr gravatar image

I have been working on a project for a few weeks everything has gone good until finished my a new node with custom messages. I am very new to ROS so I am sure that I might be missing one simple step. I have already made other nodes and msgs however this one is giving me problems. I have retraced my steps four times.

I am getting this error when rosrun my node:

Traceback (most recent call last):
      File "/home/onr/catkin_ws/src/furuno_radar/src/ARPA_node.py", line 111, in <module>
        main(sys.argv)
      File "/home/onr/catkin_ws/src/furuno_radar/src/ARPA_node.py", line 104, in main
        ARPAdata = ARPANode()
      File "/home/onr/catkin_ws/src/furuno_radar/src/ARPA_node.py", line 85, in __init__
        self._arpa_info_pub = rospy.Publisher("ARPA_data",RadarARPAInfo())
      File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/topics.py", line 803, in __init__
        super(Publisher, self).__init__(name, data_class, Registration.PUB)
      File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/topics.py", line 138, in __init__
        raise ValueError("data_class [%s] is not a class"%data_class) 
    ValueError: data_class [header: 
      seq: 0
      stamp: 
        secs: 0
        nsecs: 0
      frame_id: ''
    Target: 0
    TDistance: 0.0
    TBearing: 0.0
    TrueSpeed: 0.0
    TrueCourse: 0.0
    RelSpeed: 0.0
    RelCourse: 0.0] is not a class

My message is in is own package and CMakeLists.txt and package.xml have been edited.

Header header

int32 Target
float64 TDistance #target distance from conning(.0001nm)
float64 TBearing  #target bearing from own ship(.1 degree)
float64 TrueSpeed #target speed(.1kt)
float64 TrueCourse #target course(.1 degree)
float64 RelSpeed #relative speed (.01nm
float64 RelCourse #relitive course (.1 degree)

I created a node and made it executable. Here is my node.

#!/usr/bin/env python

import roslib
roslib.load_manifest('furuno_radar')
import sys
import rospy
from arpa_msgs.msg import RadarARPAInfo
from std_msgs.msg import String

import asyncore
import socket

import struct

class ARPANode(asyncore.dispatcher):

    class ARPA:
        radarNo = 0
        target = 0
        ccrpDist = 0.0
        ccrpBear = 0.0
        t_speed = 0.0
        t_course = 0.0
        r_speed = 0.0
        r_course = 0.0
        count = 0


    def datagram2ARPA(self, data):

        arpa = self.ARPA()
        index = 0

        length = struct.unpack_from("<I", data, index)[0]
        index += 4

        arpa.radarNo = struct.unpack_from("<I", data, index)[0]
        index += 4
        arpa.targetNo = struct.unpack_from("I", data, index)[0]
        index += 4
        arpa.ccrpDist = struct.unpack_from("<d", data, index)[0]
        index += 8
        arpa.ccrpBear = struct.unpack_from("<d", data, index)[0]
        index += 8
        arpa.t_speed = struct.unpack_from("<d", data, index)[0]
        index += 8
        arpa.t_course = struct.unpack_from("<d", data, index)[0]
        index += 8
        arpa.r_speed = struct.unpack_from("<d", data, index)[0]
        index += 8
        arpa.r_course = struct.unpack_from("<d", data, index)[0]
        index += 8
        arpa.count = struct.unpack_from("<I", data, index)[0]

        return arpa

    def ARPA2Messages(self, arpa):
        arpa_info_message = RadarARPAInfo()
        arpa_info_message.header.stamp = rospy.Time.now()
        arpa_info_message.TDistance = arpa.ccrpDist
        arpa_info_message.TBearing = arpa.ccrpBear
        arpa_info_message.TrueSpeed = arpa.t_speed
        arpa_info_message.TrueCourse = arpa.t_course
        arpa_info_message.RelSpeed = arpa.r_speed
        arpa_info_message.RelCourse = arpa.r_course

        return arpa_info_message

    def datagram2ARPAMessage(self, data):
        arpa = self.datagram2ARPA(data)
        return self.ARPA2Messages(arpa)

    def __init__(self ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2015-07-28 01:53:03 -0600

mgruhler gravatar image

The problem is in creating the Publisher. You have to pass in the msg_class as described here.

You are actually trying to pass in an instantiation of the class, not the class Type. So do a

 self._arpa_info_pub = rospy.Publisher("ARPA_data",RadarARPAInfo)

Note the missing () at the end.

edit flag offensive delete link more

Comments

Thanks so much! I knew it was something small I was overlooking. This project has been very humbling. Thanks again!

FindogJr gravatar image FindogJr  ( 2015-07-28 10:29:33 -0600 )edit

Glad I could help. If the question is solved, please accept the answer (by clicking on the check mark next to it). Thx. So it might help others with the same problem.

mgruhler gravatar image mgruhler  ( 2015-07-29 00:49:59 -0600 )edit

Question Tools

Stats

Asked: 2015-07-27 13:37:45 -0600

Seen: 3,114 times

Last updated: Jul 28 '15