Skip to content

Instantly share code, notes, and snippets.

@madhephaestus
Forked from nvitalepenniman/YodaAnamation.groovy
Created September 3, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madhephaestus/9ad31af45be2c1230da0 to your computer and use it in GitHub Desktop.
Save madhephaestus/9ad31af45be2c1230da0 to your computer and use it in GitHub Desktop.
import com.neuronrobotics.sdk.addons.kinematics.MobileBase;
import com.neuronrobotics.sdk.addons.kinematics.DHParameterKinematics;
import org.apache.commons.io.IOUtils;
import java.awt.image.BufferedImage;
import com.neuronrobotics.imageprovider.Detection;
import java.util.List;
OpenCVImageProvider eye=null;
if(DeviceManager.getSpecificDevice(OpenCVImageProvider.class, "eye")==null){
eye= new OpenCVImageProvider(0);
DeviceManager.addConnection(eye,"eye");
}else{
eye=(OpenCVImageProvider)DeviceManager.getSpecificDevice(OpenCVImageProvider.class, "eye");
}
// Starting with the connected camera from BowlerStudio
println(eye)
//Create the default detector using "lbpcascade_frontalface.xml"
IObjectDetector detector = new HaarDetector("lbpcascade_frontalface.xml")
// Create the input and display images. The display is where the detector writes its detections overlay on the input image
BufferedImage inputImage = AbstractImageProvider.newBufferImage(640,480)
BufferedImage displayImage = AbstractImageProvider.newBufferImage(640,480)
DyIO d=null;
if(DeviceManager.getSpecificDevice(DyIO.class, "dyio")==null){
d = new DyIO(ConnectionDialog.promptConnection()); // This is the DyIO to talk to.
d.connect(); // Connect to it.
DeviceManager.addConnection(d,"dyio");
}else{
d=(DyIO)DeviceManager.getSpecificDevice(DyIO.class, "dyio");
}
String xmlContent=null;
//define the file to load
xmlContent = ScriptingEngineWidget.codeFromGistID("3005490fa78c2c3daac1","Yodaconfiguration.xml")[0];
MobileBase model=null;
DHParameterKinematics puppet;
if(DeviceManager.getSpecificDevice(MobileBase.class, "yoda")==null){
model = new MobileBase(IOUtils.toInputStream(xmlContent, "UTF-8"));
//Add the custom inverse solver
DeviceManager.addConnection(model,"yoda");
}else{
model = (MobileBase)DeviceManager.getSpecificDevice(MobileBase.class, "yoda");
}
puppet = model.getAppendages().get(0);
puppet.setDesiredTaskSpaceTransform(new TransformNR(
0,// X position
-150,// y position
80,
new RotationNR()),
0);// Seconds for translation
ServoChannel mouth = new ServoChannel (d.getChannel(15));
mouth.SetPosition(0, 0);
// Loop checking the camera for faces
while(!Thread.interrupted()){
eye.getLatestImage(inputImage,displayImage) // capture image
List<Detection> data = detector.getObjects(inputImage, displayImage)
if(data.size()>0){
break;
}
}
void say(String thingToSay,ServoChannel mouth,DHParameterKinematics puppet, double x, double y, double z ){
int MouthClosedPosition=0
int MouthOpenPosition=50
new Thread(){
public void run(){
BowlerStudio.speak(thingToSay)
}
}.start()
println thingToSay.length()
for(int I=0; I<(thingToSay.length()/2.5);I++){
int oddEven=I%2
if (oddEven==0){
mouth.SetPosition(MouthClosedPosition, 0.1);
//do something
}else{
mouth.SetPosition(MouthOpenPosition, 0.1);
//do something else
}
ThreadUtil.wait(150)
}
mouth.SetPosition(MouthClosedPosition, 0);
ThreadUtil.wait(1000)
puppet.setDesiredTaskSpaceTransform(new TransformNR(
x,// X position
y,// y position
z,
new RotationNR()),
0.5);// Seconds for translation
}
say("yoda I am",mouth,puppet,43.518,-146.9, 81.317)
say("Ask questions, I do not.",mouth,puppet,21.728,-144.032, 66.635)
say("Know answers, I do.",mouth,puppet,50.223,-130.029, 98.734)
say("Hungry I am, need a hamburger, I do.",mouth,puppet,0,-150, 80)
say("Eat hamburgers, I do not. Eat batteries, I do.",mouth,puppet,
39.468,// X position
-145.481,// y position
69.878)
say("Do.",mouth,puppet, -45.881,// X position
-120.856,// y position
71.344)
say("or do not.",mouth,puppet,
-48.686,// X position
-171.610,// y position
76.173)
say("There is no try.",mouth,puppet,
0.003,// X position
-136.121,// y position
110.154)
say("Fear is the path to the dark side.",mouth,puppet,
0,// X position
-150,// y position
80)
say("Fear leads to anger, anger leads to hate, hate leads to suffering.",mouth,puppet,
0,// X position
-150,// y position
80)
say("Train yourself to let go of everything you fear to lose.",mouth,puppet,
0,// X position
-150,// y position
80)
say("Ready are you?",mouth,puppet,
0,// X position
-150,// y position
80)
say("What know you of ready?",mouth,puppet,
0,// X position
-150,// y position
80)
say("Go to the jedi temple, we must. Fight the separatists, we will.",mouth,puppet,
0,// X position
-150,// y position
80)
say("May the force be with you.",mouth,puppet,
0,// X position
-150,// y position
80)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment