org.robokind.api.motion.utils
Class RobotUtils

java.lang.Object
  extended by org.robokind.api.motion.utils.RobotUtils

public class RobotUtils
extends Object

Common Utility methods for the Motion API

Author:
Matthew Stevenson

Field Summary
static long DEFAULT_BLENDER_INTERVAL
          Default milliseconds for a Blender interval
 
Constructor Summary
RobotUtils()
           
 
Method Summary
static Map<Integer,Double> convertMap(Robot.RobotPositionMap posMap)
          Converts a RobotPositionMap to a Map of Integers to Doubles.
static Robot.RobotPositionMap getCurrentPositions(org.osgi.framework.BundleContext context, Robot.Id robotId)
          Returns a RobotPositionMap of the current positions for the Robot with the given Id.
static Robot.RobotPositionMap getDefaultPositions(org.osgi.framework.BundleContext context, Robot.Id robotId)
          Returns a RobotPositionMap of the default positions for the Robot with the given Id.
static Robot.RobotPositionMap getGoalPositions(org.osgi.framework.BundleContext context, Robot.Id robotId)
          Returns a RobotPositionMap of the goal positions for the Robot with the given Id.
static String getRobotFilter(Robot.Id robotId)
          Returns an OSGi filter String for matching the given Robot.Id.
static String getRobotFilter(Robot.Id robotId, String serviceFilter)
          Returns an OSGi filter String for matching the given Robot.Id.
static RobotManager getRobotManager(org.osgi.framework.BundleContext context)
          Returns a global RobotManager.
static org.osgi.framework.ServiceReference getRobotReference(org.osgi.framework.BundleContext context, Robot.Id robotId)
          Finds ServiceReferences for a Robot with the given id.
static boolean isRobotIdAvailable(org.osgi.framework.BundleContext context, Robot.Id robotId)
          Checks if the given robotId is available to use.
static void launchDefaultBlender(org.osgi.framework.BundleContext context, Robot.Id robotId, long blenderIntervalMsec)
           
static org.osgi.framework.ServiceRegistration registerFrameSource(org.osgi.framework.BundleContext context, Robot.Id robotId, FrameSource frameSource)
          Registers a FrameSource using the given Robot.Id as a property.
static org.osgi.framework.ServiceRegistration registerRobot(org.osgi.framework.BundleContext context, Robot robot, Properties props)
          Adds a Robot to the OSGi ServiceRegistry with the robotId as a service property.
static org.osgi.framework.ServiceRegistration[] startDefaultBlender(org.osgi.framework.BundleContext context, Robot.Id robotId, long blenderIntervalMsec)
          Creates a DefaultBlender for the Robot with the given robotId.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BLENDER_INTERVAL

public static final long DEFAULT_BLENDER_INTERVAL
Default milliseconds for a Blender interval

See Also:
Constant Field Values
Constructor Detail

RobotUtils

public RobotUtils()
Method Detail

getCurrentPositions

public static Robot.RobotPositionMap getCurrentPositions(org.osgi.framework.BundleContext context,
                                                         Robot.Id robotId)
Returns a RobotPositionMap of the current positions for the Robot with the given Id. If supported, this will communicate with the Joints themselves to get the current positions

Parameters:
context - BundleContext used to locate the robot
robotId - identifies the Robot to use
Returns:
RobotPositionMap of the current Positions for the Robot with the given Id

getGoalPositions

public static Robot.RobotPositionMap getGoalPositions(org.osgi.framework.BundleContext context,
                                                      Robot.Id robotId)
Returns a RobotPositionMap of the goal positions for the Robot with the given Id.

Parameters:
context - BundleContext used to locate the robot
robotId - identifies the Robot to use
Returns:
RobotPositionMap of the current Positions for the Robot with the given Id

getDefaultPositions

public static Robot.RobotPositionMap getDefaultPositions(org.osgi.framework.BundleContext context,
                                                         Robot.Id robotId)
Returns a RobotPositionMap of the default positions for the Robot with the given Id.

Parameters:
context - BundleContext used to locate the robot
robotId - identifies the Robot to use
Returns:
RobotPositionMap of the default Positions for the Robot with the given Id

isRobotIdAvailable

