View unanswered posts | View active topics It is currently Thu Dec 18, 2014 10:16 pm






Reply to topic  [ 3 posts ] 
Switching between Autonomous/Manual & Line follower 
Author Message
Rookie

Joined: Wed Mar 09, 2011 7:35 pm
Posts: 6
Post Switching between Autonomous/Manual & Line follower
For the Autonomous part, It only allows us to preforms the manual actions Skipping over the autonomous part.
Code:
#pragma config(Sensor, in1,    rightside,           sensorLineFollower)
#pragma config(Sensor, in2,    middle,              sensorLineFollower)
#pragma config(Sensor, in3,    leftside,            sensorLineFollower)
#pragma config(Sensor, dgtl1,  Input,               sensorSONAR_inch)
#pragma config(Motor,  port2,           rightMotor,    tmotorNormal, openLoop, reversed)
#pragma config(Motor,  port3,           leftMotor,     tmotorNormal, openLoop)
#pragma config(Motor,  port5,           Armmotor,      tmotorNormal, openLoop, reversed)
#pragma config(Motor,  port7,           Grippermotor,  tmotorNormal, openLoop, reversed)
#pragma platform(VEX)

//Competition Control and Duration Settings
#pragma competitionControl(Competition)
#pragma autonomousDuration(20)
#pragma userControlDuration(60)

#include "Vex_Competition_Includes.c"   //Main competition background code...do not modify!

void pre_auton()
{
   // All activities that occur before the competition starts
   // Example: clearing encoders, setting servo positions, ...
}

task autonomous()
{
  while (true)
  {
  motor[leftMotor]  = 63;
  motor[rightMotor] = 63;
} //   AuonomousCodePlaceholderForTesting();  // Remove this function call once you have "real" code.
}


task usercontrol()
{
   // User control code here, inside the loop

   while (true)
   {
     // Button Control:
  //ArmMotor
 if(vexRT[Btn5U] == 1)      //If button 5U is pressed:
  {
    motor[Armmotor] = 64;         //run Armmotor at quarter speed (i.e. lift arm)
  }
  else if(vexRT[Btn5D] == 1) //If button 5D is pressed:
  {
    motor[Armmotor] = -32;        //run Armmotor at quarter speed reversed (i.e. lower arm)
  }
  else if(vexRT[Btn5D] == 0)
  {
    motor[Armmotor] = 16;
  }
   else if(vexRT[Btn5U] == 0)
  {
    motor[Armmotor] = 0;
  }

  //Grippermotor
   if(vexRT[Btn6U] == 1)      //If button 6U is pressed:
  {
    motor[Grippermotor] = 64;         //run Grippermotor  at quarter speed (i.e. lift arm)
  }
  else if(vexRT[Btn6D] == 1) //If button 6D is pressed:
  {
    motor[Grippermotor] = -64;        //run Grippermotor at quarter speed reversed (i.e. lower arm)
  }
  else if(vexRT[Btn6D] == 0)
  {
    motor[Grippermotor] = 0;
  }
   else if(vexRT[Btn6U] == 0)
  {
    motor[Grippermotor] = 0;
  }
  // Wheel Motors

    motor[leftMotor]  = vexRT[Ch3];   // Left Joystick Y value
    motor[rightMotor] = vexRT[Ch2];   // Right Joystick Y value
   }
}



As for the line follower, It doesn't work to be simple. It makes a few turns here and there, but it doesn't follow the line at all.

Code:
#pragma config(Sensor, in1,    lineFollowerRIGHT,   sensorLineFollower)
#pragma config(Sensor, in2,    lineFollowerCENTER,  sensorLineFollower)
#pragma config(Sensor, in3,    lineFollowerLEFT,    sensorLineFollower)
#pragma config(Motor,  port2,           rightMotor,    tmotorNormal, openLoop, reversed)
#pragma config(Motor,  port3,           leftMotor,     tmotorNormal, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

/*----------------------------------------------------------------------------------------------------*\
|*                                    - Triple Sensor Line Tracking -                                   *|
|*                                      ROBOTC on VEX 2.0 CORTEX                                      *|
|*                                                                                                    *|
|*  This program uses 3 VEX Line Follower Sensors to track a black line on a light(er) surface.       *|
|*  There is a two second pause at the beginning of the program.                                      *|
|*                                                                                                    *|
|*                                        ROBOT CONFIGURATION                                         *|
|*    NOTES:                                                                                          *|
|*    1)  Reversing 'rightMotor' (port 2) in the "Motors and Sensors Setup" is needed with the        *|
|*        "Squarebot" mode, but may not be needed for all robot configurations.                       *|
|*    2)  Lighting conditions, line darkness, and surface lightness change from place to place,       *|
|*        so the value of 'threshold' may need to be changed to better suit your environment.         *|
|*                                                                                                    *|
|*    MOTORS & SENSORS:                                                                               *|
|*    [I/O Port]          [Name]              [Type]                [Description]                     *|
|*    Motor  - Port 2     rightMotor          VEX 3-wire module     Right side motor                  *|
|*    Motor  - Port 3     leftMotor           VEX 3-wire module     Left side motor                   *|
|*    Analog - Port 1     lineFollowerRIGHT   VEX Light Sensor      Front-right, facing down          *|
|*    Analog - Port 2     lineFollowerCENTER  VEX Light Sensor      Front-center, facing down         *|
|*    Analog - Port 3     lineFollowerLEFT    VEX Light Sensor      Front-left, facing down           *|
\*-----------------------------------------------------------------------------------------------4246-*/


