Can't read topics in Matlab

asked 2018-03-16 14:55:42 -0600

Marcus Barnet gravatar image

Hello,

I'm trying to read the /status topic from Husky A200 in Matlab. This is my bag file (20KB) I'm using this code:

%% Retrieve information from the ROSbag
filePath_Pro = 'matlab.bag';
bagPro = rosbag(filePath_Pro);
bagPro_System = select(bagPro, 'Topic', '/status');
N4=bagPro_System.NumMessages;
system_msg = readMessages(bagPro_System);

But when I call readMessages, I get this error:

Error using robotics.ros.BagSelection/deserializeMessages (line 445)
Java exception occurred:
org.ros.exception.RosMessageRuntimeException: java.lang.ClassNotFoundException:
husky_msgs.HuskyStatus
    at
        org.ros.internal.message.definition.MessageDefinitionReflectionProvider.get(MessageDefinitionReflectionProvider.java:66)
            at
        org.ros.internal.message.DefaultMessageFactory.newFromType(DefaultMessageFactory.java:42)
            at
        org.ros.internal.message.DefaultMessageDeserializer.deserialize(DefaultMessageDeserializer.java:42)
        Caused by: java.lang.ClassNotFoundException: husky_msgs.HuskyStatus
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at
        org.ros.internal.message.definition.MessageDefinitionReflectionProvider.get(MessageDefinitionReflectionProvider.java:62)
            ... 2 more
Error in robotics.ros.BagSelection/readMessages (line 195)
            msgs = obj.deserializeMessages(obj.MessageList, rows);

This is the output of the topic /status when I read it with rostopic echo /status :

header: 
  seq: 976
  stamp: 
    secs: 1517311503
    nsecs: 918934269
  frame_id: ''
uptime: 1148382
ros_control_loop_freq: 9.91557364985
mcu_and_user_port_current: 0.57
left_driver_current: 7.69
right_driver_current: 9.26
battery_voltage: 24.51
left_driver_voltage: 24.67
right_driver_voltage: 24.57
left_driver_temp: 23.42
right_driver_temp: 27.25
left_motor_temp: 14.28
right_motor_temp: 15.51
capacity_estimate: 480
charge_estimate: 0.22
timeout: False
lockout: False
e_stop: False
ros_pause: False
no_battery: False
current_limit: False

I need to read the left_driver_current and right_driver_current. I'm able to read all the other topics, but not the /status topic.

I've already downloaded the Robotics System Toolbox Interface for ROS Custom Messages but I do not know how to use it and I do not know if it is useful for my problem.

I hope you can help me,

Thanks!

edit retag flag offensive close merge delete

Comments

1

Did you follow the instructions for creating custom msgs in matlab given here?

stevejp gravatar imagestevejp ( 2018-03-19 07:31:09 -0600 )edit

Yes, but I didn't understand how to do that. I already have the bag file and I can't record them again. I tried to follow the instructions, but they are not very clear to me.

Marcus Barnet gravatar imageMarcus Barnet ( 2018-03-19 09:44:16 -0600 )edit

What part isn't clear? Also, there is an example outlining exactly what you need to do here.

stevejp gravatar imagestevejp ( 2018-03-19 11:41:08 -0600 )edit

I can't understand why I need to use rosgenmsg. I'm using the bag files from Husky A200 ROS node releases by Clearpath. Moreover, I can't undestand how to specify the structure of my messages.

Marcus Barnet gravatar imageMarcus Barnet ( 2018-03-19 11:44:42 -0600 )edit
1

The Husky ROS node is packaging all of the Husky status info up into a husky_msgs/HuskyStatus msg. When matlab receives this message, it needs to know how to unpack all of the info - this is what rosgenmsg is for.

stevejp gravatar imagestevejp ( 2018-03-19 11:53:59 -0600 )edit