public abstract class RosEnvironment extends AbstractRosEnvironment implements ros.RosListenDelegate
AbstractRosEnvironment that maintains the environment state by receiving
a single ROS message corresponding to the state of the environment. To implement this class, implement the unpackStateFromMsg(JsonNode, String)
method to provide the code that parses the ROS message into a BURLAP State.
Note that in the constructor you may want to set a low (e.g., 1) throttle rate and queue rate if state messages are sent frequently, otherwise ROS Bridge may start lagging.
This class will block on the currentObservation() method until it receives a state message from
ROS Bridge. If you would like, you can override waiting for the first state message received from ROS and force this environment to report
a specific BURLAP State using the overrideFirstReceivedState(State) method. Note
that any subsequent burlap_msgs/burlap_state messages will still update this environment's current state.
This class may also be provided a BURLAP RewardFunction and TerminalFunction
for generating non-zero rewards and terminal states. Use the setRewardFunction(RewardFunction)
and setTerminalFunction(TerminalFunction) to set them use the setRewardFunction(RewardFunction)
and setTerminalFunction(TerminalFunction) methods. This class does not have the handleEnterTerminalState()
inherited from AbstractRosEnvironment do anything, so if you want to inject code for handling the event
when the environment enters a terminal state, you should subclass this class and override that method.
| Modifier and Type | Field and Description |
|---|---|
protected burlap.mdp.core.state.State |
curState
The current
State representation of the environment |
protected int |
debugCode
The debug code used for debug prints.
|
protected burlap.mdp.singleagent.SADomain |
domain
The BURLAP
SADomain into which states will be parsed |
protected boolean |
printStateAsReceived
Debug flag indicating whether states should be printed to the terminal as they are received.
|
protected Boolean |
receivedFirstState
Indicates whether the first state message from ROS has been received yet
|
protected burlap.mdp.singleagent.model.RewardFunction |
rf
The optional
RewardFunction used to generate reward signals |
protected burlap.mdp.core.TerminalFunction |
tf
The optional
TerminalFunction used to specify terminal states of the environment |
actionPublishers, lastReward, rosBridge| Constructor and Description |
|---|
RosEnvironment(burlap.mdp.singleagent.SADomain domain,
ros.RosBridge ros,
String rosStateTopic,
int rosBridgeThrottleRate,
int rosBridgeQueueLength)
Creates an environment wrapper for state information provided over ROS with BURLAP actions
needing to be published to ROS.
|
RosEnvironment(burlap.mdp.singleagent.SADomain domain,
ros.RosBridge ros,
String rosStateTopic,
String rosStateMessageType)
Creates an environment wrapper for state information provided over ROS with BURLAP actions
needing to be published to ROS.
|
RosEnvironment(burlap.mdp.singleagent.SADomain domain,
ros.RosBridge ros,
String rosStateTopic,
String rosStateMessageType,
int rosBridgeThrottleRate,
int rosBridgeQueueLength)
Creates an environment wrapper for state information provided over ROS with BURLAP actions
needing to be published to ROS.
|
RosEnvironment(burlap.mdp.singleagent.SADomain domain,
String rosBridgeURI,
String rosStateTopic,
String rosStateMessageType)
Creates an environment wrapper for state information provided over ROS with BURLAP actions
needing to be published to ROS.
|
RosEnvironment(burlap.mdp.singleagent.SADomain domain,
String rosBridgeURI,
String rosStateTopic,
String rosStateMessageType,
int rosBridgeThrottleRate,
int rosBridgeQueueLength)
Creates an environment wrapper for state information provided over ROS with BURLAP actions
needing to be published to ROS.
|
| Modifier and Type | Method and Description |
|---|---|
void |
blockUntilStateReceived()
A method you can call that forces the calling thread to wait until the first state from ROS has been received.
|
burlap.mdp.core.state.State |
currentObservation() |
burlap.mdp.singleagent.SADomain |
getDomain()
Returns the domain of this environment.
|
protected double |
getMostRecentRewardSignal(burlap.mdp.core.state.State s,
burlap.mdp.core.action.Action a,
burlap.mdp.core.state.State sprime)
Generates the reward signal for the most recent environment interaction initiated through the
AbstractRosEnvironment.executeAction(Action)
method and what will
be returned by the AbstractRosEnvironment.lastReward() method until another AbstractRosEnvironment.executeAction(Action) method
is invoked or this environment is reset with AbstractRosEnvironment.resetEnvironment(). |
protected void |
handleEnterTerminalState()
This method is called just before exiting the
AbstractRosEnvironment.executeAction(Action) method
if the newly entered environment state is a terminal state. |
boolean |
isInTerminalState() |
protected burlap.mdp.core.state.State |
onStateReceive(burlap.mdp.core.state.State s)
This method is called after a
State is unpacked from a ROS message. |
void |
overrideFirstReceivedState(burlap.mdp.core.state.State s)
Use this method to override the first received state from ROS to be the provided
State. |
void |
receive(com.fasterxml.jackson.databind.JsonNode data,
String stringRep) |
void |
setPrintStateAsReceived(boolean printStateAsReceived)
Sets whether the default implementation of
onStateReceive(State) will print the
state information to the terminal. |
void |
setRewardFunction(burlap.mdp.singleagent.model.RewardFunction rf)
Sets a BURLAP
RewardFunction to use to provide reward signals from the AbstractRosEnvironment.lastReward() method. |
void |
setTerminalFunction(burlap.mdp.core.TerminalFunction tf)
Sets the BURLAP
TerminalFunction to use to provide terminal state checks from the isInTerminalState(). |
abstract burlap.mdp.core.state.State |
unpackStateFromMsg(com.fasterxml.jackson.databind.JsonNode data,
String stringRep)
This method receive the RosBridge message and unpacks it into a BURLAP
State object. |
executeAction, getRosBridge, lastReward, resetEnvironment, setActionPublisher, setActionPublisher, setActionPublisherForMultipleAcitonNames, setActionPublisherForMultipleActionsprotected burlap.mdp.singleagent.SADomain domain
SADomain into which states will be parsedprotected burlap.mdp.core.state.State curState
State representation of the environmentprotected burlap.mdp.singleagent.model.RewardFunction rf
RewardFunction used to generate reward signalsprotected burlap.mdp.core.TerminalFunction tf
TerminalFunction used to specify terminal states of the environmentprotected Boolean receivedFirstState
protected boolean printStateAsReceived
protected int debugCode
public RosEnvironment(burlap.mdp.singleagent.SADomain domain,
String rosBridgeURI,
String rosStateTopic,
String rosStateMessageType)
Remember that for actions to be properly handled, you will need to set the ActionPublisher
to use for each action after this class is constructed with one of the appropriate methods (e.g., AbstractRosEnvironment.setActionPublisher(String, burlap.ros.actionpub.ActionPublisher)).
domain - the domain into which ROS burlap_state messages are parsedrosBridgeURI - the URI of the ros bridge server. Note that by default, ros bridge uses port 9090. An example URI is ws://localhost:9090rosStateTopic - the name of the ROS topic that publishes the state messages.rosStateMessageType - the message type of the ROS state messages.public RosEnvironment(burlap.mdp.singleagent.SADomain domain,
String rosBridgeURI,
String rosStateTopic,
String rosStateMessageType,
int rosBridgeThrottleRate,
int rosBridgeQueueLength)
Remember that for actions to be properly handled, you will need to set the ActionPublisher
to use for each action after this class is constructed with one of the appropriate methods (e.g., AbstractRosEnvironment.setActionPublisher(String, burlap.ros.actionpub.ActionPublisher)).
domain - the domain into which ROS burlap_state messages are parsedrosBridgeURI - the URI of the ros bridge server. Note that by default, ros bridge uses port 9090. An example URI is ws://localhost:9090rosStateTopic - the name of the ROS topic that publishes the state messages.rosStateMessageType - the message type of the ROS state messages.rosBridgeThrottleRate - the ROS Bridge server throttle rate: how frequently the server will send state messagesrosBridgeQueueLength - the ROS Bridge queue length: how many messages are queued on the server; queueing is a consequence of the throttle ratepublic RosEnvironment(burlap.mdp.singleagent.SADomain domain,
ros.RosBridge ros,
String rosStateTopic,
String rosStateMessageType)
Remember that for actions to be properly handled, you will need to set the ActionPublisher
to use for each action after this class is constructed with one of the appropriate methods (e.g., AbstractRosEnvironment.setActionPublisher(String, burlap.ros.actionpub.ActionPublisher)).
domain - the domain into which ROS burlap_state messages are parsedros - the connected RosBridge instance.rosStateTopic - the name of the ROS topic that publishes the burlap_msgs/burlap_state messages.rosStateMessageType - the message type of the ROS state messages.public RosEnvironment(burlap.mdp.singleagent.SADomain domain,
ros.RosBridge ros,
String rosStateTopic,
int rosBridgeThrottleRate,
int rosBridgeQueueLength)
Remember that for actions to be properly handled, you will need to set the ActionPublisher
to use for each action after this class is constructed with one of the appropriate methods (e.g., AbstractRosEnvironment.setActionPublisher(String, burlap.ros.actionpub.ActionPublisher)).
domain - the domain into which ROS burlap_state messages are parsedros - the connected RosBridge instance.rosStateTopic - the name of the ROS topic that publishes the burlap_msgs/burlap_state messages.rosBridgeThrottleRate - the ROS Bridge server throttle rate: how frequently the server will send state messagesrosBridgeQueueLength - the ROS Bridge queue length: how many messages are queued on the server; queueing is a consequence of the throttle ratepublic RosEnvironment(burlap.mdp.singleagent.SADomain domain,
ros.RosBridge ros,
String rosStateTopic,
String rosStateMessageType,
int rosBridgeThrottleRate,
int rosBridgeQueueLength)
RosEnvironment and overridden unpackStateFromMsg(JsonNode, String), the message type should be a type
that is or adheres to "burlap_msgs/burlap_state" even if named something else.
Remember that for actions to be properly handled, you will need to set the ActionPublisher
to use for each action after this class is constructed with one of the appropriate methods (e.g., AbstractRosEnvironment.setActionPublisher(String, burlap.ros.actionpub.ActionPublisher)).
domain - the domain into which ROS burlap_state messages are parsedros - the connected RosBridge instance.rosStateTopic - the name of the ROS topic that publishes the state messages.rosStateMessageType - the message type of the ROS state messages.rosBridgeThrottleRate - the ROS Bridge server throttle rate: how frequently the server will send state messagesrosBridgeQueueLength - the ROS Bridge queue length: how many messages are queued on the server; queueing is a consequence of the throttle ratepublic void setRewardFunction(burlap.mdp.singleagent.model.RewardFunction rf)
RewardFunction to use to provide reward signals from the AbstractRosEnvironment.lastReward() method.rf - RewardFunction to use to provide reward signals.public void setTerminalFunction(burlap.mdp.core.TerminalFunction tf)
TerminalFunction to use to provide terminal state checks from the isInTerminalState().tf - the BURLAP TerminalFunction to use to provide terminal state checkspublic burlap.mdp.singleagent.SADomain getDomain()
public burlap.mdp.core.state.State currentObservation()
currentObservation in interface burlap.mdp.singleagent.environment.Environmentpublic boolean isInTerminalState()
isInTerminalState in interface burlap.mdp.singleagent.environment.Environmentprotected double getMostRecentRewardSignal(burlap.mdp.core.state.State s,
burlap.mdp.core.action.Action a,
burlap.mdp.core.state.State sprime)
AbstractRosEnvironmentAbstractRosEnvironment.executeAction(Action)
method and what will
be returned by the AbstractRosEnvironment.lastReward() method until another AbstractRosEnvironment.executeAction(Action) method
is invoked or this environment is reset with AbstractRosEnvironment.resetEnvironment().getMostRecentRewardSignal in class AbstractRosEnvironments - the previous environment state before this reward eventa - the action taken by the agent before this reward eventsprime - the resulting environment state associated with this reward eventpublic void setPrintStateAsReceived(boolean printStateAsReceived)
onStateReceive(State) will print the
state information to the terminal.printStateAsReceived - if true, then the default implementation of onStateReceive(State) will print states to the screen;
if false, the state receiving is silent by default.public void overrideFirstReceivedState(burlap.mdp.core.state.State s)
State.
If the blockUntilStateReceived() method has been called in another thread, it will be notified that the first state is received.
Note that if ROS Bridge subsequently sends state message, the state of this environment will be updated to reflect them.s - the State to force this Environment to.public void blockUntilStateReceived()
public void receive(com.fasterxml.jackson.databind.JsonNode data,
String stringRep)
receive in interface ros.RosListenDelegatepublic abstract burlap.mdp.core.state.State unpackStateFromMsg(com.fasterxml.jackson.databind.JsonNode data,
String stringRep)
State object.data - the JSON message.stringRep - the string representation of the JSON message.State object that is unpacked from the JSON message.protected burlap.mdp.core.state.State onStateReceive(burlap.mdp.core.state.State s)
State is unpacked from a ROS message. The new current state of the environment
will be set to whatever this method returns. By default, this method simply returns the same reference and
if this environment's printStateAsReceived data member is set to true, then it will print
to the terminal the string representation of the state. Override this method to provide
special handling of used state (e.g., adding virtual objects to the state that ROS does not perceive).s - the parsed state from the ROS message received.State object parsed from the ros messageprotected void handleEnterTerminalState()
AbstractRosEnvironmentAbstractRosEnvironment.executeAction(Action) method
if the newly entered environment state is a terminal state. This method does not have to do anything, but is useful
if you need to do something special with the robot when it reaches a terminal state.handleEnterTerminalState in class AbstractRosEnvironmentCopyright © 2016. All rights reserved.