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)
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;
LabView does not support retrieving constants from service definitions. Use the values directly in your code.
// Change the robot command mode, first to halt, then to trajectory
c.command_mode = RobotCommandMode.halt;
Thread.Sleep(100);
c.command_mode = RobotCommandMode.trajectory;
// Use RobotRaconteur::NodeSetup to initialize Robot Raconteur
// In this example we only use standard types so no generated types are required
RR::ClientNodeSetup node_setup(std::vector<RR::ServiceFactoryPtr>(), argc, argv);
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']
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;
LabView does not support retrieving constants from service definitions. Use the values directly in your code.
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;
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_COUNTERCCLOCKWISE;