H drive help

I justed started trying to code my H drive and it’s not working. I think I know but I’m not sure how to fix it. I’m very new to coding in c++.

hDriveMotor.spin(forward, Controller1.Axis4.value(), vex::velocityUnits::pct);
leftDriveMotor.spin(forward, Controller1.Axis1.value(), vex::velocityUnits::pct);
rightDriveMotor.spin(reverse, Controller1.Axis1.value(), vex::velocityUnits::pct);
leftDriveMotor.spin(forward, Controller1.Axis3.value(), vex::velocityUnits::pct);
rightDriveMotor.spin(forward, Controller1.Axis3.value(), vex::velocityUnits::pct);
vex::task::sleep(20);

I think that it has something to do with the fact that I’m telling the left and right motors to spin two differnt times and the program just picks the first one. Am I right to be thinking like that? And how do I fix it?

Yes, assigning the motor two different values each cycle through the loop will not do what you want it to do.

The solution is to instead add or subtract the two different controller axes, like this:

leftDriveMotor.spin(forward, Controller1.Axis1.value() + Controller1.Axis3.value(), vex::velocityUnits::pct);
rightDriveMotor.spin(forward, Controller1.Axis1.value() - Controller1.Axis3.value(), vex::velocityUnits::pct);
hDriveMotor.spin(forward, Controller1.Axis4.value(), vex::velocityUnits::pct);
2 Likes

I just packed up the robot for tonight but thank for the sugestion. I will try this tommorrow and I will let you know if it worked.