Warning: session_start(): open(/var/lib/php/sessions/sess_e7jrjt3370d41fo4pmjonad5o1, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
!7
cmodule RunVectorSDK > DynPrintLogAndEnabled {
transient Process process;
transient PrintStream out;
switchable bool printImages;
S toSay;
start-thread {
dm_reloadOnFieldChange enabled();
if (!enabled) ret;
//File script = userDir("vector-sdk/cam-stream-to-stdout.py");
File script = userDir("vector-sdk/control-from-java-v2.py");
assertFileExists(script);
makeExecutable(script);
print("Calling " + script);
process = Runtime.getRuntime().exec(platformQuoteOpt(script));
print("SDK process started");
print("PID: " + getOpt(process, "pid"));
drainErrorStreamToConsole(process, line -> enabled, lambda0 enter);
out = new PrintStream(process.getOutputStream());
dm_registerAs_direct vectorSDK();
DataInputStream in = new(process.getInputStream());
S line;
while ((line = in.readLine()) != null) {
if (enabled) {
vmBus_send vectorSDK_gotLine(module(), line);
if (eqic(line, "Connected to vector"))
vmBus_send vectorSDK_connected(module());
if (printImages || !startsWith(line, "img:"))
print("Got line: " + takeFirst(100, line));
}
}
}
void cleanMeUp_process {
if (process != null) {
print("Stopping SDK process");
process.destroy/*Forcibly*/();
print("Stopped SDK process, hopefully");
}
}
visual centerAndSouthWithMargin(super, withMargin(
dm_textFieldAndSubmit_q toSay(r { say(toSay) }, buttonText := "Say")));
// API
void eval(S pythonCode) {
if (empty(pythonCode)) ret;
out.println(jsonEncode(pythonCode));
out.flush();
}
void evalWithControl(S pythonCode) {
eval("with anki_vector.Robot() as robot2:\n" +
indent(4, jreplace(pythonCode, "robot", "robot2")));
}
// returns true if (probably) successful
bool say(S s) {
if (out == null) false;
s = newLinesToSpaces_trim(s);
if (empty(s)) true;
print("Making Vector say: " + s);
// with release_control, there is "unknown error" after first utterance
/*eval(autoUnindent(linesLL(
"robot.conn.request_control(timeout=5.0)",
"robot.behavior.say_text(" + pythonQuote(s) + ")",
//"robot.conn.release_control()"
)));*/
/*eval("with anki_vector.Robot() as robot2:\n" +
" robot2.behavior.say_text(" + pythonQuote(s) + ")");*/
evalWithControl("robot.behavior.say_text(" + pythonQuote(s) + ")");
true;
}
void playWAV(File wav) {
print("Playing: " + wav);
if (!is16KMonoWAVFile(wav)) {
print("Converting to 16k");
File wav2 = javaxCachesDir("vector.wav");
deleteFile(wav2);
ffmpeg_toMonoAudio_16k(wav, wav2);
if (!fileExists(wav2)) fail("Conversion failed");
wav = wav2;
}
int volume = 75;
evalWithControl("robot.audio.stream_wav_file(" + pythonQuote(f2s(wav)) + ", " + volume + ")";
}
void startCamStream {
eval("camFeedOn()");
}
void checkBeingTouched() {
eval([[print("is_being_touched: " + robot.touch.last_sensor_reading.is_being_touched)]]);
}
}