diff --git a/groundStation/Makefile b/groundStation/Makefile index b199aef1a4adda78d5c3b95b7355ab6667254efa..32c9062ef683a66deef45a0cf04334bf016d9e17 100644 --- a/groundStation/Makefile +++ b/groundStation/Makefile @@ -23,7 +23,7 @@ CLIBINARY=Cli CLISRCDIR=src/cli CLISOURCES := $(wildcard $(CLISRCDIR)/*.c) CLIOBJECTS = $(CLISOURCES:$(CLISRCDIR)/%.c=$(OBJDIR)/%.o) -SYMLINKS=monitor setpid getpid +SYMLINKS=monitor setpid getpid setsetpoint # Frontend-common stuff FESRCDIR=src/frontend diff --git a/groundStation/src/cli/cli.h b/groundStation/src/cli/cli.h index 924b33fe1a1b1d8c871d6ed679ec58f131181091..1d0cf6951488872906ac99447fda3b7b5e9e5b7c 100644 --- a/groundStation/src/cli/cli.h +++ b/groundStation/src/cli/cli.h @@ -1,6 +1,7 @@ #ifndef __CLI_H #define __CLI_H +#include "cli_setsetpoint.h" #include "cli_monitor.h" #include "cli_setpid.h" #include "cli_getpid.h" @@ -11,6 +12,7 @@ enum CommandNameIds{ CMD_GETPID, CMD_SETPID, CMD_GETIMU, + CMD_SETSETPOINT, MAX_COMMANDS }; @@ -19,13 +21,16 @@ static cli_function_ptr cli_functions[] = { &cli_monitor, &cli_getpid, &cli_setpid, - &cli_getimu + &cli_getimu, + &cli_setsetpoint }; static char* commandNames[MAX_COMMANDS] = { "monitor", "getpid", "setpid", - "getimu" + "getimu", + "setsetpoint" }; + #endif diff --git a/groundStation/src/cli/cli_setpid.h b/groundStation/src/cli/cli_setpid.h index 87fb0a4f40e91ed704972bd17e4859991d91641b..2ebdc9545e38f9f3d3697b02b22b8b1be2ef324e 100644 --- a/groundStation/src/cli/cli_setpid.h +++ b/groundStation/src/cli/cli_setpid.h @@ -1,5 +1,5 @@ -#ifndef _CLI_SETPID_H -#define _CLI_SETPID_H +#ifndef CLI_SETPID_H +#define CLI_SETPID_H #include "frontend_setpid.h" diff --git a/groundStation/src/cli/cli_setsetpoint.c b/groundStation/src/cli/cli_setsetpoint.c new file mode 100644 index 0000000000000000000000000000000000000000..85cd86d164712e0a83ef7bdc64bd1b50a0ffeee3 --- /dev/null +++ b/groundStation/src/cli/cli_setsetpoint.c @@ -0,0 +1,66 @@ +#include <stdio.h> +#include <unistd.h> +#include <getopt.h> + +#include "cli_setsetpoint.h" + +int cli_set(struct backend_conn * conn, int argc, char **argv) { + int c; + static int setX = 0, setY = 0, setZ = 0; + struct frontend_setpoint_data setpoint_data; + static int needHelp = 0; + static int mask; + static struct option long_options[] = { + /* These options don’t set a flag. We distinguish them by their indices. */ + {"help", no_argument, &needHelp, 1}, + {0, 0, 0, 0} + }; + + while (1) + { + /* getopt_long stores the option index here. */ + int option_index = 0; + + c = getopt_long(argc, argv, "x:y:z:", long_options, &option_index); + + /* Detect the end of the options. */ + if (c == -1) + break; + + switch(c) { + case 'x' : + setpoint_data.x = atof(optarg); + mask |= SET_X; + break; + case 'y' : + setpoint_data.y = atof(optarg); + mask |= SET_Y; + break; + case 'z' : + setpoint_data.z = atof(optarg); + mask |= SET_Z; + break; + default : + break; + } + } + + if (needHelp) { + printf("Setsetpoint sets the x, y , or z set point values for the quad.\n"); + printf("Usage Syntax : \n\t./Cli setsetpoint [options...]\n"); + printf("Symlink Usage Syntax : \n\t./setsetpoint [options...]\n\n"); + printf("Available options include the following\n"); + printf("\t[-x] 'val' : Sets the x setpoint value to 'val'\n"); + printf("\t[-z] 'val' : Sets the y setpoint value to 'val'\n"); + printf("\t[-z] 'val' : Sets the z setpoint value to 'val'\n"); + return 0; + } + + if (argc < 2) { + printf("Incorrect Usage, run './cli setpid --help' for correct usage.\n"); + return 1; + } + + frontend_setsetpoint(conn, &setpoint_data, mask); + return 0; +} diff --git a/groundStation/src/cli/cli_setsetpoint.h b/groundStation/src/cli/cli_setsetpoint.h new file mode 100644 index 0000000000000000000000000000000000000000..8f2657963222181f4fcf7e20fae9242d84b37b95 --- /dev/null +++ b/groundStation/src/cli/cli_setsetpoint.h @@ -0,0 +1,8 @@ +#ifndef CLI_SETSETPOINT_H +#define CLI_SETSETPOINT_H + +#include "frontend_setsetpoint.h" + +int cli_setsetpoint(struct backend_conn * conn, int argc, char ** argv); + +#endif /* CLI_SETSETPOINT_H */ diff --git a/groundStation/src/frontend/frontend_setpid.h b/groundStation/src/frontend/frontend_setpid.h index f1deb5d3d91568939d5bd44ffab07f082a290233..bd53cd4535e4aa5834e2841879fdf4dd6bdb014c 100644 --- a/groundStation/src/frontend/frontend_setpid.h +++ b/groundStation/src/frontend/frontend_setpid.h @@ -1,5 +1,5 @@ -#ifndef _FRONTEND_SETPID_H -#define _FRONTEND_SETPID_H +#ifndef FRONTEND_SETPID_H +#define FRONTEND_SETPID_H #include "pid_common.h" #include "frontend_common.h" @@ -12,6 +12,9 @@ int frontend_setpid( #define SET_P 0x01 #define SET_I 0x02 #define SET_D 0x04 + +#ifndef SET_ALL #define SET_ALL (SET_P | SET_I | SET_D) +#endif /* SET_ALL */ -#endif +#endif /* FRONTEND_SETPID_H */ \ No newline at end of file diff --git a/groundStation/src/frontend/frontend_setsetpoint.c b/groundStation/src/frontend/frontend_setsetpoint.c new file mode 100644 index 0000000000000000000000000000000000000000..f264479210dc801629bd27f14200a11709a38e1b --- /dev/null +++ b/groundStation/src/frontend/frontend_setsetpoint.c @@ -0,0 +1,45 @@ +#include <err.h> +#include <stdio.h> + +#include "frontend_setsetpoint.h" +#include "setpoint_common.h" +#include "frontend_common.h" + +int frontend_setsetpoint( + struct backend_conn * conn, + struct frontend_setpoint_data * setpoint_data, + int mask) +{ + if (conn == NULL) { + return -1; + } + + char buffer[2048]; + /* Set the P, I, and D */ + if (mask & SET_X) { + if (snprintf(buffer, 2048, + "setsetpointx %f\n", + setpoint_data->x) >= 2048) { + errx(0, "Buffer to small to format!"); + } + ucart_backendWrite(conn, buffer); + } + if (mask & SET_Y) { + if (snprintf(buffer, 2048, + "setsetpointy %f\n", + setpoint_data->y) >= 2048) { + errx(0, "Buffer to small to format!"); + } + ucart_backendWrite(conn, buffer); + } + if (mask & SET_Z) { + if (snprintf(buffer, 2048, + "setsetpointz %f\n", + setpoint_data->z) >= 2048) { + errx(0, "Buffer to small to format!"); + } + ucart_backendWrite(conn, buffer); + } + + return 0; +} diff --git a/groundStation/src/frontend/frontend_setsetpoint.h b/groundStation/src/frontend/frontend_setsetpoint.h new file mode 100644 index 0000000000000000000000000000000000000000..03806fdfe2bfb492a458475c36ffbb012586ebcd --- /dev/null +++ b/groundStation/src/frontend/frontend_setsetpoint.h @@ -0,0 +1,20 @@ +#ifndef FRONTEND_SETSETPOINT_H +#define FRONTEND_SETSETPOINT_H + +#include "setpoint_common.h" +#include "frontend_common.h" + +int frontend_setsetpoint( + struct backend_conn * conn, + struct frontend_setpoint_data * setpoint_data, + int mask); + +#define SET_X 0x01 +#define SET_Y 0x02 +#define SET_Z 0x04 + +#ifndef SET_ALL +#define SET_ALL (SET_X | SET_Y | SET_Z) +#endif /* SET_ALL */ + +#endif /* FRONTEND_SETSETPOINT_H */ \ No newline at end of file diff --git a/groundStation/src/frontend/setpoint_common.h b/groundStation/src/frontend/setpoint_common.h new file mode 100644 index 0000000000000000000000000000000000000000..25dc8c1ce8ee6ae76805ba10595c0e0139ea8a00 --- /dev/null +++ b/groundStation/src/frontend/setpoint_common.h @@ -0,0 +1,11 @@ +#ifndef SETPOINT_COMMON_H +#define SETPOINT_COMMON_H + +struct frontend_setpoint_data { + float x; + float y; + float z; +}; + + +#endif /* SETPOINT_COMMON_H */ \ No newline at end of file