View unanswered posts | View active topics It is currently Fri Aug 22, 2014 8:06 pm






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

Joined: Mon Oct 18, 2010 9:31 pm
Posts: 86
Post Re: Endcoders better?
before i change anything... i just tested the robot, starting out with it turned 90 degrees from the ir beacon. it would then turn left, see the beacon, and drive almost to it

But, when i test it to go to the right, it wont.

So it worked forward and left, but right is not.


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

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Endcoders better?
Team2844 wrote:
But, when i test it to go to the right, it wont.
So it worked forward and left, but right is not.

You mean starting out by placing the robot so that the beacon is on the right side? When that happened what were the numbers of the screen?


Fri Apr 22, 2011 10:53 pm
Profile
Novice

Joined: Mon Oct 18, 2010 9:31 pm
Posts: 86
Post Re: Endcoders better?
the nxt screen for the new code

left side, 1.000 l = 20, r 100

moving toward middle, l get higher, r gets lower

middle, 2.000 l =70, r =70

moving toward the right, l get higher, r gets lower

right side, 3.000 l= 100, r =20

one second on the last thing you asked


Fri Apr 22, 2011 11:01 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Endcoders better?
These numbers looked totally normal, the motors should be responding correctly to the beacon.... Why is it not working???


Fri Apr 22, 2011 11:07 pm
Profile
Novice

Joined: Mon Oct 18, 2010 9:31 pm
Posts: 86
Post Re: Endcoders better?
I tested it three times and these were the results.

First time. 2.33333
sencond time. 2.215
third time 3.00000
fourth time 4.50000 l 87, r-13

would it just be having trouble turning to the right?


Fri Apr 22, 2011 11:09 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Endcoders better?
If the left motor was programmed to 87 and the right motor was at -13, it should turn right, shouldn't it?!! So what is the symptom now? Did it just stop? Or did it continue going straight ahead?
Hmm, normally the beacon should not be too far off to the left or right, correct? If so let's limit the turn power to -10, 10. Currently, it is turning too strong. The limit will give you a delta of 20 which is enough for course correction.
I am puzzled. If it is possible, can you post a picture of your robot? It may give me some clue that I would not think of.


Fri Apr 22, 2011 11:21 pm
Profile
Novice

Joined: Mon Oct 18, 2010 9:31 pm
Posts: 86
Post Re: Endcoders better?
Before I change anything.. the robot will keep moving forward even though the beacon is to the right. but when its going forward, it seems to have a very slight pull to the right, like its trying to turn, but something is not letting it.


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

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Endcoders better?
Team2844 wrote:
fourth time 4.50000 l 87, r-13

Wait, how can these numbers be possible? drivePower is limited to between -70 and 70. So in order for L to become 87, turnPower must be 17. But if that's the case, R should be 70 - 17 = 53. So it can't be -13. Can you post your DriveIRTask code along with the g_driveIRTarget, g_turnIRKp etc. This is simply impossible unless the code is not what I think it was.


Fri Apr 22, 2011 11:53 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Endcoders better?
Team2844 wrote:
fourth time 4.50000 l 87, r-13

Wait, how can these numbers be possible? drivePower is limited to between -70 and 70. So in order for L to become 87, turnPower must be 17. But if that's the case, R should be 70 - 17 = 53. So it can't be -13. Can you post your DriveIRTask code along with the g_driveIRTarget, g_turnIRKp etc. This is simply impossible unless the code is not what I think it was.


Fri Apr 22, 2011 11:54 pm
Profile
Novice

