Constants

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:

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

Example code excerpts demonstrating the use of enums:

# Get the joint names from the robot_info data structure
joint_names = [j.joint_identifier.name for j in robot_info.joint_info]

# Retrieve the current robot state and print the current command mode
print(c.robot_state.PeekInValue()[0].command_mode)

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:

object Create
	constant double DRIVE_STRAIGHT 32.767
	constant double SPIN_CLOCKWISE -1e-3
	constant double SPIN_COUNTERCLOCKWISE 1e-3
end

Example code excerpts demonstrating the use of constants:

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']