the robot stops after the first drive command in the autonomous, any tips? its not mechanical, because it drives during usercontrol.
/*----------------------------------------------------------------------------*/
/* /
/ Module: main.cpp /
/ Author: VEX /
/ Created: Thu Sep 26 2019 /
/ Description: Competition Template /
/ /
/----------------------------------------------------------------------------*/
// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name] [Type] [Port(s)]
// Controller1 controller
// FL motor 4
// FR motor 8
// BL motor 3
// BR motor 1
// FT motor 7
// Lift2 motor 2
// Lift9 motor 9
// ---- END VEXCODE CONFIGURED DEVICES ----
#include “vex.h”
using namespace vex;
// A global instance of competition
competition Competition;
//id Drive (int deg, int spe){
void Drive (int deg, int spe){
FL.startRotateFor(forward,deg,degrees,spe,velocityUnits::pct);
FR.startRotateFor(forward,deg,degrees,spe,velocityUnits::pct);
BL.startRotateFor(forward,deg,degrees,spe,velocityUnits::pct);
BR.rotateFor(forward,deg,degrees,spe,velocityUnits::pct);
BR.setTimeout(2, seconds);
}
void reve (int deg, int spe){
FL.startRotateFor(reverse,deg,degrees,spe,velocityUnits::pct);
FR.startRotateFor(reverse,deg,degrees,spe,velocityUnits::pct);
BL.startRotateFor(reverse,deg,degrees,spe,velocityUnits::pct);
BR.rotateFor(reverse,deg,degrees,spe,velocityUnits::pct);
}
void Right (int deg){
FL.startRotateFor(forward,deg,degrees,60,velocityUnits::pct);
FR.startRotateFor(reverse,deg,degrees,60,velocityUnits::pct);
BL.startRotateFor(forward,deg,degrees,60,velocityUnits::pct);
BR.rotateFor(reverse,deg,degrees,60,velocityUnits::pct);
}
void Left (int deg){
FL.startRotateFor(reverse,deg,degrees,60,velocityUnits::pct);
FR.startRotateFor(forward,deg,degrees,60,velocityUnits::pct);
BL.startRotateFor(reverse,deg,degrees,60,velocityUnits::pct);
BR.rotateFor(forward,deg,degrees,60,velocityUnits::pct);
}
void lift (int deg){
Lift2.startRotateFor(forward,deg,degrees,50,velocityUnits::pct);
Lift9.rotateFor(forward,deg,degrees,50,velocityUnits::pct);
}
void revlif (int deg){
Lift2.startRotateFor(reverse,deg,degrees,50,velocityUnits::pct);
Lift9.rotateFor(reverse,deg,degrees,50,velocityUnits::pct);
}
/---------------------------------------------------------------------------/
/* 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 V5 has been powered on and /
/ not every time that the robot is disabled. /
/---------------------------------------------------------------------------*/
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, …
}
/---------------------------------------------------------------------------/
/* /
/ 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) {
// …
lift(300);
Drive(150,100);
revlif(250);
reve(100,70);
Left(225);
Drive(500,70);
Right(225);
Drive(2700,70);
lift(300);
Drive(50,50);
revlif(250);
reve(100,70);
lift(50);
Drive(100,70);
lift(400);
reve(300,70);
// …
}
// moter 8 can go die in a hole i hate programing
/--------------------------------------------------------------------------/
/* /
/ User Control Task /
/ /
/ This task is used to control your robot during the user control phase of /
/ a VEX Competition. /
/ /
/ 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) {
FR.spin (forward, Controller1.Axis2.value(),velocityUnits::pct);
FL.spin (forward, Controller1.Axis3.value(),velocityUnits::pct);
BR.spin (forward, Controller1.Axis2.value(),velocityUnits::pct);
BL.spin (forward, Controller1.Axis3.value(),velocityUnits::pct);
if (Controller1.ButtonR2.pressing()){
Lift2.spin(forward, 50, velocityUnits::pct);
Lift9.spin(forward, 50, velocityUnits::pct);
}
else if (Controller1.ButtonR1. pressing()){
Lift2.spin(reverse, 50, velocityUnits::pct);
Lift9.spin(reverse, 50, velocityUnits::pct);
}
else { Lift2.stop(hold);
Lift9.stop(hold);
}
if (Controller1.ButtonL1.pressing()){
FT.spin(forward, 50, velocityUnits::pct);
}
else if (Controller1.ButtonL2. pressing()){
FT.spin(reverse, 50, velocityUnits::pct);
}
else {FT.stop(hold);
} // This is the main execution loop for the user control program.
// Each time through the loop your program should update motor + servo
// values based on feedback from the joysticks.
// ........................................................................
// Insert user code here. This is where you use the joystick values to
// update your motors, etc.
// ........................................................................
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.
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);
}
}