Joined: Mon Oct 18, 2010 9:31 pm
Posts: 86
Post Re: Endcoders better?
Maybe i put something in wrong??
Code:
#pragma config(Hubs,  S1, HTMotor,  HTMotor,  HTServo,  none)
#pragma config(Sensor, S2,     Magnet,              sensorHiTechnicMagnetic)
#pragma config(Sensor, S3,     gyro,                sensorI2CCustom)
#pragma config(Sensor, S4,     IRSeeker2,           sensorI2CCustom)
#pragma config(Motor,  mtr_S1_C1_1,     motorLeft,     tmotorNormal, openLoop, encoder)
#pragma config(Motor,  mtr_S1_C1_2,     motorRight,    tmotorNormal, openLoop, reversed, encoder)
#pragma config(Motor,  mtr_S1_C2_1,     lights,        tmotorNormal, openLoop, encoder)
#pragma config(Motor,  mtr_S1_C2_2,     motorArm,      tmotorNormal, openLoop, encoder)
#pragma config(Servo,  srvo_S1_C3_1,    trailer1,             tServoStandard)
#pragma config(Servo,  srvo_S1_C3_2,    trailer2,             tServoStandard)
#pragma config(Servo,  srvo_S1_C3_3,    gate,                 tServoStandard)
#pragma config(Servo,  srvo_S1_C3_4,    ,                     tServoStandard)
#pragma config(Servo,  srvo_S1_C3_5,    ,                     tServoStandard)
#pragma config(Servo,  srvo_S1_C3_6,    twist,                tServoStandard)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "JoystickDriver.c"  //Include file to "handle" the Bluetooth messages.
#include "C:\Documents and Settings\Mom\My Documents\Robotics\Code\gyro.h"
#include "C:\Projects\rdpartyrobotcdr-v1.8.1-HT\drivers\HTIRS2-driver.h"

#define BOUND(n, l, h) (((n) < (l))? (l): ((n) > (h))? (h): (n))
#define PI                      3.14159
#define CLICKS_PER_REVOLUTION   1440.0          //encoder clicks per revolution
#define GEAR_RATIO              (40.0/120.0)     //motor:wheel=24:16 (use your own gear ratio)
#define WHEEL_DIAMETER          4.0  //use your own wheel size
#define WHEEL_CIRCUMFERENCE     (PI*WHEEL_DIAMETER)
#define INCHES_PER_CLICK        (0.005807764)
#define DEGREES_PER_CLICK       (0.03333)

GYRO  g_Gyro;
float g_turnTarget = 0.0;
bool  g_turnEnabled = false;
float g_turnTolerance = 0.3;    //needs to be tuned
float g_turnKp = 24.0;             //needs to be tuned
float g_driveTarget = 0.0;
bool  g_driveEnabled = false;
float g_driveTolerance = 0.5;
float g_driveKp = 50.0;
bool  g_driveIREnabled = false;
float g_turnIRKp = 50.0;    //need to tune this

void SetTurnTarget(float angle)
{
    GyroReset(g_Gyro);
    g_turnTarget = angle;
    g_turnEnabled = true;
}

void TurnTask()
{
    if (g_turnEnabled)
    {
        float error = GyroGetHeading(g_Gyro) - g_turnTarget;
        if (abs(error) > g_turnTolerance)
        {
            //
            // Simple proportional PID control.
            // Limit the outpout to the range of -70 to 70.
            //
            int turnPower = BOUND((int)(g_turnKp*error), -100, 100);
            motor[motorLeft] = turnPower;
            motor[motorRight] = -turnPower;
        }
        else
        {
            motor[motorLeft] = 0;
            motor[motorRight] = 0;
            g_turnEnabled = false;
            nxtDisplayTextLine(7, "err=%f", error);
        }
        nxtDisplayTextLine(3, "Heading=%f", GyroGetHeading(g_Gyro));
        nxtDisplayTextLine(6, "target=%f,tol=%f", g_turnTarget, g_turnTolerance);
    }
}

float GetDriveDistance()
{
    return (float)(nMotorEncoder[motorLeft] + nMotorEncoder[motorRight])/2.0*INCHES_PER_CLICK;
}

void SetDriveTarget(float distance)
{
    nMotorEncoder[motorLeft] = 0;
    nMotorEncoder[motorRight] = 0;
    GyroReset(g_Gyro);
    g_driveTarget = distance;
    g_driveEnabled = true;
}

void DriveTask()
{
    if (g_driveEnabled)
    {
        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 = GyroGetHeading(g_Gyro);
            int turnPower = BOUND((int)(g_turnKp*turnErr), -100, 100);
            motor[motorLeft] = BOUND(drivePower + turnPower, -100, 100);
            motor[motorRight] = BOUND(drivePower - turnPower, -100, 100);
            nxtDisplayTextLine(7, "drvErr=%f", driveErr);
        }
        else
        {
            motor[motorLeft] = 0;
            motor[motorRight] = 0;
            g_driveEnabled = false;
        }
        nxtDisplayTextLine(4, "Distance=%f", GetDriveDistance());
   }
}

