Our while loop for controlling motors works as intended, but when we add the while loop into our user control section, we can no longer control our drive train. If we comment out our while loop, we regain control of the drive train. What would cause an issue like this? The issue is inside of our user control function, but we may be missing something somewhere else. We are first year competitors and had everything working before. We heard we had to use a template and are trying to get our code working with the competition template. Our code is below:
/*----------------------------------------------------------------------------*/
/* */
/* Module: main.cpp */
/* Author: VEX */
/* Created: Thu Sep 26 2019 */
/* Description: Competition Template */
/* */
/*----------------------------------------------------------------------------*/
// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name] [Type] [Port(s)]
// lift motor 7
// launcher motor 9
// frontSucker2 motor 2
// frontSucker1 motor 1
// Drivetrain drivetrain 12, 11
// Controller1 controller
// ---- END VEXCODE CONFIGURED DEVICES ----
#include "vex.h"
using namespace vex;
competition Competition;
void initialize() {
lift.setVelocity(100, percent);
frontSucker1.setVelocity(100, percent);
frontSucker2.setVelocity(100, percent);
launcher.setVelocity(100, percent);
Drivetrain.setDriveVelocity(30, percent);
}
void liftUp() {
lift.spin(reverse);
launcher.spin(reverse);
}
void liftDown() {
lift.spin(forward);
launcher.spin(forward);
}
void suckerIn() {
frontSucker1.spin(reverse);
frontSucker2.spin(reverse);
}
void suckerOut() {
frontSucker1.spin(forward);
frontSucker2.spin(forward);
}
void liftStop() {
lift.stop();
launcher.stop();
}
void suckerStop() {
frontSucker1.stop();
frontSucker2.stop();
}
void allStop() {
lift.stop();
frontSucker1.stop();
frontSucker2.stop();
launcher.stop();
}
void pre_auton(void) {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// All activities that occur before the competition starts
// Example: clearing encoders, setting servo positions, ...
}
void autonomous(void) {
initialize();
Drivetrain.setDriveVelocity(50, percent);
Brain.Screen.print("autonomous");
}
void usercontrol(void) {
Drivetrain.setDriveVelocity(100, percent);
while (1) {
if(Controller1.ButtonR1.pressing()){
suckerIn();
}
else if(Controller1.ButtonL1.pressing()){
suckerOut();
}
else{
suckerStop();
}
if(Controller1.ButtonR2.pressing()){
liftUp();
}
else if(Controller1.ButtonL2.pressing()){
liftDown();
}
else{
liftStop();
}
wait(20, msec); // Sleep the task for a short amount of time to
// prevent wasted resources.
}
}
//
// Main will set up the competition functions and callbacks.
//
int main() {
// Set up callbacks for autonomous and driver control periods.
autonomous();
usercontrol();
Competition.autonomous(autonomous);
Competition.drivercontrol(usercontrol);
// Run the pre-autonomous function.
pre_auton();
// Prevent main from exiting with an infinite loop.
while (true) {
wait(100, msec);
}
}