Week (24)
Description
I had a good session this week as I managed to get into Uni, I got to work with my tutor in getting the jaw to function to move when processing outputted to applescript. There is still more work to be done and we installed a switch to stop the mouth moving on demand because we I have to work out how to make an audio trigger and wire that straight into the Arduino. The system works by a simple routine in arduino, the code adds random co-ordinates to specific angels for examples if the mouth servo goes over 90 degrees then add random 40 degrees and the same for the delay function this is to give the servos a more natural sporadic movement. The cut off switch works by using a simple switch mechanism that cuts the circuit and stop the arduino receiving information into the analog port, when no information is sent the arduino reverts to 134 degrees or mouth closed.
Equipment.
Bread Board
Wires
Transistor
Switch
(1.1, 1.2)
Arduino side
#include <Servo.h>
int c=0;
int talkmode=0;
int talkmode2=0;
long rfac;
long mpos;
long rfac2;
long mpos2;
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
Servo myservo2;
Servo myservo3;
Servo myservo4;
int talkcount=255; //eventually use audio stop trigger
void setup()
{
Serial.begin(9600);
pinMode(A0,OUTPUT);
pinMode(A2,OUTPUT);
pinMode(A3,OUTPUT);
pinMode(A4,OUTPUT);
myservo.attach(A0);
myservo2.attach(A2);
// myservo3.attach(A3);
// myservo4.attach(A4);
}
void loop(){
while(Serial.available()>0){
talkmode=Serial.read();
}
if(talkmode==1){
rfac=random(100);
if(rfac<40){
// mpos=random(130);
mpos=95+random(40);
delay(20+random(30))
}else{
mpos=128;
}
int r=analogRead(5);
if(r<1000){
mpos=128;
talkmode=0;
}
}
if(talkmode==0){
mpos=300;
}
myservo.write(mpos);
Processing side
import processing.serial.*;
/*
A little example using the classic "Eliza" program.
Eliza was compiled as a Processing library, based on the
java source code by Charles Hayden:
htp://www.chayden.net/eliza/Eliza.html
The default script that determines Eliza's behaviour can be
changed with the readScript() function.
Intructions to modify the script file are available here:
http://www.chayden.net/eliza/instructions.txt
*/
import codeanticode.eliza.*;
Serial myport;
Serial myport2; // neck motor
int drawskeleton=0; //1 / 0
Eliza eliza;
PFont font;
String elizaResponse, humanResponse;
boolean showCursor;
int lastTime;
PImage bg1a;
void setup()
{
size(1200, 786);
background(200,0,0);
//end si
bg1a=loadImage("bg1.jpg");
println(Serial.list());
myport=new Serial(this, Serial.list()[6],9600);
//myport2=new Serial(this, Serial.list()[??????],9600);
// When Eliza is initialized, a default script built into the
// library is loaded.
eliza = new Eliza(this);
// A new script can be loaded through the readScript function.
// It can take local as well as remote files.
eliza.readScript("scriptnew.txt");
//eliza.readScript("http://chayden.net/eliza/script");
// To go back to the default script, use this:
//eliza.readDefaultScript();
font = loadFont("Rockwell-24.vlw");
textFont(font);
printElizaIntro();
humanResponse = "";
showCursor = true;
lastTime = 0;
}
void draw()
fill(255);
stroke (111);
text(elizaResponse, 30, 450, width - 40, height);
fill(0);
int t = millis();
if (t - lastTime > 500)
{
showCursor = !showCursor;
lastTime = t;
}
if (showCursor) text(humanResponse + "_", 30, 600, width - 40, height);
else text(humanResponse, 30, 600, width - 40, height);
simpleopennidrawmethod();
}
void keyPressed()
{
if ((key == ENTER) || (key == RETURN))
{
println(humanResponse);
//first scan for keywords
elizaResponse = eliza.processInput(humanResponse);
println(">> " + elizaResponse);
String[] out={elizaResponse};
saveStrings("/Users/macbookpro/Desktop/test.txt",out);
delay(10);
println(sketchPath+"/data/applescriptbridge.app");
open(sketchPath+"/data/applescriptbridge.app");
myport.write(1);
humanResponse = "";
}
else if ((key > 31) && (key != CODED))
{
// If the key is alphanumeric, add it to the String
humanResponse = humanResponse + key;
}
else if ((key == BACKSPACE) && (0 < humanResponse.length()))
{
char c = humanResponse.charAt(humanResponse.length() - 1);
humanResponse = humanResponse.substring(0, humanResponse.length() - 1);
}
}
void printElizaIntro()
{
String hello = "Hello.";
elizaResponse = hello + " " + eliza.processInput(hello);
println(">> " + elizaResponse);
}
}
Base Building
Equipment.
1 x 800mm Di cheq alumium place (1.3)
1 x 800 mm Di - 300 mm Dep Wooden Circular Cut out (1.4)
Black Spray Paint
Black guitar neck Plate
Black guitar neck Plate
I built the base for the robot this week, I ordered the bits i needed off Ebay. To start with I matched the legs of the robots base up to the check plate and drilled small holes into it then i did the same for the wooden base but only particle holes not all the way through, these where to slot the very tips of the bottom base rods into them. I secured the aluminium plate onto the legs using bolts. I then drilled 3 additional holes into the Aluminium plate and stuck screws through the holes, i then screwed the screws into the wood base plate after I had sprayed it black with spray paint. I also found an old guitar neck plate that I thought i could use to cover up part of the neck framework to make it look more professional however this may also come in useful later on for attaching the neck framework for securely to the base (1.5, 1.6)
Feelings
I am happy with how the build is progressing again I am hoping that I will get the major parts of it finished in the next couple of weeks. I also think that the project is starting to look really interesting as people are stopping and having a look and talking to me about the project as they pass by my desk so I'm feeling pleased that people are naturally taking an interesting in the project.
Evaluation
This session was a good experience, I am not 100% on how the code interacts from processing into Arduino using the audio switch but i will have an in-depth look into it when I have chance and properly annotate the code. I was pleased with the parts i had ordered because there is always a worry when ordering over the internet that things are not going to be but to the correct size but everything fit into place like it should.
Analysis
The current situation of the build does make sense to me I do know there are parts of the code I need to go over and give closer examination, but i am happy at where i am with the project and how it relates to the brief. I am really starting to see how the application of code is bringing life to the project and the more I learn about the interaction between processing and arduino the more I can see how useful it could be for future projects.
Conclusion
In conclusion, a lot has been achieved this session the project has taken a massive leap and is starting to come together well. I really like how the mouth mechanism works the action is really smooth, I need to test it out with the jaw L/R servo working at the same time to see what it looks like when both systems are working simultaneously to see if the same natural movement can be achieved.
Action Plan
If I had to re-do this session I would write down notes from the time i spent with my lecturer, because I thought I could remember how the process worked in my head but a few days later I cannot remember it fully. Next session will be spent rigging up a digital audio trigger, I am also thinking that I may leave this circuit in but use it as a cut off switch for the whole project by flatlining all the servos.
1.1
1.2
1.3
1.4
1.5
1.6
