Skip to content

Commit

Permalink
Merge branch 'develop' of github.com-myrobotlab:MyRobotLab/myrobotlab…
Browse files Browse the repository at this point in the history
… into inmoov-and-statemachine-1
  • Loading branch information
supertick committed Nov 14, 2023
2 parents 37624b4 + 8d33fc5 commit 3d4c7e1
Show file tree
Hide file tree
Showing 14 changed files with 377 additions and 146 deletions.
22 changes: 21 additions & 1 deletion src/main/java/org/myrobotlab/audio/AudioProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
Expand Down Expand Up @@ -32,6 +36,8 @@ public class AudioProcessor extends Thread {
// it seems to make sense - some how the file gets decoded enough - so that
// a audio decoder can be slected from some
// internal registry ... i think

private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); transient private final ScheduledExecutorService delayScheduler = Executors.newScheduledThreadPool(1);

protected int currentTrackCount = 0;

Expand Down Expand Up @@ -231,7 +237,14 @@ public AudioData play(AudioData data) {
peak = abs;
}
}
audioFile.invoke("publishPeak", peak * (double) audioFile.getPeakMultiplier());

final double value = peak * (double) audioFile.getPeakMultiplier();

if (audioFile.getConfig().peakDelayMs == null) {
audioFile.invoke("publishPeak", value);
} else {
delayScheduler.schedule(() -> audioFile.invoke("publishPeak", value), audioFile.getConfig().peakDelayMs, TimeUnit.MILLISECONDS);
}
}
}
// Stop
Expand All @@ -247,6 +260,12 @@ public AudioData play(AudioData data) {

// System.gc();

if (audioFile.getConfig().peakDelayMs == null) {
audioFile.invoke("publishPeak", 0);
} else {
delayScheduler.schedule(() -> audioFile.invoke("publishPeak", 0), audioFile.getConfig().peakDelayMs, TimeUnit.MILLISECONDS);
}

audioFile.invoke("publishPeak", 0);
audioFile.invoke("publishAudioEnd", data);

Expand Down Expand Up @@ -313,6 +332,7 @@ public void run() {
}
// default waits on queued audio requests
log.info("audio processor {} exiting", getName());
delayScheduler.shutdown();
}

public void setVolume(Double volume) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/myrobotlab/service/AudioFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,10 @@ public AudioData play(String filename, boolean blocking, Integer repeat, String
data.track = track;
data.repeat = repeat;

return play(data);
return playAudioData(data);
}

