View unanswered posts | View active topics It is currently Fri Aug 01, 2014 11:35 am






Reply to topic  [ 133 posts ]  Go to page Previous  1 ... 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?
Let's do something drastic. Let's eliminate everything that could go wrong and go back to simple. First, restore the IRSeeker2 pragma to "sensorHiTechnicIRSeeker1200". Remove the include of the "HTIRS2-driver.h". Remove the line "HTIRS2setDSPMode(IRSeeker2, DSP_1200);" from initializeRobot. Then change the DriveIRTask function to the following. This will eliminate the new IR seeker library function in case there is something wrong with it. Let me know if there is any difference. If it is the same, then there was nothing wrong with the IR seeker code. And we will focus on something else.
Code:
#pragma config(Sensor, S4,     IRSeeker2,           sensorHiTechnicIRSeeker1200)

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 -70 to 70 for drive
            // and -10 to 10 for turn
            //
            int drivePower = BOUND((int)(g_driveKp*driveErr), -70, 70);
            float turnErr = (float)SensorValue[IRSeeker2] - 2.0;  //use zone 2 as the straight ahead zone.
            nxtDisplayTextLine(2, "IR=%d", SensorValue[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 5:53 pm
Profile
Novice

Joined: Mon Oct 18, 2010 9:31 pm
Posts: 86
Post Re: Endcoders better?
OK, so here we go..

1st
I did what you said above, with the kp at 10, and the drivers at -10, 10. It still had the same problems.

2nd.
I spiked the kp up to 30, and drivers at -30, 30, better on the turn(left) but still having trouble even turning left.

3rd.
I spiked the kp up to 50, and the drivers at -50, 50, and got the turn back, but still, no right at all.

4th
I took the sensor and put it back to the 5 zone as forward. i could hear that the robot was trying to turn right.

5th
I have stuff from an old ftc team that they let me have, and I changed out the ir sensor., i could hear it trying to turn right.

6th
I started the robot, with the beacon at the right... and the robot started to move forward, seeing it, trying to turn right, and soon lost it as it drifted off to the left of it, and started turning left.

7th
I started the robot, with the beacon in front of it about 12 inches, and moved the beacon back as the robot moved toward it. I could see the robot and hear the gears click as it turn very slightly to the right when the beacon was to the right.

8th
I put the beacon on the right of the robot, about 40 inches or so, started the program, it started to run forward, so i grabbed the right wheel, and held it from moving. I could feel that there wasnt to much power in it, and the left side started pushing harder, turn the robot to the right., until it had the beacon in zone 5, when i could feel the right side wheels get more power.

When this runs... say turning left, to make the left wheel go backwards, and the right wheel to go forward, giving it more of a boost, than just one wheel getting less power.


Sat Apr 23, 2011 8:25 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Endcoders better?
So even with the old IR code (i.e. doing SensorValue instead of IRGetACDir) you still have problems turning right, correct? If so, the problem is not with the new IR sensor code.
Quote:
4th
I took the sensor and put it back to the 5 zone as forward. i could hear that the robot was trying to turn right.

5th
I have stuff from an old ftc team that they let me have, and I changed out the ir sensor., i could hear it trying to turn right.

What do you mean by "you can hear the robot trying to turn right"? If you elevate the robot so the wheels won't touch the ground or anything, could you see if the wheels are turning right? The problem is: I can't see how the robot is responding and I don't quite understand your description, so I can't tell you what the problem is.
Quote:
8th
I put the beacon on the right of the robot, about 40 inches or so, started the program, it started to run forward, so i grabbed the right wheel, and held it from moving. I could feel that there wasnt to much power in it, and the left side started pushing harder, turn the robot to the right., until it had the beacon in zone 5, when i could feel the right side wheels get more power.

This is correct. For the robot to turn right, right wheel should be weak but left wheel should be strong. That will make the robot turn right.
Okay, let's go even more drastic. Let's not use PID for IR. Here is what you should change DriveIRTask to. Basically, we will turn left with turnPower -50 if the beacon is on the left and turn right with turnPower +50 if the beacon is on the right. So there is no proportional control. See if it works better.
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 -70 to 70 for drive
            // and -10 to 10 for turn
            //
            int drivePower = BOUND((int)(g_driveKp*driveErr), -70, 70);
            float turnErr = (float)SensorValue[IRSeeker2] - 2.0;  //use zone 2 as the straight ahead zone.
            nxtDisplayTextLine(2, "IR=%d", SensorValue[IRSeeker2]);
            int turnPower = (turnErr < 0.0)? -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;
        }
   }
}


