I have been working on a spin-up bot, and my goal is to program a button that will reverse the direction and controls, so that it is easier to aim the bot. The problem is that we use the drivetrain option as a built-in system. Ideally, I would like to find a way to make changes to specific motors in the existing drivetrain, but I understand I might have to code a drivetrain myself in order to do that.
Does anyone have an idea or code that can help? I use V5 pro C++
Something that might work for you is to create an integer variable that has a default value of 1. When the button is pressed, you toggle the variable between 1 and -1. You can then just multiply the power you are setting to the drive train by this variable. This will change the direction to either negative or positive, changing the direction that you are driving in.
I can’t give a more specific answer since I don’t know what your code looks like.
Yeah… I’ve had that in a previous code, but we had each motor individually programmed. The thing is, once we tried the drivetrain option we couldn’t go back. It’s just superior.
So for this reason I am searching for the code used to make the pre-built drivetrain in the compiler.
I have not actually used VexCode before so someone else can probably figure this problem out much easier but I’m guessing you are using this class? From what I can see, the methods have parameters where you can enter a power or velocity, so I’m assuming that if you enter a negative value, it will just drive the robot backwards.
The simplest way to do that is to set it up as motor groups for each side and program the driver control yourself.
If you want the drivetrain functionality for other reasons like autonomous, you can still have that. Take a look at robot-config.cpp, under “src” near the left side of the screen. You should see something like this (your port numbers, etc. are likely to be different):
motor leftMotorA = motor(PORT1, ratio18_1, false);
motor leftMotorB = motor(PORT2, ratio18_1, false);
motor_group LeftDriveSmart = motor_group(leftMotorA, leftMotorB);
motor rightMotorA = motor(PORT3, ratio18_1, true);
motor rightMotorB = motor(PORT4, ratio18_1, true);
motor_group RightDriveSmart = motor_group(rightMotorA, rightMotorB);
drivetrain Drivetrain = drivetrain(LeftDriveSmart, RightDriveSmart, 319.19, 295, 40, mm, 1);
This code is created when you make a drivetrain in the devices menu. Copy the last line (setting up the drivetrain) and put it near the top of your own code (in main.cpp). Then redo your robot setup with two motor groups called LeftDriveSmart and RightDriveSmart. Now you should be able to write your driver control code by setting LeftDriveSmart and RightDriveSmart, and your autonomous code using the Drivetrain which you set up in your own code.
By the way, if anyone reading this is using regular Vexcode V5 instead of Pro, you can already control the left sides and right sides as motor groups if you have set up a Drivetrain. Click the + reveal button next to #pragma on line 1 of your code to see how everything is set up.