Thursday, December 17, 2009

Final Project - Motor Controller

The AMC 12A8 Servo Amplifier was used to send the impulse current to our electromagnetic drum. It is capable of handling 20-80 volts and a peak impulse current of 12 amps (6amps continuous). The amp was used in "voltage mode", were an output voltage was determined from a reference input pwm sent from the Arduino. We initially tried to use the amp in "current mode" but found a parasitic current was always sent to our drum, not ideal for our setup. While in voltage mode we tuned the potentiometer gains while the amplifier was connected to an oscilloscope to provide a maximum output current from the pwm signal.

The amp was connected to (4) 25V power supplies, 2 connected in series, 2 in parallel to provide 50 V and twice the amperage. This resulted in a reasonable repelling force.

Final Project - Arduino Code

We used the Arduino Mega board to manage drumstick motion detection, sound synthesis, and force feedback.

Drumstick Motion Detection
We set up our detection system using three pairs of IR emitters and sensors. Each pair of emitter and sensor acts as a photogate; that is, the voltage across the sensor changes when the IR beam is blocked by an object, such as our drumstick. When the IR beams are not blocked, Arduino receives a high analog value (>300). When the drumstick passes through the IR beam, Arduino received a low analog value (<100).

Each pair was mounted such that the IR beam was horizontal, and the three pairs were stacked vertically, separated by 2 inches. The top two pairs were used to measure the velocity of the drumstick. This is accomplished by recording the time between when the top photogate is broken and when the second photogate is broken. Based on this time and the known distance between the two photogates, Arduino calculates the velocity of the drumstick. The third photogate acts as the virtual drum face, so that when it is broken Arduino sends a PWM signal to the electromagnet controller and a MIDI signal to the MIDI controller. The duty cycle of the PWM signal and the loudness of the MIDI sound is modulated by the measured drumstick velocity. The figure below shows the signals coming from the photogates during a typical strike of the drumstick (the signal from Sensor 1 is stronger due to better alignment of the emitter and sensor).


Sound Synthesis
We created a function in Arduino called noteOn that sends a signal to the MIDI controller telling it what sound to make. The function takes in three arguments. The first argument tells the MIDI controller to turn on or off any sounds. The second argument specifies the type of sound to make (i.e., snare, tomtom, cymbals, etc.). The third argument is a loudness value between 0 and 127. This value is derived from the measured drumstick velocity.

Force Feedback
The PWM signal sent from the Arduino when the third photogate is broken goes to a controller that supplies power to the electromagnet. The duty cycle of the PWM signal determines how much current to supply the electromagnet. The figure below shows the supply current with respect to duty cycle. Note: the supply current saturates at a PWM signal of about 230.


The duty cycle is derived from the measured drumstick velocity, and can also be amplified or attenuated to match different drum types. The duration of the PWM signal is a constant that can be altered to match the characteristics of any drum. For example, in the code shown below the duration of the signal in snare mode is short, but it repeats creating a vibratory effect, and the duration of the signal in tomtom mode is long. The figure below shows the (inverted) supply current profile for five separate strikes of the drumstick with an impulse duration of 100ms.


Aduino Code

int sensorpin1 = 0;
int sensorpin2 = 1;
int sensorpin3 = 2;
int PWMpin = 10;
int switchSend = 24;
int switchRec = 34;
int sensorval1 = 0;
int sensorval2 = 0;
int sensorval3 = 0;
int sensorval3_prev = 300;
long time1 = 0;
long time2 = 0;
float vel = 0;
float distance = 2;
float clearance = 2.8;
float snare_dur = 50;
float tomtom_dur = 100;
float snare_coef = 2;
float tomtom_coef = 1.2;
float impulse_amp = 0;
float impulse_coeff = 2000;
int soundOn = 1;

void setup()
{
Serial.begin(31250);
pinMode(switchSend, OUTPUT);
pinMode(switchRec, INPUT);
digitalWrite(switchSend, HIGH);
}

