Tags:
create new tag
view all tags
#pragma config(Motor,  port2,           LeftForward,   tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor,  port3,           RightForward,  tmotorServoContinuousRotation, openLoop)
#pragma config(Motor,  port4,           LeftBack,      tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor,  port5,           RightBack,     tmotorServoContinuousRotation, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

##function to cause all motors to stop, stopping the vehicle when the button command is pressed
void stopMotor()
{
   motor[LeftForward] = 0;
   motor[RightForward]  = 0;
   motor[LeftBack] = 0;
   motor[RightBack] = 0;
}

##function that causes all wheels to move simultaneously at the same speed, causing it to move forward with a variable passed to it to determine for how long
void moveForwardForTime(int howLong)
{
   motor[LeftForward] = 127;
   motor[RightForward]  = 127;
   motor[LeftBack] = 127;
   motor[RightBack] = 127;
   wait1Msec(howLong); ##built in function wait1Msec to receive the howLong variable. This determines how long the vehicle should move forward
}

##function that turns left wheels forward at standard forward speed (clockwise), but turns right wheels the negative amount (counter-clockwise). This cause the the vehicle to rotate in place, turning to the right.
void rotateForTime(int howLong)
{
   motor[LeftForward] = 127;
   motor[RightForward]  = -127;
   motor[LeftBack] = 127;
   motor[RightBack] = -127;
   wait1Msec(howLong);
   stopMotor(); ##the stopMotor function is used here to ensure that after each iteration used in doSquare the tumbler stops completely before resuming again
}

##this function calls the moveForwardForTime and rotateForTime functions several times to cause the tumbler to move in a square. They are passed the same variables repeatedly to ensure the movements are uniform, creating the square.
void doSquare()
{
   moveForwardForTime(2000);
   rotateForTime(300);
   moveForwardForTime(2000);
   rotateForTime(300);
   moveForwardForTime(2000);
   rotateForTime(300);
   moveForwardForTime(2000);
   rotateForTime(300);
   return;
}

 
##this function causes the left wheels to move faster than the right wheels, causing the tumbler to form a circle
void doCircle()
{
   motor[LeftForward] = 127;
   motor[RightForward]  = 20;
   motor[LeftBack] = 127;
   motor[RightBack] = 20;
   wait1Msec(2000); ##no variable is passed in the function definition, so it is instead passed directly to the wait1Msec funstion to determine how long it will rotate
}


##main that assigns doSquare function to 7U, doCircle to 8U, and stopMotor to 7D
task main()
{
   while(true)
   {
      if(vexRT[Btn7U])
         doSquare();
      if(vexRT[Btn8U])
         doCircle();
      if(vexRT[Btn7D])
         stopMotor();
   }
}

<meta name="robots" content="noindex" />

-- (c) Fordham University Robotics and Computer Vision

Topic revision: r1 - 2013-03-25 - DavidWalsh
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback