File tree Expand file tree Collapse file tree 6 files changed +29
-17
lines changed Expand file tree Collapse file tree 6 files changed +29
-17
lines changed Original file line number Diff line number Diff line change @@ -78,7 +78,7 @@ namespace Ped {
7878 virtual Tvector obstacleForce () const ;
7979 virtual Tvector lookaheadForce (Tvector desired) const ;
8080 virtual Tvector myForce (Tvector desired);
81- virtual void updateState () {}
81+ virtual void updateState (int event = 0 ) {}
8282
8383 void setPosition (double px, double py, double pz);
8484 void setType (AgentType t) { this ->type = t; };
Original file line number Diff line number Diff line change @@ -65,7 +65,10 @@ class Agent : public Ped::Tagent
6565 void setX (double xIn);
6666 void setY (double yIn);
6767 void setType (Ped::Tagent::AgentType t);
68- void updateState ();
68+ void updateState (int event = 0 );
69+
70+ StateMachine::State status () { return state_machine_->getCurrentState (); }
71+ StateMachine::State prevStatus () { return state_machine_->getPreviousState (); }
6972
7073private:
7174 StateMachinePtr state_machine_;
Original file line number Diff line number Diff line change @@ -55,11 +55,11 @@ class StateMachine
5555 // / \brief Agent events to transition between states
5656 enum Event
5757 {
58- START_WALKING = 0 ,
59- STOP_WALKING = 1 ,
60- JOIN_QUEUE = 2 ,
61- LEAVE_QUEUE = 3 ,
62- NO_EVENT = 4
58+ NO_EVENT = 0 ,
59+ START_WALKING = 1 ,
60+ STOP_WALKING = 2 ,
61+ JOIN_QUEUE = 3 ,
62+ LEAVE_QUEUE = 4
6363 };
6464
6565
@@ -90,12 +90,15 @@ class StateMachine
9090 // / Walking transitions
9191 if ( current_state_ == WALKING )
9292 {
93+ if ( previous_state_ == QUEUEING )
94+ return ;
95+
9396 if ( triggered_event == JOIN_QUEUE )
9497 {
9598 previous_state_ = WALKING;
9699 current_state_ = QUEUEING;
97100 }
98- else if ( triggered_event == START_WALKING )
101+ else if ( triggered_event == STOP_WALKING )
99102 {
100103 previous_state_ = WALKING;
101104 current_state_ = IDLE;
@@ -120,6 +123,11 @@ class StateMachine
120123 return current_state_;
121124 }
122125
126+ State getPreviousState ()
127+ {
128+ return previous_state_;
129+ }
130+
123131 void reset ()
124132 {
125133 current_state_ = IDLE;
Original file line number Diff line number Diff line change @@ -82,13 +82,14 @@ Ped::Tvector Agent::myForce ( Ped::Tvector desired ) const
8282 return t;
8383}
8484
85- void Agent::updateState ()
85+ void Agent::updateState (int event )
8686{
8787 if ( getteleop () == true )
8888 state_machine_->reset ();
8989
9090 // check state
91- state_machine_->doStateTransition ( StateMachine::NO_EVENT );
91+ StateMachine::Event ev = static_cast <StateMachine::Event>(event);
92+ state_machine_->doStateTransition ( ev );
9293}
9394
9495// / \brief Move the agents in one time step
Original file line number Diff line number Diff line change @@ -285,18 +285,16 @@ void Scene::updateQueues()
285285 // / Add agents into queues
286286 BOOST_FOREACH ( Agent* a, agents )
287287 {
288- if ( a->gettype () != Ped::Tagent::ROBOT )
288+ if ( a->gettype () != Ped::Tagent::ROBOT && q-> agentInQueue ( a ) == false )
289289 {
290- if ( q-> agentInQueue ( a ) == false )
290+ if ( a-> prevStatus () != StateMachine::QUEUEING )
291291 {
292292 double d = distance (
293293 q->getX (), q->getY (),
294294 a->getx (), a->gety () );
295295
296296 if ( d < 4.5 && coinFlip () > 0.5 )
297297 {
298- // TODO - do state transition
299-
300298 q->enqueueAgent ( a );
301299 }
302300 }
Original file line number Diff line number Diff line change @@ -87,7 +87,7 @@ void WaitingQueue::enqueueAgent ( Agent *a )
8787 Ped::Tvector qend = getQueueEnd ();
8888 a->setPosition ( qend.x , qend.y );
8989
90- a->updateState (); // / TODO - add event information here
90+ a->updateState ( StateMachine::JOIN_QUEUE );
9191
9292 queueing_agents_.push_back ( a );
9393}
@@ -144,8 +144,10 @@ void WaitingQueue::releaseAgent ( Agent *a )
144144{
145145 // reset the factors for the social forces
146146 a->setMobile ();
147- a->setPosition ( x_ + a->getRadius () + 10 , y_ + a->getRadius () + 10 );
148- a->updateState (); // / TODO - add event information here
147+ a->setPosition ( x_ + a->getRadius (), y_ + a->getRadius () );
148+ a->updateState ( StateMachine::LEAVE_QUEUE );
149+
150+ queueing_agents_.pop_front ();
149151}
150152
151153
You can’t perform that action at this time.
0 commit comments