I need help with the driver control part where the control drives foreward, backward, and turns. The problem is depending on how I alter the code the forward backward part will work but then the turn will malfunction where it tries to run the code and the wheels take turns gingerly spinning but it doesn’t do what it’s meant to and vice verse. I’m wanting to know what to change so that both the forward backward part and turning part can both operate the way they are supposed to when their specific joystick is moved. Please tell me what you think. Thanks!
#pragma region VEXcode Generated Robot Configuration
// Make sure all required headers are included.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <string.h>
#include "vex.h"
using namespace vex;
// Brain should be defined by default
brain Brain;
// START V5 MACROS
#define waitUntil(condition) \
do { \
wait(5, msec); \
} while (!(condition))
#define repeat(iterations) \
for (int iterator = 0; iterator < iterations; iterator++)
// END V5 MACROS
// Robot configuration code.
// Robot configuration code.
motor L1 = motor(PORT1, ratio6_1, true);
motor L2 = motor(PORT2, ratio6_1, true);
motor L3 = motor(PORT3, ratio6_1, true);
motor R1 = motor(PORT11, ratio6_1, false);
motor R2 = motor(PORT12, ratio6_1, false);
motor R3 = motor(PORT13, ratio6_1, false);
motor Catapult = motor(PORT10, ratio6_1, true);
controller Controller1 = controller(primary);
motor_group RightDriveSmart = motor_group(R3, R2, R1);
motor_group LeftDriveSmart = motor_group(L3, L2, L1);
drivetrain Drivetrain = drivetrain(LeftDriveSmart, RightDriveSmart, 319.19, 295, 40, mm, 1);
// Helper to make playing sounds from the V5 in VEXcode easier and
// keeps the code cleaner by making it clear what is happening.
void playVexcodeSound(const char * soundName) {
printf("VEXPlaySound:%s\n", soundName);
wait(5, msec);
}
// define variable for remote controller enable/disable
bool RemoteControlCodeEnabled = true;
// define variables used for controlling motors based on controller inputs
bool DrivetrainLNeedsToBeStopped_Controller1 = true;
bool DrivetrainRNeedsToBeStopped_Controller1 = true;
// define a task that will handle monitoring inputs from Controller1
int rc_auto_loop_function_Controller1() {
// process the controller input every 20 milliseconds
// update the motors based on the input values
while (true) {
if (RemoteControlCodeEnabled) {
// calculate the drivetrain motor velocities from the controller joystick axies
// left = Axis3 + Axis1
// right = Axis3 - Axis1
int drivetrainLeftSideSpeed = Controller1.Axis3.position() + Controller1.Axis1.position();
int drivetrainRightSideSpeed = Controller1.Axis3.position() - Controller1.Axis1.position();
// check if the value is inside of the deadband range
if (drivetrainLeftSideSpeed < 5 && drivetrainLeftSideSpeed > -5) {
// check if the left motor has already been stopped
if (DrivetrainLNeedsToBeStopped_Controller1) {
// stop the left drive motor
LeftDriveSmart.stop();
// tell the code that the left motor has been stopped
DrivetrainLNeedsToBeStopped_Controller1 = false;
}
} else {
// reset the toggle so that the deadband code knows to stop the left motor nexttime the input is in the deadband range
DrivetrainLNeedsToBeStopped_Controller1 = true;
}
// check if the value is inside of the deadband range
if (drivetrainRightSideSpeed < 5 && drivetrainRightSideSpeed > -5) {
// check if the right motor has already been stopped
if (DrivetrainRNeedsToBeStopped_Controller1) {
// stop the right drive motor
RightDriveSmart.stop();
// tell the code that the right motor has been stopped
DrivetrainRNeedsToBeStopped_Controller1 = false;
}
} else {
// reset the toggle so that the deadband code knows to stop the right motor next time the input is in the deadband range
DrivetrainRNeedsToBeStopped_Controller1 = true;
}
// only tell the left drive motor to spin if the values are not in the deadband range
if (DrivetrainLNeedsToBeStopped_Controller1) {
LeftDriveSmart.setVelocity(drivetrainLeftSideSpeed, percent);
LeftDriveSmart.spin(forward);
}
// only tell the right drive motor to spin if the values are not in the deadband range
if (DrivetrainRNeedsToBeStopped_Controller1) {
RightDriveSmart.setVelocity(drivetrainRightSideSpeed, percent);
RightDriveSmart.spin(forward);
}
}
// wait before repeating the process
wait(20, msec);
}
return 0;
}
task rc_auto_loop_task_Controller1(rc_auto_loop_function_Controller1);
#pragma endregion VEXcode Generated Robot Configuration
////////////////////////////////////////////////////////
There is code inbeteween the top section and bottom section but it is irrelevant so I removed it. The code missing is preauton and auton stuff, I didn't want to make this overly long.
////////////////////////////////////////////////////
void userControl(void) {
Brain.Screen.clearScreen();
// place driver control in this while loop
while (true) {
// "when driver control" hat block
if (Controller1.Axis3.position() > 10) {
L1.spin(forward, Controller1.Axis3.position(), volt);
L2.spin(forward, Controller1.Axis3.position(), volt);
L3.spin(forward, Controller1.Axis3.position(), volt);
R1.spin(forward, Controller1.Axis3.position(), volt);
R2.spin(forward, Controller1.Axis3.position(), volt);
R3.spin(forward, Controller1.Axis3.position(), volt);
}
// "when driver control" hat block
else if (Controller1.Axis1.position() > 10) {
L1.spin(reverse, Controller1.Axis1.position(), volt);
L2.spin(reverse, Controller1.Axis1.position(), volt);
L3.spin(reverse, Controller1.Axis1.position(), volt);
R1.spin(forward, Controller1.Axis1.position(), volt);
R2.spin(forward, Controller1.Axis1.position(), volt);
R3.spin(forward, Controller1.Axis1.position(), volt);
} else {
L1.stop();
L2.stop();
L3.stop();
R1.stop();
R2.stop();
R3.stop();
}
// "when driver control" hat block
Brain.Screen.clearScreen();
if (Controller1.ButtonX.pressing()) {
Catapult.spin(forward);
waitUntil(Controller1.ButtonA.pressing());
} else {
Catapult.stop();
}
// Start the driver control tasks....
wait(20, msec);
}
}
int main() {
// create competition instance
competition Competition;
// Set up callbacks for autonomous and driver control periods.
Competition.autonomous(autonomous);
Competition.drivercontrol(userControl);
// Run the pre-autonomous function.
preAutonomous();
// Prevent main from exiting with an infinite loop.
while (true) {
wait(100, msec);
}
}