public abstract class AbstractRosEnvironment extends Object implements burlap.oomdp.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.getCurrentObservation() or
Environment.isInTerminalState() and
the Environment.getLastReward() method requires this class's
abstract method getMostRecentRewardSignal(burlap.oomdp.core.states.State, burlap.oomdp.singleagent.GroundedAction, burlap.oomdp.core.states.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 name), an ActionPublisher may be specified using one of the following
methods:
setActionPublisher(burlap.oomdp.singleagent.Action, burlap.ros.actionpub.ActionPublisher),
setActionPublisher(String, burlap.ros.actionpub.ActionPublisher)
setActionPublisherForMultipleAcitons(java.util.List, burlap.ros.actionpub.ActionPublisher), or
setActionPublisherForMultipleAcitonNames(java.util.List, burlap.ros.actionpub.ActionPublisher).
When executeAction(burlap.oomdp.singleagent.GroundedAction) is called, the corresponding ActionPublisher
for the provided GroundedAction is retrieved (with a runtime exception being thrown if none have been set for it).
The ActionPublisher.publishAction(burlap.oomdp.singleagent.GroundedAction) is then called and passed the input
GroundedAction. 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.getCurrentObservation() 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(burlap.oomdp.core.states.State, burlap.oomdp.singleagent.GroundedAction, burlap.oomdp.core.states.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(burlap.oomdp.singleagent.GroundedAction) 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.oomdp.singleagent.environment.EnvironmentOutcome |
executeAction(burlap.oomdp.singleagent.GroundedAction ga) |
double |
getLastReward() |
protected abstract double |
getMostRecentRewardSignal(burlap.oomdp.core.states.State s,
burlap.oomdp.singleagent.GroundedAction ga,
burlap.oomdp.core.states.State sprime)
Generates the reward signal for the most recent environment interaction initiated through the
executeAction(burlap.oomdp.singleagent.GroundedAction)
method and what will
be returned by the getLastReward() method until another executeAction(burlap.oomdp.singleagent.GroundedAction) 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(burlap.oomdp.singleagent.GroundedAction) method
if the newly entered environment state is a terminal state. |
void |
resetEnvironment() |
void |
setActionPublisher(burlap.oomdp.singleagent.Action action,
ActionPublisher ap)
Sets the
ActionPublisher to handle executions of the given Action |
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 |
setActionPublisherForMultipleAcitons(List<burlap.oomdp.singleagent.Action> actions,
ActionPublisher ap)
Sets a single
ActionPublisher to handle the execution of a list of Action 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.oomdp.singleagent.Action action,
ActionPublisher ap)
ActionPublisher to handle executions of the given Actionaction - the Action to handleap - the ActionPublisher to handle the executionspublic void setActionPublisherForMultipleAcitons(List<burlap.oomdp.singleagent.Action> actions, ActionPublisher ap)
ActionPublisher to handle the execution of a list of Action objects.actions - the Action 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.oomdp.singleagent.environment.EnvironmentOutcome executeAction(burlap.oomdp.singleagent.GroundedAction ga)
executeAction in interface burlap.oomdp.singleagent.environment.Environmentpublic double getLastReward()
getLastReward in interface burlap.oomdp.singleagent.environment.Environmentpublic void resetEnvironment()
resetEnvironment in interface burlap.oomdp.singleagent.environment.Environmentprotected abstract double getMostRecentRewardSignal(burlap.oomdp.core.states.State s,
burlap.oomdp.singleagent.GroundedAction ga,
burlap.oomdp.core.states.State sprime)
executeAction(burlap.oomdp.singleagent.GroundedAction)
method and what will
be returned by the getLastReward() method until another executeAction(burlap.oomdp.singleagent.GroundedAction) method
is invoked or this environment is reset with resetEnvironment().s - the previous environment state before this reward eventga - the action taken by the agent before this reward eventsprime - the resulting environment state associated with this reward eventprotected abstract void handleEnterTerminalState()
executeAction(burlap.oomdp.singleagent.GroundedAction) 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.