Sat Apr 23, 2011 8:45 pm
Profile
Novice

Joined: Mon Oct 18, 2010 9:31 pm
Posts: 86
Post Re: Endcoders better?
MHTS wrote:
What do you mean by "you can hear the robot trying to turn right"? If you elevate the robot so the wheels won't touch the ground or anything, could you see if the wheels are turning right? The problem is: I can't see how the robot is responding and I don't quite understand your description, so I can't tell you what the problem is.


Yes, if i go to elevate the robot, you can see that the right side wheels are lower than the left side wheels. What I mean by hearing it is the left side will get louder in the gearing.. not by much, but enough for me to notice it getting more power.

MHTS wrote:
This is correct. For the robot to turn right, right wheel should be weak but left wheel should be strong. That will make the robot turn right.


When you mean weak, do you mean that the right side is running slower but still forward, allowing the left to turn the robot? Is there any way to make it run backward instead of getting less power.

With the above you said, the results.

Beacon on the right side, the robot drifts to the right about 10 degrees, but still missing the beacon to the left.
Code:
Left     Right   Zone 
  75       -25      6           this happened three times in a row. All the same result.


Beacon on the left, drove to it.
Beacon in the middle, drove to it.

What is really confusing me is that if I run the program to the trailer, I have no problem with it turning right.


Sat Apr 23, 2011 10:42 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Endcoders better?
Team2844 wrote:
Yes, if i go to elevate the robot, you can see that the right side wheels are lower than the left side wheels. What I mean by hearing it is the left side will get louder in the gearing.. not by much, but enough for me to notice it getting more power.

If that's the case, it is turning right. Why did you say it is drifting left? It may be turning right slower than you want it but it should at least be turning right. It is impossible that the left wheel is turning forward faster than the right wheel and the robot is still drifting left. It is important to know what problem I am debugging. If it was indeed turning right but not strong enough then we can tweak the parameters to get it to turn stronger. However, if it is really turning left, then it is a totally different issue.
Team2844 wrote:
When you mean weak, do you mean that the right side is running slower but still forward, allowing the left to turn the robot? Is there any way to make it run backward instead of getting less power.

Yes, if you increase the turnPower limit to -50, 50 and decrease the drivePower limit to also -50, 50. You will see a much stronger turn.
Team2844 wrote:
With the above you said, the results.

Beacon on the right side, the robot drifts to the right about 10 degrees, but still missing the beacon to the left.

So it is turning right! What do you mean by missing the beacon to the left? Now it sounds like you are using zone 5 as straight ahead. Zone 5 is a very wide zone meaning that you could be off the beacon by up to 20-25 degrees and still be in zone 5. That's why I recommend using zone 2.


Sun Apr 24, 2011 1:04 am
Profile
Novice

Joined: Mon Oct 18, 2010 9:31 pm
Posts: 86
Post Re: Endcoders better?
OK, so I have had the turn already at -50,50, because the robot would do almost nothing at -10,10. but i did just cange the drive to -50, 50 and i got..


RIGHT TURNING!!

Sort of...

it works, it crawls to the sensor.

turn, stop, straight, stop, turn, stop, straight, stop, until it gets all the way up to the beacon. My code calls for the robot to get close to the dispenser without using the ir, and then using the ir to line it up right... so this will work for me at least..

I can't thank you enough for the amount of help that you have given to me. THANK YOU.

Are you an FTC team going to World, just wondering?

Again, THANK YOU.
Team 2844
~Valley X


Sun Apr 24, 2011 1:21 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Endcoders better?
No, our team's robot had major mechanical problem during the regional so we didn't make it to St Louis. Good luck to your team though. Hope the St Louis airport will be open next week.


Sun Apr 24, 2011 1:43 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Endcoders better?
BTW, what's your final code looks like?


Sun Apr 24, 2011 1:51 am
Profile
Novice

Joined: Mon Oct 18, 2010 9:31 pm
Posts: 86
Post Re: Endcoders better?
Wow, I just heard about the airport...

On our code... im still working on it even with three days left before the regional. Before it even gets to the other side of the field, there is already 600 lines of code, and probably a few hundred more to come. I will post them when I am finished.

What is your team number... I would like to mention your team in our engineering notebook.


Sun Apr 24, 2011 9:44 am
Profile
Novice

Joined: Mon Oct 18, 2010 9:31 pm
Posts: 86
Post Re: Endcoders better?
This poped up when i was testing a piece of the code...

http://img847.imageshack.us/img847/614/45682082.jpg

Any idea?
All the code is to turn 30 degrees right, go 15 inches forward, and turn 30 degrees left.


