diff --git a/groundStation/Makefile b/groundStation/Makefile index d5ecdc66bc451561e6e149c2479a4aadb00e437a..c3970786e8e22cf7f21643be048600d022e2ee61 100644 --- a/groundStation/Makefile +++ b/groundStation/Makefile @@ -7,7 +7,7 @@ CFLAGS= -Wall -pedantic -Wextra -Werror -std=gnu99 -g -Wno-unused-parameter -Wno CXXFLAGS= -Wall -pedantic -Wextra -Werror -Wno-reorder -Wno-unused-variable -std=c++0x -g INCLUDES = $(foreach dir, $(INCDIR), -I$(dir)) INCDIR= src/vrpn src/vrpn/quat src/vrpn/build $(BESRCDIR) $(CLISRCDIR) $(FESRCDIR) ../quad/inc -LIBS= -lpthread -lbluetooth -lvrpn -lquat -Lsrc/vrpn/build -Lsrc/vrpn/build/quat -L../quad/lib -lquad_app -lcommands -lgraph_blocks -lm -lcomputation_graph +LIBS= -lpthread -lbluetooth -lvrpn -lquat -Lsrc/vrpn/build -Lsrc/vrpn/build/quat -L../quad/lib -lquad_app -lcommands -lgraph_blocks -lcomputation_graph -lm OBJDIR=obj # Backend Specific Variables diff --git a/groundStation/scripts/bypass_kill_switch.sh b/groundStation/scripts/bypass_kill_switch.sh index b1061e271a8bef3effbc2a9e9f7f6acba81d4ab7..183df7b8e30d642e0bf92b8a0fbc7b1ef1949e7f 100755 --- a/groundStation/scripts/bypass_kill_switch.sh +++ b/groundStation/scripts/bypass_kill_switch.sh @@ -1,4 +1,9 @@ #! /bin/bash + +if [ -z "$1" ]; then + echo "No argument supplied" + exit 0 +fi cd .. while true ; do ./setparam 37 0 $1 diff --git a/groundStation/scripts/eric.sh b/groundStation/scripts/eric.sh index b84457723c09faed7f8854d47e156010357e7725..0fe0e845ee8d65a003c17b8e6b2aae40d1c1cd61 100755 --- a/groundStation/scripts/eric.sh +++ b/groundStation/scripts/eric.sh @@ -18,11 +18,11 @@ #outer loop ./setparam 'X pos PID' 'kp' -0.015 -./setparam 'X pos PID' 'ki' -0.0005 +./setparam 'X pos PID' 'ki' -0 ./setparam 'X pos PID' 'kd' -0.25 ./setparam 'X pos PID' 'alpha' 0.88 ./setparam 'Y pos PID' 'kp' 0.015 -./setparam 'Y pos PID' 'ki' 0.0005 +./setparam 'Y pos PID' 'ki' 0 ./setparam 'Y pos PID' 'kd' 0.25 ./setparam 'Y pos PID' 'alpha' 0.88 diff --git a/groundStation/src/backend/backend.c b/groundStation/src/backend/backend.c index 9ebf7752ba869da017f552a28efa43b5dd213a9b..d6b49449d6ca33b2a3727e06d0fdbccc2cfe5696 100644 --- a/groundStation/src/backend/backend.c +++ b/groundStation/src/backend/backend.c @@ -27,6 +27,8 @@ #include <sys/ioctl.h> #include <sys/types.h> #include <netinet/tcp.h> +#include <fcntl.h> +#include <sys/stat.h> //user created includes #include "commands.h" @@ -88,6 +90,9 @@ char * create_log_name(char * buffer, size_t max); pthread_mutex_t quadSocketMutex; static ssize_t writeQuad(const uint8_t * buf, size_t count); static ssize_t readQuad(char * buf, size_t count); +static int local_comm_channel; +static int zybo_fifo_rx; +static int zybo_fifo_tx; /* Functions for recording Latencies */ void findTimeDiff(int respID); @@ -120,6 +125,10 @@ pthread_mutex_t quadResponseMutex, cliInputMutex ; unsigned char *commandBuf; int newQuadResponse = 0, newCliInput = 0; +static void sig_handler(int s) { + printf("Caught SIGPIPE from quad fifo..\n"); +} + // Callback to be ran whenever the tracker receives data. // Currently doing much more than it should. It will be slimmed down // in the future. @@ -191,7 +200,13 @@ int main(int argc, char **argv) exit(1); } - printf("zyboSocket = %d\n", zyboSocket); + if (!local_comm_channel) { + printf("zyboSocket = %d\n", zyboSocket); + } else { + /* if we are using fifo's we don't want the quad to be able to shut us down. */ + signal(SIGPIPE, sig_handler); + printf("zybo_fifo_rx = %d\nzybo_fifo_tx = %d\n", zybo_fifo_rx, zybo_fifo_tx); + } if (pthread_mutex_unlock(&quadSocketMutex)) { err(-2, "pthrtead_mutex_unlock (%s:%d):", __FILE__, __LINE__); @@ -268,9 +283,18 @@ int main(int argc, char **argv) } } + ucart_vrpn_tracker_freeInstance(tracker); - safe_close_fd(zyboSocket, &quadSocketMutex); + + if (!local_comm_channel) { + safe_close_fd(zyboSocket, &quadSocketMutex); + } else { + safe_close_fd(zybo_fifo_rx, &quadSocketMutex); + safe_close_fd(zybo_fifo_tx, &quadSocketMutex); + } + fclose(quadlog_file); + return 0; } @@ -329,22 +353,33 @@ int connectToZybo() { if (getenv(QUAD_COMM_ENV)) { /* Determine if we are using bluetooth or local */ if(strcmp(getenv(QUAD_COMM_ENV), "local") == 0) { - printf("Using Local Socket Settings\n"); + printf("Using Local Fifo Settings\n"); + local_comm_channel = 1; + char * fifo_rx = QUAD_LOCAL_DEFAULT_TX; + char * fifo_tx = QUAD_LOCAL_DEFAULT_RX; - struct sockaddr_un remote; - char str[100]; - - if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { - perror("socket"); - exit(1); + if (getenv(QUAD_LOCAL_RX)) { + fifo_tx = getenv(QUAD_LOCAL_RX); + } + if (getenv(QUAD_LOCAL_TX)) { + fifo_rx = getenv(QUAD_LOCAL_TX); } - remote.sun_family = AF_UNIX; - char * sock_env = getenv(QUAD_LOCAL_SOCKET); - strcpy(remote.sun_path, sock_env ? sock_env : QUAD_DEFAULT_LOCAL_SOCKET); - printf("Attempting to connect to local socket at '%s'. please be patiend.\n", remote.sun_path); - - status = connect(sock, (struct sockaddr *)&remote, sizeof(remote)); + zybo_fifo_tx = open(fifo_tx, O_WRONLY | O_NONBLOCK); + if (zybo_fifo_tx < 0) { + warnx("Opening zybo_fifo_tx..."); + return -1; + } + /* Must use O_RDWR so that there is at least one writer on the fifo + and each subsequent call to select() won't return EOF + */ + zybo_fifo_rx = open(fifo_rx, O_RDWR | O_NONBLOCK); + if (zybo_fifo_rx < 0) { + warnx("Opening zybo_fifo_rx..."); + return -1; + } + status = 0; + sock = zybo_fifo_rx; } else if (strcmp(getenv(QUAD_COMM_ENV), "bluetooth") == 0) { printf("Using BT Settings\n"); struct sockaddr_rc addr; @@ -450,7 +485,13 @@ static ssize_t writeQuad(const uint8_t * buf, size_t count) { if (pthread_mutex_lock(&quadSocketMutex)) { err(-2, "pthrtead_mutex_lock (%s:%d):", __FILE__, __LINE__); } - retval = write(zyboSocket, buf, count); + + if (local_comm_channel) { + retval = write(zybo_fifo_tx, buf, count); + } else { + retval = write(zyboSocket, buf, count); + } + if (pthread_mutex_unlock(&quadSocketMutex)) { err(-2, "pthrtead_mutex_unlock (%s:%d):", __FILE__, __LINE__); } @@ -466,7 +507,13 @@ static ssize_t readQuad(char * buf, size_t count) { if (pthread_mutex_lock(&quadSocketMutex)) { err(-2, "pthrtead_mutex_lock (%s:%d):", __FILE__, __LINE__); } - retval = read(zyboSocket, buf, count); + + if (local_comm_channel) { + retval = read(zybo_fifo_rx, buf, count); + } else { + retval = read(zyboSocket, buf, count); + } + if (pthread_mutex_unlock(&quadSocketMutex)) { err(-2, "pthrtead_mutex_unlock (%s:%d):", __FILE__, __LINE__); } @@ -722,6 +769,7 @@ static void client_recv(int fd) { int retval = writeQuad(packet, psize); // printf("sent %d bytes\n", retval); + free(data); } @@ -758,7 +806,8 @@ static void quad_recv() { // } // printf("'\n"); - while(respBufLen){ + + while(respBufLen) { datalen = DecodePacket(&m, data, CMD_MAX_LENGTH, respBuf, respBufLen); if (datalen == -1) { warnx("No start Byte"); @@ -836,7 +885,7 @@ static void quad_recv() { printf("(Backend): message type %d ignored from quad\n", m.msg_type); break; } - } + } } static void handleResponse(struct metadata *m, uint8_t * data) diff --git a/groundStation/src/backend/config.h b/groundStation/src/backend/config.h index 1e8ad0d20c7959c7465c6ceb4b85c1ab67554782..4236b1328142c9583dee075e92380f499412995e 100644 --- a/groundStation/src/backend/config.h +++ b/groundStation/src/backend/config.h @@ -13,8 +13,12 @@ // backend with sudo elevation and with the --preserve-env flag or -E #define QUAD_COMM_ENV "UCART_COMM_CHANNEL" -#define QUAD_DEFAULT_LOCAL_SOCKET "./virtquad.socket" -#define QUAD_LOCAL_SOCKET "VIRT_QUAD_SOCKET" +#define QUAD_LOCAL_RX "UCART_LOCAL_RX" +#define QUAD_LOCAL_TX "UCART_LOCAL_TX" +#define QUAD_LOCAL_DEFAULT_RX "../quad/bin/virt-quad-fifos/uart-rx" +#define QUAD_LOCAL_DEFAULT_TX "../quad/bin/virt-quad-fifos/uart-tx" + + #define QUAD_IP_ENV "UCART_QUAD_IP" #define QUAD_IP_DEFAULT "192.168.1.1" #define QUAD_PORT_ENV "UCART_QUAD_PORT" diff --git a/quad/src/virt_quad/hw_impl_unix_pwm_input.c b/quad/src/virt_quad/hw_impl_unix_pwm_input.c index 49bf19385f79053a50d58a47965bb81a0f7da6cf..e81e88254b81021d78d9332c93f9e8b9007d27fb 100644 --- a/quad/src/virt_quad/hw_impl_unix_pwm_input.c +++ b/quad/src/virt_quad/hw_impl_unix_pwm_input.c @@ -38,7 +38,7 @@ int unix_pwm_input_reset(struct PWMInputDriver *self) { cache[5] = FLAP_1; for (i = 0; i < 6; i += 1) { - printf("%s: %d\n", input_names[i], cache[i]); + printf("%s: %lu\n", input_names[i], cache[i]); } return 0; @@ -72,7 +72,7 @@ void * update_input_cache(void *arg) { unsigned long val = strtoll(buff, NULL, 10); if (val < max && val > min) { cache[i] = val; - printf("%s: %d\n", input_names[i], val); + printf("%s: %lu\n", input_names[i], val); } else { printf("%s: Bad value - input not received\n", input_names[i]);