dlife.robot.util.kteam
Class KTeamSerialDelegate
java.lang.Object
dlife.robot.util.kteam.KTeamSerialDelegate
- All Implemented Interfaces:
- KTeamCommDelegate
public class KTeamSerialDelegate
- extends Object
- implements KTeamCommDelegate
Delegate for communicating with a KTeam robot (e.g. Hemisson / Khepera II)
via a serial device file (e.g. /dev/ttys0)..
When establishConnection is invoked it attempts to start a
SerialToTCP server running on the local host on port 10000. For
this to work a compiled version of the SerialToTCP server must
reside in the dLifeDist/native where dlife is the
distribution directory that contains the dlife.jar file.
Commands sent to the robot are transmitted to
the server via a TCP socket connection. The server then issues the commands
to the robot via the serial device file. The server returns any responses
from the robot via the TCP connection.
Note: On some machines the IP of the local host must be resolvable. If this is
a problem and the machine is not in a DNS then add its ip and name to the /etc/hosts file.
- Version:
- Jan 12, 2011
- Author:
- Grant Braught, Dickinson College
|
Constructor Summary |
KTeamSerialDelegate(String devFilename,
String robotType)
Construct a new KTeamSerialDelegate using the specified device file to
communicate with the robot. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
KTeamSerialDelegate
public KTeamSerialDelegate(String devFilename,
String robotType)
- Construct a new KTeamSerialDelegate using the specified device file to
communicate with the robot. This constructor also attempts to
start the SerialToTCPxxx server that is used for the communications.
Note: If this constructor is called from a junit test then the
devFilename is ignored and the SerialToTCPxxx server is not started. It
is assumed that the test code will have started a mock server for testing
purposes.
- Parameters:
devFilename - the device file to use for the serial communications.robotType - a string name for the type of robot being connected to. This
is used when generating status and error messages.
establishConnection
public void establishConnection()
- Establish a connection to the robot via a SerialToTCP server.
- Specified by:
establishConnection in interface KTeamCommDelegate
- Throws:
RobotCommunicationException - if unable to establish communication
with the SerialToTCPxxx server.
closeConnection
public void closeConnection()
- Close the connection to the Hemisson. This includes terminating the
SerialToTCP server if it is running.
- Specified by:
closeConnection in interface KTeamCommDelegate
- Throws:
RobotCommunicationException - if unable to close the connection to
the Hemisson.
sendMessage
public String sendMessage(String message,
int delay)
- Send a message to the robot via the serial interface. The message is
sent and this method waits up to "delay" ms for a response. If no response is
received during this delay, or the response is an error message from the
robot then the message is resent. If the message is resent 3 times it is
assumed that communication with the robot has been lost and an exception
is thrown.
This method is included to allow sensors to wait for longer
periods of time when necessary (e.g. sonar echos).
- Specified by:
sendMessage in interface KTeamCommDelegate
- Parameters:
message - the message to be sent. This method appends a CR character
to the end of the message as is expected by the robot.delay - the number of milliseconds to wait before checking for
responses.
- Returns:
- the response from the robot.
- Throws:
RobotCommunicationException - if unable to communicate with the
robot.