while (!methodDescList.isEmpty()) {
MethodDescriptor md = methodDescList.removeLast();
- System.out.println("\n#updateCompositeLocationAssignments=" + md);
+ // System.out.println("\n#updateCompositeLocationAssignments=" + md);
FlowGraph flowGraph = getFlowGraph(md);
Set<FlowNode> nodeSet = flowGraph.getNodeSet();
for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
FlowNode node = (FlowNode) iterator.next();
- System.out.println("-node=" + node + " node.getDescTuple=" + node.getDescTuple());
+ // System.out.println("-node=" + node + " node.getDescTuple=" + node.getDescTuple());
if (node.getCompositeLocation() != null) {
CompositeLocation compLoc = node.getCompositeLocation();
CompositeLocation updatedCompLoc = updateCompositeLocation(compLoc);
node.setCompositeLocation(updatedCompLoc);
- System.out.println("---updatedCompLoc1=" + updatedCompLoc);
+ // System.out.println("---updatedCompLoc1=" + updatedCompLoc);
} else {
NTuple<Descriptor> descTuple = node.getDescTuple();
- System.out.println("update desc=" + descTuple);
+ // System.out.println("update desc=" + descTuple);
CompositeLocation compLoc = convertToCompositeLocation(md, descTuple);
compLoc = updateCompositeLocation(compLoc);
node.setCompositeLocation(compLoc);
- System.out.println("---updatedCompLoc2=" + compLoc);
+ // System.out.println("---updatedCompLoc2=" + compLoc);
}
if (node.isDeclaratonNode()) {
private void translateCompositeLocationAssignmentToFlowGraph(MethodDescriptor mdCaller) {
- System.out.println("\n\n###translateCompositeLocationAssignmentToFlowGraph mdCaller="
- + mdCaller);
+ // System.out.println("\n\n###translateCompositeLocationAssignmentToFlowGraph mdCaller="
+ // + mdCaller);
// First, assign a composite location to a node in the flow graph
GlobalFlowGraph callerGlobalFlowGraph = getSubGlobalFlowGraph(mdCaller);
// it matches with the current argument composite location
// so what is the corresponding parameter local descriptor?
FlowNode paramNode = calleeFlowGraph.getParamFlowNode(idx);
- System.out.println("----------found paramNode=" + paramNode);
+ // System.out.println("----------found paramNode=" + paramNode);
NTuple<Descriptor> paramDescTuple = paramNode.getCurrentDescTuple();
NTuple<Location> newParamTupleFromArgTuple = translateToLocTuple(mdCallee, paramDescTuple);
newParamTupleFromArgTuple.add(argLocTuple.get(i));
}
- System.out.println("-----------newParamTuple=" + newParamTupleFromArgTuple);
+ // System.out.println("-----------newParamTuple=" + newParamTupleFromArgTuple);
return new CompositeLocation(newParamTupleFromArgTuple);
}
for (Iterator iterator2 = holderOutEdge.iterator(); iterator2.hasNext();) {
FlowEdge outEdge = (FlowEdge) iterator2.next();
NTuple<Descriptor> toberemovedTuple = outEdge.getEndTuple();
- System.out.println("---remove " + tupleFromHolder + " -> " + toberemovedTuple);
+ // System.out.println("---remove " + tupleFromHolder + " -> " + toberemovedTuple);
callerFlowGraph.removeEdge(tupleFromHolder, toberemovedTuple);
}
}
System.out.println("----- add global flow globalArgLocTuple=" + globalArgLocTuple
+ "-> globalParamLocTuple=" + globalParamLocTuple);
hasChanges = true;
- System.out.println("B1");
globalGraph.addValueFlowEdge(globalArgLocTuple, globalParamLocTuple);
}
}
+ "-> globalParamLocTu!globalArgLocTuple.get(0).getLocDescriptor().equals(LITERALDESC)ple="
+ globalParamLocTuple);
hasChanges = true;
- System.out.println("B2");
globalGraph.addValueFlowEdge(pcLocTuple, globalParamLocTuple);
}
baseLocTuple = translateToLocTuple(mdCaller, mapMethodInvokeNodeToBaseTuple.get(min));
}
- System.out.println("\n-#translate caller=" + mdCaller + " infer composite loc to callee="
- + mdCallee + " baseLocTuple=" + baseLocTuple);
- // System.out.println("-mapIdxToArgTuple=" + mapIdxToArgTuple);
- // System.out.println("-callerMapLocToCompLoc=" + callerMapLocToCompLoc);
+ // System.out.println("\n-#translate caller=" + mdCaller + " infer composite loc to callee="
+ // + mdCallee + " baseLocTuple=" + baseLocTuple);
Set<Location> keySet = callerMapLocToCompLoc.keySet();
for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
translateCompositeLocationToCallee(callerCompLoc, baseLocTuple, mdCallee);
calleeGlobalGraph.addMapLocationToInferCompositeLocation(key, newCalleeCompLoc);
- System.out.println("1---key=" + key + " callerCompLoc=" + callerCompLoc
- + " newCalleeCompLoc=" + newCalleeCompLoc);
- System.out.println("-----caller=" + mdCaller + " callee=" + mdCallee);
+ // System.out.println("1---key=" + key + " callerCompLoc=" + callerCompLoc
+ // + " newCalleeCompLoc=" + newCalleeCompLoc);
+ // System.out.println("-----caller=" + mdCaller + " callee=" + mdCallee);
if (!newCalleeCompLoc.get(0).getDescriptor().equals(mdCallee)) {
System.exit(0);
}
newCalleeCompLoc.addLocation(callerCompLoc.get(i));
}
calleeGlobalGraph.addMapLocationToInferCompositeLocation(key, newCalleeCompLoc);
- System.out.println("2---key=" + key + " callerCompLoc=" + callerCompLoc
- + " newCalleeCompLoc=" + newCalleeCompLoc);
- System.out.println("-----caller=" + mdCaller + " callee=" + mdCallee);
+ // System.out.println("2---key=" + key + " callerCompLoc=" + callerCompLoc
+ // + " newCalleeCompLoc=" + newCalleeCompLoc);
+ // System.out.println("-----caller=" + mdCaller + " callee=" + mdCallee);
} else {
int paramIdx = getParamIdx(callerCompLoc, mapIdxToArgTuple);
// so transfer the same composite location to the callee
if (!calleeGlobalGraph.contrainsInferCompositeLocationMapKey(key)) {
if (callerCompLoc.get(0).getDescriptor().equals(mdCallee)) {
- System.out.println("3---key=" + key + " callerCompLoc=" + callerCompLoc
- + " newCalleeCompLoc=" + callerCompLoc);
- System.out.println("-----caller=" + mdCaller + " callee=" + mdCallee);
+ // System.out.println("3---key=" + key + " callerCompLoc=" + callerCompLoc
+ // + " newCalleeCompLoc=" + callerCompLoc);
+ // System.out.println("-----caller=" + mdCaller + " callee=" + mdCallee);
calleeGlobalGraph.addMapLocationToInferCompositeLocation(key, callerCompLoc);
} else {
- System.out.println("3---SKIP key=" + key + " callerCompLoc=" + callerCompLoc);
+ // System.out.println("3---SKIP key=" + key + " callerCompLoc=" + callerCompLoc);
}
}
continue;
newCalleeCompLoc.addLocation(callerCompLoc.get(i));
}
calleeGlobalGraph.addMapLocationToInferCompositeLocation(key, newCalleeCompLoc);
- System.out.println("4---key=" + key + " callerCompLoc=" + callerCompLoc
- + " newCalleeCompLoc=" + newCalleeCompLoc);
- System.out.println("-----caller=" + mdCaller + " callee=" + mdCallee);
-
- // System.out.println("-----argTuple=" + argTuple + " caller=" + mdCaller +
- // " callee="
- // + mdCallee);
- // System.out.println("-----paramIdx=" + paramIdx + " paramFlowNode=" + paramFlowNode);
+ // System.out.println("4---key=" + key + " callerCompLoc=" + callerCompLoc
+ // + " newCalleeCompLoc=" + newCalleeCompLoc);
+ // System.out.println("-----caller=" + mdCaller + " callee=" + mdCallee);
}
}
}
- // System.out.println("-----*AFTER TRANSLATING COMP LOC MAPPING, CALLEE MAPPING="
- // + calleeGlobalGraph.getMapLocationToInferCompositeLocation());
-
System.out.println("#ASSIGN COMP LOC TO CALLEE PARAMS: callee=" + mdCallee + " caller="
+ mdCaller);
// If the location of an argument has a composite location
if (!needToGenerateCompositeLocation(paramGlobalNode, curPrefix)) {
System.out.println("NO NEED TO GENERATE COMP LOC to " + paramGlobalNode
+ " with prefix=" + curPrefix);
- // System.out.println("prefixList=" + prefixList);
- // System.out.println("reachableNodeSet=" + reachableNodeSet);
return null;
}
for (Iterator iterator = paramNodeSet.iterator(); iterator.hasNext();) {
FlowNode paramFlowNode = (FlowNode) iterator.next();
if (curPrefix.startsWith(translateToLocTuple(md, paramFlowNode.getDescTuple()))) {
- System.out.println("here1?!");
return true;
}
}
FlowNode paramNode = getFlowGraph(mdCallee).getParamFlowNode(paramIdx);
if (checkNodeReachToReturnNode(mdCallee, paramNode)) {
- System.out.println("here2?!");
return true;
}
mapMethodDescriptorToCompositeReturnCase.get(md).booleanValue();
if (hasCompReturnLocWithThis) {
if (checkNodeReachToReturnNode(md, flowNode)) {
- System.out.println("here3?!");
return true;
}
}
GlobalFlowNode subGlobalReachalbeNode = (GlobalFlowNode) iterator3.next();
if (subGlobalReachalbeNode.getLocTuple().get(0).getLocDescriptor().equals(md.getThis())) {
System.out.println("PREFIX FOUND=" + subGlobalReachalbeNode);
- System.out.println("here4?!");
return true;
}
}
}
}
- // System.out.println("flowGraph.getReturnNodeSet()=" + flowGraph.getReturnNodeSet());
- // System.out.println("flowGraph.contains(node.getDescTuple())="
- // + flowGraph.contains(node.getDescTuple()) + " flowGraph.getFlowNode(node.getDescTuple())="
- // + flowGraph.getFlowNode(node.getDescTuple()));reachableSet
-
- // if (flowGraph.contains(node.getDescTuple())
- // && flowGraph.getReturnNodeSet().contains(flowGraph.getFlowNode(node.getDescTuple()))) {
- // // return checkFlowNodeReturnThisField(flowGraph);
- // }
-
Location lastLocationOfPrefix = curPrefix.get(curPrefix.size() - 1);
// check whether prefix appears in the list of parameters
Set<MethodInvokeNode> minSet = mapMethodDescToMethodInvokeNodeSet.get(md);
if (globalReachlocTuple.get(i).equals(lastLocationOfPrefix)) {
System.out.println("ARG " + argTuple + " IS MATCHED WITH="
+ lastLocationOfPrefix);
- System.out.println("here5?!");
-
return true;
}
}
}
}
- // ClassDescriptor cd;
- // if (lastLocationOfPrefix.getLocDescriptor() instanceof VarDescriptor) {
- // cd = ((VarDescriptor) lastLocationOfPrefix.getLocDescriptor()).getType().getClassDesc();
- // } else {
- // // it is a field descriptor
- // cd = ((FieldDescriptor) lastLocationOfPrefix.getLocDescriptor()).getType().getClassDesc();
- // }
- //
- // GlobalFlowGraph subGlobalFlowGraph = getSubGlobalFlowGraph(md);
- // Set<GlobalFlowNode> subGlobalReachableSet = subGlobalFlowGraph.getReachableNodeSetFrom(node);
- //
- // System.out.println("TRY TO FIND lastLocationOfPrefix=" + lastLocationOfPrefix);
- // for (Iterator iterator2 = subGlobalReachableSet.iterator(); iterator2.hasNext();) {
- // GlobalFlowNode subGlobalReachalbeNode = (GlobalFlowNode) iterator2.next();
- // // NTuple<Location> locTuple = translateToLocTuple(md, reachalbeNode.getDescTuple());
- // NTuple<Location> locTuple = subGlobalReachalbeNode.getLocTuple();
- //
- // for (int i = 0; i < locTuple.size(); i++) {
- // if (locTuple.get(i).equals(lastLocationOfPrefix)) {
- // return true;
- // }
- // }
- //
- // Location lastLoc = locTuple.get(locTuple.size() - 1);
- // Descriptor enclosingDescriptor = lastLoc.getDescriptor();
- //
- // if (enclosingDescriptor != null && enclosingDescriptor.equals(cd)) {
- // System.out.println("# WHY HERE?");
- // System.out.println("subGlobalReachalbeNode=" + subGlobalReachalbeNode);
- // return true;
- // }
- // }
-
return false;
}
}
});
- // remove a prefix which is not suitable for generating composite location
- Location localVarLoc = node.getLocTuple().get(0);
- MethodDescriptor md = (MethodDescriptor) localVarLoc.getDescriptor();
- ClassDescriptor cd = md.getClassDesc();
-
- int idx = 0;
- Set<NTuple<Location>> toberemoved = new HashSet<NTuple<Location>>();
- // for (int i = 0; i < prefixList.size(); i++) {
- // NTuple<Location> prefixLocTuple = prefixList.get(i);
- // if (!containsClassDesc(cd, prefixLocTuple)) {
- // toberemoved.add(prefixLocTuple);
- // }
- // }
-
- // System.out.println("method class=" + cd + " toberemoved=" + toberemoved);
-
- prefixList.removeAll(toberemoved);
-
return prefixList;
}
MethodDescriptor curPrefixFirstElementMethodDesc =
(MethodDescriptor) curPrefix.get(0).getDescriptor();
- // MethodDescriptor nodePrefixLocFirstElementMethodDesc =
- // (MethodDescriptor) prefixLoc.getDescriptor();
-
- // System.out.println("curPrefixFirstElementMethodDesc=" +
- // curPrefixFirstElementMethodDesc);
- // System.out.println("nodePrefixLocFirstElementMethodDesc="
- // + nodePrefixLocFirstElementMethodDesc);
-
- // TODO
- // if (!node.getLocTuple().startsWith(curPrefix.get(0))) {
-
Location curPrefixLocalLoc = curPrefix.get(0);
Location targetLocalLoc = new Location(md, node.getDescTuple().get(0));
System.out.println("NEED2ASSIGN COMP LOC TO " + node + " with prefix=" + curPrefix);
System.out.println("-targetLocalLoc=" + targetLocalLoc + " - newCompLoc=" + newCompLoc);
- // // makes sure that a newly generated location appears in the hierarchy graph
- // for (int compIdx = 0; compIdx < newCompLoc.getSize(); compIdx++) {
- // Location curLoc = newCompLoc.get(compIdx);
- // getHierarchyGraph(curLoc.getDescriptor()).getHNode(curLoc.getLocDescriptor());
- // }
- // subGlobalFlowGraph.addMapLocationToInferCompositeLocation(targetLocalLoc, newCompLoc);
node.setCompositeLocation(newCompLoc);
return newCompLoc;
// here only keep the first element(method location) of the descriptor
// tuple
NTuple<Location> srcLocTuple = translateToLocTuple(md, srcDescTuple);
- // Location srcMethodLoc = srcLocTuple.get(0);
- // Descriptor srcVarDesc = srcMethodLoc.getLocDescriptor();
- // // if (flowGraph.isParamDesc(srcVarDesc) &&
- // (!srcVarDesc.equals(md.getThis()))) {
- // if (!srcVarDesc.equals(md.getThis())) {
- // srcLocTuple = new NTuple<Location>();
- // Location loc = new Location(md, srcVarDesc);
- // srcLocTuple.add(loc);
- // }
- //
NTuple<Location> dstLocTuple = translateToLocTuple(md, dstDescTuple);
- // Location dstMethodLoc = dstLocTuple.get(0);
- // Descriptor dstVarDesc = dstMethodLoc.getLocDescriptor();
- // if (!dstVarDesc.equals(md.getThis())) {
- // dstLocTuple = new NTuple<Location>();
- // Location loc = new Location(md, dstVarDesc);
- // dstLocTuple.add(loc);
- // }
- System.out.println("B11");
globalGraph.addValueFlowEdge(srcLocTuple, dstLocTuple);
} else if (desc instanceof FieldDescriptor) {
enclosingDesc = ((FieldDescriptor) desc).getType().getClassDesc();
} else {
- // TODO: inter descriptor case
enclosingDesc = desc;
}
if (callerSrcNodeLocTuple != null && callerSrcNodeLocTuple.size() > 0) {
for (Iterator iterator2 = pcLocTupleSet.iterator(); iterator2.hasNext();) {
NTuple<Location> pcLocTuple = (NTuple<Location>) iterator2.next();
- System.out.println("B12");
callerSubGlobalGraph.addValueFlowEdge(pcLocTuple, callerSrcNodeLocTuple);
}
// + callerDstNodeLocTuple);
if (callerSrcNodeLocTuple != null && callerDstNodeLocTuple != null
&& callerSrcNodeLocTuple.size() > 0 && callerDstNodeLocTuple.size() > 0) {
- System.out.println("B3");
callerSubGlobalGraph.addValueFlowEdge(callerSrcNodeLocTuple, callerDstNodeLocTuple);
}
}
FlowNode flowNode = flowGraph.getParamFlowNode(paramIdx);
CompositeLocation inferredCompLoc =
updateCompositeLocation(flowNode.getCompositeLocation());
- // NTuple<Descriptor> descTuple = flowNode.getDescTuple();
- //
- // CompositeLocation assignedCompLoc = flowNode.getCompositeLocation();
- // CompositeLocation inferredCompLoc;
- // if (assignedCompLoc != null) {
- // inferredCompLoc = translateCompositeLocation(assignedCompLoc);
- // } else {
- // Descriptor locDesc = descTuple.get(0);
- // Location loc = new Location(md, locDesc.getSymbol());
- // loc.setLocDescriptor(locDesc);
- // inferredCompLoc = new CompositeLocation(loc);
- // }
System.out.println("-paramIdx=" + paramIdx + " infer=" + inferredCompLoc + " original="
+ flowNode.getCompositeLocation());
if (!paramDescNOTHavingInFlowSet.contains(node.getCurrentDescTuple().get(0))) {
flowNodeLowerthanPCLocSet.add(node);
fg.addValueFlowEdge(pcDescTuple, node.getDescTuple());
- System.out.println("B10");
subGlobalFlowGraph.addValueFlowEdge(pcLocTuple,
translateToLocTuple(md, node.getDescTuple()));
newImplicitTupleSet.addTupleSet(implicitFlowTupleSet);
newImplicitTupleSet.addTupleSet(condTupleNode);
- System.out.println("A5");
newImplicitTupleSet.addGlobalFlowTupleSet(implicitFlowTupleSet.getGlobalLocTupleSet());
newImplicitTupleSet.addGlobalFlowTupleSet(condTupleNode.getGlobalLocTupleSet());
// translateToLocTuple(md, callerImplicitTuple));
// }
// }
- System.out.println("A4");
newImplicitTupleSet.addGlobalFlowTupleSet(condTupleNode.getGlobalLocTupleSet());
analyzeFlowBlockNode(md, nametable, isn.getTrueBlock(), newImplicitTupleSet);
GlobalFlowGraph globalFlowGraph = getSubGlobalFlowGraph(md);
for (Iterator<NTuple<Location>> iterator = nodeSetRHS.globalIterator(); iterator.hasNext();) {
NTuple<Location> calleeReturnLocTuple = iterator.next();
- System.out.println("B7");
globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple, translateToLocTuple(md, tupleLHS));
}
for (Iterator<NTuple<Location>> iterator = implicitFlowTupleSet.globalIterator(); iterator
.hasNext();) {
NTuple<Location> implicitGlobalTuple = iterator.next();
- System.out.println("B8");
globalFlowGraph.addValueFlowEdge(implicitGlobalTuple, translateToLocTuple(md, tupleLHS));
}
private void analyzeFlowTertiaryNode(MethodDescriptor md, SymbolTable nametable, TertiaryNode tn,
NodeTupleSet nodeSet, NodeTupleSet implicitFlowTupleSet) {
- System.out.println("analyzeFlowTertiaryNode=" + tn.printNode(0));
+ // System.out.println("analyzeFlowTertiaryNode=" + tn.printNode(0));
NodeTupleSet tertiaryTupleNode = new NodeTupleSet();
analyzeFlowExpressionNode(md, nametable, tn.getCond(), tertiaryTupleNode, null,
newImplicitTupleSet.addTuple(interTuple);
}
- System.out.println("A7");
newImplicitTupleSet.addGlobalFlowTupleSet(tertiaryTupleNode.getGlobalLocTupleSet());
System.out.println("---------newImplicitTupleSet=" + newImplicitTupleSet);
analyzeFlowExpressionNode(md, nametable, tn.getFalseExpr(), tertiaryTupleNode, null,
newImplicitTupleSet, false);
- System.out.println("A8");
nodeSet.addGlobalFlowTupleSet(tertiaryTupleNode.getGlobalLocTupleSet());
nodeSet.addTupleSet(tertiaryTupleNode);
}
returnHolderNode.addTuple(interTuple);
- // TODO
+
nodeSet.addTuple(interTuple);
System.out.println("ADD TUPLESET=" + interTuple + " to returnnode=" + returnHolderNode);
NTuple<Location> calleeReturnLocTuple = iterator.next();
for (Iterator<NTuple<Descriptor>> arrIter = expNodeTupleSet.iterator(); arrIter.hasNext();) {
NTuple<Descriptor> arrTuple = arrIter.next();
- System.out.println("B4");
globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple, translateToLocTuple(md, arrTuple));
}
}
}
- System.out.println("A1");
nodeSet.addGlobalFlowTupleSet(idxNodeTupleSet.getGlobalLocTupleSet());
nodeSet.addTupleSet(nodeSetArrayAccessExp);
nodeSet.addTupleSet(leftOpSet);
nodeSet.addTupleSet(rightOpSet);
- System.out.println("A6");
nodeSet.addGlobalFlowTupleSet(leftOpSet.getGlobalLocTupleSet());
nodeSet.addGlobalFlowTupleSet(rightOpSet.getGlobalLocTupleSet());
for (Iterator<NTuple<Location>> iterator = idxNodeTupleSet.globalIterator(); iterator
.hasNext();) {
NTuple<Location> calleeReturnLocTuple = iterator.next();
- System.out.println("B9");
globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple,
translateToLocTuple(md, flowFieldTuple));
nodeSet.clear();
flowFieldTuple = interTuple;
}
- System.out.println("A3");
nodeSet.addGlobalFlowTupleSet(idxNodeTupleSet.getGlobalLocTupleSet());
}
NTuple<Descriptor> callerLHSTuple = iter2.next();
System.out.println("$$$ GLOBAL FLOW ADD=" + calleeReturnLocTuple + " -> "
+ translateToLocTuple(md, callerLHSTuple));
- System.out.println("B5");
globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple,
translateToLocTuple(md, callerLHSTuple));
NTuple<Location> calleeReturnLocTuple = iterator.next();
for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
NTuple<Descriptor> callerLHSTuple = iter2.next();
- System.out.println("B6");
globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple,
translateToLocTuple(md, callerLHSTuple));
if (nodeSet != null) {
nodeSet.addTupleSet(nodeSetLHS);
- System.out.println("A2");
nodeSet.addGlobalFlowTupleSet(nodeSetLHS.getGlobalLocTupleSet());
}
}
--- /dev/null
+@LATTICE("V")
+public class Command {
+
+ @LOC("V") public int onOffMode;
+ @LOC("V") public int manualAutonomusMode;
+ @LOC("V") public byte lineSensorsMask;
+ @LOC("V") public byte sonarSensors;
+ @LOC("V") byte command;
+
+}
--- /dev/null
+public class HWSimulator {
+
+ public static int onOffMode = RobotMain.ON_MODE;
+ public static int manualAutonomusMode = RobotMain.AUTONOMUS_MODE;
+ public static byte lineSensorsMask;
+ public static byte sonarSensors;
+
+ // public byte currentSonars;
+
+ @TRUST
+ public static Command getCommand() {
+
+ byte currentCommand = TestSensorInput.getCommand();
+
+ int data = (int) (currentCommand & RobotMain.ALL_DATA);
+ int opCode = (int) (currentCommand & 0xe0); // ALL_COMMANDS);
+
+ switch ((int) opCode) {
+ case RobotMain.ON_OFF:
+ if ((data & 0x1) == 0x1) {
+ HWSimulator.onOffMode = RobotMain.ON_MODE;
+ } else {
+ HWSimulator.onOffMode = RobotMain.OFF_MODE;
+ }
+ break;
+ case RobotMain.MANUAL_AUTONOMUS:
+ if ((data & 0x1) == 0x1) {
+ HWSimulator.manualAutonomusMode = RobotMain.MANUAL_MODE;
+ } else {
+ HWSimulator.manualAutonomusMode = RobotMain.AUTONOMUS_MODE;
+ }
+ break;
+ case RobotMain.LINE_SENSORS:
+ HWSimulator.lineSensorsMask = (byte) (data & RobotMain.LS_ALL);
+ break;
+ case RobotMain.SONAR_SENSORS:
+ HWSimulator.sonarSensors = (byte) (data & RobotMain.ALL_SONARS);
+ break;
+ }
+
+ Command com = new Command();
+
+ com.command = currentCommand;
+
+ com.onOffMode = HWSimulator.onOffMode;
+ com.manualAutonomusMode = HWSimulator.manualAutonomusMode;
+ com.lineSensorsMask = HWSimulator.lineSensorsMask;
+ com.sonarSensors = HWSimulator.sonarSensors;
+
+ return com;
+
+ }
+
+}
*/\r
\r
/**\r
- * PWMManager - Interface between robot strategy code and the various motors\r
- * PWMControl classes. Agility is a number between 0 to 100 and represent the\r
- * precentage of max speed to be applied to the turn side wheel. On left turn\r
- * the left wheel will receive less speed as % of "speed" value represented by\r
- * agility.\r
+ * PWMManager - Interface between robot strategy code and the various motors PWMControl classes.\r
+ * Agility is a number between 0 to 100 and represent the precentage of max speed to be applied to\r
+ * the turn side wheel. On left turn the left wheel will receive less speed as % of "speed" value\r
+ * represented by agility.\r
* \r
* @author Michael Gesundheit\r
* @version 1.0\r
*/\r
public PWMManager(String pwmSelection) {\r
/*\r
- * Instantiate PWM Makers one for each motor. motorPortId is 1 to 8 and is\r
- * corresponding to 8 bits in a byte.\r
+ * Instantiate PWM Makers one for each motor. motorPortId is 1 to 8 and is corresponding to 8\r
+ * bits in a byte.\r
*/\r
// if (pwmSelection.equals("rtsj"))\r
// pwmControl = new PWMRtsj(this, MOTOR_PORTID_6, MOTOR_PORTID_7);\r
currentRegMask |= myValue;\r
/*\r
* // if (DEBUG){ // System.out.println("PWMM: writeToPort: myBit = 0x" +\r
- * Integer.toHexString(myBit) + // " ~myBit = 0x" +\r
- * Integer.toHexString(~myBit) + " myValue = 0x" + //\r
- * Integer.toHexString(myValue) + " currentRegMask = 0x" + //\r
+ * Integer.toHexString(myBit) + // " ~myBit = 0x" + Integer.toHexString(~myBit) +\r
+ * " myValue = 0x" + // Integer.toHexString(myValue) + " currentRegMask = 0x" + //\r
* Integer.toHexString(currentRegMask)); //}\r
*/\r
// rawJEM.set(GPIO_E_OUT, currentRegMask);\r
* public void stop(){ if(DEBUG) System.out.println("PWMManager: stop....");\r
* pwmControl.setSpeedLeft(zeroSpeed); pwmControl.setSpeedRight(zeroSpeed); }\r
* \r
- * public void search(){ if(DEBUG)\r
- * System.out.println("PWMManager: search...."); pwmControl.setSpeedLeft(70);\r
- * pwmControl.setSpeedRight(50); }\r
+ * public void search(){ if(DEBUG) System.out.println("PWMManager: search....");\r
+ * pwmControl.setSpeedLeft(70); pwmControl.setSpeedRight(50); }\r
* \r
- * public void straight(){ if(DEBUG)\r
- * System.out.println("PWMManager: strait...."); pwmControl.setSpeedLeft(100);\r
- * pwmControl.setSpeedRight(100); }\r
+ * public void straight(){ if(DEBUG) System.out.println("PWMManager: strait....");\r
+ * pwmControl.setSpeedLeft(100); pwmControl.setSpeedRight(100); }\r
* \r
- * public void spinRight(){ if(DEBUG)\r
- * System.out.println("PWMManager: spinRight....");\r
+ * public void spinRight(){ if(DEBUG) System.out.println("PWMManager: spinRight....");\r
* pwmControl.setSpeedSpinLeft(100); pwmControl.setSpeedSpinRight(0); }\r
* \r
- * public void spinLeft(){ if(DEBUG)\r
- * System.out.println("PWMManager: spinLeft....");\r
+ * public void spinLeft(){ if(DEBUG) System.out.println("PWMManager: spinLeft....");\r
* pwmControl.setSpeedSpinLeft(0); pwmControl.setSpeedSpinRight(100); }\r
* \r
* public void spin180(){ int mod = (rand.nextInt() % 2);\r
* public void left(){ if(DEBUG) System.out.println("PWMManager: left....");\r
* pwmControl.setSpeedLeft(zeroSpeed); pwmControl.setSpeedTurnRight(100); }\r
* \r
- * public void bearRight(){ if(DEBUG)\r
- * System.out.println("PWMManager: bearRight....");\r
+ * public void bearRight(){ if(DEBUG) System.out.println("PWMManager: bearRight....");\r
* pwmControl.setSpeedTurnLeft(100); pwmControl.setSpeedTurnRight(60); }\r
* \r
- * public void bearLeft(){ if(DEBUG)\r
- * System.out.println("PWMManager: bearLeft....");\r
+ * public void bearLeft(){ if(DEBUG) System.out.println("PWMManager: bearLeft....");\r
* pwmControl.setSpeedTurnLeft(60); pwmControl.setSpeedTurnRight(100); }\r
* \r
* public void back(){ if(DEBUG) System.out.println("PWMManager: back....");\r
* pwmControl.setSpeedLeft(0); pwmControl.setSpeedRight(0); }\r
* \r
- * public void backBearLeft(){ if(DEBUG)\r
- * System.out.println("PWMManager: backBearLeft....");\r
+ * public void backBearLeft(){ if(DEBUG) System.out.println("PWMManager: backBearLeft....");\r
* pwmControl.setSpeedLeft(30); pwmControl.setSpeedRight(0); }\r
* \r
- * public void backBearRight(){ if(DEBUG)\r
- * System.out.println("PWMManager: backBearRight....");\r
+ * public void backBearRight(){ if(DEBUG) System.out.println("PWMManager: backBearRight....");\r
* pwmControl.setSpeedLeft(0); pwmControl.setSpeedRight(30); }\r
*/\r
public void resume() {\r
}\r
\r
/**\r
- * Control debug messaging. true - Activate debug messages false - deactivate\r
- * debug messages\r
+ * Control debug messaging. true - Activate debug messages false - deactivate debug messages\r
*/\r
public void setDebug(boolean debug) {\r
DEBUG = debug;\r
}\r
+\r
}
\ No newline at end of file
* @author Michael Gesundheit
* @version 1.0
*/
-@METHODDEFAULT("IN")
+@METHODDEFAULT("IN,THISLOC=IN")
public class RCBridge {
public void setManualMode() {
--- /dev/null
+public class RandomWrapper {
+ private static Random rand;
+
+ @TRUST
+ public static void init() {
+ rand = new Random();
+ }
+
+ @TRUST
+ public static int nextInt() {
+ return rand.nextInt();
+ }
+
+}
@LOC("T")\r
private static boolean DEBUG = true;\r
\r
- private static final int OFF_MODE = 1;\r
- private static final int ON_MODE = 2;\r
- private static final int MANUAL_MODE = 1;\r
- private static final int AUTONOMUS_MODE = 2;\r
- private static final int ON_OFF = 128;// 0x80\r
- private static final int MANUAL_AUTONOMUS = 32; // 0x20\r
+ public static final int OFF_MODE = 1;\r
+ public static final int ON_MODE = 2;\r
+ public static final int MANUAL_MODE = 1;\r
+ public static final int AUTONOMUS_MODE = 2;\r
+ public static final int ON_OFF = 128;// 0x80\r
+ public static final int MANUAL_AUTONOMUS = 32; // 0x20\r
public static final int LINE_SENSORS = 64; // 0x40\r
- private static final int SONAR_SENSORS = 96; // 0x60\r
+ public static final int SONAR_SENSORS = 96; // 0x60\r
public static final int ALL_COMMANDS = 0xe0;\r
\r
public static final byte LF_FRONT = 0x1;\r
public static final byte LS_LEFT_REAR = 0x5;\r
public static final byte LS_RIGHT_REAR = 0x6;\r
public static final byte LS_ALL = 0x7;\r
- private static final int ALL_DATA = 0x1f;\r
+ public static final int ALL_DATA = 0x1f;\r
\r
@LOC("MGR")\r
- private static PWMManager pwmm;\r
+ private PWMManager pwmm;\r
@LOC("MGR")\r
- private static StrategyMgr strategyMgr;\r
+ private StrategyMgr strategyMgr;\r
\r
@LOC("MASK")\r
- private static int onOffMode = ON_MODE;\r
+ private int onOffMode = ON_MODE;\r
@LOC("MASK")\r
- private static int manualAutonomusMode = AUTONOMUS_MODE;\r
+ private int manualAutonomusMode = AUTONOMUS_MODE;\r
@LOC("MASK")\r
- private static byte lineSensorsMask;\r
+ private byte lineSensorsMask;\r
@LOC("MASK")\r
- private static byte sonarSensors;\r
+ private byte sonarSensors;\r
@LOC("CCMD")\r
- private static byte currentCommand;\r
+ private byte currentCommand;\r
@LOC("MASK")\r
- private static byte privSonars;\r
+ private byte privSonars;\r
@LOC("PREV")\r
- private static byte privLineSensors;\r
+ private byte privLineSensors;\r
@LOC("MASK")\r
- private static byte currentSonars;\r
+ private byte currentSonars;\r
@LOC("MASK")\r
- public static String pwmSelection;\r
+ public String pwmSelection;\r
\r
/**\r
* Constructor for the class for the robot main thread.\r
}\r
\r
/**\r
- * Processes sonar sensor input. This method is called each time new sonar\r
- * sensor data arrives, and each time that a mode switch occurs between ON/OFF\r
- * and Manual Override.\r
+ * Processes sonar sensor input. This method is called each time new sonar sensor data arrives,\r
+ * and each time that a mode switch occurs between ON/OFF and Manual Override.\r
*/\r
- static void processSonars() {\r
+ void processSonars() {\r
strategyMgr.processSonars(sonarSensors);\r
}\r
\r
/**\r
- * Processes line sensor input. This method is called each time new line\r
- * sensor data arrives, and each time that a mode switch occurs between ON/OFF\r
- * and Manual Override.\r
+ * Processes line sensor input. This method is called each time new line sensor data arrives, and\r
+ * each time that a mode switch occurs between ON/OFF and Manual Override.\r
*/\r
- static void processLineSensors() {\r
+ void processLineSensors() {\r
strategyMgr.processLineSensors(lineSensorsMask);\r
resume();\r
}\r
/**\r
* Resumes motors as per the last sonar command.\r
*/\r
- public static void resume() {\r
+ void resume() {\r
processSonars();\r
}\r
\r
/**\r
- * Extracts sonar sensor data from the adjunct sensor controller and from line\r
- * sensor data from the JStamp line sensor pins.\r
+ * Extracts sonar sensor data from the adjunct sensor controller and from line sensor data from\r
+ * the JStamp line sensor pins.\r
*/\r
@LATTICE("THIS,THISLOC=THIS,GLOBALLOC=THIS")\r
- private static void processIOCommand() {\r
+ private void processIOCommand() {\r
\r
// int data = 0;\r
// int opCode = 0;\r
lineSensorsMask = (byte) (data & LS_ALL);\r
\r
/*\r
- * Line sensors with '0' data means the robot moved off the edge line, and\r
- * there is nothing to do.\r
+ * Line sensors with '0' data means the robot moved off the edge line, and there is nothing to\r
+ * do.\r
*/\r
if (((data & LS_ALL) == 0) || ((data & LS_ALL) == privLineSensors)) {\r
privLineSensors = (byte) (data & LS_ALL);\r
}\r
currentSonars = (byte) (data & ALL_SONARS);\r
/*\r
- * No need to synchronized on this variable assignment since all referring\r
- * code is on the same logical thread\r
+ * No need to synchronized on this variable assignment since all referring code is on the same\r
+ * logical thread\r
*/\r
sonarSensors = (byte) currentSonars;\r
if ((onOffMode == ON_MODE) && (manualAutonomusMode == AUTONOMUS_MODE)) {\r
/**\r
* Saves the current IOManager command byte locally.\r
*/\r
- static public void setIOManagerCommand(byte[] cmd) {\r
+ public void setIOManagerCommand(byte[] cmd) {\r
// synchronized (obj1) {\r
currentCommand = cmd[0];\r
// }\r
}\r
\r
/**\r
- * Sets debug messaging state: true - Activate debug messages false -\r
- * deactivate debug messages\r
+ * Sets debug messaging state: true - Activate debug messages false - deactivate debug messages\r
*/\r
static public void setDebug(boolean debug) {\r
DEBUG = debug;\r
/**\r
* Runs the robot's main thread.\r
*/\r
- @LATTICE("THIS<C,THIS<MC,MC<IN,C<IN,IN<T,C*,THISLOC=THIS,GLOBALLOC=THIS")\r
public static void main(@LOC("IN") String args[]) {\r
\r
TestSensorInput.init();\r
+ RobotMain r = new RobotMain();\r
+ r.doit();\r
+ }\r
+\r
+ @LATTICE("THIS<C,THIS<MC,MC<IN,C<IN,IN<T,C*,THISLOC=THIS,GLOBALLOC=THIS")\r
+ public void doit() {\r
@LOC("T") boolean active = true;\r
/**\r
- * RealTime management of the robot behaviour based on sensors and commands\r
- * input.\r
+ * RealTime management of the robot behaviour based on sensors and commands input.\r
*/\r
\r
/**\r
- * Set the low level PWM interface type, e.g. "rtsj" or "native" (ajile\r
- * library-based).\r
+ * Set the low level PWM interface type, e.g. "rtsj" or "native" (ajile library-based).\r
*/\r
pwmSelection = "rtsj";\r
\r
strategyMgr = new StrategyMgr(mc);\r
\r
/*\r
- * Sets initial values for the speed and agility parameters. Speed and\r
- * agility are arbitrary scale factors for the overall speed and speed of\r
- * turns, respectively. These work with PWM via the native ajile libraries,\r
- * but do not work well with the RTSJ implementation due to limits on the\r
- * granularity of timing for the PWM pulse (quantization).\r
+ * Sets initial values for the speed and agility parameters. Speed and agility are arbitrary\r
+ * scale factors for the overall speed and speed of turns, respectively. These work with PWM via\r
+ * the native ajile libraries, but do not work well with the RTSJ implementation due to limits\r
+ * on the granularity of timing for the PWM pulse (quantization).\r
*/\r
pwmm.setSpeedAgilityFactors(100, 100);\r
\r
/*\r
- * Robot's initial state is "ON" by default. Set this parameter to "OFF" if\r
- * the robot is to be started over the TCP/IP link.\r
+ * Robot's initial state is "ON" by default. Set this parameter to "OFF" if the robot is to be\r
+ * started over the TCP/IP link.\r
*/\r
// issueCommand("OFF");\r
\r
SSJAVA: while (active) {\r
\r
- // if (DEBUG) {\r
- // System.out.println("Main: Waiting for remote commands");\r
- // }\r
- // try {\r
- // obj.wait();\r
- // } catch (IllegalMonitorStateException ie) {\r
- // System.out.println("IllegalMonitorStateException caught in main loop");\r
- // }\r
- currentCommand = TestSensorInput.getCommand();\r
+ @LOC("IN") Command com = HWSimulator.getCommand();\r
+ currentCommand = com.command;\r
+ sonarSensors = com.sonarSensors;\r
+ lineSensorsMask = com.lineSensorsMask;\r
+ manualAutonomusMode = com.manualAutonomusMode;\r
+ onOffMode = com.onOffMode;\r
+\r
if (currentCommand == -1) {\r
break;\r
}\r
System.out.println("currentCommand=" + currentCommand);\r
processIOCommand();\r
+ // erase current settings\r
+ initialize();\r
}\r
System.exit(0);\r
}\r
\r
+ public void initialize() {\r
+ privLineSensors = 0;\r
+ currentCommand = 0;\r
+ privSonars = 0;\r
+ currentSonars = 0;\r
+ pwmSelection = "";\r
+ }\r
+\r
}\r
private MotorControl mc;\r
private static final int zeroSpeed = 45;\r
@LOC("T")\r
- private Random rand;\r
- @LOC("T")\r
private boolean DEBUGL = true;\r
// private boolean DEBUGL = false;\r
\r
*/\r
public StrategyMgr(@DELEGATE MotorControl motorControl) {\r
mc = motorControl;\r
- rand = new Random();\r
+ RandomWrapper.init();\r
}\r
\r
void processSonars(@LOC("IN") byte sonarSensors) {\r
}\r
\r
public void spin180() {\r
- @LOC("THIS,StrategyMgr.V") int mod = (rand.nextInt() % 2);\r
+ @LOC("THIS,StrategyMgr.V") int mod = (RandomWrapper.nextInt() % 2);\r
\r
if (DEBUG)\r
System.out.println("StrategyMgr: spin180....");\r
--- /dev/null
+
+public class Command {
+
+ public int onOffMode;
+ public int manualAutonomusMode;
+ public byte lineSensorsMask;
+ public byte sonarSensors;
+ byte command;
+
+}
--- /dev/null
+public class HWSimulator {
+
+ public static int onOffMode = RobotMain.ON_MODE;
+ public static int manualAutonomusMode = RobotMain.AUTONOMUS_MODE;
+ public static byte lineSensorsMask;
+ public static byte sonarSensors;
+
+ // public byte currentSonars;
+
+ @TRUST
+ public static Command getCommand() {
+
+ byte currentCommand = TestSensorInput.getCommand();
+
+ int data = (int) (currentCommand & RobotMain.ALL_DATA);
+ int opCode = (int) (currentCommand & 0xe0); // ALL_COMMANDS);
+
+ switch ((int) opCode) {
+ case RobotMain.ON_OFF:
+ if ((data & 0x1) == 0x1) {
+ HWSimulator.onOffMode = RobotMain.ON_MODE;
+ } else {
+ HWSimulator.onOffMode = RobotMain.OFF_MODE;
+ }
+ break;
+ case RobotMain.MANUAL_AUTONOMUS:
+ if ((data & 0x1) == 0x1) {
+ HWSimulator.manualAutonomusMode = RobotMain.MANUAL_MODE;
+ } else {
+ HWSimulator.manualAutonomusMode = RobotMain.AUTONOMUS_MODE;
+ }
+ break;
+ case RobotMain.LINE_SENSORS:
+ HWSimulator.lineSensorsMask = (byte) (data & RobotMain.LS_ALL);
+ break;
+ case RobotMain.SONAR_SENSORS:
+ HWSimulator.sonarSensors = (byte) (data & RobotMain.ALL_SONARS);
+ break;
+ }
+
+ Command com = new Command();
+
+ com.command = currentCommand;
+
+ com.onOffMode = HWSimulator.onOffMode;
+ com.manualAutonomusMode = HWSimulator.manualAutonomusMode;
+ com.lineSensorsMask = HWSimulator.lineSensorsMask;
+ com.sonarSensors = HWSimulator.sonarSensors;
+
+ return com;
+
+ }
+
+}
System.out.println("setSpeedTurnLeft: input-> " + Integer.toString(timePosition));\r
}\r
int timePosLocal = normalizeTime(timePosition);\r
- int motorUpTime =\r
- (timePosLocal * 100 + ((100 - timePosLocal) * (100 - agilityFactor))) * speedFactor;\r
+ int motorUpTime = (timePosLocal * 100 + ((100 - timePosLocal) * (100 - agilityFactor))) * speedFactor;\r
if (motorUpTime == 0) {\r
motorUpTime = 1;\r
// System.out.println("returning....");\r
System.out.println("setSpeedTurnRight: input-> " + Integer.toString(timePosition));\r
}\r
int timePos = normalizeTime(timePosition);\r
- int motorUpTime =\r
- ((timePos * 100) + ((100 - timePos) * (100 - agilityFactor))) * speedFactor;\r
+ int motorUpTime = ((timePos * 100) + ((100 - timePos) * (100 - agilityFactor))) * speedFactor;\r
if (motorUpTime == 0) {\r
motorUpTime = 1;\r
// System.out.println("returning....");\r
*/\r
\r
/**\r
- * PWMManager - Interface between robot strategy code and the various motors\r
- * PWMControl classes. Agility is a number between 0 to 100 and represent the\r
- * precentage of max speed to be applied to the turn side wheel. On left turn\r
- * the left wheel will receive less speed as % of "speed" value represented by\r
- * agility.\r
+ * PWMManager - Interface between robot strategy code and the various motors PWMControl classes.\r
+ * Agility is a number between 0 to 100 and represent the precentage of max speed to be applied to\r
+ * the turn side wheel. On left turn the left wheel will receive less speed as % of "speed" value\r
+ * represented by agility.\r
* \r
* @author Michael Gesundheit\r
* @version 1.0\r
*/\r
public PWMManager(String pwmSelection) {\r
/*\r
- * Instantiate PWM Makers one for each motor. motorPortId is 1 to 8 and is\r
- * corresponding to 8 bits in a byte.\r
+ * Instantiate PWM Makers one for each motor. motorPortId is 1 to 8 and is corresponding to 8\r
+ * bits in a byte.\r
*/\r
// if (pwmSelection.equals("rtsj"))\r
// pwmControl = new PWMRtsj(this, MOTOR_PORTID_6, MOTOR_PORTID_7);\r
currentRegMask |= myValue;\r
/*\r
* // if (DEBUG){ // System.out.println("PWMM: writeToPort: myBit = 0x" +\r
- * Integer.toHexString(myBit) + // " ~myBit = 0x" +\r
- * Integer.toHexString(~myBit) + " myValue = 0x" + //\r
- * Integer.toHexString(myValue) + " currentRegMask = 0x" + //\r
+ * Integer.toHexString(myBit) + // " ~myBit = 0x" + Integer.toHexString(~myBit) +\r
+ * " myValue = 0x" + // Integer.toHexString(myValue) + " currentRegMask = 0x" + //\r
* Integer.toHexString(currentRegMask)); //}\r
*/\r
// rawJEM.set(GPIO_E_OUT, currentRegMask);\r
* public void stop(){ if(DEBUG) System.out.println("PWMManager: stop....");\r
* pwmControl.setSpeedLeft(zeroSpeed); pwmControl.setSpeedRight(zeroSpeed); }\r
* \r
- * public void search(){ if(DEBUG)\r
- * System.out.println("PWMManager: search...."); pwmControl.setSpeedLeft(70);\r
- * pwmControl.setSpeedRight(50); }\r
+ * public void search(){ if(DEBUG) System.out.println("PWMManager: search....");\r
+ * pwmControl.setSpeedLeft(70); pwmControl.setSpeedRight(50); }\r
* \r
- * public void straight(){ if(DEBUG)\r
- * System.out.println("PWMManager: strait...."); pwmControl.setSpeedLeft(100);\r
- * pwmControl.setSpeedRight(100); }\r
+ * public void straight(){ if(DEBUG) System.out.println("PWMManager: strait....");\r
+ * pwmControl.setSpeedLeft(100); pwmControl.setSpeedRight(100); }\r
* \r
- * public void spinRight(){ if(DEBUG)\r
- * System.out.println("PWMManager: spinRight....");\r
+ * public void spinRight(){ if(DEBUG) System.out.println("PWMManager: spinRight....");\r
* pwmControl.setSpeedSpinLeft(100); pwmControl.setSpeedSpinRight(0); }\r
* \r
- * public void spinLeft(){ if(DEBUG)\r
- * System.out.println("PWMManager: spinLeft....");\r
+ * public void spinLeft(){ if(DEBUG) System.out.println("PWMManager: spinLeft....");\r
* pwmControl.setSpeedSpinLeft(0); pwmControl.setSpeedSpinRight(100); }\r
* \r
* public void spin180(){ int mod = (rand.nextInt() % 2);\r
* public void left(){ if(DEBUG) System.out.println("PWMManager: left....");\r
* pwmControl.setSpeedLeft(zeroSpeed); pwmControl.setSpeedTurnRight(100); }\r
* \r
- * public void bearRight(){ if(DEBUG)\r
- * System.out.println("PWMManager: bearRight....");\r
+ * public void bearRight(){ if(DEBUG) System.out.println("PWMManager: bearRight....");\r
* pwmControl.setSpeedTurnLeft(100); pwmControl.setSpeedTurnRight(60); }\r
* \r
- * public void bearLeft(){ if(DEBUG)\r
- * System.out.println("PWMManager: bearLeft....");\r
+ * public void bearLeft(){ if(DEBUG) System.out.println("PWMManager: bearLeft....");\r
* pwmControl.setSpeedTurnLeft(60); pwmControl.setSpeedTurnRight(100); }\r
* \r
* public void back(){ if(DEBUG) System.out.println("PWMManager: back....");\r
* pwmControl.setSpeedLeft(0); pwmControl.setSpeedRight(0); }\r
* \r
- * public void backBearLeft(){ if(DEBUG)\r
- * System.out.println("PWMManager: backBearLeft....");\r
+ * public void backBearLeft(){ if(DEBUG) System.out.println("PWMManager: backBearLeft....");\r
* pwmControl.setSpeedLeft(30); pwmControl.setSpeedRight(0); }\r
* \r
- * public void backBearRight(){ if(DEBUG)\r
- * System.out.println("PWMManager: backBearRight....");\r
+ * public void backBearRight(){ if(DEBUG) System.out.println("PWMManager: backBearRight....");\r
* pwmControl.setSpeedLeft(0); pwmControl.setSpeedRight(30); }\r
*/\r
public void resume() {\r
}\r
\r
/**\r
- * Control debug messaging. true - Activate debug messages false - deactivate\r
- * debug messages\r
+ * Control debug messaging. true - Activate debug messages false - deactivate debug messages\r
*/\r
public void setDebug(boolean debug) {\r
DEBUG = debug;\r
}\r
+\r
}
\ No newline at end of file
--- /dev/null
+public class RandomWrapper {
+ private static Random rand;
+
+ @TRUST
+ public static void init() {
+ rand = new Random();
+ }
+
+ @TRUST
+ public static int nextInt() {
+ return rand.nextInt();
+ }
+
+}
\r
private static boolean DEBUG = true;\r
\r
- private static final int OFF_MODE = 1;\r
- private static final int ON_MODE = 2;\r
- private static final int MANUAL_MODE = 1;\r
- private static final int AUTONOMUS_MODE = 2;\r
- private static final int ON_OFF = 128;// 0x80\r
- private static final int MANUAL_AUTONOMUS = 32; // 0x20\r
+ public static final int OFF_MODE = 1;\r
+ public static final int ON_MODE = 2;\r
+ public static final int MANUAL_MODE = 1;\r
+ public static final int AUTONOMUS_MODE = 2;\r
+ public static final int ON_OFF = 128;// 0x80\r
+ public static final int MANUAL_AUTONOMUS = 32; // 0x20\r
public static final int LINE_SENSORS = 64; // 0x40\r
- private static final int SONAR_SENSORS = 96; // 0x60\r
+ public static final int SONAR_SENSORS = 96; // 0x60\r
public static final int ALL_COMMANDS = 0xe0;\r
\r
public static final byte LF_FRONT = 0x1;\r
public static final byte LS_LEFT_REAR = 0x5;\r
public static final byte LS_RIGHT_REAR = 0x6;\r
public static final byte LS_ALL = 0x7;\r
- private static final int ALL_DATA = 0x1f;\r
+ public static final int ALL_DATA = 0x1f;\r
\r
\r
- private static PWMManager pwmm;\r
+ private PWMManager pwmm;\r
\r
- private static StrategyMgr strategyMgr;\r
+ private StrategyMgr strategyMgr;\r
\r
\r
- private static int onOffMode = ON_MODE;\r
+ private int onOffMode = ON_MODE;\r
\r
- private static int manualAutonomusMode = AUTONOMUS_MODE;\r
+ private int manualAutonomusMode = AUTONOMUS_MODE;\r
\r
- private static byte lineSensorsMask;\r
+ private byte lineSensorsMask;\r
\r
- private static byte sonarSensors;\r
+ private byte sonarSensors;\r
\r
- private static byte currentCommand;\r
+ private byte currentCommand;\r
\r
- private static byte privSonars;\r
+ private byte privSonars;\r
\r
- private static byte privLineSensors;\r
+ private byte privLineSensors;\r
\r
- private static byte currentSonars;\r
+ private byte currentSonars;\r
\r
- public static String pwmSelection;\r
+ public String pwmSelection;\r
\r
/**\r
* Constructor for the class for the robot main thread.\r
}\r
\r
/**\r
- * Processes sonar sensor input. This method is called each time new sonar\r
- * sensor data arrives, and each time that a mode switch occurs between ON/OFF\r
- * and Manual Override.\r
+ * Processes sonar sensor input. This method is called each time new sonar sensor data arrives,\r
+ * and each time that a mode switch occurs between ON/OFF and Manual Override.\r
*/\r
- static void processSonars() {\r
+ void processSonars() {\r
strategyMgr.processSonars(sonarSensors);\r
}\r
\r
/**\r
- * Processes line sensor input. This method is called each time new line\r
- * sensor data arrives, and each time that a mode switch occurs between ON/OFF\r
- * and Manual Override.\r
+ * Processes line sensor input. This method is called each time new line sensor data arrives, and\r
+ * each time that a mode switch occurs between ON/OFF and Manual Override.\r
*/\r
- static void processLineSensors() {\r
+ void processLineSensors() {\r
strategyMgr.processLineSensors(lineSensorsMask);\r
resume();\r
}\r
/**\r
* Resumes motors as per the last sonar command.\r
*/\r
- public static void resume() {\r
+ void resume() {\r
processSonars();\r
}\r
\r
/**\r
- * Extracts sonar sensor data from the adjunct sensor controller and from line\r
- * sensor data from the JStamp line sensor pins.\r
+ * Extracts sonar sensor data from the adjunct sensor controller and from line sensor data from\r
+ * the JStamp line sensor pins.\r
*/\r
\r
- private static void processIOCommand() {\r
+ private void processIOCommand() {\r
\r
// int data = 0;\r
// int opCode = 0;\r
lineSensorsMask = (byte) (data & LS_ALL);\r
\r
/*\r
- * Line sensors with '0' data means the robot moved off the edge line, and\r
- * there is nothing to do.\r
+ * Line sensors with '0' data means the robot moved off the edge line, and there is nothing to\r
+ * do.\r
*/\r
if (((data & LS_ALL) == 0) || ((data & LS_ALL) == privLineSensors)) {\r
privLineSensors = (byte) (data & LS_ALL);\r
}\r
currentSonars = (byte) (data & ALL_SONARS);\r
/*\r
- * No need to synchronized on this variable assignment since all referring\r
- * code is on the same logical thread\r
+ * No need to synchronized on this variable assignment since all referring code is on the same\r
+ * logical thread\r
*/\r
sonarSensors = (byte) currentSonars;\r
if ((onOffMode == ON_MODE) && (manualAutonomusMode == AUTONOMUS_MODE)) {\r
/**\r
* Saves the current IOManager command byte locally.\r
*/\r
- static public void setIOManagerCommand(byte[] cmd) {\r
+ public void setIOManagerCommand(byte[] cmd) {\r
// synchronized (obj1) {\r
currentCommand = cmd[0];\r
// }\r
}\r
\r
/**\r
- * Sets debug messaging state: true - Activate debug messages false -\r
- * deactivate debug messages\r
+ * Sets debug messaging state: true - Activate debug messages false - deactivate debug messages\r
*/\r
static public void setDebug(boolean debug) {\r
DEBUG = debug;\r
/**\r
* Runs the robot's main thread.\r
*/\r
- \r
public static void main( String args[]) {\r
\r
TestSensorInput.init();\r
+ RobotMain r = new RobotMain();\r
+ r.doit();\r
+ }\r
+\r
+ \r
+ public void doit() {\r
boolean active = true;\r
/**\r
- * RealTime management of the robot behaviour based on sensors and commands\r
- * input.\r
+ * RealTime management of the robot behaviour based on sensors and commands input.\r
*/\r
\r
/**\r
- * Set the low level PWM interface type, e.g. "rtsj" or "native" (ajile\r
- * library-based).\r
+ * Set the low level PWM interface type, e.g. "rtsj" or "native" (ajile library-based).\r
*/\r
pwmSelection = "rtsj";\r
\r
strategyMgr = new StrategyMgr(mc);\r
\r
/*\r
- * Sets initial values for the speed and agility parameters. Speed and\r
- * agility are arbitrary scale factors for the overall speed and speed of\r
- * turns, respectively. These work with PWM via the native ajile libraries,\r
- * but do not work well with the RTSJ implementation due to limits on the\r
- * granularity of timing for the PWM pulse (quantization).\r
+ * Sets initial values for the speed and agility parameters. Speed and agility are arbitrary\r
+ * scale factors for the overall speed and speed of turns, respectively. These work with PWM via\r
+ * the native ajile libraries, but do not work well with the RTSJ implementation due to limits\r
+ * on the granularity of timing for the PWM pulse (quantization).\r
*/\r
pwmm.setSpeedAgilityFactors(100, 100);\r
\r
/*\r
- * Robot's initial state is "ON" by default. Set this parameter to "OFF" if\r
- * the robot is to be started over the TCP/IP link.\r
+ * Robot's initial state is "ON" by default. Set this parameter to "OFF" if the robot is to be\r
+ * started over the TCP/IP link.\r
*/\r
// issueCommand("OFF");\r
\r
SSJAVA: while (active) {\r
\r
- // if (DEBUG) {\r
- // System.out.println("Main: Waiting for remote commands");\r
- // }\r
- // try {\r
- // obj.wait();\r
- // } catch (IllegalMonitorStateException ie) {\r
- // System.out.println("IllegalMonitorStateException caught in main loop");\r
- // }\r
- currentCommand = TestSensorInput.getCommand();\r
+ Command com = HWSimulator.getCommand();\r
+ currentCommand = com.command;\r
+ sonarSensors = com.sonarSensors;\r
+ lineSensorsMask = com.lineSensorsMask;\r
+ manualAutonomusMode = com.manualAutonomusMode;\r
+ onOffMode = com.onOffMode;\r
+\r
if (currentCommand == -1) {\r
break;\r
}\r
System.out.println("currentCommand=" + currentCommand);\r
processIOCommand();\r
+ // erase current settings\r
+ initialize();\r
}\r
System.exit(0);\r
}\r
\r
+ public void initialize() {\r
+ privLineSensors = 0;\r
+ currentCommand = 0;\r
+ privSonars = 0;\r
+ currentSonars = 0;\r
+ pwmSelection = "";\r
+ }\r
+\r
}\r
private MotorControl mc;\r
private static final int zeroSpeed = 45;\r
\r
- private Random rand;\r
- \r
private boolean DEBUGL = true;\r
// private boolean DEBUGL = false;\r
\r
*/\r
public StrategyMgr(@DELEGATE MotorControl motorControl) {\r
mc = motorControl;\r
- rand = new Random();\r
+ RandomWrapper.init();\r
}\r
\r
void processSonars( byte sonarSensors) {\r
}\r
\r
public void spin180() {\r
- int mod = (rand.nextInt() % 2);\r
+ int mod = (RandomWrapper.nextInt() % 2);\r
\r
if (DEBUG)\r
System.out.println("StrategyMgr: spin180....");\r