I have easyc 1.1 for programing my vex kit, but i can’t figure out how to get my 3 linetrackers working. So could someone post the linetracker file?
A working version of the linetracker code is already posted here, as well as the related discussion.
There are also pictures of our tracker robot in the gallery, and a YouTube of it in action.
Cheers,
- Dean
i have easyc 1.1 and the code will not work
Ahh, right. I suppose I could post screenshots of the code so you can re-create it…
- Dean
EasyC 1.x does not have the ability to to create User Functions within EasyC. You will need to either write ALL the code Inline, or Create your own User Functions and call them with EasyC 1.x User Code command.
Main Header File
#ifndef _main_h_
#define _main_h_
#include "UserAPI.h"
#define RUN_SPEED 127
#define SPIN_SPEED 96
#define VEER_SPEED 64
#define STOP 1
#define GO 0
#define BLACK 1
#define WHITE 0
#define RIGHT 1
#define LEFT 0
extern int LastBlack ;
extern int Threshold ;
int Track_Line ( void ) ;
void Left_Speed ( int speed ) ;
void Right_Speed ( int speed ) ;
#endif // _main_h_
Main Code
#include "Main.h"
void main ( void )
{
int Stop = 1;
int Buttons = 127;
while ( 1 ) // Loop Forever
{
Buttons = GetRxInput ( 1 , 5 ) ;
if ( Buttons < 50 )
{
Stop = STOP ;
SetMotor ( 8 , 127 ) ; // Turn Lamp Off
SetDigitalOutput ( 11 , 0 ) ; // Turn LED Off
}
else if ( Buttons >200 )
{
Stop = GO ;
SetMotor ( 8 , 255 ) ; // Turn Lamp On
SetDigitalOutput ( 11 , 1 ) ; // Turn LED On
Threshold = GetAnalogInput ( 4 ) ;
}
if ( Stop )
{
Tank2 ( 0 , 3 , 2 , 3 , 2 , 0 , 1 ) ; // Standard 23 Tank Mode
}
else
{
Stop = Track_Line ( ) ;
if ( Stop == 1 )
{
Left_Speed ( 0 ) ;
Right_Speed ( 0 ) ;
}
}
}
}
Track Line
#include "Main.h"
int Track_Line ( void )
{
int Right = 0;
int Left = 0;
int Center = 0;
Right = GetAnalogInput ( 1 ) ;
Left = GetAnalogInput ( 2 ) ;
Center = GetAnalogInput ( 3 ) ;
Right = Right > Threshold ; // 1=Black, 0=White
Left = Left > Threshold ; // 1=Black, 0=White
Center= Center > Threshold ; // 1=Black, 0=White
if ( Center == WHITE ) // Center sees White! Need to Steer
{
if ( Right == BLACK ) // Need to steer right
{
Left_Speed ( SPIN_SPEED ) ;
Right_Speed ( 0 ) ;
LastBlack = RIGHT ;
}
else if ( Left == BLACK ) // Need to steer left
{
Left_Speed ( 0 ) ;
Right_Speed ( SPIN_SPEED ) ;
LastBlack = LEFT ;
}
else // All White - need to hunt!
{
if ( LastBlack == RIGHT ) // Need to hunt right
{
Left_Speed ( VEER_SPEED ) ;
Right_Speed ( -SPIN_SPEED ) ;
}
else // Need to hunt left
{
Left_Speed ( -SPIN_SPEED ) ;
Right_Speed ( VEER_SPEED ) ;
}
}
}
else // Center sees Black
{
if ( (Right == BLACK) && (Left == BLACK) ) // All Three Black! Need to hunt
{
if ( LastBlack == RIGHT ) // Need to hunt right
{
Left_Speed ( SPIN_SPEED ) ;
Right_Speed ( -VEER_SPEED ) ;
}
else // Need to hunt left
{
Left_Speed ( -VEER_SPEED ) ;
Right_Speed ( SPIN_SPEED ) ;
}
}
else
{
if ( Right == BLACK ) // Line is on Right, need to veer right
{
Left_Speed ( SPIN_SPEED ) ;
Right_Speed ( VEER_SPEED ) ;
LastBlack = RIGHT ;
}
else if ( Left == BLACK ) // Line is on Left, need to veer left
{
Left_Speed ( VEER_SPEED ) ;
Right_Speed ( SPIN_SPEED ) ;
LastBlack = LEFT ;
}
else // Line is dead center - full speed ahead!
{
Left_Speed ( SPIN_SPEED ) ;
Right_Speed ( SPIN_SPEED ) ;
}
}
}
return GO ;
}
Left Speed
#include "Main.h"
void Left_Speed ( int speed )
{ // Left motor speed (-127..0..127)
SetMotor ( 3 , 127+speed ) ;
}
Right Speed
#include "Main.h"
void Right_Speed ( int speed )
{ // Right motor speed (-127..0..127)
SetMotor ( 2 , 127-speed ) ;
}
Yep - the code that matters is all in Track_Line(), which can simply become main(). The original main() just has code to turn line-tracking on and off, which isn’t really necessary.
You’ll need to make sure to set Threshold to a sensible value, though. I read it from a potentiometer so it could easily be adjusted, but we never needed to change it. Just pick a value that is half way between the dark and light readings you get from your line sensors.
Also, Left_Speed() and Right_Speed() can be easily eliminated by just inserting each function’s code wherever they were called.
Those changes will easily get you down to a single block of code.
Cheers,
- Dean
I forgot the DEFINES in the Header File… Added Now…
A very simple one-sensor line tracker and program are given in both the documents Vex Machinations or Vex for the Technically Challenged, posted here:
http://www.vexrobotics.com/vex-education-general-resources.shtml