-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add EventEffect that moves target agents into a specified state
- Adds the new EventEffect - Adds an example to exercise that feature. - Updates release notes.
- Loading branch information
Showing
13 changed files
with
388 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# ChangeStateEffect Examples | ||
|
||
This provides a single example whose purpose is to show how the ChangeStateEffect class is | ||
exercised. The example doesn't show the "force_reentry" parameter. And the scenario duplicates that | ||
shown in other examples (pedModelSwap, rise_to, and drop_to). The comparison with `rise_to` is | ||
particularly significant. | ||
|
||
## change_state | ||
|
||
Two hallways cross at right angles. One group of agents move from top to bottom, the other moves | ||
from right to left. The agents moving from right to left _wait_ to start moving until most of the | ||
agents have crossed the intersection. | ||
|
||
The agents moving left to right begin in a "wait" state -- a state with a zero velocity component | ||
and _no_ transitions out of it. The only way an agent can leave that state would be a mechanism | ||
outside of the standard FSM mechanism -- such as this event effect. | ||
|
||
When enough agents moving from top to bottom have crossed the intersection, all agents in the wait | ||
state are moved to a walking state. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0"?> | ||
|
||
<Project | ||
scene="change_stateS.xml" | ||
behavior="change_stateB.xml" | ||
view="change_stateV.xml" | ||
model="orca" | ||
dumpPath="images/change_state" | ||
timeStep=".1" | ||
outSamples="3" | ||
random="5" | ||
/> |
47 changes: 47 additions & 0 deletions
47
examples/core/events/change_state_effect/change_stateB.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?xml version="1.0"?> | ||
<BFSM> | ||
<EventSystem conservative="1"> | ||
<Target name="left_waiting_agents" type="named_state_member" is_member="1" state="WaitLeft" /> | ||
<Effect name="left_waiting_start" type="change_state" state="MoveLeft" /> | ||
<Event name="left_done_waiting"> | ||
<Trigger name="down_done" type="state_population" threshold="10" behavior="rise_to" | ||
state="GoalReachedDown" /> | ||
<Response effect="left_waiting_start" target="left_waiting_agents" /> | ||
</Event> | ||
</EventSystem> | ||
|
||
<GoalSet id="0"> | ||
<Goal id="0" type="AABB" min_x="-2" max_x="2" min_y="-10" max_y="-5" weight="1.0" /> | ||
<Goal id="1" type="AABB" min_x="-10" min_y="-2" max_x="-5" max_y="2" /> | ||
</GoalSet> | ||
|
||
<State name="MoveDown" speedPolicy="min" final="0" > | ||
<GoalSelector type="explicit" goal_set="0" goal="0" /> | ||
<VelComponent type="goal" weight="1.0" /> | ||
</State> | ||
<State name="GoalReachedDown" speedPolicy="min" final="1" > | ||
<GoalSelector type="identity" /> | ||
<VelComponent type="zero" /> | ||
</State> | ||
|
||
<Transition order="1" from="MoveDown" to="GoalReachedDown"> | ||
<Condition type="goal_reached" distance="0.25" /> | ||
</Transition> | ||
|
||
<State name="WaitLeft" speedPolicy="min" final="0" > | ||
<GoalSelector type="identity" /> | ||
<VelComponent type="zero" /> | ||
</State> | ||
<State name="MoveLeft" speedPolicy="min" final="0" > | ||
<GoalSelector type="explicit" goal_set="0" goal="1" /> | ||
<VelComponent type="goal" weight="1.0" /> | ||
</State> | ||
<State name="GoalReachedLeft" speedPolicy="min" final="1" > | ||
<GoalSelector type="identity" /> | ||
<VelComponent type="zero" /> | ||
</State> | ||
|
||
<Transition order="1" from="MoveLeft" to="GoalReachedLeft"> | ||
<Condition type="goal_reached" distance="0.25" /> | ||
</Transition> | ||
</BFSM> |
81 changes: 81 additions & 0 deletions
81
examples/core/events/change_state_effect/change_stateS.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?xml version="1.0"?> | ||
<Experiment version="2.0"> | ||
<SpatialQuery type="kd-tree" test_visibility="false" /> | ||
|
||
<Common time_step="0.1" /> | ||
<GCF reaction_time="0.5" max_agent_dist="2" max_agent_force="3" agent_interp_width="0.1" | ||
agent_force_strength="0.35" /> | ||
<Helbing agent_scale="4000" obstacle_scale="2000" reaction_time="0.2" body_force="1200" | ||
friction="2400" force_distance="0.02" /> | ||
<Johansson agent_scale="35" obstacle_scale="35" reaction_time="0.5" force_distance="0.15" | ||
stride_time="0.5" /> | ||
<Karamouzas orient_weight="0.8" fov="200" reaction_time="0.4" wall_steepness="2" wall_distance="2" | ||
colliding_count="5" d_min="1" d_mid="8" d_max="10" agent_force="2" weight_factor="0.8" | ||
/> | ||
<Zanlungo agent_scale="2000" obstacle_scale="4000" reaction_time="0.5" force_distance="0.015" /> | ||
<Dummy stddev="0.05" /> | ||
|
||
<AgentProfile name="group1" > | ||
<Common max_angle_vel="360" class="1" max_neighbors="10" obstacleSet="1" neighbor_dist="5" | ||
r="0.2" pref_speed="1.34" max_speed="2" max_accel="5" /> | ||
<OpenSteer tau="3" tauObst="6" /> | ||
<PedVO factor="1.57" buffer="0.9" tau="3" tauObst="0.1" turningBias="1.0" /> | ||
<GCF stand_depth="0.18" move_scale="0.53" slow_width="0.25" sway_change="0.05" /> | ||
<Helbing mass="80" /> | ||
<Johansson fov_weight="0.16" /> | ||
<Karamouzas personal_space="0.69" anticipation="8" /> | ||
<ORCA tau="3.0" tauObst="0.15" /> | ||
<Zanlungo mass="80" orient_weight="0.75" /> | ||
</AgentProfile> | ||
|
||
<AgentProfile name="group2" inherits="group1" > | ||
<Common class="2" /> | ||
</AgentProfile> | ||
|
||
<AgentGroup> | ||
<ProfileSelector type="const" name="group1" /> | ||
<StateSelector type="const" name="MoveDown" /> | ||
<Generator type="hex_lattice" | ||
anchor_x="0" anchor_y="5" | ||
alignment="center" row_direction="x" | ||
density="0.5" width="4" | ||
population="12" rotation="0" | ||
displace_dist="n" displace_mean="0.1" displace_stddev="0.03" | ||
/> | ||
</AgentGroup> | ||
|
||
<AgentGroup> | ||
<ProfileSelector type="const" name="group2" /> | ||
<StateSelector type="const" name="WaitLeft" /> | ||
<Generator type="hex_lattice" | ||
anchor_x="5" anchor_y="0" | ||
alignment="center" row_direction="x" | ||
density="0.5" width="4" | ||
population="12" rotation="-90" | ||
displace_dist="n" displace_mean="0.1" displace_stddev="0.03" | ||
/> | ||
</AgentGroup> | ||
|
||
<ObstacleSet type="explicit" class="1"> | ||
<Obstacle closed="1"> | ||
<Vertex p_x="2.0" p_y="50.00" /> | ||
<Vertex p_x="2.0" p_y="2.0" /> | ||
<Vertex p_x="50" p_y="2.0" /> | ||
</Obstacle> | ||
<Obstacle closed="1"> | ||
<Vertex p_x="2.0" p_y="-2.0" /> | ||
<Vertex p_x="2.0" p_y="-50.00" /> | ||
<Vertex p_x="50.0" p_y="-2.0" /> | ||
</Obstacle> | ||
<Obstacle closed="1"> | ||
<Vertex p_x="-2.0" p_y="-2.0" /> | ||
<Vertex p_x="-50" p_y="-2.0" /> | ||
<Vertex p_x="-2.0" p_y="-50" /> | ||
</Obstacle> | ||
<Obstacle closed="1"> | ||
<Vertex p_x="-2.0" p_y="2.0" /> | ||
<Vertex p_x="-2.0" p_y="50.0" /> | ||
<Vertex p_x="-50" p_y="2.0" /> | ||
</Obstacle> | ||
</ObstacleSet> | ||
</Experiment> |
13 changes: 13 additions & 0 deletions
13
examples/core/events/change_state_effect/change_stateV.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0"?> | ||
|
||
<View width="640" height="480" z_up="1" > | ||
<Camera xpos="-0.00195143" ypos="-0.00220079" zpos="19.13" xtgt="-0.00195143" ytgt="0.0077992" | ||
ztgt="4.07539e-06" far="500" near="0.01" fov="0.0" orthoScale="0.446361" /> | ||
<Camera xpos="-0.00195143" ypos="-0.00220079" zpos="19.13" xtgt="-0.00195143" ytgt="0.0077992" | ||
ztgt="4.07539e-006" far="500" near="0.01" fov="0" orthoScale="0.240759"/> | ||
<Light x="1" y="0" z="-1" type="directional" space="camera" diffR="1" diffG="0.8" diffB="0.8"/> | ||
<Light x="-1" y="0" z="-1" type="directional" space="camera" diffR="0.8" diffG="0.8" diffB="1"/> | ||
<Light x="0" y="0" z="1" type="directional" space="world" diffR="0.8" diffG="0.8" diffB="0.8"/> | ||
<Watermark file_name="../../../mengeLogo.png" alignment="bottom_right" scale="0.5" | ||
opacity="0.25"/> | ||
</View> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include "MengeCore/Agents/Events/change_state_effect.h" | ||
|
||
#include <sstream> | ||
|
||
#include "MengeCore/Core.h" | ||
#include "MengeCore/Agents/Events/EventSystem.h" | ||
#include "MengeCore/BFSM/FSM.h" | ||
#include "MengeCore/BFSM/State.h" | ||
|
||
namespace Menge { | ||
|
||
///////////////////////////////////////////////////////////////////// | ||
// Implementation of ChangeStateEffect | ||
///////////////////////////////////////////////////////////////////// | ||
|
||
void ChangeStateEffect::finalize() { | ||
_state = ACTIVE_FSM->getNode(_stateName); | ||
if (_state == 0x0) { | ||
std::stringstream ss; | ||
ss << "Event event unable to to locate state " << _stateName << "."; | ||
EventSystem::finalizeException(ss.str()); | ||
} | ||
} | ||
|
||
///////////////////////////////////////////////////////////////////// | ||
|
||
void ChangeStateEffect::agentEffect(Agents::BaseAgent* agent) { | ||
ACTIVE_FSM->forceStateTransition(agent, _state, _force_reentry); | ||
} | ||
|
||
///////////////////////////////////////////////////////////////////// | ||
// Implementation of ChangeStateEffectFactory | ||
///////////////////////////////////////////////////////////////////// | ||
|
||
ChangeStateEffectFactory::ChangeStateEffectFactory() : EventEffectFactory() { | ||
_stateID = _attrSet.addStringAttribute("state", true); | ||
_forceID = _attrSet.addBoolAttribute("force_reentry", false); | ||
} | ||
|
||
///////////////////////////////////////////////////////////////////// | ||
|
||
bool ChangeStateEffectFactory::setFromXML(EventEffect * effect, TiXmlElement * node, | ||
const std::string & behaveFldr) const { | ||
ChangeStateEffect * sEffect = dynamic_cast<ChangeStateEffect*>(effect); | ||
assert(sEffect != 0x0 && | ||
"Trying to set attributes of a state event effect on an incompatible object"); | ||
|
||
if (!EventEffectFactory::setFromXML(sEffect, node, behaveFldr)) return false; | ||
|
||
sEffect->_stateName = _attrSet.getString(_stateID); | ||
sEffect->_force_reentry = _attrSet.getBool(_forceID); | ||
|
||
return true; | ||
} | ||
|
||
} // namespace Menge |
Oops, something went wrong.