Wednesday, December 10, 2014

Laser Cut Part

The picture above is a screen shot of the assembly depicting the usage of our laser cut part. The blue cylinder is the stand that holds the barrel of the cannon. The green part shown is the laser cut part made from .25" acrylic. The open square area is where the stepper motor is situated. This part essentially created a more aesthetically appealing design as well as situated the stepper motor in a place that maximized its potential to pull on the barrel of the cannon.

Tuesday, December 9, 2014

The Finished Product


It's safe to say that while our project didn't come out exactly how we planned, we are still happy with the finished product and certainly had a lot of fun along the way. In our original design, we had planned to  be able to move the cannon from side to side and up and down using a wireless Wii nun chuck. Due to difficulties with both the programming of the wireless nun chuck and weak stepper motors, we were unable to make this a reality. However, we did manage to rig the cannon up to a regular Wii nun chuck, allowing us to fire it by pushing the "C" button on the controller. Since we couldn't get the stepper motors to handle the load necessary to move the cannon, our laser cut part was no longer necessary in order for the cannon to function properly. Perhaps in the future we will be able to find a strong enough motor so that we can aim the cannon better, but that just wasn't possible given the window of time we had to work on the project. Luckily, the cannon does satisfy the most important goal of being able to use it to launch candy into our mouths. Although getting it to fire just right takes a little bit of trial and error, it is all part of the fun and makes actually being able to catch the candy that much better. As soon as the project expo is over, we look forward to applying an excessive amount of pressure to the tank to see just how far our cannon can launch candy.

Monday, December 1, 2014

Wii Made The Nunchuck Work!

After many hours of trials and numerous codes used, we finally found a code that works!! The following code incorporates two servo motor as well as a single LED. The servo motors are controlled via the accelerometer as well as the joystick of the Wii Nunchuck. The LED is turned on when the C Button is pressed on the Nunchuck.

"
// Honus 2007
// This allows the use of a Wii nunchuck as an input device and is modified/extended from the original code
// by Tod E. Kurt and Windmeadow Labs
// 2007 Tod E. Kurt, http://todbot.com/blog/
// The Wii Nunchuck reading code is taken from Windmeadow Labs, http://www.windmeadow.com/node/42

// Further updated and coded for Manual Mode of 2 servos when WiiNunchuck ZButton is pushed.
// By: Raymond Willis Jr., 2013, email at willisjr24@yahoo.com


#include "Wire.h"

int ledPin1 = 8; // Control pin for LED 1
int servoPin1 = 5; // Control pin for servo motor
int servoPin2 = 6; // Control pin for servo motor


int pulseWidth1 = 2; // Amount to pulse the servo 1
int pulseWidth2 = 2; // Amount to pulse the servo 2


int refreshTime = 30; // the time in millisecs needed in between pulses

long lastPulse1;
long lastPulse2;


int minPulse = 700; // minimum pulse width
int loop_cnt=0;

void setup()
{
Serial.begin(19200);
pinMode(servoPin1, OUTPUT); // Set servo pin as an output pin
pinMode(servoPin2, OUTPUT); // Set servo pin as an output pin

pulseWidth1 = minPulse; // Set the motor position to the minimum
pulseWidth2 = minPulse; // Set the motor position to the minimum


nunchuck_init(); // send the initilization handshake
Serial.print("NunchuckServo ready\n");
}

void loop()
{
checkNunchuck1();
updateServo1(); // update servo 1 position
checkNunchuck2();
updateServo2(); // update servo 2 position


if( nunchuck_cbutton() ) // light the LED if c button is pressed
digitalWrite(ledPin1, HIGH);
else
digitalWrite(ledPin1,LOW);

delay(2.5); // this is here to give a known time per loop
}


void checkNunchuck1()
{
if( loop_cnt > 100 ) { // loop()s is every 1msec, this is every 100msec

nunchuck_get_data();
nunchuck_print_data();

if( nunchuck_zbutton() ) // Manual Control if z button is pressed
 {
 float tilt = nunchuck_joyx(); // x-axis, in this case ranges from ~70 - ~185
 tilt = (tilt - 70) * 1.5; // convert to angle in degrees, roughly
 pulseWidth1 = (tilt * 9) + minPulse; // convert angle to microseconds
 }
else
 {
 float tilt = nunchuck_accelx(); // x-axis, in this case ranges from ~70 - ~185
 tilt = (tilt - 70) * 1.5; // convert to angle in degrees, roughly
 pulseWidth1 = (tilt * 9) + minPulse; // convert angle to microseconds
 }
loop_cnt = 0; // reset for
}
loop_cnt++;

}

// called every loop().
// uses global variables servoPin, pulsewidth, lastPulse, & refreshTime
void updateServo1()
{
// pulse the servo again if rhe refresh time (20 ms) have passed:
if (millis() - lastPulse1 >= refreshTime) {
digitalWrite(servoPin1, HIGH); // Turn the motor on
delayMicroseconds(pulseWidth1); // Length of the pulse sets the motor position
digitalWrite(servoPin1, LOW); // Turn the motor off
lastPulse1 = millis(); // save the time of the last pulse
}
}

void checkNunchuck2()
{
if( loop_cnt > 100 ) { // loop()s is every 1msec, this is every 100msec

nunchuck_get_data();
nunchuck_print_data();

if( nunchuck_zbutton() ) // Manual Control if z button is pressed
 {
 float tilt = nunchuck_joyy(); // y-axis, in this case ranges from ~70 - ~185
 tilt = (tilt - 70) * 1.5; // convert to angle in degrees, roughly
 pulseWidth2 = (tilt * 9) + minPulse; // convert angle to microseconds
 }
else
 {
 float tilt = nunchuck_accely(); // y-axis, in this case ranges from ~70 - ~185
 tilt = (tilt - 70) * 1.5; // convert to angle in degrees, roughly
 pulseWidth2 = (tilt * 9) + minPulse; // convert angle to microseconds
}
loop_cnt = 0; // reset for
}
loop_cnt++;

}

// called every loop().
// uses global variables servoPin, pulsewidth, lastPulse, & refreshTime
void updateServo2()
{
// pulse the servo again if rhe refresh time (20 ms) have passed:
if (millis() - lastPulse2 >= refreshTime) {
digitalWrite(servoPin2, HIGH); // Turn the motor on
delayMicroseconds(pulseWidth2); // Length of the pulse sets the motor position
digitalWrite(servoPin2, LOW); // Turn the motor off
lastPulse2 = millis(); // save the time of the last pulse
}
}


//
// Nunchuck functions
//

static uint8_t nunchuck_buf[6]; // array to store nunchuck data,


// initialize the I2C system, join the I2C bus,
// and tell the nunchuck we're talking to it
void nunchuck_init()
{
Wire.begin(); // join i2c bus as master
Wire.beginTransmission(0x52); // transmit to device 0x52
Wire.write(0x40); // sends memory address
Wire.write(0x00); // sends sent a zero.
Wire.endTransmission(); // stop transmitting
}

// Send a request for data to the nunchuck
// was "send_zero()"
void nunchuck_send_request()
{
Wire.beginTransmission(0x52); // transmit to device 0x52
Wire.write(0x00); // sends one byte
Wire.endTransmission(); // stop transmitting
}

// Receive data back from the nunchuck,
// returns 1 on successful read. returns 0 on failure
int nunchuck_get_data()
{
int cnt=0;
Wire.requestFrom (0x52, 6); // request data from nunchuck
while (Wire.available ()) {
// receive byte as an integer
nunchuck_buf[cnt] = nunchuk_decode_byte(Wire.read());
cnt++;
}
nunchuck_send_request(); // send request for next data payload
// If we recieved the 6 bytes, then go print them
if (cnt >= 5) {
return 1; // success
}
return 0; //failure
}

// Print the input data we have recieved
// accel data is 10 bits long
// so we read 8 bits, then we have to add
// on the last 2 bits. That is why I
// multiply them by 2 * 2
void nunchuck_print_data()
{
static int i=0;
int joy_x_axis = nunchuck_buf[0];
int joy_y_axis = nunchuck_buf[1];
int accel_x_axis = nunchuck_buf[2]; // * 2 * 2;
int accel_y_axis = nunchuck_buf[3]; // * 2 * 2;
int accel_z_axis = nunchuck_buf[4]; // * 2 * 2;

int z_button = 0;
int c_button = 0;

// byte nunchuck_buf[5] contains bits for z and c buttons
// it also contains the least significant bits for the accelerometer data
// so we have to check each bit of byte outbuf[5]
if ((nunchuck_buf[5] >> 0) & 1)
z_button = 1;
if ((nunchuck_buf[5] >> 1) & 1)
c_button = 1;

if ((nunchuck_buf[5] >> 2) & 1)
accel_x_axis += 2;
if ((nunchuck_buf[5] >> 3) & 1)
accel_x_axis += 1;

if ((nunchuck_buf[5] >> 4) & 1)
accel_y_axis += 2;
if ((nunchuck_buf[5] >> 5) & 1)
accel_y_axis += 1;

if ((nunchuck_buf[5] >> 6) & 1)
accel_z_axis += 2;
if ((nunchuck_buf[5] >> 7) & 1)
accel_z_axis += 1;

Serial.print(i,DEC);
Serial.print("\t");

Serial.print("joy:");
Serial.print(joy_x_axis,DEC);
Serial.print(",");
Serial.print(joy_y_axis, DEC);
Serial.print(" \t");

Serial.print("acc:");
Serial.print(accel_x_axis, DEC);
Serial.print(",");
Serial.print(accel_y_axis, DEC);
Serial.print(",");
Serial.print(accel_z_axis, DEC);
Serial.print("\t");

Serial.print("but:");
Serial.print(z_button, DEC);
Serial.print(",");
Serial.print(c_button, DEC);

Serial.print("\r\n"); // newline
i++;
}

