rp1.rossum
Class RsClient
java.lang.Object
rp1.rossum.RsProtocol
rp1.rossum.RsClient
- All Implemented Interfaces:
- java.lang.Runnable, RsLogInterface, RsRunnable
public class RsClient
- extends RsProtocol
- implements RsRunnable, RsLogInterface
The main class for connecting a client-side application to the
simulator.
Note that even though this class implements Runnable (through RsRunnable),
an application does not necessarily have to launch it as an independent thread.
For example, an object of type
RsClient might just be an element in another class which does, itself,
extend Thread. The run method and Runnable interface is provided both as
documentation and as a convenience.
In general, the methods in this class are organized as follows:
- Send methods -- send requests (control sequences) to simulator
- Add methods -- allow an application to add event handlers
- Initialization and run methods
- Miscelaneous utilities
In implementing an RP1 client, it is often useful to write a client class that
extends RsClient. This is not, of course, the only approach to building an RP1
client, but is a good way of taking advantage of Java's object-oriented capabilities.
The sequence for establishing an RP1 client is discussed extensively
in the RP1 Users Guide.
This class will not prevent you from sending a request for an event when you have
no event handler registered. When the requested, but non-handled, event comes
in, it will be ignored.
Method Summary |
void |
addContactSensorEventHandler(RsBodyContactSensor sensor,
RsContactSensorEventHandler reference)
|
void |
addEncoderStatusEventHandler(RsEncoderStatusEventHandler reference)
|
void |
addHeartbeatEventHandler(RsHeartbeatEventHandler reference)
|
void |
addMotionHaltedEventHandler(RsMotionHaltedEventHandler reference)
|
void |
addMotionStartedEventHandler(RsMotionStartedEventHandler reference)
|
void |
addMouseClickEventHandler(RsMouseClickEventHandler reference)
|
void |
addPaintSensorEventHandler(RsBodyPaintSensor sensor,
RsPaintSensorEventHandler reference)
|
void |
addPlacementEventHandler(RsPlacementEventHandler reference)
|
void |
addPlanEventHandler(RsPlanEventHandler reference)
|
void |
addPositionEventHandler(RsPositionEventHandler reference)
|
void |
addRangeSensorEventHandler(RsBodyRangeSensor sensor,
RsRangeSensorEventHandler reference)
|
void |
addTargetSelectionEventHandler(RsTargetSelectionEventHandler reference)
|
void |
addTargetSensorEventHandler(RsBodyTargetSensor sensor,
RsTargetSensorEventHandler reference)
|
void |
addTimeoutEventHandler(RsTimeoutEventHandler reference)
|
RsProperties |
getProperties()
|
double |
getSimTime()
returns the simulation time based on the most recent communications
from the simulator. |
void |
initialize()
The initialize call is used to set up the RP1 client before the run() method
is invoked. |
void |
initialize(RsProperties rsp)
This version of initialize allows the application to supply alternate
properties specifications rather than reading them from rossum.ini
as the standard initialize method does |
void |
initiateConnection(RsProperties properties)
|
void |
initiateLogger(RsProperties properties)
|
void |
removeContactSensorEventHandler(RsBodyContactSensor sensor)
|
void |
removeContactSensorEventHandler(RsBodyContactSensor sensor,
RsContactSensorEventHandler reference)
|
void |
removeEncoderStatusEventHandler()
|
void |
removeEncoderStatusEventHandler(RsEncoderStatusEventHandler reference)
|
void |
removeHeartbeatEventHandler()
|
void |
removeHeartbeatEventHandler(RsHeartbeatEventHandler reference)
|
void |
removeMotionHaltedEventHandler()
|
void |
removeMotionHaltedEventHandler(RsMotionStartedEventHandler reference)
|
void |
removeMotionStartedEventHandler()
|
void |
removeMotionStartedEventHandler(RsMotionStartedEventHandler reference)
|
void |
removeMouseClickEventHandler()
|
void |
removeMouseClickEventHandler(RsMouseClickEventHandler reference)
|
void |
removePaintSensorEventHandler(RsBodyPaintSensor sensor)
|
void |
removePaintSensorEventHandler(RsBodyPaintSensor sensor,
RsPaintSensorEventHandler reference)
|
void |
removePlacementEventHandler()
|
void |
removePlacementEventHandler(RsPlacementEventHandler reference)
|
void |
removePlanEventHandler()
|
void |
removePlanEventHandler(RsPlanEventHandler reference)
|
void |
removePositionEventHandler()
|
void |
removePositionEventHandler(RsPositionEventHandler reference)
|
void |
removeRangeSensorEventHandler(RsBodyRangeSensor sensor)
|
void |
removeRangeSensorEventHandler(RsBodyRangeSensor sensor,
RsRangeSensorEventHandler reference)
|
void |
removeTargetSelectionEventHandler()
|
void |
removeTargetSelectionEventHandler(RsTargetSelectionEventHandler reference)
|
void |
removeTargetSensorEventHandler(RsBodyTargetSensor sensor)
|
void |
removeTargetSensorEventHandler(RsBodyTargetSensor sensor,
RsTargetSensorEventHandler reference)
|
void |
removeTimeoutEventHandler()
|
void |
removeTimeoutEventHandler(RsTimeoutEventHandler reference)
|
void |
run()
|
void |
sendActuatorControlRequest(RsActuatorControlRequest r)
|
void |
sendAllTargetsSelectionRequest(boolean status)
|
void |
sendBodySpecification(RsBody body)
The sendBodySpecification sends the body specification to the simulator
and absolutely must be invoked before any requests are sent to RP1. |
int |
sendEncoderStatusRequest(RsEncoder[] encoders,
boolean clearOnRequest)
sends an request for the status of one or more encoders (given in array). |
int |
sendEncoderStatusRequest(RsEncoder encoder,
boolean clearOnRequest)
sends a request for the status of a single encoder. |
void |
sendExclusiveRandomTargetSelectionRequest()
|
void |
sendExclusiveTargetSelectionRequest(java.lang.String targetName)
|
void |
sendHaltRequest()
|
void |
sendHeartbeatCancellationRequest()
|
void |
sendHeartbeatRequest(double period)
Activates the "heartbeat" function in RP1. |
void |
sendMotionRequest(RsMotionRequest r)
|
void |
sendPainterActivationRequest(RsBodyPainter painter)
|
void |
sendPainterDeactivationRequest(RsBodyPainter painter)
|
void |
sendPainterErasureRequest(RsBodyPainter painter)
|
void |
sendPlacementRequest(java.lang.String name)
|
void |
sendPlanRequest()
|
void |
sendPositionRequest()
|
void |
sendRandomTargetSelectionRequest(boolean status)
|
void |
sendSensorStatusRequest(RsBodySensor sensor)
|
void |
sendTargetSelectionRequest(java.lang.String targetName,
boolean status)
|
int |
sendTimeoutRequest(double duration)
Sends a request for a timeout event. |
Methods inherited from class rp1.rossum.RsProtocol |
getVerbosity, isInputSet, isLoggerSet, isOutputSet, log, logIt, setInputOutputStreams, setLogger, setProtocolShutdownHandler, setSocket, setVerbosity, verbose |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
rsProperties
public RsProperties rsProperties
RsClient
public RsClient()
initiateLogger
public void initiateLogger(RsProperties properties)
throws java.io.IOException
- Throws:
java.io.IOException
initiateConnection
public void initiateConnection(RsProperties properties)
throws java.io.IOException
- Throws:
java.io.IOException
getProperties
public RsProperties getProperties()
addMouseClickEventHandler
public void addMouseClickEventHandler(RsMouseClickEventHandler reference)
removeMouseClickEventHandler
public void removeMouseClickEventHandler()
removeMouseClickEventHandler
public void removeMouseClickEventHandler(RsMouseClickEventHandler reference)
addMotionStartedEventHandler
public void addMotionStartedEventHandler(RsMotionStartedEventHandler reference)
removeMotionStartedEventHandler
public void removeMotionStartedEventHandler()
removeMotionStartedEventHandler
public void removeMotionStartedEventHandler(RsMotionStartedEventHandler reference)
addMotionHaltedEventHandler
public void addMotionHaltedEventHandler(RsMotionHaltedEventHandler reference)
removeMotionHaltedEventHandler
public void removeMotionHaltedEventHandler()
removeMotionHaltedEventHandler
public void removeMotionHaltedEventHandler(RsMotionStartedEventHandler reference)
addTargetSensorEventHandler
public void addTargetSensorEventHandler(RsBodyTargetSensor sensor,
RsTargetSensorEventHandler reference)
removeTargetSensorEventHandler
public void removeTargetSensorEventHandler(RsBodyTargetSensor sensor)
removeTargetSensorEventHandler
public void removeTargetSensorEventHandler(RsBodyTargetSensor sensor,
RsTargetSensorEventHandler reference)
addContactSensorEventHandler
public void addContactSensorEventHandler(RsBodyContactSensor sensor,
RsContactSensorEventHandler reference)
removeContactSensorEventHandler
public void removeContactSensorEventHandler(RsBodyContactSensor sensor)
removeContactSensorEventHandler
public void removeContactSensorEventHandler(RsBodyContactSensor sensor,
RsContactSensorEventHandler reference)
addRangeSensorEventHandler
public void addRangeSensorEventHandler(RsBodyRangeSensor sensor,
RsRangeSensorEventHandler reference)
removeRangeSensorEventHandler
public void removeRangeSensorEventHandler(RsBodyRangeSensor sensor)
removeRangeSensorEventHandler
public void removeRangeSensorEventHandler(RsBodyRangeSensor sensor,
RsRangeSensorEventHandler reference)
addPaintSensorEventHandler
public void addPaintSensorEventHandler(RsBodyPaintSensor sensor,
RsPaintSensorEventHandler reference)
removePaintSensorEventHandler
public void removePaintSensorEventHandler(RsBodyPaintSensor sensor)
removePaintSensorEventHandler
public void removePaintSensorEventHandler(RsBodyPaintSensor sensor,
RsPaintSensorEventHandler reference)
addTimeoutEventHandler
public void addTimeoutEventHandler(RsTimeoutEventHandler reference)
removeTimeoutEventHandler
public void removeTimeoutEventHandler()
removeTimeoutEventHandler
public void removeTimeoutEventHandler(RsTimeoutEventHandler reference)
addPositionEventHandler
public void addPositionEventHandler(RsPositionEventHandler reference)
removePositionEventHandler
public void removePositionEventHandler()
removePositionEventHandler
public void removePositionEventHandler(RsPositionEventHandler reference)
addPlacementEventHandler
public void addPlacementEventHandler(RsPlacementEventHandler reference)
removePlacementEventHandler
public void removePlacementEventHandler()
removePlacementEventHandler
public void removePlacementEventHandler(RsPlacementEventHandler reference)
addTargetSelectionEventHandler
public void addTargetSelectionEventHandler(RsTargetSelectionEventHandler reference)
removeTargetSelectionEventHandler
public void removeTargetSelectionEventHandler()
removeTargetSelectionEventHandler
public void removeTargetSelectionEventHandler(RsTargetSelectionEventHandler reference)
addPlanEventHandler
public void addPlanEventHandler(RsPlanEventHandler reference)
removePlanEventHandler
public void removePlanEventHandler()
removePlanEventHandler
public void removePlanEventHandler(RsPlanEventHandler reference)
addHeartbeatEventHandler
public void addHeartbeatEventHandler(RsHeartbeatEventHandler reference)
removeHeartbeatEventHandler
public void removeHeartbeatEventHandler()
removeHeartbeatEventHandler
public void removeHeartbeatEventHandler(RsHeartbeatEventHandler reference)
addEncoderStatusEventHandler
public void addEncoderStatusEventHandler(RsEncoderStatusEventHandler reference)
removeEncoderStatusEventHandler
public void removeEncoderStatusEventHandler()
removeEncoderStatusEventHandler
public void removeEncoderStatusEventHandler(RsEncoderStatusEventHandler reference)
sendTimeoutRequest
public int sendTimeoutRequest(double duration)
- Sends a request for a timeout event. After a period of time specified
in seconds, the simulator wil respond with a timeout event. Note that
this function returns a serial index number identified with the timeout request.
Thus, when a timeout event is received, it can be matched to the
request from which it was generated.
- Parameters:
duration
- delay time in seconds until the timeout event is returned.
sendSensorStatusRequest
public void sendSensorStatusRequest(RsBodySensor sensor)
sendMotionRequest
public void sendMotionRequest(RsMotionRequest r)
sendPositionRequest
public void sendPositionRequest()
sendPlacementRequest
public void sendPlacementRequest(java.lang.String name)
sendHaltRequest
public void sendHaltRequest()
sendTargetSelectionRequest
public void sendTargetSelectionRequest(java.lang.String targetName,
boolean status)
sendExclusiveTargetSelectionRequest
public void sendExclusiveTargetSelectionRequest(java.lang.String targetName)
sendRandomTargetSelectionRequest
public void sendRandomTargetSelectionRequest(boolean status)
sendExclusiveRandomTargetSelectionRequest
public void sendExclusiveRandomTargetSelectionRequest()
sendAllTargetsSelectionRequest
public void sendAllTargetsSelectionRequest(boolean status)
sendPlanRequest
public void sendPlanRequest()
sendHeartbeatRequest
public void sendHeartbeatRequest(double period)
- Activates the "heartbeat" function in RP1. When activated, the
simulator will send an RsHeartbeatEvent back to the client at a
fixed interval. The stream of events will continue until a
call is made to sendHeartbeatCancellationRequest.
- Parameters:
period
- heartbeat interval, in seconds.
sendHeartbeatCancellationRequest
public void sendHeartbeatCancellationRequest()
sendPainterActivationRequest
public void sendPainterActivationRequest(RsBodyPainter painter)
sendPainterDeactivationRequest
public void sendPainterDeactivationRequest(RsBodyPainter painter)
sendPainterErasureRequest
public void sendPainterErasureRequest(RsBodyPainter painter)
sendActuatorControlRequest
public void sendActuatorControlRequest(RsActuatorControlRequest r)
sendEncoderStatusRequest
public int sendEncoderStatusRequest(RsEncoder encoder,
boolean clearOnRequest)
- sends a request for the status of a single encoder.
- Parameters:
encoder
- An RsEncoder object associated with an RsWheel object.clearOnRequest
- indicates that the encoder accumulators are to be clear upon query completion.
sendEncoderStatusRequest
public int sendEncoderStatusRequest(RsEncoder[] encoders,
boolean clearOnRequest)
- sends an request for the status of one or more encoders (given in array).
- Parameters:
encoders
- An array of RsEncoder objects associated with RsWheel objects.clearOnRequest
- indicates that the encoder accumulators are to be cleared upon query completion.
sendBodySpecification
public void sendBodySpecification(RsBody body)
- The sendBodySpecification sends the body specification to the simulator
and absolutely must be invoked before any requests are sent to RP1.
initialize
public void initialize()
throws java.io.IOException
- The initialize call is used to set up the RP1 client before the run() method
is invoked. The expectation for use is that when client classes extend
RsClient, they will usually override initialize(), but may call it using
a call to super.initialize(). Note that it performs three tasks
- reads properties from rossum.ini if they were not supplied by application
- opens run-time log as indicated in config file if it's not opened by application
by calling initiateLogger.
- establishes connection to RP1 simulator by calling initiateConnection.
- Specified by:
initialize
in interface RsRunnable
- Throws:
java.io.IOException
initialize
public void initialize(RsProperties rsp)
throws java.io.IOException
- This version of initialize allows the application to supply alternate
properties specifications rather than reading them from rossum.ini
as the standard initialize method does
- Throws:
java.io.IOException
run
public void run()
- Specified by:
run
in interface java.lang.Runnable
getSimTime
public double getSimTime()
- returns the simulation time based on the most recent communications
from the simulator. Note that this value will not be updated during
a period of inactivity. If more regular updates are required, it is
that a heartbeat request be sent to the simulator.