File: Constants.rst

package info (click to toggle)
robotraconteur 1.2.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 101,380 kB
  • sloc: cpp: 1,149,268; cs: 87,653; java: 58,127; python: 26,897; ansic: 356; sh: 152; makefile: 90; xml: 51
file content (131 lines) | stat: -rw-r--r-- 4,375 bytes parent folder | download
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
131
.. _constants:

=========
Constants
=========

.. contents:: Table of Contents
   :depth: 1
   :local:
   :backlinks: none

Overview
========

Robot Raconteur defines two types of constants: ``enum`` and ``const``. An ``enum`` is a set of named integer
constants, while a ``const`` is a named constant of a specific type.
Constants are made available to clients when they connect to a service, or are generated
as part of "thunk" code for statically typed languages.

Enum Types
==========

Enums are defined using the ``enum`` keyword.

The following is an example of an enum definition from ``com.robotraconteur.robotics.robot`` service definition:

.. code-block::

    enum RobotCommandMode
        invalid_state = -1,
        halt = 0,
        jog,
        trajectory,
        position_command,
        velocity_command,
        homing
    end

Example code excerpts demonstrating the use of enums:

.. tabs::

    .. group-tab:: Python

        .. literalinclude:: ../../../examples/standard_devices/robot/python/robot_client_trajectory.py
            :language: python
            :lines: 21-26

    .. group-tab:: MATLAB

        .. code-block::

            c = RobotRaconteur.ConnectService(url);
            robot_const = RobotRaconteur.GetConstants(c,'com.robotraconteur.robotics.robot');
            robot_command_mode = robot_const.RobotCommandMode;
            halt_mode = robot_command_mode.halt;
            position_command_mode = robot_command_mode.position_command;

    .. group-tab:: LabView

        LabView does not support retrieving constants from service definitions. Use the values directly in your code.

    .. group-tab:: C\#

        .. literalinclude:: ../../../examples/standard_devices/robot/cs/robot_client_trajectory.cs
            :language: csharp
            :lines: 38-41

    .. group-tab:: C++

        .. literalinclude:: ../../../examples/standard_devices/robot/cpp/robot_client_trajectory.cpp
            :language: cpp
            :lines: 35-38

Constants
=========

Constants are declared using the ``const`` keyword. Constants can be numbers, numeric arrays, or strings.
Strings can use JSON encoding to represent special characters. ``const`` can be defined at the service level or within
an object.

Constants are accessed the same way as enums, but there is a single value.

The following is an example of a constant definition from the ``experimental.create3.Create`` object:

.. literalinclude:: ../../../examples/irobot_create/robdef/experimental.create3.robdef
    :lines: 39-42,62

Example code excerpts demonstrating the use of constants:

.. tabs::

    .. group-tab:: Python

        .. code-block:: python

            c = RRN.ConnectService(url)
            create_const = RobotRaconteur.GetConstants('experimental.create3.Create',c)
            drive_straight = create_const['Create']['DRIVE_STRAIGHT']
            spin_clockwise = create_const['Create']['SPIN_CLOCKWISE']
            spin_counterclockwise = create_const['Create']['SPIN_COUNTERCLOCKWISE']

    .. group-tab:: MATLAB

        .. code-block::

            c = RobotRaconteur.ConnectService(url);
            robot_const = RobotRaconteur.GetConstants(c,'com.robotraconteur.robotics.robot');
            drive_straight = robot_const.Create.DRIVE_STRAIGHT;
            spin_clockwise = robot_const.Create.SPIN_CLOCKWISE;
            spin_counterclockwise = robot_const.Create.SPIN_COUNTERCLOCKWISE;

    .. group-tab:: LabView

        LabView does not support retrieving constants from service definitions. Use the values directly in your code.

    .. group-tab:: C\#

        .. code-block:: csharp

            var drive_straight = experimental.create3..Create.experimental__create3Constants.DRIVE_STRAIGHT;
            var spin_clockwise = experimental.create3.Create.experimental__create3Constants.SPIN_CLOCKWISE;
            var spin_counterclockwise = experimental.create3.Create.experimental__create3Constants.SPIN_COUNTERCLOCKWISE;

    .. group-tab:: C++

        .. code-block:: cpp

            auto drive_straight = experimental::create3::experimental__create3Constants::Create::DRIVE_STRAIGHT;
            auto spin_clockwise = experimental::create3::experimental__create3Constants::Create::SPIN_CLOCKWISE;
            auto spin_counterclockwise = experimental::create3::experimental__create3Constants::Create::SPIN_COUNTERCLOCKWISE;