BallBot
Posted: 16 Dec 2010, 18:32
Hello,
I have a problem with program ballbot. My idea is to make first segway with one gyro and make this work. After build ballbot and do this i two axes. I'm using gyro sensors. I had made before segway with light sensor and program.
Program had PID control. I don't have any idea how made segway with gyro and use similar PID control.
I tried change code form http://www.hitechnic.com/blog/gyro-sensor/htway but I won't to know if somebody have any easier ideas to make this code.
That look my code for segway with light sensor:
#define sensor Sensor(IN_3)
#define Kp 25
#define Ki 2
#define Kd 10
task main()
{
int error= 0;
int prev_error = 0;
int middle;
int now;
int calk;
int rozn;
int power;
int P;
int I;
int D;
int PID;
SetSensorLight(IN_3);
SENSOR_TYPE_LIGHT_ACTIVE;
Wait(1000);
TextOut(1,LCD_LINE1,"SET");
middle = sensor;
NumOut(25,LCD_LINE1,middle);
Wait(1000);
while (true)
{
now = sensor;
TextOut(40,LCD_LINE1,"| TERAZ");
NumOut(85,LCD_LINE1,teraz);
//P
error = middle - now;
// I
calk = calk + error;
//D
rozn = error - prev_error;
//PID
D = Kd * rozn;
I = Ki * calk;
P = Kp * error;
pop_blad = blad;
// PID
PID = (P+I+D)/2;
power=abs(PID);
if (PID < 0)
{
OnFwd(OUT_BC, power);
TextOut(1,LCD_LINE7,"pid<0");
NumOut(55,LCD_LINE7, power);
}
else if (PID > 0)
{
OnRev(OUT_BC, power);
TextOut(1,LCD_LINE8,"pid>0");
NumOut(55,LCD_LINE8, power);
}
I have a problem with program ballbot. My idea is to make first segway with one gyro and make this work. After build ballbot and do this i two axes. I'm using gyro sensors. I had made before segway with light sensor and program.
Program had PID control. I don't have any idea how made segway with gyro and use similar PID control.
I tried change code form http://www.hitechnic.com/blog/gyro-sensor/htway but I won't to know if somebody have any easier ideas to make this code.
That look my code for segway with light sensor:
#define sensor Sensor(IN_3)
#define Kp 25
#define Ki 2
#define Kd 10
task main()
{
int error= 0;
int prev_error = 0;
int middle;
int now;
int calk;
int rozn;
int power;
int P;
int I;
int D;
int PID;
SetSensorLight(IN_3);
SENSOR_TYPE_LIGHT_ACTIVE;
Wait(1000);
TextOut(1,LCD_LINE1,"SET");
middle = sensor;
NumOut(25,LCD_LINE1,middle);
Wait(1000);
while (true)
{
now = sensor;
TextOut(40,LCD_LINE1,"| TERAZ");
NumOut(85,LCD_LINE1,teraz);
//P
error = middle - now;
// I
calk = calk + error;
//D
rozn = error - prev_error;
//PID
D = Kd * rozn;
I = Ki * calk;
P = Kp * error;
pop_blad = blad;
// PID
PID = (P+I+D)/2;
power=abs(PID);
if (PID < 0)
{
OnFwd(OUT_BC, power);
TextOut(1,LCD_LINE7,"pid<0");
NumOut(55,LCD_LINE7, power);
}
else if (PID > 0)
{
OnRev(OUT_BC, power);
TextOut(1,LCD_LINE8,"pid>0");
NumOut(55,LCD_LINE8, power);
}