float IRGetACDir(tSensors link)
{
    static float prevDir = 0.0;
    float currDir;
    int acS[5];
    int idx;

    idx = HTIRS2readACDir(link);
    currDir = (float)idx;
    if (idx == 0)
    {
        currDir = prevDir;
    }
    else if (HTIRS2readAllACStrength(link, acS[0], acS[1], acS[2], acS[3], acS[4]))
    {
        idx = (idx - 1)/2;
        if ((idx < 4) && (acS[idx] != 0) && (acS[idx + 1] != 0))
        {
            currDir += (float)(acS[idx + 1] - acS[idx])/
                          max(acS[idx], acS[idx + 1]);
        }
    }
    prevDir = currDir;

    return currDir;
}

void SetDriveIRTarget(float distance)
{
    nMotorEncoder[motorLeft] = 0;
    nMotorEncoder[motorRight] = 0;
    g_driveTarget = distance;
    g_driveIREnabled = true;
}

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(2, "IR=%f", IRGetACDir(IRSeeker2));
            int turnPower = BOUND((int)(g_turnIRKp*turnErr), -50, 50);
            nxtDisplayTextLine(6, "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;
        }
   }
}

void initializeRobot()
{
  HTIRS2setDSPMode(IRSeeker2, DSP_1200);
  servoTarget[servo1] = 247;
  servoTarget[servo2] = 0;
  servoTarget[servo3] = 100;
  servoTarget[servo4] = 205;
  servoTarget[servo5] = 49;
  servoTarget[servo6] = 136;
  // Place code here to sinitialize servos to starting positions.
  // Sensors are automatically configured and setup by ROBOTC. They may need a brief time to stabilize.
  GyroInit(g_Gyro, gyro, 0);

  return;
}

task main()
{
    int step = 0;

    StopTask(displayDiagnostics);
    eraseDisplay();
    initializeRobot();
    waitForStart(); // Wait for the beginning of autonomous phase.
    while (true)
    {
        GyroTask(g_Gyro);

        nxtDisplayTextLine(5, "Step=%d", step);
        switch (step)
        {
//*****************************Drive to opp side of field*************************************

            case 0:
                // step 2: ir seeker drive.
                SetDriveIRTarget(56.0);
                step++;
                break;

            case 1:
                // step 3: wait for drive to complete.
                if (g_driveIREnabled == false)
                {
                    step++;
                }
                break;

        }

        TurnTask();
        DriveTask();
        DriveIRTask();
        wait1Msec(10);
    }


Sat Apr 23, 2011 12:08 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Endcoders better?
Ok, I was wrong. It is possible to have those numbers. drivePower was 37 and turnPower was 50. So Left=37+50=87 and Right=37-50=-13. This means the turning power is way too strong. So Kp should be tuned much lower. I suggested setting g_turnIRKp lower but you didn't do that. I also suggested to limit turnPower to the range of -10 to 10. You didn't do that either. That's why I thought it wasn't possible to have a turnPower as high as 50. Please set g_turnIRKp to 10.0 and limit turnPower to the range -10.0 to 10.0. Now that would make the numbers behave more reasonably but it still doesn't explain why the robot doesn't turn right. Can you lift the robot off the ground so that the wheels are not touching anything. And face the robot such that the IR reading is approx. 2.9 (close to 3.0) and see how the wheels are turning. I am wondering if your motors are somehow too weak. By lifting it off the gound, it has no load and will be freely turning. If that behaves correctly. Then run it again on the ground and see what happens.


Sat Apr 23, 2011 12:50 am
Profile
Novice

Joined: Mon Oct 18, 2010 9:31 pm
Posts: 86
Post Re: Endcoders better?
Ok, where do you want me to turn the turn power down. In the TurnTask, or in DriveIRTask.

Without turning that down, but the kp to 10, I got these results. The robot is off the ground for these.

Code:
 L       R      zone
38     28    2.5
55     35    3.0    this happened 4 times.
37     35    2.12
38     28    2.52
36     16    2.58


When I run the code, it will usually jump to the 3.0 zone, and totally skip the 2.6-2.9 range. or go to the 2.59 range and down.

I did get these weird numbers though three times. same exact area as the beacon was above.
Code:
 L       R      zone
86      0     6.38
84     -16    7.0   
83     -7     6.5



I know that it can turn right... I just ran the code to go to the trailer from the left side starting position, and it turns the 90 degrees to the right perfectly.


Sat Apr 23, 2011 10:32 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Endcoders better?
Team2844 wrote:
Ok, where do you want me to turn the turn power down. In the TurnTask, or in DriveIRTask.

DriveIRTask. That's what we are debugging. Try this and let me know if the robot can turn right to go to the beacon. Please report the following info because I wasn't quite clear on your previous account what had happened. For example, I would like to see the numbers as well as the effect on the robot:
Code:
IRValue  LeftPower  RightPower Describe what happened
  2.5       38          28     Robot going straight ignoring the beacon

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(2, "IR=%f", IRGetACDir(IRSeeker2));
            int turnPower = BOUND((int)(g_turnIRKp*turnErr), -10, 10);
            nxtDisplayTextLine(6, "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;
        }
   }
}


