BallBot

Discussion specific to projects ideas and support.
Post Reply
numeras
Posts: 5
Joined: 16 Dec 2010, 18:13

BallBot

Post by numeras »

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);
}
aswin0
Posts: 201
Joined: 29 Sep 2010, 06:58

Re: BallBot

Post by aswin0 »

There is an important difference between the light sensor you used before and the gyro you wan't to use. The light sensor tells you directly how far your bot is out of balance. The gyro does not. It tells you how fast your robot is moving.
(if your robot was a car and Balance was a town, then the light sensor would tell the distance to the town, the gyro would give you the speed of the car).Therefore you cannot change your program directly.
You must first try to translate the "movement" data of your gyro into "location" data. This is not very hard in theory. The gyro gives degrees a second. With integration you can translate this into an angle in degrees: angle= gyro_output * delta_time.
In practice you will encounter all kind of problems, therefore it's best to try to master the gyro in a simpler robot. Try to make a pointer that points straight up no matter how you hold the NXT, this can be done with a simple beam attached to a single motor attached to the NXT.
My blog: nxttime.wordpress.com
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests