Skip to content
Snippets Groups Projects
Commit 079f2140 authored by bbartels's avatar bbartels
Browse files

Merge branch 'master' of git.ece.iastate.edu:danc/MicroCART_17-18

parents 40840e6b 0c1e3650
No related branches found
No related tags found
No related merge requests found
*.asv
\ No newline at end of file
close all; clear all; clc;
filename = 'imu.csv';
data = load_IMU_data_from_csv( filename ) ;
t = data.t;
ax = data.ax;
ay = data.ay;
az = data.az;
gx = data.gx;
gy = data.gy;
gz = data.gz;
% analyze the noise (deviation from mean) on each axis and compare the
% emperical distribution to one generated from a quantized Gaussian
% distrubtuion with the same variance.
quantized_accel_noise_gauss_anal( ax , 'x-axis')
quantized_accel_noise_gauss_anal( ay , 'y-axis')
quantized_accel_noise_gauss_anal( az , 'z-axis')
\ No newline at end of file
function data = load_IMU_data_from_csv( filename )
% load_IMU_data_from_csv load data from csv file into workspace
%
%SYNTAX
% data = load_IMU_data_from_csv( filename )
%
%DESCRIPTION
% ...to be written...
%
%
%Inputs:
% filename - string specifying the file
%
%Options:
% none
%
%Outputs:
% data - IMU data loaded into a structure (specify more later)
%
%EXAMPLES
%
%NOTES
% This function currently assumes the csv format that was used as of the
% date: 11/15/2016 (m/d/y)
%
%AUTHORS
% Matt Rich - m87rich@iastate.edu
%
%DEVELOPERS
%
%
%DEVELOPMENT NOTES
%
% dates are in m-d-y format
%
% Initial bare bones function.
% - Matt Rich 11-15-2016
%
delimiter = ',';
formatSpec = '%f%f%f%f%f%f%f%[^\n\r]';
fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'EmptyValue' ,NaN, 'ReturnOnError', false);
fclose(fileID);
data.t = dataArray{:, 1};
data.ax = dataArray{:, 2};
data.ay = dataArray{:, 3};
data.az = dataArray{:, 4};
data.gx = dataArray{:, 5};
data.gy = dataArray{:, 6};
data.gz = dataArray{:, 7};
end
% function microcart_imu_analysis_1
close all; clc;
filename = 'imu.csv';
delimiter = ',';
formatSpec = '%f%f%f%f%f%f%f%[^\n\r]';
fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'EmptyValue' ,NaN, 'ReturnOnError', false);
fclose(fileID);
t = dataArray{:, 1};
ax = dataArray{:, 2};
ay = dataArray{:, 3};
az = dataArray{:, 4};
gx = dataArray{:, 5};
gy = dataArray{:, 6};
gz = dataArray{:, 7};
clearvars filename delimiter formatSpec fileID dataArray ans;
% magnitude of acceleration in gs
a = ( ax.^2 + ay.^2 + az.^2 ).^0.5 ;
% magnitude of deviation from ideal
ea1 = 1 - a ;
% magnitude of deviation from mean
ea2 = a - mean(a) ;
% RMS error
ea1rms = sqrt(1/length(ea1)*(ea1')*ea1) ;
ea2rms = sqrt(1/length(ea2)*(ea2')*ea2) ;
subplot(3,1,1);
plot(t, a , t , ones(length(t),1)); axis([min(t),max(t),min([a;1])-0.01,max([a;1])+0.01]); grid;
xlabel('Time (s)'); ylabel('Acceleration (gs)');
legend('Measured','Ideal');
subplot(3,1,2);
plot(t, ea1 ); axis([min(t),max(t),min(ea1)-0.01,max(ea1)+0.01]); grid;
xlabel('Time (s)'); ylabel('Error From Ideal (gs)');
subplot(3,1,3);
plot(t, ea2 ); axis([min(t),max(t),min(ea2)-0.01,max(ea2)+0.01]); grid;
xlabel('Time (s)'); ylabel('Error From Mean (gs)');
%
figure;
X = fft(ea2);
N = length(ea2);
fs = 1/(t(2)-t(1));
F = ([-N/2:N/2-1]/N)*fs; %frequency axis for plotting FFTs
% subplot(2,1,1);
plot(F,fftshift(abs(X))); grid;
xlabel('frequency (Hz)');
ylabel(['|FFT(x)|']);
% subplot(2,1,2);
% plot(F,20*log10(fftshift(abs(X)))); grid;
% xlabel('frequency (Hz)');
% ylabel('|FFT(x)| dB');
suptitle('x = Error From Mean (gs)');
eax = ax - mean(ax);
vx = var(ax);
sigmax = sqrt(vx);
figure;
bins = unique(eax) ;
dbins = bins(2)-bins(1); % the quantization levels consistent
bins_right = bins + dbins/2;
bins_left = bins - dbins/2;
cgauss_right = normcdf(bins_right,0,sigmax);
cgauss_left = normcdf(bins_left,0,sigmax);
empf = length(eax)*(cgauss_right-cgauss_left);
stairs(bins_left,empf,'r','LineWidth',1) ;
xlabel('Error From Mean (gs)');
ylabel('Occurences');
grid;
hold on;
h = hist(eax,bins);
stem(bins,h);
legend(['Quantized Gaussian Noise: N(0,',num2str(vx),')'],'Emperical Distribution')
quantized_accel_noise_gauss_anal( ax )
% end
function varargout = quantized_accel_noise_gauss_anal( a , axis )
% quantized_accel_noise_gauss_anal analysis for quantized acelerometer data
%
%SYNTAX
% quantized_accel_noise_gauss_anal( a , axis )
%
%DESCRIPTION
% ...to be written...
%
%
%Inputs:
% a - vector of a single axis accelerometer reading
% axis - string specifying the axis label
%
%Options:
% none
%
%Outputs:
% none
%
%EXAMPLES
%
%NOTES
% This function is only really meaningful for a static (not moving) test.
%
%AUTHORS
% Matt Rich - m87rich@iastate.edu
%
%DEVELOPERS
%
%
%DEVELOPMENT NOTES
%
% dates are in m-d-y format
%
% Initial bare bones function.
% - Matt Rich 11-15-2016
%
mu = mean(a);
v = var(a);
sigma = sqrt(v);
ea = a - mu;
mue = mean(ea); %calculate the mean of the error from mean
figure;
bins = unique(ea) ;
dbins = bins(2)-bins(1); % assuming the quantization levels consistent
bins_right = bins + dbins/2;
bins_left = bins - dbins/2;
cgauss_right = normcdf(bins_right,mue,sigma);
cgauss_left = normcdf(bins_left,mue,sigma);
emp_dist = length(ea)*(cgauss_right-cgauss_left);
stairs(bins_left,emp_dist,'r','LineWidth',1) ;
xlabel('Error From Mean (gs)');
ylabel('Occurences');
grid;
hold on;
h = hist(ea,bins);
stem(bins,h);
legend(['Quantized Gaussian Noise: N(',num2str(mue),',',num2str(v),')'],'Emperical Distribution');
title(['Accelerometer deviation from mean on ',axis]);
end
This diff is collapsed.
......@@ -567,6 +567,7 @@ static void client_recv(int fd) {
}
buffer[len_pre + r] = '\0';
int index = 0;
/* Parse buffer and handle commands */
while (1) {
/* not using strtok because reasons */
......@@ -584,31 +585,20 @@ static void client_recv(int fd) {
break;
}
buffer[newline] = '\0';
printf("Client(%d) : '%s'\n",fd, buffer);
unsigned char * packet;
// printf("newline =%li, Client sent: '%s'\n", newline, buffer);
if(formatCommand(buffer, &packet) == -1) {
printf("Could not recognize command '%s'\n", buffer);
} else {
int datalen = (packet[6] << 8) | (packet[5]);
writeQuad((char *) packet, datalen +7);
}
int datalen = (packet[6] << 8) | (packet[5]);
printf("data length = %d\n", datalen);
printf("packet = '");
for (int i = 0; i < datalen+7+1; ++i)
{
printf("%x ", packet[i]);
}
printf("'\n");
writeQuad((char *) packet, datalen +7);
//free(packet);
char * rest = &buffer[newline] + 1;
size_t restLen = (strlen(rest) == 0) ? 1 : strlen(rest);
/* Delete parsed data and move the rest to the left */
memmove(buffer, rest, restLen);
break;
memmove(buffer, rest, restLen + 1);
}
}
......
......@@ -182,7 +182,7 @@ int formatPacket(metadata_t *metadata, void *data, unsigned char **formattedComm
{
data_checksum ^= (*formattedCommand)[i];
}
printf("checksum = %x\n", (unsigned )data_checksum);
(*formattedCommand)[7 + metadata->data_len] = data_checksum;
return 0;
......
#include <stdio.h>
#include <string.h>
#include <err.h>
#include <unistd.h>
#include <libgen.h>
#include "cli.h"
......@@ -12,7 +12,7 @@ int main(int argc, char **argv)
int i , useSymlink = 0;
struct backend_conn *conn;
command = argv[0];
command = basename(argv[0]);
for(i = 0; i < MAX_COMMANDS; ++i) {
if (strncmp(command, commandNames[i], strlen(commandNames[i])) == 0)
{
......@@ -43,12 +43,11 @@ int main(int argc, char **argv)
}
if(useSymlink) {
//TODO Call correct command function pointer with (argv[1] ... argc[argc])
(*cli_functions[cmdID]) (conn, argc, &argv[0]);
}else {
(*cli_functions[0]) (conn, argc-1, &argv[1]);
(*cli_functions[cmdID]) (conn, argc-1, &argv[1]);
}
sleep(1);
ucart_backendDisconnect(conn);
return 0;
}
\ No newline at end of file
}
......@@ -6,7 +6,6 @@
// #include "cli_setpid.h"
#include "cli_getpid.h"
// #include "cli_getimu.h"
enum CommandNameIds{
CMD_MONITOR,
CMD_SETPID,
......@@ -31,4 +30,4 @@ static char* commandNames[MAX_COMMANDS] = {
};
#endif
\ No newline at end of file
#endif
......@@ -75,6 +75,8 @@ int getValues(struct backend_conn * conn, struct frontend_pid_data * pid_data) {
return 1;
}
return 0;
switch(pid_data->pid) {
case PITCH :
printf("Pitch Constants: P = %f\tI = %f\tD = %f\n",
......
......@@ -22,22 +22,23 @@
int frontend_getpid(
struct backend_conn * conn, struct frontend_pid_data * pid_data) {
char line[100];
char line[100] = "";
switch (pid_data->pid) {
case PITCH :
strncpy(line, "getpitchp\ngetpitchd\n\0", 21);
strncpy(line, "getpitchp\ngetpitchd\n", 20);
break;
case ROLL :
strncpy(line, "getrollp\ngetrolld\n\0", 19);
strncpy(line, "getrollp\ngetrolld\n", 18);
break;
case YAW :
strncpy(line, "getyawp\ngetyawd\n\0", 17);
strncpy(line, "getyawp\ngetyawd\n", 17);
break;
default :
return 1;
}
int size;
printf("sending '%s'\n",line);
if((size = ucart_backendWrite(conn, line)) < 0 ) {
return 1;
}
......
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