Latest work

This commit is contained in:
Philip Rosedale 2012-11-02 16:49:08 -07:00
parent 181a0b8afc
commit cabcbbc0d2
6 changed files with 21 additions and 10 deletions

View file

@ -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)

View file

@ -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

View file

@ -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;

View file

@ -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();
}

View file

@ -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