Animatronics playback

Ask - Discuss - Share everything about your code in embedded for your projects. Processing, Embedded C, Fritzing...
sunilvallu
Posts: 3
Joined: Thu Oct 25, 2012 10:39 am

Animatronics playback

Postby sunilvallu » Thu Oct 25, 2012 12:56 pm

Hi,

I'm a designer working in the area of new media and interaction design. I'm currently working on a project which involves animatronics activated/deactivated by a sensor input (in this case sound within a proximity limit). The challenges that im currently facing could be separated into 2 sections for ease,
1. datalogging + Servo, 2. Sensor input (sound)

1. DATALOGGING + SERVO
The idea is to enact various movements wearing nunchuck or wii remote (preferable) over a head. In precise, simulating movements of a human neck. The data is captured using a program called 'coolTerm' in the form of a 'txt' file. Now there are various compositions of such movements stored in the form of txt files in an sd card. each txt file contains values of acceleration in both x and y. These files are called on a random function and combined to form a continuous unique motion. In the case of wii I have decimal values between 0 and 1 (example: 23:14:39.509377,0.333333,-0.370370,-1.021739). In the case of nunchuck to arduino by using a library called ArduinoNunchuck by GabrielBianconi gave me values integers between 250 and 700 instead of 0 and 1024. These vales are still usable to run servos when compared to wii values which are killing the servos. I would like to know if there is a way that I can run these servos from the acceleration data.

2. SENSOR
Now the second part is that I need to detect sound caused by human interaction within a limited area. One could use various sensors like ultra sonic ranger finder or proximity, but the idea is that the object is blind and can only hear. So sound become the only input. For this I have been tinkering with electret microphone manufactured by sparfun https://www.sparkfun.com/products/9964 but it is neither stable enough in the first place in performance nor it can detect with in a proximity. Also it restricts to a very limited frequency of sound and responds only for harsh vibrations and cannot really identify human vocal sound. It is also hugely affected by fan and other wind sources near by. Also this object will be placed in a booth at a large exhibition hall where there is a great amount disturbance and noise. Is there a solution for getting this right?

To sum up, the object is like a robot but in an abstract form. Also it is a blind robot. The robot is continuously acting (moving its head) until it is interrupted by human presence or any sudden sudden sound.


Thanks
Sunil
abhimanyu
Posts: 94
Joined: Tue Oct 18, 2011 9:49 pm

Re: Animatronics playback

Postby abhimanyu » Thu Oct 25, 2012 6:20 pm

Cool Project.
ArduinoNunchuck by GabrielBianconi gave me values integers between 250 and 700 instead of 0 and 1024

1.) Servo - You may want to calibrate the values first to find the minimum and maximum values of the acceleration sensor rather than fixing these as Constants. It can be done using the following code: (Similar code was implemented here to calculate maximum and minimum values from a Joystick)

Code: Select all

int sensorValue = 0;
int sensorMax = 0;
int sensorMin = 1500;

while (millis() < 5000)            // Wait for 5 seconds
    {
      sensorValue = analogRead(A0);        //      Nintendo Wii's Acceleration Values
      if (sensorValue > sensorMax)              //     record the maximum sensor value
      {
        sensorMax = sensorValue;
      }
      if (sensorValue < sensorMin)                //    record the minimum sensor value
      {
        sensorMin = sensorValue;
      }
    }

Put this code in the void setup() function of your Arduino. As soon as the Robot is powered On and the Code starts running, the first five seconds will be dedicated to calibration. By moving your Nintendo sensor(s) back and forth, tilting, etc. to their full extent, you will be calibrating it and the sensorMin and sensorMax variables will contain the minimum and maximum values of your Nintendo Wii/ Chuck accelerometer sensor.

After Calibration, you may map these values from 0 to 180 degrees for Servo rather than some arbitrary number:

Code: Select all

Servo_Input = map(sensorValue, sensorMin, sensorMax, 0, 180);   // The full range of Accelerometer's values will be converted to 0-180 degree range

Then see, if the servos are easily getting controlled or still facing jitter.

2.)
Is there a solution for getting this right?

Sound detection becomes easy when you have multiple Microphones (even the Electret ones from SparkFun will work). It helps in Noise Cancellation and may help to locate the source by comparison.
See this project: DIY Sound Localization Sensor
Some more resources: link and another link.
sunilvallu
Posts: 3
Joined: Thu Oct 25, 2012 10:39 am

Re: Animatronics playback

Postby sunilvallu » Fri Oct 26, 2012 9:46 am

Thanks for the quick revert Abhimanyu!

1.) Servo - You may want to calibrate the values first to find the minimum and maximum values of the acceleration sensor rather than fixing these as Constants.


Funnily enough, I had tried both the possibilities of calibrating and then mapping. but in the case of the electret microphone to detect the base value of the room. Strangely it didnt seem to work. The idea was to calibrate my sensor every time I switch the device on. will comeback on this topic in the later section. Sorry, Also to avoid confusion in beginning, I havent really explained the entire problem.

