robotsim first test
[aversive.git] / projects / microb2010 / tests / hostsim / robotsim.c
index 6f4dbbf..7ed49f4 100644 (file)
@@ -22,6 +22,9 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdint.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 
 #include <aversive.h>
 #include <aversive/error.h>
 static int32_t l_pwm, r_pwm;
 static int32_t l_enc, r_enc;
 
+static int fd;
+
 /* */
-#define FILTER  98
+#define FILTER  97
 #define FILTER2 (100-FILTER)
 
 /* must be called periodically */
@@ -62,6 +67,18 @@ void robotsim_update(void)
        r_enc += (r_speed / 1000);
 }
 
+void robotsim_dump(void)
+{
+       char buf[BUFSIZ];
+       int len;
+
+       len =snprintf(buf, sizeof(buf), "%d %d %d\n",
+                     position_get_x_s16(&mainboard.pos),
+                     position_get_y_s16(&mainboard.pos),
+                     position_get_a_deg_s16(&mainboard.pos));
+       write(fd, buf, len);
+}
+
 void robotsim_pwm(void *arg, int32_t val)
 {
        //      printf("%p, %d\n", arg, val);
@@ -79,3 +96,12 @@ int32_t robotsim_encoder_get(void *arg)
                return r_enc;
        return 0;
 }
+
+int robotsim_init(void)
+{
+       mkfifo("/tmp/.robot", 0600);
+       fd = open("/tmp/.robot", O_WRONLY, 0);
+       if (fd < 0)
+               return -1;
+       return 0;
+}