Sun Apr 24, 2011 11:34 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Endcoders better?
Our FTC team number is 3543. The popup you have is an error in initializeRobot. Are you using IRGetACDir or SensorValue? If you are using latter, you need to take out the SetDSPMode line and comment out the inlcude to Xander's driver.


Sun Apr 24, 2011 1:09 pm
Profile
Novice

Joined: Mon Oct 18, 2010 9:31 pm
Posts: 86
Post Re: Endcoders better?
I not using the IR code for the error that i am getting... heres the code i am using, which doesnt even have the ir stuff in it yet.
Code:
#pragma config(Sensor, S2,     Magnet,              sensorHiTechnicMagnetic)
#pragma config(Sensor, S3,     gyro,                sensorI2CCustom)
#pragma config(Sensor, S4,     IRSeeker2,           sensorHiTechnicIRSeeker1200)
#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"

#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 = 30.0;             //needs to be tuned
float g_driveTarget = 0.0;
bool  g_driveEnabled = false;
float g_driveTolerance = 0.3;
float g_driveKp = 50.0;
float g_armTarget = 0.0;
bool  g_armEnabled = false;
float g_armTolerance = 0.3;
float g_armKp = 10.0;

void SetArmTarget(float angle)
{
  g_armTarget = angle;
  g_armEnabled = true;
}

float GetArmPosition()
{
    return (float)nMotorEncoder[motorArm]*DEGREES_PER_CLICK;
}

void ArmTask()
{
  if (g_armEnabled)
  {
    float error = g_armTarget - GetArmPosition();
    nxtDisplayTextLine(4, "ArmPos=%f", GetArmPosition());
    if (abs(error) > g_armTolerance)
    {
      motor[motorArm] = BOUND((int)(g_armKp*error), -50, 50);
    }
    else
    {
      motor[motorArm] = 0;
      g_armEnabled = false;
    }
  }
}

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());
   }
}

void initializeRobot()
{
  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.
    nMotorEncoder[motorArm] = 0;
    while (true)
    {
        GyroTask(g_Gyro);

        nxtDisplayTextLine(5, "Step=%d", step);
        switch (step)
        {
//*****************************Drive to trailer*************************************
          case 0:
                // step 0: go forward.
                servoTarget[servo4] = 152;
                servoTarget[servo5] = 102;
                step++;
                break;

          case 1:
                // step 1: wait for drive to complete.
                if (time1[T1] > 500)
                {
                    step++;
                }
                break;

            case 2:
                // step 2: turn 90 right degrees.
                SetTurnTarget(30.0);
                step++;
                break;

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

            case 4:
                // step 2: drive forward.
                SetDriveTarget(15.0);
                step++;
                break;

            case 5:
                // step 3: wait for drive to complete.
                if (g_driveEnabled == false)
                {
                    step++;
                }
                break;
               
            case 6:
                // step 2: turn 90 left degrees.
                SetTurnTarget(-30.0);
                step++;
                break;

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

        }

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


Sun Apr 24, 2011 3:41 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Endcoders better?
This code worked at one point, right? If so, try to remember what changed. Since if is complaining about initializeRobot and the only suspicious line in there is GyroInit. Comment out that line of code and see if the error is gone. But of course, you need that line for the code to work. But this will narrow down what the compiler is complaining.


Sun Apr 24, 2011 5:39 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Endcoders better?
I copied and pasted your code to a local file and compiled it with RobotC. Aside from adding back the S1 pragma and minor corrections to your servo names, I don't have any problem compiling the code.
Code:
C:\Temp-> diff 2844.c.orig 2844.c
0a1
> #pragma config(Hubs,  S1, HTMotor,  HTMotor,  HTServo,  none)
17c18
< #include "C:\Documents and Settings\Mom\My Documents\Robotics\Code\gyro.h"
---
> #include "gyro.h"
151,153c152,154
<   servoTarget[servo1] = 247;
<   servoTarget[servo2] = 0;
<   servoTarget[servo3] = 100;
---
>   servoTarget[trailer1] = 247;
>   servoTarget[trailer2] = 0;
>   servoTarget[gate] = 100;
156c157
<   servoTarget[servo6] = 136;
---
>   servoTarget[twist] = 136;



Sun Apr 24, 2011 6:17 pm
Profile
Novice

Joined: Mon Oct 18, 2010 9:31 pm
Posts: 86
Post Re: Endcoders better?
Whats confusing me is the only thing i would change is the distance.. and it would stop working.


Sun Apr 24, 2011 6:45 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 133 posts ]  Go to page Previous  1 ... 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.