Package api.basic
Class Hexapode
- java.lang.Object
-
- api.basic.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 callinggetInstance()
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 Stringstatic 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 runningDevServer
using the default port (4444)void
connectToDevServer(java.lang.String hostname, int port)
Connect to a runningDevServer
void
exec(java.lang.String command)
Execute a command and apply PIN-mappingstatic Hexapode
getClient()
LikegetInstance
, but forces the returned instance to be in client-mode
Note: This method must be called before callinggetInstance()
static Hexapode
getInstance()
Get the shared instance of this Singletonboolean
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 commandvoid
serialCommand(java.lang.String command)
Directly executes a command.
-
-
-
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 andPIN_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
LikegetInstance
, but forces the returned instance to be in client-mode
Note: This method must be called before callinggetInstance()
- 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()
-
serialCommand
public void serialCommand(java.lang.String command)
Directly executes a command.Note: This method does not use the PIN-mapping
- Parameters:
command
- The command to be executed- See Also:
Execute a command with applied PIN-mapping
-
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 commandTo execute more complex commands use
Bundles
.- Parameters:
servo
- The pin of the servo to movepos
- The position the servo should move totimeMillis
- 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 runningDevServer
using the default port (4444)- Parameters:
hostname
- The hostname of the host to connect to- Throws:
java.net.UnknownHostException
- Thrown by theSocket contructor
java.io.IOException
- Thrown by theSocket 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 callinggetClient()
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 runningDevServer
- Parameters:
hostname
- The hostname of the host to connect toport
- The port to connect to- Throws:
java.net.UnknownHostException
- Thrown by theSocket contructor
java.io.IOException
- Thrown by theSocket 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 callinggetClient()
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()
-
-