public abstract class AbstractRosEnvironment extends Object implements burlap.mdp.singleagent.environment.Environment
Environment implementation that executes
actions on robots controlled by ROS via ROS Bridge. Note that this abstract class does not implement
the Environment methods
Environment.currentObservation() or
Environment.isInTerminalState() and
the Environment.lastReward() method requires this class's
abstract method getMostRecentRewardSignal(State, Action, State) to be implemented.
Instead, the primary purpose of this class is to provide a general framework for handling action execution on ROS via the ActionPublisher
methodology. Specifically, for each BURLAP action (identified by its String action name), an ActionPublisher may be specified using one of the following
methods:
setActionPublisher(ActionType, burlap.ros.actionpub.ActionPublisher),
setActionPublisher(String, burlap.ros.actionpub.ActionPublisher)
setActionPublisherForMultipleActions(java.util.List, burlap.ros.actionpub.ActionPublisher), or
setActionPublisherForMultipleAcitonNames(java.util.List, burlap.ros.actionpub.ActionPublisher).
When executeAction(Action) is called, the corresponding ActionPublisher
for the provided Action is retrieved (with a runtime exception being thrown if none have been set for it).
The ActionPublisher.publishAction(Action) is then called and passed the input
Action. After the method returns, the thread sleeps (and blocks) for the amount of time in
milliseconds specified by the return value of the method so long as it is greater than zero. The returned EnvironmentOutcome
object is formed by querying the Environment.currentObservation() method before the ActionPublisher is invoked for the pre-state
and after the thread sleeping completes for the post-state; this object's abstract getMostRecentRewardSignal(State, Action, State)
method is then called to get the reward signal to use (and is provided the state-action-state transition that was just recorded, which may or may not be needed); and the
the terminal state flag is set by invoking this object's Environment.isInTerminalState(). If the environment transitions to a terminal state,
then before the executeAction(Action) method exits, it calls the
handleEnterTerminalState() abstract method. This latter method does not have to be implemented, but allows you
to easily inject code for handling the special case when the robot enters a terminal state. Therefore, as long as all necessary methods for this abstract class
are implemented, everything will work.
| Modifier and Type | Field and Description |
|---|---|
protected Map<String,ActionPublisher> |
actionPublishers
The mapping from BURLAP
Action names to the corresponding
ActionPublisher to use. |
protected double |
lastReward
The last reward signal generated.
|
protected ros.RosBridge |
rosBridge
The
RosBridge connection |
| Constructor and Description |
|---|
AbstractRosEnvironment(ros.RosBridge rosBridge)
Initializes with the given
RosBridge. |
AbstractRosEnvironment(String rosBridgeURI)
Creates a
RosBridge connection for this Environment at the given ROS Bridge URI. |
| Modifier and Type | Method and Description |
|---|---|
burlap.mdp.singleagent.environment.EnvironmentOutcome |
executeAction(burlap.mdp.core.action.Action a) |
protected abstract 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
executeAction(Action)
method and what will
be returned by the lastReward() method until another executeAction(Action) method
is invoked or this environment is reset with resetEnvironment(). |
ros.RosBridge |
getRosBridge()
Returns the
RosBridge object to which this environment is connected. |
protected abstract void |
handleEnterTerminalState()
This method is called just before exiting the
executeAction(Action) method
if the newly entered environment state is a terminal state. |
double |
lastReward() |
void |
resetEnvironment() |
void |
setActionPublisher(burlap.mdp.core.action.ActionType action,
ActionPublisher ap)
Sets the
ActionPublisher to handle executions of the given ActionType
assuming that Actions generated by the ActionType have the same name as the type name. |
void |
setActionPublisher(String actionName,
ActionPublisher ap)
Sets the
ActionPublisher to handle executions of actions with the name actionName |
void |
setActionPublisherForMultipleAcitonNames(List<String> actionNames,
ActionPublisher ap)
Sets a single
ActionPublisher to handle the execution of a list of actions identified by given action names. |
void |
setActionPublisherForMultipleActions(List<burlap.mdp.core.action.ActionType> actions,
ActionPublisher ap)
Sets a single
ActionPublisher to handle the execution of a list of ActionType objects. |
protected ros.RosBridge rosBridge
RosBridge connectionprotected Map<String,ActionPublisher> actionPublishers
Action names to the corresponding
ActionPublisher to use.protected double lastReward
public AbstractRosEnvironment(ros.RosBridge rosBridge)
RosBridge.rosBridge - the RosBridge connection to use.public AbstractRosEnvironment(String rosBridgeURI)
RosBridge connection for this Environment at the given ROS Bridge URI.
and blocks until a connection with has been established.rosBridgeURI - the ROS Bridge URI; e.g., ws://localhost:9090public void setActionPublisher(String actionName, ActionPublisher ap)
ActionPublisher to handle executions of actions with the name actionNameactionName - the name of the actionap - the ActionPublisher that handles executions of actions with that namepublic void setActionPublisher(burlap.mdp.core.action.ActionType action,
ActionPublisher ap)
ActionPublisher to handle executions of the given ActionType
assuming that Actions generated by the ActionType have the same name as the type name.action - the ActionType to handleap - the ActionPublisher to handle the executionspublic void setActionPublisherForMultipleActions(List<burlap.mdp.core.action.ActionType> actions, ActionPublisher ap)
ActionPublisher to handle the execution of a list of ActionType objects.
Assumes that Actions generated by the ActionTypes will have the same name
as the name of the types that generated them.actions - the ActionType objects to handleap - the ActionPublisher that handles the executionpublic void setActionPublisherForMultipleAcitonNames(List<String> actionNames, ActionPublisher ap)
ActionPublisher to handle the execution of a list of actions identified by given action names.actionNames - the list of action names to handleap - the ActionPublisher that handles executionpublic ros.RosBridge getRosBridge()
RosBridge object to which this environment is connected.RosBridge object to which this environment is connected.public burlap.mdp.singleagent.environment.EnvironmentOutcome executeAction(burlap.mdp.core.action.Action a)
executeAction in interface burlap.mdp.singleagent.environment.Environmentpublic double lastReward()
lastReward in interface burlap.mdp.singleagent.environment.Environmentpublic void resetEnvironment()
resetEnvironment in interface burlap.mdp.singleagent.environment.Environmentprotected abstract double getMostRecentRewardSignal(burlap.mdp.core.state.State s,
burlap.mdp.core.action.Action a,
burlap.mdp.core.state.State sprime)
executeAction(Action)
method and what will
be returned by the lastReward() method until another executeAction(Action) method
is invoked or this environment is reset with resetEnvironment().s - 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 eventprotected abstract void handleEnterTerminalState()
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.Copyright © 2016. All rights reserved.