//+++++++++++++++++++++++++++++++++++++++++++++| MAIN |+++++++++++++++++++++++++++++++++++++++++++++++
task main()
{
 // wait1Msec(2000);          // The program waits for 2000 milliseconds before continuing.

  int threshold = 505;      /* found by taking a reading on both DARK and LIGHT    */
                            /* surfaces, adding them together, then dividing by 2. */
  while(true)
  {
    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\
    displayLCDCenteredString(0, "LEFT  CNTR  RGHT");        //  Display   |
    displayLCDPos(1,0);                                     //  Sensor    |
    displayNextLCDNumber(SensorValue(lineFollowerLEFT));    //  Readings  |
    displayLCDPos(1,6);                                     //  to LCD.   |
    displayNextLCDNumber(SensorValue(lineFollowerCENTER));  //            |
    displayLCDPos(1,12);                                    //  L  C  R   |
    displayNextLCDNumber(SensorValue(lineFollowerRIGHT));   //  x  x  x   |
    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -/

    // RIGHT sensor sees dark:
    //  if(SensorValue(lineFollowerLEFT & lineFollowerCENTER & lineFollowerRIGHT) > threshold)
   //{
      // stop:
   //  motor[leftMotor]  = 0;
   //  motor[rightMotor] = 0;
   //}
   if(SensorValue(lineFollowerRIGHT) > threshold)
    {
      // counter-steer right:
      motor[leftMotor]  = 63;
      motor[rightMotor] = 0;
    }
    // CENTER sensor sees dark:
    if(SensorValue(lineFollowerCENTER) > threshold)
    {
      // go straight
      motor[leftMotor]  = 63;
      motor[rightMotor] = 63;
    }
    // LEFT sensor sees dark:
    if(SensorValue(lineFollowerLEFT) > threshold)
    {
      // counter-steer left:
      motor[leftMotor]  = 0;
      motor[rightMotor] = 63;
    }

  }
}


Thanks

_________________
Kyle Johnson
Booker T. Washington's BEST Robotics team.
Tuskegee, Alabama


Mon Mar 14, 2011 4:12 am
Profile
Rookie

Joined: Wed Mar 09, 2011 7:35 pm
Posts: 6
Post Re: Switching between Autonomous/Manual & Line follower
We only have about 5 days left, please help quickly.

_________________
Kyle Johnson
Booker T. Washington's BEST Robotics team.
Tuskegee, Alabama


Mon Mar 14, 2011 4:13 am
Profile
Site Admin
Site Admin

Joined: Mon Jun 08, 2009 4:50 pm
Posts: 70
Post Re: Switching between Autonomous/Manual & Line follower
Hi yuukikaihou,

For your first problem, are you sure that you have your game board switch set to autonomous? The code seems correct and simple, but the robot needs to know that it is in Autonomous mode and not User control Mode.

For the second part, the line following--This is a general template, and what seems to be the issue is the threshold value isn't working for you. You should adjust the value or better yet, calibrate first and then adjust. These sample programs are written to show you how to do certain things, but there is no guarantee that with your lighting conditions or sensor distance from the ground, that it will work.

Be sure that your light sensor is about half a centimeter from the ground. Also adjust the threshold. If your room is brighter or darker than the test room we wrote this program in, chances are that it wont work.

To calibrate the light sensor (best idea so that it will work regardless of lighting conditions) take a reading on your light surface and take a reading on your dark surface. That way you know exactly what the robot sees with your sensor on your board. Then, a nice and simple way to get a good threshold is to add the value for light to the value for dark, and divide them in half: (lightReading + darkReading) / 2


Hope that this helps you,

_________________
Bence Feher

Undergraduate Intern - NREC, Robotics Academy
ROBOTC - Testing/Documentation/Developer

Computer Science, Japanese, East Asian Studies
University of Pittsburgh, Konan University 甲南大学


Tue Mar 15, 2011 11:46 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


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.