How to use the haros.hpl.ros_types.TypeToken function in haros

To help you get started, we’ve selected a few haros examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github git-afsantos / haros / haros / gen_tests.py View on Github external
def _get_class_fields(self, msg_class, msg_queue):
        self.log.debug("extracting msg fields")
        fields = {}
        for i in xrange(len(msg_class.__slots__)):
            field_name = msg_class.__slots__[i]
            field_type = msg_class._slot_types[i]
            base_type, is_array, length = parse_type(field_type)
            if is_array:
                type_token = ArrayTypeToken(base_type, length=length)
            else:
                type_token = TypeToken(base_type)
            fields[field_name] = type_token
            if "/" in base_type and base_type != "std_msgs/Header":
                msg_queue.append(base_type)
        return fields
github git-afsantos / haros / haros / hpl / test_generator.py View on Github external
################################################################################
# Test Code
################################################################################

if __name__ == "__main__":
    from .hpl_ast import (HplReceiveStatement, HplMsgFilter, HplProperty,
        HplMsgFieldCondition, HplFieldReference, HplPublishStatement,
        HplTimeBound, HplLiteral)
    from .ros_types import (TypeToken, ArrayTypeToken)

    TEST_DATA = {
        "geometry_msgs/Twist": {
            "linear": TypeToken("geometry_msgs/Vector3"),
            "angular": TypeToken("geometry_msgs/Vector3")
        },
        "geometry_msgs/Vector3": {
            "x": TypeToken("float64"),
            "y": TypeToken("float64"),
            "z": TypeToken("float64")
        },
        "kobuki_msgs/BumperEvent": {
            "bumper": TypeToken("uint8"),
            "state": TypeToken("uint8")
        },
        "pkg/Msg": {
            "int": TypeToken("int32"),
            "float": TypeToken("float64"),
            "string": TypeToken("string"),
            "twist": TypeToken("geometry_msgs/Twist"),
            "int_list": ArrayTypeToken("int32"),
github git-afsantos / haros / haros / hpl / test_generator.py View on Github external
"angular": TypeToken("geometry_msgs/Vector3")
        },
        "geometry_msgs/Vector3": {
            "x": TypeToken("float64"),
            "y": TypeToken("float64"),
            "z": TypeToken("float64")
        },
        "kobuki_msgs/BumperEvent": {
            "bumper": TypeToken("uint8"),
            "state": TypeToken("uint8")
        },
        "pkg/Msg": {
            "int": TypeToken("int32"),
            "float": TypeToken("float64"),
            "string": TypeToken("string"),
            "twist": TypeToken("geometry_msgs/Twist"),
            "int_list": ArrayTypeToken("int32"),
            "int_array": ArrayTypeToken("int32", length=3),
            "float_list": ArrayTypeToken("float64"),
            "float_array": ArrayTypeToken("float64", length=3),
            "string_list": ArrayTypeToken("string"),
            "string_array": ArrayTypeToken("string", length=3),
            "twist_list": ArrayTypeToken("geometry_msgs/Twist"),
            "twist_array": ArrayTypeToken("geometry_msgs/Twist", length=3),
            "nested_array": ArrayTypeToken("pkg/Nested", length=3)
        },
        "pkg/Nested": {
            "int": TypeToken("int32"),
            "int_array": ArrayTypeToken("int32", length=3),
            "nested_array": ArrayTypeToken("pkg/Nested2", length=3)
        },
        "pkg/Nested2": {
github git-afsantos / haros / haros / hpl / test_generator.py View on Github external
"linear": TypeToken("geometry_msgs/Vector3"),
            "angular": TypeToken("geometry_msgs/Vector3")
        },
        "geometry_msgs/Vector3": {
            "x": TypeToken("float64"),
            "y": TypeToken("float64"),
            "z": TypeToken("float64")
        },
        "kobuki_msgs/BumperEvent": {
            "bumper": TypeToken("uint8"),
            "state": TypeToken("uint8")
        },
        "pkg/Msg": {
            "int": TypeToken("int32"),
            "float": TypeToken("float64"),
            "string": TypeToken("string"),
            "twist": TypeToken("geometry_msgs/Twist"),
            "int_list": ArrayTypeToken("int32"),
            "int_array": ArrayTypeToken("int32", length=3),
            "float_list": ArrayTypeToken("float64"),
            "float_array": ArrayTypeToken("float64", length=3),
            "string_list": ArrayTypeToken("string"),
            "string_array": ArrayTypeToken("string", length=3),
            "twist_list": ArrayTypeToken("geometry_msgs/Twist"),
            "twist_array": ArrayTypeToken("geometry_msgs/Twist", length=3),
            "nested_array": ArrayTypeToken("pkg/Nested", length=3)
        },
        "pkg/Nested": {
            "int": TypeToken("int32"),
            "int_array": ArrayTypeToken("int32", length=3),
            "nested_array": ArrayTypeToken("pkg/Nested2", length=3)
        },
github git-afsantos / haros / haros / hpl / hypothesis_strategies.py View on Github external
# Test Code
################################################################################

if __name__ == "__main__":
    TEST_DATA = {
        "geometry_msgs/Twist": {
            "linear": TypeToken("geometry_msgs/Vector3"),
            "angular": TypeToken("geometry_msgs/Vector3")
        },
        "geometry_msgs/Vector3": {
            "x": TypeToken("float64"),
            "y": TypeToken("float64"),
            "z": TypeToken("float64")
        },
        "kobuki_msgs/BumperEvent": {
            "bumper": TypeToken("uint8"),
            "state": TypeToken("uint8")
        },
        "pkg/Msg": {
            "int": TypeToken("int32"),
            "float": TypeToken("float64"),
            "string": TypeToken("string"),
            "twist": TypeToken("geometry_msgs/Twist"),
            "int_list": ArrayTypeToken("int32"),
            "int_array": ArrayTypeToken("int32", length=3),
            "float_list": ArrayTypeToken("float64"),
            "float_array": ArrayTypeToken("float64", length=3),
            "string_list": ArrayTypeToken("string"),
            "string_array": ArrayTypeToken("string", length=3),
            "twist_list": ArrayTypeToken("geometry_msgs/Twist"),
            "twist_array": ArrayTypeToken("geometry_msgs/Twist", length=3),
            "nested_array": ArrayTypeToken("pkg/Nested", length=3)
github git-afsantos / haros / haros / hpl / parser.py View on Github external
}
    }

    TEST_CONSTANTS = {
        "geometry_msgs/Twist": {},
        "geometry_msgs/Vector3": {},
        "kobuki_msgs/BumperEvent": {
            "LEFT": (0, TypeToken("uint8")),
            "CENTER": (1, TypeToken("uint8")),
            "RIGHT": (2, TypeToken("uint8")),
            "RELEASED": (0, TypeToken("uint8")),
            "PRESSED": (1, TypeToken("uint8"))
        },
        "pkg/Msg": {
            "INT": (42, TypeToken("int32")),
            "FLOAT": (3.141592, TypeToken("float64")),
            "STRING": ("Hello, World!", TypeToken("string"))
        },
        "pkg/Nested": {
            "INT": (42, TypeToken("int32")),
            "FLOAT": (3.141592, TypeToken("float64")),
            "STRING": ("Hello, World!", TypeToken("string"))
        },
        "pkg/Nested2": {}
    }

    TEST_TOPICS = {
        "topic": "pkg/Msg",
        "~events/bumper": "kobuki_msgs/BumperEvent",
        "~cmd_vel": "geometry_msgs/Twist"
    }
github git-afsantos / haros / haros / hpl / ros_types.py View on Github external
for field_name, field_type in type_token.fields.items():
                    n = "{}.{}".format(name, field_name)
                    stack.append((n, field_type))
            elif type_token.is_array:
                arrays[name] = type_token
            else:
                assert type_token.is_primitive
                primitives[name] = type_token
        return primitives, arrays

    def __repr__(self):
        return "{}({}, {}, constants={})".format(type(self).__name__,
            repr(self.type_name), repr(self.fields), repr(self.constants))


class ArrayType(TypeToken):
    __slots__ = ("type_token", "length")

    def __init__(self, type_token, length=None):
        # type_token :: TypeToken
        # length :: int >= 0
        self.type_token = type_token
        self.length = length

    @property
    def type_name(self):
        return self.type_token.type_name

    @property
    def is_builtin(self):
        return self.type_token.is_builtin
github git-afsantos / haros / haros / hpl / parser.py View on Github external
"int_array": ArrayTypeToken("int32", length=3)
        }
    }

    TEST_CONSTANTS = {
        "geometry_msgs/Twist": {},
        "geometry_msgs/Vector3": {},
        "kobuki_msgs/BumperEvent": {
            "LEFT": (0, TypeToken("uint8")),
            "CENTER": (1, TypeToken("uint8")),
            "RIGHT": (2, TypeToken("uint8")),
            "RELEASED": (0, TypeToken("uint8")),
            "PRESSED": (1, TypeToken("uint8"))
        },
        "pkg/Msg": {
            "INT": (42, TypeToken("int32")),
            "FLOAT": (3.141592, TypeToken("float64")),
            "STRING": ("Hello, World!", TypeToken("string"))
        },
        "pkg/Nested": {
            "INT": (42, TypeToken("int32")),
            "FLOAT": (3.141592, TypeToken("float64")),
            "STRING": ("Hello, World!", TypeToken("string"))
        },
        "pkg/Nested2": {}
    }

    TEST_TOPICS = {
        "topic": "pkg/Msg",
        "~events/bumper": "kobuki_msgs/BumperEvent",
        "~cmd_vel": "geometry_msgs/Twist"
    }
