Tuesday, October 20, 2009

Lab 4 - Our process, in detail

Method
In the previous lab, we were using a Hall-effect sensor to measure the position of the pendulum. The sensor produced voltage in the range of 2.0V to 3.0 V, which is read by the Arduino's analog reading as a value between 495 and 540. With this range, the position only has 45 data points and this resolution is not sufficient to reproduce a good virtual spring and damping. When we use the sensor readings to determine the speed of the pendulum, it often takes into account the random noise from the Hall-effect sensor and since the resolution was poor, the PWM output tended to be large. This resulted in a lot of stability problem in our control.

In this lab, we used OP Amp to amplify the voltage range so that the output voltage came in the voltage range of 0V to 5.0V, which enabled us to use the full extent of the Arduino's analog input range. Below is the circuit diagram of the OP Amp we used in this lab.

We set the positive terminal to be 2.5V so that the neutral position of the output voltage from the OP Amp to be 2.5V. We choose this value to match the middle output of the Hall-effect sensor. The resistors in the negative terminal are used to amplify the ±0.5V voltage range from the Hall-effect into ±2.5V so that the voltage output range from the OP Amp has a range of 2.5V ±2.5V or 0V to 5V. Since this is an inverting OP Amp, the gain is reversed so that 2.5V±0.5V range translated into 2.5V±(-2.5V) range for the output from the OP Amp.

Theoretically, we should get this range of 0V to 5.0V, but the middle point of the Hall-effect sensor turned out to be not exactly on 2.5V, so the actual output voltage range from the OP Amp came out to be between 0V and 4.0V. This is still a huge increase in voltage range, and the analog reading from the Arduino read values between 0 and 827. The new range has more than 800 data points, which is approximately 20 times as large as the original.

With the new resolution, we can try the previous lab's code to test the virtual spring and damping and see if there is any improvement in the controls.





With the new resolution from the OP Amp, we edited the previous lab's code to adjust with the new analog reading values. We decided to try the proportional control first. With the new resolution, the movement of the pendulum looked more fluid compared to the old resolution and the motion is more "spring-like". However, there are still some noises inside the reading of roughly ±30 data points, which is large because it is also got amplified by the OP Amp. When we moved into the derivative control, there was no significant improvement compared to the previous lab's. Large noises still present and instability still occurred.

You can see the proportional and derivative control at work in the video below.



Once we accomplished this, we moved to programming the Arduino to send amplified analog data from the hall effect sensor to the PD interface. We downloaded Arduino2PD patches available on programmer websites, and altered them to meet our needs, as there were no functions dedicated to actually playing the notes in the original patches.

Results
PD programming: We ended up with the program below (Note the change in port number and speed ("comport 19 38400") and the addition of five function blocks to play a note).

The first five analog in number boxes do not apply here. They would only apply if we were using multiple sensors with analog outputs. The number that we want to pay attention to is the analog in 5 number, which is the exact number that the hall effect sensor would have returned even if placed in circuit with solely the Arduino.

Discussion
Virtual environment testing: OP amp does help by increasing the resolution of the output, but does not help with reducing the noise, which was the major problem for the derivative control.

PD programming: We subtracted 500 and multiplied the result by 1.5 so that we could (a) only play notes if the armature was displaced from equilibrium and (b) get the largest range possible. If we multiplied by more than 1.5, the range would be the same but within a smaller domain. If we multiplied by less than 1.5, on the other hand, the range would not reach the highest note possible, even when armature was fully displaced. The value of 1.5 gave us the optimal performance for our set-up.

After that was completed, it was easy for us to integrate the virtual spring with tuned values from the first part of this lab. As previously mentioned in the "Accomplishments" section of the last blog post, we ended up with an instrument that played higher notes and gave higher feedback forces as the armature's displacement from center increased.

No comments:

Post a Comment