Package api.basic

Class Hexapode


  • public class Hexapode
    extends java.lang.Object
    Lowest-level class to control the hexapod directly by sending commands.

    This is the base class used by all classes of this API to access the hardware.
    There may only be one shared instance of this class. You can get it by calling getInstance() on this class.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static boolean DEBUGGING
      Set this boolean to true to print additional error information and stack traces to the console.
      static int[][] PIN_MAPPING
      WARNING: The PINS must not have IDs below 0!
      static double[] POS_MULTIP  
    • Method Summary

      Modifier and Type Method Description
      static java.lang.String applyPINMapping​(java.lang.String command)
      Apply pin-mapping to a given String
      static java.lang.String applyPositionMapping​(java.lang.String command)
      Apply position-mapping to a given String
      (Scale the positions of legs as defined in the pinConfig file)
      void connectToDevServer​(java.lang.String hostname)
      Connect to a running DevServer using the default port (4444)
      void connectToDevServer​(java.lang.String hostname, int port)
      Connect to a running DevServer
      void exec​(java.lang.String command)
      Execute a command and apply PIN-mapping
      static Hexapode getClient()
      Like getInstance, but forces the returned instance to be in client-mode
      Note: This method must be called before calling getInstance()
      static Hexapode getInstance()
      Get the shared instance of this Singleton
      boolean isClient()
      Get a boolean whether this instance is a client and must be connected to a DevServer to work
      Note: You can not change the mode (client-mode or local-mode) of an instance once it has been created.
      void moveServo​(int servo, int pos, int timeMillis)
      Wrapper class to execute a simple command
      void serialCommand​(java.lang.String command)
      Directly executes a command.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • PIN_MAPPING

        public static final int[][] PIN_MAPPING
        WARNING: The PINS must not have IDs below 0!
        The array containing a list of mapped pins

        PIN_MAPPING[index][0] contains the original pin on the board and PIN_MAPPING[index][1] contains an alternative pin that can be used instead.
        Tip: You can still use the original "hardware" pin number if no other pin is mapped to it.

        See Also:
        PINConfig, PINConstants
      • POS_MULTIP

        public static final double[] POS_MULTIP
      • DEBUGGING

        public static boolean DEBUGGING
        Set this boolean to true to print additional error information and stack traces to the console.
    • Method Detail

      • getInstance

        public static Hexapode getInstance()
        Get the shared instance of this Singleton
        Returns:
        An instance of this class
        See Also:
        getClient()
      • getClient

        public static Hexapode getClient()
                                  throws java.lang.IllegalStateException
        Like getInstance, but forces the returned instance to be in client-mode
        Note: This method must be called before calling getInstance()
        Returns:
        An instance of this class using the DevServer
        Throws:
        java.lang.IllegalStateException - If getInstance has been called before and already created a local (non-client) instance of the Singleton
        See Also:
        getInstance()
      • exec

        public void exec​(java.lang.String command)
        Execute a command and apply PIN-mapping
        Parameters:
        command - The command to be executed
        See Also:
        applyPINMapping(String)
      • applyPINMapping

        public static java.lang.String applyPINMapping​(java.lang.String command)
        Apply pin-mapping to a given String
        Parameters:
        command - The command which pin-mapping should be applied to
        Returns:
        The command after pin-mapping has been applied
      • applyPositionMapping

        public static java.lang.String applyPositionMapping​(java.lang.String command)
        Apply position-mapping to a given String
        (Scale the positions of legs as defined in the pinConfig file)
        Parameters:
        command - The command which position-mapping should be applied to
        Returns:
        The command after position-mapping has been applied
      • moveServo

        public void moveServo​(int servo,
                              int pos,
                              int timeMillis)
        Wrapper class to execute a simple command

        To execute more complex commands use Bundles.

        Parameters:
        servo - The pin of the servo to move
        pos - The position the servo should move to
        timeMillis - The time the servo will need to reach the targeted position
        See Also:
        Example1
      • connectToDevServer

        public void connectToDevServer​(java.lang.String hostname)
                                throws java.net.UnknownHostException,
                                       java.io.IOException,
                                       java.lang.IllegalStateException
        Connect to a running DevServer using the default port (4444)
        Parameters:
        hostname - The hostname of the host to connect to
        Throws:
        java.net.UnknownHostException - Thrown by the Socket contructor
        java.io.IOException - Thrown by the Socket contructor
        java.lang.IllegalStateException - If this method is called on a local (non-client) instance
        Tip: You can force the instance to be a client instance by calling getClient() the first time you want to get an instance of this class.
        See Also:
        getClient()
      • connectToDevServer

        public void connectToDevServer​(java.lang.String hostname,
                                       int port)
                                throws java.net.UnknownHostException,
                                       java.io.IOException,
                                       java.lang.IllegalStateException
        Connect to a running DevServer
        Parameters:
        hostname - The hostname of the host to connect to
        port - The port to connect to
        Throws:
        java.net.UnknownHostException - Thrown by the Socket contructor
        java.io.IOException - Thrown by the Socket contructor
        java.lang.IllegalStateException - If this method is called on a local (non-client) instance
        Tip: You can force the instance to be a client instance by calling getClient() the first time you want to get an instance of this class.
        See Also:
        getClient()
      • isClient

        public boolean isClient()
        Get a boolean whether this instance is a client and must be connected to a DevServer to work
        Note: You can not change the mode (client-mode or local-mode) of an instance once it has been created.
        Returns:
        Whether this instance is in client-mode
        See Also:
        getInstance(), getClient()