Difference between revisions of "250a Haptics Lab 2012 zz"
|Line 57:||Line 57:|
* Plug in your speakers or earbuds.
* Plug in your speakers or earbuds.
* in Pd, add the following directories to your path by going to File->Path->New:
* in Pd, add the following directories to your path by going to File->Path->New :
Revision as of 15:40, 18 October 2012
- 1 Haptics Lab Using the FireFader for Music 250a
Haptics Lab Using the FireFader for Music 250a
by Edgar Berdahl and edited by Wendy Ju
See this quarter's schedule for due dates.
The goal of this lab is to introduce actuation and active force feedback. Each haptic effect can easily be coupled to a sound because the feedback loop is controlled directly in pd. Different haptic effects suggest different sounds; different sounds suggest different effects. What are the most interesting mappings? Which are appropriate, controllable, even "expressive"? Try each sound control with and without haptic feedback enabled. Are there some that simply cannot be played without haptics?
Feel The Motors
But first find the foam-core board that has motors mounted on it and try them out.
For the DC motors, connect one alligator clip to the 6V supply on the Triple Output Power Supply from Hewlett Packard, and connect the other alligator clip to ground, which is labeled COM. Careful! Don't use the 18V supply instead--you could burn out the motors! By adjusting the +6V knob, you can change what voltage you are applying to each of the DC motors. Which way does the solenoid pull? What are small motors good for and what are large motors good for?
For the AC motors, use the Tektronix Function Generator. Try sine waves in the audible range 20Hz-20kHz on the white-colored AC motor. For it to be loud, it needs to be connected to something that can vibrate. Try changing the sound by coupling it to the foam core or the violin body or something else. The other, smaller AC motor can be used to vibrate objects with iron or steel in them or magnets. Try to use it to vibrate the magnet glued to the foam core. Try to use it to vibrate the violin string directly, which contains some steel inside it. (Hint: You will have to place it very closely to the string without touching the string.) Do you know at which frequencies the violin string responds the most?
Connect the FireFader to Your Beagle Board
Be careful with the FireFader. It is possible to break it, for instance if it goes unstable! If it goes unstable, you should immediately cut the power by turning off the power switch on the FireFader. The power cable for the FireFader has a yellow end on it, on which is written 12V. Be very careful NEVER to plug this into the Beagle Board because you would break it. (The Beagle Board needs to receive only 5V.)
- Disconnect the Arduino Nano that you normally use from your Beagle Board.
- Then connect your Beagle Board instead to the Arduino Nano on the FireFader.
- You will see that a circuit has already been created on the bread board. This is essentially the circuit for the H-bridge motor driver L298 (see p. 6 of the datasheet) with the large LEDs connected in parallel with the motor.
Setup the Software on Your Satellite CCRMA Kit
- First startup your kit
- Connect your Satellite CCRMA kit to your laptop and boot it.
- Use a terminal window to login to Satellite CCRMA as usual using the command ssh -XY firstname.lastname@example.org with the password temppwd
- Download the lab files to your laptop.
- Copy the lab files to your home directory ~ using CyberDuck.
- Unzip the files directly on your board: change into your ~ directory and unzip the archive by running the following two commands:
cd ~ unzip hapticslab2012.zip
- (Note: Don't first unzip the files on your laptop and then copy them over unzipped because we have observed some problems with this!)
- You shouldn't need to reinstall the FireFader Firmware, but in case there is an issue, you can
- run the command arduino& to start the Arduino software. (If it asks you if you want to install a newer version of the Arduino software, tell it no.)
- Use the Arduino software to open ~/hapticslab2012/haptics_firmware/haptics_firmware.pde. Upload this code to the Arduino.
- Look at the main loop loop() in the source code for this firmware for a minute. You can see that it reads data from the serial connection from pd and uses this to set the PWM pins using analogWrite(). Then it writes data to the serial connection to pd about the position of the Fire Fader. Additional data from the analog input pins 1-3 is also sent over the serial, but these pins aren't currently used.
- First start audio. You can dp this with start-jackd as usual, but if you use the following command the audio quality will be slightly better with the FireFader:
jackd --silent -R -P62 --timeout 200 -dalsa -dhw:0 -p512 -n3 -i2 -o2 -s -S -r22050 -Xseq &
- To start pd for this lab, use the following command
pd -sleepgrain 1 &
- Plug in your speakers or earbuds.
- in Pd, add the following directories to your path by going to File->Path->New (be sure to press the Apply button before pressing OK):
(If you have trouble later loading the lab patches, try quitting pd and starting it again to see if this helps with it recognizing the paths.)
- Open pd and load the patch ~/hapticslab2012/datadir/puredatadir/touch_ground~-help.pd
- Read the text of the patch so that you can understand how the layout of the patch relates to the equivalent mechanical system of the FireFader being connected by a touch link to ground.
- Turn on audio by clicking on compute audio, which also allows the haptic forces to be computed.
- Verify that by moving the FireFader back and forth, you can make the hslider shown in the patch change.
- Plug in the 12V yellow power connector to the FireFader.
- Switch the FireFader on while holding onto the fader.
- You should be able to feel a spongy "wall" when you move the FireFader to the left of the center position. (If not, then check your setup.)
- Because of the spring and damper action of the touch link, the force increases when you move to the left. However, if you move far enough to the left, then the motors can no longer increase the force level any further due to mechanical limitations.
- Try decreasing the stiffness of the touch link to 150 N/m. How does this feel?
- Consider a hypothetical situation involving two springs with stiffness k N/m. If you connect the two springs in series, is the net stiffness 2k or 0.5k? What if you connect the two springs in parallel?
- When you are done with the patch, turn the motor amplifier board off again. (The motor can get hot if left on while exerting a force.)
Note: Systems with feedback can become unstable if the right conditions arise. This is why it is a good idea to turn off the motor amplifier board when you are not using the system. (Otherwise, consider what can happen with a public address system if you leave it alone and it starts to squeal/howl.)
- To use Synth-A-Modeler with the FireFader, we actually have to have exactly two audioouts and two ports (the ones that look like hands). This is because we have stereo audio out, and some FireFaders have a second motorized fader connected. Because of this, the model MDL file in Synth-A-Modeler actually looks like the following:
In this case, we are not interested in listening to the sound of a touch link hitting ground (rather boring), so the audioouts are disconnected. The second port is disconnected because we are not using it.
- Close any other open patches, and then open ~/hapticslab2012/datadir/puredatadir/pluck_a_mass_on_spring~-help.pd
- The model MDL file for this patch specifies a port connected by a pluck link to a virtual mass (shown in red), which is connected by a linear link to ground. One audioout is connected to the position of the mass so that we can hear it, and the other audioout is connected to pluck link, which could allow us to listen to the plucking force.
- What happens if you change the virtual "resonator" mass's value from 0.008kg (i.e. 8g) to 0.004kg (i.e. 4g)?
- What happens if you greatly increase the "resonator" damping, which is the variable name for the damping in the linear link?
- In the previous example, you discovered that you could not directly adjust the frequency of the mass-linear link oscillator.
- In this example, the oscillator is implemented using a resonator object, which looks like a purple tuning fork within a circle.
- Try out this patch. If you hear some distortion, reduce the output volume a little bit.
- Why does the pitch increase when you touch the virtual mass?
- What happens if you make the resonator mass much larger?
- Can you guess why is becomes hard to pluck the resonator when you instead make the mass very small?
- Try interacting with the plucked string model.
- Adjust the pitches of the strings using the "waveguide frequency scaler" sliders.
- Try playing the strings with the haptic feedback disabled. Can you play them as accurately?
- If you would like to learn more about physical modeling then take Julius Smith's course Music 420 in the winter quarter. For some specific information about this particular physical modeling method, see this brief tutorial.
- Very roughly speaking, the following model describes a kind of virtual snare drum. The membrane is modeled by a 3x3 grid of points, the corners of which are grounds, and the the remaining points of which are masses, drawn in red. Three of the membrane masses have snare masses that bounce above them -- they are connected by touch links. The FireFader knob is connected by a linear link to a virtual mass, which represents a virtual drumstick. This in turn is connected by a touch link to the center membrane mass from underneath the membrane.
- First explore the timbre of the model with the power to the motor amplifier board turned off. Try the different preset-numbers to find a timbre that you like. The only differences in between the timbres is that the parameters of the membrane and snare masses.
- One of the linear links in the figure above is highlighted in red. It connects the haptic device port to the second port. A target from pd will be fed into the second port, which will be used to pull the haptic device back and forth.
- Now hold onto the FireFader while you turn on the motor amplifier board with the other hand. (Be careful because this patch is especially likely to become unstable! If the FireFader should become unstable, turn off the motor amplifier board again.)
- First adjust the center position of the robot oscillation back and forth using the hslider.
- To feel the virtual "robot" shake the FireFader back and forth, increaes the number box connected to the osc~ object. For instance, try 0.5 times per second or 3 times per second.
Try out guiro~.pd to see if you like it. You can see the MDL file by opening it using the Synth-A-ModelerGUI program. To do so, first change to the hapticslab2012 directory
and then type
For instance, you might want to retune the guiro. To do this, you can
- first close guiro~.pd in Pure Data.
- go to File | Open and navigate to guiro.mdl, which is inside datadir.
- double-click on each resonator you want to edit. In the window that pops up, enter the desired resonance frequency in Hz.
- Save the model.
- Make sure that puredata makefile is selected in the Generate menu.
- Then select Binary from the Generate menu.
- Wait about one minute. Once it finishes compiling, you should see a message in the Output window.
- Restart pd and load guiro~.pd again. (Note -- if you forget to restart pd, it will not implement the changes you made.)
Build Your Own
Make your very own musical controller using the FireFader and one of the above patches as a starting point. Here are some ideas, but feel free to follow your own interests:
- Make a record scratching interface allowing you to feel the record.
- Or try to impart kinetic energy from your body into a physical model of an instrument.
- Or can you program the haptic interface so that it allows you to feel a texture?
- Or use the same physical model to calculate both the haptic force feedback and the audio feedback. For instance, you could create multiple virtual objects that you can pluck by giving them different mechanical ground positions.
Make us proud. Post the video of your controller at Music 250a Lab Video Wiki. And be ready show off your controller at the next lab session!
This lab was inspired by an older lab exercise for this class by Bill Verplank as well as work done at Claude Cadoz's laboratory.