Skip to content

Commit

Permalink
Peer config utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
supertick committed Oct 21, 2023
1 parent ef9e25b commit 4f47f23
Show file tree
Hide file tree
Showing 10 changed files with 270 additions and 125 deletions.
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
# fast build
mvn -DskipTests package -o
# execute
mvn exec:java -Dexec.mainClass=org.myrobotlab.service.Runtime -Dexec.args="-s webgui WebGui intro Intro python Python"
# specific test
mvn test -Dtest="org.myrobotlab.service.WebGuiTest#postTest"
Expand Down
254 changes: 175 additions & 79 deletions src/main/java/org/myrobotlab/framework/Service.java

Large diffs are not rendered by default.

60 changes: 32 additions & 28 deletions src/main/java/org/myrobotlab/service/InMoov2.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ public static boolean loadFile(String file) {

protected String voiceSelected;


public InMoov2(String n, String id) {
super(n, id);
}

// should be removed in favor of general listeners
public void addTextListener(TextListener service) {
// CORRECT WAY ! - no direct reference - just use the name in a subscription
addListener("publishText", service.getName());
Expand Down Expand Up @@ -407,7 +407,7 @@ public String execGesture(String gesture) {
subscribe("python", "publishStatus", this.getName(), "onGestureStatus");
startedGesture(gesture);
lastGestureExecuted = gesture;
Python python = (Python)Runtime.getService("python");
Python python = (Python) Runtime.getService("python");
if (python == null) {
error("python service not started");
return null;
Expand Down Expand Up @@ -773,19 +773,19 @@ public void moveHead(Integer neck, Integer rothead, Integer rollNeck) {
moveHead((double) neck, (double) rothead, null, null, null, (double) rollNeck);
}

public void moveHeadBlocking(Double neck, Double rothead) {
public void moveHeadBlocking(Double neck, Double rothead) {
moveHeadBlocking(neck, rothead, null);
}

public void moveHeadBlocking(Double neck, Double rothead, Double rollNeck) {
public void moveHeadBlocking(Double neck, Double rothead, Double rollNeck) {
moveHeadBlocking(neck, rothead, null, null, null, rollNeck);
}

public void moveHeadBlocking(Double neck, Double rothead, Double eyeX, Double eyeY, Double jaw) {
public void moveHeadBlocking(Double neck, Double rothead, Double eyeX, Double eyeY, Double jaw) {
moveHeadBlocking(neck, rothead, eyeX, eyeY, jaw, null);
}

public void moveHeadBlocking(Double neck, Double rothead, Double eyeX, Double eyeY, Double jaw, Double rollNeck) {
public void moveHeadBlocking(Double neck, Double rothead, Double eyeX, Double eyeY, Double jaw, Double rollNeck) {
try {
sendBlocking(getPeerName("head"), "moveToBlocking", neck, rothead, eyeX, eyeY, jaw, rollNeck);
} catch (Exception e) {
Expand Down Expand Up @@ -866,7 +866,7 @@ public void onGestureStatus(Status status) {
error("I cannot execute %s, please check logs", lastGestureExecuted);
}
finishedGesture(lastGestureExecuted);

unsubscribe("python", "publishStatus", this.getName(), "onGestureStatus");
}

Expand Down Expand Up @@ -994,10 +994,10 @@ public void onStarted(String name) {
Runtime runtime = Runtime.getInstance();
log.info("onStarted {}", name);

// BAD IDEA - better to ask for a system report or an error report
// if (runtime.isProcessingConfig()) {
// invoke("publishEvent", "CONFIG STARTED");
// }
// BAD IDEA - better to ask for a system report or an error report
// if (runtime.isProcessingConfig()) {
// invoke("publishEvent", "CONFIG STARTED");
// }

String peerKey = getPeerKey(name);
if (peerKey == null) {
Expand Down Expand Up @@ -1229,8 +1229,8 @@ public String publishHeartbeat() {
}

/**
* A more extensible interface point than publishEvent
* FIXME - create interface for this
* A more extensible interface point than publishEvent FIXME - create
* interface for this
*
* @param msg
* @return
Expand Down Expand Up @@ -1561,7 +1561,7 @@ public void setTorsoSpeed(Integer topStom, Integer midStom, Integer lowStom) {
setTorsoSpeed((double) topStom, (double) midStom, (double) lowStom);
}

@Deprecated
@Deprecated /* use setTorsoSpeed */
public void setTorsoVelocity(Double topStom, Double midStom, Double lowStom) {
setTorsoSpeed(topStom, midStom, lowStom);
}
Expand Down Expand Up @@ -1814,8 +1814,7 @@ public void startService() {
subscribe("runtime", "shutdown");
// power up loopback subscription
addListener(getName(), "powerUp");



subscribe("runtime", "publishConfigList");
if (runtime.isProcessingConfig()) {
invoke("publishEvent", "configStarted");
Expand Down Expand Up @@ -1923,7 +1922,6 @@ public void waitTargetPos() {
sendToPeer("torso", "waitTargetPos");
}


public static void main(String[] args) {
try {

Expand All @@ -1934,20 +1932,26 @@ public static void main(String[] args) {

// Runtime.startConfig("pr-1213-1");

Runtime.main(new String[] {"--log-level", "info", "-s", "webgui", "WebGui", "intro", "Intro", "python", "Python"});
WebGui webgui = (WebGui) Runtime.create("webgui", "WebGui");
// webgui.setSsl(true);
webgui.autoStartBrowser(false);
// webgui.setPort(8888);
webgui.startService();

InMoov2 i01 = (InMoov2)Runtime.start("i01","InMoov2");
i01.setPeerConfigValue("opencv", "flip", true);
// i01.savePeerConfig("", null);

// Runtime.startConfig("default");

// Runtime.main(new String[] { "--log-level", "info", "-s", "webgui", "WebGui", "intro", "Intro", "python", "Python" });

boolean done = true;
if (done) {
return;
}


WebGui webgui = (WebGui) Runtime.create("webgui", "WebGui");
// webgui.setSsl(true);
webgui.autoStartBrowser(false);
// webgui.setPort(8888);
webgui.startService();

Runtime.start("python", "Python");
// Runtime.start("ros", "Ros");
Runtime.start("intro", "Intro");
Expand All @@ -1959,7 +1963,6 @@ public static void main(String[] args) {
// Polly polly = (Polly)Runtime.start("i01.mouth", "Polly");
// i01 = (InMoov2) Runtime.start("i01", "InMoov2");


// polly.speakBlocking("Hi, to be or not to be that is the question,
// wheather to take arms against a see of trouble, and by aposing them end
// them, to sleep, to die");
Expand Down Expand Up @@ -1999,14 +2002,15 @@ public static void main(String[] args) {

random.save();

// i01.startChatBot();
//
// i01.startAll("COM3", "COM4");
// i01.startChatBot();
//
// i01.startAll("COM3", "COM4");
Runtime.start("python", "Python");

} catch (Exception e) {
log.error("main threw", e);
}
}


}
15 changes: 15 additions & 0 deletions src/main/java/org/myrobotlab/service/OpenCV.java
Original file line number Diff line number Diff line change
Expand Up @@ -1967,6 +1967,19 @@ public void enableFilter(String name) {
}
}

/**
* flip the video display vertically
* @param toFlip
*/
public void flip(boolean toFlip) {
config.flip = toFlip;
if (config.flip) {
addFilter("Flip");
} else {
removeFilter("Flip");
}
}

@Override
public void disableFilter(String name) {
OpenCVFilter f = filters.get(name);
Expand Down Expand Up @@ -2062,6 +2075,8 @@ public OpenCVConfig apply(OpenCVConfig c) {
// TODO: better configuration of the filter when it's added.
}
}

flip(c.flip);

if (c.capturing) {
capture();
Expand Down
30 changes: 16 additions & 14 deletions src/main/java/org/myrobotlab/service/Runtime.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public class Runtime extends Service<RuntimeConfig> implements MessageListener,
* all these requests.
*/
@Deprecated /* use the filesystem only no memory plan */
transient final Plan masterPlan = new Plan("runtime");
protected final Plan masterPlan = new Plan("runtime");

/**
* thread for non-blocking install of services
Expand Down Expand Up @@ -2661,6 +2661,7 @@ synchronized static public ServiceInterface start(String name, String type) {
}

Runtime.load(name, type);
Runtime.savePlan(null);
// FIXME - does some order need to be maintained
Map<String, ServiceInterface> services = createServicesFromPlan(Runtime.getPlan(), null, name);

Expand Down Expand Up @@ -4805,6 +4806,16 @@ synchronized private Plan loadService(Plan plan, String name, String type, boole

return plan;
}

/**
* read a service's configuration, in the context
* of current config set name or default
* @param name
* @return
*/
public ServiceConfig readServiceConfig(String name) {
return readServiceConfig(null, name);
}

/**
*
Expand Down Expand Up @@ -4845,19 +4856,6 @@ public String publishConfigLoaded(String name) {
return name;
}

// @Override
// public ServiceConfig getConfig() {
// RuntimeConfig config = (RuntimeConfig)super.getConfig();
// List<org.myrobotlab.service.config.ServiceConfig.Listener> listeners = new
// ArrayList
// for (org.myrobotlab.service.config.ServiceConfig.Listener listener:
// config.listeners) {
// if (listener.equals("stopped") || listener.equals("created")||
// listener.equals("registered")|| listener.equals("released")) {
//
// }
// }
// }

public String setAllIds(String id) {
Platform.getLocalInstance().setId(id);
Expand Down Expand Up @@ -5154,6 +5152,10 @@ private void savePlanInternal(String configName) {

for (String s : masterPlan.keySet()) {
String filename = CONFIG_ROOT + fs + configName + fs + s + ".yml";
File check = new File(filename);
if (check.exists()) {
continue;
}
String data = CodecUtils.toYaml(masterPlan.get(s));
try {
FileIO.toFile(filename, data.getBytes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ public class InMoov2Config extends ServiceConfig {
public boolean neoPixelFlashWhenSpeaking = true;

public boolean openCVFaceRecognizerActivated=true;

public boolean openCVFlipPicture=false;


public boolean pirEnableTracking = false;

/**
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/myrobotlab/service/config/OpenCVConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@ public class OpenCVConfig extends ServiceConfig {
public boolean webViewer = false;
public boolean capturing = false;
public Map<String, OpenCVFilter> filters = new LinkedHashMap<>();
/**
* flip the video vertically
*/
public boolean flip = false;

}
16 changes: 15 additions & 1 deletion src/main/resources/resource/WebGui/app/peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

console.info('peer')

angular.module('peer', []).service('peer', function( mrl /*$rootScope, $log*/
angular.module('peer', []).service('peer', function( mrl
) {
service = {};

Expand Down Expand Up @@ -40,6 +40,20 @@ angular.module('peer', []).service('peer', function( mrl /*$rootScope, $log*/
return null
}

service.getPeerConfig = function(service, key) {
try {
if (service && service.config && service.config.peers && service.config.peers[key]){
return mrl.getService('runtime').masterPlan['config'][service.config.peers[key].name]
// return mrl.getService(service.config.peers[key].name).config
} else {
// if peer is not started - return the filesystem config
}
} catch (error) {
console.error(error);
}
return null
}

service.changePeerTab = function(service, key) {
try {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ angular.module('mrlapp.service.RuntimeGui', []).controller('RuntimeGuiCtrl', ['$
_self.updateState(data)
$scope.$apply()
break
case 'onPlan':
$scope.plan = data
$scope.$apply()
break
case 'onLocalServices':
$scope.registry = data
// $scope.$apply()
Expand Down Expand Up @@ -408,6 +412,7 @@ angular.module('mrlapp.service.RuntimeGui', []).controller('RuntimeGuiCtrl', ['$
msg.subscribe("publishStatus")
msg.subscribe('publishConfigList')
msg.subscribe('publishInterfaceToNames')
// msg.subscribe("getPlan")

//msg.send("getLocalServices")
msg.send("getStartYml")
Expand All @@ -417,6 +422,7 @@ angular.module('mrlapp.service.RuntimeGui', []).controller('RuntimeGuiCtrl', ['$
msg.send("getLocales")
msg.send("publishInterfaceToNames")
msg.send("getConfigName")
// msg.send("getPlan")

// msg.send("getHosts")
msg.subscribe(this)
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/resource/framework/pom.xml.template
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
# fast build
mvn -DskipTests package -o

# execute
mvn exec:java -Dexec.mainClass=org.myrobotlab.service.Runtime -Dexec.args="-s webgui WebGui intro Intro python Python"

# specific test
mvn test -Dtest="org.myrobotlab.service.WebGuiTest#postTest"

Expand Down

0 comments on commit 4f47f23

Please sign in to comment.