Skip to content
Snippets Groups Projects
Commit 82a470e8 authored by bbartels's avatar bbartels
Browse files

quad: delete unused files (13 files?!?!)

resolves #16
parent 560bbde2
No related branches found
No related tags found
No related merge requests found
Showing
with 0 additions and 650 deletions
/*
* 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;
}
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.
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "log_data.h" #include "log_data.h"
#include "sensor_processing.h" #include "sensor_processing.h"
#include "quadposition.h"
#include "type_def.h" #include "type_def.h"
/** /**
......
/*
* 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;
}
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#define _CONTROLLERS_H #define _CONTROLLERS_H
#include "util.h" #include "util.h"
#include "quadposition.h"
/** /**
* *
......
#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 */
/*
* 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_ */
/*
* 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;
}
*/
/*
* 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_ */
/*
* 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_ */
/*
* 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;
}
/*
* 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_ */
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "sensor_processing.h" #include "sensor_processing.h"
#include "control_algorithm.h" #include "control_algorithm.h"
#include "send_actuator_commands.h" #include "send_actuator_commands.h"
#include "update_gui.h"
#include "communication.h" #include "communication.h"
#include "mio7_led.h" #include "mio7_led.h"
...@@ -71,8 +70,6 @@ int quad_main(int (*setup_hardware)(hardware_t *hardware_struct)) ...@@ -71,8 +70,6 @@ int quad_main(int (*setup_hardware)(hardware_t *hardware_struct))
else { else {
kill_motors(&(structs.hardware_struct.motors)); kill_motors(&(structs.hardware_struct.motors));
} }
// update the GUI
update_GUI(&(structs.log_struct));
if (!this_kill_condition) { if (!this_kill_condition) {
// Log the data collected in this loop // Log the data collected in this loop
......
#ifndef _QUADPOSITION_H
#define _QUADPOSITION_H
#endif /* _QUADPOSITION_H */
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "log_data.h" #include "log_data.h"
#include "user_input.h" #include "user_input.h"
#include "packet_processing.h"
#include "hw_iface.h" #include "hw_iface.h"
/** /**
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "log_data.h" #include "log_data.h"
#include "sensor.h" #include "sensor.h"
#include "conversion.h" #include "conversion.h"
#include "quadposition.h"
#include "sensor_processing.h" #include "sensor_processing.h"
#include "timer.h" #include "timer.h"
#include <math.h> #include <math.h>
......
/*
* update_gui.c
*
* Created on: Feb 20, 2016
* Author: ucart
*/
#include "update_gui.h"
int update_GUI(log_t* log_struct)
{
return 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_ */
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