freeruner logo Zkoušel jsem si zase hrát s akcelerometrama na openmoku a tohle je výsledek.

#include <linux/input.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
//#define EVENT_PATH "/dev/input/event2"
#define EVENT_PATH "/dev/input/event3"
#define EVENT_SLEEP 50000
#define LOG_NAME "accel-dump.log"
#define BUFSIZE 8
#define MAX(a, b)           (((a) > (b)) ? (a) : (b))
#define DEBUG 0int counter = 0;

void process_packet (FILE *eventfp) {
struct input_event buffer[BUFSIZE];
int x, y, z, maxVal;
maxVal = x = y = z = 0;
if (fread(buffer, sizeof (struct input_event), BUFSIZE, eventfp) != BUFSIZE) {
  fprintf(stderr, "fread() failedn");
  exit(1);
}

for (int i = 0; i < BUFSIZE; i++) {
  if (buffer[i].type == EV_REL) {
  switch(buffer[i].code) {
  case REL_X: x = buffer[i].value;break;
  case REL_Y: y = buffer[i].value;break;
  case REL_Z: z = buffer[i].value;break;
}

maxVal = MAX(buffer[i].value, maxVal);
maxVal = MAX(-buffer[i].value, maxVal);

}

}

FILE* fp = fopen(LOG_NAME, "a");
fprintf(fp, "%d %d %d %d %dn", counter++, x, y, z, maxVal);
fclose(fp);

}

int main (int argc, char *argv[]) {
FILE *eventfp;
eventfp = fopen(EVENT_PATH, "rb");
if (eventfp == NULL) {
fprintf(stderr, "Couldn't open file.n");
exit(1);
}

for (;;) {
process_packet(eventfp);
usleep(EVENT_SLEEP);
}
}

gnuplot

x = x + 1
plot "/mnt/moko/home/root/accel-dump.log" using 1:2 with lines title "x", "/mnt/moko/home/root/accel-dump.log" using 1:3 with lines title "y", "/mnt/moko/home/root/accel-dump.log" using 1:4 with lines title "z"
if(x<1000) reread

připojení openmoka přes sshfs

sudo sshfs root@moko:/ /mnt/moko/ -o allow_other

a nakonec se to spustilo na telefonu

./accel-dump

na desktopu

x=0; load "accel-dump.gnuplot"


http://www.stud.fit.vutbr.cz/~xmlich02/openmoko/accel-dump.avi (5mb)
http://www.stud.fit.vutbr.cz/~xmlich02/openmoko/accel-dump2.avi (22mb)

Loading

By Jozef Mlích

Software Developer at GreyCortex, NemoMobile contributor, Micro light aircraft pilot, OpenAlt Conference organizer

6 thoughts on “Akcelerometry v openmoku”
  1. (2) daval jsem to na youtube vcera vecer a doufal jsem, ze do rana to bude zpracovane. dal jsem tam link primo na to to video. youtube suxx (-;

Comments are closed.