#include “robot-config.h”
/---------------------------------------------------------------------------/
/* /
/ Description: Competition template for VCS VEX V5 /
/ /
/---------------------------------------------------------------------------*/
//Creates a competition object that allows access to Competition methods.
vex::competition competition;
vex::rotationUnits rotations = vex::rotationUnits::rev;
/---------------------------------------------------------------------------/
/* Pre-Autonomous Functions /
/ /
/ You may want to perform some actions before the competition starts. /
/ Do them in the following function. You must return from this function /
/ or the autonomous and usercontrol tasks will not be started. This /
/ function is only called once after the cortex has been powered on and /
/ not every time that the robot is disabled. /
/---------------------------------------------------------------------------*/
void pre_auton( void ) {
// All activities that occur before the competition starts
// Example: clearing encoders, setting servo positions, …
}
/---------------------------------------------------------------------------/
/* /
/ Autonomous Task /
/ /
/ This task is used to control your robot during the autonomous phase of /
/ a VEX Competition. /
/ /
/ You must modify the code to add your own robot specific commands here. /
/---------------------------------------------------------------------------*/
void autonomous( void ) {
int howMany = 1;
LeftDrive.startRotateFor(howMany, rotations);
RightDrive.rotateFor(howMany, rotations);
}
/----------------------------------------------------------------------------/
/* /
/ User Control Task /
/ /
/ This task is used to control your robot during the user control phase of /
/ a VEX Competition. 45 q /
/ /
/ You must modify the code to add your own robot specific commands here. /
/----------------------------------------------------------------------------*/
void usercontrol( void ) {
// User control code here, inside the loop
while (1){
// …
// Insert user code here. This is where you use the joystick values to
// update your motors, etc.
// …
vex::task::sleep(20); //Sleep the task for a short amount of time to prevent wasted resources.
}
}
//
// Main will set up the competition functions and callbacks.
//
int main() {
//Run the pre-autonomous function.
pre_auton();
//Set up callbacks for autonomous and driver control periods.
Competition.autonomous( autonomous );
Competition.drivercontrol( usercontrol );
int armSpeedPCT = 50;
int clawSpeedPCT = 50;
//Prevent main from exiting with an infinite loop.
while(1) {
//Driver Control
while(true) {
LeftDrive.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct); //(Axis3+Axis4)/2
RightDrive.spin(vex::directionType::fwd, Controller1.Axis1.value(), vex::velocityUnits::pct);//(Axis3-Axis4)/2onType::rev, Controller1.Axis1.value(), vex::velocityUnits::pct);//(Axis3-Axis4)/2
//Arm Control
if(Controller1.ButtonR2.pressing()) { //If button L2 is pressed…
(Controller1.ButtonL2.pressing());
//…Spin the arm motor forward.
ArmMotor1.spin(vex::directionType::fwd, armSpeedPCT, vex::velocityUnits::pct);
ArmMotor2.spin(vex::directionType::fwd, armSpeedPCT, vex::velocityUnits::pct);
}
else if(Controller1.ButtonR1.pressing()) { //If button L2 is pressed…
(Controller1.ButtonL1.pressing());
//…Spin the arm motor backward.
ArmMotor1.spin(vex::directionType::rev, armSpeedPCT, vex::velocityUnits::pct);
ArmMotor2.spin(vex::directionType::rev, armSpeedPCT, vex::velocityUnits::pct);
}
else { //If the R1 or R2 button is not pressed…
//…Stop the arm motor.
ArmMotor1.stop(vex::brakeType::brake);
ArmMotor2.stop(vex::brakeType::brake);
}
if(Controller1.ButtonA.pressing()) { //If the A button is pressed…
//…Spin the claw motor forward.
ClawMotor.spin(vex::directionType::fwd, clawSpeedPCT, vex::velocityUnits::pct);
}
else if(Controller1.ButtonY.pressing()) { //If the Y button is pressed…
//…Spin the claw motor backward.
ClawMotor.spin(vex::directionType::rev, clawSpeedPCT, vex::velocityUnits::pct);
}
else { //If the A or Y button are not pressed…
//…Stop the claw motor.
ClawMotor.stop(vex::brakeType::brake);
}
vex::task::sleep(100);//Sleep the task for a short amount of time to prevent wasted resources.
}
}