github git-afsantos / haros / haros / hpl / ros_types.py View on Github external
def __eq__(self, other):
        if not isinstance(other, TypeToken):
            return False
        return self.type_name == other.type_name
github git-afsantos / haros / haros / hpl / parser.py View on Github external
"nested_array": ArrayTypeToken("pkg/Nested2", length=3)
        },
        "pkg/Nested2": {
            "int": TypeToken("int32"),
            "int_array": ArrayTypeToken("int32", length=3)
        }
    }

    TEST_CONSTANTS = {
        "geometry_msgs/Twist": {},
        "geometry_msgs/Vector3": {},
        "kobuki_msgs/BumperEvent": {
            "LEFT": (0, TypeToken("uint8")),
            "CENTER": (1, TypeToken("uint8")),
            "RIGHT": (2, TypeToken("uint8")),
            "RELEASED": (0, TypeToken("uint8")),
            "PRESSED": (1, TypeToken("uint8"))
        },
        "pkg/Msg": {
            "INT": (42, TypeToken("int32")),
            "FLOAT": (3.141592, TypeToken("float64")),
            "STRING": ("Hello, World!", TypeToken("string"))
        },
        "pkg/Nested": {
            "INT": (42, TypeToken("int32")),
            "FLOAT": (3.141592, TypeToken("float64")),
            "STRING": ("Hello, World!", TypeToken("string"))
        },
        "pkg/Nested2": {}
    }

    TEST_TOPICS = {