Skip to content
Snippets Groups Projects
Commit d376f75f authored by ucart's avatar ucart
Browse files

found memory issue on quad side. Creating branch to handle fixes.

parent b687bb47
No related branches found
No related tags found
No related merge requests found
#! /bin/bash #! /bin/bash
if [ -z "$1" ]; then
echo "No argument supplied"
exit 0
fi
cd .. cd ..
while true ; do while true ; do
./setparam 37 0 $1 ./setparam 37 0 $1
......
...@@ -18,11 +18,11 @@ ...@@ -18,11 +18,11 @@
#outer loop #outer loop
./setparam 'X pos PID' 'kp' -0.015 ./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' 'kd' -0.25
./setparam 'X pos PID' 'alpha' 0.88 ./setparam 'X pos PID' 'alpha' 0.88
./setparam 'Y pos PID' 'kp' 0.015 ./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' 'kd' 0.25
./setparam 'Y pos PID' 'alpha' 0.88 ./setparam 'Y pos PID' 'alpha' 0.88
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/types.h> #include <sys/types.h>
#include <netinet/tcp.h> #include <netinet/tcp.h>
#include <fcntl.h>
#include <sys/stat.h>
//user created includes //user created includes
#include "commands.h" #include "commands.h"
...@@ -88,6 +90,9 @@ char * create_log_name(char * buffer, size_t max); ...@@ -88,6 +90,9 @@ char * create_log_name(char * buffer, size_t max);
pthread_mutex_t quadSocketMutex; pthread_mutex_t quadSocketMutex;
static ssize_t writeQuad(const uint8_t * buf, size_t count); static ssize_t writeQuad(const uint8_t * buf, size_t count);
static ssize_t readQuad(char * 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 */ /* Functions for recording Latencies */
void findTimeDiff(int respID); void findTimeDiff(int respID);
...@@ -120,6 +125,10 @@ pthread_mutex_t quadResponseMutex, cliInputMutex ; ...@@ -120,6 +125,10 @@ pthread_mutex_t quadResponseMutex, cliInputMutex ;
unsigned char *commandBuf; unsigned char *commandBuf;
int newQuadResponse = 0, newCliInput = 0; 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. // Callback to be ran whenever the tracker receives data.
// Currently doing much more than it should. It will be slimmed down // Currently doing much more than it should. It will be slimmed down
// in the future. // in the future.
...@@ -191,7 +200,13 @@ int main(int argc, char **argv) ...@@ -191,7 +200,13 @@ int main(int argc, char **argv)
exit(1); 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)) { if (pthread_mutex_unlock(&quadSocketMutex)) {
err(-2, "pthrtead_mutex_unlock (%s:%d):", __FILE__, __LINE__); err(-2, "pthrtead_mutex_unlock (%s:%d):", __FILE__, __LINE__);
...@@ -268,9 +283,18 @@ int main(int argc, char **argv) ...@@ -268,9 +283,18 @@ int main(int argc, char **argv)
} }
} }
ucart_vrpn_tracker_freeInstance(tracker); 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); fclose(quadlog_file);
return 0; return 0;
} }
...@@ -329,22 +353,33 @@ int connectToZybo() { ...@@ -329,22 +353,33 @@ int connectToZybo() {
if (getenv(QUAD_COMM_ENV)) { if (getenv(QUAD_COMM_ENV)) {
/* Determine if we are using bluetooth or local */ /* Determine if we are using bluetooth or local */
if(strcmp(getenv(QUAD_COMM_ENV), "local") == 0) { 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; if (getenv(QUAD_LOCAL_RX)) {
char str[100]; fifo_tx = getenv(QUAD_LOCAL_RX);
}
if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { if (getenv(QUAD_LOCAL_TX)) {
perror("socket"); fifo_rx = getenv(QUAD_LOCAL_TX);
exit(1);
} }
remote.sun_family = AF_UNIX; zybo_fifo_tx = open(fifo_tx, O_WRONLY | O_NONBLOCK);
char * sock_env = getenv(QUAD_LOCAL_SOCKET); if (zybo_fifo_tx < 0) {
strcpy(remote.sun_path, sock_env ? sock_env : QUAD_DEFAULT_LOCAL_SOCKET); warnx("Opening zybo_fifo_tx...");
printf("Attempting to connect to local socket at '%s'. please be patiend.\n", remote.sun_path); return -1;
}
status = connect(sock, (struct sockaddr *)&remote, sizeof(remote)); /* 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) { } else if (strcmp(getenv(QUAD_COMM_ENV), "bluetooth") == 0) {
printf("Using BT Settings\n"); printf("Using BT Settings\n");
struct sockaddr_rc addr; struct sockaddr_rc addr;
...@@ -450,7 +485,13 @@ static ssize_t writeQuad(const uint8_t * buf, size_t count) { ...@@ -450,7 +485,13 @@ static ssize_t writeQuad(const uint8_t * buf, size_t count) {
if (pthread_mutex_lock(&quadSocketMutex)) { if (pthread_mutex_lock(&quadSocketMutex)) {
err(-2, "pthrtead_mutex_lock (%s:%d):", __FILE__, __LINE__); 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)) { if (pthread_mutex_unlock(&quadSocketMutex)) {
err(-2, "pthrtead_mutex_unlock (%s:%d):", __FILE__, __LINE__); err(-2, "pthrtead_mutex_unlock (%s:%d):", __FILE__, __LINE__);
} }
...@@ -466,7 +507,13 @@ static ssize_t readQuad(char * buf, size_t count) { ...@@ -466,7 +507,13 @@ static ssize_t readQuad(char * buf, size_t count) {
if (pthread_mutex_lock(&quadSocketMutex)) { if (pthread_mutex_lock(&quadSocketMutex)) {
err(-2, "pthrtead_mutex_lock (%s:%d):", __FILE__, __LINE__); 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)) { if (pthread_mutex_unlock(&quadSocketMutex)) {
err(-2, "pthrtead_mutex_unlock (%s:%d):", __FILE__, __LINE__); err(-2, "pthrtead_mutex_unlock (%s:%d):", __FILE__, __LINE__);
} }
...@@ -722,6 +769,7 @@ static void client_recv(int fd) { ...@@ -722,6 +769,7 @@ static void client_recv(int fd) {
int retval = writeQuad(packet, psize); int retval = writeQuad(packet, psize);
// printf("sent %d bytes\n", retval); // printf("sent %d bytes\n", retval);
free(data); free(data);
} }
...@@ -758,7 +806,8 @@ static void quad_recv() { ...@@ -758,7 +806,8 @@ static void quad_recv() {
// } // }
// printf("'\n"); // printf("'\n");
while(respBufLen){
while(respBufLen) {
datalen = DecodePacket(&m, data, CMD_MAX_LENGTH, respBuf, respBufLen); datalen = DecodePacket(&m, data, CMD_MAX_LENGTH, respBuf, respBufLen);
if (datalen == -1) { if (datalen == -1) {
warnx("No start Byte"); warnx("No start Byte");
...@@ -836,7 +885,7 @@ static void quad_recv() { ...@@ -836,7 +885,7 @@ static void quad_recv() {
printf("(Backend): message type %d ignored from quad\n", m.msg_type); printf("(Backend): message type %d ignored from quad\n", m.msg_type);
break; break;
} }
} }
} }
static void handleResponse(struct metadata *m, uint8_t * data) static void handleResponse(struct metadata *m, uint8_t * data)
......
...@@ -13,8 +13,12 @@ ...@@ -13,8 +13,12 @@
// backend with sudo elevation and with the --preserve-env flag or -E // backend with sudo elevation and with the --preserve-env flag or -E
#define QUAD_COMM_ENV "UCART_COMM_CHANNEL" #define QUAD_COMM_ENV "UCART_COMM_CHANNEL"
#define QUAD_DEFAULT_LOCAL_SOCKET "./virtquad.socket" #define QUAD_LOCAL_RX "UCART_LOCAL_RX"
#define QUAD_LOCAL_SOCKET "VIRT_QUAD_SOCKET" #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_ENV "UCART_QUAD_IP"
#define QUAD_IP_DEFAULT "192.168.1.1" #define QUAD_IP_DEFAULT "192.168.1.1"
#define QUAD_PORT_ENV "UCART_QUAD_PORT" #define QUAD_PORT_ENV "UCART_QUAD_PORT"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment