Go to Post If you don't have a hairtie, use a ziptie instead. It works, it's cute, and way geeky. :p - Katie Reynolds [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 11-03-2011, 15:32
Jagbots(Robert)'s Avatar
Jagbots(Robert) Jagbots(Robert) is offline
Registered User
AKA: Robert Wood
FRC #2929 (Jagbots)
Team Role: Programmer
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Puyallup
Posts: 1
Jagbots(Robert) is an unknown quantity at this point
Exclamation Line Tracking Code Help

Hello,

I'm one of the programmers for team 2929 for Emerald Ridge. Recently our robot was bagged and tagged and I’ve been working on our code for the line tracking sensors, because when we worked on the line tracking in autonomous, the robot only went backwards only, and one time did the spin of death, violently turning left continuously. So I was hoping if anyone sees any bugs in the robot code I’m posting, it would be great if someone could help me find and fix them.

Thanks in advance!
Attached Files
File Type: txt Robot Code.txt (2.5 KB, 79 views)

Last edited by Jagbots(Robert) : 11-03-2011 at 15:35.
Reply With Quote
  #2   Spotlight this post!  
Unread 11-03-2011, 15:48
davidalln's Avatar
davidalln davidalln is offline
World's Worst Coder
AKA: David Allen
FRC #2415 (The Westminster Wiredcats)
Team Role: Programmer
 
Join Date: Mar 2009
Rookie Year: 2008
Location: Atlanta, GA
Posts: 108
davidalln is on a distinguished road
Send a message via AIM to davidalln
Re: Line Tracking Code Help

If your robot is running backwards, then just take the opposite numbers of the motor values (-1 instead of 1) and continue.

Looking over your code, though, there's a better way of doing it. First of all, I would advise against running a motor at full speed when trying to turn, because you should just be making gradual adjustments. Second, a more accurate autonomous can be achieved by just slightly increasing the speed of whichever side of the robot you want to turn and continuing on. That's how we did it, and we were extremely consistent in our autonomous at Alamo.
__________________
SANTOSH ANDREW DECKER RICK WYNNIE SEAN DEREK MATT
(alamo (semis), p'tree (CHAMPS!), nc (CHAMPS!), newton (quarters))


Best four years of my life. Thanks to everyone who made it happen.
Reply With Quote
  #3   Spotlight this post!  
Unread 12-03-2011, 00:38
taichichuan's Avatar
taichichuan taichichuan is offline
Software Mentor
AKA: Mike Anderson
FRC #0116 (Epsilon Delta)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2010
Location: Herndon, VA
Posts: 328
taichichuan has much to be proud oftaichichuan has much to be proud oftaichichuan has much to be proud oftaichichuan has much to be proud oftaichichuan has much to be proud oftaichichuan has much to be proud oftaichichuan has much to be proud oftaichichuan has much to be proud oftaichichuan has much to be proud oftaichichuan has much to be proud of
Send a message via AIM to taichichuan
Re: Line Tracking Code Help

Quote:
Originally Posted by davidalln View Post
If your robot is running backwards, then just take the opposite numbers of the motor values (-1 instead of 1) and continue.

Looking over your code, though, there's a better way of doing it. First of all, I would advise against running a motor at full speed when trying to turn, because you should just be making gradual adjustments. Second, a more accurate autonomous can be achieved by just slightly increasing the speed of whichever side of the robot you want to turn and continuing on. That's how we did it, and we were extremely consistent in our autonomous at Alamo.
Any chance you could post your autonomous code?

TIA,

Mike
Reply With Quote
  #4   Spotlight this post!  
Unread 12-03-2011, 13:36
davidalln's Avatar
davidalln davidalln is offline
World's Worst Coder
AKA: David Allen
FRC #2415 (The Westminster Wiredcats)
Team Role: Programmer
 
Join Date: Mar 2009
Rookie Year: 2008
Location: Atlanta, GA
Posts: 108
davidalln is on a distinguished road
Send a message via AIM to davidalln
Re: Line Tracking Code Help

My raw autonomous code wouldn't be much use to you, as its deeply integrated in our system and would be difficult to read if you don't know what everything does. But here's the basic idea:

Code:
if (leftSensorTripped) {
   robotDrive->TankDrive(0.7, 0.8);
} else if (rightSensorTripped) {
   robotDrive->TankDrive(0.8, 0.7);
} else {
   robotDrive->TankDrive(0.7, 0.7);
}
This will gradually get your robot back on the line without overcorrecting. Obviously this is oversimplified and you'll need to adapt it to your bot, but this shows the basic idea. Note that this will not work well in the Y (middle autonomous) as you need a much sharper turn at the corner. For that you need to make a sharper turn.
__________________
SANTOSH ANDREW DECKER RICK WYNNIE SEAN DEREK MATT
(alamo (semis), p'tree (CHAMPS!), nc (CHAMPS!), newton (quarters))


Best four years of my life. Thanks to everyone who made it happen.
Reply With Quote
  #5   Spotlight this post!  
Unread 12-03-2011, 18:54
taichichuan's Avatar
taichichuan taichichuan is offline
Software Mentor
AKA: Mike Anderson
FRC #0116 (Epsilon Delta)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2010
Location: Herndon, VA
Posts: 328
taichichuan has much to be proud oftaichichuan has much to be proud oftaichichuan has much to be proud oftaichichuan has much to be proud oftaichichuan has much to be proud oftaichichuan has much to be proud oftaichichuan has much to be proud oftaichichuan has much to be proud oftaichichuan has much to be proud oftaichichuan has much to be proud of
Send a message via AIM to taichichuan
Re: Line Tracking Code Help

Quote:
Originally Posted by davidalln View Post
My raw autonomous code wouldn't be much use to you, as its deeply integrated in our system and would be difficult to read if you don't know what everything does. But here's the basic idea:

Code:
if (leftSensorTripped) {
   robotDrive->TankDrive(0.7, 0.8);
} else if (rightSensorTripped) {
   robotDrive->TankDrive(0.8, 0.7);
} else {
   robotDrive->TankDrive(0.7, 0.7);
}
This will gradually get your robot back on the line without overcorrecting. Obviously this is oversimplified and you'll need to adapt it to your bot, but this shows the basic idea. Note that this will not work well in the Y (middle autonomous) as you need a much sharper turn at the corner. For that you need to make a sharper turn.
Thanks for the info. We've gotten our line tracking code working and now we just need access to a real field for tuning!

Mike
Reply With Quote
  #6   Spotlight this post!  
Unread 12-03-2011, 20:09
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 667
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Line Tracking Code Help

Our line following algorithm uses PID control. Basically, we combined the readings of the three light sensors into a 3-bit value (0-7) and used it to index a table. If the line is right at the center, it maps to 0.0. If the line is slightly to the left, it maps to 1.0, more to the left maps to 2.0. If the line is slightly to the right, its maps to -1.0 and -2.0 if further right. 999.0 is just a number used to indicate no valid line is found. The number -2.0 to 2.0 is then used as the current input in PID control calculation and the setpoint is 0.0 (the center). The turning power is proportional on how far we are "off course". The speed driving forward is inversely proportional to the turning power. So the harder we turn, the slower we go. Our algorithm is actually more complicated than that but a simplified version is shown below.
Code:
UINT32
GetRawValue(
    void
    )
{
    UINT32 value = 0;
 
    value = m_leftLightSensor->Get() << 2;
    value |= m_centerLightSensor->Get() << 1;
    value |= m_rightLightSensor->Get();
 
    return value;
}   //GetRawValue
 
static float inputMap[8] =
{
    999.0, //000: n/a (No light)
    -2.0,   //001: Extreme right
    0.0,    //010: Center
    -1.0,   //011: Slight right
    2.0,    //100: Extreme left
    999.0, //101: n/a (At Y)
    1.0,    //110: Slight left
    999.0  //111: n/a (At T)
};
 
UINT32 sensorRawValue = GetRawValue();
if (sensorRawValue == 0)
{
    //
    // deal with losing the line.
    //
}
else if (sensorRawValue == 0x5)
{
    //
    // deal with the Y fork.
    //
}
else if (sensorRawValue == 0x7)
{
    //
    // deal with the T-end.
    //
}
else
{
    float sensorMappedValue = inputMap[sensorRawValue];
    float turnPower = CalcPIDOutput(sensorMappedValue);
    float drivePower = m_maxDrivePower*(1.0 - fabs(turnPower));
    ArcardeDrive(drivePower, turnPower);
}
__________________

Last edited by mikets : 12-03-2011 at 20:16.
Reply With Quote
  #7   Spotlight this post!  
Unread 13-03-2011, 20:46
tomy tomy is offline
Registered User
FRC #3038 (I.C.E. Robotics)
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Stacy, Minnesota
Posts: 494
tomy has a spectacular aura abouttomy has a spectacular aura about
Re: Line Tracking Code Help

my mentor and i did it in binary case statements and it worked well very confusing though
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 04:13.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi