View unanswered posts | View active topics It is currently Tue Sep 30, 2014 6:46 am






Reply to topic  [ 133 posts ]  Go to page Previous  1 ... 3, 4, 5, 6, 7, 8, 9  Next
Endcoders better? 
Author Message
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Endcoders better?
Team2844 wrote:
It runs the 12 inches.. stops.. then runs 56 inches just forward, ignoring the sensor. Is that where i need to tune it?

What do you mean by "ignoring the sensor"? Where was the IR beacon in relation to the robot? Was it right in front of it? Was it in front but off to the left or right side? In any case, try to bump g_turnIRKp up to 50. I think Kp was too weak. This will show you if the robot saw the sensor.


Fri Apr 22, 2011 8:09 pm
Profile
Novice

Joined: Mon Oct 18, 2010 9:31 pm
Posts: 86
Post Re: Endcoders better?
I have tried the beacon in different areas... but even with the kp at up to 50, it will still just run forward. It just runs the 56 inches forward, and stops... not turning at all toward the beacon.


Fri Apr 22, 2011 8:21 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Endcoders better?
Is you beacon turned on? Put the following debug line in the code:
Code:
void DriveIRTask()
{
    if (g_driveIREnabled)
    {
        float driveErr = g_driveTarget - GetDriveDistance();

        if (abs(driveErr) > g_driveTolerance)
        {
            //
            // Simple proportional PID control.
            // Limit the outpout to the range of -100 to 100 for drive
            // and -50 to 50 for turn
            //
            int drivePower = BOUND((int)(g_driveKp*driveErr), -100, 100);
            float turnErr = IRGetACDir(IRSeeker2) - 2.0;  //use zone 2 as the straight ahead zone
            nxtDisplayTextLine(<free line>, "IR=%f", IRGetACDir(IRSeeker2));
            int turnPower = BOUND((int)(g_turnIRKp*turnErr), -50, 50);
            motor[motorLeft] = BOUND(drivePower + turnPower, -100, 100);
            motor[motorRight] = BOUND(drivePower - turnPower, -100, 100);
        }
        else
        {
            motor[motorLeft] = 0;
            motor[motorRight] = 0;
            g_driveIREnabled = false;
        }
   }
}


Fri Apr 22, 2011 8:24 pm
Profile
Novice

Joined: Mon Oct 18, 2010 9:31 pm
Posts: 86
Post Re: Endcoders better?
The beacon is on, and the sensor is on. With that line of code, it see the beacon, changing when it hits the different zones, but will not turn at all.


Fri Apr 22, 2011 8:51 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Endcoders better?
Just want to make sure... So if the beacon is right in front, you should read something around 2.0, right? If the beacon is to the left, you should read something less than 2.0. If the beacon is on the right, you should read something greater than 2.0. If that's the case, add anther debug line:
Code:
void DriveIRTask()
{
    if (g_driveIREnabled)
    {
        float driveErr = g_driveTarget - GetDriveDistance();

        if (abs(driveErr) > g_driveTolerance)
        {
            //
            // Simple proportional PID control.
            // Limit the outpout to the range of -100 to 100 for drive
            // and -50 to 50 for turn
            //
            int drivePower = BOUND((int)(g_driveKp*driveErr), -100, 100);
            float turnErr = IRGetACDir(IRSeeker2) - 2.0;  //use zone 2 as the straight ahead zone
            nxtDisplayTextLine(<free line>, "IR=%f", IRGetACDir(IRSeeker2));
            int turnPower = BOUND((int)(g_turnIRKp*turnErr), -50, 50);
            nxtDisplayTextLine(<free line>, "Drv=%d,Turn=%d", drivePower, turnPower);
            motor[motorLeft] = BOUND(drivePower + turnPower, -100, 100);
            motor[motorRight] = BOUND(drivePower - turnPower, -100, 100);
        }
        else
        {
            motor[motorLeft] = 0;
            motor[motorRight] = 0;
            g_driveIREnabled = false;
        }
   }
}


Fri Apr 22, 2011 8:56 pm
Profile
Novice

Joined: Mon Oct 18, 2010 9:31 pm
Posts: 86
Post Re: Endcoders better?
The sensor is set up right... to the left of the sensor is less than 2.0, to the right if the sensor, is more than 2.0.

OK, so i put that in... and tested a few things, all about 50-60 inches from the robot... first, tested it without the ir beacon and it started curving to the left over 30 inches or so before it hit the wall. Next, tested it with the beacon right in front of the robot, and it started to curve left over about 20 inches about 30 degrees, and drove forward until the 56 inches was reached. I tested it to the right side of the robot, and it didn't even pick it up, just did the same thing that the no beacon test did. I tested it to the left of the robot, and it curved about 45 degrees over 20 inches, and then ran the rest of the 56 inches forward. I was able to look at the new line, and the numbers ranged in the drive from 20-35 and the turn was usual -7ish.


