Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/MyRobotLab/myrobotlab in…
Browse files Browse the repository at this point in the history
…to inmoov2-heart
  • Loading branch information
supertick committed Apr 22, 2024
2 parents 11e9cfc + 0b17318 commit bedaad1
Show file tree
Hide file tree
Showing 11 changed files with 455 additions and 390 deletions.
11 changes: 11 additions & 0 deletions api-example.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
curl -X POST http://localhost:8888/api/service \
-d '{"name":"i01.chatBot","method":"getResponse","data":["grog", "hi there!"]}'

curl -X POST http://localhost:8888/api/service/i01.chatBot/getResponse \
-d '["grog", "hi there!"]'

curl -X POST http://localhost:8888/api/service/i01.chatBot/setCurrentBotName \
-d '["ru-RU"]'



2 changes: 2 additions & 0 deletions src/main/java/org/myrobotlab/service/Gpt3.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ public Response getResponse(String text) {

HttpClient http = (HttpClient) startPeer("http");

log.info("curl {} -d '{}'", c.url, json);

String msg = http.postJson(c.token, c.url, json);

Map<String, Object> payload = CodecUtils.fromJson(msg, new StaticType<>() {});
Expand Down
152 changes: 91 additions & 61 deletions src/main/java/org/myrobotlab/service/InMoov2.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public Heartbeat(InMoov2 inmoov) {
* This method will load a python file into the python interpreter.
*
* @param file
* file to load
* file to load
* @return success/failure
*/
@Deprecated /* use execScript - this doesn't handle resources correctly */
Expand Down Expand Up @@ -262,8 +262,7 @@ public InMoov2Config apply(InMoov2Config c) {
super.apply(c);
try {

locales = Locale.getLocaleMap("en-US", "fr-FR", "es-ES", "de-DE", "nl-NL", "pl-PL", "ru-RU", "hi-IN", "it-IT",
"fi-FI", "pt-PT", "tr-TR");
locales = Locale.getLocaleMap("en-US", "fr-FR", "es-ES", "de-DE", "nl-NL", "pl-PL", "ru-RU", "hi-IN", "it-IT", "fi-FI", "pt-PT", "tr-TR");

if (c.locale != null) {
setLocale(c.locale);
Expand All @@ -273,9 +272,28 @@ public InMoov2Config apply(InMoov2Config c) {
// one way sync configuration into predicates
configToPredicates();

execScript();

loadAppsScripts();

loadInitScripts();

if (c.loadGestures) {
loadGestures();
}

if (c.heartbeat) {
startHeartbeat();
} else {
stopHeartbeat();
}

// one way sync configuration into predicates
configToPredicates();

} catch (Exception e) {
error(e);
}
}
return c;
}

Expand Down Expand Up @@ -627,6 +645,13 @@ public void disable() {
sendToPeer("torso", "disable");
}

public void disableRandom() {
Random random = (Random) getPeer("random");
if (random != null) {
random.disable();
}
}

public void displayFullScreen(String src) {
try {
if (imageDisplay == null) {
Expand All @@ -649,13 +674,6 @@ public void enableRandomHead() {
}
}

public void disableRandom() {
Random random = (Random) getPeer("random");
if (random != null) {
random.disable();
}
}

public void enable() {
sendToPeer("head", "enable");
sendToPeer("rightHand", "enable");
Expand Down Expand Up @@ -686,7 +704,7 @@ public boolean exec(String pythonCode) {
* This method will try to launch a python command with error handling
*
* @param gesture
* the gesture
* the gesture
* @return gesture result
*/
public String execGesture(String gesture) {
Expand Down Expand Up @@ -721,7 +739,7 @@ public void execScript() {
* a filesystem file :P
*
* @param someScriptName
* execute a resource script
* execute a resource script
* @return success or failure
*/
public void execScript(String someScriptName) {
Expand Down Expand Up @@ -970,7 +988,7 @@ public void loadGestures() {
* file should contain 1 method definition that is the same as the filename.
*
* @param directory
* - the directory that contains the gesture python files.
* - the directory that contains the gesture python files.
* @return true/false
*/
public boolean loadGestures(String directory) {
Expand Down Expand Up @@ -1069,8 +1087,7 @@ public void moveHand(String which, Double thumb, Double index, Double majeure, D
moveHand(which, thumb, index, majeure, ringFinger, pinky, null);
}

public void moveHand(String which, Double thumb, Double index, Double majeure, Double ringFinger, Double pinky,
Double wrist) {
public void moveHand(String which, Double thumb, Double index, Double majeure, Double ringFinger, Double pinky, Double wrist) {
invoke("publishMoveHand", which, thumb, index, majeure, ringFinger, pinky, wrist);
}

Expand Down Expand Up @@ -1122,10 +1139,8 @@ public void moveLeftHand(Double thumb, Double index, Double majeure, Double ring
moveHand("left", thumb, index, majeure, ringFinger, pinky, wrist);
}

public void moveLeftHand(Integer thumb, Integer index, Integer majeure, Integer ringFinger, Integer pinky,
Integer wrist) {
moveHand("left", (double) thumb, (double) index, (double) majeure, (double) ringFinger, (double) pinky,
(double) wrist);
public void moveLeftHand(Integer thumb, Integer index, Integer majeure, Integer ringFinger, Integer pinky, Integer wrist) {
moveHand("left", (double) thumb, (double) index, (double) majeure, (double) ringFinger, (double) pinky, (double) wrist);
}

public void moveRightArm(Double bicep, Double rotate, Double shoulder, Double omoplate) {
Expand All @@ -1136,10 +1151,8 @@ public void moveRightHand(Double thumb, Double index, Double majeure, Double rin
moveHand("right", thumb, index, majeure, ringFinger, pinky, wrist);
}

public void moveRightHand(Integer thumb, Integer index, Integer majeure, Integer ringFinger, Integer pinky,
Integer wrist) {
moveHand("right", (double) thumb, (double) index, (double) majeure, (double) ringFinger, (double) pinky,
(double) wrist);
public void moveRightHand(Integer thumb, Integer index, Integer majeure, Integer ringFinger, Integer pinky, Integer wrist) {
moveHand("right", (double) thumb, (double) index, (double) majeure, (double) ringFinger, (double) pinky, (double) wrist);
}

public void moveTorso(Double topStom, Double midStom, Double lowStom) {
Expand Down Expand Up @@ -1168,7 +1181,7 @@ public PredicateEvent onChangePredicate(PredicateEvent event) {
* comes in from runtime which owns the config list
*
* @param configList
* list of configs
* list of configs
*/
public void onConfigList(List<String> configList) {
this.configList = configList;
Expand Down Expand Up @@ -1197,12 +1210,23 @@ public void onErrors(List<LogEntry> log) {
errors.addAll(log);
}

@Deprecated /* use onConfigFinished */
public void onFinishedConfig(String configName) {
log.info("onFinishedConfig");
// invoke("publishEvent", "configFinished");
invoke("publishConfigFinished", configName);
}

public void onConfigFinished(String configName) {
log.info("onConfigFinished");
invoke("publishConfigFinished", configName);
}

public void onConfigStarted(String configName) {
log.info("onConfigStarted");
invoke("publishConfigStarted", configName);
}


public void onGestureStatus(Status status) {
if (!status.equals(Status.success()) && !status.equals(Status.warn("Python process killed !"))) {
error("I cannot execute %s, please check logs", lastGestureExecuted);
Expand Down Expand Up @@ -1236,6 +1260,23 @@ public void onJoystickInput(JoystickData input) throws Exception {
invoke("publishEvent", "joystick");
}

/**
* Centralized logging system will have all logging from all services,
* including lower level logs that do not propegate as statuses
*
* @param log
* - flushed log from Log service
*/
public void onLogEvents(List<LogEntry> log) {
// scan for warn or errors
for (LogEntry entry : log) {
if ("ERROR".equals(entry.level) && errors.size() < 100) {
errors.add(entry);
// invoke("publishError", entry);
}
}
}

public String onNewState(String state) {
log.error("onNewState {}", state);

Expand Down Expand Up @@ -1421,7 +1462,7 @@ public void powerUp() {
}

public void processMessage(String method) {
processMessage(method, null);
processMessage(method, (Object[]) null);
}

/**
Expand Down Expand Up @@ -1593,8 +1634,7 @@ public Message publishMessage(Message msg) {
return msg;
}

public HashMap<String, Double> publishMoveArm(String which, Double bicep, Double rotate, Double shoulder,
Double omoplate) {
public HashMap<String, Double> publishMoveArm(String which, Double bicep, Double rotate, Double shoulder, Double omoplate) {
HashMap<String, Double> map = new HashMap<>();
map.put("bicep", bicep);
map.put("rotate", rotate);
Expand All @@ -1608,8 +1648,7 @@ public HashMap<String, Double> publishMoveArm(String which, Double bicep, Double
return map;
}

public HashMap<String, Object> publishMoveHand(String which, Double thumb, Double index, Double majeure,
Double ringFinger, Double pinky, Double wrist) {
public HashMap<String, Object> publishMoveHand(String which, Double thumb, Double index, Double majeure, Double ringFinger, Double pinky, Double wrist) {
HashMap<String, Object> map = new HashMap<>();
map.put("which", which);
map.put("thumb", thumb);
Expand All @@ -1626,8 +1665,7 @@ public HashMap<String, Object> publishMoveHand(String which, Double thumb, Doubl
return map;
}

public HashMap<String, Double> publishMoveHead(Double neck, Double rothead, Double eyeX, Double eyeY, Double jaw,
Double rollNeck) {
public HashMap<String, Double> publishMoveHead(Double neck, Double rothead, Double eyeX, Double eyeY, Double jaw, Double rollNeck) {
HashMap<String, Double> map = new HashMap<>();
map.put("neck", neck);
map.put("rothead", rothead);
Expand All @@ -1647,8 +1685,7 @@ public HashMap<String, Double> publishMoveLeftArm(Double bicep, Double rotate, D
return map;
}

public HashMap<String, Double> publishMoveLeftHand(Double thumb, Double index, Double majeure, Double ringFinger,
Double pinky, Double wrist) {
public HashMap<String, Double> publishMoveLeftHand(Double thumb, Double index, Double majeure, Double ringFinger, Double pinky, Double wrist) {
HashMap<String, Double> map = new HashMap<>();
map.put("thumb", thumb);
map.put("index", index);
Expand All @@ -1668,8 +1705,7 @@ public HashMap<String, Double> publishMoveRightArm(Double bicep, Double rotate,
return map;
}

public HashMap<String, Double> publishMoveRightHand(Double thumb, Double index, Double majeure, Double ringFinger,
Double pinky, Double wrist) {
public HashMap<String, Double> publishMoveRightHand(Double thumb, Double index, Double majeure, Double ringFinger, Double pinky, Double wrist) {
HashMap<String, Double> map = new HashMap<>();
map.put("thumb", thumb);
map.put("index", index);
Expand Down Expand Up @@ -1851,8 +1887,7 @@ public void setAutoDisable(Boolean param) {
}

@Override
public void setConfigValue(String fieldname, Object value)
throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
public void setConfigValue(String fieldname, Object value) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
super.setConfigValue(fieldname, value);
setPredicate(fieldname, value);
}
Expand All @@ -1861,8 +1896,7 @@ public void setHandSpeed(String which, Double thumb, Double index, Double majeur
setHandSpeed(which, thumb, index, majeure, ringFinger, pinky, null);
}

public void setHandSpeed(String which, Double thumb, Double index, Double majeure, Double ringFinger, Double pinky,
Double wrist) {
public void setHandSpeed(String which, Double thumb, Double index, Double majeure, Double ringFinger, Double pinky, Double wrist) {
InMoov2Hand hand = getHand(which);
if (hand == null) {
warn("%s hand not started", which);
Expand All @@ -1872,14 +1906,12 @@ public void setHandSpeed(String which, Double thumb, Double index, Double majeur
}

@Deprecated
public void setHandVelocity(String which, Double thumb, Double index, Double majeure, Double ringFinger,
Double pinky) {
public void setHandVelocity(String which, Double thumb, Double index, Double majeure, Double ringFinger, Double pinky) {
setHandSpeed(which, thumb, index, majeure, ringFinger, pinky, null);
}

@Deprecated
public void setHandVelocity(String which, Double thumb, Double index, Double majeure, Double ringFinger, Double pinky,
Double wrist) {
public void setHandVelocity(String which, Double thumb, Double index, Double majeure, Double ringFinger, Double pinky, Double wrist) {
setHandSpeed(which, thumb, index, majeure, ringFinger, pinky, wrist);
}

Expand All @@ -1895,8 +1927,7 @@ public void setHeadSpeed(Double rothead, Double neck, Double eyeXSpeed, Double e
setHeadSpeed(rothead, neck, eyeXSpeed, eyeYSpeed, jawSpeed, null);
}

public void setHeadSpeed(Double rothead, Double neck, Double eyeXSpeed, Double eyeYSpeed, Double jawSpeed,
Double rollNeckSpeed) {
public void setHeadSpeed(Double rothead, Double neck, Double eyeXSpeed, Double eyeYSpeed, Double jawSpeed, Double rollNeckSpeed) {
sendToPeer("head", "setSpeed", rothead, neck, eyeXSpeed, eyeYSpeed, jawSpeed, rollNeckSpeed);
}

Expand All @@ -1920,8 +1951,7 @@ public void setHeadVelocity(Double rothead, Double neck, Double eyeXSpeed, Doubl
}

@Deprecated
public void setHeadVelocity(Double rothead, Double neck, Double eyeXSpeed, Double eyeYSpeed, Double jawSpeed,
Double rollNeckSpeed) {
public void setHeadVelocity(Double rothead, Double neck, Double eyeXSpeed, Double eyeYSpeed, Double jawSpeed, Double rollNeckSpeed) {
setHeadSpeed(rothead, neck, eyeXSpeed, eyeYSpeed, jawSpeed, rollNeckSpeed);
}

Expand All @@ -1933,15 +1963,12 @@ public void setLeftArmSpeed(Integer bicep, Integer rotate, Integer shoulder, Int
setArmSpeed("left", (double) bicep, (double) rotate, (double) shoulder, (double) omoplate);
}

public void setLeftHandSpeed(Double thumb, Double index, Double majeure, Double ringFinger, Double pinky,
Double wrist) {
public void setLeftHandSpeed(Double thumb, Double index, Double majeure, Double ringFinger, Double pinky, Double wrist) {
setHandSpeed("left", thumb, index, majeure, ringFinger, pinky, wrist);
}

public void setLeftHandSpeed(Integer thumb, Integer index, Integer majeure, Integer ringFinger, Integer pinky,
Integer wrist) {
setHandSpeed("left", (double) thumb, (double) index, (double) majeure, (double) ringFinger, (double) pinky,
(double) wrist);
public void setLeftHandSpeed(Integer thumb, Integer index, Integer majeure, Integer ringFinger, Integer pinky, Integer wrist) {
setHandSpeed("left", (double) thumb, (double) index, (double) majeure, (double) ringFinger, (double) pinky, (double) wrist);
}

@Override
Expand Down Expand Up @@ -1979,6 +2006,11 @@ public void setNeopixelAnimation(String animation, Integer red, Integer green, I
sendToPeer("neopixel", "animation", red, green, blue, speed);
}

public boolean setPirPlaySounds(boolean b) {
config.pirPlaySounds = b;
return b;
}

public Object setPredicate(String key, Object data) {
if (data == null) {
chatBot.setPredicate(key, null); // "unknown" "null" other sillyness ?
Expand All @@ -1996,15 +2028,12 @@ public void setRightArmSpeed(Integer bicep, Integer rotate, Integer shoulder, In
setArmSpeed("right", (double) bicep, (double) rotate, (double) shoulder, (double) omoplate);
}

public void setRightHandSpeed(Double thumb, Double index, Double majeure, Double ringFinger, Double pinky,
Double wrist) {
public void setRightHandSpeed(Double thumb, Double index, Double majeure, Double ringFinger, Double pinky, Double wrist) {
setHandSpeed("right", thumb, index, majeure, ringFinger, pinky, wrist);
}

public void setRightHandSpeed(Integer thumb, Integer index, Integer majeure, Integer ringFinger, Integer pinky,
Integer wrist) {
setHandSpeed("right", (double) thumb, (double) index, (double) majeure, (double) ringFinger, (double) pinky,
(double) wrist);
public void setRightHandSpeed(Integer thumb, Integer index, Integer majeure, Integer ringFinger, Integer pinky, Integer wrist) {
setHandSpeed("right", (double) thumb, (double) index, (double) majeure, (double) ringFinger, (double) pinky, (double) wrist);
}

public boolean setSpeechType(String speechType) {
Expand Down Expand Up @@ -2218,6 +2247,7 @@ public void stopNeopixelAnimation() {

public void systemCheck() {
Platform platform = Runtime.getPlatform();
log.info("systemCheck()");
int servoCount = 0;
for (ServiceInterface si : Runtime.getServices()) {
if (si.getClass().getSimpleName().equals("Servo")) {
Expand Down
Loading

0 comments on commit bedaad1

Please sign in to comment.