Sat Apr 23, 2011 1:11 pm
Profile
Novice

Joined: Mon Oct 18, 2010 9:31 pm
Posts: 86
Post Re: Endcoders better?
With only me... i am not able to watch what it is saying the zone is until it stops the 56 inches. the zones are what it is when they finish.

Code:

Left of robot
IRValue  LeftPower  RightPower   Describe what happened
  3.0       36            16        Drifted left the 56 inches about 40 degrees
  3.0       39            19        Drifted left the 56 inches about 45 degrees

front of robot
IRValue  LeftPower  RightPower   Describe what happened
  0.0       23            43        Drifted left the 56 inches about 65 degrees, ignoring the beacon
  0.0       21            41        Drifted left the 56 inches about 70 degrees, ignoring the beacon

Right of robot
IRValue  LeftPower  RightPower   Describe what happened
  3.0       38           18        Drifted left the 56 inches about 20 degrees
  3.0       40           20        Drifted left 20 degrees over 24 inches, driving moderately straight the rest of the way.


With more than the -10,10 the robot will turn better to the left close to it, but again, had trouble turning right like it should with a load on it. Yet when you look at it trying to turn right without a load, you can see its trying to... is there anyway that I can give the left side just a little more power than the right side, even when its suppose to be going straight.

Also, say its turning left, is this code just giving less power to the left side, or is it allowing for the left side to go backward.. actting like a tank drive. My robot runs better when i turn it like that, other than just running one side and leaving the other low or off of power.


Sat Apr 23, 2011 1:59 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Endcoders better?
Team2844 wrote:
Code:

Left of robot
IRValue  LeftPower  RightPower   Describe what happened
  3.0       36            16        Drifted left the 56 inches about 40 degrees
  3.0       39            19        Drifted left the 56 inches about 45 degrees

front of robot
IRValue  LeftPower  RightPower   Describe what happened
  0.0       23            43        Drifted left the 56 inches about 65 degrees, ignoring the beacon
  0.0       21            41        Drifted left the 56 inches about 70 degrees, ignoring the beacon

Right of robot
IRValue  LeftPower  RightPower   Describe what happened
  3.0       38           18        Drifted left the 56 inches about 20 degrees
  3.0       40           20        Drifted left 20 degrees over 24 inches, driving moderately straight the rest of the way.


BTW, do you know you can see the LCD screen remotely? in the RobotC IDE, if you click the "Robot" menu, there is an item about debug window and you can pop open the remote LCD screen so you can see it on your laptop (don't have RobotC in front of me, so can't tell you exactly what the menu item is called).
Are you sure the data is right? On "Left of robot", the IR value should be below 2.0 but it's 3.0. Could be because you read the numbers at the end of the 56-inche run so by then the beacon was on the right instead even though it started on the left. A major concern is the IR value 0.0 when the beacon is in front. This means the sensor doesn't see the IR beacon at all. Can you make sure the way you mount the IR sensor that it has full 180-degree view to the front of the robot. I am worrying about something is blocking the IR signal at a certain angle. Also, make sure there is no shiny reflective surface that could reflect a false IR signal from the wrong angle. From the data "Right of robot", the data still said the robot should be turning right, I don't know why it is turning left. I guess if you are reading this data at the end of the 56-inch run, it could be the wrong data. I really need the data while it is turning left, not at the end when it's stopped. Misleading data could lead me into the wrong path.


Sat Apr 23, 2011 2:28 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 133 posts ]  Go to page Previous  1 ... 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.