Last edited by Team2844 on Fri Apr 22, 2011 10:15 pm, edited 1 time in total.



Fri Apr 22, 2011 10:08 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Endcoders better?
Disable the motors by commenting out the motor[leftMotor] and motor[rightMotor] lines in the DriveIRTask so that the robot won't really move. Then put the beacon on the left side and tell me what numbers you get (IR, Drv and Turn) on the LCD screen. Do that again when the beacon is right in front and again with the beacon on the right. From the numbers, I can tell what's wrong with it.


Fri Apr 22, 2011 10:11 pm
Profile
Novice

Joined: Mon Oct 18, 2010 9:31 pm
Posts: 86
Post Re: Endcoders better?
left side below 2.0, drive 100, turn -50

front 2.0, drive 100, turn 0

right above 2.0, drive 100, turn 50


Last edited by Team2844 on Fri Apr 22, 2011 10:24 pm, edited 1 time in total.



Fri Apr 22, 2011 10:21 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Endcoders better?
What about the drive and turn power? I am interested in the value to see what the wheel powers look like? If possible tell me the exact numbers. So I can calculate based on them.


Fri Apr 22, 2011 10:23 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Endcoders better?
So if the beacon is on the right, the drive power is 100 turn is 50 means that the left wheel will get BOUND(150, -100, 100) which will give you 100. And the right wheel will get BOUND(50, -100, 100) which will give you 50. Left 100 and right 50 will turn the robot to the right. So it should work. Although I can see the left wheel power is saturated. You may want to change the left motor line to the following to give it a little margin. BTW, please tell me the exact value of IR. What exactly is above 2.0 and below 2.0?
Code:
            int drivePower = BOUND((int)(g_driveKp*driveErr), -70, 70);


Fri Apr 22, 2011 10:29 pm
Profile
Novice

Joined: Mon Oct 18, 2010 9:31 pm
Posts: 86
Post Re: Endcoders better?
^ ok... will try that.

left side, 1.000 drive 100, turn -50

moving toward middle, gets higher on zone, drive 100, turn going toward 0

middle, 2.000 drive 100, turn 0

moving toward the right, gets higher on zone, drive 100, going higher

right side, 3.000 drive 100, turn 50

it usual goes right to the whole numbers.


Fri Apr 22, 2011 10:31 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Endcoders better?
From the numbers you mentioned, you can see that it should respond correctly, can't you?


Fri Apr 22, 2011 10:33 pm
Profile
Novice

Joined: Mon Oct 18, 2010 9:31 pm
Posts: 86
Post Re: Endcoders better?
yes, which is confusing me.. haha


Fri Apr 22, 2011 10:35 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Endcoders better?
In case I missed something, please change the debug line to:
Code:
void DriveIRTask()
{
    if (g_driveIREnabled)
    {
        float driveErr = g_driveTarget - GetDriveDistance();

        if (abs(driveErr) > g_driveTolerance)
        {
            //
            // Simple proportional PID control.
            // Limit the outpout to the range of -100 to 100 for drive
            // and -50 to 50 for turn
            //
            int drivePower = BOUND((int)(g_driveKp*driveErr), -70, 70);
            float turnErr = IRGetACDir(IRSeeker2) - 2.0;  //use zone 2 as the straight ahead zone
            nxtDisplayTextLine(<free line>, "IR=%f", IRGetACDir(IRSeeker2));
            int turnPower = BOUND((int)(g_turnIRKp*turnErr), -50, 50);
            nxtDisplayTextLine(<free line>, "L=%d,R=%d",
                      BOUND(drivePower + turnPower, -100, 100),
                      BOUND(drivePower - turnPower, -100, 100));
            motor[motorLeft] = BOUND(drivePower + turnPower, -100, 100);
            motor[motorRight] = BOUND(drivePower - turnPower, -100, 100);
        }
        else
        {
            motor[motorLeft] = 0;
            motor[motorRight] = 0;
            g_driveIREnabled = false;
        }
   }
}


Fri Apr 22, 2011 10:36 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Endcoders better?
BTW, turn Kp back down to 15.0 or so. It is correcting too strong. It may affect the IR sensor when in motion.


Fri Apr 22, 2011 10:41 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 133 posts ]  Go to page Previous  1 ... 3, 4, 5, 6, 7, 8, 9  Next

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.