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

rosbridge publish to /joy_node: Error Received a message without an op

asked 2020-02-17 09:04:11 -0500

mtbsteve gravatar image

updated 2020-02-17 09:11:30 -0500

I am trying to publish joystick movements to the /cmd_vel topic and the /joy_node topic from rosbridge Android. While publishing to the /cmd_vel node works perfectly fine, publishing to /joy_node fails with the Error: "Received a message without an op." over the same connection to the ROSbridge master.

My coding:

....
   private float joy_axes[] = {0f, 0f, 0f, 0f, 0f, 0f};
    private int joy_buttons[] = {0,0,0,0,0,0,0,0,0,0,0,0};
    private int sequence_ID = 0;
    private long time_stamp_sec= System.currentTimeMillis()/1000;
    private long timestamp_nsec=222234283;
    private long time_stamp_prev;
    private String frame_id="";

private void onLoginSuccess() throws JSONException {
        // we advertise the ROS topic node we want to use for the Joystick (cmd_vel supports only the analog axis movements,
        // the joy node is the "real" ROS topic to publish all joystick features)
        Advertise("/cmd_vel", "geometry_msgs/Twist");
        Advertise("/joy_node", "sensor_msgs/Joy");
        connected_to_ros =true;
        connected_to_ros_message = "Connected to ROS Server: " + message;

        // send a test message to /cmd_vel ***** this works
        String cmdvel = "{\"op\":\"publish\",\"topic\":\"/cmd_vel\",\"msg\":{\"linear\":{\"x\":" + joy_axes[0] + ",\"y\":" + joy_axes[1] + ",\"z\":" + joy_axes[2] + "},\"angular\":{\"x\":" + joy_axes[3] + ",\"y\":" + joy_axes[4] + ",\"z\":" + joy_axes[5] + "}}}";
        client.send(cmdvel);

        //build the json array for the axes and buttons
        JSONArray json_joy_axes= new JSONArray();
        for (int i = 0; i < joy_axes.length; i++) {
            json_joy_axes.put(joy_axes[i]);
        }
        JSONArray json_joy_buttons= new JSONArray();
        for (int i = 0; i < joy_buttons.length; i++) {
            json_joy_buttons.put(joy_buttons[i]);
        }

        //send a test message to /joy_node **** this fails
        String joynode = "{\"op\":\"publish\",\"topic\":\"/joy_node\",\"msg\":{\"header\":{\"seq\": " + sequence_ID + ",\"stamp\":{\"secs\": " + time_stamp_sec + ",\"nsecs\": " + timestamp_nsec + "},\"frame_id\": " + frame_id + "},\"axes\":" + json_joy_axes +",\"buttons\":" + json_joy_buttons + "}}";
        client.send(joynode);
    }

I read here in this forum that rosbridge doesnt have a dedicated error handling for the parsing od json obects and that the error received indicates some problem with the json object definition. So I verified the json string in JSONlint and it appears valid and consistent with the message type definition at http://docs.ros.org/api/sensor_msgs/h...

What is wrong with my json object here? Thanks!

edit retag flag offensive close merge delete

Comments

Not an answer, but a comment on something I noticed in your code:

// we advertise the ROS topic node we want to use for the Joystick (cmd_vel supports only the analog axis movements,

// the joy node is the "real" ROS topic to publish all joystick features)

cmd_vel is a topic (not a node), and it carries geometry_msgs/Twist messages. Those have no direct relationship with joysticks. They only encode a linear and angular velocity.

joy is a topic (the node is called joy_node) which carries sensor_msgs/Joy messages. Those do have a relationship with joysticks, in that they "Report the state of a joysticks axes and buttons".

Joy messages can be used to calculate values for a Twist message, but the two are not related directly, nor do they have to be used together necessarily (in fact, Twist is used for many purposes not even remotely related to joysticks).

gvdhoorn gravatar image gvdhoorn  ( 2020-02-17 09:26:50 -0500 )edit

Yes I know. Thats why I am trying to use the /joy topic. I implemented the /cmd_vel topic only to verify that rosbridge is operational and to rule out any problems with the websocket connection.

