This is our team’s first year in Vex, and we’ve encountered a problem with our autonomous programming. We’re using an X-drive for our base, and we haven’t had any issues with it so far. The programming for the user control driving is done without using the drivetrain configuration which is built into the V5 pro editor. For autonomous, however, we used the drivetrain, for the integral sensor that it provides, as well as the programming ease that it provides. Unfortunately, configuring the drivetrain for the autonomous makes it interfere while controlling the user control, which is programmed without the drivetrain. Is there any way to have the drivetrain enabled for the autonomous period, but disabled for the user control? Ideally it would be a fix like that, but if that isn’t possible, what else could I do to make the autonomous programming work using the inertial sensor? The current autonomous code is test code.
Code is as follows:
/*----------------------------------------------------------------------------*/
/* */
/* Module: main.cpp */
/* Author: VEX */
/* Created: Thu Sep 26 2019 */
/* Description: Clawbot Competition Template */
/* */
/*----------------------------------------------------------------------------*/
// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name] [Type] [Port(s)]
// Controller1 controller
// Drivetrain drivetrain 1, 2, 8, 9, 4
// ---- END VEXCODE CONFIGURED DEVICES ----
#include "vex.h"
using namespace vex;
// A global instance of competition
competition Competition;
vex::motor frontRight(vex::PORT8, vex::gearSetting::ratio18_1);
vex::motor frontLeft(vex::PORT2, vex::gearSetting::ratio18_1);
vex::motor backRight(vex::PORT9, vex::gearSetting::ratio18_1);
vex::motor backLeft(vex::PORT1, vex::gearSetting::ratio18_1);
vex::motor armRight(vex::PORT19, vex::gearSetting::ratio36_1);
vex::motor armLeft(vex::PORT12, vex::gearSetting::ratio36_1);
vex::motor clawBottom(vex::PORT5, vex::gearSetting::ratio36_1);
// define your global instances of motors and other devices here
/*---------------------------------------------------------------------------*/
/* 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) {
// Insert autonomous user code here.
//test code.
Drivetrain.driveFor(12, inches);
Drivetrain.turnFor(right, 90, degrees);
Drivetrain.driveFor(18, inches);
Drivetrain.turnFor(right, 90, degrees);
Drivetrain.driveFor(12, inches);
Drivetrain.turnFor(right, 90, degrees);
Drivetrain.driveFor(18,inches);
Drivetrain.turnFor(right, 90, degrees);
}
/*---------------------------------------------------------------------------*/
/* */
/* 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
int leftX = 0, rightY = 0, rightX = 0; //left axis 4, right axis 1 & 2
bool lTop = false, lBottom = false; //left buttons, top and bottom
int leftY = 0;
bool rBottom = false;
double driveSpeedMult = 1;
while (1) {
leftX = Controller1.Axis4.value();
rightY = Controller1.Axis2.value();
rightX = Controller1.Axis1.value();
lTop = Controller1.ButtonL1.pressing();
lBottom = Controller1.ButtonL2.pressing();
rBottom = Controller1.ButtonR2.pressing();
leftY = Controller1.Axis3.value();
//keep motors locked in place
armRight.stop(brakeType::hold);
armLeft.stop(brakeType::hold);
clawBottom.stop(brakeType::hold);
//reduce motor speed on right bottom press
if (rBottom) {
driveSpeedMult = 0.02;
}
else {
driveSpeedMult = 1;
}
//xDrive
frontLeft.spin(directionType::fwd, (leftX+rightY+rightX)*driveSpeedMult, voltageUnits::volt);
backLeft.spin(directionType::fwd, (leftX+rightY-rightX)*driveSpeedMult, voltageUnits::volt);
frontRight.spin(directionType::fwd, (leftX-rightY+rightX)*driveSpeedMult, voltageUnits::volt);
backRight.spin(directionType::fwd, (leftX-rightY-rightX)*driveSpeedMult, voltageUnits::volt);
//arm
if (lTop) {
if (rBottom) {
armLeft.spin(directionType::fwd, (-5), voltageUnits::volt);
armRight.spin(directionType::fwd, (5), voltageUnits::volt);
}
else {
armLeft.spin(directionType::fwd, (-15), voltageUnits::volt);
armRight.spin(directionType::fwd, (15), voltageUnits::volt);
}
}
else if (lBottom) {
if (rBottom) {
armLeft.spin(directionType::fwd, 1, voltageUnits::volt);
armRight.spin(directionType::fwd, -1, voltageUnits::volt);
}
else {
armLeft.spin(directionType::fwd, 5, voltageUnits::volt);
armRight.spin(directionType::fwd, -5, voltageUnits::volt);
}
}
//claw
if (leftY > 50) {
if (rBottom) {
clawBottom.spin(directionType::fwd, 2, voltageUnits::volt);
}
else {
clawBottom.spin(directionType::fwd, 6, voltageUnits::volt);
}
}
else if (leftY < -50) {
if (rBottom) {
clawBottom.spin(directionType::fwd, -0.5, voltageUnits::volt);
}
else {
clawBottom.spin(directionType::fwd, -4, voltageUnits::volt);
}
}
// 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);
}
}