Commit cd5086cc authored by jp7g21's avatar jp7g21
Browse files

stuff

parent 7713ca81
...@@ -5,9 +5,9 @@ res=$? ...@@ -5,9 +5,9 @@ res=$?
if [ $res != 0 ] if [ $res != 0 ]
then then
/usr/lib/duck/duck headshake 3 /usr/lib/duck/duck headshake 4
else else
/usr/lib/duck/duck nod 1 /usr/lib/duck/duck nod 2
fi fi
exit $res exit $res
......
...@@ -27,17 +27,22 @@ void shake(int motor, int number, int min, int max, int delay) ...@@ -27,17 +27,22 @@ void shake(int motor, int number, int min, int max, int delay)
duck_delay(delay2); duck_delay(delay2);
} }
int read_mode = 0;
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int option; int option;
const char *fname = DEFAULT_DUCK_FNAME; const char *fname = DEFAULT_DUCK_FNAME;
char buf[100]; char buf[100];
while ((option=getopt(argc, argv, "t:d")) != -1) { while ((option=getopt(argc, argv, "+t:dr")) != -1) {
switch (option) { switch (option) {
case 'd': case 'd':
duck_debug_mode = 1; duck_debug_mode = 1;
break; break;
case 'r':
read_mode = 1;
break;
case 't': case 't':
strncpy(buf, optarg, 100); strncpy(buf, optarg, 100);
fname = buf; fname = buf;
...@@ -61,11 +66,12 @@ int main(int argc, char **argv) ...@@ -61,11 +66,12 @@ int main(int argc, char **argv)
i += 2; i += 2;
} }
} else if (strcmp(argv[i], "vel") == 0) { } else if (strcmp(argv[i], "vel") == 0) {
if (argv[i+1] && argv[i+2]) { if (argv[i+1] && argv[i+2] && argv[i+3]) {
int motor = atoi(argv[i+1]); int motor = atoi(argv[i+1]);
int deg_per_sec = atoi(argv[i+2]); int deg_per_sec = atoi(argv[i+2]);
duck_set_velocity(motor, deg_per_sec); int ms = atoi(argv[i+3]);
i += 2; duck_set_velocity(motor, deg_per_sec, ms);
i += 3;
} }
} else if (strcmp(argv[i], "headshake") == 0) { } else if (strcmp(argv[i], "headshake") == 0) {
if (argv[i+1]) { if (argv[i+1]) {
...@@ -87,6 +93,11 @@ int main(int argc, char **argv) ...@@ -87,6 +93,11 @@ int main(int argc, char **argv)
} }
} }
} }
if (read_mode) {
while (1) {
char c;
if (read(duckfd, &c, 1) != 1) err(
close_duck();
return 0; return 0;
} }
...@@ -80,11 +80,12 @@ int duck_delay(int ms) ...@@ -80,11 +80,12 @@ int duck_delay(int ms)
return duck_printf("d %d\n", ms); return duck_printf("d %d\n", ms);
} }
int duck_set_velocity(int motor, int deg_per_sec) /* Final position will be (deg_per_sec * ms / 1000), rounded down to nearest degree */
int duck_set_velocity(int motor, int deg_per_sec, int ms)
{ {
if (!validate_motor(motor)) return -1; if (!validate_motor(motor)) return -1;
if (abs(deg_per_sec) > 1000) return -1; if (abs(deg_per_sec) > 1000) return -1;
return duck_printf("v %d %d\n", motor, deg_per_sec); return duck_printf("v %d %d %d\n", motor, deg_per_sec, ms);
} }
void close_duck(void) void close_duck(void)
......
...@@ -15,7 +15,7 @@ void open_duck(const char *fname); ...@@ -15,7 +15,7 @@ void open_duck(const char *fname);
void configure_duck(void); void configure_duck(void);
int duck_set_position(int motor, int angle); int duck_set_position(int motor, int angle);
int duck_delay(int ms); int duck_delay(int ms);
int duck_set_velocity(int motor, int deg_per_sec); int duck_set_velocity(int motor, int deg_per_sec, int ms);
void close_duck(void); void close_duck(void);
#endif /* _LIBDUCK_H */ #endif /* _LIBDUCK_H */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment