Week 7
For the coding, we have decided to use MATLAB for it was a coding language that we all understood and could contribute tweaks and fixes to.
This week, we have successfully created a "sample" code. This code includes the basic movements that the Wheatley animatronic should be able to preform, such as opening and closing each eyelid (at the same time of course), moving the eyeball in circles, and turning the entire eye setup to the right and left. Here is the sample coding:
Blink Command
for j=1:1:1
for i=1:1.5:45
servos.move0(60-i); pause(0.000);
servos.move1(30-i); pause(0.000);
end
for i=1:1.5:45
servos.move0(i); pause(0.000);
servos.move1(-20+i); pause(0.000);
end
end
for i=1:1:1
for i=1:1:25
servos.move2(i); pause(0.000);
servos.move3(i); pause(0.000);
end
pause(0.5);
for i=1:1:25
servos.move2(-i); pause(0.000);
servos.move3(i); pause(0.000);
end
pause(0.5);
for i=1:1:45
servos.move2(-i); pause(0.000);
servos.move3(-i); pause(0.000);
end
pause(0.5);
for i=1:1:45
servos.move2(i); pause(0.000);
servos.move3(-i); pause(0.000);
end
end
for j=1:1:1
for i=-35:.50:5
servos.move4(i); pause(0.00);
end
pause(1.00);
for i=5:-.50:-35
servos.move4(i); pause(0.00);
end
end
Certain angles in the coding that determine the position of the servos may seem a bit off if this project were to be replicated. This is due to the servos positioning; some are not perfectly adjusted to have 45 degrees be one extreme and -45 degrees be the other extreme. The format would be similar, however the rest of the angles would need to be adjusted.
Next to be coded is a recreation of a line spoken by Wheatley in the game Portal 2.
Week 8
We have created a function file in order to make the coding a cleaner process. The function consists of 6 servo motion lines in order to compress the amount of code writing.
function wheatley( servos,a,b,c,d,e )
servos.move0(-10+a); %Top Eyelid -down/+up
servos.move1(-10+b); %Bottom Eyelid +down/-up
servos.move2(-20+c); %Eyeball -left/+right
servos.move3(-10-d); %Eyeball +up/-down
servos.move4(0+e); %Rotation Plate -left/+right
end
The constants in front of the variables a,b,c,d, and e are there to move the servos to the zero position. This allows for the numbers entered into the variable position to move the servos relative to the zero position. The 4th servo (servos.move3) is negative due to the servo placement. Making the variable negative allows for the numbers in the code to make more sense to the coder.
Next week, we will be coding in the final servo (servo 6) after it is installed in order to have the entire setup move up and down.
Week 9
We.have successfully added the sixth servo to the animatronic. The new Wheatley function file now looks like this:
function wheatley( servos,a,b,c,d,e,f )
servos.move0(-10+a); %Top Eyelid -down/+up
servos.move1(-10+b); %Bottom Eyelid -down/+up
servos.move2(-20+c); %Eyeball -left/+right
servos.move3(-10-d); %Eyeball +up/-down
servos.move4(0+e); %Rotation Plate -left/+right
servos.move5(15-f); %Rotation Inner Sphere -down/+up
servos.move5(15-f); %Rotation Inner Sphere -down/+up
end
wheatley(servos,0,0,0,0,0,0);
clear y Fs
[y, Fs] = wavread('part_1.wav');
wavplay(y,Fs,'async')
The sixth servo is assigned to the f value in the function. So, now the initial position for the animatronic in the script file is
wheatley(servos,0,0,0,0,0,0);
We also will be using sound clips from the video game that will sync to Wheatley's movements using this line of code:
clear y Fs
[y, Fs] = wavread('part_1.wav');
wavplay(y,Fs,'async')
These lines of code are able to read .wav files that are in the same location as the MATLAB file. For this project we will be using about four .wav files.
Week 10
The algorithm for the animatronic is finished. It consists of three function files and one script file which contains all movement functions for the animatronic. One function file detects the servo controller, one detects the attached servos, and the last one allows for all servo positions to be set using a single function. Below is a flow chart explaining how all of the files work together:
No comments:
Post a Comment