2 Wheel VEX Drivetrain

I am unable to get a 2 wheel drive train code to work on my robot. Does anyone have any ideas of a simple code that could work for this?

What type of drive are you using tank or arcade

Please post the code that you have tried to far.

1 Like

#include “vex.h”
#include
using namespace vex;

int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();

}
void autonomous(void);
void usercontrol(void);
double turnImportance = 1;

while (1) {

double turnval = Controller1.Axis1.position(percent);
double forwardval = Controller1.Axis3.position(percent);

double turnvolts = turnval * 0.12;
double forwardvolts = forwardval * 0.12 * (1 - (std::abs(turnVolts)/12.0) * turnImportance);

motor1.spin(forward, fowardvolts - turnvolts, voltageUnits::volts);
motor10.spin(forward, fowardvolts + turnvolts, voltageUnits::volts);
}

I am very new to this coding and watched many videos in order to put this code together. I just am not sure what the problem is.

Your code structure is incorrect.

It should be like this

#include “vex.h”
using namespace vex;
void usercontrol(void){
while (1) {

double turnval = Controller1.Axis1.position(percent);
double forwardval = Controller1.Axis3.position(percent);

double turnvolts = turnval * 0.12;
double forwardvolts = forwardval * 0.12 * (1 - (std::abs(turnVolts)/12.0) * turnImportance);

motor1.spin(forward, fowardvolts - turnvolts, voltageUnits::volts);
motor10.spin(forward, fowardvolts + turnvolts, voltageUnits::volts);
}
}
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
void autonomous(void);
void usercontrol(void);
}

double turnImportance = 1;

2 Likes

That code didn’t work. I am unsure why.

I haven’t tested your code but the main() function is being closed before it reaches the rest of your code.

main() is the primary function called by the robot. It runs the code within the curly braces and completes. It never reaches the code below. Move the closing curly brace } down to the end of your code so it is all included in the main() function.

#include “vex.h”
using namespace vex;

int main() {
    // Initializing Robot Configuration. DO NOT REMOVE!
	vexcodeInit();
//} <--Move this down.

	// void autonomous(void);
	// void usercontrol(void);

	double turnImportance = 1;

	while (1) {

	double turnval = Controller1.Axis1.position(percent);
	double forwardval = Controller1.Axis3.position(percent);

	double turnvolts = turnval * 0.12;
	double forwardvolts = forwardval * 0.12 * (1 - (std::abs(turnVolts)/12.0) * turnImportance);

	motor1.spin(forward, fowardvolts - turnvolts, voltageUnits::volts);
	motor10.spin(forward, fowardvolts + turnvolts, voltageUnits::volts);
	}

} //<-- To here.
7 Likes