Skip to content

Commit 95b5c6b

Browse files
author
Ernesto Corbellini
committed
Added state translation to get a meaninful string.
1 parent ead8f66 commit 95b5c6b

File tree

1 file changed

+49
-18
lines changed

1 file changed

+49
-18
lines changed

src/rosjava_actionlib/rosjava_actionlib/src/main/java/com/github/ekumen/rosjava_actionlib/ClientStateMachine.java

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import actionlib_msgs.GoalStatus;
2121
import java.util.Vector;
2222
import java.util.Iterator;
23+
import org.apache.commons.logging.Log;
24+
import org.apache.commons.logging.LogFactory;
2325

2426

2527
/**
@@ -40,24 +42,58 @@ public static class ClientStates {
4042
public final static int PREEMPTING = 6;
4143
public final static int DONE = 7;
4244
public final static int LOST = 8;
45+
46+
public static String translateState(int state) {
47+
String stateName;
48+
switch (state) {
49+
case INVALID_TRANSITION:
50+
stateName = "INVALID_TRANSITION";
51+
break;
52+
case NO_TRANSITION:
53+
stateName = "NO_TRANSITION";
54+
break;
55+
case WAITING_FOR_GOAL_ACK:
56+
stateName = "WAITING_FOR_GOAL_ACK";
57+
break;
58+
case PENDING:
59+
stateName = "PENDING";
60+
break;
61+
case ACTIVE:
62+
stateName = "ACTIVE";
63+
break;
64+
case WAITING_FOR_RESULT:
65+
stateName = "WAITING_FOR_RESULT";
66+
break;
67+
case WAITING_FOR_CANCEL_ACK:
68+
stateName = "WAITING_FOR_CANCEL_ACK";
69+
break;
70+
case RECALLING:
71+
stateName = "RECALLING";
72+
break;
73+
case PREEMPTING:
74+
stateName = "PREEMPTING";
75+
break;
76+
case DONE:
77+
stateName = "DONE";
78+
break;
79+
case LOST:
80+
stateName = "LOST";
81+
break;
82+
default:
83+
stateName = "UNKNOWN_STATE";
84+
break;
85+
}
86+
return stateName;
87+
}
4388
}
4489

4590
int latestGoalStatus;
4691
int state;
4792
int nextState;
48-
49-
50-
/**
51-
* Constructor
52-
*/
53-
public void ClientStateMachine()
54-
{
55-
// interface object for the callbacks?
56-
// store arguments locally in the object
57-
//this.goal = actionGoal;
58-
}
93+
private Log log = LogFactory.getLog(ActionClient.class);
5994

6095
public synchronized void setState(int state) {
96+
log.info("ClientStateMachine - State changed from " + this.state + " to " + state);
6197
this.state = state;
6298
}
6399

@@ -89,9 +125,7 @@ public synchronized void updateStatus(int status)
89125
// Determine the next state
90126

91127
//if (this.state
92-
93128
}
94-
95129
}
96130

97131
/**
@@ -107,6 +141,8 @@ public synchronized void transition(int goalStatus)
107141
nextStates = getTransition(goalStatus);
108142
iterStates = nextStates.iterator();
109143

144+
log.info("ClientStateMachine - State transition invoked.");
145+
110146
while (iterStates.hasNext()) {
111147
this.state = iterStates.next();
112148
}
@@ -432,9 +468,4 @@ public boolean cancel() {
432468
public void markAsLost()
433469
{
434470
}
435-
436-
public void updateResult(int statusResult)
437-
{
438-
}
439-
440471
}

0 commit comments

Comments
 (0)