]> git.droids-corp.org - aversive.git/blobdiff - projects/microb2010/tests/hostsim/robotsim.c
work on hostsim
[aversive.git] / projects / microb2010 / tests / hostsim / robotsim.c
index 6f4dbbfa405615c789439614e20a73b9d31e5a36..9303a85444110ed8e1275171d14f71a5ece3ac18 100644 (file)
 #include <stdio.h>
 #include <string.h>
 #include <stdint.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.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 +68,20 @@ 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));
+       hostsim_lock();
+       write(fd, buf, len);
+       hostsim_unlock();
+}
+
 void robotsim_pwm(void *arg, int32_t val)
 {
        //      printf("%p, %d\n", arg, val);
@@ -79,3 +99,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;
+}