Academy 2013

Final Project

11

My troll head
The final project was the main focus this summer.

The head

I made a troll head in the Shopbot. At first I sculpted in a program called Sculptris.

Here is a picture of the head

1 2

I exported the head as an OBJ file and opened it in PartWorks 3D. In there I was able to slice the head in to layers. I had 7 cm thick Styrofoam planes so that was the thickness on each layer.

After that I had eight pieces to cut out.

Here is a picture of on layer being cut out

3

To keep the foam at its place I drilled together some wood blocks into an L-shape and then drilled them tight to the foam. That way I was able to drill in the wooden bottom part of the Shopbot without going trough the Styrofoam.

The Styrofoam is week material so I wanted to make the Shopbot go as fast as possible. To make that happen I only made finishing toolpath so the machine began cutting the head straight away without cutting it into dozens of layers like it would if the material had harder, for example wood.

Here is the Shopbot working on another layer

4

5

6


When I had cut out all of the layers I glued them together

Here are all of the layers together

7

The Circuit board

The most difficult part about the final project was programming the circuit board. The idea was to have a servo board which controlled two motors. From the board there would be two buttons, one for right movement and one for left. The motors would then spin the eyes of the troll left or right.

Arduino

The first thing I did was connecting the board to an Arduino to get a better look on what I was trying to do. As you can see on the picture below there is an variable resistor there. I used that to controlled the movement of the eyes.

final

This method worked out well but converting it into an hello board was a lot more work than I thought.

hello.servo

I used Neil's servo board in the beginning. I brought out the old oscilloscope to help me find the Pulse Width Modulation (PWM). The problem was that the pulse the program was sending was well over what the servo could handle. So the servo motor just vibrated constantly.

The oscilloscope showing some pulse
9

I did all the programming a program called Atmel Studio 6.1.

I noticed a line on top of the file that said set lfuse to 0x7E for 20 MHz xtal. I found where I could set the lfuse in Atmel Studio but nothing happened. Then I got an advice from a friend who told be to write # define F_CPU 20000000. This line defined the 20 MHz crystal.

Then I tried different variations on the pulse to get the right curve on the eyes movement. On the picture below I saw that the pulse had to be between 1 and 2 ms. Otherwise the motor would go further then it is suppose to go.

8

I settled on the 1300 us as a middle point (eyes front) and 1800 and 800 as left and right.

Now I had to connect an output to the eyes so I could control them. On the ATtiny44 are some unused pins (PA0, PA1, PA2, PA3) so the idea was to use them to control the button inputs.

hello.servo board

servo

To make sure the these pins where working I connected a small led light to a breadboard and tried to turn it on from Atmel Studio. After a lot of work I had the light going and connected it to a button. I defined the button in the program so when I pressed it the light went on and when I released it the light went off.
This is how i defined the Led light
#define LED (1 << PA2)          
#define LED_direction DDRA
Now all I had to do was make another button, connect both of them to the movement of the motors and define them as left or right buttons.

Here is the full code I used for the programming:
// Based on hello.servo.44.2.c
//
// two-channel software PWM servo motor hello-world
//
// set lfuse to 0x7E for 20 MHz xtal
//
// Neil Gershenfeld
// 4/8/12
//
// modified by Bjartur Tyr
// Fablab Vestmannaeyjar
// 12/6/2013
//
// (c) Massachusetts Institute of Technology 2012
// Permission granted for experimental and personal use;
// license for commercial sale available from MIT.
//
# define F_CPU 20000000 

#include <avr/io.h>
#include <util/delay.h>
#define output(directions,pin) (directions |= pin) // set port direction for output
#define set(port,pin) (port |= pin) // set port pin
#define clear(port,pin) (port &= (~pin)) // clear port pin
#define pin_test(pins,pin) (pins & pin) // test for port pin
#define bit_test(byte,bit) (byte & (1 << bit)) // test for bit set
#define position_delay() _delay_ms(1000)
#define PWM_port PORTA
#define PWM_direction DDRA
#define PWM_pin_0 (1 << PA6)
#define PWM_pin_1 (1 << PA7)
#define input_pins PINA
#define loop_count 1

#define input_pin1 (1 << PA0) // defining PA0 as right button
#define input_pin2 (1 << PA2) // defining PA2 as left button
int main(void) {
    //
    // main
    //

    uint8_t i;
    //
    // set clock divider to /1
    //

    CLKPR = (1 << CLKPCE);
    CLKPR = (0 << CLKPS3) | (0 << CLKPS2) | (0 << CLKPS1) | (0 << CLKPS0);
    //
    // set PWM pins to output
    //

    clear(PWM_port, PWM_pin_0);
    output(PWM_direction, PWM_pin_0);
    clear(PWM_port, PWM_pin_1);
    output(PWM_direction, PWM_pin_1);
    //
    // main loop
    //

    while(1){
        //
        // here the motor stays still
        //
        // if button 1 is pressed?
//

        if (pin_test(input_pins,input_pin1) == 0) {
            for (i = 0; i < loop_count; ++i) {
                set(PWM_port,PWM_pin_0);
                set(PWM_port,PWM_pin_1);
                _delay_us(1800);                // this number turns the eye left
                clear(PWM_port,PWM_pin_0);
                clear(PWM_port,PWM_pin_1);
                _delay_us(19000);
            }
        }
//
        // if button 2 is pressed?
//

        else if (pin_test(input_pins,input_pin2)==0) {
            for (i = 0; i < loop_count; ++i) {
                set(PWM_port,PWM_pin_0);
                set(PWM_port,PWM_pin_1);
                _delay_us(800);                   // this number turns the eye right
                clear(PWM_port,PWM_pin_0);
                clear(PWM_port,PWM_pin_1);
                _delay_us(19000);
            }
        }
//
        // no button pressed
//

        else {
            for (i = 0; i < loop_count; ++i) {
                set(PWM_port,PWM_pin_0);
                set(PWM_port,PWM_pin_1);
                _delay_us(1300);             // this number makes the eye watch forward
                clear(PWM_port,PWM_pin_0);
                clear(PWM_port,PWM_pin_1);
                _delay_us(19000);
            }
        }
    }
}


Here is a video of the eyes working



Circuit Board

After I got the motors spinning with Neils board I had to make my own. I put two resistors on the breadboard when I was working with the original servo board so I had to make room for them. The resistors were 1 kΩ and 10 kΩ.
I also had to make patches next to the ATtiny so I had more space to solder the wires for the buttons on.

Here is a picture of the servo board edited by me

servo

After the circu        it board was ready I made two small boards just for the buttons and little space for the wires.

takki

Here is a picture of the buttons connected to wires

10

In the end here are two pictures of the head after it is finished

12

13

Final Project Presentation



 

fablab
Vestmannaeyjar, Iceland