by alasi89 » Wed Sep 12, 2012 6:51 pm
by alasi89
Wed Sep 12, 2012 6:51 pm
After 7 months working, I put my graduation project between your hands,
the Arduino mega 2560 board works as the controller of the stabilazation system, while the cm5 controls the robotic car. the tilt angle comes from the acceleration sensor witch is fixed on the top of the Arduino board, the sensor's signal was filtered and underwent linearity adjustment process to get the correct tilt angle between the car plane with respect to the gravity vector.
this is the video segment :
http://www.youtube.com/watch?v=xmYzwiYQERg&feature=player_detailpage
the code in java for the arduino board :
- Code: Select all
/* Auther : Eng. Alaa Alasi
All Rights reserved for Mechatronics Engineering Department.
University of Aleppo.
Syrian Arab Repuplic.
This code is in the public domain.*/
#include <CDS5500>
CDS5500 SERVO;
word z ,z_k_1 , z_k_3 , z_k_2 ;
word y,y_k_1,y_k_3 , y_k_2 ;
word z_avg , y_avg;
float x,Y;
int Sdelay = 2 ;
int Adelay = 10 ;
int z_zero;
int Tsam=0.0001;
int Wcut=30;
int i;
word sampels=40;
void setup(){
Serial.begin(1000000); //init Serial baudrate for the servo command
Serial3.begin(9600); // serial communaction with PC
analogReference(INTERNAL2V56); // ADC Vref init
pinMode(2, OUTPUT); // RX Buffer
pinMode(3, OUTPUT); // tx
pinMode(13, OUTPUT);
digitalWrite(3, HIGH); // TX Buffer enable
}
void loop(){
digitalWrite(13, HIGH); // Flag to measure the sampling time 1
//Digital filtring ::
z_avg = analogRead(1); // 10 KHz ... 100 u sec
y_avg = analogRead(3);
for(i = 0;i <sampels; i++){
z_avg = z_avg + analogRead(1);
y_avg = y_avg + analogRead(3);
}
z_avg = z_avg/sampels;
y_avg = y_avg/sampels;
// Normalization
float(x);
x=z_avg ;
Y=y_avg ;
x=x-340; // bias in sensor signal: angle (0)= 0.85 volt = 340 in decimal
Y=Y-340;
x=(x/640)*1023; // max value: angle(180) = 2.45 volt = 980 - 340
Y=(Y/640)*1023;
x = (512 - x)/512; // cos (z) from -1 to 1
Y = (512 - Y)/512;
// LINERIZATION :
x = (3.1416/2) - (x + (0.1666 *pow(x,3))+(0.075*pow(x,5))+0.0446*pow(x,7)+0.03*pow(x,9)+0.0223*pow(x,11)+0.0173*pow(x,13)+0.0139*pow(x,15)+0.01151*pow(x,17)) ; // arc cos z formula
Y = (3.1416/2) - (Y + (0.1666 *pow(Y,3))+(0.075*pow(Y,5))+0.0446*pow(Y,7)+0.03*pow(Y,9)+0.0223*pow(Y,11)+0.0173*pow(Y,13)+0.0139*pow(Y,15)+0.01151*pow(Y,17)) ;
x=x*180/3.1416; // converting Radian to degrees , angle rang [0 180]
Y=Y*180/3.1416;
x=x+60; // addin 60 digree bias for the range to be [60 240]
Y=Y+60;
x=(x/240)*818; // converting from digree to decimal rang [205 818]
Y=(Y/240)*818;
Y=1023-Y; // invers the Direction of Rotation
word(x);
word(Y);
// SERVO COMMAND :
SERVO.WritePos(1,x,0);// Servo ID:1, rotate to the position:0x2FF, rotate speed:0x1FF (Roll Angle)
SERVO.WritePos(6,512,0);
SERVO.WritePos(5,Y,0); // Roll angle
SERVO.WritePos(13,Y,0);
//delay(1);
// SENDING DADTA TO OBSERV SENSOR SIGNSL :
Serial3.println(x,DEC);
Serial3.print(",");
digitalWrite(13, LOW); // sampling time flag low
}
I want to take advantage of this occasion to tell you that we are being killed and tormented every day in Syria from the Syrian dictator Bashar Al Assad .
SOS
After 7 months working, I put my graduation project between your hands,
the Arduino mega 2560 board works as the controller of the stabilazation system, while the cm5 controls the robotic car. the tilt angle comes from the acceleration sensor witch is fixed on the top of the Arduino board, the sensor's signal was filtered and underwent linearity adjustment process to get the correct tilt angle between the car plane with respect to the gravity vector.
this is the video segment :
http://www.youtube.com/watch?v=xmYzwiYQERg&feature=player_detailpage
the code in java for the arduino board :
- Code: Select all
/* Auther : Eng. Alaa Alasi
All Rights reserved for Mechatronics Engineering Department.
University of Aleppo.
Syrian Arab Repuplic.
This code is in the public domain.*/
#include <CDS5500>
CDS5500 SERVO;
word z ,z_k_1 , z_k_3 , z_k_2 ;
word y,y_k_1,y_k_3 , y_k_2 ;
word z_avg , y_avg;
float x,Y;
int Sdelay = 2 ;
int Adelay = 10 ;
int z_zero;
int Tsam=0.0001;
int Wcut=30;
int i;
word sampels=40;
void setup(){
Serial.begin(1000000); //init Serial baudrate for the servo command
Serial3.begin(9600); // serial communaction with PC
analogReference(INTERNAL2V56); // ADC Vref init
pinMode(2, OUTPUT); // RX Buffer
pinMode(3, OUTPUT); // tx
pinMode(13, OUTPUT);
digitalWrite(3, HIGH); // TX Buffer enable
}
void loop(){
digitalWrite(13, HIGH); // Flag to measure the sampling time 1
//Digital filtring ::
z_avg = analogRead(1); // 10 KHz ... 100 u sec
y_avg = analogRead(3);
for(i = 0;i <sampels; i++){
z_avg = z_avg + analogRead(1);
y_avg = y_avg + analogRead(3);
}
z_avg = z_avg/sampels;
y_avg = y_avg/sampels;
// Normalization
float(x);
x=z_avg ;
Y=y_avg ;
x=x-340; // bias in sensor signal: angle (0)= 0.85 volt = 340 in decimal
Y=Y-340;
x=(x/640)*1023; // max value: angle(180) = 2.45 volt = 980 - 340
Y=(Y/640)*1023;
x = (512 - x)/512; // cos (z) from -1 to 1
Y = (512 - Y)/512;
// LINERIZATION :
x = (3.1416/2) - (x + (0.1666 *pow(x,3))+(0.075*pow(x,5))+0.0446*pow(x,7)+0.03*pow(x,9)+0.0223*pow(x,11)+0.0173*pow(x,13)+0.0139*pow(x,15)+0.01151*pow(x,17)) ; // arc cos z formula
Y = (3.1416/2) - (Y + (0.1666 *pow(Y,3))+(0.075*pow(Y,5))+0.0446*pow(Y,7)+0.03*pow(Y,9)+0.0223*pow(Y,11)+0.0173*pow(Y,13)+0.0139*pow(Y,15)+0.01151*pow(Y,17)) ;
x=x*180/3.1416; // converting Radian to degrees , angle rang [0 180]
Y=Y*180/3.1416;
x=x+60; // addin 60 digree bias for the range to be [60 240]
Y=Y+60;
x=(x/240)*818; // converting from digree to decimal rang [205 818]
Y=(Y/240)*818;
Y=1023-Y; // invers the Direction of Rotation
word(x);
word(Y);
// SERVO COMMAND :
SERVO.WritePos(1,x,0);// Servo ID:1, rotate to the position:0x2FF, rotate speed:0x1FF (Roll Angle)
SERVO.WritePos(6,512,0);
SERVO.WritePos(5,Y,0); // Roll angle
SERVO.WritePos(13,Y,0);
//delay(1);
// SENDING DADTA TO OBSERV SENSOR SIGNSL :
Serial3.println(x,DEC);
Serial3.print(",");
digitalWrite(13, LOW); // sampling time flag low
}
I want to take advantage of this occasion to tell you that we are being killed and tormented every day in Syria from the Syrian dictator Bashar Al Assad .
SOS