mtbsteve gravatar image mtbsteve  ( 2020-02-17 11:55:31 -0500 )edit

2 Answers

Sort by » oldest newest most voted
0

answered 2020-02-17 09:29:51 -0500

gvdhoorn gravatar image

updated 2020-02-18 06:54:11 -0500

Edit:

I just noticed this part in your String joynode:

[..] \"frame_id\": " + frame_id + "}, [..]

frame_id is a string, so it must be quoted, even in JSON.

I would expect something like this:

[..] \"frame_id\": \"" + frame_id + "\"}, [..]

note the additional \" surrounding the frame_id.

Unless whatever library you're using for emitting JSON takes care of this itself, I suspect that is actually the problem (if you're not using any library for serialising Java objects to JSON, you could consider using one, as it could prevent issues with quoting and general JSON layout).

Your comment about "an empty frame_id string" working seems to point to the same cause, as you don't pass an empty frame_id variable, but an explicit \"\".


Original answer: I haven't checked this in any way, but while reading wiki/joy: Nodes and comparing it with the code you show, I noticed this:

Advertise("/joy_node", "sensor_msgs/Joy");

The topic to publish sensor_msgs/Joy messages on is called joy. The node that typically does this would be called joy_node.

Your code appears to be publishing to a topic called joy_node, which, if your downstream consumers expect the regular topic, will result in no messages being received by those subscribers. This could explain why you get the error your report (but it might also not).

You may want to run roswtf after you have started up your application (including all ROS nodes). I suspect it will report some unconnected subscribers and/or publishers.

edit flag offensive delete link more

Comments

Thanks @gvdhoorn I tried advertising of /joy and publishing to /joy instead of /joy_node makes no difference. I still get the same error. roswtf runs with "No errors or warnings". So the problem must be somewhere in the json string I am using, or with the rosbridge kinetic implementation for this topic...

mtbsteve gravatar image mtbsteve  ( 2020-02-17 11:40:20 -0500 )edit

I tried advertising of /joy and publishing to /joy instead of /joy_node makes no difference. I still get the same error.

regardless, /joy would be the appropriate topic. Not /joy_node.

gvdhoorn gravatar image gvdhoorn  ( 2020-02-18 06:53:09 -0500 )edit

Thanks @gvdhoorn adding the quotes to the frame_id variable fixed it. But since the frame_id is left empty also in the „official“ kinetic/melodic ros joy package implementation, I guess it can also be hardcoded in the rosbridge json object as I initially did.

mtbsteve gravatar image mtbsteve  ( 2020-02-18 11:14:08 -0500 )edit

Yes. A frame_id doesn't make much sense for a Joy message.

gvdhoorn gravatar image gvdhoorn  ( 2020-02-18 11:59:46 -0500 )edit
0

answered 2020-02-18 03:11:39 -0500

mtbsteve gravatar image

OK I could finally solve the problem. The issue was the definition of the frame_id. While the ROS message definition declares the frame_id as string (http://docs.ros.org/api/std_msgs/html...), the rosbridge parser fails to interpret it regardless how you set it in a variable. The only way to get it working is to hardcode the frame_id as empty string (\"frame_id\":\"\") in the json object, such as:

String joynode = "{\"op\":\"publish\",\"topic\":\"/joy\",\"msg\":{\"header\":{\"seq\":" + sequence_ID + ",\"stamp\":{\"secs\":" + time_stamp_sec + ",\"nsecs\":" + timestamp_nsec + "},\"frame_id\":\"\"},\"axes\":" + json_joy_axes +",\"buttons\":" + json_joy_buttons + "}}";

As soon as frame_id contains anything else but a hardcoded empty string, rosbridge will fail.

edit flag offensive delete link more

Comments

I'm not saying it doesn't work for you, but there should be no requirement to leave frame_id empty. If there is, that would be a bug.

Your post describes a work-around, not a solution.

RobotWebTools/rosbridge_suite#217 seems to describe a similar issue (also with Joy).

gvdhoorn gravatar image gvdhoorn  ( 2020-02-18 06:11:12 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2020-02-17 09:04:11 -0500

Seen: 832 times

Last updated: Feb 18 '20