public static boolean isRobotIdAvailable(org.osgi.framework.BundleContext context,
                                         Robot.Id robotId)
Checks if the given robotId is available to use. Returns true if the robotId is not found in the OSGi Service Registry.

Parameters:
context - BundleContext to use
robotId - Robot.Id to check
Returns:
true if the robotId is not found in the OSGi Service Registry

registerRobot

public static org.osgi.framework.ServiceRegistration registerRobot(org.osgi.framework.BundleContext context,
                                                                   Robot robot,
                                                                   Properties props)
Adds a Robot to the OSGi ServiceRegistry with the robotId as a service property. Returns the ServiceRegistration object or null if unable to register.

Parameters:
context - BundleContext to use
robot - Robot to register
props - option service properties to add to the registration
Returns:
ServiceRegistration object or null if unable to register

getRobotReference

public static org.osgi.framework.ServiceReference getRobotReference(org.osgi.framework.BundleContext context,
                                                                    Robot.Id robotId)
Finds ServiceReferences for a Robot with the given id. Returns null if a ServiceReference could not be found. The ServiceReference can be used to fetch the registered robot using context.getService(serviceReference). This should be followed with context.ungetService(serviceReference) when finished using the Robot. Runtime Exceptions should be expected when working with a ServiceReference as the Service can be unregistered at any time.

Parameters:
context - BundleContext used to retrieve a ServiceReference
robotId - the id to filter by
Returns:
ServiceReference to a Robot with a matching id, or null if a robot is not found.
Throws:
NullPointerException - if context or robotId are null
IllegalArgumentException - if robotId is empty

startDefaultBlender

public static org.osgi.framework.ServiceRegistration[] startDefaultBlender(org.osgi.framework.BundleContext context,
                                                                           Robot.Id robotId,
                                                                           long blenderIntervalMsec)
Creates a DefaultBlender for the Robot with the given robotId. The Blender runs on a timer with the given interval in milliseconds. If existing components are already registered, this will fail and return null.

Parameters:
context - BundleContext to use
robotId - Robot.Id to use
blenderIntervalMsec - Blender timer interval
Returns:
array of ServiceRegistrations from adding Blender components to the OSGi Service Registry, these are used to unregister the components if needed

launchDefaultBlender

public static void launchDefaultBlender(org.osgi.framework.BundleContext context,
                                        Robot.Id robotId,
                                        long blenderIntervalMsec)

registerFrameSource

public static org.osgi.framework.ServiceRegistration registerFrameSource(org.osgi.framework.BundleContext context,
                                                                         Robot.Id robotId,
                                                                         FrameSource frameSource)
Registers a FrameSource using the given Robot.Id as a property.

Parameters:
context - BundleContext to use
robotId - Robot.Id to associate with the FrameSource
frameSource - FrameSource to register
Returns:
ServiceRegistration for this FrameSource, this is used to unregister the FrameSource

getRobotFilter

public static String getRobotFilter(Robot.Id robotId)
Returns an OSGi filter String for matching the given Robot.Id.

Parameters:
robotId - the Robot.Id to match
Returns:
OSGi filter String for matching the given Robot.Id

getRobotFilter

public static String getRobotFilter(Robot.Id robotId,
                                    String serviceFilter)
Returns an OSGi filter String for matching the given Robot.Id. If serviceFilter is not null, the return filter String will match that filter as well.

Parameters:
robotId - Robot.Id to match
serviceFilter - addition filter to match
Returns:
filter string matching the Robot.Id and given serviceFilter

convertMap

public static Map<Integer,Double> convertMap(Robot.RobotPositionMap posMap)
Converts a RobotPositionMap to a Map of Integers to Doubles. If the Robot contains Joints with duplicate Joint Ids, the size of the RobotPositionMap will be added to the id until it is unique.

Parameters:
posMap - RobotPositionMap to convert
Returns:
Map of Integer ids to Doubles

getRobotManager

public static RobotManager getRobotManager(org.osgi.framework.BundleContext context)
Returns a global RobotManager. The RobotManager is retrieved from the OSGi Service Registry.

Parameters:
context - BundleContext for OSGi
Returns:
global RobotManager


Copyright © 2011-2013. All Rights Reserved.