public AudioData play(AudioData data) {
public AudioData playAudioData(AudioData data) {
// use File interface such that filename is preserved
// but regardless of location (e.g. url, local, resource)
// or type (mp3 wav) a stream is opened and the
Expand Down Expand Up @@ -382,7 +382,7 @@ public AudioData repeat(String filename, Integer count) {
// TODO Auto-generated method stub
AudioData data = new AudioData(filename);
data.repeat = count;
return play(data);
return playAudioData(data);
}

@Deprecated /* use setTrack() */
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/myrobotlab/service/I2cMux.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,13 @@ public void attach(Attachable service) throws Exception {
}
}

@Deprecated /* use attach(String) */
public void attach(String controllerName, String deviceBus, String deviceAddress) {
attach((I2CController) Runtime.getService(controllerName), deviceBus, deviceAddress);
}

@Override
@Deprecated /*use attach(String) */
public void attach(I2CController controller, String deviceBus, String deviceAddress) {

if (isAttached && this.controller != controller) {
Expand Down
152 changes: 138 additions & 14 deletions src/main/java/org/myrobotlab/service/InMoov2.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
import org.myrobotlab.service.abstracts.AbstractSpeechRecognizer;
import org.myrobotlab.service.abstracts.AbstractSpeechSynthesis;
import org.myrobotlab.service.config.InMoov2Config;
import org.myrobotlab.service.data.Event;
import org.myrobotlab.service.config.OpenCVConfig;
import org.myrobotlab.service.config.SpeechSynthesisConfig;
import org.myrobotlab.service.data.JoystickData;
import org.myrobotlab.service.data.LedDisplayData;
import org.myrobotlab.service.data.Locale;
Expand Down Expand Up @@ -1274,6 +1275,19 @@ public OpenCVData onOpenCVData(OpenCVData data) {
// FIXME - publish event with or without data ? String file reference
return data;
}

/**
* onPeak volume callback TODO - maybe make it variable with volume ?
*
* @param volume
*/
public void onPeak(double volume) {
if (config.neoPixelFlashWhenSpeaking && !configStarted) {
if (volume > 0.5) {
invoke("publishSpeakingFlash", "speaking");
}
}
}

/**
* onPeak volume callback TODO - maybe make it variable with volume ?
Expand Down Expand Up @@ -1852,16 +1866,6 @@ public void setRightHandSpeed(Integer thumb, Integer index, Integer majeure, Int
setHandSpeed("right", (double) thumb, (double) index, (double) majeure, (double) ringFinger, (double) pinky, (double) wrist);
}

public String setSpeechType(String speechType) {
updatePeerType("mouth" /* getPeerName("mouth") */, speechType);
return speechType;
}

// -----------------------------------------------------------------------------
// These are methods added that were in InMoov1 that we no longer had in
// InMoov2.
// From original InMoov1 so we don't loose the

public void setTorsoSpeed(Double topStom, Double midStom, Double lowStom) {
sendToPeer("torso", "setSpeed", topStom, midStom, lowStom);
}
Expand Down Expand Up @@ -2225,6 +2229,44 @@ public void waitTargetPos() {
sendToPeer("leftArm", "waitTargetPos");
sendToPeer("torso", "waitTargetPos");
}

public boolean setSpeechType(String speechType) {

if (speechType == null) {
error("cannot change speech type to null");
return false;
}

if (!speechType.contains(".")) {
speechType = "org.myrobotlab.service." + speechType;
}

Runtime runtime = Runtime.getInstance();
String peerName = getName() + ".mouth";
Plan plan = runtime.getDefault(peerName, speechType);
try {
SpeechSynthesisConfig mouth = (SpeechSynthesisConfig)plan.get(peerName);
mouth.speechRecognizers = new String[] { getName() + ".ear" };

savePeerConfig("mouth", plan.get(peerName));

if (isPeerStarted("mouth")) {
// restart
releasePeer("mouth");
startPeer("mouth");
}

} catch(Exception e) {
error("could not create config for %s", speechType);
return false;
}

return true;

// updatePeerType("mouth" /* getPeerName("mouth") */, speechType);
// return speechType;
}


public void closeRightHand() {

Expand Down Expand Up @@ -2383,9 +2425,91 @@ public static void main(String[] args) {
try {

LoggingFactory.init(Level.ERROR);
// identical to command line start
// Runtime.startConfig("inmoov2");
Runtime.main(new String[] { "--log-level", "info", "-s", "webgui", "WebGui", "intro", "Intro", "python", "Python" });
// Platform.setVirtual(true);
// Runtime.start("s01", "Servo");
// Runtime.start("intro", "Intro");

Runtime.startConfig("dev");

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");

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


OpenCVConfig ocvConfig = i01.getPeerConfig("opencv", new StaticType<>() {});
ocvConfig.flip = true;
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" });



Runtime.start("python", "Python");
// Runtime.start("ros", "Ros");
Runtime.start("intro", "Intro");
// InMoov2 i01 = (InMoov2) Runtime.start("i01", "InMoov2");
// i01.startPeer("simulator");
// Runtime.startConfig("i01-05");
// Runtime.startConfig("pir-01");

// 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");
// i01.startPeer("mouth");
// i01.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");

Runtime.start("python", "Python");

// i01.startSimulator();
Plan plan = Runtime.load("webgui", "WebGui");
// WebGuiConfig webgui = (WebGuiConfig) plan.get("webgui");
// webgui.autoStartBrowser = false;
Runtime.startConfig("webgui");
Runtime.start("webgui", "WebGui");

Random random = (Random) Runtime.start("random", "Random");

random.addRandom(3000, 8000, "i01", "setLeftArmSpeed", 8.0, 25.0, 8.0, 25.0, 8.0, 25.0, 8.0, 25.0);
random.addRandom(3000, 8000, "i01", "setRightArmSpeed", 8.0, 25.0, 8.0, 25.0, 8.0, 25.0, 8.0, 25.0);

random.addRandom(3000, 8000, "i01", "moveLeftArm", 0.0, 5.0, 85.0, 95.0, 25.0, 30.0, 10.0, 15.0);
random.addRandom(3000, 8000, "i01", "moveRightArm", 0.0, 5.0, 85.0, 95.0, 25.0, 30.0, 10.0, 15.0);

random.addRandom(3000, 8000, "i01", "setLeftHandSpeed", 8.0, 25.0, 8.0, 25.0, 8.0, 25.0, 8.0, 25.0, 8.0, 25.0, 8.0, 25.0);
random.addRandom(3000, 8000, "i01", "setRightHandSpeed", 8.0, 25.0, 8.0, 25.0, 8.0, 25.0, 8.0, 25.0, 8.0, 25.0, 8.0, 25.0);

random.addRandom(3000, 8000, "i01", "moveRightHand", 10.0, 160.0, 10.0, 60.0, 10.0, 60.0, 10.0, 60.0, 10.0, 60.0, 130.0, 175.0);
random.addRandom(3000, 8000, "i01", "moveLeftHand", 10.0, 160.0, 10.0, 60.0, 10.0, 60.0, 10.0, 60.0, 10.0, 60.0, 5.0, 40.0);

random.addRandom(200, 1000, "i01", "setHeadSpeed", 8.0, 20.0, 8.0, 20.0, 8.0, 20.0);
random.addRandom(200, 1000, "i01", "moveHead", 70.0, 110.0, 65.0, 115.0, 70.0, 110.0);

random.addRandom(200, 1000, "i01", "setTorsoSpeed", 2.0, 5.0, 2.0, 5.0, 2.0, 5.0);
random.addRandom(200, 1000, "i01", "moveTorso", 85.0, 95.0, 88.0, 93.0, 70.0, 110.0);

random.save();

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

} catch (Exception e) {
log.error("main threw", e);
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/myrobotlab/service/Motor.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,16 @@ public static void main(String[] args) {

}

@Override
public void attachMotorController(String controller) throws Exception {
// TODO Auto-generated method stub

}

@Override
public void detachMotorController(String controller) {
// TODO Auto-generated method stub

}

}
43 changes: 22 additions & 21 deletions src/main/java/org/myrobotlab/service/MotorDualPwm.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package org.myrobotlab.service;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import org.myrobotlab.framework.Platform;
import org.myrobotlab.logging.Level;
import org.myrobotlab.logging.LoggingFactory;
import org.myrobotlab.service.abstracts.AbstractMotor;
import org.myrobotlab.service.config.MotorDualPwmConfig;
import org.myrobotlab.service.config.ServiceConfig;

public class MotorDualPwm extends AbstractMotor<MotorDualPwmConfig> {
private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -92,32 +91,34 @@ public MotorDualPwmConfig apply(MotorDualPwmConfig c) {
return c;
}

public static void main(String[] args) throws InterruptedException {

LoggingFactory.init(Level.INFO);
String arduinoPort = "COM5";

VirtualArduino virtual = (VirtualArduino) Runtime.start("virtual", "VirtualArduino");
public static void main(String[] args) {
try {
virtual.connect(arduinoPort);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Runtime.start("gui", "SwingGui");
Runtime.start("python", "Python");
LoggingFactory.init(Level.INFO);
String arduinoPort = "COM5";

Platform.setVirtual(true);
Runtime.startConfig("dev");
Runtime.start("webgui", "WebGui");
MotorDualPwm motor = (MotorDualPwm) Runtime.start("motor", "MotorDualPwm");
Arduino arduino = (Arduino) Runtime.start("arduino", "Arduino");
arduino.connect(arduinoPort);
motor.setPwmPins(10, 11);

MotorDualPwm motor = (MotorDualPwm) Runtime.start("motor", "MotorDualPwm");
Arduino arduino = (Arduino) Runtime.start("arduino", "Arduino");
arduino.connect(arduinoPort);
motor.setPwmPins(10, 11);
try {
motor.attach(arduino);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

@Override
public void attachMotorController(String controller) throws Exception {
// TODO Auto-generated method stub

}

@Override
public void detachMotorController(String controller) {
// TODO Auto-generated method stub

}
}
12 changes: 12 additions & 0 deletions src/main/java/org/myrobotlab/service/MotorHat4Pi.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,16 @@ public static void main(String[] args) {
hat.attach(raspi, "1", "0x60");
}

@Override
public void attachMotorController(String controller) throws Exception {
// TODO Auto-generated method stub

}

@Override
public void detachMotorController(String controller) {
// TODO Auto-generated method stub

}

}
Loading

0 comments on commit 3d4c7e1

Please sign in to comment.