// Encode data to format that most wiimote drivers except
// only needed if you use one of the regular wiimote drivers
char nunchuk_decode_byte (char x)
{
x = (x ^ 0x17) + 0x17;
return x;
}

// returns zbutton state: 1=pressed, 0=notpressed
int nunchuck_zbutton()
{
return ((nunchuck_buf[5] >> 0) & 1) ? 0 : 1; // voodoo
}

// returns zbutton state: 1=pressed, 0=notpressed
int nunchuck_cbutton()
{
return ((nunchuck_buf[5] >> 1) & 1) ? 0 : 1; // voodoo
}

// returns value of x-axis joystick
int nunchuck_joyx()
{
return nunchuck_buf[0];
}

// returns value of y-axis joystick
int nunchuck_joyy()
{
return nunchuck_buf[1];
}

// returns value of x-axis accelerometer
int nunchuck_accelx()
{
return nunchuck_buf[2]; // FIXME: this leaves out 2-bits of the data
}

// returns value of y-axis accelerometer
int nunchuck_accely()
{
return nunchuck_buf[3]; // FIXME: this leaves out 2-bits of the data
}

// returns value of z-axis accelerometer
int nunchuck_accelz()
{
return nunchuck_buf[4]; // FIXME: this leaves out 2-bits of the data
}
"

This should be easily translatable to a stepper motor instead of two servos. We will also be able to use the LED function to control the inline sprinkler valve to control the air flow and pressure release. 

Secondly, the following picture is the finished product! It has been souped up with a wonderful, custom paint job. Check it out!

Saturday, November 29, 2014

Are We There Yet?



Progress: This is the SolidWorks sketch for the laser cut part. It will be the base in which the motor and the stand will be placed in. Today we as well drew up the final sketch for how the cannon will be attached and moved. The programming is still a work in progress. We have attempted to interface multiple codes with our board and Wii Nunchuck. None of them have worked. We will continue to search for codes that work and try to make progress on a possible Nunchuck - Arduino interaction.

Wednesday, November 19, 2014

Incorporating Arduino

Today we made drastic improvements on our project! Rather than requiring the two wires to be touched manually for a launch, we experimented with using a relay and a button in order to control the firing mechanism. The code for this follows this post. When this code and setup succeed, we proceeded to test many different pressure levels with Whoppers, ranging from 30 psi up to 80 psi. The video above is a high speed video shot on an iPhone 5s at 120 frames per second. A piece of paper towel was inserted to the barrel of the cannon prior to loading the Whopper to create a more air tight seal. The pressure loading on this shot was 80 psi. Although this is highly unrealistic for catching a Whopper in ones mouth, we were intrigued and decided to try high pressures such as this. It should also be noted that the paper towel is not necessary to launch the Whopper, this was merely to see what the effect of a more air tight seal would be. This was a huge step for us as using a push button to control the firing mechanism will be easily translatable to the Wii nun-chuck remote, our ultimate goal to control the firing of the candies.

The following code was used to create the launch using a push button and a relay:
"
int relay = 8;
int button = 2;

void setup(){
  pinMode(led,OUTPUT);
  pinMode(relay,OUTPUT);
  pinMode(button, INPUT_PULLUP);
 
  digitalWrite(relay, LOW);
}

void loop(){
  boolean buttonState = digitalRead(button);
 
  if(buttonState == 0){
    digitalWrite(relay, HIGH);
    delay(100);
    digitalWrite(relay, LOW);
   
  }
 
  if(buttonState == 1){
    digitalWrite(relay, LOW);
  }
}
"

Sunday, November 16, 2014

First Launch!

Today we successfully executed our first trial launch! Upon inserting one Whopper, the air pressure was set to 50 psi. As you can see in the video the launch went very smoothly. Although the trajectory of the Whopper itself is difficult to see in the video you can see a small splash toward the right side of the video as the Whopper lands in the water. A few other trials were performed with varying pressure levels as well as one launch attempted with multiple pieces of candy. As the pressure tank still has an issue with a leak, these tests were mainly geared towards the functionality of the design. As soon as the leaking issue of the pressure tank is resolved we will be able to work more towards firing with precision. The tests today have proven that this design will ultimately work for our final goal of  catching candies in our mouths. After the design is finalized we would also like to experiment with candies other than Whoppers to see which may be easiest for participants to catch.

Progress

Design sketch
Design sketch
 Yesterday we finally managed to gather all the parts we needed to build the cannon. We were able to construct the cannon pretty successfully according to our design. However, we did encounter some difficulty with applying a seal around the valve being used to pump air into the pressure tank, which is causing our tank to lose pressure from a slow leak. Luckily, for the time being, this isn't stopping us from doing a few test launches. Our next step will be to construct the pan and tilt function on the cannon and then finally figure out how to program the whole system so that it can be aimed and fired with a wireless Wii nun-chuck controller.

Our cannon!