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

Reading pushlished data of custom msg types

asked 2021-08-22 18:11:16 -0500

sisko gravatar image

I have a peculiar problem when I attempt to read data from a custom topic.

My msg type are Space.msg :

string region
uint8[] spaces

And, SpaceArray.msg :

Space[] spaces

I am successfully publishing data using the following function of one of my python scripts : def publish(self) : message_pub = rospy.Publisher("scans_freespace", SpaceArray, queue_size=10)

    spacesArray = SpaceArray()

    for region in self.regions :
        space = Space()
        space.region = region
        space.spaces = self.function_returning_array_of_numbers()
        spacesArray.spaces.append(space)

    message_pub.publish( spacesArray )

All the above work as expected. I get the expected output from * as displayed below :

spaces: 
  - 
    region: "port_bow"
    spaces: []
  - 
    region: "port_abeam_aft"
    spaces: [97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130]
  - 
    region: "starboard_abeam_bow"
    spaces: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130]
  - 
    region: "port_abeam_bow"
    spaces: []
  - 
    region: "starboard_bow"
    spaces: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]
  - 
    region: "port_aft"
    spaces: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130]
  - 
    region: "starboard_abeam_aft"
    spaces: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64 ...
(more)
edit retag flag offensive close merge delete

Comments

Is the array size what you intended it to be? You may want to check the following.

rospy.loginfo(self.freespace.spaces.size())
rospy.loginfo(space.spaces.size())
miura gravatar image miura  ( 2021-08-22 18:26:36 -0500 )edit
1

First line:

AttributeError: 'list' object has no attribute 'size'

Second line:

AttributeError: 'str' object has no attribute 'size'

I get those error in response to the code you suggested.

sisko gravatar image sisko  ( 2021-08-22 21:33:57 -0500 )edit
1

I believe this is a duplicate. See #q363356 fi.

gvdhoorn gravatar image gvdhoorn  ( 2021-08-23 01:19:22 -0500 )edit

I think it's definitely the same problem.

miura gravatar image miura  ( 2021-08-23 18:33:31 -0500 )edit

@miura: Maybe, but unless I missed something, there is no solution in that post

sisko gravatar image sisko  ( 2021-08-23 18:57:37 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-08-24 18:10:44 -0500

miura gravatar image

Using the uint8[] type will result in a str, so if you don't mind the larger data size, it would be easy to change the spaces to the uint16[] type.

Alternatively, you could do the following

spaces = [ord(c) for c in space.spaces]
rospy.loginfo(spaces)

ref: https://answers.ros.org/question/3419...

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2021-08-22 18:11:16 -0500

Seen: 84 times

Last updated: Aug 24 '21