void loop()
{
sensorval1 = analogRead(sensorpin1);
sensorval2 = analogRead(sensorpin2);
sensorval3 = analogRead(sensorpin3);
if (sensorval1<100)>
time1 = millis();
}
if (sensorval2<100)>
time2 = millis();
}
if (time2 > time1 && time2-time1<1500)>
vel = distance/(time2-time1); // vel = [in/ms]
impulse_amp = vel*impulse_coeff;
impulse_amp = constrain(impulse_amp,0,255);
}
else {
impulse_amp = 127;
}
if (sensorval3 <>
if (digitalRead(switchRec) == HIGH) {
if (sensorval3_prev > 100) noteOn(0x90, 38, map(impulse_amp,0,255,0,127));
for (int i=0; i<=5; i++) {
analogWrite(PWMpin, snare_coef*impulse_amp);
digitalWrite(13,HIGH);
delay(snare_dur);
analogWrite(PWMpin,0);
digitalWrite(13,LOW);
delay(snare_dur);
}
if (sensorval3_prev > 100) noteOn(0x80, 38, 127);
} else {
if (sensorval3_prev > 100) noteOn(0x90, 48, map(impulse_amp,0,255,0,127));
analogWrite(PWMpin, tomtom_coef*impulse_amp);
digitalWrite(13,HIGH);
delay(tomtom_dur);
analogWrite(PWMpin,0);
digitalWrite(13,LOW);
if (sensorval3_prev > 100) noteOn(0x80, 48, 127);
}
}
sensorval3_prev = sensorval3;
}

void noteOn(int cmd, int pitch, int velocity) {
Serial.print(cmd, BYTE);
Serial.print(pitch, BYTE);
Serial.print(velocity, BYTE);
}

Final Project - MIDI

We are using General MIDI to communicate between the drum and sound synthesizer. Since our instrument is a percussion device, we are using channel 10. When the MIDI synthesizer is in channel 10, note becomes different instruments. For our drum, we opted to produce snare drum and high tom sound.

We are using the note number 38 to generate the snare drum sound and the note number 48 to generate the high tom sound.

Final Project - Fabrication


Our prototype is consist of the IR emitter and receivers, a wood base, wood towers for the IR sensors, an electromagnet, an Arduino Mega, an amplifier and power supplies.

The IR sensors were bought at Radio Shack and placed on the wood towers. The sensors were placed 2 inches apart from each other as seen on the pictures above. The wood towers and base were made from flat wooden panels and the laser cutter in the Autolab machine shop was used to cut the parts. The base is made of two flat wooden panels that sandwich the bottom plate of the electromagnet. By this way, the electromagnets are secured to the instrument and more professional look was achieved. Furthermore, in order to enhance the overall ergonomics of the playing drum, the base is tilted so that it faces the user. Lastly, the switch for selecting different instruments was attached to the base. The pictures below show the CAD drawing for the laser cut parts.





The electromagnet was made from a spool of insulated magnet wire. The entire spool was used as the core of the electromagnet and we used a circular pipe and a thin iron plate to minimize the magnetic field loss.

We are using one Arduino Mega board for data acquisition and control signal generation and the code is shown on another thread. The Arduino board sends out a PWM signal to drive the electromagnet and the signal is amplified by AMC 12A8 motor controller. The amplifier receives the power from four 25 V power supplies. The power supplies are connected in series and parallel to achieve both high voltage and current. Two power supplies are connected in series and so are the other two. And then the two groups of power supplies are connected in parallel. This gave us approximately 50 V to operate the amplifier and high current so that the electromagnet could generate the strong magnetic field.

Wednesday, December 16, 2009

Final Project - Circuit Diagram


Final Project - Bill of Materials

The following are the components used in our working prototype.


Electromagnet:


(1) Steel Core with theaded hole
(1) Clear Plastic Spool
(~3600 Windings) Insulated Magnet Wire

(1) Galvanized Steel Cylinder Tube for BackIron

(1) Retangular Steel Plate for BackIron

(1) LaserCut Wood Base


DrumStick:


(2) 2B Wooden Drumstick

(3" Long) 1/4" Cylinder Magnets


Sensor Array:


(2) LaserCut Wood Towers

(3) InfraRed Emitting LED

(3) PhotoTransistor Detectors


Power and Control:


(4) 25V Power Supply

(1) AMC 12A8 Servo Amplifier

(1) Ardunio Mega

(1) MidiSport 2X2 USB Box

Final Project - Electromagnetic drum kit with controlled impulse response

There will be three main components to our design: the electromagnetic drum, the drum stick with an embedded permanent magnet, and a sensor curtain. The electromagnetic drum will consist of a ferrous, non-permanent winding core surrounded by a back iron. The purpose of the winding core and back iron will be to minimize the air gap around the electromagnet, thereby increasing the strength of the magnetic field. A cylinder magnet will be embedded in the drum stick, with an isolated pole at the tip designed to experience repelling forces when placed near the "virtual drum face". The sensor curtain will be composed of infrared emitters and phototransistor detectors to determine the speed of the drumstick and location to correlate a proper impulse response to the drum.

When playing the instrument, the user will initially select what type of drum they would like to play, be that a snare or tom tom. This will tell the controller which type of impulse to send to the electromagnet. At wil the user can change the design, and sound, of the drum.


Concept Sketch: