1 package com.neuronrobotics.bowlerstudio;
3 import java.awt.Desktop;
4 import java.io.BufferedReader;
5 import java.io.BufferedWriter;
7 import java.io.FileNotFoundException;
8 import java.io.FileOutputStream;
9 import java.io.FileReader;
10 import java.io.FileWriter;
11 import java.io.IOException;
12 import java.io.OutputStreamWriter;
13 import java.io.PrintWriter;
15 import java.net.URISyntaxException;
17 import java.nio.file.Files;
18 import java.util.ArrayList;
19 import java.util.Arrays;
20 import java.util.Collection;
21 import java.util.List;
29 import jline.ConsoleReader;
30 import jline.Terminal;
32 import com.neuronrobotics.bowlerstudio.creature.CadFileExporter;
33 import com.neuronrobotics.bowlerstudio.creature.IMobileBaseUI;
34 import com.neuronrobotics.bowlerstudio.creature.IgenerateBed;
35 import com.neuronrobotics.bowlerstudio.creature.MobileBaseCadManager;
36 import com.neuronrobotics.bowlerstudio.printbed.PrintBedManager;
37 import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine;
38 import com.neuronrobotics.bowlerstudio.vitamins.VitaminBomManager;
39 import com.neuronrobotics.sdk.addons.kinematics.MobileBase;
41 import eu.mihosoft.vrl.v3d.CSG;
42 import eu.mihosoft.vrl.v3d.ICSGProgress;
43 import eu.mihosoft.vrl.v3d.JavaFXInitializer;
44 import javafx.scene.transform.Affine;
45 import marytts.signalproc.effects.LpcWhisperiserEffect;
46 import marytts.signalproc.effects.RobotiserEffect;
47 import marytts.signalproc.effects.ChorusEffectBase;
48 import marytts.signalproc.effects.HMMDurationScaleEffect;
49 import marytts.signalproc.effects.VolumeEffect;
58 ArrayList<String> history =
new ArrayList<>();
62 }
catch (IOException e) {
66 history.add(
"println SDKBuildInfo.getVersion()");
67 history.add(
"for(int i=0;i<1000000;i++) { println dyio.getValue(0) }");
68 history.add(
"dyio.setValue(0,128)");
69 history.add(
"println dyio.getValue(0)");
70 history.add(
"ScriptingEngine.inlineGistScriptRun(\"d4312a0787456ec27a2a\", \"helloWorld.groovy\" , null)");
71 history.add(
"DeviceManager.addConnection(new DyIO(ConnectionDialog.promptConnection()),\"dyio\")");
72 history.add(
"DeviceManager.addConnection(new DyIO(new SerialConnection(\"/dev/DyIO0\")),\"dyio\")");
73 history.add(
"shellType Clojure #Switches shell to Clojure");
74 history.add(
"shellType Jython #Switches shell to Python");
75 history.add(
"shellType Groovy #Switches shell to Groovy/Java");
77 history.add(
"println \"Hello world!\"");
83 private static void fail() {
85 "Usage: \r\njava -jar BowlerScriptKernel.jar -s <file 1> .. <file n> # This will load one script after the next ");
87 "java -jar BowlerScriptKernel.jar -p <file 1> .. <file n> # This will load one script then take the list of objects returned and pss them to the next script as its 'args' variable ");
89 "java -jar BowlerScriptKernel.jar -r <Groovy Jython or Clojure> (Optional)(-s or -p)<file 1> .. <file n> # This will start a shell in the requested langauge and run the files provided. ");
90 System.err.println(
"java -jar BowlerScriptKernel.jar -g <Git repo> <Git file> # this will run a file from git");
98 @SuppressWarnings(
"unchecked")
99 public static
void main(String[] args) throws Exception {
100 long startTime = System.currentTimeMillis();
103 }
catch (Throwable t) {
105 System.err.println(
"ERROR No UI engine availible");
108 if (args.length == 0) {
113 boolean gitRun =
false;
114 String gitRepo =
null;
115 String gitFile =
null;
116 for (String s : args) {
119 if (gitRepo ==
null) {
121 }
else if (gitFile ==
null) {
125 if (s.startsWith(
"-g")) {
130 File baseWorkspaceFile =
null;
131 if (gitRun && gitRepo !=
null) {
136 boolean fileExists =
false;
139 if (gitFile.endsWith(
"/"))
141 for (String f : files) {
142 if (f.startsWith(gitFile)) {
148 System.err.println(
"\n\nERROR file does not exist: " + gitFile);
158 }
catch (Throwable e) {
163 System.out.println(
"Files in git:");
164 for (String f : files) {
165 System.out.println(
"\t" + f);
176 boolean startLoadingScripts =
false;
177 for (String s : args) {
178 if (startLoadingScripts) {
181 File f =
new File(s);
182 File parentFile = f.getParentFile();
183 if(parentFile==
null) {
184 parentFile=
new File(
".");
186 String location =parentFile.getAbsolutePath();
187 if(location.endsWith(
".")) {
188 location=location.substring(0,location.length()-1);
190 if(!location.endsWith(
"/")) {
193 baseWorkspaceFile =
new File(location);
195 System.out.println(
"Using working directory "+baseWorkspaceFile.getAbsolutePath());
196 f=
new File(baseWorkspaceFile.getAbsolutePath()+
"/"+f.getName());
197 System.out.println(
"File "+f.getName());
199 }
catch (Throwable e) {
204 if (s.startsWith(
"-f") || s.startsWith(
"-s")) {
205 startLoadingScripts =
true;
208 if (startLoadingScripts) {
210 startLoadingScripts =
false;
215 for (String s : args) {
217 if (startLoadingScripts) {
220 }
catch (Throwable e) {
225 if (s.startsWith(
"-p")) {
226 startLoadingScripts =
true;
229 if (startLoadingScripts) {
234 boolean runShell =
false;
235 String groovy =
"Groovy";
236 String shellTypeStorage = groovy;
237 for (String s : args) {
241 shellTypeStorage = s;
242 }
catch (Throwable e) {
243 shellTypeStorage = groovy;
247 if (s.startsWith(
"-r")) {
255 System.out.println(
"Starting Bowler REPL in langauge: " + shellTypeStorage);
259 if (!Terminal.getTerminal().isSupported()) {
260 System.out.println(
"Terminal not supported " + Terminal.getTerminal());
264 ConsoleReader reader =
new ConsoleReader();
265 reader.addTriggeredAction(Terminal.CTRL_C, e -> {
271 reader.getHistory().addToHistory(
"println SDKBuildInfo.getVersion()");
272 reader.getHistory().addToHistory(
"for(int i=0;i<100;i++) { println dyio.getValue(0) }");
273 reader.getHistory().addToHistory(
"dyio.setValue(0,128)");
274 reader.getHistory().addToHistory(
"println dyio.getValue(0)");
275 reader.getHistory().addToHistory(
276 "ScriptingEngine.inlineGistScriptRun(\"d4312a0787456ec27a2a\", \"helloWorld.groovy\" , null)");
277 reader.getHistory().addToHistory(
278 "DeviceManager.addConnection(new DyIO(ConnectionDialog.promptConnection()),\"dyio\")");
279 reader.getHistory().addToHistory(
280 "DeviceManager.addConnection(new DyIO(new SerialConnection(\"/dev/DyIO0\")),\"dyio\")");
281 reader.getHistory().addToHistory(
"BowlerKernel.speak(\"Text to speech works like this\")");
282 reader.getHistory().addToHistory(
283 "ScriptingEngine.gitScriptRun(\\\"https://github.com/OperationSmallKat/greycat.git\\\", \\\"launch.groovy\\\" , null)");
284 reader.getHistory().addToHistory(
"println \"Hello world!\"");
288 for (String h : history) {
289 reader.getHistory().addToHistory(h);
292 reader.setBellEnabled(
false);
293 reader.setDebug(
new PrintWriter(
new FileWriter(
"writer.debug",
true)));
295 Runtime.getRuntime().addShutdownHook(
new Thread() {
308 while ((line = reader.readLine(
"Bowler " + shellTypeStorage +
"> ")) !=
null) {
309 if (line.equalsIgnoreCase(
"quit") || line.equalsIgnoreCase(
"exit")) {
312 if (line.equalsIgnoreCase(
"history") || line.equalsIgnoreCase(
"h")) {
313 List<String> h = reader.getHistory().getHistoryList();
315 System.out.println(s);
319 if (line.startsWith(
"shellType")) {
321 shellTypeStorage = line.split(
" ")[1];
322 }
catch (Exception e) {
323 shellTypeStorage = groovy;
330 System.out.println(ret);
335 }
catch (Exception e) {
339 }
catch (Exception e) {
345 private static void finish(
long startTime) {
347 "Process took " + (((
double) (System.currentTimeMillis() - startTime))) / 60000.0 +
" minutes");
352 if(baseWorkspaceFile!=
null)
353 System.out.println(
"Processing file in directory "+baseWorkspaceFile.getAbsolutePath());
356 public void progressUpdate(
int currentIndex,
int finalIndex, String type,
357 eu.mihosoft.vrl.v3d.CSG intermediateShape) {
362 if (baseWorkspaceFile !=
null) {
363 File baseDirForFiles =
new File(
"./manufacturing/");
364 if (baseDirForFiles.exists()) {
366 File bomCSV =
new File(
368 if (bomCSV.exists()) {
370 File file =
new File(baseDirForFiles.getAbsolutePath() +
"/bom.csv");
374 Files.copy(bomCSV.toPath(), file.toPath());
375 }
catch (IOException e) {
383 File file =
new File(baseDirForFiles.getAbsolutePath() +
"/bom.json");
387 Files.copy(bom.toPath(), file.toPath());
388 }
catch (IOException e) {
395 ArrayList<CSG> csgBits =
new ArrayList<>();
399 System.out.println(
"Loading printbed URL "+url);
404 System.out.println(
"Exporting files without print bed");
407 }
catch (Throwable t) {
415 if (List.class.isInstance(ret)) {
416 List lst = (List) ret;
417 for (
int i = 0; i < lst.size(); i++)
421 if (
CSG.class.isInstance(ret)) {
422 csgBits.add((
CSG) ret);
430 public void setSelectedCsg(Collection<CSG> selectedCsg) {
436 public void setSelected(Affine rootListener) {
442 public void setAllCSG(Collection<CSG> toAdd, File source) {
448 public void highlightException(File fileEngineRunByName, Throwable ex) {
449 ex.printStackTrace();
454 public Set<CSG> getVisibleCSGs() {
460 public void addCSG(Collection<CSG> toAdd, File source) {
471 File baseDir =
new File(
"./manufacturing/");
472 File dir =
new File(baseDir.getAbsolutePath() +
"/" + base.
getScriptingName());
478 }
catch (Throwable T) {
479 throw new RuntimeException(T.getMessage());
486 System.out.println(
"Found arrangeBed API in CAD engine");
487 List<CSG> totalAssembly = bed.
arrangeBed(base);
492 long heapSize = Runtime.getRuntime().totalMemory();
496 long heapMaxSize = Runtime.getRuntime().maxMemory();
500 for (
int i = 0; i < totalAssembly.size(); i++) {
501 List<CSG> tmp = Arrays.asList(totalAssembly.get(i));
502 totalAssembly.set(i,
null);
513 }
catch (Exception e) {
521 public static ArrayList<String>
loadHistory() throws IOException {
522 ArrayList<String> history =
new ArrayList<>();
524 BufferedReader br =
new BufferedReader(
new FileReader(
historyFile));
527 while ((line = br.readLine()) !=
null) {
535 System.out.println(
"Saving history");
536 FileOutputStream fos;
539 BufferedWriter bw =
new BufferedWriter(
new OutputStreamWriter(fos));
540 for (String s : history) {
546 }
catch (FileNotFoundException e) {
549 }
catch (IOException e) {
557 return speak(msg, 200, 0, 100, 1.0, 1.0, progress);
560 public static int speak(String msg) {
562 return speak(msg, 200, 0, 301, 1.0, 1.0,
null);
565 @SuppressWarnings(
"unused")
566 public static
int speak(String msg, Number rate, Number pitch, Number voice, Number shift, Number volume) {
567 return speak(msg, rate, pitch, voice, shift, volume,
null);
570 @SuppressWarnings(
"unused")
571 public static
int speak(String msg, Number rate, Number pitch, Number voiceNumber, Number shift, Number volume,
573 if (rate.doubleValue() > 300)
575 if (rate.doubleValue() < 10)
578 if (voiceNumber.doubleValue() >= 800) {
583 }
catch (Throwable t) {
588 tts.
getAvailableVoices().stream().forEach(voice -> System.out.println(
"Voice: " + voice));
591 String voice =
"dfki-poppy-hsmm";
592 if (voiceNumber.doubleValue() > 600)
593 voice = (
"dfki-prudence-hsmm");
594 else if (voiceNumber.doubleValue() > 500)
595 voice = (
"cmu-rms-hsmm");
596 else if (voiceNumber.doubleValue() > 400)
597 voice = (
"cmu-bdl-hsmm");
598 else if (voiceNumber.doubleValue() > 300)
599 voice = (
"dfki-obadiah-hsmm");
600 else if (voiceNumber.doubleValue() > 200)
601 voice = (
"cmu-slt-hsmm");
602 else if (voiceNumber.doubleValue() > 100)
603 voice = (
"dfki-spike-hsmm");
607 System.out.println(
"Using voice " + voice);
609 RobotiserEffect vocalTractLSE =
new RobotiserEffect();
610 vocalTractLSE.setParams(
"amount:" + pitch.intValue());
624 if (volume.doubleValue() < 0.5) {
626 LpcWhisperiserEffect lpcWhisperiserEffect =
new LpcWhisperiserEffect();
627 lpcWhisperiserEffect.setParams(
"amount:" + (50 + (50 * volume.doubleValue())));
628 effect +=
"+" + lpcWhisperiserEffect.getFullEffectAsString();
631 if (shift.doubleValue() < 1) {
632 ChorusEffectBase ce =
new ChorusEffectBase();
633 ce.setParams(
"delay1:" + (
int) (366.0 * shift.doubleValue())
634 +
";amp1:0.54;delay2:600;amp2:-0.10;delay3:250;amp3:0.30");
635 effect +=
"+" + ce.getFullEffectAsString();
642 VolumeEffect volumeEffect =
new VolumeEffect();
643 volumeEffect.setParams(
"amount:" + volume);
645 HMMDurationScaleEffect ratEff =
new HMMDurationScaleEffect();
646 ratEff.setParams(
"durScale:" + rate.doubleValue() / 100.0);
648 effect +=
"+" + ratEff.getFullEffectAsString();
649 effect +=
"+" + volumeEffect.getFullEffectAsString();
650 if (pitch.intValue() > 0)
651 effect +=
"+" + vocalTractLSE.getFullEffectAsString();
652 System.out.println(msg +
"-->" + effect);
655 tts.
speak(msg, 2.0f,
false,
true, progress);
662 System.err.println(
"Opening " +
string);
666 }
catch (URISyntaxException e) {
669 }
catch (Throwable e) {
676 if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE))
678 Desktop.getDesktop().browse(htmlUrl);
679 }
catch (IOException e) {
static int speak(String msg)
static void processReturnedObjects(Object ret, ArrayList< CSG > csgBits)
static ArrayList< String > loadHistory()
static void processReturnedObjectsStart(Object ret, File baseWorkspaceFile)
static void main(String[] args)
static int speak(String msg, ISpeakingProgress progress)
static void upenURL(URI htmlUrl)
static void writeHistory(List< String > history)
static void finish(long startTime)
static void upenURL(String string)
static CoquiDockerManager get(double doubleValue)
int speak(String text, float gainValue, boolean daemon, boolean join, ISpeakingProgress progress)
Collection< Voice > getAvailableVoices()
MaryInterface getMarytts()
int speak(String text, float gainValue, boolean daemon, boolean join, ISpeakingProgress progress)
void setVoice(String voice)
ArrayList< File > generateManufacturingParts(List< CSG > totalAssembly, File baseDirForFiles)
static MobileBaseCadManager get(MobileBase device, IMobileBaseUI ui)
ArrayList< CSG > generateBody()
void setConfigurationViewerMode(boolean b)
ArrayList< File > _generateStls(MobileBase base, File baseDirForFiles, boolean kinematic)
void setUi(IMobileBaseUI ui)
IgenerateBed getIgenerateBed()
IgenerateBed getPrintBed(File baseDirForFiles, IgenerateBed bed, File baseWorkspaceFile)
ArrayList< CSG > makePrintBeds()
static ArrayList< String > filesInGit(String remote, String branch, String extnetion)
static void waitForLogin()
static String locateGitUrl(File f)
static Object gitScriptRun(String gitURL, String Filename)
static Object inlineFileScriptRun(File f, ArrayList< Object > args)
static Object inlineScriptStringRun(String line, ArrayList< Object > args, String shellTypeStorage)
static File getWorkspace()
static File getRepositoryCloneDirectory(String remoteURI)
static void pull(String remoteURI, String branch)
static final String MANUFACTURING_BOM_JSON
static final String MANUFACTURING_BOM_CSV
String[] getGitSelfSource()
String getScriptingName()
static void setProgressMoniter(ICSGProgress progressMoniter)
ArrayList< CSG > arrangeBed(MobileBase base)