Now my problem is that these values are not realtime. They are being retrieved from a text file (Quoted below). I havent really tried to calibrate in this part though. As I was facing some strange issues with the SD part. I loaded a txt file (with comma separated values) into the SD card of an ethernet shield. Also was able retrive these values individually at the same time. But strangely when I connect my mini servo the values (from the txt file) on the serial monitor start throwing zeros instead of the actual values. sometimes if not immediately, but later in few seconds or so it would throw only zeros and would never retrive actual values even after pressing the rest button on the arduino. It would only work when unplugged and re-plugged but again only for few seconds. Also these values are being captured by a program called coolTerm from the serialport. All said, these values are from nunchuck which are easy to use as they are all in integers, but I prefer using wiimote (only because it is wireless) values captured by another program called OSCulator. Like I mentioned earlier that I wasn't really be able to use these values (Quoted below) as they were all in decimals between 0 and 1. Also they wii seem to throw a lot more values at a very short interval. Weather the values are from nunchuk or wii, at the end it is just a txt file in an SD card. so core the problem still remains. To keep it simple, I think I would like to solve it step by step, so could we look at the sensor input later? Also the aesthetics really rely on the animatronics of the object. So I am really worried in getting this sorted. I hope it isnt getting complex and confusing. Also could we connect over phone sometime, so I could explain it better.


Below is the current Code for retrieving data from SD and playing a servo

#include <SD.h>

// On the Ethernet Shield, CS is pin 4. Note that even if it's not
// used as the CS pin, the hardware CS pin (10 on most Arduino boards,
// 53 on the Mega) must be left as an output or the SD library
// functions will not work.
const int chipSelect = 4;


const int NUMBER_OF_FIELDS = 4; // how many comma-separated fields we expect
int fieldIndex = 0; // the current field being received
int values[NUMBER_OF_FIELDS]; // array holding values for all the fields


#include <Servo.h>
Servo myservo; // create servo object to control a servo

void setup()
{
Serial.begin(9600);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
Serial.print("Initializing SD card...");
// make sure that the default chip select pin is set to
// output, even if you don't use it:
pinMode(10, OUTPUT);

// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");

}

void loop()
{

// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("datalog.txt");

if(dataFile) {
while (dataFile.available()) {
for(fieldIndex = 0; fieldIndex < 4; fieldIndex ++)
{
values[fieldIndex] = dataFile.parseInt(); // get a numeric value
}
// Serial.print( fieldIndex);
// Serial.println(" fields received:");

// for(int i=0; i < fieldIndex; i++)
// {
// Serial.println(values[i]);
// }

int xval = map(values[3],200,700,0,179);
myservo.write(xval); // sets the servo position according to the scaled value
delay(15);
Serial.println(values[3]);
fieldIndex = 0; // ready to start over

}
dataFile.close();
}
}




NUNCHUCK (DATA FROM THE TEXT FILE)

123,132,679,574
123,132,679,574
123,132,677,574
123,132,679,574
123,132,677,574


WII (DATA FROM THE TEXT FILE)

time,AccX,AccY,AccZ
23:14:39.509377,0.333333,-0.370370,-1.021739
23:14:39.509571,0.296296,-0.333333,-0.956522
23:14:39.509618,0.277778,-0.314815,-0.956522
23:14:39.509677,0.277778,-0.314815,-1.000000
23:14:39.509727,0.277778,-0.314815,-1.043478



Thanks
Sunil
abhimanyu
Posts: 94
Joined: Tue Oct 18, 2011 9:49 pm

Re: Animatronics playback

Postby abhimanyu » Fri Oct 26, 2012 1:19 pm

If the values are not realtime, then are you using the Wii controller for just recording the values at a prior time?
Calibration is not needed in case of Pre-recorded values.
But strangely when I connect my mini servo the values (from the txt file) on the serial monitor start throwing zeros

Have you tied the grounds of Arduino and Servo Motor together? Also, check for loose connections.

Code: Select all

int xval = map(values[3],200,700,0,179);

Do you only need the xval variable? Since you are mapping only the last value of the values array.
sunilvallu
Posts: 3
Joined: Thu Oct 25, 2012 10:39 am

Re: Animatronics playback

Postby sunilvallu » Sat Oct 27, 2012 1:52 pm

If the values are not realtime, then are you using the Wii controller for just recording the values at a prior time?


Yes the values are pre-recorded from nunchuck as of now, but would prefer to use wii finally.

Have you tied the grounds of Arduino and Servo Motor together? Also, check for loose connections.


As of now, I am only using one servo for testing purposes. The servo yellow wire is connected to the digital pin 9, black wire to arduino GND and red to Arduino +5v. Also I was using the mini/micro servo. When I tested the servo with +3v on Arduino, the serial monitor works fine, but the servo seem to run in a random motion. but it doesnt really seem to be in sync with the values on the serial monitor. it looks as if it is movingly randomly but in loop.

Do you only need the xval variable? Since you are mapping only the last value of the values array.


No I will need all the three axis, but for testing purposes I was using only 1 axis at that moment. In fact, I had to compromise on the third axis (YAW) purely for the limitations of wii (classic) and nunchuck.

Return to “Code”

Who is online

Users browsing this forum: No registered users and 1 guest