diff --git a/SerialInterface.cpp b/SerialInterface.cpp index 427c184812..3d95fbbc16 100644 --- a/SerialInterface.cpp +++ b/SerialInterface.cpp @@ -72,14 +72,15 @@ int read_sensors(int first_measurement, float * avg_adc_channels, int * adc_chan // At end - Extract value from string to variables if (serial_buffer[0] != 'p') { - sscanf(serial_buffer, "%d %d %d %d %d %d %d", + sscanf(serial_buffer, "%d %d %d %d %d %d %d %d", /* Needs to match Num Channels */ &adc_channels[0], &adc_channels[1], &adc_channels[2], &adc_channels[3], &adc_channels[4], &adc_channels[5], - &adc_channels[6]); + &adc_channels[6], + &adc_channels[7]); for (int i = 0; i < NUM_CHANNELS; i++) { if (!first_measurement) diff --git a/SerialInterface.h b/SerialInterface.h index 87e51d9cb5..e2bb82fde1 100644 --- a/SerialInterface.h +++ b/SerialInterface.h @@ -9,7 +9,7 @@ int init_port (int baud); int read_sensors(int first_measurement, float * avg_adc_channels, int * adc_channels); -#define NUM_CHANNELS 7 +#define NUM_CHANNELS 8 #define SERIAL_PORT_NAME "/dev/tty.usbmodem411" #endif diff --git a/audio.cpp b/audio.cpp index 13f6d54ec9..5e8e57ff88 100644 --- a/audio.cpp +++ b/audio.cpp @@ -149,7 +149,7 @@ bool Audio::init() 2, // output channels paFloat32, // sample format 44100, // sample rate (hz) - 256, // frames per buffer + 512, // frames per buffer audioCallback, // callback function (void*)data); // user data to be passed to callback if (err != paNoError) goto error; diff --git a/hardware/head_hand/head_hand.pde b/hardware/head_hand/head_hand.pde index 3719d5ba45..7e4bb60955 100644 --- a/hardware/head_hand/head_hand.pde +++ b/hardware/head_hand/head_hand.pde @@ -2,11 +2,19 @@ Read a set of analog input lines and echo their readings over the serial port with averaging */ +// ADC PIN MAPPINGS +// +// 0, 1 = Head Pitch, Yaw gyro +// 2,3,4 = Head Accelerometer +// 10,11,12 = Hand Accelerometer + #define NUM_CHANNELS 8 #define AVERAGE_COUNT 100 +#define TOGGLE_LED_SAMPLES 1000 int inputPins[NUM_CHANNELS] = {0,1,2,3,4,10,11,12}; + int measured[NUM_CHANNELS]; float accumulate[NUM_CHANNELS]; @@ -28,7 +36,7 @@ void loop() int i; sampleCount++; for (i = 0; i < NUM_CHANNELS; i++) { - if (sampleCount % NUM_SAMPLES == 0) { + if (sampleCount % AVERAGE_COUNT == 0) { measured[i] = accumulate[i] / AVERAGE_COUNT; SerialUSB.print(measured[i]); SerialUSB.print(" "); @@ -37,7 +45,8 @@ void loop() accumulate[i] += analogRead(inputPins[i]); } } - if (sampleCount % NUM_SAMPLES == 0) SerialUSB.println(""); + if (sampleCount % AVERAGE_COUNT == 0) SerialUSB.println(""); + if (sampleCount % TOGGLE_LED_SAMPLES == 0) toggleLED(); } diff --git a/interface.xcodeproj/project.xcworkspace/xcuserdata/philip.xcuserdatad/UserInterfaceState.xcuserstate b/interface.xcodeproj/project.xcworkspace/xcuserdata/philip.xcuserdatad/UserInterfaceState.xcuserstate index 8cfc080bbe..9a297636f2 100644 Binary files a/interface.xcodeproj/project.xcworkspace/xcuserdata/philip.xcuserdatad/UserInterfaceState.xcuserstate and b/interface.xcodeproj/project.xcworkspace/xcuserdata/philip.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/main.cpp b/main.cpp index abdb8e5bc8..5aa33a44ab 100644 --- a/main.cpp +++ b/main.cpp @@ -469,13 +469,14 @@ void update_pos(float frametime) // Update hand/manipulator location for measured forces from serial channel const float MIN_HAND_ACCEL = 30.0; - glm::vec3 hand_accel(avg_adc_channels[4] - adc_channels[4], - avg_adc_channels[5] - adc_channels[5], - avg_adc_channels[6] - adc_channels[6]); + const float HAND_FORCE_SCALE = 0.5; + glm::vec3 hand_accel(-(avg_adc_channels[6] - adc_channels[6]), + -(avg_adc_channels[7] - adc_channels[7]), + -(avg_adc_channels[5] - adc_channels[5])); if (glm::length(hand_accel) > MIN_HAND_ACCEL) { - myHand.addVel(hand_accel*frametime); + myHand.addVel(frametime*hand_accel*HAND_FORCE_SCALE); } // Update render direction (pitch/yaw) based on measured gyro rates