use of nars.nal.nal8.operator.NullOperator in project narchy by automenta.
the class CarefulRover method initMotors.
protected void initMotors(Body torso) {
nar.on(new NullOperator("vision") {
@Override
public List<Task> apply(Operation o) {
final String command = command(o, o.getMemory());
String[] sections = command.split(",");
if (sections.length == 1) {
// switch (sections[0]) {
// case "far":
// dist = 20f;
// break;
// case "near":
// dist = 10f;
// break;
// default:
// return null;
// }
String angle = sections[0];
float dist;
dist = 5 + 20f * o.getTask().getTruth().getExpectation();
VisionRay vr = pixels.get(angle);
if (vr != null)
vr.setDistance(dist);
}
return null;
}
});
System.out.println(pixels);
for (String a : pixels.keySet()) {
randomActions.add("vision(" + a + ")! :!: %1%");
randomActions.add("vision(" + a + ")! :|: %0%");
}
randomActions.add("motor(left)! :|:");
// randomActions.add("motor(left,left)!");
randomActions.add("motor(right)! :|:");
// randomActions.add("motor(right,right)!");
// randomActions.add("motor(forward,forward)!"); //too much actions are not good,
// however i would agree if <motor(forward,forward) --> motor(forward)>.
randomActions.add("motor(forward)! :|:");
// randomActions.add("motor(forward,forward)!");
// randomActions.add("motor(forward)!");
randomActions.add("motor(reverse)! :|:");
randomActions.add("motor(stop)! :|:");
// randomActions.add("motor(random)!");
nar.on(new NullOperator("motor") {
@Override
public List<Task> apply(Operation operation) {
String command = command(operation, operation.getMemory());
if (command.equals("$1")) {
// variable causes random movement
double v = Math.random();
if (v < 0.25f) {
command = "left";
} else if (v < 0.5f) {
command = "right";
} else if (v < 0.75f) {
command = "forward";
} else {
command = "reverse";
}
}
float strength = operation.getTaskExpectation();
float rotSpeed = 15 * strength;
float linSpeed = 1 * strength;
switch(command) {
case "right":
rotateRelative(-rotSpeed);
break;
case "right,right":
rotateRelative(-rotSpeed * 2);
break;
case "left":
rotateRelative(+rotSpeed);
break;
case "left,left":
rotateRelative(+rotSpeed * 2);
break;
case "forward,forward":
thrustRelative(+2 * linSpeed);
break;
case "forward":
thrustRelative(+linSpeed);
break;
case "reverse":
thrustRelative(-linSpeed);
break;
case "stop":
stop();
break;
case "random":
randomAction();
break;
}
return null;
}
});
}
Aggregations