rosfiware

FIWARE FIROS Publish cmd_vel from Non-ROS-World


Within firos turtlesim example (https://firos.readthedocs.io/en/latest/install/turtlesim-example.html) I'm trying to publish msg on /turtle1/cmd_vel topic from Non-ROS-World trough POST request in order to move the robot.

However I'm not sure how to do that because when I start firos/core.py the list of entities created is:

{"id":".turtle1.pose","type":"turtlesim%2FPose","angular_velocity":{"type":"number","value":0,"metadata":{"dataType":{"type":"dataType","value":"float32"}}},"linear_velocity":{"type":"number","value":0,"metadata":{"dataType":{"type":"dataType","value":"float32"}}},"theta":{"type":"number","value":0,"metadata":{"dataType":{"type":"dataType","value":"float32"}}},"x":{"type":"number","value":5.544444561,"metadata":{"dataType":{"type":"dataType","value":"float32"}}},"y":{"type":"number","value":5.544444561,"metadata":{"dataType":{"type":"dataType","value":"float32"}}}}

And the list of subscriptions is:

{"id":"XXXX","expires":"2021-06-09T22:10:17.000Z","status":"active","subject":{"entities":[{"id":".turtle1.cmd_vel","type":"geometry_msgs%2FTwist"}],"condition":{"attrs":[]}},"notification":{"attrs":["linear","angular"],"onlyChangedAttrs":false,"attrsFormat":"normalized","http":{"url":"http://XXX.XXX.X.XXX:YYYYY"}}}

None entity with .turtle1.cmd_vel id is created, so that I don't know how to update for example linear attr. Do I have to create .turtle1.cmd_vel entity manually first and update attr after? I tried it:

curl -iX POST \
  'http://localhost:1026/v2/entities' \
  -H 'Content-Type: application/json' \
  -d '
{
    "id": ".turtle1.cmd_vel",
    "type": "geometry_msgs%2FTwist",
    "linear": {
        "type": "float64",
        "value": {
            "x": "1",
            "y": "0",
            "z": "0"
        }
    },
    "angular": {
        "type": "float64",
        "value": {
             "x": "0",
             "y": "0",
             "z": "0"
        }
    }
}'

but I got errors.


Solution

  • Finally I solved the problem as follows:

    POST the entity:

    curl -iX POST \
      'http://localhost:1026/v2/entities' \
      -H 'Content-Type: application/json' \
      -d '
    {
        "id":".turtle1.cmd_vel",
        "type":"geometry_msgs%2FTwist",
        
        "angular":{
            "type":"geometry_msgs%2FVector3",
            "value":{
                "y":{
                    "type":"number",
                    "value":0.0
                },
                "x":{
                    "type":"number",
                    "value":0.0
                },
                "z":{
                    "type":"number",
                    "value":0.0
                }
            },
            "metadata":{
                "dataType":{
                    "type":"dataType",
                    "value":{
                        "y":"float64",
                        "x":"float64",
                        "z":"float64"
                    }
                }
            }
        },
        "linear":{
            "type":"geometry_msgs%2FVector3",
            "value":{
                "y":{
                    "type":"number",
                    "value":0.0
                },
                "x":{
                    "type":"number",
                    "value":0.0
                },
                "z":{
                    "type":"number",
                    "value":0.0
                }
            },
            "metadata":{
                "dataType":{
                    "type":"dataType",
                    "value":{
                        "y":"float64",
                        "x":"float64",
                        "z":"float64"
                    }
                }
            }
        }
    }'
    

    To update values:

    curl -iX PATCH \
      --url 'http://localhost:1026/v2/entities/.turtle1.cmd_vel/attrs' \
      --header 'Content-Type: application/json' \
      --data-raw ' {
        "angular": {
            "type":"geometry_msgs%2FVector3",
            "value":{
                "y":{
                    "type":"number",
                    "value": 0.0
                },
                "x":{
                    "type":"number",
                    "value": 0.0
                },
                "z":{
                    "type":"number",
                    "value": 0.0
                }
            },
            "metadata":{
                "dataType":{
                    "type":"dataType",
                    "value":{
                        "y":"float64",
                        "x":"float64",
                        "z":"float64"
                    }
                }
            }
        },
        "linear": {
            "type":"geometry_msgs%2FVector3",
            "value":{
                "y":{
                    "type":"number",
                    "value": 8.0
                },
                "x":{
                    "type":"number",
                    "value": 8.0
                },
                "z":{
                    "type":"number",
                    "value": 8.0
                }
            },
            "metadata":{
                "dataType":{
                    "type":"dataType",
                    "value":{
                        "y":"float64",
                        "x":"float64",
                        "z":"float64"
                    }
                }
            }
        }
    }'
    

    Note about updating entity:

    It cannot directly update the sub-attribute "x" (from "linear" attr) on its own, it needs to resupply the whole JSON Object.

    The reasoning behind this is as follows: NGSI just deals with Properties and Relationships - it is an abstraction layer for interoperability. The Property "linear" is an atomic unit hence you either change the whole "linear" or none of it. The value of "linear" is in this case a JSON object.