Visual Command Alpha 0.0.0.0.0.1

June 22nd, 2009

Visual Command

I have been playing around with this idea since I graduated in May.  I learned a lot about QT from this project.

It can dynamically create an interface for a command prompt application.

It currently uses check boxes, numerical integer , and strings as inputs.

Files, doubles, and sliders will be next, along with a way to upload/download GUI interfaces to a server.

It was built using QT over the previous month.  Never used Qt before so it was more of a learning experience.

Visual Command Edit ModeVisual Command run Mode

Sam Uncategorized

Calling base function, and base constructor C++

June 17th, 2009

class ParentClass{

ParentClass(){

}

void FunctionA(){

}

}

class ChildClass:ParentClass{

ChildClass():ParentClass(){

}

void FunctionA(){

ParentClass::FunctionA();

}

}

Sam Uncategorized ,

Favorite Applications

June 11th, 2009

Launcy - http://sourceforge.net/projects/launchy/

Launchy is a free windows utility designed to help you forget about your start menu, your desktop icons, and your file manager. Launchy indexes and launches your applications, documents, project files, folders, and bookmarks with just a few keystrokes!

Synergy - http://sourceforge.net/projects/synergy2/

Synergy lets you easily share a single mouse and keyboard between multiple computers with different operating systems without special hardware. It’s intended for users with multiple computers on their desk since each system uses its own display.

Sam Uncategorized

Speed Function Prototypes vs Switch vs if/else if statements

March 19th, 2009

When implimenting a state machine in c++ code it could be implimented using a Function Prototypes, Case /Switch statements, or If / Else if structures.  What is faster though?

I ran a couple of tests on Visual studio 2005.

book1_10149_image001

Function Prototypes are always slower than case statements.

If statements are only fastest when less than6 states are used.

Here is the quick and dirty code for testing.

Speed test code file

Sam Uncategorized

Static class members

March 18th, 2009

#include “stdafx.h”
#include <iostream>
#include <iomanip>
using namespace std;

class test{
public:
void hi(){
static int i=0;
cout << i++<<endl;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
test A;
test B;

A.hi(); //prints 0
A.hi();// prints 1
B.hi();// prints 2
int x;
cin >>x;
return 0;
}

Sam Uncategorized

Function Prototypes Example

March 18th, 2009

#include <iostream>
#include <iomanip>
using namespace std;

void Add(int x,int y);
void Sub(int x,int y);
void (* fun)(int x,int y);
int _tmain(int argc, _TCHAR* argv[])
{
int x;
cout <<”Test\n”;

fun = Add;
fun(1,2);
fun = Sub;
fun(1,2);
cin >> x;
return 0;
}
void Add(int x,int y){
cout << x+y<<endl;
}
void Sub(int x,int y){
cout << x-y<<endl;
}

Sam Uncategorized

Random Math Equations

February 24th, 2009

Expected Value

First moment

\bar{X} = E[ X ] = \int_{-\infty}^{\infty}{x f(x) dx}

Second moment

\bar{X^2} = E[ X^2 ] = \int_{-\infty}^{\infty}{x^2 f(x) dx}

Nth Moment

\bar{X^n} = E[ X^n ] = \int_{-\infty}^{\infty}{x^n f(x) dx}

Variance

\sigma^2 = \overline{(X-\bar{X})^2} = E[(X-\overline{X})^2] = \int_{-\infty}^{\infty}{(x-\bar{X})^2 f(x) dx}

Autocorrelation

R_x(t_1,t_2) = E[X_1 X_2] = \int_{-\infty}^{\infty} dx_1 \int_{-\infty}^{\infty}{x_1 x_2 f(x_1,x_2) d x_2}

Sam Uncategorized

Phase Margin Design.

February 17th, 2009

It is often useful to have your phase margin peak at your cross over frequency.  The following technique works well when you know your noise margin
W_c = Cross over frequency

W_P = pole

W_Z = zero

An easy way to calculate the position of your poles and zeros is as follows.

1. Pick your cutoff frequency as close to your nosise margin as possible.

2. Calculate the contributing phase from the poles at this location.

tan(\frac{W_c}{W_{P1}}) + tan(\frac{W_c}{W_{P2}}) + ....+ tan(\frac{W_c}{W_{Pn}})

3. Subtract the phase from any contributing zeros in the plant.

tan(\frac{W_c}{W_{Z1}}) + tan(\frac{W_c}{W_{Z2}}) + ....+ tan(\frac{W_c}{W_{Zn}})

4. Add your desired phase margin and subtract 180.(Phase margin is the distance above 180 degrees.)  We will call this number P.

5. If the P is greater than 80 then two zeros should be added to the system.  If the calculated number is above 160 then 3 zeros should be added.  Let the number of zeros to be added be called N.

6.  Solve for the position to place your zeros using the following equation.

tan(\frac{W_C}{W_Z}) = \frac{P}{N}

admin Control Theory , ,

Printing/Display in C on a 8051 Emac board.

February 8th, 2009

Printf is defaulted to be displayed to the serial port on an 8051 board.  Printf works by calling putchar repeatably in order to display a string.  In order to change the location that printf prints to one needs to override the putchar function.  This can be done by adding putchar.c to your project, and then customizing the function to send the character to a different serial port, or to the LCD display.

Attached is a demo version of putchar to display to the LCD.

putchar.c

admin Uncategorized

Calculate Phase Margin

February 7th, 2009

Zeros - Poles

Phase margin is the phase distance from -180 degrees at the location of the cross over frequency.

The phase of a system at a radian/sec of Wc can be found as follows

Phase = \sum_{a=1}^n (tan^{-1}\frac{W_c}{Z_a}) - \sum_{a=1}^m( tan^{-1}\frac{W_c}{P_a})

Where Za is a zero placement in radians / sec, and Pa is pole placement in radians/sec poles and zeros at an origin are -90, +90 degrees of phase.

The phase margin is equal to Phase + 180.

In example if the phase at the cross over frequency was -130 degrees then the phase margin would be -130 +180 = 50.

Phase margin is used to specify stability.  A phase margin greater than 0 is considered to be stable, though in practice the phase margin should be greater than 30 degrees to keep overshoot low.

admin Control Theory