#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 */
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);
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;
+}