For whatever reason, when I try and use inches on my code, it gives me an error. I looked at the vexcode page and it said I could use inches. Why isn’t it working?
This is my code:
driveTrain.setVelocity(30,pct);
insideMotors.setVelocity(100,pct);
Brain.Screen.print(“VELOCITY SET”)
insideMotors.spin(fwd);
driveTrain.spinFor(fwd,24,inches);
Brain.Screen.print(“BALL PICKED UP”);
because inches is not a unit you can use. when you’re telling a motor to spin, you have to specify it in rotational units. if you want to use inches, you’ll have to make a function that converts inches into revolutions (or degrees).
to do this, you’ll need to use the relationship between revolutions and tangential distance, which is:
distance in inches = wheel circumference*revolutions
If he is using the drivetrain class, than it would work in inches. So I guess the logical question is are you using the drivetrain object in your program or do you just have a motor group named driveTrain?
Also, tip for posting code in VEX Forum:
Use ``` at both the beginning and end of your code.
I’m not super familiar with the driveTrain class, since I’ve never used it, but looking at the documentation on it, SpinFor only accepts rotational units. Drive or DriveFor seem to be the things that accept linear units.
I can’t see that spinFor function in the drivetrain class. That might just be the error. Again, @angrycoder,
are you using the drivetrain class or did you just name a bunch of motors “driveTrain?”
or alternatively just control the motors independently without a drivetrain class. I think you can get a lot more control over what yours motors are doing if you just control them individually.
of course for autonomous you can use functions to make it easy to control them as a group.
Note: All of these responses, including this one, are unofficial. But for the meantime I hope we can be of help until you receive an official response.
+1
I highly agree, the vexcode drivetrain system is way too simple and the choices are too restricted. @angrycoder
If you want the motor to turn x amount of inches forward, you will need to convert the inches to rotations:
#include <math.h>
# Settings
wheelDiameter = 4; // inches;
double getDesiredRotations(diam, distance){
double circumference = (M_PI * diam);
double revolutions = distance / circumference;
return revolutions;
}
main(){
// I wanna go x inches
inchesToMove = 24; // Inches
// Get revolutions required to achieve x distance
motorRevolutionsToMove = getDesiredRotations(wheelDiameter , inchesToMove );
motor.spinfor(fwd, motorRevolutionsToMove, rotationUnits::rev);
}
If you are using a smart drive, then the command would be drivetrain.driveFor(DIR, NUMBER, INCHES);
If you are not using smart drive i’d suggest you switch or you’d have to figure out how many rotations are in an inch for your drivetrain.
Can you put this command in the code or would you have to calculate this manually? And if you can implement this command in your code, where would you put it?