diff --git a/groundStation/gui/MicroCART/mainwindow.cpp b/groundStation/gui/MicroCART/mainwindow.cpp index 29c350553967eb144087e69f1e12815e1ba5b0cb..daed528e84e331e8d384b84b642492a66a6a8bae 100644 --- a/groundStation/gui/MicroCART/mainwindow.cpp +++ b/groundStation/gui/MicroCART/mainwindow.cpp @@ -31,7 +31,6 @@ MainWindow::MainWindow(QWidget *parent) : ui->topView->setScene(topScene); QuadItem * quad = new QuadItem(); - topScene->addItem(); topScene->addItem(quad); /* Set up environment variables */ diff --git a/quad/scripts/tests/test_communication.rb b/quad/scripts/tests/test_communication.rb index 4887a29bca60829b2a4bf4691a5c9de0e9fe546d..8797cc16dabab068acafe493cdc1b2dfab824ddd 100644 --- a/quad/scripts/tests/test_communication.rb +++ b/quad/scripts/tests/test_communication.rb @@ -16,7 +16,7 @@ Timeout::timeout(30) { puts("Setting up...") # Start virtual quad - quad_pid = Process.spawn("./virt-quad -q", + quad_pid = Process.spawn("./virt-quad start -q", { :rlimit_as => 536870912, # 512 MiB total RAM :rlimit_stack => 1048576}) # 1 MiB stack @@ -49,7 +49,7 @@ Timeout::timeout(30) { # Send a debug command Thread.new { - sleep 0.1 + sleep 0.5 send_packet [0xBE, 1, 0, 0, 0, 0, 0, 0xBF] } @@ -58,7 +58,7 @@ Timeout::timeout(30) { # Receive the header msg = [] for i in 1..7 - sleep 0.0001 + sleep 0.01 c = fifo.read(1) msg.push(c) end @@ -68,7 +68,7 @@ Timeout::timeout(30) { msg = [] for i in 1..length - sleep 0.0001 + sleep 0.01 c = fifo.read(1) msg.push(c) end diff --git a/quad/scripts/tests/test_logging.rb b/quad/scripts/tests/test_logging.rb index a0e86e716eb4ccd71435b0f88a16f40e7f40e712..58d16f73caa7837e2b9aa82dfa48e0e7bbb257d4 100644 --- a/quad/scripts/tests/test_logging.rb +++ b/quad/scripts/tests/test_logging.rb @@ -16,7 +16,7 @@ Timeout::timeout(30) { puts("Setting up...") # Start virtual quad - quad_pid = Process.spawn("./virt-quad -q", + quad_pid = Process.spawn("./virt-quad start -q", { :rlimit_as => 536870912, # 512 MiB total RAM :rlimit_stack => 1048576}) # 1 MiB stack @@ -83,7 +83,7 @@ Timeout::timeout(30) { # Get logs Thread.new { - sleep 0.5 + sleep 1 puts("Swiching off GEAR...") set_gear GEAR_OFF } diff --git a/quad/scripts/tests/test_memory_integrity.rb b/quad/scripts/tests/test_memory_integrity.rb index d7116c1d4f2d3cd1d59e33824225c5f127c70c44..adb8f9190b6adb3fff8a6e6f8de2eb143854cfe3 100644 --- a/quad/scripts/tests/test_memory_integrity.rb +++ b/quad/scripts/tests/test_memory_integrity.rb @@ -14,7 +14,7 @@ Dir.chdir(bin_dir) puts("Firing up the quad...") # Start virtual quad -quad = Process.spawn("valgrind --leak-check=full --log-file=./valgrind.out ./virt-quad") +quad = Process.spawn("valgrind --leak-check=full --log-file=./valgrind.out ./virt-quad start") sleep 1.5 diff --git a/quad/scripts/tests/test_safety_checks.rb b/quad/scripts/tests/test_safety_checks.rb index c5557cecec1bb09aefdf6a88d73a3263fd5bce8e..c96a8228f66cde705e62e81ab992eabd803c2569 100644 --- a/quad/scripts/tests/test_safety_checks.rb +++ b/quad/scripts/tests/test_safety_checks.rb @@ -17,7 +17,7 @@ Timeout::timeout(60) { puts("Setting up...") # Start virtual quad - quad_pid = Process.spawn("./virt-quad -q", + quad_pid = Process.spawn("./virt-quad start -q", { :rlimit_as => 536870912, # 512 MiB total RAM :rlimit_stack => 1048576}) # 1 MiB stack diff --git a/quad/src/quad_app/PID.c b/quad/src/quad_app/PID.c deleted file mode 100644 index 185e7b8dc6161616321bd8fae82f5dd709f94174..0000000000000000000000000000000000000000 --- a/quad/src/quad_app/PID.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * PID.c - * - * Created on: Nov 10, 2014 - * Author: ucart - */ - -#include "PID.h" -#include <math.h> -#include <float.h> - -// The generic PID diagram. This function takes in pid parameters (PID_t * pid) and calculates the output "pid_correction" -// part based on those parameters. -// -// + --- error ------------------ P + --- ---------------------------- -// setpoint ---> / sum \ --------->| Kp * error |--------------->/ sum \ -------->| output: "pid_correction" | -// \ / | ------------------ \ / ---------------------------- -// --- | --- || -// - ^ | + ^ ^ + || -// | | ------------------------------- | | ------- \/------------ -// | |----->| Ki * accumulated error * dt |----+ | | | -// | | ------------------------------- I | | SYSTEM | -// | | | | | -// | | | --------||------------ -// | | | || -// | | ---------------------------------- | || -// | |----->| Kd * (error - last error) / dt |----+ || -// | ---------------------------------- D || -// | || -// | -----------\/----------- -// |____________________________________________________________| Sensor measurements: | -// | "current point" | -// ------------------------ -// -PID_values pid_computation(PID_t *pid) { - - float P = 0.0, I = 0.0, D = 0.0; - - // calculate the current error - float error = pid->setpoint - pid->current_point; - - // Accumulate the error (if Ki is less than epsilon, rougly 0, - // then reset the accumulated error for safety) - if (fabs(pid->Ki) <= FLT_EPSILON) { - pid->acc_error = 0; - } else { - pid->acc_error += error; - } - - float change_in_error = error - pid->prev_error; - - // Compute each term's contribution - P = pid->Kp * error; - I = pid->Ki * pid->acc_error * pid->dt; - D = pid->Kd * (change_in_error / pid->dt); - - PID_values ret = {P, I, D, error, change_in_error, P + I + D}; - - pid->prev_error = error; // Store the current error into the PID_t - - pid->pid_correction = P + I + D; // Store the computed correction - return ret; -} diff --git a/quad/src/quad_app/README.txt b/quad/src/quad_app/README.txt deleted file mode 100644 index 0e065fbfb65ff25e0844aa10225af4b34d0b07ab..0000000000000000000000000000000000000000 --- a/quad/src/quad_app/README.txt +++ /dev/null @@ -1 +0,0 @@ -This application is the PID implementation of the modular control loop. This is the same implementation as the existing quad controller. The mixer in this application needs to be changed to be correct according to common implementation. diff --git a/quad/src/quad_app/control_algorithm.h b/quad/src/quad_app/control_algorithm.h index 8e8a15b79b705fe025c57965b45f8f975eadfb1b..92c0feeac5a4121319b8fbf1e28b0b477cb8a3c5 100644 --- a/quad/src/quad_app/control_algorithm.h +++ b/quad/src/quad_app/control_algorithm.h @@ -12,7 +12,6 @@ #include "log_data.h" #include "sensor_processing.h" -#include "quadposition.h" #include "type_def.h" /** diff --git a/quad/src/quad_app/controllers.c b/quad/src/quad_app/controllers.c deleted file mode 100644 index 14abde800f5ea36af1154894c29fdf18e680067f..0000000000000000000000000000000000000000 --- a/quad/src/quad_app/controllers.c +++ /dev/null @@ -1,48 +0,0 @@ -/* - * controllers.c - * - * Created on: Oct 11, 2014 - * Author: ucart - */ - -/** - * Lots of useful information in controllers.h, look in there first - */ -#include "controllers.h" -#include "quadposition.h" -#include "util.h" -#include "stdio.h" -#include <math.h> - -// 0 was -6600 -//int motor0_bias = -4500, motor1_bias = 100, motor2_bias = 5300, motor3_bias = 10300; -int motor0_bias = -9900, motor1_bias = -200, motor2_bias = -10200, motor3_bias = 250; - -/** - * Takes the raw signal inputs from the receiver and filters it so the - * quadcopter doesn't flip or do something extreme - */ -void filter_PWMs(int* mixer) { - -} - -/** - * Converts PWM signals into 4 channel pitch, roll, yaw, throttle - */ -// javey: unused -void PWMS_to_Aero(int* PWMs, int* aero) { - /** - * Reference used to derive equations - */ - // pwm0 = throttle_base - pitch_base + yaw_base; - // pwm1 = throttle_base + roll_base - yaw_base; - // pwm2 = throttle_base - roll_base - yaw_base; - // pwm3 = throttle_base + pitch_base + yaw_base; - - aero[THROTTLE] = (PWMs[0] + PWMs[1] + PWMs[2] + PWMs[3]) / 4; - aero[ROLL] = (PWMs[1] - PWMs[2]) / 2; - aero[PITCH] = (PWMs[3] - PWMs[0]) / 2; - aero[YAW] = (PWMs[3] + PWMs[0] - PWMs[1] - PWMs[2]) / 4; -} - - diff --git a/quad/src/quad_app/controllers.h b/quad/src/quad_app/controllers.h index 40c7832601fd0509a002cb2f5c3c29fa80c304ff..2b6f38cc5fc3c87db0eddea0c199868049484df9 100644 --- a/quad/src/quad_app/controllers.h +++ b/quad/src/quad_app/controllers.h @@ -8,7 +8,6 @@ #define _CONTROLLERS_H #include "util.h" -#include "quadposition.h" /** * diff --git a/quad/src/quad_app/gam.h b/quad/src/quad_app/gam.h deleted file mode 100644 index 0f4803e8d2a2cb50e6733acb278529ebb658f636..0000000000000000000000000000000000000000 --- a/quad/src/quad_app/gam.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef _GAM_H -#define _GAM_H - -//Gyro, accelerometer, and magnetometer data structure -//Used for reading an instance of the sensor data -typedef struct { - - // GYRO - //Xint16 raw_gyro_x, raw_gyro_y, raw_gyro_z; - - float gyro_xVel_p; // In degrees per second - float gyro_yVel_q; - float gyro_zVel_r; - - // ACCELEROMETER - //Xint16 raw_accel_x, raw_accel_y, raw_accel_z; - - float accel_x; //In g - float accel_y; - float accel_z; - - float accel_roll; - float accel_pitch; - - - // MAG - //Xint16 raw_mag_x, raw_mag_y, raw_mag_z; - - float heading; // In degrees - - float mag_x; //Magnetic north: ~50 uT - float mag_y; - float mag_z; - - - -}gam_t; -#endif /* _GAM_H */ diff --git a/quad/src/quad_app/hw_iface.h b/quad/src/quad_app/hw_iface.h index 2880dcc234d23358967189f99834bd8060d2dfe3..1a5f5109ce012bc531d73cbcfe40761e0613882e 100644 --- a/quad/src/quad_app/hw_iface.h +++ b/quad/src/quad_app/hw_iface.h @@ -15,6 +15,11 @@ * hardware layer appropriate for your circumstance: * ../../xsdk_worksapce/real_quad -> running quad_app on the Zybo * ../virt_quad -> running quad_app in a Unix environment + * + * Function Pointer Return Values: + * - All driver functions return the error code + * - 0 for success + * - nonzero otherwise */ // Forward declared types diff --git a/quad/src/quad_app/new_PID.h b/quad/src/quad_app/new_PID.h deleted file mode 100644 index fae2778ec8b422875e1d88d6ae98a70dee00a8e3..0000000000000000000000000000000000000000 --- a/quad/src/quad_app/new_PID.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * PID.h - * - * Created on: Nov 10, 2014 - * Author: ucart - */ - -#ifndef PID_H_ -#define PID_H_ - -#include "type_def.h" - -// Yaw constants - -// when using units of radians -#define YAW_ANGULAR_VELOCITY_KP 200.0 * 2292.0f -#define YAW_ANGULAR_VELOCITY_KI 0.0f -#define YAW_ANGULAR_VELOCITY_KD 0.0f -#define YAW_ANGLE_KP 2.6f -#define YAW_ANGLE_KI 0.0f -#define YAW_ANGLE_KD 0.0f - -// when using units of radians -#define ROLL_ANGULAR_VELOCITY_KP 100.0 * 46.0f -#define ROLL_ANGULAR_VELOCITY_KI 0.0f -#define ROLL_ANGULAR_VELOCITY_KD 100.0 * 5.5f -#define ROLL_ANGLE_KP 15.0f -#define ROLL_ANGLE_KI 0.0f -#define ROLL_ANGLE_KD 0.2f -#define YPOS_KP 0.08f -#define YPOS_KI 0.01f -#define YPOS_KD 0.1f - - -//Pitch constants - -// when using units of radians -#define PITCH_ANGULAR_VELOCITY_KP 100.0 * 46.0f -#define PITCH_ANGULAR_VELOCITY_KI 0.0f -#define PITCH_ANGULAR_VELOCITY_KD 100.0 * 5.5f -#define PITCH_ANGLE_KP 15.0f -#define PITCH_ANGLE_KI 0.0f -#define PITCH_ANGLE_KD 0.2f -#define XPOS_KP 0.08f -#define XPOS_KI 0.01f -#define XPOS_KD 0.1f - - -//Throttle constants -#define ALT_ZPOS_KP -9804.0f -#define ALT_ZPOS_KI -817.0f -#define ALT_ZPOS_KD -7353.0f - -// Computes control error and correction -PID_values pid_computation(PID_t *pid); - -#endif /* PID_H_ */ diff --git a/quad/src/quad_app/new_log_data.c b/quad/src/quad_app/new_log_data.c deleted file mode 100644 index 7b2b758f2722673336296c4a3d3f7525b8d4de91..0000000000000000000000000000000000000000 --- a/quad/src/quad_app/new_log_data.c +++ /dev/null @@ -1,225 +0,0 @@ -/* - * log_data.c - * - * Created on: Feb 20, 2016 - * Author: ucart - */ - -/* - #include "log_data.h" - -// Current index of the log array -int arrayIndex = 0; -// Size of the array -int arraySize = LOG_STARTING_SIZE; -int resized = 0; - -// The number of times we resized the array -int resizeCount = 0; - -// Pointer to point to the array with all the logging information -// for now its not dynamic -log_t logArray[LOG_STARTING_SIZE * 3];// up to 60 seconds of log - -int log_data(log_t* log_struct) -{ - updateLog(*log_struct); - return 0; -} - -* - * Fills up an xbox hueg amount of memory with log data - -void updateLog(log_t log_struct){ - // If the first iteration, allocate enough memory for "arraySize" elements of logging -// if(logArray == NULL){ -// // size in memory is 1,720,320 bytes (1.64 megabytes) because logging struct is 420 bytes each -// // up to 20 seconds of log before resizing -// logArray = malloc(LOG_STARTING_SIZE * sizeof(log_t)); -// uart0_sendStr("initialized log array.\n"); -// sleep(1); -// } - - // semi dynamic log -// if((arrayIndex >= arraySize - 1) && (!resized)){ -// realloc(logArray, LOG_STARTING_SIZE * 3 * sizeof(log_t)); // up to 60 seconds of log -// resized = 1; -// arraySize = LOG_STARTING_SIZE * 3; -// uart0_sendStr("resized log array.\n"); -// sleep(1); -// } - - if(arrayIndex >= arraySize - 1) - { - return; - } - - // Add log to the array - logArray[arrayIndex++] = log_struct; - - // If the index is too big, reallocate memory to double the size as before -// if(arrayIndex == arraySize){ -// arraySize *= 2; -// logArray = (log_t *) realloc(logArray, arraySize * sizeof(log_t)); -// ++resizeCount; -// } -// else if(arrayIndex > arraySize){ -// // Something fishy has occured -// xil_printf("Array index is out of bounds. This shouldn't happen but somehow you did the impossible\n\r"); -// } -} - - -* - * Prints all the log information. - * - * TODO: This should probably be transmitting in binary instead of ascii - - -void printLogging(){ - int i, numBytes; - char buf[2304] = {}; - char comments[256] = {}; - char header[1024] = {}; - char units [1024] = {}; - - char tempLog[4096*2] = {}; - - sprintf(comments, "# MicroCART On-board Quad Log\r\n# Sample size: %d\r\n", arrayIndex); - sprintf(header, "%%Time\t" "LoopPeriod\t" - - //current points (measurements) - "X_Current_Position\t" "Y_Current_Position\t" "Z_Current_Position\t" - "Cam_Meas_Roll\tCam_Meas_Pitch\tCam_Meas_Yaw\t" - "Quad_Meas_Roll\tQuad_Meas_Pitch\t" - "roll_velocity\tpitch_velocity\tyaw_velocity\t" - - //setpoints - "X_setpoint\t" "Y_setpoint\t" "Z_setpoint\t" - "Roll_setpoint\tPitch_setpoint\tYaw_setpoint\t" - "Roll_vel_setpoint\tPitch_vel_setpoint\tYaw_vel_setpoint\t" - - //corrections - "PID_x\t" - "PID_y\t" - "PID_z\t" - "PID_roll\t" - "PID_pitch\t" - "PID_yaw\t" - "PID_roll_vel\t" - "PID_pitch_vel\t" - "PID_yaw_vel\t" - - //trims - "Roll_trim\tPitch_trim\tYaw_trim\tThrottle_trim\t" - - //motor commands - "Motor_0\tMotor_1\tMotor_2\tMotor_3\n" - - ); - - - sprintf(units, "&sec\tsec\t" - - //current points - "meters\tmeters\tmeters\t" - "radians\tradians\tradians\t" - "radians\tradians\t" - "radians//sec\tradians//sec\tradians//sec\t" - - //setpoints - "meters\tmeters\tmeters\t" - "radians\tradians\tradians\t" - "radians//sec\tradians//sec\tradians//sec\t" - - //corrections - "radians\tradians\tradians\t" - "radians//sec\tradians//sec\tradians//sec\t" - "none\tnone\tnone\t" - - //trims - "none\tnone\tnone\tnone\t" - - //motors - "none\tnone\tnone\tnone\n" - - ); - - strcat(buf,comments); - strcat(buf,header); - strcat(buf,units); - - - numBytes = logData(buf, tempLog); - uart0_sendBytes(tempLog, strlen(tempLog)); - usleep(100000); - - *********************** - print & send log data - for(i = 0; i < arrayIndex; i++){ - char* logLine = format(logArray[i]); - numBytes = logData(logLine, tempLog); - uart0_sendBytes(tempLog, numBytes); - usleep(10000); - //free(logLine); - //break; - } -} - - -char* format(log_t log){ - char *retString = malloc(4096*2); - - sprintf(retString, "%.3f\t%.4f\t" //Time and TimeSlice - - // current points - "%.3f\t%.3f\t%.3f\t" - "%.3f\t%.3f\t%.3f\t" - "%.3f\t%.3f\t" - "%.3f\t%.3f\t%.3f\t" - - //setpoints - "%.3f\t%.3f\t%.3f\t" - "%.3f\t%.3f\t%.3f\t" - "%.3f\t%.3f\t%.3f\t" - - //corrections - "%.3f\t%.3f\t%.3f\t" - "%.3f\t%.3f\t%.3f\t" - "%.3f\t%.3f\t%.3f\t" - - //trims - "%d\t%d\t%d\t%d\t" - - //motors - "%d\t%d\t%d\t%d\n" - - ,log.time_stamp, log.time_slice, - - // current points - log.local_x_PID.current_point,log.local_y_PID.current_point, log.altitude_PID.current_point, - log.currentQuadPosition.roll, log.currentQuadPosition.pitch, log.currentQuadPosition.yaw, - log.roll_angle_filtered, log.pitch_angle_filtered, - log.phi_dot, log.theta_dot, log.psi_dot, - - //setpoints - log.local_x_PID.setpoint, log.local_y_PID.setpoint, log.altitude_PID.setpoint, - log.angle_roll_PID.setpoint, log.angle_pitch_PID.setpoint, log.angle_yaw_PID.setpoint, - log.ang_vel_roll_PID.setpoint, log.ang_vel_pitch_PID.setpoint, log.ang_vel_pitch_PID.setpoint, - - //corrections - log.local_x_PID_values.pid_correction, log.local_y_PID_values.pid_correction, log.altitude_PID_values.pid_correction, - log.angle_roll_PID_values.pid_correction, log.angle_pitch_PID_values.pid_correction, log.angle_yaw_PID_values.pid_correction, - log.ang_vel_roll_PID_values.pid_correction, log.ang_vel_pitch_PID_values.pid_correction, log.ang_vel_yaw_PID_values.pid_correction, - - //trims - log.trims.roll, log.trims.pitch, log.trims.yaw, log.trims.throttle, - - //motors - log.motors[0], log.motors[1], log.motors[2], log.motors[3] - ); - - - return retString; -} -*/ diff --git a/quad/src/quad_app/new_log_data.h b/quad/src/quad_app/new_log_data.h deleted file mode 100644 index 13e713a9ecd1ea71fd799de4860d36808bc2f856..0000000000000000000000000000000000000000 --- a/quad/src/quad_app/new_log_data.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * log_data.h - * - * Created on: Feb 20, 2016 - * Author: ucart - */ - -#ifndef LOG_DATA_H_ -#define LOG_DATA_H_ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "PID.h" -#include "type_def.h" -#include "sleep.h" -#include "communication.h" - -#define LOG_STARTING_SIZE 4096 //262144 // 2^18 32768 2^15 - - -/** - * @brief - * Logs the data obtained throughout the controller loop. - * - * @param log_struct - * structure of the data to be logged - * - * @return - * error message - * - */ - int log_data(log_t* log_struct); - - /** - * Fills up an xbox hueg amount of memory with log data - */ - void updateLog(log_t log_struct); - - /** - * Prints all the log information. - */ - void printLogging(); - - char* format(log_t log); - -#endif /* LOG_DATA_H_ */ diff --git a/quad/src/quad_app/old_log_data.h b/quad/src/quad_app/old_log_data.h deleted file mode 100644 index 13e713a9ecd1ea71fd799de4860d36808bc2f856..0000000000000000000000000000000000000000 --- a/quad/src/quad_app/old_log_data.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * log_data.h - * - * Created on: Feb 20, 2016 - * Author: ucart - */ - -#ifndef LOG_DATA_H_ -#define LOG_DATA_H_ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "PID.h" -#include "type_def.h" -#include "sleep.h" -#include "communication.h" - -#define LOG_STARTING_SIZE 4096 //262144 // 2^18 32768 2^15 - - -/** - * @brief - * Logs the data obtained throughout the controller loop. - * - * @param log_struct - * structure of the data to be logged - * - * @return - * error message - * - */ - int log_data(log_t* log_struct); - - /** - * Fills up an xbox hueg amount of memory with log data - */ - void updateLog(log_t log_struct); - - /** - * Prints all the log information. - */ - void printLogging(); - - char* format(log_t log); - -#endif /* LOG_DATA_H_ */ diff --git a/quad/src/quad_app/packet_processing.c b/quad/src/quad_app/packet_processing.c deleted file mode 100644 index 8652c92335a2c778569e6e9e5a98591e155ba626..0000000000000000000000000000000000000000 --- a/quad/src/quad_app/packet_processing.c +++ /dev/null @@ -1,46 +0,0 @@ -/* - * process_packet.c - * - * Created on: Mar 2, 2016 - * Author: ucart - */ -#include "packet_processing.h" -#include "type_def.h" -#include "util.h" -#include "communication.h" - -#define DEBUG 0 - -tokenList_t tokenize(char* cmd) { - int maxTokens = 16; - tokenList_t ret; - ret.numTokens = 0; - ret.tokens = malloc(sizeof(char *)* 20 * maxTokens); - - int i = 0; - ret.tokens[0] = NULL; - char* token = strtok(cmd, " "); - while (token != NULL && i < maxTokens - 1) { - ret.tokens[i] = malloc(strlen(token) + 10); - strcpy(ret.tokens[i], token); - ret.tokens[++i] = NULL; - ret.numTokens++; - token = strtok(NULL, " "); - } - - return ret; -} - -float getFloat(unsigned char* str, int pos) { - union { - float f; - int i; - } x; - x.i = ((str[pos+3] << 24) | (str[pos+2] << 16) | (str[pos+1] << 8) | (str[pos])); - return x.f; -} - -int getInt(unsigned char* str, int pos) { - int i = ((str[pos+3] << 24) | (str[pos+2] << 16) | (str[pos+1] << 8) | (str[pos])); - return i; -} diff --git a/quad/src/quad_app/packet_processing.h b/quad/src/quad_app/packet_processing.h deleted file mode 100644 index 55a5494b3e1535ac46db7abdaa0ee18b2591f212..0000000000000000000000000000000000000000 --- a/quad/src/quad_app/packet_processing.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * process_packet.h - * - * Created on: Mar 2, 2016 - * Author: ucart - */ - -#ifndef PROCESS_PACKET_H_ -#define PROCESS_PACKET_H_ - -#include <stdlib.h> -#include <string.h> -#include <stdio.h> -#include "type_def.h" - -tokenList_t tokenize(char* cmd); -int processUpdate(unsigned char* update, quadPosition_t* currentQuadPosition); -//int processCommand(stringBuilder_t * sb, setpoint_t * setpoint_struct, parameter_t * parameter_struct); -int doProcessing(char* cmd, tokenList_t * tokens, setpoint_t * setpoint_struct, parameter_t * parameter_struct); -float getFloat(unsigned char* str, int pos); -int getInt(unsigned char* str, int pos); - -#endif /* PROCESS_PACKET_H_ */ diff --git a/quad/src/quad_app/quad_app.c b/quad/src/quad_app/quad_app.c index b6bde4fd02ea9ca30556da45e8a6e27fa59cfcb2..7f7db6b4fbf3734ea357bc6214bd53c8411c16bd 100644 --- a/quad/src/quad_app/quad_app.c +++ b/quad/src/quad_app/quad_app.c @@ -13,7 +13,6 @@ #include "sensor_processing.h" #include "control_algorithm.h" #include "send_actuator_commands.h" -#include "update_gui.h" #include "communication.h" #include "mio7_led.h" @@ -71,8 +70,6 @@ int quad_main(int (*setup_hardware)(hardware_t *hardware_struct)) else { kill_motors(&(structs.hardware_struct.motors)); } - // update the GUI - update_GUI(&(structs.log_struct)); if (!this_kill_condition) { // Log the data collected in this loop diff --git a/quad/src/quad_app/quadposition.h b/quad/src/quad_app/quadposition.h deleted file mode 100644 index 05011e04e6289f951700e838b666634b04b4cbc9..0000000000000000000000000000000000000000 --- a/quad/src/quad_app/quadposition.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _QUADPOSITION_H -#define _QUADPOSITION_H - - - -#endif /* _QUADPOSITION_H */ diff --git a/quad/src/quad_app/sensor.h b/quad/src/quad_app/sensor.h index d8b9c2620408626afe187c000564968c006ac867..da359e3e05e94133cc33bdae196f894554021570 100644 --- a/quad/src/quad_app/sensor.h +++ b/quad/src/quad_app/sensor.h @@ -12,7 +12,6 @@ #include "log_data.h" #include "user_input.h" -#include "packet_processing.h" #include "hw_iface.h" /** diff --git a/quad/src/quad_app/sensor_processing.c b/quad/src/quad_app/sensor_processing.c index 99a3cfbacaf3d1b8777a21d3f07e7aabdf0992ed..c1edf7c3d0701a5a7798550a0dfafbabc4bc5ec4 100644 --- a/quad/src/quad_app/sensor_processing.c +++ b/quad/src/quad_app/sensor_processing.c @@ -9,7 +9,6 @@ #include "log_data.h" #include "sensor.h" #include "conversion.h" -#include "quadposition.h" #include "sensor_processing.h" #include "timer.h" #include <math.h> diff --git a/quad/src/quad_app/update_gui.c b/quad/src/quad_app/update_gui.c deleted file mode 100644 index 320936e5aa73f0309209ab945f56807f72d69d1d..0000000000000000000000000000000000000000 --- a/quad/src/quad_app/update_gui.c +++ /dev/null @@ -1,14 +0,0 @@ -/* - * update_gui.c - * - * Created on: Feb 20, 2016 - * Author: ucart - */ - -#include "update_gui.h" - -int update_GUI(log_t* log_struct) -{ - return 0; -} - diff --git a/quad/src/quad_app/update_gui.h b/quad/src/quad_app/update_gui.h deleted file mode 100644 index a348ade955798e225c96f1b59b27d79a75861d59..0000000000000000000000000000000000000000 --- a/quad/src/quad_app/update_gui.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * update_gui.h - * - * Created on: Feb 20, 2016 - * Author: ucart - */ - -#ifndef UPDATE_GUI_H_ -#define UPDATE_GUI_H_ - -#include <stdio.h> - -#include "log_data.h" - -/** - * @brief - * Updates the user interface. - * - * @param log_struct - * structure of the data to be logged - * - * @return - * error message - * - */ -int update_GUI(log_t* log_struct); - -#endif /* UPDATE_GUI_H_ */ diff --git a/quad/src/virt_quad/README.md b/quad/src/virt_quad/README.md index 3607ec44cadba0f318a6797a296b35a8f687c091..3b263e52847000867fb67a6cb12da244efeca7ee 100644 --- a/quad/src/virt_quad/README.md +++ b/quad/src/virt_quad/README.md @@ -8,17 +8,18 @@ plethoria of things required for flight in Coover 3050. In fact, you don't even have to be in Coover 3050... # Using the Virtual Quad -Start it up: +The virt-quad has help output. Get started with: ``` -make run +./virt-quad ``` -And you can do things with it. You'll notice it will make a bunch of FIFOs in -the current directory. Write to / read from these FIFOs as you see fit. +## Using the UART Driver -## Writing to FIFO from shell +The UART interface is implemented with unix FIFOs. You can treat these FIFOs +as regular unix files. Read from uart-tx to hear with the quad is saying. Write +to uart-rx to tell the quad something. ``` -echo "170000" > virt-quad-fifos/pwm-input-gear # Setting the gear to '1' -cat virt-quad-fifos/pwm-output-motor1 # Read the motor 1 pwm signal +echo "hello world" > virt-quad-fifos/uart-rx +cat virt-quad-fifos/uart-tx ``` \ No newline at end of file diff --git a/quad/src/virt_quad/main.c b/quad/src/virt_quad/main.c index 105a8a5e68ae04d21e8001b9eb8c0b78a8629038..1e24ab458cec3ca535a21a7a538d51c4b08f6eb3 100644 --- a/quad/src/virt_quad/main.c +++ b/quad/src/virt_quad/main.c @@ -4,15 +4,28 @@ #include "quad_app.h" #include <fcntl.h> +struct VirtQuadIO *virt_quad_io; +int virt_quad_io_file_descriptor; + +enum CLISubCommand { + START, + GET, + SET, + USAGE, + HELP, +}; + +int start_virt_quad(char *argv[]); int handle_io_output(const char *name); int handle_io_input(const char *name, const char *value_str); void set_shm(float value, float *dest, pthread_mutex_t *lock); void print_shm_float(float *value, pthread_mutex_t *lock); void print_shm_int(int *value, pthread_mutex_t *lock); void usage(char *executable_name); - -struct VirtQuadIO *virt_quad_io; -int virt_quad_io_file_descriptor; +enum CLISubCommand parse_sub_command(char *argv[]); +void open_new_shm_io(); +void open_existing_shm_io(); +void help_sub_command(char *argv[]); /** * Implement each of the hardware interfaces. @@ -33,61 +46,91 @@ int setup_hardware(hardware_t *hardware) { } int main(int argc, char *argv[]) { - int fd; + enum CLISubCommand sub_command = parse_sub_command(argv + 1); + + switch (sub_command) { + case START: + open_new_shm_io(); + start_virt_quad(argv + 2); // will block + break; + case SET: + open_existing_shm_io(); + handle_io_input(argv[2], argv[3]); + break; + case GET: + open_existing_shm_io(); + handle_io_output(argv[2]); + break; + case HELP: + help_sub_command(argv); + break; + case USAGE: + usage(argv[0]); + break; + } - // Decide if we are launching the quad or parsing arguments - if (argv[1] == NULL || strcmp(argv[1], "-q") == 0) { - // launch the quad - - // Allow making the quad quiet - if (argv[1] != NULL && strcmp(argv[1], "-q") == 0) { - fd = open("/dev/null", O_WRONLY); - close(STDOUT_FILENO); - dup2(STDOUT_FILENO, fd); - } - - // Prepare the shared memory for io. Clear memory and initialize. - int *fd = &virt_quad_io_file_descriptor; - *fd = shm_open(VIRT_QUAD_SHARED_MEMORY, O_CREAT | O_RDWR | O_TRUNC, 0666); - ftruncate(*fd, sizeof(struct VirtQuadIO)); - virt_quad_io = mmap(NULL, sizeof(struct VirtQuadIO), PROT_READ | PROT_WRITE, MAP_SHARED, *fd, 0); - pthread_mutexattr_t attr; - pthread_mutexattr_init(&attr); - pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED); - pthread_mutex_init(&virt_quad_io->led_lock, &attr); - pthread_mutex_init(&virt_quad_io->motors_lock, &attr); - pthread_mutex_init(&virt_quad_io->rc_lock, &attr); + return 0; +} + +enum CLISubCommand parse_sub_command(char *argv[]) { + if (argv[0] == NULL) { + return USAGE; + } + else if (strcmp(argv[0], "start") == 0) { + return START; + } + else if (strcmp(argv[0], "help") == 0) { + return HELP; + } + else if (strcmp(argv[0], "get") == 0 && argv[1] != NULL) { + return GET; + } + else if (strcmp(argv[0], "set") == 0 && argv[1] != NULL && argv[2] != NULL) { + return SET; } else { - // parse command line arguments + return USAGE; + } +} - // Open exising shared memory for io. DO NOT CLEAR. - int *fd = &virt_quad_io_file_descriptor; - *fd = shm_open(VIRT_QUAD_SHARED_MEMORY, O_CREAT | O_RDWR, 0666); - virt_quad_io = mmap(NULL, sizeof(struct VirtQuadIO), PROT_READ | PROT_WRITE, MAP_SHARED, *fd, 0); +int start_virt_quad(char *argv[]) { + int fd; - if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0) { - usage(argv[0]); - exit(0); - } - else if (strcmp(argv[1], "get") == 0 && argv[2] != NULL) { - handle_io_output(argv[2]); - } - else if (strcmp(argv[1], "set") == 0 && argv[2] != NULL && argv[3] != NULL) { - handle_io_input(argv[2], argv[3]); - } - else { - puts("Error in parsing commands"); - usage(argv[0]); - } - return 0; + // Allow making the quad quiet + if (argv[0] != NULL && strcmp(argv[0], "-q") == 0) { + fd = open("/dev/null", O_WRONLY); + close(STDOUT_FILENO); + dup2(STDOUT_FILENO, fd); } - puts("Starting the quad application"); + puts("Starting the virtual quad."); + puts("Open another tab to query and control the virt quad, using the get and set commands."); quad_main(setup_hardware); return 0; } +void open_new_shm_io() { + // Prepare the shared memory for io. Clear memory and initialize. + int *fd = &virt_quad_io_file_descriptor; + *fd = shm_open(VIRT_QUAD_SHARED_MEMORY, O_CREAT | O_RDWR | O_TRUNC, 0666); + ftruncate(*fd, sizeof(struct VirtQuadIO)); + virt_quad_io = mmap(NULL, sizeof(struct VirtQuadIO), PROT_READ | PROT_WRITE, MAP_SHARED, *fd, 0); + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED); + pthread_mutex_init(&virt_quad_io->led_lock, &attr); + pthread_mutex_init(&virt_quad_io->motors_lock, &attr); + pthread_mutex_init(&virt_quad_io->rc_lock, &attr); +} + +void open_existing_shm_io() { + // Open exising shared memory for io. DO NOT CLEAR. + int *fd = &virt_quad_io_file_descriptor; + *fd = shm_open(VIRT_QUAD_SHARED_MEMORY, O_CREAT | O_RDWR, 0666); + virt_quad_io = mmap(NULL, sizeof(struct VirtQuadIO), PROT_READ | PROT_WRITE, MAP_SHARED, *fd, 0); +} + + /** * The user wants to read an output by name. Get the output * and print to stdout. @@ -203,25 +246,79 @@ void print_shm_int(int *value, pthread_mutex_t *lock) { } void usage(char *executable_name) { - printf("Usage: %s [ -h | --help | -q ] [ command ]\n", executable_name); + printf("Usage: %s command [ args ]\n", executable_name); puts("Overview:"); puts(" The virtual quad emulates the behavior of the real quad in the Unix"); puts(" environment. Start the virtual quad in one tab (no arguments), and"); puts(" then control the I/O of the quad through commands."); + puts(""); + puts(" For help on a particular command, pass the command name to the help command"); + puts(" Example:"); + printf(" %s help get\n", executable_name); + puts(""); puts("Commands:"); - puts(" get output"); - puts(" set input value"); - puts("Outpus:"); - puts(" led"); - puts(" motors"); - puts("Inputs:"); - puts(" rc_gear"); - puts(" rc_flap"); - puts(" rc_throttle"); - puts(" rc_pitch"); - puts(" rc_roll"); - puts(" rc_yaw"); - puts("Examples:"); - printf(" %s get led # prints 0 or 1 to stdout\n", executable_name); - printf(" in%s set rc_gear 1 # sets gear to \"on\" \n", executable_name); + puts(" help"); + puts(" get"); + puts(" set"); + puts(" start"); + puts(""); +} + +void help_sub_command(char *argv[]) { + if (argv[2] == NULL) { + usage(argv[0]); + } + else if (strcmp(argv[2], "help") == 0) { + puts("Really?"); + } + else if (strcmp(argv[2], "get") == 0) { + printf("Usage: %s get output_name\n", argv[0]); + puts(""); + puts(" Get an output on the virtual quad, specified by its output_name, and print"); + puts(" to stdout"); + puts(""); + puts(" Possible output names"); + puts(" led"); + puts(" motor1"); + puts(" motor2"); + puts(" motor3"); + puts(" motor4"); + puts(""); + } + else if (strcmp(argv[2], "set") == 0) { + printf("Usage: %s set input_name val\n", argv[0]); + puts(""); + puts(" Set the value of an input on the quad, specified by its input_name"); + puts(""); + puts(" Possible input names"); + puts(" rc_throttle"); + puts(" rc_pitch"); + puts(" rc_roll"); + puts(" rc_yaw"); + puts(" rc_gear"); + puts(" rc_flap"); + puts(" i2c_imu_x"); + puts(" i2c_imu_y"); + puts(" i2c_imu_z"); + puts(" i2c_imu_p"); + puts(" i2c_imu_q"); + puts(" i2c_imu_r"); + puts(" i2c_imu_mag_x"); + puts(" i2c_imu_mag_y"); + puts(" i2c_imu_mag_z"); + puts(""); + } + else if (strcmp(argv[2], "start") == 0) { + printf("Usage: %s start [ -q ]\n", argv[0]); + puts(""); + puts(" Start the virtual quad. Exit using ctrl-c. In order to get and set I/O,"); + puts(" you'll need to open another tab."); + puts(""); + puts(" Flags"); + puts(" q - Keep the quad quiet; don't print logs to the stdout"); + puts(""); + } + else { + usage(argv[0]); + } } diff --git a/website/content/computation_graph.md b/website/content/computation_graph.md new file mode 100644 index 0000000000000000000000000000000000000000..0f955b19ceea85b6bb1455477a75aee37b5b00a4 --- /dev/null +++ b/website/content/computation_graph.md @@ -0,0 +1,15 @@ +Title: A new and flexible way to compute +Date: 2017-02-01 +Authors: Brendan +Category: Highlights +thumbnail: "/images/computation_graph.png" + +The controls team wants to start tuning the controller on the quadcopter, they also want to have the modify the controller in order to better characterize each part. Currently, there is no way to do that except re-write the code on the quad, which bleeds into their development cycle. David took the challenge to solve this issue, and developed the idea of a computation graph. + +<a href="/images/computation_graph.png"> +<figure> +<img src="/images/computation_graph.png"> +</figure> +</a> + +The idea is a typical graph data structure, specifically a directed acyclic multigraph with weighted edges. However, when normally the nodes in a graph represent some data, the nodes in the computation represent functions, and each edge represents a value that gets passed from the "output" of one node to the "input" of another node. Computing the whole graph is simply a matter of performing a depth-first-search algorithm, where the "inputs" of a node represent the node's children. \ No newline at end of file diff --git a/website/content/finding_discrepencies.md b/website/content/finding_discrepencies.md new file mode 100644 index 0000000000000000000000000000000000000000..1e93eed9341080194281c38f97ee1075767f28ac --- /dev/null +++ b/website/content/finding_discrepencies.md @@ -0,0 +1,21 @@ +Title: Tracking Down Discrepancies +Date: 2017-03-28 +Authors: Brendan +Category: Highlights +thumbnail: "/images/discrepancies_bad.png" + +David, Andy, and Tara have been trying to track down discrepancies between the quadcopter controller implementation and the Simulink model. With each discovered discrepancy, the model keeps getting better. Here is one example of where the quad code and model were performing the calculation for the complementary filter differently. + +<a href="/images/discrepancies_bad.png"> +<figure> +<img src="/images/discrepancies_bad.png"> +</figure> +</a> + +This is looking at the output of a simulation in the Simulink model, overlayed with actual logged data from a flight test of the quadcopter. After resolving the discrepency, the model predicts the behavior much more closely. + +<a href="/images/discrepancies_good.png"> +<figure> +<img src="/images/discrepancies_good.png"> +</figure> +</a> \ No newline at end of file diff --git a/website/content/height_stabilization.md b/website/content/height_stabilization.md deleted file mode 100644 index dc28ec032ab293bcd7577f5bd2f72b27f1d88da3..0000000000000000000000000000000000000000 --- a/website/content/height_stabilization.md +++ /dev/null @@ -1,13 +0,0 @@ -Title: Height Stabilization (movie) -Date: 2016-12-04 -Authors: Brendan -Category: Highlights -image: - -The following test flight demonstrates altitude stabilization. Once the pilot puts the quadcopter into autonomous mode, the quadcopter uses its internal control algorithm to maintain its altitude. The pilot still must provide x and y-axis stabilization through the remote control. - -<figure> -<video controls> -<source src="/videos/height_stabilization.mp4"> -</video> -</figure> diff --git a/website/content/images/computation_graph.png b/website/content/images/computation_graph.png new file mode 100644 index 0000000000000000000000000000000000000000..79f6ad79766f226b7101cd6e9e5d0bb62d7ee071 Binary files /dev/null and b/website/content/images/computation_graph.png differ diff --git a/website/content/images/discrepancies_bad.png b/website/content/images/discrepancies_bad.png new file mode 100644 index 0000000000000000000000000000000000000000..b549628ecbaa5e329a677365cc632027a95c274a Binary files /dev/null and b/website/content/images/discrepancies_bad.png differ diff --git a/website/content/images/discrepancies_good.png b/website/content/images/discrepancies_good.png new file mode 100644 index 0000000000000000000000000000000000000000..4506945f7c5dde49542e1349d675f0db28538389 Binary files /dev/null and b/website/content/images/discrepancies_good.png differ diff --git a/website/content/images/model_pitch_rate.png b/website/content/images/model_pitch_rate.png new file mode 100644 index 0000000000000000000000000000000000000000..623f0214a3e4402a6e0b559b1881f9a5d4ae6c66 Binary files /dev/null and b/website/content/images/model_pitch_rate.png differ diff --git a/website/content/model_pitch_rate.md b/website/content/model_pitch_rate.md new file mode 100644 index 0000000000000000000000000000000000000000..5b8c8a5fa7562d3e68f2a97abfa57146d79f87f0 --- /dev/null +++ b/website/content/model_pitch_rate.md @@ -0,0 +1,15 @@ +Title: Simulink Model Update +Date: 2017-02-10 +Authors: Brendan +Category: Highlights +thumbnail: "/images/model_pitch_rate.png" + +Andy and Tara have been working to flesh out the Simulink model of our quadcopter. They have obtained the measurements they need to physically describe the model, now they are finishing up the Simulink model. Here is an example output of the pitch position controller. + +<a href="/images/model_pitch_rate.png"> +<figure> +<img src="/images/model_pitch_rate.png"> +</figure> +</a> + +This controller represents one of many controllers that we consider to be "inner loop" controllers. Right now, the inner loop controllers in the model are stable, like this pitch position controller. The controls team is now working through PID constants to determine a stable controller for the outer loop controllers. \ No newline at end of file diff --git a/website/content/pages/about.md b/website/content/pages/about.md index 3059f09b11e2b4a8d5a26f0e1d8a2995b33ca17e..156c09c8445c343db83cd355c1cdf2d996bd8775 100644 --- a/website/content/pages/about.md +++ b/website/content/pages/about.md @@ -17,8 +17,7 @@ embedded systems. This year, our team is responsible for advancing the modular structure the platform, developing a controls model, and improving the autonomous flight capabilities of the quadcopter. -For additional information regarding the project, please visit the -[supplemental wiki -page][1]. +Team members should consult the [Gitlab project page][1] for technical +documentation and instructions. -[1]: https://wikis.ece.iastate.edu/microcart-senior-design/index.php/2016-2017_Main_Page +[1]: https://git.ece.iastate.edu/danc/MicroCART_17-18 diff --git a/website/themes/notmyidea/templates/base.html b/website/themes/notmyidea/templates/base.html index 455bcb40aee9fc6ac6c167ff43d142bed100ac4f..c4739eed4c5781e4c474fba1537a4a3e3eae71d5 100644 --- a/website/themes/notmyidea/templates/base.html +++ b/website/themes/notmyidea/templates/base.html @@ -36,7 +36,6 @@ <li{% if cat == category %} class="active"{% endif %}><a href="{{ SITEURL }}/{{ cat.url }}">{{ cat }}</a></li> {% endfor %} {% endif %} - <li><a href="https://wikis.ece.iastate.edu/microcart-senior-design/index.php/2016-2017_Main_Page">Wiki</a></li> </ul></nav> </header><!-- /#banner --> {% block content %}