Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#41 Segway Support Please !

open
nobody
None
5
2014-08-19
2012-11-19
Arko
No

Hi
I was trying to stabilize segway using NXC and light sensor. As you already has done something. Can you please support !! Its shaking a lot. then fell down. Its using one light sensor.

#define MAX 100 // Maximum Speed
#define MIN 0 // Minimum Speed
#define Kp 3.0 // Proportional Gain PID
#define Ki 3.0 //Integral Gain PID
#define Kd 3.0 // Integral Gain PID

int balance=50; // Initial blanced value of floor

float integral_error=0.0;
float proportional_error = 0.0;
float lasterror=0.0;
float derivative_error= 0.0;
int light_value=0;
float current_error = 0.0;
float total_error = 0.0;
int powerB = 0;
int powerC = 0;

task main(){

SetSensorLight(IN_4);
SetSensorMode(IN_4, SENSOR_MODE_PERCENT);

while(true){

light_value = SENSOR_4;
current_error = SENSOR_4 - balance;

integral_error = integral_error + current_error;
derivative_error = current_error - lasterror;

total_error =((Kp * current_error) + (Ki * integral_error) + (Kd * derivative_error));

powerB = 70 + total_error;
powerC = 70 + total_error;

//powerB=abs(powerB);
//powerC=abs(powerC);

if(powerB < MIN)
powerB = MIN;
if(powerC < MIN)
powerC=MIN;
if(powerB > MAX)
powerB=MAX;
if(powerC > MAX)
powerC=MAX;

if(light_value > balance){

OnFwd(OUT_B, powerB);
OnFwd(OUT_C, powerC);
until(SENSOR_4 == balance);
}

if(light_value < balance){

OnRev(OUT_B, powerB);
OnRev(OUT_C, powerC);
until(SENSOR_4 == balance);
}

lasterror = current_error;

}

}

Discussion

  • Arko
    Arko
    2012-11-19

    Sageway

     
    Attachments